-
Notifications
You must be signed in to change notification settings - Fork 3
/
SpecialMixerComponent.py
294 lines (246 loc) · 12.5 KB
/
SpecialMixerComponent.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
#Embedded file name: /Users/versonator/Jenkins/live/Projects/AppLive/Resources/MIDI Remote Scripts/Push/SpecialMixerComponent.py
from functools import partial
from _Framework import Task
from _Framework.SubjectSlot import subject_slot
from _Framework.MixerComponent import MixerComponent
from _Framework.DisplayDataSource import DisplayDataSource
from SpecialChanStripComponent import SpecialChanStripComponent
def tracks_to_use_from_song(song):
return tuple(song.visible_tracks) + tuple(song.return_tracks)
class SpecialMixerComponent(MixerComponent):
"""
Special mixer class that uses return tracks alongside midi and
audio tracks. This provides also a more convenient interface to
set controls for the different modes of the L9C.
"""
num_label_segments = 4
def __init__(self, *a, **k):
super(SpecialMixerComponent, self).__init__(*a, **k)
self._pan_send_index = 0
self._pan_send_controls = None
self._pan_send_names_display = None
self._pan_send_values_display = None
self._pan_send_graphics_display = None
self._pan_send_toggle_skip = False
self._pan_send_alt_display = None
self._volume_alt_display = None
self._track_mix_alt_display = None
self._volume_touch_buttons = []
self._pan_send_touch_buttons = []
self._track_mix_touch_buttons = []
self._selected_track_data_sources = map(DisplayDataSource, ('',) * self.num_label_segments)
self._selected_track_data_sources[0].set_display_string('Track Selection:')
self._selected_track_name_data_source = self._selected_track_data_sources[1]
self._on_selected_track_changed.subject = self.song().view
self._update_selected_track()
def tracks_to_use(self):
return tracks_to_use_from_song(self.song())
def _create_strip(self):
return SpecialChanStripComponent()
def set_pan_send_toggle(self, toggle):
"""
The pan_send_toggle cycles through the different pan, or send
modes changing the bejhaviour of the pan_send display and
controls.
"""
self._pan_send_toggle = toggle
self._on_pan_send_value.subject = toggle
self._pan_send_toggle_skip = True
def set_selected_values_display(self, display):
if display:
sources = [ self.selected_strip().track_parameter_data_sources(index) for index in xrange(8) ]
display.set_data_sources(sources)
def set_selected_graphics_display(self, display):
if display:
sources = [ self.selected_strip().track_parameter_graphic_sources(index) for index in xrange(8) ]
display.set_data_sources(sources)
def set_selected_names_display(self, display):
if display:
sources = [ self.selected_strip().track_parameter_name_sources(index) for index in xrange(8) ]
display.set_data_sources(sources)
def set_selected_track_name_display(self, display):
if display:
display.set_data_sources(self._selected_track_data_sources)
def set_track_select_buttons(self, buttons):
for strip, button in map(None, self._channel_strips, buttons or []):
if button:
button.set_on_off_values('Option.Selected', 'Option.Unselected')
strip.set_select_button(button)
def set_solo_buttons(self, buttons):
for strip, button in map(None, self._channel_strips, buttons or []):
if button:
button.set_on_off_values('Mixer.SoloOn', 'Mixer.SoloOff')
strip.set_solo_button(button)
def set_mute_buttons(self, buttons):
for strip, button in map(None, self._channel_strips, buttons or []):
if button:
button.set_on_off_values('Mixer.MuteOff', 'Mixer.MuteOn')
strip.set_mute_button(button)
def set_track_names_display(self, display):
if display:
sources = [ strip.track_name_data_source() for strip in self._channel_strips ]
display.set_data_sources(sources)
def set_volume_touch_buttons(self, encoder_touch_buttons):
if not encoder_touch_buttons:
encoder_touch_buttons = []
self._volume_touch_buttons = self._volume_touch_buttons != encoder_touch_buttons and encoder_touch_buttons
self._on_volume_touch_value.subject = encoder_touch_buttons or None
self._try_set_volume_alt_display()
def set_pan_send_touch_buttons(self, encoder_touch_buttons):
if not encoder_touch_buttons:
encoder_touch_buttons = []
self._pan_send_touch_buttons = self._pan_send_touch_buttons != encoder_touch_buttons and encoder_touch_buttons
self._on_pan_send_touch_value.subject = encoder_touch_buttons or None
self._try_set_pan_send_alt_display()
def set_track_mix_touch_buttons(self, encoder_touch_buttons):
if not encoder_touch_buttons:
encoder_touch_buttons = []
self._track_mix_touch_buttons = self._track_mix_touch_buttons != encoder_touch_buttons and encoder_touch_buttons
self._on_track_mix_touch_value.subject = encoder_touch_buttons or None
self._try_set_track_mix_alt_display()
def set_volume_alt_display(self, display):
if not display:
display = None
self._volume_alt_display = self._volume_alt_display != display and display
self._try_set_volume_alt_display()
def set_pan_send_alt_display(self, display):
if not display:
display = None
self._pan_send_alt_display = self._pan_send_alt_display != display and display
self._try_set_pan_send_alt_display()
def set_track_mix_alt_display(self, display):
if not display:
display = None
self._track_mix_alt_display = self._track_mix_alt_display != display and display
self._try_set_track_mix_alt_display()
def set_volume_names_display(self, display):
self._set_parameter_names_display(display, 0)
def set_volume_values_display(self, display):
self._set_parameter_values_display(display, 0)
def set_volume_graphics_display(self, display):
self._set_parameter_graphics_display(display, 0)
def set_volume_controls(self, controls):
for strip, control in map(None, self._channel_strips, controls or []):
strip.set_volume_control(control)
def set_pan_send_names_display(self, display):
self._normalize_pan_send_index()
self._pan_send_names_display = display
self._set_parameter_names_display(display, self._pan_send_index + 1)
def set_pan_send_values_display(self, display):
self._normalize_pan_send_index()
self._pan_send_values_display = display
self._set_parameter_values_display(display, self._pan_send_index + 1)
def set_pan_send_graphics_display(self, display):
self._normalize_pan_send_index()
self._pan_send_graphics_display = display
self._set_parameter_graphics_display(display, self._pan_send_index + 1)
def set_pan_send_controls(self, controls):
self.set_send_controls(None)
self.set_pan_controls(None)
self._pan_send_controls = controls
self._normalize_pan_send_index()
if self._pan_send_index == 0:
self.set_pan_controls(controls)
else:
sends = self._pan_send_index - 1
self.set_send_controls(map(lambda ctl: (None,) * sends + (ctl,), controls or []))
def set_selected_controls(self, controls):
strip = self.selected_strip()
if controls:
strip.set_volume_control(controls[0])
strip.set_pan_control(controls[1])
strip.set_send_controls(controls[2:])
else:
strip.set_volume_control(None)
strip.set_pan_control(None)
strip.set_send_controls(tuple())
def on_track_list_changed(self):
super(SpecialMixerComponent, self).on_track_list_changed()
self._update_pan_sends()
def set_pan_controls(self, controls):
for strip, control in map(None, self._channel_strips, controls or []):
strip.set_pan_control(control)
def set_send_controls(self, controls):
for strip, control in map(None, self._channel_strips, controls or []):
strip.set_send_controls(control)
def _set_parameter_names_display(self, display, parameter):
if display:
sources = [ strip.track_parameter_name_sources(parameter) for strip in self._channel_strips ]
display.set_data_sources(sources)
def _set_parameter_values_display(self, display, parameter):
if display:
sources = [ strip.track_parameter_data_sources(parameter) for strip in self._channel_strips ]
display.set_data_sources(sources)
def _set_parameter_graphics_display(self, display, parameter):
if display:
sources = [ strip.track_parameter_graphic_sources(parameter) for strip in self._channel_strips ]
display.set_data_sources(sources)
@subject_slot('value')
def _on_volume_touch_value(self, value, x, y, is_momentary):
self._try_set_volume_alt_display()
@subject_slot('value')
def _on_pan_send_touch_value(self, value, x, y, is_momentary):
self._try_set_pan_send_alt_display()
@subject_slot('value')
def _on_track_mix_touch_value(self, value, x, y, is_momentary):
self._try_set_track_mix_alt_display()
@subject_slot('value')
def _on_pan_send_value(self, value):
if not self._pan_send_toggle_skip and self.is_enabled() and (value or not self._pan_send_toggle.is_momentary()):
self._pan_send_index += 1
self._update_pan_sends()
self._pan_send_toggle_skip = False
def _update_pan_sends(self):
self.set_pan_send_controls(self._pan_send_controls)
self.set_pan_send_names_display(self._pan_send_names_display)
self.set_pan_send_graphics_display(self._pan_send_graphics_display)
self._try_set_pan_send_alt_display()
def _try_set_volume_alt_display(self):
if self._volume_alt_display != None:
for button in self._volume_touch_buttons:
if button != None and button.is_pressed():
self.set_volume_values_display(self._volume_alt_display)
return
else:
self.set_selected_track_name_display(self._volume_alt_display)
def _try_set_pan_send_alt_display(self):
if self._pan_send_alt_display != None:
for button in self._pan_send_touch_buttons:
if button != None and button.is_pressed():
self.set_pan_send_values_display(self._pan_send_alt_display)
return
else:
self.set_selected_track_name_display(self._pan_send_alt_display)
def _try_set_track_mix_alt_display(self):
if self._track_mix_alt_display != None:
for button in self._track_mix_touch_buttons:
if button != None and button.is_pressed():
self.set_selected_values_display(self._track_mix_alt_display)
return
else:
self.set_selected_track_name_display(self._track_mix_alt_display)
def _normalize_pan_send_index(self):
if len(self.song().tracks) == 0 or self._pan_send_index > len(self.song().tracks[0].mixer_device.sends):
self._pan_send_index = 0
def _reassign_tracks(self):
tracks = self.tracks_to_use()
returns = self.song().return_tracks
num_empty_tracks = max(0, len(self._channel_strips) + self._track_offset - len(tracks))
num_visible_tracks = max(0, len(tracks) - len(returns) - self._track_offset)
num_visible_returns = len(self._channel_strips) - num_empty_tracks - num_visible_tracks
for index in range(len(self._channel_strips)):
track_index = self._track_offset + index
if len(tracks) > track_index:
track = tracks[track_index]
if tracks[track_index] not in returns:
self._channel_strips[index].set_track(track)
else:
self._channel_strips[index + num_empty_tracks].set_track(track)
else:
self._channel_strips[index - num_visible_returns].set_track(None)
@subject_slot('selected_track')
def _on_selected_track_changed(self):
self._update_selected_track()
def _update_selected_track(self):
selected = self.song().view.selected_track
self._selected_track_name_data_source.set_display_string(selected.name)