Skip to content

Commit

Permalink
addr_type binding returns non-struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Casey Tucker committed Mar 9, 2024
1 parent f4554bc commit 077fa89
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ doc/xml
doc/_build
site-packages
pyvenv.cfg
bridge/share
3 changes: 1 addition & 2 deletions bindings/capmix.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def __init__(self):
@staticmethod
def setup_returns(lib):
lib.capmix_type.restype = POINTER(TYPE)
lib.capmix_addr_type = TYPE
lib.capmix_get.restype = EVENT
lib.capmix_put.restype = EVENT
lib.capmix_memory_get_unpacked = UNPACKED
Expand Down Expand Up @@ -112,6 +111,6 @@ def __str__(self):

@classmethod
def parse(cls, ty, str):
ret = Value(ty, capmix.parse_type(ty, str.encode()))
ret = Value(ty, capmix.parse_type(ty, str))
return ret

89 changes: 57 additions & 32 deletions bridge/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<< >> [] |> () R + R + R + R + R + R + R + R +
Ch: 16 1 2 3 4 5 6 7 8
CC 85 86 80 10 80 10 80 10 80 10 80 10 80 10 80 10 80 10
CC 87 88 89 90 81 81 81 81 81 81 81 81
CC 111 112 113 114 115 82 7 82 7 82 7 82 7 82 7 82 7 82 7 82 7
Expand All @@ -54,10 +55,9 @@
def print_monitor_mutes():
global logged
size = os.get_terminal_size()
print("\033[r",end='')
#print("\033[r",end='')

#print("\0337",end='')
print("\033[H\033[2K ", end='')
print("\033[?25l\033[H\033[2K ", end='')
for ch in range(0, 16):
s = '/' if stereo[ch+1] else ' '
print("%2d %s " % (ch+1, s), end='')
Expand All @@ -82,7 +82,7 @@ def print_monitor_mutes():
msg = "----"
color = "\033[1;33m"
else:
msg = "MU "
msg = "MUTE"
color = "\033[4;7;2;31m"
print("%s%3s\033[0m " % (color,msg), end='')
print()
Expand All @@ -94,7 +94,7 @@ def print_monitor_mutes():
print("\033[2K")
#print("\0338", end='')

print("\033[10;%dr\033[%d;1f" % (size.lines, size.lines-1))
print("\033[10;%dr\033[%d;1f\033[?25h" % (size.lines, size.lines-1))
logged = False

def log(*msg):
Expand Down Expand Up @@ -128,6 +128,14 @@ def control_listener(event):
def capmix_send(param, value):
capmix.put(capmix.parse_addr(param), value)

cache = {}
def capmix_value(param):
global cache
addr = capmix.parse_addr(param)
val = cache[addr]
ty = capmix.addr_type(addr)
return Value(ty, val.unpacked)

def handle_nrpn(msb, lsb, value):
param = ""
if msb >= 0 and msb <= 3:
Expand Down Expand Up @@ -174,7 +182,6 @@ def listener(self, event):
k = super().listener(event)
if k == 'arm':
self.do_arm(event.value)
log(repr(self))
elif k == 'fader':
self.do_fader(event.value)
elif k == 'knob':
Expand All @@ -184,15 +191,19 @@ def listener(self, event):
def mixer_channel(self):
return 1 + (self.channel * 2)

def do_arm(self, val):
def do_arm(self, down):
ch = self.mixer_channel()
if val == 0:
capmix_send('input_monitor.a.channel.%d.mute' % (ch), 1)
capmix_send('input_monitor.c.channel.%d.mute' % (ch), 1)
capmix_send('input_monitor.d.channel.%d.mute' % (ch), 0)
else:
self.do_fader(self.fader)
if down == 0:
return

val = capmix_value('input_monitor.d.channel.%d.mute' % (ch))
if val.unpacked.discrete == 0:
#self.do_fader(self.fader)
capmix_send('input_monitor.d.channel.%d.mute' % (ch), 1)
else:
#capmix_send('input_monitor.a.channel.%d.mute' % (ch), 1)
#capmix_send('input_monitor.c.channel.%d.mute' % (ch), 1)
capmix_send('input_monitor.d.channel.%d.mute' % (ch), 0)

