diff --git a/ludwig/boards/__init__.py b/ludwig/boards/__init__.py index 42e2a95..654a304 100644 --- a/ludwig/boards/__init__.py +++ b/ludwig/boards/__init__.py @@ -1,3 +1,4 @@ from .qu24 import Qu24 from .gld import Gld from .xair import XAir +from .command8 import Command8 diff --git a/ludwig/boards/command8.py b/ludwig/boards/command8.py new file mode 100644 index 0000000..2e4b588 --- /dev/null +++ b/ludwig/boards/command8.py @@ -0,0 +1,49 @@ +from ludwig import mixer, Mixer, Midi +from rtmidi.midiconstants import NOTE_ON, CONTROL_CHANGE +from ludwig.types import uint1, uint2, uint3, uint4, uint5, uint7, uint8 + + +class Command8(Midi, Mixer): + """Focusrite Command8 mixing station""" + + @mixer + def fader(self, channel: uint4, volume: uint7): + """Fade the channel""" + self.send([CONTROL_CHANGE | channel, 7, volume]) + + @mixer + def pan(self, channel: uint4, pan: uint7): + """Pan the channel""" + self.send([CONTROL_CHANGE | channel, 10, pan]) + + @mixer + def mute(self, channel: uint4): + """Mute the channel""" + self.send([CONTROL_CHANGE | channel, 14, 127]) + + @mixer + def unmute(self, channel: uint4): + """Unmute the channel""" + self.send([CONTROL_CHANGE | channel, 14, 0]) + + def __call__(self, event, data=None): + message, deltatime = event + print('Command8!', message, deltatime) + if message[0] & 0xF0 == CONTROL_CHANGE: + print( + f'found control change message {message[0]} on channel {message[0] & 0x0F}' + ) + if message[1] == 7: + print(f'fader channel {message[0] & 0x0F } at {message[2]}') + self.hook.fader(channel=message[0] & 0x0F, volume=message[2]) + elif message[1] == 10: + print(f'pan channel {message[0] & 0x0F } at {message[2]}') + self.hook.pan(channel=message[0] & 0x0F, pan=message[2]) + elif message[1] == 14: + print( + f'{"un" if message[2] == 0 else ""}mute channel {message[0] & 0x0F }' + ) + if message[2]: + self.hook.mute(channel=message[0] & 0x0F) + else: + self.hook.unmute(channel=message[0] & 0x0F) diff --git a/ludwig/midi.py b/ludwig/midi.py index 941df32..62ecf2e 100644 --- a/ludwig/midi.py +++ b/ludwig/midi.py @@ -8,6 +8,7 @@ class Midi: def __init__( self, *args, + hook, port: str, client_name: str = 'midi', channel: uint4 = 0, @@ -24,7 +25,7 @@ def __init__( send(message): send a MIDI message of bytes (sent as integers) nrpm(message): send a MIDI NRPN (Non-Registered Parameter Number) """ - + self.hook = hook self.port = port self.client_name = client_name self.channel = channel