From 2d3f2be7b037398a187fc3bb9680ecb7dc0fc375 Mon Sep 17 00:00:00 2001 From: sbahling Date: Tue, 23 Oct 2018 22:46:21 +0200 Subject: Create main command tascam-fw-console - Add list units option - Autodiscover and use first found Tascam Console unit --- console.py | 88 +++++++++++++++++++++++++++++++------------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) (limited to 'console.py') diff --git a/console.py b/console.py index 7d6650c..a8757c0 100644 --- a/console.py +++ b/console.py @@ -20,13 +20,11 @@ :license: GPL-2.0, see COPYING for details """ -import argparse import string import time import threading from pathlib import Path -import osc import strips import fw_1884_buttons @@ -34,6 +32,7 @@ import gi gi.require_version('Hinawa', '2.0') from gi.repository import Hinawa # noqa: E402 +from hinawa_utils.tscm.config_rom_parser import TscmConfigRomParser # noqa: E402 E501 from hinawa_utils.tscm.tscm_console_unit import TscmConsoleUnit # noqa: E402 @@ -86,13 +85,28 @@ class RunningStatusThread(): class Console(): - def __init__(self, card): + def __init__(self, card_id=None, guid=None): + + fullpath = None + if guid: + fullpath = self._seek_snd_unit_from_guid(card_id) + elif card_id: + fullpath = '/dev/snd/hwC{0}D0'.format(card_id) + else: + try: + units = list_units() + if units: + model, fullpath, guid = units[0] + except Exception: + raise Exception('No Tascam FW Console unit found') - fullpath = seek_snd_unit_path(card) if fullpath: self.unit = TscmConsoleUnit(fullpath) + model = self.unit.model_name + guid = self.unit.get_property('guid') + print('Found Tascam {0} unit with GUID: {1:016x}'.format(model, guid)) # noqa E501 else: - exit() + raise Exception('No Tascam FW Console unit found') self.state = {} self.current_bank = 1 @@ -106,6 +120,20 @@ class Console(): self.status_thread = RunningStatusThread(self) # noqa F841 + def _seek_snd_unit_from_guid(self, guid): + for fullpath in Path('/dev/snd').glob('hw*'): + fullpath = str(fullpath) + try: + unit = Hinawa.SndUnit() + unit.open(fullpath) + if unit.get_property('guid') == guid: + return fullpath + except Exception as e: + pass + finally: + del unit + return None + def init_buttons(self): self.button_map = fw_1884_buttons.init_buttons(self) for index, items in self.button_map.items(): @@ -292,49 +320,21 @@ def _check_hexadecimal(literal): return True -def _seek_snd_unit_from_guid(guid): +def list_units(): + units = [] for fullpath in Path('/dev/snd').glob('hw*'): fullpath = str(fullpath) + unit = None try: unit = Hinawa.SndUnit() unit.open(fullpath) - if unit.get_property('guid') == guid: - return fullpath + parser = TscmConfigRomParser() + info = parser.parse_rom(unit.get_config_rom()) + model = info['model-name'] + guid = unit.get_property('guid') + if model in ('FW-1082', 'FW-1884'): + units.append((model, fullpath, guid)) except Exception as e: pass - finally: - del unit - return None - - -def seek_snd_unit_path(card_id): - # Assume as sound card number if it's digit literal. - if card_id.isdigit(): - return '/dev/snd/hwC{0}D0'.format(card_id) - # Assume as GUID on IEEE 1394 bus if it's hexadecimal literal. - elif _check_hexadecimal(card_id): - return _seek_snd_unit_from_guid(int(card_id, base=16)) - return None - - -if __name__ == "__main__": - - parser = argparse.ArgumentParser() - parser.add_argument("--card", default="1", - help="number of the ALSA sound card") - parser.add_argument("--listen-ip", default="127.0.0.1", - help="The ip to listen on") - parser.add_argument("--listen-port", type=int, default=5005, - help="The port to listen on") - parser.add_argument("--ip", default="127.0.0.1", - help="The ip of the OSC server") - parser.add_argument("--port", type=int, default=3819, - help="The port the OSC server is listening on") - 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() + + return units -- cgit v1.2.3