-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathEncoderUserModesComponent.py
executable file
·171 lines (139 loc) · 6.77 KB
/
EncoderUserModesComponent.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# http://remotescripts.blogspot.com
"""
Customized APC40 control surface script
Copyright (C) 2010 Hanz Petrov <[email protected]>
Additional modification for Ableton Live 9 - Fabrizio Poce 2013 - <http://www.fabriziopoce.com/>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
"""
import Live
from _Framework.ModeSelectorComponent import ModeSelectorComponent
from _Framework.ButtonElement import ButtonElement
from _Framework.DeviceComponent import DeviceComponent
class EncoderUserModesComponent(ModeSelectorComponent):
' SelectorComponent that assigns encoders to different user functions '
__module__ = __name__
def __init__(self, parent, encoder_modes, param_controls, bank_buttons, mixer, device, encoder_device_modes, encoder_eq_modes): #, mixer, sliders):
assert (len(bank_buttons) == 4)
ModeSelectorComponent.__init__(self)
self._parent = parent
self._encoder_modes = encoder_modes
self._param_controls = param_controls
self._bank_buttons = bank_buttons
self._mixer = mixer
self._device = device
self._encoder_device_modes = encoder_device_modes
self._encoder_eq_modes = encoder_eq_modes
self._mode_index = 0
self._modes_buttons = []
self._user_buttons = []
self._last_mode = 0
def disconnect(self):
ModeSelectorComponent.disconnect(self)
self._parent = None
self._encoder_modes = None
self._param_controls = None
self._bank_buttons = None
self._mixer = None
self._device = None
self._encoder_device_modes = None
self._encoder_eq_modes = None
self._modes_buttons = None
self._user_buttons = None
def on_enabled_changed(self):
pass
def set_mode(self, mode):
assert isinstance(mode, int)
assert (mode in range(self.number_of_modes()))
if (self._mode_index != mode):
self._last_mode = 0 # self._mode_index # keep track of previous mode, to allow conditional actions
self._mode_index = mode
self._set_modes()
def set_mode_buttons(self, buttons):
assert isinstance(buttons, (tuple,
type(None)))
for button in self._modes_buttons:
button.remove_value_listener(self._mode_value)
self._modes_buttons = []
if (buttons != None):
for button in buttons:
assert isinstance(button, ButtonElement)
identify_sender = True
button.add_value_listener(self._mode_value, identify_sender)
self._modes_buttons.append(button)
assert (self._mode_index in range(self.number_of_modes()))
def number_of_modes(self):
return 4
def update(self):
pass
def _mode_value(self, value, sender):
assert (len(self._modes_buttons) > 0)
assert isinstance(value, int)
assert isinstance(sender, ButtonElement)
assert (self._modes_buttons.count(sender) == 1)
if ((value is not 0) or (not sender.is_momentary())):
self.set_mode(self._modes_buttons.index(sender))
def _set_modes(self):
if self.is_enabled():
assert (self._mode_index in range(self.number_of_modes()))
for index in range(len(self._modes_buttons)):
if (index <= self._mode_index):
self._modes_buttons[index].turn_on()
else:
self._modes_buttons[index].turn_off()
for button in self._modes_buttons:
button.release_parameter()
button.use_default_message()
for control in self._param_controls:
control.release_parameter()
control.use_default_message()
#control.set_needs_takeover(False)
self._encoder_modes.set_enabled(False)
self._encoder_device_modes.set_lock_button(None)
self._encoder_device_modes._alt_device.set_bank_nav_buttons(None, None)
self._encoder_device_modes._alt_device.set_on_off_button(None)
if self._encoder_device_modes._alt_device._parameter_controls != None:
for control in self._encoder_device_modes._alt_device._parameter_controls:
control.release_parameter()
self._encoder_device_modes.set_enabled(False)
self._encoder_eq_modes.set_enabled(False)
self._encoder_eq_modes.set_lock_button(None)
if self._encoder_eq_modes._track_eq != None:
self._encoder_eq_modes._track_eq.set_cut_buttons(None)
if self._encoder_eq_modes._track_eq._gain_controls != None:
for control in self._encoder_eq_modes._track_eq._gain_controls:
control.release_parameter()
if self._encoder_eq_modes._strip != None:
self._encoder_eq_modes._strip.set_send_controls(None)
self._user_buttons = []
if (self._mode_index == 0):
self._encoder_modes.set_enabled(True)
elif (self._mode_index == 1):
self._encoder_device_modes.set_enabled(True)
self._encoder_device_modes.set_controls_and_buttons(self._param_controls, self._modes_buttons)
elif (self._mode_index == 2):
self._encoder_eq_modes.set_enabled(True)
self._encoder_eq_modes.set_controls_and_buttons(self._param_controls, self._modes_buttons)
elif (self._mode_index == 3):
self._encoder_eq_modes._ignore_buttons = True
if self._encoder_eq_modes._track_eq != None:
self._encoder_eq_modes._track_eq._ignore_cut_buttons = True
self._encoder_device_modes._ignore_buttons = True
for button in self._modes_buttons:
self._user_buttons.append(button)
for control in self._param_controls:
control.set_identifier((control.message_identifier() - 9))
control._ring_mode_button.send_value(0)
else:
pass
#self._rebuild_callback()
# local variables:
# tab-width: 4