From 27ba3bc396a2da4ffcc39e3e36da5f37df8f628e Mon Sep 17 00:00:00 2001 From: Eddy Pedroni Date: Sat, 1 Jan 2022 20:54:15 +0100 Subject: Added playback rate functionality to launchpad --- midi_controller_launchpad_mini.py | 11 ++++++++++- midi_launchpad_mini_integrationtest.py | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/midi_controller_launchpad_mini.py b/midi_controller_launchpad_mini.py index adf18d5..960dd7d 100644 --- a/midi_controller_launchpad_mini.py +++ b/midi_controller_launchpad_mini.py @@ -11,14 +11,18 @@ class MidiController: self._midiWrapper = MidiWrapper() self._handlers = { + 96 : self._soloTool.stop, 112 : self._playPause, - 96 : self._soloTool.stop, 101 : self._soloTool.jumpToA, 102 : self._soloTool.previousStoredAbLimits, 103 : self._soloTool.nextStoredAbLimits, 118 : self._soloTool.previousSong, 119 : self._soloTool.nextSong } + + for i in range(16, 24): + rate = round(0.5 + (i - 16) * 0.1, 1) + self._handlers[i] = self._createSetPlaybackRateCallback(rate) def connect(self): self._midiWrapper.connect(MidiController.DEVICE_NAME) @@ -37,3 +41,8 @@ class MidiController: else: self._soloTool.play() + def _createSetPlaybackRateCallback(self, rate): + def f(): + self._soloTool.setPlaybackRate(rate) + return f + diff --git a/midi_launchpad_mini_integrationtest.py b/midi_launchpad_mini_integrationtest.py index 8779503..ee39182 100644 --- a/midi_launchpad_mini_integrationtest.py +++ b/midi_launchpad_mini_integrationtest.py @@ -149,6 +149,24 @@ def test_previousAndNextAbButtons(uut, midiWrapperMock, soloTool, playerMock): midiWrapperMock.simulateInput(previousLimitButton) checkLimit(abLimits[0][0], abLimits[0][1]) +def test_playbackRateButtons(uut, midiWrapperMock, soloTool, playerMock): + playbackRateOptions = { + 16 : 0.5, + 17 : 0.6, + 18 : 0.7, + 19 : 0.8, + 20 : 0.9, + 21 : 1.0, + 22 : 1.1, + 23 : 1.2 + } + uut.connect() + assert playerMock.rate == 1.0 + + for button in playbackRateOptions: + midiWrapperMock.simulateInput(button) + assert playerMock.rate == playbackRateOptions[button] + def test_unassignedButton(uut, midiWrapperMock): unassignedButton = 48 uut.connect() @@ -156,3 +174,4 @@ def test_unassignedButton(uut, midiWrapperMock): # expect no crash midiWrapperMock.simulateInput(unassignedButton) # XXX would be better to assert that nothing changed in the solo tool + -- cgit v1.2.3