-
Notifications
You must be signed in to change notification settings - Fork 82
/
InstrumentControllerComponent.py
835 lines (731 loc) · 29.8 KB
/
InstrumentControllerComponent.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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
import Live
from _Framework.CompoundComponent import CompoundComponent
from _Framework.SubjectSlot import subject_slot
from _Framework.ButtonElement import ButtonElement
from _Framework.Util import find_if, clamp
try:
from itertools import imap
except ImportError:
# Python 3...
imap=map
from .TrackControllerComponent import TrackControllerComponent
from .ScaleComponent import ScaleComponent,CIRCLE_OF_FIFTHS,MUSICAL_MODES,KEY_NAMES
try:
from .Settings import Settings
except ImportError:
from .Settings import *
#fix for python3
try:
xrange
except NameError:
xrange = range
from _Framework.ButtonMatrixElement import ButtonMatrixElement
KEY_MODE = 0
SCALE_TYPE_MODE = 1
class InstrumentControllerComponent(CompoundComponent):
def __init__(self, matrix, side_buttons, top_buttons, control_surface, note_repeat):
super(InstrumentControllerComponent, self).__init__()
self._control_surface = control_surface
self._note_repeat = note_repeat
self._osd = None
self._matrix = None
self._side_buttons = side_buttons
self._remaining_buttons = []
self._track_controller = None
self.base_channel = 11
self._quick_scales = [0, 1, 2, 3, 4, 5, 6, 7, 10, 13, 14, 15, 17, 18, 24]
self._quick_scale_root = 0
self._normal_feedback_velocity = int(self._control_surface._skin['Note.Feedback'])
self._recordind_feedback_velocity = int(self._control_surface._skin['Note.FeedbackRecord'])
self._drum_group_device = None
self._octave_up_button = None
self._octave_down_button = None
self._scales_toggle_button = None
self.set_scales_toggle_button(side_buttons[0])#Enable scale selecting mode
self.set_octave_up_button(side_buttons[2])#Shift octave up
self.set_octave_down_button(side_buttons[3])#Shift octave down
self._osd_mode_backup = "Instrument"
self._track_controller = self.register_component(TrackControllerComponent(control_surface = control_surface, implicit_arm = True))
self._track_controller.set_enabled(False)
#Clip navigation buttons
self._track_controller.set_prev_scene_button(top_buttons[0])
self._track_controller.set_next_scene_button(top_buttons[1])
self._track_controller.set_prev_track_button(top_buttons[2])
self._track_controller.set_next_track_button(top_buttons[3])
#Clip edition buttons
self._track_controller.set_undo_button(side_buttons[1])
self._track_controller.set_start_stop_button(side_buttons[4])
self._track_controller.set_lock_button(side_buttons[5])
self._track_controller.set_solo_button(side_buttons[6])
self._track_controller.set_session_record_button(side_buttons[7])
self._scales = self.register_component(ScaleComponent(self._control_surface))
#self._scales.set_enabled(False)
self._scales.set_matrix(matrix)
self._scales.set_osd(self._osd)
self.set_matrix(matrix)
self._on_session_record_changed.subject = self.song()
self._on_swing_amount_changed_in_live.subject = self.song()
self._note_repeat_selector = False
self._note_repeat.set_enabled(False)
def _remove_scale_listeners(self):
try:
self.song().remove_root_note_listener(self.handle_root_note_changed)
except RuntimeError:
pass
try:
self.song().remove_scale_name_listener(self.handle_scale_name_changed)
except RuntimeError:
pass
def _register_scale_listeners(self):
try:
self.song().add_root_note_listener(self.handle_root_note_changed)
except RuntimeError:
pass
try:
self.song().add_scale_name_listener(self.handle_scale_name_changed)
except RuntimeError:
pass
def handle_root_note_changed(self):
self._scales.set_key(self.song().root_note, False, True)
self.update()
def handle_scale_name_changed(self):
self._scales.set_modus(self._scales._modus_names.index(self.song().scale_name), False, True)
self.update()
def set_enabled(self, enabled):
CompoundComponent.set_enabled(self, enabled)
if self._track_controller != None:
self._track_controller.set_enabled(enabled)
feedback_channels = [self.base_channel, self.base_channel + 1, self.base_channel + 2, self.base_channel + 3]
# non_feedback_channel = self.base_channel + 4
self._set_feedback_velocity()
self._control_surface.set_feedback_channels(feedback_channels)
if not enabled:
self._control_surface.release_controlled_track()
self._note_repeat.set_enabled(False)
self._remove_scale_listeners()
else:
self._control_surface.set_controlled_track(self._track_controller.selected_track)
if self._track_controller != None:
self._register_scale_listeners()
self._track_controller._do_implicit_arm(enabled)
self._track_controller.set_enabled(enabled)
if enabled:
self._update_OSD()
self.on_selected_track_changed()
def _set_feedback_velocity(self):
if self.song().session_record:
self._control_surface._c_instance.set_feedback_velocity(self._recordind_feedback_velocity)
else:
self._control_surface._c_instance.set_feedback_velocity(self._normal_feedback_velocity)
@subject_slot('session_record')
def _on_session_record_changed(self):
self._set_feedback_velocity()
@subject_slot('swing_amount')
def _on_swing_amount_changed_in_live(self):
self.update()
def _change_swing_amount_value(self, value):
self._set_swing_amount_value(clamp(self.song().swing_amount + value*0.025, 0.0, 0.99))
def _set_swing_amount_value(self, value):
self.song().swing_amount = value
self._control_surface.show_message("REPEATER Swing amount: " + str(int(self._swing_amount()*100)) + "%")
def _swing_amount(self):
return self.song().swing_amount
def _toggle_note_repeat_selector(self):
self._note_repeat_selector = not self._note_repeat_selector
def _toggle_note_repeater(self):
self._note_repeat.set_enabled(not self._note_repeat.is_enabled())
# Refresh button and its listener
def set_scales_toggle_button(self, button):
assert isinstance(button, (ButtonElement, type(None)))
if (self._scales_toggle_button != None):
self._scales_toggle_button.remove_value_listener(self._scales_toggle)
self._scales_toggle_button = button
if (self._scales_toggle_button != None):
self._scales_toggle_button.add_value_listener(self._scales_toggle, identify_sender=True)
self._scales_toggle_button.turn_off()
# Refresh button and its listener
def set_octave_up_button(self, button=None):
assert isinstance(button, (ButtonElement, type(None)))
if (self._octave_up_button != None):
self._octave_up_button.remove_value_listener(self._scroll_octave_up)
self._octave_up_button = button
if (self._octave_up_button != None):
self._octave_up_button.add_value_listener(self._scroll_octave_up, identify_sender=True)
self._octave_up_button.turn_off()
# Refresh button and its listener
def set_octave_down_button(self, button=None):
assert isinstance(button, (ButtonElement, type(None)))
if (self._octave_down_button != None):
self._octave_down_button.remove_value_listener(self._scroll_octave_down)
self._octave_down_button = button
if (self._octave_down_button != None):
self._octave_down_button.add_value_listener(self._scroll_octave_down, identify_sender=True)
self._octave_down_button.turn_off()
#Enables scale selection mode
def _scales_toggle(self, value, sender):
if self.is_enabled():
if (value is not 0):
self._get_drumrack_device()
if(self._scales.is_drumrack and self._drum_group_device != None):
self._toggle_note_repeat_selector()
self._scales_toggle_button.turn_on()
else:
self._scales.set_enabled(True)
self._osd_mode_backup = self._osd.mode
self._osd.mode = self._osd_mode_backup + ' - Scale'
self._scales_toggle_button.turn_on()
self._scales.update()
else:
self._scales_toggle_button.turn_off()
self._scales.set_enabled(False)
self._osd.mode = self._osd_mode_backup
if(not self._scales.is_quick_scale):
self._note_repeat.set_enabled(False)
self.update()
# Transposes key one octave up
def _scroll_octave_up(self, value, sender):
if self.is_enabled():
if ((not sender.is_momentary()) or (value is not 0)):
if self._can_scroll_octave_up():
self._scales._octave += 1
self.update()
def _can_scroll_octave_up(self):
if(self._scales.is_drumrack):
if self._note_repeat_selector:
return self._scales._octave < 6
else:
return self._scales._octave < 5
else:
return self._scales._octave < 10
# Transposes key one octave down
def _scroll_octave_down(self, value, sender):
if self.is_enabled():
if ((not sender.is_momentary()) or (value is not 0)):
if self._can_scroll_octave_down():
self._scales._octave -= 1
self.update()
def _can_scroll_octave_down(self):
if(self._scales.is_drumrack):
return self._scales._octave > 0
else:
return self._scales._octave > -2
#Handles scale setting and configuration
def _matrix_value_quickscale(self, value, x, y, is_momentary): # matrix buttons listener for advanced mode
if self.is_enabled():
if self._scales.is_drumrack:
if ((value != 0) or (not is_momentary)):
if(y == 0):
if x == 4:
self._change_swing_amount_value(-1)
elif x == 5:
self._change_swing_amount_value(1)
elif x == 6:
pass
elif x == 7:
self._toggle_note_repeater()
self._control_surface.show_message("REPEATER is: " + str("ON" if self._note_repeat.is_enabled() else "OFF"))
elif(y == 1):
if x == 4:
self._set_swing_amount_value(0.0)
elif x == 5:
self._set_swing_amount_value(0.25)
if x == 6:
self._set_swing_amount_value(0.5)
elif x == 7:
self._set_swing_amount_value(0.75)
elif(y == 2):
self._note_repeat.set_freq_index((x-4)*2+y-2)
self._control_surface.show_message("REPEATER Step: " + str(self._note_repeat.freq_name()))
elif(y == 3):
self._note_repeat.set_freq_index((x-4)*2+y-2)
self._control_surface.show_message("REPEATER Step: " + str(self._note_repeat.freq_name()))
self.update()
elif not self._scales.is_enabled() and self._scales.is_quick_scale:
keys = ["C","C#","D","D#","E","F","F#","G","G#","A","A#","B"]
if ((value != 0) or (not is_momentary)):
if self._quick_scale_root==0:
root = -1
selected_key = self._scales._key
selected_modus = self._scales._modus
#Root selection keys
if y == 1 and x < 7 or y == 0 and x in[0, 1, 3, 4, 5]:
if y == 1:
root = [0, 2, 4, 5, 7, 9, 11, 12][x]
self._control_surface.show_message(keys[root]+" "+str(self._scales._modus_names[selected_modus]))
if y == 0 and x < 6:
root = [0, 2, 4, 5, 7, 9, 11, 12][x] + 1
self._control_surface.show_message(keys[root]+" "+str(self._scales._modus_names[selected_modus]))
if root == selected_key: # alternate minor/major
if selected_modus == 0:
selected_modus = self._scales._current_minor_mode
elif selected_modus in [1, 13, 14]:
self._scales._current_minor_mode = selected_modus
selected_modus = 0
elif selected_modus == 11:
selected_modus = 12
elif selected_modus == 12:
selected_modus = 11
self._control_surface.show_message(keys[root]+" "+str(self._scales._modus_names[selected_modus]))
else:
if y == 0 and x == 7: # change scale mode
self.setup_quick_scale_mode()
self.update()
if y == 1 and x == 7: # nav circle of 5th right
root = CIRCLE_OF_FIFTHS[(self.tuple_idx(CIRCLE_OF_FIFTHS, selected_key) + 1 + 12) % 12]
self._control_surface.show_message("circle of 5ths -> "+keys[selected_key]+" "+str(self._scales._modus_names[selected_modus])+" => "+keys[root]+" "+str(self._scales._modus_names[selected_modus]))
if y == 0 and x == 6: # nav circle of 5th left
root = CIRCLE_OF_FIFTHS[(self.tuple_idx(CIRCLE_OF_FIFTHS, selected_key) - 1 + 12) % 12]
self._control_surface.show_message("circle of 5ths <- "+keys[selected_key]+" "+str(self._scales._modus_names[selected_modus])+" => "+keys[root]+" "+str(self._scales._modus_names[selected_modus]))
if y == 0 and x == 2: # relative scale
if selected_modus == 0:
selected_modus = self._scales._current_minor_mode
root = CIRCLE_OF_FIFTHS[(self.tuple_idx(CIRCLE_OF_FIFTHS, selected_key) + 3) % 12]
elif selected_modus in [1, 13, 14]:
self._scales._current_minor_mode = selected_modus
selected_modus = 0
root = CIRCLE_OF_FIFTHS[(self.tuple_idx(CIRCLE_OF_FIFTHS, selected_key) - 3 + 12) % 12]
elif selected_modus == 11:
selected_modus = 12
root = CIRCLE_OF_FIFTHS[(self.tuple_idx(CIRCLE_OF_FIFTHS, selected_key) + 3) % 12]
elif selected_modus == 12:
selected_modus = 11
root = CIRCLE_OF_FIFTHS[(self.tuple_idx(CIRCLE_OF_FIFTHS, selected_key) - 3 + 12) % 12]
self._control_surface.show_message("Relative scale : "+keys[root]+" "+str(self._scales._modus_names[selected_modus]))
if root != -1:
self._scales.set_modus(selected_modus, False)
self._scales.set_key(root, False)
self.update()
elif self._quick_scale_root==1:
if(y == 0):
if x < 7 and self._quick_scales[x] != -1:
self._scales.set_modus(self._quick_scales[x])
self._control_surface.show_message("mode : "+str(self._scales._modus_names[self._scales._modus]))
self.update()
if x == 7:
self.setup_quick_scale_mode()
self.update()
if(y == 1):
if x < 8 and self._quick_scales[x + 7] != -1:
self._scales.set_modus(self._quick_scales[x + 7])
self._control_surface.show_message("mode : "+str(self._scales._modus_names[self._scales._modus]))
self.update()
else:
if(y == 0):
if x == 0:
self._change_swing_amount_value(-1)
elif x == 1:
self._change_swing_amount_value(1)
elif x == 2:
self._set_swing_amount_value(0.0)
elif x == 3:
self._set_swing_amount_value(0.25)
elif x == 4:
self._set_swing_amount_value(0.5)
elif x == 5:
self._set_swing_amount_value(0.75)
elif x == 6:
self._toggle_note_repeater()
self._control_surface.show_message("REPEATER is: " + str("ON" if self._note_repeat.is_enabled() else "OFF"))
elif x == 7:
self.setup_quick_scale_mode()
if(y == 1):
if x in range(8):
self._note_repeat.set_freq_index(x)
self._control_surface.show_message("REPEATER Step: " + str(self._note_repeat.freq_name()))
self.update()
def setup_quick_scale_mode(self):
self._quick_scale_root = ((self._quick_scale_root + 1) % 3)
if self._quick_scale_root==0:
self._control_surface.show_message("quick scale : root")
elif self._quick_scale_root==1:
self._control_surface.show_message("quick scale : modes")
else:
self._control_surface.show_message("quick scale : REPEATER")
def update(self):
if self.is_enabled():
if self._track_controller != None:
self._track_controller.set_enabled(True)
self._update_matrix()
for button in self._remaining_buttons:
button.set_light("DefaultButton.Disabled")
if self._scales_toggle_button != None:
self._scales_toggle_button.set_on_off_values("Note.Scale")
self._scales_toggle_button.turn_off()
if self._octave_up_button != None:
self._octave_up_button.set_on_off_values("Note.Octave")
if(self._can_scroll_octave_up()):
self._octave_up_button.turn_on()
else:
self._octave_up_button.turn_off()
if self._octave_down_button != None:
self._octave_down_button.set_on_off_values("Note.Octave")
if(self._can_scroll_octave_down()):
self._octave_down_button.turn_on()
else:
self._octave_down_button.turn_off()
self._update_OSD()
#self._control_surface.log_message("Swing Amount: " + str(self._swing_amount()))
def set_osd(self, osd):
self._osd = osd
def _update_OSD(self):
if self._osd != None:
if self._scales.is_quick_scale:
self._osd.mode = "Instrument (quick scale)"
else:
self._osd.mode = "Instrument"
self._osd.attributes[0] = MUSICAL_MODES[self._scales._modus * 2]
self._osd.attribute_names[0] = "Scale"
self._osd.attributes[1] = KEY_NAMES[self._scales._key % 12]
self._osd.attribute_names[1] = "Root Note"
self._osd.attributes[2] = self._scales._octave
self._osd.attribute_names[2] = "Octave"
self._osd.attributes[3] = " "
self._osd.attribute_names[3] = " "
self._osd.attributes[4] = " "
self._osd.attribute_names[4] = " "
self._osd.attributes[5] = " "
self._osd.attribute_names[5] = " "
self._osd.attributes[6] = " "
self._osd.attribute_names[6] = " "
self._osd.attributes[7] = " "
self._osd.attribute_names[7] = " "
if self._track_controller.selected_track != None:
self._osd.info[0] = "track : " + self._track_controller.selected_track.name
else:
self._osd.info[0] = " "
self._osd.info[1] = " "
self._osd.update()
# Refresh matrix and its listener
def set_matrix(self, matrix):
self._matrix = matrix
if matrix:
matrix.reset()
if (matrix != self._matrix):
if (self._matrix != None):
self._matrix.remove_value_listener(self._matrix_value_quickscale)
self._matrix = matrix
if (self._matrix != None):
self._matrix.add_value_listener(self._matrix_value_quickscale)
self._update_matrix()
#Listener, setup drumrack scale mode and load the selected scale for Track/Cip (Disabled)
def on_selected_track_changed(self):
if self._track_controller._implicit_arm:
self._get_drumrack_device()
if self._drum_group_device != None:
self._scales.set_drumrack(True)
else:
self._scales.set_drumrack(False)
self._note_repeat.set_enabled(False)
self.update()
def on_selected_scene_changed(self):
if self._track_controller._implicit_arm:
self.update()
#Set the drum rack instrument to _drum_group_device variable, if it exists
def _get_drumrack_device(self):
if self._track_controller.selected_track != None:
track = self._track_controller.selected_track
if(track.devices != None and len(track.devices) > 0):
#device = track.devices[0]
device = self.find_drum_group_device(track)
if(device != None and device.can_have_drum_pads and device.has_drum_pads):
self._drum_group_device = device
else:
self._drum_group_device = None
else:
self._drum_group_device = None
else:
self._drum_group_device = None
#Return the drum device inside the track devices or inside the track chain or None if device is not a Drum
def find_drum_group_device(self, track):
device = find_if(lambda d: d.type == Live.Device.DeviceType.instrument, track.devices)
if device:
if device.can_have_drum_pads:
return device
elif device.can_have_chains:
return find_if(bool, imap(self.find_drum_group_device, device.chains))
else:
return None
def _update_matrix(self):
if not self.is_enabled() or not self._matrix or self._scales.is_enabled():
self._control_surface.release_controlled_track()
# self._control_surface.set_feedback_channels([])
else:
# feedback_channels = [self.base_channel, self.base_channel + 1, self.base_channel + 2, self.base_channel + 3]
non_feedback_channel = self.base_channel + 4
# create array to keep last channel used for note.
note_channel = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ]
#range(128)
for i in range(128):
note_channel[i] = self.base_channel
# Validate if device is drumrack (assign _drum_group_device)
self._get_drumrack_device()
if self._scales.is_drumrack and not self._scales.is_diatonic and not self._scales.is_chromatic:
self._scales.set_drumrack(True)
else:
self._scales.set_drumrack(False)
for button, (x, y) in self._matrix.iterbuttons():
button.use_default_message()
button.set_channel(non_feedback_channel)
#button.force_next_send()
if self._scales.is_drumrack:
#Live.Base.log("InstrumentControllerComponent - OCTAVE: " + str(self._scales._octave))
for button, (x, y) in self._matrix.iterbuttons():
if button:
note = 0
if(x < 4):
note = 16 * (self._scales._octave -1)+ x + 4 * (8 - y)
else:
note = 16 * (self._scales._octave -1) + 32 + x + 4 * (7 - y)
if self._note_repeat_selector:
if(x >= 4 and y<4):
note = -99 #Avoid light errors
if note < 128 and note >= 0:
if self._drum_group_device == None or (self._drum_group_device != None and self._drum_group_device.can_have_drum_pads and self._drum_group_device.has_drum_pads and self._drum_group_device.drum_pads[note].chains):
light = self._getLightForNote(note)
button.set_light(light)
button.set_enabled(False)
button.set_channel(self.base_channel)
button.set_identifier(note)
else:
button.set_light("DrumGroup.PadEmpty")
button.set_enabled(False)
button.set_channel(self.base_channel)
button.set_identifier(note)
elif (note == -99):
button.set_enabled(True)
button.set_channel(non_feedback_channel)
if (y==0):
if(x==4):
button.set_on_off_values("QuickScale.Quant.On", "QuickScale.Quant.Off")
if(not self._swing_amount() ==0.0):
button.turn_on()
else:
button.turn_off()
elif(x ==5):
button.set_on_off_values("QuickScale.Quant.On", "QuickScale.Quant.Off")
if(self._swing_amount() < 0.98):
button.turn_on()
else:
button.turn_off()
elif(x ==6):
button.set_light("DrumGroup.PadEmpty")
elif(x ==7):
button.set_on_off_values("QuickScale.NoteRepeater.On", "QuickScale.NoteRepeater.Off")
if(self._note_repeat.is_enabled()):
button.turn_on()
else:
button.turn_off()
elif(y==1):
if(x ==4):
button.set_on_off_values("QuickScale.Quant.Straight", "DefaultButton.Disabled")
button.turn_on()
elif(x ==5):
button.set_on_off_values("QuickScale.Quant.Swing", "DefaultButton.Disabled")
button.turn_on()
elif(x ==6):
button.set_on_off_values("QuickScale.Quant.Dotted", "DefaultButton.Disabled")
button.turn_on()
elif(x ==7):
button.set_on_off_values("QuickScale.Quant.Flam", "DefaultButton.Disabled")
button.turn_on()
elif(y==2 or y==3):
if(x%2==0):
button.set_on_off_values("QuickScale.Quant.Selected", "QuickScale.Quant.Note")
else:
button.set_on_off_values("QuickScale.Quant.Selected", "QuickScale.Quant.Tripplet")
if ((x-4)*2+y-2) == self._note_repeat.freq_index():
button.turn_on()
else:
button.turn_off()
else:
button.set_light("DrumGroup.PadEmpty")
button.set_enabled(True)
button.set_channel(non_feedback_channel)
#button.force_next_send()
#button.turn_off()
else:
if self._scales.is_quick_scale:
selected_modus = self._scales._modus
selected_key = self._scales._key
if self._quick_scale_root==KEY_MODE:
if selected_modus == 0 or selected_modus == 12:
key_color = "QuickScale.Major.Key"
fifth_button_color = "QuickScale.Major.CircleOfFifths"
mode_button_color = "QuickScale.Major.Mode"
relative_scale_button_color = "QuickScale.Major.RelativeScale"
elif selected_modus == 1 or selected_modus == 11:
key_color = "QuickScale.Minor.Key"
fifth_button_color = "QuickScale.Minor.CircleOfFifths"
mode_button_color = "QuickScale.Minor.Mode"
relative_scale_button_color = "QuickScale.Minor.RelativeScale"
else:
key_color = "QuickScale.Other.Key"
fifth_button_color = "QuickScale.Other.CircleOfFifths"
mode_button_color = "QuickScale.Other.Mode"
relative_scale_button_color = "QuickScale.Other.RelativeScale"
# circle of 5th nav right
button = self._matrix.get_button(7, 1)
button.set_light(fifth_button_color)
# circle of 5th nav left
button = self._matrix.get_button(6, 0)
button.set_light(fifth_button_color)
# mode button
button = self._matrix.get_button(7, 0)
button.set_light(mode_button_color)
# relative scale button
button = self._matrix.get_button(2, 0)
button.set_light(relative_scale_button_color)
for x in [0, 1, 3, 4, 5]:
button = self._matrix.get_button(x, 0)
button.set_enabled(True)
button.set_on_off_values(key_color)
#button.force_next_send()
if [0, 2, 4, 5, 7, 9, 11, 12][x] + 1 == selected_key:
button.turn_on()
else:
button.turn_off()
for x in [0, 1, 2, 3, 4, 5, 6]:
button = self._matrix.get_button(x, 1)
button.set_enabled(True)
button.set_on_off_values(key_color)
#button.force_next_send()
if [0, 2, 4, 5, 7, 9, 11, 12][x] == selected_key:
button.turn_on()
else:
button.turn_off()
elif self._quick_scale_root==SCALE_TYPE_MODE:
button = self._matrix.get_button(7, 0)
button.set_light("QuickScale.Major.Mode")
for x in range(7):
button = self._matrix.get_button(x, 0)
button.set_enabled(True)
if self._quick_scales[x] != -1:
button.set_on_off_values("QuickScale.Modus")
if self._quick_scales[x] == selected_modus:
button.turn_on()
else:
button.turn_off()
else:
button.set_light("DefaultButton.Disabled")
for x in range(8):
button = self._matrix.get_button(x, 1)
button.set_enabled(True)
if self._quick_scales[x + 7] != -1:
button.set_on_off_values("QuickScale.Modus")
else:
button.set_on_off_values("DefaultButton.Disabled", "DefaultButton.Disabled")
#button.force_next_send()
if self._quick_scales[x + 7] == selected_modus:
button.turn_on()
else:
button.turn_off()
else: #NOTE REPEATER
button = self._matrix.get_button(7, 0)
button.set_light("QuickScale.Quant.Mode")
for x in range(7):
button = self._matrix.get_button(x, 0)
button.set_enabled(True)
if(x ==0):
button.set_on_off_values("QuickScale.Quant.On", "QuickScale.Quant.Off")
if(not self._swing_amount() ==0.0):
button.turn_on()
else:
button.turn_off()
elif(x ==1):
button.set_on_off_values("QuickScale.Quant.On", "QuickScale.Quant.Off")
if(self._swing_amount() < 0.98):
button.turn_on()
else:
button.turn_off()
elif(x ==2):
button.set_on_off_values("QuickScale.Quant.Straight", "DefaultButton.Disabled")
button.turn_on()
elif(x ==3):
button.set_on_off_values("QuickScale.Quant.Swing", "DefaultButton.Disabled")
button.turn_on()
elif(x ==4):
button.set_on_off_values("QuickScale.Quant.Dotted", "DefaultButton.Disabled")
button.turn_on()
elif(x ==5):
button.set_on_off_values("QuickScale.Quant.Flam", "DefaultButton.Disabled")
button.turn_on()
elif(x ==6):
button.set_on_off_values("QuickScale.NoteRepeater.On", "QuickScale.NoteRepeater.Off")
if(self._note_repeat.is_enabled()):
button.turn_on()
else:
button.turn_off()
for x in range(8):
button = self._matrix.get_button(x, 1)
button.set_enabled(True)
if(x%2==0):
button.set_on_off_values("QuickScale.Quant.Selected", "QuickScale.Quant.Note")
else:
button.set_on_off_values("QuickScale.Quant.Selected", "QuickScale.Quant.Tripplet")
if (x) == self._note_repeat.freq_index():
button.turn_on()
else:
button.turn_off()
pattern = self._scales.get_pattern()
max_j = self._matrix.width() - 1
a = 0
if self._scales.is_chromatic:
a= 63
for button, (i, j) in self._matrix.iterbuttons():
if button and (not self._scales.is_quick_scale or j > 1):
a = a +1
note_info = pattern.note(i, max_j - j)
if note_info.index != None:
if note_info.root:
button.set_light("Note.Pads.Root")
elif note_info.highlight:
button.set_light("Note.Pads.Highlight")
elif note_info.in_scale:
button.set_light("Note.Pads.InScale")
elif note_info.valid:
button.set_light("Note.Pads.OutOfScale")
else:
button.set_light("Note.Pads.Invalid")
button.set_enabled(False)
button.set_channel(note_channel[note_info.index])
# comment the line above and use the one below if you want instrument controller to use one channel instead of 3
# button.set_channel(note_channel[0])
button.set_identifier(note_info.index)
if(note_channel[note_info.index]<15):
note_channel[note_info.index] = note_channel[note_info.index] + 1
else:
button.set_channel(non_feedback_channel)
button.set_identifier(a)
button.set_light("Note.Pads.Invalid")
button.set_enabled(True)
button.force_next_send()
for button in self._side_buttons:
button.use_default_message()
button.set_channel(non_feedback_channel)
button.set_enabled(True)
button.force_next_send()
def _getLightForNote(self, note):
return "DrumGroup.PadFilled"
if (note<4):
return "DrumGroup.PadFilled1"
elif (note<20):
return "DrumGroup.PadFilled2"
elif (note<36):
return "DrumGroup.PadFilled3"
elif (note<52):
return "DrumGroup.PadFilled4"
elif (note<68):
return "DrumGroup.PadFilled5"
elif (note<84):
return "DrumGroup.PadFilled1"
elif (note<100):
return "DrumGroup.PadFilled2"
elif (note<116):
return "DrumGroup.PadFilled3"
else:
return "DrumGroup.PadFilled4"
def tuple_idx(self, target_tuple, obj):
for i in xrange(0, len(target_tuple)):
if (target_tuple[i] == obj):
return i
return(False)