summaryrefslogtreecommitdiff
path: root/buttons.py
diff options
context:
space:
mode:
authorsbahling <sbahling@cagafuego.fritz.box>2018-10-20 23:59:28 +0200
committersbahling <sbahling@cagafuego.fritz.box>2018-10-20 23:59:28 +0200
commit6effbc283b3fa5b34bd45045c81168afa979572c (patch)
treea57236c458c1833551b81bc94ccf8d82500b117c /buttons.py
parent50ae6f1fdd4fd9e880435ff7e831f7461cb5302e (diff)
downloadtascam-fw-osc-6effbc283b3fa5b34bd45045c81168afa979572c.tar.gz
tascam-fw-osc-6effbc283b3fa5b34bd45045c81168afa979572c.tar.xz
tascam-fw-osc-6effbc283b3fa5b34bd45045c81168afa979572c.zip
Initial refactoring work
Diffstat (limited to 'buttons.py')
-rw-r--r--buttons.py246
1 files changed, 246 insertions, 0 deletions
diff --git a/buttons.py b/buttons.py
new file mode 100644
index 0000000..89ae479
--- /dev/null
+++ b/buttons.py
@@ -0,0 +1,246 @@
+#!/usr/bin/env python3
+"""
+ Open Sound Control send/recieve daemon for Tascam Firewire control surface
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+ :copyright: Copyright (c) 2012-2014 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
+"""
+
+import re
+import pyautogui
+from osc import osc
+
+
+keymap = {'CTRL': 'ctrl',
+ 'ALT': 'alt',
+ 'SHIFT': 'shift',
+ }
+
+
+osc_addrs = {'STOP': '/transport_stop',
+ 'PLAY': '/transport_play',
+ 'F.FWD': '/ffwd',
+ 'REW': '/rewind',
+ 'REC': '/rec_enable_toggle',
+ }
+
+re_strip_num = re.compile('.*([1-9])')
+
+current_bank = 1
+more_banks_up = False
+more_banks_down = False
+
+
+class Button():
+ def __init__(self, console, name):
+ self.name = name
+ self.state = 0
+ self.console = None
+
+ def press(self):
+ self.state = 1
+ print('%s pressed' % self.name)
+
+ def release(self):
+ self.state = 0
+ print('%s released' % self.name)
+
+ @property
+ def pressed(self):
+ if self.state:
+ return True
+ return False
+
+
+class EncoderButton(Button):
+ def __init__(self, console, name):
+ super().__init__(console, name)
+
+ def press(self):
+
+ encoder_mode = self.console.state.get('encoder_mode', None)
+ print(encoder_mode)
+ if encoder_mode == self.name:
+ return
+
+ self.state = 1
+ if encoder_mode:
+ self.console.unit.leds.turn_off(encoder_mode)
+ self.console.state[encoder_mode] = 0
+ self.console.unit.leds.turn_on(self.name)
+ self.console.state['encoder_mode'] = self.name
+ super().press()
+
+
+class StripSelButton(Button):
+ def __init__(self, console, name, strip):
+ super().__init__(console, name)
+ self.strip = strip
+ self.strip.select = self
+
+ def press(self):
+
+ strip = self.strip
+ print('handle_strip_sel', strip)
+ if self.get('REC ENABLE', 0):
+ if strip.recenable:
+ osc.send_message('/strip/recenable', (strip.num, 0))
+ else:
+ osc.send_message('/strip/recenable', (strip.num, 1))
+ super().press()
+
+
+class StripMuteButton(Button):
+ def __init__(self, console, name, strip):
+ super().__init__(console, name)
+ self.strip = strip
+ self.strip.mute = self
+
+ def press(self):
+
+ strip = self.strip
+ if strip.mute:
+ strip.mute = False
+ osc.send_message('/strip/mute', (strip.num, 0))
+ else:
+ strip.mute = True
+ osc.send_message('/strip/mute', (strip.num, 1))
+ super().press()
+
+
+class StripSoloButton(Button):
+ def __init__(self, console, name, strip):
+ super().__init__(console, name)
+ self.strip = strip
+ self.strip.solo = self
+
+ def press(self):
+
+ strip = self.strip
+ if strip.solo:
+ strip.solo = False
+ osc.send_message('/strip/solo', (strip.num, 0))
+ else:
+ strip.solo = True
+ osc.send_message('/strip/solo', (strip.num, 1))
+ super().press()
+
+
+class ArrowButton(Button):
+ def __init__(self, console, name):
+ super().__init__(console, name)
+
+ def press(self):
+ key = keymap.get(self.name.lower(), self.name.lower())
+ pyautogui.press(key)
+
+
+class ModButton(Button):
+ def __init__(self, console, name):
+ super().__init__(console, name)
+
+ def mod_button_press(self):
+ key = keymap.get(self.name, None)
+ if key is None:
+ return
+
+ pyautogui.keyDown(key)
+ super().press()
+
+ def release(self):
+ key = keymap.get(self.name, None)
+ if key is None:
+ return
+
+ pyautogui.keyUp(key)
+ super().release()
+
+
+class ComputerButton(Button):
+ def __init__(self, console, name):
+ super().__init__(console, name)
+
+ def press(self):
+ osc.send_message('/set_surface', (8, 7, 19, 1, 8, 11))
+ super().press()
+
+
+class ClrSoloButton(Button):
+ def __init__(self, console, name):
+ super().__init__(console, name)
+
+ def press(self):
+ osc.send_message('/cancel_all_solos', 1)
+ super().press()
+
+
+class LoopButton(Button):
+ def __init__(self, console, name):
+ super().__init__(console, name)
+
+ def press(self, *args):
+ if self.console.state.get('loop', 0):
+ print('******* loop off')
+ osc.send_message('/loop_toggle', 0)
+ else:
+ print('******* loop on')
+ osc.send_message('/loop_toggle', 1)
+ super().press()
+
+
+class TransportButton(Button):
+ def __init__(self, console, name):
+ super().__init__(console, name)
+
+ def press(self):
+ addr = osc_addrs.get(self.name, None)
+ if addr:
+ osc.send_message(addr, 1)
+ super().press()
+
+
+class BankSwitchButton(Button):
+ def __init__(self, console, name, direction):
+ super().__init__(console, name)
+ self.direction = direction
+
+ def press(self):
+
+ direction = self.direction
+ print(direction, more_banks_up, more_banks_down)
+ if direction > 0 and more_banks_up:
+ print('calling /bank_up 1')
+ osc.send_message('/bank_up', 1)
+ elif direction < 0 and more_banks_down:
+ print('calling /bank_down 1')
+ osc.send_message('/bank_down', 1)
+ super().press()
+
+
+class NudgeButton(Button):
+ def __init__(self, console, name, direction):
+ super().__init__(console, name)
+ self.direction = direction
+
+ def nudge_press(self):
+ direction = self.direction
+ print(direction)
+ if direction > 0:
+ osc.send_message('/access_action', 'Common/nudge-next-forward')
+ else:
+ osc.send_message('/access_action', 'Common/nudge-next-backward')
+ super().press()