summaryrefslogtreecommitdiff
path: root/console.py
diff options
context:
space:
mode:
Diffstat (limited to 'console.py')
-rw-r--r--console.py175
1 files changed, 137 insertions, 38 deletions
diff --git a/console.py b/console.py
index a06c5ee..c7f1d2c 100644
--- a/console.py
+++ b/console.py
@@ -26,6 +26,7 @@ import time
import threading
from pathlib import Path
+import osc
import strips
import fw_1884_buttons
@@ -38,13 +39,17 @@ from hinawa_utils.tscm.tscm_console_unit import TscmConsoleUnit # noqa: E402
bits32 = '{:032b}'.format
-current_bank = 1
-more_banks_up = False
-more_banks_down = False
+class ConsoleStatus():
+ def __init__(self, quadlets):
+ self.quadlets = quadlets
-def check_bitR2L(data, bit):
- return bool(data & (0b1 << bit))
+ def field(self, quadlet, first_bit=0, last_bit=32):
+ bits = self.quadlets[quadlet]
+
+ # reverse the bit order before slicing so the index '0' is the LSB
+ # and reverse back before converting to int
+ return int(bits32(bits)[::-1][first_bit:last_bit][::-1], 2)
class RunningStatusThread():
@@ -53,13 +58,14 @@ class RunningStatusThread():
:type interval: int
:param interval: Check interval, in seconds
"""
+ self.console = console
self.interval = interval
+ self.callbacks = set()
+ self.last_status = []
- thread = threading.Thread(target=self.run, args=(console))
+ thread = threading.Thread(target=self.run)
thread.daemon = True # Daemonize thread
thread.start() # Start the execution
- self.callbacks = set()
- self.last_status = []
def add_callback(self, obj):
self.callbacks.add(obj)
@@ -67,36 +73,14 @@ class RunningStatusThread():
def remove_callback(self, obj):
self.callbacks.remove(obj)
- def fetch_status_values(self, quadlets=None, first_bit=0, last_bit=32):
- if quadlets is None:
- quadlets = [i for i in range(0, 16)]
-
- def getvalue(bits):
- # reverse the bit order before slicing so the index '0' is the LSB
- # and reverse back before converting to int
- return int(bits32(bits)[::-1][first_bit:last_bit][::-1], 2)
-
- values = [getvalue(self.last_status[q]) for q in quadlets]
-
- if len(values) == 1:
- return values[0]
-
- return values
-
- def run(self, console):
+ def run(self):
""" Method that runs forever """
while True:
-
- if not self.callbacks:
- continue
-
- try:
- self.last_status = console.unit.get_status()
- except Exception:
- continue # we should emit warning or error here!
-
- for callback in self.callbacks:
- callback.call(self.fetch_status_values(**callback.args))
+ for obj in self.callbacks:
+ value = self.console.status.field(obj.status_quadlet,
+ **obj.status_bits,
+ )
+ obj.status_callback(value)
time.sleep(self.interval)
@@ -111,19 +95,29 @@ class Console():
exit()
self.state = {}
- self.strips = strips.init_strips(self.unit)
+ self.current_bank = 1
+ self.more_banks_up = False
+ self.more_banks_down = False
+ self.strips = strips.init_strips(self)
self.buttons = fw_1884_buttons.init_buttons(self)
self.unit.connect('control', self.handle_control)
status_thread = RunningStatusThread(self) # noqa F841
+ @property
+ def status(self):
+ try:
+ return ConsoleStatus(self.unit.get_status())
+ except Exception as e:
+ raise e
+
def handle_bit_flags(self, index, before, after):
changed = before ^ after
for bit in [i for i, b in enumerate(bits32(changed)) if int(b)]:
- high = check_bitR2L(after, bit)
+ high = bool(after & (0b1 << bit))
button = self.buttons[index][int(bit)]
if button is None:
print('unhandled control bit {}:{}'.format(index, bit))
@@ -146,6 +140,106 @@ class Console():
self.handle_encoder(index, before, after)
return
+ def strip_fader_handler(self, addr, args, ssid, pos):
+ print('fader_handler', addr, ssid, pos)
+ strip = self.strips(int(ssid))
+ if strip.name == ' ':
+ return
+ pos = pos * 1023
+ strip.fader.position = pos
+
+ def master_fader_handler(self, addr, args, pos):
+ print('master_fader_handler', pos)
+ self.strips[0].fader.position(1023 * pos)
+
+ def default_handler(self, addr, *args):
+ print(addr, args)
+
+ def strip_mute_handler(self, addr, args, ssid, state):
+ strip = self.strips(int(ssid))
+ print('mute_handler', strip, state)
+ if strip.name == ' ':
+ return
+ if state:
+ strip.mute = True
+ else:
+ strip.mute = False
+
+ def strip_solo_handler(self, addr, args, ssid, state):
+ strip = self.strips(int(ssid))
+ print('solo_handler', strip, state)
+ if strip.name == ' ':
+ return
+ if state:
+ strip.solo = True
+ else:
+ strip.solo = False
+
+ def strip_recenable_handler(self, addr, args, ssid, state):
+ strip = self.strips(int(ssid))
+ print('recenable_handler', strip, state)
+ if strip.name == ' ':
+ return
+ if state:
+ strip.recenable = True
+ else:
+ strip.recenable = False
+
+ def loop_toggle_handler(self, addr, state):
+ print(addr, state)
+ if state:
+ self.state['LOOP'] = 1
+ self.unit.leds.loop.turn_on()
+ else:
+ self.state['LOOP'] = 0
+ self.unit.leds.loop.turn_off()
+
+ def transport_stop_handler(self, addr, args, state):
+ print(addr, args, state)
+ if state:
+ self.unit.leds.stop.turn_on()
+ else:
+ self.unit.leds.stop.turn_off()
+
+ def transport_play_handler(self, addr, args, state):
+ print(addr, args, state)
+ if state:
+ self.unit.leds.play.turn_on()
+ else:
+ self.unit.leds.play.turn_off()
+
+ def ffwd_handler(self, addr, args, state):
+ if state:
+ self.unit.leds.f_fwd.turn_on()
+ else:
+ self.unit.leds.f_fwd.turn_off()
+
+ def rewind_handler(self, addr, args, state):
+ if state:
+ self.unit.leds.rew.turn_on()
+ else:
+ self.unit.leds.rew.turn_off()
+
+ def rec_enable_toggle_handler(self, addr, args, state):
+ if state:
+ self.unit.leds.rec.turn_on()
+ else:
+ self.unit.leds.rec.turn_off()
+
+ def pan_stereo_position_handler(self, addr, pos, pan):
+ self.strips[pos].recv_pan(pan)
+
+ def strip_name_handler(self, addr, ssid, name):
+ self.strips[int(ssid)].name = name
+
+ def bank_up_handler(self, addr, more_up):
+ print(addr, more_up)
+ self.more_banks_up = bool(more_up)
+
+ def bank_down_handler(self, addr, more_down):
+ print(addr, more_down)
+ self.more_banks_down = bool(more_down)
+
def _check_hexadecimal(literal):
if literal.find('0x') == 0:
@@ -200,3 +294,8 @@ if __name__ == "__main__":
args = parser.parse_args()
console = Console(args.card)
+ osc.init_client(args.ip, args.port)
+ osc.init_server(args.listen_ip, args.listen_port, console)
+
+ print("Serving on {}".format(osc.server.server_address))
+ osc.server.serve_forever()