diff options
Diffstat (limited to 'midi_controller_launchpad_mini.py')
-rw-r--r-- | midi_controller_launchpad_mini.py | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/midi_controller_launchpad_mini.py b/midi_controller_launchpad_mini.py index cb3bc37..10013b5 100644 --- a/midi_controller_launchpad_mini.py +++ b/midi_controller_launchpad_mini.py @@ -13,9 +13,9 @@ class MidiController: 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 + MIN_PLAYBACK_VOLUME = 0.5 + MAX_PLAYBACK_VOLUME = 1.2 + PLAYBACK_VOLUME_STEP = 0.1 def __init__(self, soloTool, midiWrapperOverride=None): self._soloTool = soloTool @@ -26,6 +26,8 @@ class MidiController: self._registerHandlers() self._soloTool.registerPlayingStateCallback(self._updatePlayPauseButton) + self._soloTool.registerPlaybackVolumeCallback(self._updateVolumeRow) + self._soloTool.registerPlaybackRateCallback(self._updateRateRow) def _registerHandlers(self): self._handlers = { @@ -39,12 +41,12 @@ class MidiController: } for i in range(0, 8): - volume = round(MidiController.MIN_PLAYBACK_VOLUME + i * MidiController.PLAYBACK_VOLUME_STEP, 3) - self._handlers[i] = self._createSetPlaybackVolumeCallback(volume, i) + volume = round(MidiController.MIN_PLAYBACK_VOLUME + MidiController.PLAYBACK_VOLUME_STEP * i, 1) + self._handlers[i] = self._createSetPlaybackVolumeCallback(volume) 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, i) + self._handlers[button] = self._createSetPlaybackRateCallback(rate) def connect(self): self._midiWrapper.setCallback(self._callback) @@ -73,23 +75,35 @@ class MidiController: else: self._setButtonLED(7, 0, MidiController.LED_YELLOW) - def _createSetPlaybackRateCallback(self, rate, column): + def _updateVolumeRow(self): + volume = self._soloTool.getPlaybackVolume() + t1 = int(round(volume / MidiController.PLAYBACK_VOLUME_STEP, 1)) + t2 = int(round(MidiController.MIN_PLAYBACK_VOLUME / MidiController.PLAYBACK_VOLUME_STEP, 1)) + lastColumnLit = t1 - t2 + 1 + self._lightRowUntilColumn(0, lastColumnLit, MidiController.LED_GREEN) + + def _updateRateRow(self): + rate = self._soloTool.getPlaybackRate() + t1 = int(round(rate / MidiController.PLAYBACK_RATE_STEP, 1)) + t2 = int(round(MidiController.MIN_PLAYBACK_RATE / MidiController.PLAYBACK_RATE_STEP, 1)) + lastColumnLit = t1 - t2 + 1 + self._lightRowUntilColumn(1, lastColumnLit, MidiController.LED_YELLOW) + + def _createSetPlaybackRateCallback(self, rate): def f(): self._soloTool.setPlaybackRate(rate) - self._lightRowUntilColumn(1, column, MidiController.LED_YELLOW) return f - def _createSetPlaybackVolumeCallback(self, volume, column): + def _createSetPlaybackVolumeCallback(self, volume): def f(): self._soloTool.setPlaybackVolume(volume) - self._lightRowUntilColumn(0, column, MidiController.LED_GREEN) return f def _setButtonLED(self, row, col, colour): self._midiWrapper.sendMessage(MidiController.BUTTON_MATRIX[row][col], colour, MidiController.LIGHT_CONTROL_CHANNEL) def _lightRowUntilColumn(self, row, column, litColour): - colours = [litColour] * (column + 1) + [MidiController.LED_OFF] * (7 - column) + colours = [litColour] * column + [MidiController.LED_OFF] * (8 - column) for col in range(0, 8): self._setButtonLED(row, col, colours[col]) @@ -102,16 +116,14 @@ class MidiController: self._allLEDsOff() # volume buttons - for col in range(0, 8): - self._setButtonLED(0, col, MidiController.LED_GREEN) + self._updateVolumeRow() # playback rate buttons - for col in range(0, 6): - self._setButtonLED(1, col, MidiController.LED_YELLOW) + self._updateRateRow() # playback control self._setButtonLED(6, 0, MidiController.LED_RED) - self._setButtonLED(7, 0, MidiController.LED_YELLOW) + self._updatePlayPauseButton() # AB control self._setButtonLED(6, 5, MidiController.LED_YELLOW) |