from midi_wrapper_mido import MidiWrapper class MidiController: DEVICE_NAME = "Launchpad Mini MIDI 1" def __init__(self, soloTool, midiWrapperOverride=None): self._soloTool = soloTool if midiWrapperOverride is not None: self._midiWrapper = midiWrapperOverride else: self._midiWrapper = MidiWrapper() self._handlers = { 112 : self._playPause, 96 : self._soloTool.stop, 101 : self._soloTool.jumpToA, 118 : self._soloTool.previousSong, 119 : self._soloTool.nextSong } def connect(self): self._midiWrapper.connect(MidiController.DEVICE_NAME) self._midiWrapper.setCallback(self._callback) def _callback(self, msg): if msg.velocity < 127: return if msg.note in self._handlers: handler = self._handlers[msg.note]() def _playPause(self): if self._soloTool.isPlaying(): self._soloTool.pause() else: self._soloTool.play()