diff options
author | Eddy Pedroni <eddy@0xf7.com> | 2022-01-03 16:47:48 +0100 |
---|---|---|
committer | Eddy Pedroni <eddy@0xf7.com> | 2022-01-03 16:47:48 +0100 |
commit | 1423f2922650a8ba9104e595f87d66a83a244fb1 (patch) | |
tree | d46fc7dacf8a4a4815bd6d07af1e950d2bcb53a6 | |
parent | 794d645856da721e0bc7e97a788dcc60e4c87f0c (diff) |
Added LED feedback to playback rate and volume, same hacky implementation
-rw-r--r-- | midi_controller_launchpad_mini.py | 28 | ||||
-rw-r--r-- | midi_launchpad_mini_integrationtest.py | 54 |
2 files changed, 54 insertions, 28 deletions
diff --git a/midi_controller_launchpad_mini.py b/midi_controller_launchpad_mini.py index ec69509..2e83cc2 100644 --- a/midi_controller_launchpad_mini.py +++ b/midi_controller_launchpad_mini.py @@ -9,6 +9,14 @@ class MidiController: LED_OFF = 0 BUTTON_MATRIX = [[x for x in range(y * 16, y * 16 + 8)] for y in range(0,8)] # address as [row][col] + MIN_PLAYBACK_RATE = 0.5 + MAX_PLAYBACK_RATE = 1.2 + PLAYBACK_RATE_STEP = 0.1 + + MIN_PLAYBACK_VOLUME = 0.125 + MAX_PLAYBACK_VOLUME = 1.0 + PLAYBACK_VOLUME_STEP = 0.125 + def __init__(self, soloTool, midiWrapperOverride=None): self._soloTool = soloTool if midiWrapperOverride is not None: @@ -30,12 +38,12 @@ class MidiController: } for i in range(0, 8): - volume = round(0.125 + i * 0.125, 3) - self._handlers[i] = self._createSetPlaybackVolumeCallback(volume) + volume = round(MidiController.MIN_PLAYBACK_VOLUME + i * MidiController.PLAYBACK_VOLUME_STEP, 3) + self._handlers[i] = self._createSetPlaybackVolumeCallback(volume, [MidiController.LED_GREEN] * (i + 1) + [MidiController.LED_OFF] * (7 - i)) - for i in range(16, 24): - rate = round(0.5 + (i - 16) * 0.1, 1) - self._handlers[i] = self._createSetPlaybackRateCallback(rate) + for i, button in enumerate(range(16, 24)): + rate = round(MidiController.MIN_PLAYBACK_RATE + MidiController.PLAYBACK_RATE_STEP * i, 1) + self._handlers[button] = self._createSetPlaybackRateCallback(rate, [MidiController.LED_YELLOW] * (i + 1) + [MidiController.LED_OFF] * (7 - i)) def connect(self): self._midiWrapper.setCallback(self._callback) @@ -43,7 +51,7 @@ class MidiController: self._initialiseButtonLEDs() def _callback(self, msg): - if msg.velocity < 127: + if msg.type != "note_on" or msg.velocity < 127: return if msg.note in self._handlers: @@ -61,14 +69,18 @@ class MidiController: self._soloTool.stop() self._setButtonLED(7, 0, MidiController.LED_YELLOW) - def _createSetPlaybackRateCallback(self, rate): + def _createSetPlaybackRateCallback(self, rate, colours): def f(): self._soloTool.setPlaybackRate(rate) + for col, colour in enumerate(colours): + self._setButtonLED(1, col, colour) return f - def _createSetPlaybackVolumeCallback(self, volume): + def _createSetPlaybackVolumeCallback(self, volume, colours): def f(): self._soloTool.setPlaybackVolume(volume) + for col, colour in enumerate(colours): + self._setButtonLED(0, col, colour) return f def _setButtonLED(self, row, col, colour): diff --git a/midi_launchpad_mini_integrationtest.py b/midi_launchpad_mini_integrationtest.py index 5a28925..4400695 100644 --- a/midi_launchpad_mini_integrationtest.py +++ b/midi_launchpad_mini_integrationtest.py @@ -162,40 +162,54 @@ def test_previousAndNextAbButtons(uut, midiWrapperMock, soloTool, playerMock): checkLimit(abLimits[0][0], abLimits[0][1]) def test_playbackRateButtons(uut, midiWrapperMock, soloTool, playerMock): + ledYellow = 126 + ledOff = 0 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 + 16 : (0.5, [ledYellow] * 1 + [ledOff] * 7), + 17 : (0.6, [ledYellow] * 2 + [ledOff] * 6), + 18 : (0.7, [ledYellow] * 3 + [ledOff] * 5), + 19 : (0.8, [ledYellow] * 4 + [ledOff] * 4), + 20 : (0.9, [ledYellow] * 5 + [ledOff] * 3), + 21 : (1.0, [ledYellow] * 6 + [ledOff] * 2), + 22 : (1.1, [ledYellow] * 7 + [ledOff] * 1), + 23 : (1.2, [ledYellow] * 8) } uut.connect() assert playerMock.rate == 1.0 - for button in playbackRateOptions: + for t, button in enumerate(playbackRateOptions): + midiWrapperMock.sentMessages.clear() + midiWrapperMock.simulateInput(button) - assert playerMock.rate == playbackRateOptions[button] + assert playerMock.rate == playbackRateOptions[button][0] + + for i, colour in enumerate(playbackRateOptions[button][1]): + assert midiWrapperMock.sentMessages[i] == (16 + i, colour, 0) def test_playbackVolumeButtons(uut, midiWrapperMock, soloTool, playerMock): + ledGreen = 124 + ledOff = 0 playbackVolumeOptions = { - 0 : 0.125, - 1 : 0.250, - 2 : 0.375, - 3 : 0.500, - 4 : 0.625, - 5 : 0.750, - 6 : 0.875, - 7 : 1.000 + 0 : (0.125, [ledGreen] * 1 + [ledOff] * 7), + 1 : (0.250, [ledGreen] * 2 + [ledOff] * 6), + 2 : (0.375, [ledGreen] * 3 + [ledOff] * 5), + 3 : (0.500, [ledGreen] * 4 + [ledOff] * 4), + 4 : (0.625, [ledGreen] * 5 + [ledOff] * 3), + 5 : (0.750, [ledGreen] * 6 + [ledOff] * 2), + 6 : (0.875, [ledGreen] * 7 + [ledOff] * 1), + 7 : (1.000, [ledGreen] * 8) } uut.connect() assert playerMock.volume == 1.0 - for button in playbackVolumeOptions: + for t, button in enumerate(playbackVolumeOptions): + midiWrapperMock.sentMessages.clear() + midiWrapperMock.simulateInput(button) - assert playerMock.volume == playbackVolumeOptions[button] + assert playerMock.volume == playbackVolumeOptions[button][0] + + for i, colour in enumerate(playbackVolumeOptions[button][1]): + assert midiWrapperMock.sentMessages[i] == (i, colour, 0) def test_unassignedButton(uut, midiWrapperMock): unassignedButton = 48 |