aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2022-01-03 17:01:57 +0100
committerEddy Pedroni <eddy@0xf7.com>2022-01-03 17:01:57 +0100
commitfedc8c0c4c301024ce8c5ef997e1ef9e6a4a413e (patch)
tree108983b5d4aac4b4d55d19f551dd1c53b739759a
parent1423f2922650a8ba9104e595f87d66a83a244fb1 (diff)
Refactored lighting code to facilitate future implementation
-rw-r--r--midi_controller_launchpad_mini.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/midi_controller_launchpad_mini.py b/midi_controller_launchpad_mini.py
index 2e83cc2..3bcef13 100644
--- a/midi_controller_launchpad_mini.py
+++ b/midi_controller_launchpad_mini.py
@@ -26,6 +26,7 @@ class MidiController:
self._registerHandlers()
+
def _registerHandlers(self):
self._handlers = {
96 : self._stop,
@@ -39,11 +40,11 @@ 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, [MidiController.LED_GREEN] * (i + 1) + [MidiController.LED_OFF] * (7 - i))
+ self._handlers[i] = self._createSetPlaybackVolumeCallback(volume, i)
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))
+ self._handlers[button] = self._createSetPlaybackRateCallback(rate, i)
def connect(self):
self._midiWrapper.setCallback(self._callback)
@@ -69,23 +70,26 @@ class MidiController:
self._soloTool.stop()
self._setButtonLED(7, 0, MidiController.LED_YELLOW)
- def _createSetPlaybackRateCallback(self, rate, colours):
+ def _createSetPlaybackRateCallback(self, rate, column):
def f():
self._soloTool.setPlaybackRate(rate)
- for col, colour in enumerate(colours):
- self._setButtonLED(1, col, colour)
+ self._lightRowUntilColumn(1, column, MidiController.LED_YELLOW)
return f
- def _createSetPlaybackVolumeCallback(self, volume, colours):
+ def _createSetPlaybackVolumeCallback(self, volume, column):
def f():
self._soloTool.setPlaybackVolume(volume)
- for col, colour in enumerate(colours):
- self._setButtonLED(0, col, colour)
+ 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)
+ for col in range(0, 8):
+ self._setButtonLED(row, col, colours[col])
+
def _allLEDsOff(self):
for row in range(0, 8):
for col in range(0, 8):