diff options
author | Eddy Pedroni <epedroni@pm.me> | 2024-11-09 23:22:55 +0100 |
---|---|---|
committer | Eddy Pedroni <epedroni@pm.me> | 2024-11-09 23:22:55 +0100 |
commit | f676c50ba91ca6d4d0da9f77aeadc8b3fb16dc26 (patch) | |
tree | dd7cf29dff80610ec3e6179b444954a5bca3e125 /solo-tool-project/src/solo_tool | |
parent | cda8197669409689be291660f93cb288ab2d31b3 (diff) |
CLI improvements
Diffstat (limited to 'solo-tool-project/src/solo_tool')
-rw-r--r-- | solo-tool-project/src/solo_tool/midi_controller_launchpad_mini.py | 7 | ||||
-rw-r--r-- | solo-tool-project/src/solo_tool/midi_wrapper_mido.py | 19 |
2 files changed, 17 insertions, 9 deletions
diff --git a/solo-tool-project/src/solo_tool/midi_controller_launchpad_mini.py b/solo-tool-project/src/solo_tool/midi_controller_launchpad_mini.py index 961127c..8f32650 100644 --- a/solo-tool-project/src/solo_tool/midi_controller_launchpad_mini.py +++ b/solo-tool-project/src/solo_tool/midi_controller_launchpad_mini.py @@ -51,10 +51,13 @@ class MidiController: self._handlers[button] = self._createSetPlaybackRateCallback(rate) def connect(self): - self._midiWrapper.setCallback(self._callback) - self._midiWrapper.connect(MidiController.DEVICE_NAME) + self._midiWrapper.connect(MidiController.DEVICE_NAME, self._callback) self._initialiseButtonLEDs() + def disconnect(self): + self._allLEDsOff() + self._midiWrapper.disconnect() + def _callback(self, msg): if msg.type != "note_on" or msg.velocity < 127: return diff --git a/solo-tool-project/src/solo_tool/midi_wrapper_mido.py b/solo-tool-project/src/solo_tool/midi_wrapper_mido.py index bf3aa85..4cfc9c3 100644 --- a/solo-tool-project/src/solo_tool/midi_wrapper_mido.py +++ b/solo-tool-project/src/solo_tool/midi_wrapper_mido.py @@ -4,15 +4,20 @@ class MidiWrapper: def __init__(self): self._inPort = None self._outPort = None - self._callback = None - def setCallback(self, callback): - self._callback = callback + 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 connect(self, deviceName): - self._inPort = mido.open_input(deviceName) - self._inPort.callback = self._callback - self._outPort = mido.open_output(deviceName) + def disconnect(self): + self._inPort.close() + self._inPort = None + + self._outPort.reset() + self._outPort.close() + self._outPort = None def sendMessage(self, note, velocity, channel): if self._outPort is not None: |