-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShiftableDeviceComponent.py
More file actions
executable file
·85 lines (72 loc) · 3.14 KB
/
ShiftableDeviceComponent.py
File metadata and controls
executable file
·85 lines (72 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import Live
from _Generic.Devices import *
from _Framework.DeviceComponent import DeviceComponent
from _Framework.ChannelTranslationSelector import ChannelTranslationSelector
from _Framework.ButtonElement import ButtonElement
class ShiftableDeviceComponent(DeviceComponent):
""" DeviceComponent that only uses bank buttons if a shift button is pressed """
def __init__(self):
DeviceComponent.__init__(self)
self._shift_button = None
self._shift_pressed = False
self._control_translation_selector = ChannelTranslationSelector(8)
def disconnect(self):
DeviceComponent.disconnect(self)
self._control_translation_selector.disconnect()
if self._shift_button is not None:
self._shift_button.remove_value_listener(self._shift_value)
self._shift_button = None
def set_parameter_controls(self, controls):
DeviceComponent.set_parameter_controls(self, controls)
self._control_translation_selector.set_controls_to_translate(controls)
self._control_translation_selector.set_mode(self._bank_index)
def set_device(self, device):
DeviceComponent.set_device(self, device)
self._control_translation_selector.set_mode(self._bank_index)
def set_shift_button(self, button):
if not (button == None or isinstance(button, ButtonElement) and button.is_momentary()):
raise AssertionError
if self._shift_button != button:
if self._shift_button != None:
self._shift_button.remove_value_listener(self._shift_value)
self._shift_button = button
self._shift_button != None and self._shift_button.add_value_listener(self._shift_value)
self.update()
def update(self):
if self._parameter_controls is not None:
for control in self._parameter_controls:
control.release_parameter()
if self.is_enabled() and self._device is not None:
self._device_bank_registry.set_device_bank(self._device, self._bank_index)
if self._parameter_controls is not None:
if self._bank_index < number_of_parameter_banks(self._device):
old_bank_name = self._bank_name
self._assign_parameters()
if self._bank_name != old_bank_name:
self._show_msg_callback(self._device.name + ' Bank: ' + self._bank_name)
self._shift_pressed or self._on_on_off_changed()
elif self._bank_buttons is not None:
for index in range(len(self._bank_buttons)):
if index == self._bank_index:
self._bank_buttons[index].turn_on()
else:
self._bank_buttons[index].turn_off()
def _shift_value(self, value):
raise self._shift_button is not None or AssertionError
raise value in range(128) or AssertionError
self._shift_pressed = value != 0
self.update()
def _bank_value(self, value, sender):
if not (sender != None and sender in self._bank_buttons):
raise AssertionError
if self._shift_pressed and self.is_enabled():
self._bank_name = (value != 0 or not sender.is_momentary()) and ''
self._bank_index = list(self._bank_buttons).index(sender)
self._control_translation_selector.set_mode(self._bank_index)
self.update()
def _on_off_value(self, value):
if not self._shift_pressed:
DeviceComponent._on_off_value(self, value)
def _on_on_off_changed(self):
if not self._shift_pressed:
DeviceComponent._on_on_off_changed(self)