Skip to content

Commit

Permalink
Merge pull request #7 from quaternionmedia/command8
Browse files Browse the repository at this point in the history
Command8
  • Loading branch information
mrharpo authored Jan 6, 2023
2 parents 9a82853 + 4c58aaa commit 31eca1a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions ludwig/boards/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .qu24 import Qu24
from .gld import Gld
from .xair import XAir
from .command8 import Command8
49 changes: 49 additions & 0 deletions ludwig/boards/command8.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 2 additions & 1 deletion ludwig/midi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Midi:
def __init__(
self,
*args,
hook,
port: str,
client_name: str = 'midi',
channel: uint4 = 0,
Expand All @@ -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
Expand Down

0 comments on commit 31eca1a

Please sign in to comment.