aboutsummaryrefslogtreecommitdiffstats
path: root/solo-tool-project/src/solo_tool/midi_wrapper_mido.py
blob: 34f1031533fa41389d311c0190090fda2961f43e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import mido

class MidiWrapper:
    def __init__(self):
        self._inPort = None
        self._outPort = None

    def connect(self, deviceName, callback):
        if self._inPort is None and self._outPort is None:
            self._inPort = mido.open_input(deviceName)
            self._inPort.callback = callback
            self._outPort = mido.open_output(deviceName)

    def disconnect(self):
        if self._inPort is not None:
            self._inPort.close()
            self._inPort = None

        if self._outPort is not None:
            self._outPort.reset()
            self._outPort.close()
            self._outPort = None

    def sendMessage(self, note, velocity, channel):
        if self._outPort is not None:
            msg = mido.Message('note_on', channel=channel, velocity=velocity, note=note)
            self._outPort.send(msg)