How to use the mido.Message function in mido

To help you get started, we’ve selected a few mido examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github segfault16 / modular-led-controller-workstation / tests / test_midi_full_controller.py View on Github external
caplog.set_level(logging.DEBUG)
    logging.debug("UPDATE TEST")
    f = mock.Mock()
    version._test_version = "0.0.0"
    tmpDirPath = os.path.join(tmpdir, "pyu-data", "deploy")
    # tmpDirPath = os.getcwd()  # Enable for testing after creating release or release-dev
    # Write test files
    if not os.path.exists(tmpDirPath):
        os.makedirs(tmpDirPath)

    opts = midi_full.MidiProjectControllerOptions()
    opts.update_paths = [os.path.join(tmpDirPath, "pyu-data", "deploy")]
    # opts.client_config = TConfig()
    ctrl = midi_full.MidiProjectController(callback=f, options=opts)
    # Update message
    testMsg = mido.Message('sysex')
    testMsg.data = [0x00, 0x11]
    # Init in-memory config
    cfg = serverconfiguration.ServerConfiguration()
    # Handle message
    ctrl.handleMidiMsg(testMsg, cfg, None)
    if f.call_count > 0:
        retMsg = f.call_args[0][0]
        assert retMsg.data[0] == 0x00
        assert retMsg.data[1] == 0x1F
github segfault16 / modular-led-controller-workstation / tests / test_midi_full_controller.py View on Github external
def test_delete_project_not_found():
    # Setup
    f = mock.Mock()
    ctrl = midi_full.MidiProjectController(callback=f)
    # Get active project metadata
    testMsg = mido.Message('sysex')
    testMsg.data = [0x00, 0x70] + sysex_data.encode(bytes("blubb", encoding='utf8'))
    # Init in-memory config
    cfg = serverconfiguration.ServerConfiguration()
    proj = cfg.getActiveProjectOrDefault()
    proj.stopProcessing()
    # Handle message
    ctrl.handleMidiMsg(testMsg, cfg, proj)
    assert f.call_count == 1
    retMsg = f.call_args[0][0]
    # Check response message ID
    assert retMsg.data[0] == 0x00
    assert retMsg.data[1] == 0x7F
github eegsynth / eegsynth / module / outputmidi / outputmidi.py View on Github external
if name.startswith('control'):
        if midichannel is None:
            msg = mido.Message('control_change', control=code, value=val)
        else:
            msg = mido.Message('control_change', control=code, value=val, channel=midichannel)
    elif name.startswith('polytouch'):
        if midichannel is None:
            msg = mido.Message('polytouch', note=code, value=val)
        else:
            msg = mido.Message('polytouch', note=code, value=val, channel=midichannel)
    elif name == 'aftertouch':
        if midichannel is None:
            msg = mido.Message('aftertouch', value=val)
        else:
            msg = mido.Message('aftertouch', value=val, channel=midichannel)
    elif name == 'pitchwheel':
        if midichannel is None:
            msg = mido.Message('pitchwheel', pitch=val)
        else:
            msg = mido.Message('pitchwheel', pitch=val, channel=midichannel)
    # the following MIDI messages are not channel specific
    elif name == 'start':
        msg = mido.Message('start')
    elif name == 'continue':
        msg = mido.Message('continue')
    elif name == 'stop':
        msg = mido.Message('stop')
    elif name == 'reset':
        msg = mido.Message('reset')
    # send the MIDI message
    outputport.send(msg)
github eegsynth / eegsynth / module / launchcontrol / launchcontrol.py View on Github external
def ledcolor(note, color):
    if not midichannel is None:
    	outputport.send(mido.Message('note_on', note=int(note), velocity=color, channel=midichannel))
github eegsynth / eegsynth / module / launchcontrol / launchcontrol.py View on Github external
def ledcolor(note,color):
    if not midichannel is None:
	outputport.send(mido.Message('note_on', note=int(note), velocity=color, channel=midichannel))
github hartmetzls / audio_to_midi / create_dataset.py View on Github external
delta_time_midi_segment.append([note_on_or_off, pitch, delta_time])
            time_so_far = time

        mid = MidiFile()
        track = MidiTrack()
        mid.tracks.append(track)
        for message in delta_time_midi_segment:
            note_on_or_off = message[0]
            pitch = int(message[1])
            delta_ticks = message[-1]

            # debugging/for future use with a dataset other than SMD
            if type(delta_ticks) != int or delta_ticks < 0:
                print("time issue")

            track.append(Message(note_on_or_off, note=pitch, time=delta_ticks))

        # for testing by listening to midi (currently written for windows)
        # str_start_time = str(midi_segment[0])
        # filename_format = "C:/Users/Lilly/audio_and_midi/segments/midi/{0}_start_time_{1}.mid"
        # filename = filename_format.format(midi_filename, str_start_time)
        # mid.save(filename)

    return
github mido / mido / extras / hid_joystick.py View on Github external
if event['type'] == 'button':
            print(event)

            button = event['number'] + 1  # Number buttons starting with 1.
            if button not in note_mapping:
                continue

            if event['value']:
                type_ = 'note_on'
            else:
                type_ = 'note_off'
            
            note = note_mapping[button]

            message = mido.Message(type_, channel=9, note=note, velocity=64)
            print(message)
            out.send(message)
github AmazingThew / KnobSock / animator.py View on Github external
def setKnobColor(self, index, color):
        message = mido.Message('control_change', channel=1, control=index, value=color)
        self._send(message)
github dagargo / microdude / microdude / connector.py View on Github external
def get_ctl_msgs(self, param, value):
        if param == BEND_RANGE:
            return [
                Message('control_change', channel=self.channel,
                        control=101, value=0),
                Message('control_change', channel=self.channel,
                        control=100, value=0),
                Message('control_change', channel=self.channel,
                        control=6, value=value),
                Message('control_change', channel=self.channel,
                        control=38, value=0)
            ]
        else:
            ctl = PARAM_CTL_MAPPING[param]['ctl']
            val = PARAM_CTL_MAPPING[param]['map'](value)
            return [Message('control_change', channel=self.channel,
                          control=ctl, value=val)]