From cbf12b6a6191d38550cd03adbb8eafce5c1bc66c Mon Sep 17 00:00:00 2001 From: sbahling Date: Fri, 2 Nov 2018 20:47:59 +0100 Subject: rafactor strips - move initialization of console strips to console module - rename strips.py to strip.py --- tascam_fw_console/console.py | 8 ++- tascam_fw_console/strip.py | 146 +++++++++++++++++++++++++++++++++++++++++ tascam_fw_console/strips.py | 153 ------------------------------------------- 3 files changed, 152 insertions(+), 155 deletions(-) create mode 100644 tascam_fw_console/strip.py delete mode 100644 tascam_fw_console/strips.py (limited to 'tascam_fw_console') diff --git a/tascam_fw_console/console.py b/tascam_fw_console/console.py index 0f9a131..21b2ac9 100644 --- a/tascam_fw_console/console.py +++ b/tascam_fw_console/console.py @@ -25,7 +25,7 @@ import time import threading from pathlib import Path -from tascam_fw_console import strips +from tascam_fw_console.strip import Strip from tascam_fw_console import osc from tascam_fw_console import fw_1884_buttons @@ -116,7 +116,7 @@ class Console(): self.current_bank = 1 self.more_banks_up = True self.more_banks_down = True - self.strips = strips.init_strips(self) + self.strips = self.init_strips() self.buttons = {} self.init_buttons() self.init_encoder_mode() @@ -133,6 +133,10 @@ class Console(): self.status_thread = RunningStatusThread(self) # noqa F841 + def init_strips(self): + for strip_num in range(0, 9): + self.strips.append(Strip(self, strip_num)) + def init_encoder_mode(self): self.state['encoder_mode'] = 'PAN' for mode in ENCODER_MODES: diff --git a/tascam_fw_console/strip.py b/tascam_fw_console/strip.py new file mode 100644 index 0000000..17d4a7e --- /dev/null +++ b/tascam_fw_console/strip.py @@ -0,0 +1,146 @@ +#!/usr/bin/env python3 +""" + Open Sound Control send/recieve daemon for Tascam Firewire control surface + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + :copyright: Copyright (c) 2018 Scott Bahling + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program (see the file COPYING); if not, write to the + Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + :license: GPL-2.0, see COPYING for details +""" + +from tascam_fw_console.fader import Fader +from tascam_fw_console import osc + + +class Strip(): + + def __init__(self, console, num): + self.console = console + self.num = num + self.mute_button = None + self._mute = False + self.solo_button = None + self._solo = False + self.select_button = None + self._select = False + self._rec = False + self.pan = 0.5 + self.trimdb = 0.0 + self.fader = Fader(self) + self.name = None + + self.encoder_handlers = {'PAN': self.send_pan, + 'AUX1': self.send_trim, + } + + @property + def mute_led(self): + return self.console.unit.strips[self.num].mute_led + + @property + def solo_led(self): + return self.console.unit.strips[self.num].solo_led + + @property + def sel_led(self): + return self.console.unit.strips[self.num].sel_led + + @property + def rec_led(self): + return self.console.unit.strips[self.num].rec_led + + @property + def mute(self): + return self._mute + + @mute.setter + def mute(self, state): + state = bool(state) + self._mute = state + if state: + self.mute_led.turn_on() + else: + self.mute_led.turn_off() + + @property + def solo(self): + return self._solo + + @solo.setter + def solo(self, state): + state = bool(state) + self._solo = state + if state: + self.solo_led.turn_on() + else: + self.solo_led.turn_off() + + @property + def select(self): + return self._select + + @select.setter + def select(self, state): + state = bool(state) + self._select = state + if state: + self.sel_led.turn_on() + else: + self.sel_led.turn_off() + + @property + def rec(self): + return self._rec + + @rec.setter + def rec(self, state): + state = bool(state) + self._rec = state + if state: + self.rec_led.turn_on() + else: + self.rec_led.turn_off() + + def send_pan(self, delta): + addr = '/strip/pan_stereo_position' + pan = self.pan + delta * 0.02 + if pan < 0: + pan = 0 + if pan > 1.0: + pan = 1.0 + osc.client.send_message(addr, (self.num, pan)) + + def recv_pan(self, pan): + print('Pan: {} {}'.format(self.num, pan)) + self.pan = pan + + def send_trim(self, delta): + addr = '/strip/trimdB' + trimdb = self.trimdb + delta * 0.5 + if trimdb < -20: + trimdb = -20 + if trimdb > 20: + trimdb = 20 + osc.client.send_message(addr, (self.num, trimdb)) + + def recv_trim(self, trimdb): + print('TrimdB: {} {}'.format(self.num, trimdb)) + self.trimdb = trimdb + + def handle_encoder(self, mode, delta): + self.encoder_handlers.get(mode, self.default_encoder_handler)(delta) + + def default_encoder_handler(self, delta): + print(delta) diff --git a/tascam_fw_console/strips.py b/tascam_fw_console/strips.py deleted file mode 100644 index e063f52..0000000 --- a/tascam_fw_console/strips.py +++ /dev/null @@ -1,153 +0,0 @@ -#!/usr/bin/env python3 -""" - Open Sound Control send/recieve daemon for Tascam Firewire control surface - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - :copyright: Copyright (c) 2018 Scott Bahling - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License version 2 as - published by the Free Software Foundation. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program (see the file COPYING); if not, write to the - Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA - :license: GPL-2.0, see COPYING for details -""" - -from tascam_fw_console.fader import Fader -from tascam_fw_console import osc - - -class Strip(): - - def __init__(self, console, num): - self.console = console - self.num = num - self.mute_button = None - self._mute = False - self.solo_button = None - self._solo = False - self.select_button = None - self._select = False - self._rec = False - self.pan = 0.5 - self.trimdb = 0.0 - self.fader = Fader(self) - self.name = None - - self.encoder_handlers = {'PAN': self.send_pan, - 'AUX1': self.send_trim, - } - - @property - def mute_led(self): - return self.console.unit.strips[self.num].mute_led - - @property - def solo_led(self): - return self.console.unit.strips[self.num].solo_led - - @property - def sel_led(self): - return self.console.unit.strips[self.num].sel_led - - @property - def rec_led(self): - return self.console.unit.strips[self.num].rec_led - - @property - def mute(self): - return self._mute - - @mute.setter - def mute(self, state): - state = bool(state) - self._mute = state - if state: - self.mute_led.turn_on() - else: - self.mute_led.turn_off() - - @property - def solo(self): - return self._solo - - @solo.setter - def solo(self, state): - state = bool(state) - self._solo = state - if state: - self.solo_led.turn_on() - else: - self.solo_led.turn_off() - - @property - def select(self): - return self._select - - @select.setter - def select(self, state): - state = bool(state) - self._select = state - if state: - self.sel_led.turn_on() - else: - self.sel_led.turn_off() - - @property - def rec(self): - return self._rec - - @rec.setter - def rec(self, state): - state = bool(state) - self._rec = state - if state: - self.rec_led.turn_on() - else: - self.rec_led.turn_off() - - def send_pan(self, delta): - addr = '/strip/pan_stereo_position' - pan = self.pan + delta * 0.02 - if pan < 0: - pan = 0 - if pan > 1.0: - pan = 1.0 - osc.client.send_message(addr, (self.num, pan)) - - def recv_pan(self, pan): - print('Pan: {} {}'.format(self.num, pan)) - self.pan = pan - - def send_trim(self, delta): - addr = '/strip/trimdB' - trimdb = self.trimdb + delta * 0.5 - if trimdb < -20: - trimdb = -20 - if trimdb > 20: - trimdb = 20 - osc.client.send_message(addr, (self.num, trimdb)) - - def recv_trim(self, trimdb): - print('TrimdB: {} {}'.format(self.num, trimdb)) - self.trimdb = trimdb - - def handle_encoder(self, mode, delta): - self.encoder_handlers.get(mode, self.default_encoder_handler)(delta) - - def default_encoder_handler(self, delta): - print(delta) - -def init_strips(unit): - strips = [] - for strip_num in range(0, 9): - strips.append(Strip(unit, strip_num)) - - return strips -- cgit v1.2.3