-
Notifications
You must be signed in to change notification settings - Fork 8
/
ShiftTranslatorComponent.py
executable file
·60 lines (39 loc) · 1.67 KB
/
ShiftTranslatorComponent.py
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
# http://remotescripts.blogspot.com
# emacs-mode: -*- python-*-
# -*- coding: utf-8 -*-
from _Framework.ChannelTranslationSelector import ChannelTranslationSelector
from _Framework.ButtonElement import ButtonElement
from _Framework.MixerComponent import MixerComponent
class ShiftTranslatorComponent(ChannelTranslationSelector):
' Class that translates the channel of some buttons as long as a shift button is held '
__module__ = __name__
def __init__(self):
ChannelTranslationSelector.__init__(self)
self._shift_button = None
self._shift_pressed = False
def disconnect(self):
if (self._shift_button != None):
self._shift_button.remove_value_listener(self._shift_value)
self._shift_button = None
ChannelTranslationSelector.disconnect(self)
def set_shift_button(self, button):
assert ((button == None) or (isinstance(button, ButtonElement) and button.is_momentary()))
if (self._shift_button != None):
self._shift_button.remove_value_listener(self._shift_value)
self._shift_button = button
if (self._shift_button != None):
self._shift_button.add_value_listener(self._shift_value)
self.set_mode(0)
def on_enabled_changed(self):
if self.is_enabled():
self.set_mode(int(self._shift_pressed))
def number_of_modes(self):
return 2
def _shift_value(self, value):
assert (self._shift_button != None)
assert (value in range(128))
self._shift_pressed = (value != 0)
if self.is_enabled():
self.set_mode(int(self._shift_pressed))
# local variables:
# tab-width: 4