Skip to content

Commit

Permalink
refactor control queueing
Browse files Browse the repository at this point in the history
  • Loading branch information
Casey Tucker committed Mar 14, 2024
1 parent 57cbc6b commit f6d7ab6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 35 deletions.
1 change: 1 addition & 0 deletions bridge/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def check_connections(client, port):
log("STUDIO-CAPTURE connected")
capture.ok = capture.connect()
view.dim(False)
control.hello()

control.ping()
first_attempt = False
Expand Down
1 change: 1 addition & 0 deletions bridge/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def listener(cls, event):
mutes[ch][mon] = mute
#self.model.queue.put([ord(mon) - ord('a'), ch, 0 if mute == 0 else 127])
if mon == 'd':
# TODO may not be needed
self.model.queue.put([int((ch-1)/2), 82, 0 if mute == 0 else 127])
elif '.stereo' in addr:
ch = ((event.addr & 0x0f00) >> 8) + 1
Expand Down
54 changes: 23 additions & 31 deletions bridge/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def listener(self, event):
def __repr__(self):
return repr(self.__dict__)

def send(self, name, val):
cc = self.cc_map[name]
self.model.queue.put([self.channel, cc, val])

class ControlChannel(ControlSection):
cc_map = {
'fader': 7,
Expand Down Expand Up @@ -132,6 +136,7 @@ def do_knob(self, val):


class ControlTransport(ControlSection):
channel = 15
cc_map = {
'rew': 111,
'ffw': 112,
Expand Down Expand Up @@ -163,7 +168,7 @@ def __init__(self):
self.looping = False

def ready(self):
self.model.queue.put([15, self.cc_map[self.state], 127])
self.send(self.state, 127)

def listener(self, event):
k = super().listener(event)
Expand All @@ -175,10 +180,7 @@ def listener(self, event):
log(self.state)

for state in ['ffw','rew','play','stop']:
cc = self.cc_map[state]
v = 127 if self.state == state else 0
self.model.queue.put([15, cc, v])

self.send(state, 127 if self.state == state else 0)

if k == 'rec':
if event.value == 0: return
Expand All @@ -191,17 +193,8 @@ def listener(self, event):
if k == 'stop' and prev_state == 'play':
self.recording = False

cc = self.cc_map['rec']
if self.recording:
self.model.queue.put([15, cc, 127])
else:
self.model.queue.put([15, cc, 0])

cc = self.cc_map['cycle']
if self.looping:
self.model.queue.put([15, cc, 127])
else:
self.model.queue.put([15, cc, 0])
self.send('rec' , 127 if self.recording else 0)
self.send('cycle', 127 if self.looping else 0)

if self.left > 0 and self.right > 0 and k == 'stop' and prev_state == 'stop':
os.system("reset")
Expand All @@ -224,6 +217,7 @@ def listener(self, event):
os.system('tmux next-window')

if k == 'set':
self.dim()
self.view.dim(True, force=True)
log(repr(self))

Expand All @@ -244,6 +238,7 @@ def model(self, model):
c.model = model
self.transport.model = model
self._model = model
self.transport.dim = self.dim

@property
def view(self):
Expand Down Expand Up @@ -287,6 +282,15 @@ 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 send(self, name, val):
if name in self.transport.cc_map:
self.transport.send(name, val)

def dim(self):
self.send('stop', 0)
self.send('cycle', 0)
self.channels[0].send('mute', 0)

def hello(self, delay=0.01):
def blink(ch, cc, val):
self.send_cc(ch, cc, val)
Expand Down Expand Up @@ -330,18 +334,6 @@ def listener(self, event):
self.channels[event.channel].stop_held = (self.transport.stop > 0)
self.channels[event.channel].listener(event)

def send_nrpn(self, ch, msb, lsb, val):
event1 = ControlChangeEvent(channel=15, param=99, value=msb)
event2 = ControlChangeEvent(channel=15, param=98, value=lsb)
event3 = ControlChangeEvent(channel=15, param=6, value=val)

self.client.event_output(event1, port=self.port)
self.client.event_output(event2, port=self.port)
self.client.event_output(event3, port=self.port)

log(repr(event1), repr(event2), repr(event3))
self.client.drain_output()

def sync_mutes(self):
for i, chan in enumerate(self.channels):
ch = 2 * i + 1
Expand All @@ -358,11 +350,11 @@ def sync_mutes(self):
chan.armed = mutes[ch]['d']

if s != chan.soloed:
self.model.queue.put([i, chan.cc_map['solo'], 127 if chan.soloed else 0])
chan.send('solo', 127 if chan.soloed else 0)
if m != chan.muted:
self.model.queue.put([i, chan.cc_map['mute'], 127 if chan.muted else 0])
chan.send('mute', 127 if chan.muted else 0)
if r != chan.armed:
self.model.queue.put([i, chan.cc_map['arm'], 127 if chan.armed else 0])
chan.send('arm' , 127 if chan.armed else 0)

def sync(self):
self.sync_mutes()
Expand Down
4 changes: 0 additions & 4 deletions bridge/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,10 @@ def dim(self, dark=True, force=False):
if dark:
if not self.dimmed:
self.backlight(0)
self.model.queue.put([15, 113, 0])
self.model.queue.put([0, 82, 0])
self.model.queue.put([0, 87, 0])
self.model.reset()
else:
if self.dimmed:
self.backlight()
self.model.queue.put([15, 113, 127])
self.dimmed = dark

def pan_graphic(self, pan, width=4):
Expand Down

0 comments on commit f6d7ab6

Please sign in to comment.