aboutsummaryrefslogtreecommitdiffstats
path: root/midi_controller_launchpad_mini.py
diff options
context:
space:
mode:
authorEddy Pedroni <eddy@0xf7.com>2022-01-02 09:34:37 +0100
committerEddy Pedroni <eddy@0xf7.com>2022-01-02 14:39:24 +0100
commit430466b0e3a4dd762d8c4a44403437691d9d6118 (patch)
tree6666fa004d6cc48f9fa52af10c4fdd30744e59ba /midi_controller_launchpad_mini.py
parentab49963447a3f6ba16fe0a13b3b4761b54b556f4 (diff)
Added basic LED support for launchpad, removed old MIDI code
Diffstat (limited to 'midi_controller_launchpad_mini.py')
-rw-r--r--midi_controller_launchpad_mini.py45
1 files changed, 44 insertions, 1 deletions
diff --git a/midi_controller_launchpad_mini.py b/midi_controller_launchpad_mini.py
index bc2ed8a..1f430c2 100644
--- a/midi_controller_launchpad_mini.py
+++ b/midi_controller_launchpad_mini.py
@@ -2,6 +2,12 @@ from midi_wrapper_mido import MidiWrapper
class MidiController:
DEVICE_NAME = "Launchpad Mini MIDI 1"
+ LIGHT_CONTROL_CHANNEL = 0
+ LED_GREEN = 124
+ LED_YELLOW = 126
+ LED_RED = 3
+ 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]
def __init__(self, soloTool, midiWrapperOverride=None):
self._soloTool = soloTool
@@ -10,6 +16,9 @@ class MidiController:
else:
self._midiWrapper = MidiWrapper()
+ self._registerHandlers()
+
+ def _registerHandlers(self):
self._handlers = {
96 : self._soloTool.stop,
112 : self._playPause,
@@ -29,8 +38,9 @@ class MidiController:
self._handlers[i] = self._createSetPlaybackRateCallback(rate)
def connect(self):
- self._midiWrapper.connect(MidiController.DEVICE_NAME)
self._midiWrapper.setCallback(self._callback)
+ self._midiWrapper.connect(MidiController.DEVICE_NAME)
+ self._initialiseButtonLEDs()
def _callback(self, msg):
if msg.velocity < 127:
@@ -54,3 +64,36 @@ class MidiController:
def f():
self._soloTool.setPlaybackVolume(volume)
return f
+
+ def _setButtonLED(self, row, col, colour):
+ self._midiWrapper.sendMessage(MidiController.BUTTON_MATRIX[row][col], colour, MidiController.LIGHT_CONTROL_CHANNEL)
+
+ def _allLEDsOff(self):
+ for row in range(0, 8):
+ for col in range(0, 8):
+ self._setButtonLED(row, col, MidiController.LED_OFF)
+
+ def _initialiseButtonLEDs(self):
+ self._allLEDsOff()
+
+ # volume buttons
+ for col in range(0, 8):
+ self._setButtonLED(0, col, MidiController.LED_GREEN)
+
+ # playback rate buttons
+ for col in range(0, 6):
+ self._setButtonLED(1, col, MidiController.LED_YELLOW)
+
+ # playback control
+ self._setButtonLED(6, 0, MidiController.LED_RED)
+ self._setButtonLED(7, 0, MidiController.LED_GREEN)
+
+ # AB control
+ self._setButtonLED(6, 5, MidiController.LED_YELLOW)
+ self._setButtonLED(6, 6, MidiController.LED_RED)
+ self._setButtonLED(6, 7, MidiController.LED_GREEN)
+
+ # Song control
+ self._setButtonLED(7, 6, MidiController.LED_RED)
+ self._setButtonLED(7, 7, MidiController.LED_GREEN)
+