def do_fader(self, val):
ch = self.mixer_channel()
Expand Down Expand Up @@ -227,10 +238,10 @@ def do_knob(self, val):

capmix_send('input_monitor.a.channel.%d.pan' % (ch) , pan_l.unpacked)
capmix_send('input_monitor.a.channel.%d.pan' % (ch+1), pan_r.unpacked)
#capmix_send('input_monitor.c.channel.%d.pan' % (ch) , pan_l)
#capmix_send('input_monitor.c.channel.%d.pan' % (ch+1), pan_r)
#capmix_send('input_monitor.d.channel.%d.pan' % (ch) , pan_l)
#capmix_send('input_monitor.d.channel.%d.pan' % (ch+1), pan_r)
capmix_send('input_monitor.c.channel.%d.pan' % (ch) , pan_l.unpacked)
capmix_send('input_monitor.c.channel.%d.pan' % (ch+1), pan_r.unpacked)
capmix_send('input_monitor.d.channel.%d.pan' % (ch) , pan_l.unpacked)
capmix_send('input_monitor.d.channel.%d.pan' % (ch+1), pan_r.unpacked)
pans[ch] = pan_l
pans[ch+1] = pan_r

Expand Down Expand Up @@ -289,24 +300,34 @@ def ping(self):
self.client.event_output(event, port=self.port)
self.client.drain_output()

def hello(self):
for p in range(80,83):
def send_cc(self, ch, cc, val):
self.client.event_output(ControlChangeEvent(channel=ch, param=cc, value=val), port=self.port)
self.client.drain_output()

def hello(self, delay=0.016):
def blink(ch, cc, val):
self.send_cc(ch, cc, val)
time.sleep(delay)

def chase(val):
for i in range(0,8):
event = ControlChangeEvent(channel=i, param=p, value=127)
self.client.event_output(event, port=self.port)
self.client.drain_output()
time.sleep(0.032)
blink(i, 80, val)
blink(15, 87, val)

for p in range(80,83):
for i in range(0,8):
self.client.event_output(ControlChangeEvent(channel=i, param=p, value=0))
self.client.drain_output()
time.sleep(0.032)
blink(i, 81, val)

for p in [111, 112, 113, 114, 115]:
blink(15, p, val)
for i in range(0,8):
blink(i, 82, val)

chase(127)
chase(0)

def listen(self):
event = self.client.event_input(timeout=0.01)
if event:
#control_listener(event)
self.listener(event)

def listener(self, event):
Expand Down Expand Up @@ -336,15 +357,17 @@ def send_nrpn(self, ch, msb, lsb, val):

def sync(self):
global queue
#for msg in queue:
# self.send_nrpn(15, msg[0], msg[1], msg[2])
for msg in queue:
self.send_cc(msg[0], msg[1], msg[2])
queue = []

class Capture:
@classmethod
def listener(cls, event):
global queue
global queue, cache
value = event.value()
cache[event.addr] = value

addr = capmix.format_addr(event.addr)
if 'input_monitor.' in addr:
dirty = True
Expand All @@ -353,7 +376,9 @@ def listener(cls, event):
mon = monitors[(event.addr & 0xf000) >> 12]
mute = value.unpacked.discrete
mutes[ch][mon] = mute
queue += [[ord(mon) - ord('a'), ch, 0 if mute == 0 else 127]]
#queue += [[ord(mon) - ord('a'), ch, 0 if mute == 0 else 127]]
if mon == 'd':
queue += [[int((ch-1)/2), 82, 0 if mute == 0 else 127]]
elif '.stereo' in addr:
ch = ((event.addr & 0x0f00) >> 8) + 1
stereo[ch] = value.unpacked.discrete
Expand Down

0 comments on commit 077fa89

Please sign in to comment.