forked from hdavid/Launchpad85
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainSelectorComponent.py
378 lines (329 loc) · 13.6 KB
/
MainSelectorComponent.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
from _Framework.ModeSelectorComponent import ModeSelectorComponent
from _Framework.ButtonElement import ButtonElement
from _Framework.ButtonMatrixElement import ButtonMatrixElement
from _Framework.ButtonSliderElement import ButtonSliderElement
from _Framework.ClipSlotComponent import ClipSlotComponent
from _Framework.ChannelStripComponent import ChannelStripComponent
from _Framework.SceneComponent import SceneComponent
from _Framework.SessionZoomingComponent import SessionZoomingComponent
from ConfigurableButtonElement import ConfigurableButtonElement
from DeviceControllerComponent import DeviceControllerComponent
from QuickMixerComponent import QuickMixerComponent
from SpecialSessionComponent import SpecialSessionComponent
from SubSelectorComponent import *
from StepSequencerComponent import StepSequencerComponent
class MainSelectorComponent(ModeSelectorComponent):
""" Class that reassigns the button on the launchpad to different functions """
def __init__(self, matrix, top_buttons, side_buttons, config_button, parent):
assert isinstance(matrix, ButtonMatrixElement)
assert ((matrix.width() == 8) and (matrix.height() == 8))
assert isinstance(top_buttons, tuple)
assert (len(top_buttons) == 8)
assert isinstance(side_buttons, tuple)
assert (len(side_buttons) == 8)
assert isinstance(config_button, ButtonElement)
ModeSelectorComponent.__init__(self)
self._parent = parent
self._session = SpecialSessionComponent(matrix.width(), matrix.height())
self._zooming = SessionZoomingComponent(self._session)
self._session.name = 'Session_Control'
self._zooming.name = 'Session_Overview'
self._matrix = matrix
self._side_buttons = side_buttons
self._nav_buttons = top_buttons[:4]
self._config_button = config_button
self._zooming.set_empty_value(LED_OFF)
self._all_buttons = []
for button in self._side_buttons + self._nav_buttons:
self._all_buttons.append(button)
self._sub_modes = SubSelectorComponent(matrix, side_buttons, self._session)
self._sub_modes.name = 'Mixer_Modes'
self._sub_modes.set_update_callback(self._update_control_channels)
self._stepseq = StepSequencerComponent(self, self._matrix,self._side_buttons,self._nav_buttons)
self._quick_mix = None#QuickMixerComponent(self._nav_buttons,self._side_buttons,self)
self._device_controller = DeviceControllerComponent(self._matrix, self._side_buttons, self._nav_buttons, self)
self._init_session()
self._all_buttons = tuple(self._all_buttons)
self._previous_mode_index=-1
self._sub_mode_index=[0,0,0,0]
for index in range(4):
self._sub_mode_index[index]=0
self.set_mode_buttons(top_buttons[4:])
def disconnect(self):
for button in self._modes_buttons:
button.remove_value_listener(self._mode_value)
self._session = None
self._zooming = None
for button in self._all_buttons:
button.set_on_off_values(127, LED_OFF)
self._config_button.turn_off()
self._matrix = None
self._side_buttons = None
self._nav_buttons = None
self._config_button = None
ModeSelectorComponent.disconnect(self)
def session_component(self):
return self._session
def set_mode(self, mode):
assert mode in range(self.number_of_modes())
if ((self._mode_index != mode) or (mode == 3) or True):
self._mode_index = mode
self.update()
def number_of_modes(self):
return 4
def on_enabled_changed(self):
self.update()
def _update_mode_buttons(self):
if self._mode_index==self._previous_mode_index:
if self._mode_index==1:
#user mode 1 and device controller
self._sub_mode_index[self._mode_index] = (self._sub_mode_index[self._mode_index]+1)%2
elif self._mode_index==2:
#user mode 2 and step sequencer
self._sub_mode_index[self._mode_index] = (self._sub_mode_index[self._mode_index]+1)%3
else:
self._sub_mode_index[self._mode_index] = 0
for index in range(4):
if(self._sub_mode_index[index]==0):
self._modes_buttons[index].set_on_off_values(AMBER_FULL,AMBER_THIRD)
if(self._sub_mode_index[index]==1):
self._modes_buttons[index].set_on_off_values(GREEN_FULL,GREEN_THIRD)
if(self._sub_mode_index[index]==2):
self._modes_buttons[index].set_on_off_values(RED_FULL,RED_THIRD)
if (index == self._mode_index):
self._modes_buttons[index].turn_on()
else:
self._modes_buttons[index].turn_off()
def channel_for_current_mode(self):
#trying to keep
if self._mode_index==0:
return 0
elif self._mode_index==1:
if self._sub_mode_index[self._mode_index]==0:
new_channel=4#user 1
else :
new_channel = 1#device ctrl
elif self._mode_index==2:
if self._sub_mode_index[self._mode_index]==0:
new_channel=5#user 2
else:
new_channel = 1 + self._sub_mode_index[self._mode_index]#step seq
elif self._mode_index==3:#mixer modes
new_channel = 6 + self._sub_modes.mode()
#if (new_channel > 0):
# new_channel += 3
return new_channel
def update(self):
assert (self._modes_buttons != None)
if self.is_enabled():
#for index in range(len(self._modes_buttons)):
# self._modes_buttons[index].set_force_next_value()
# if index == self._mode_index:
# self._modes_buttons[index].turn_on()
# else:
# self._modes_buttons[index].turn_off()
self._update_mode_buttons()
#update matrix and side buttons
for scene_index in range(8):
#update scene button
self._side_buttons[scene_index].set_enabled(True)
for track_index in range(8):
#update matrix
self._matrix.get_button(track_index, scene_index).set_enabled(True)
for button in self._nav_buttons:
button.set_enabled(True)
as_active = True
as_enabled = True
self._session.set_allow_update(False)
self._zooming.set_allow_update(False)
self._config_button.send_value(40)
self._config_button.send_value(1)
release_buttons = (self._mode_index == 1)
if (self._mode_index == 0):
#session
self._setup_mixer((not as_active))
self._setup_device_controller((not as_active))
self._setup_step_sequencer((not as_active),0)
self._setup_device_controller((not as_active))
self._setup_session(as_active, as_enabled)
elif (self._mode_index == 1):
#user mode + device controller
self._setup_mixer((not as_active))
if (self._sub_mode_index[self._mode_index]==0):
self._setup_step_sequencer((not as_active),0)
self._setup_device_controller((not as_active))
self._setup_session((not as_active), (as_enabled))
self._setup_user1(True,True,True)
else:
self._setup_session(not as_active, not as_enabled)
self._setup_step_sequencer(not as_active,0)
self._setup_device_controller(as_active)
elif (self._mode_index == 2):
self._setup_session((not as_active), (not as_enabled))
self._setup_mixer((not as_active))
self._setup_device_controller((not as_active))
if (self._sub_mode_index[self._mode_index]==0):
self._setup_device_controller((not as_active))
self._setup_step_sequencer((not as_active),0)
self._setup_user2(release_buttons)
else:
self._setup_device_controller((not as_active))
self._setup_step_sequencer(as_active,self._sub_mode_index[self._mode_index])
elif (self._mode_index == 3):
self._setup_step_sequencer((not as_active),0)
self._setup_device_controller((not as_active))
self._setup_session((not as_active), as_enabled)
self._setup_mixer(as_active)
else:
assert False
self._previous_mode_index=self._mode_index
self._session.set_allow_update(True)
self._zooming.set_allow_update(True)
self._update_control_channels()
#Update the channels of the buttons in the user modes..
def _update_control_channels(self):
new_channel = self.channel_for_current_mode()
for button in self._all_buttons:
button.set_channel(new_channel)
button.set_force_next_value()
def _setup_session(self, as_active, as_enabled):
assert isinstance(as_active, type(False))
for button in self._nav_buttons:
if as_enabled:
button.set_on_off_values(GREEN_FULL, GREEN_THIRD)
else:
button.set_on_off_values(127, LED_OFF)
#matrix
for scene_index in range(8):
scene = self._session.scene(scene_index)
if as_active:
scene_button = self._side_buttons[scene_index]
scene_button.set_on_off_values(127, LED_OFF)
scene.set_launch_button(scene_button)
else:
scene.set_launch_button(None)
for track_index in range(8):
if as_active:
button = self._matrix.get_button(track_index, scene_index)
button.set_on_off_values(127, LED_OFF)
scene.clip_slot(track_index).set_launch_button(button)
else:
scene.clip_slot(track_index).set_launch_button(None)
#zoom
if as_active:
self._zooming.set_zoom_button(self._modes_buttons[0])
self._zooming.set_button_matrix(self._matrix)
self._zooming.set_scene_bank_buttons(self._side_buttons)
self._zooming.set_nav_buttons(self._nav_buttons[0], self._nav_buttons[1], self._nav_buttons[2], self._nav_buttons[3])
self._zooming.update()
else:
self._zooming.set_zoom_button(None)
self._zooming.set_button_matrix(None)
self._zooming.set_scene_bank_buttons(None)
self._zooming.set_nav_buttons(None, None, None, None)
#nav buttons
if as_enabled:
self._session.set_track_bank_buttons(self._nav_buttons[3], self._nav_buttons[2])
self._session.set_scene_bank_buttons(self._nav_buttons[1], self._nav_buttons[0])
else:
self._session.set_track_bank_buttons(None, None)
self._session.set_scene_bank_buttons(None, None)
def _setup_quick_mix(self, as_active):
if self._quick_mix!=None:
if as_active:
for button in range(8):
self._side_buttons[button].set_enabled(True)
self._quick_mix._is_active = True
self._quick_mix.set_enabled(True)
else:
self._quick_mix._is_active = False
self._quick_mix.set_enabled(False)
def _setup_step_sequencer(self, as_active, mode):
if(self._stepseq!=None):
if(self._stepseq._is_active!=as_active or self._stepseq._mode!=mode ):
if as_active:
self._stepseq._mode=mode
self._stepseq._force_update = True
self._stepseq._is_active = True
self._stepseq.set_enabled(True)
self._stepseq._on_notes_changed()
self._config_button.send_value(32)
else:
self._stepseq._mode=1
self._stepseq._is_active = False
self._stepseq.set_enabled(False)
def _setup_device_controller(self, as_active):
if self._device_controller!=None:
if as_active:
#for button in range(8):
# self._side_buttons[button].set_enabled(True)
self._device_controller._is_active = True
self._device_controller.set_enabled(True)
self._device_controller.update()
self._config_button.send_value(32)
else:
self._device_controller._is_active = False
self._device_controller.set_enabled(False)
def _setup_mixer(self, as_active):
assert isinstance(as_active, type(False))
if(as_active and self._sub_modes.is_enabled()):
self._sub_modes.set_mode(-1)
self._sub_modes.set_enabled(as_active)
def _setup_user1(self, release_matrix=True,release_side_buttons =True,release_nav_buttons = True):
for scene_index in range(8):
if(release_side_buttons):
scene_button = self._side_buttons[scene_index]
scene_button.set_on_off_values(127, LED_OFF)
scene_button.turn_off()
scene_button.set_enabled((not release_side_buttons))
for track_index in range(8):
button = self._matrix.get_button(track_index, scene_index)
button.set_on_off_values(127, LED_OFF)
button.turn_off()
button.set_enabled((not release_matrix))
for button in self._nav_buttons:
if(release_nav_buttons):
button.set_on_off_values(127, LED_OFF)
button.turn_off()
button.set_enabled((not release_nav_buttons))
if release_matrix:
self._config_button.send_value(2)
self._config_button.send_value(32, force_send=True)
def _setup_user2(self, release_buttons):
for scene_index in range(8):
scene_button = self._side_buttons[scene_index]
scene_button.set_on_off_values(127, LED_OFF)
scene_button.turn_off()
scene_button.set_enabled(not release_buttons)
for track_index in range(8):
button = self._matrix.get_button(track_index, scene_index)
button.set_on_off_values(127, LED_OFF)
button.turn_off()
button.set_enabled(not release_buttons)
for button in self._nav_buttons:
button.set_on_off_values(127, LED_OFF)
button.turn_off()
button.set_enabled(not release_buttons)
if release_buttons:
self._config_button.send_value(2)
self._config_button.send_value(32, force_send=True)
def _init_session(self):
self._session.set_stop_track_clip_value(AMBER_BLINK)
for scene_index in range(self._matrix.height()):
scene = self._session.scene(scene_index)
scene.set_triggered_value(GREEN_BLINK)
scene.name = 'Scene_' + str(scene_index)
for track_index in range(self._matrix.width()):
clip_slot = scene.clip_slot(track_index)
clip_slot.set_triggered_to_play_value(GREEN_BLINK)
clip_slot.set_triggered_to_record_value(RED_BLINK)
clip_slot.set_stopped_value(AMBER_FULL)
clip_slot.set_started_value(GREEN_FULL)
clip_slot.set_recording_value(RED_FULL)
clip_slot.name = str(track_index) + '_Clip_Slot_' + str(scene_index)
self._all_buttons.append(self._matrix.get_button(track_index, scene_index))
self._zooming.set_stopped_value(RED_FULL)
self._zooming.set_selected_value(AMBER_FULL)
self._zooming.set_playing_value(GREEN_FULL)
def log_message(self, message):
self._parent.log_message(message)