-
Notifications
You must be signed in to change notification settings - Fork 82
/
SpecialProSessionComponent.py
1456 lines (1248 loc) · 49.4 KB
/
SpecialProSessionComponent.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
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# imported from https://github.com/poltow/Launchpad97
import Live
#import traceback
from .ClipSlotMK2 import ClipSlotMK2
from _Framework.SceneComponent import SceneComponent
from _Framework.ButtonElement import ButtonElement
from _Framework.SubjectSlot import subject_slot
from _Framework.ClipSlotComponent import ClipSlotComponent
from _Framework import Task
from _Framework.Util import in_range
from _Framework.SubjectSlot import subject_slot_group
import time
from .SpecialProSessionRecordingComponent import SpecialProSessionRecordingComponent
from .SpecialSessionComponent import SpecialSessionComponent
from .TargetTrackComponent import TargetTrackComponent
_Q = Live.Song.Quantization
Rec_Q = Live.Song.RecordingQuantization
try:
xrange
except NameError:
xrange = range
REC_QNTZ_RATES = [
Rec_Q.rec_q_quarter,
Rec_Q.rec_q_eight,
Rec_Q.rec_q_eight_triplet,
Rec_Q.rec_q_eight_eight_triplet,
Rec_Q.rec_q_sixtenth,
Rec_Q.rec_q_sixtenth_triplet,
Rec_Q.rec_q_sixtenth_sixtenth_triplet,
Rec_Q.rec_q_thirtysecond]
REC_QNTZ_FIXED_RATES = [
Rec_Q.rec_q_quarter,
Rec_Q.rec_q_eight,
Rec_Q.rec_q_eight_triplet,
Rec_Q.rec_q_sixtenth,
Rec_Q.rec_q_sixtenth_triplet]
REC_QNTZ_NAMES = ('1/4', '1/8', '1/8t', '1/8+t', '1/16', '1/16t', '1/16+t', '1/32')
REC_QNTZ_RATES_LEN = len(REC_QNTZ_RATES)
LAUNCH_QNTZ_RATES = [
_Q.q_8_bars,
_Q.q_4_bars,
_Q.q_2_bars,
_Q.q_bar,
_Q.q_half,
_Q.q_half_triplet,
_Q.q_quarter,
_Q.q_quarter_triplet,
_Q.q_eight,
_Q.q_eight_triplet,
_Q.q_sixtenth,
_Q.q_sixtenth_triplet,
_Q.q_thirtytwoth
]
LAUNCH_QNTZ_FIXED_RATES = [
_Q.q_2_bars,
_Q.q_bar,
_Q.q_quarter,
_Q.q_eight,
_Q.q_sixtenth
]
LAUNCH_QNTZ_NAMES = ('8 Bars', '4 Bars', '2 Bars', '1 Bar', '1/2', '1/2t', '1/4', '1/4t', '1/8', '1/8t', '1/16', '1/16t', '1/32')
LAUNCH_QNTZ_RATES_LEN = len(LAUNCH_QNTZ_RATES)
LENGTH_OPTION_NAMES = ('1 Beat', '1 Bar', '2 Bars', '4 Bars', '8 Bars')
FIXED_LENGTH_VALUES = [0.25, 1, 2, 4, 8]
MAX_FIXED_LENGTH = 31
#SHIFT_COLORS = ('TapSet.One', 'TapSet.Two', 'TapSet.Three', 'TapSet.Four', 'TapSet.Five', 'TapSet.Six', 'TapSet.Seven',
# 'TapSet.Six', 'TapSet.Five', 'TapSet.Four', 'TapSet.Three', 'TapSet.Two')
#SHIFT_COLORS_LEN = len(SHIFT_COLORS)
#TAP_COLORS = ('ShiftSet.One', 'ShiftSet.Two', 'ShiftSet.Three', 'ShiftSet.Two')
#TAP_COLORS_LEN = len(TAP_COLORS)
LONG_PRESS = 0.5
SHORT_PRESS = 0.25
class SpecialClipSlotComponent(ClipSlotComponent):
quantization_component = None
device = True
def __init__(self, should_arm = None, *a, **k):
super(SpecialClipSlotComponent, self).__init__(*a, **k)
def _set_parent(self, parent):
self._parent = parent
def _do_select_clip(self, clip_slot):
super(SpecialClipSlotComponent, self)._do_select_clip(clip_slot)
if self._clip_slot is not None:
clip = clip_slot.clip
if not self.application().view.is_view_visible('Detail'):
self.application().view.show_view('Detail')
self.device = True
if clip:
if not self.application().view.is_view_visible('Detail/Clip') and self.device and self._isSelecting():
self.application().view.show_view('Detail/Clip')
else:
self.device = False
if not self.application().view.is_view_visible('Detail/DeviceChain') and not self.device and self._isSelecting():
self.application().view.show_view('Detail/DeviceChain')
self.device = not self.device
def _isSelecting(self):
if not self._is_shifting():
return False
if self._is_copypasting():
return False
if self._is_quantizing():
return False
if self._is_doubling():
return False
if self._is_deleting():
return False
if self._is_duplicating():
return False
return True
def _do_duplicate_clip(self):
if self._clip_slot:
slot = self._clip_slot
should_launch = True
song = self._get_song()
try:
clip = slot.clip if slot is not None else None
if clip is not None:
track = slot.canonical_parent
view = song.view
try:
start_duplicate = should_launch and clip.is_playing
target_index = list(track.clip_slots).index(slot)
destination_index = track.duplicate_clip_slot(target_index)
view.highlighted_clip_slot = track.clip_slots[destination_index]
view.detail_clip = view.highlighted_clip_slot.clip
if start_duplicate:
view.highlighted_clip_slot.fire(force_legato=True, launch_quantization=_Q.q_no_q)
self._print('Clip duplicated')
except Live.Base.LimitationError:
pass
except RuntimeError:
pass
except (AttributeError, TypeError):
pass
def _do_copypaste_clip(self, clip_slot):
if self._should_copy() and clip_slot.has_clip:
self._set_slot_copy_buffer(clip_slot)
else:
if (not self._should_copy()):
try:
self._get_slot_copy_buffer().duplicate_clip_to(clip_slot)
except RuntimeError:
pass
def _do_double_loop(self, clip_slot):
self._do_select_clip(clip_slot)
clip = self.song().view.detail_clip
if self._can_duplicate_loop(clip):
try:
self._get_song().view.detail_clip.duplicate_loop()
self._print('Clip length doubled to ' + str(clip.length))
except (AttributeError, TypeError):
pass
except RuntimeError:
pass
def _can_duplicate_loop(self, clip):
return clip and clip.is_midi_clip
def _do_quantize_clip(self, clip_slot):
if self._clip_slot and self._clip_slot.has_clip:
clip = clip_slot.clip
assert isinstance(clip, Live.Clip.Clip)
clip.quantize(self._get_record_quantization(), 1.0)
self._print('Clip quantized to ' + str(REC_QNTZ_NAMES[REC_QNTZ_RATES.index(self._get_record_quantization())]))
def _do_delete_clip(self):
if self._clip_slot and self._clip_slot.has_clip:
self._clip_slot.delete_clip()
self._print('Clip deleted')
def _do_track_arm(self):
if self._clip_slot:
track = self._clip_slot.canonical_parent
if track.can_be_armed and not track.arm:
if self._get_song().exclusive_arm:
for t in self._get_song().tracks:
if t.can_be_armed and t.arm:
t.arm = False
track.arm = True
if self._get_song().view.selected_track != track:
self._get_song().view.selected_track = track
if self._clip_slot.has_clip:
self._get_song().session_record = not self._get_song().session_record
def _do_launch_clip(self, value):
if(not self._is_fixed_length_on()):
super(SpecialClipSlotComponent, self)._do_launch_clip(value)
else:
button = self._launch_button_value.subject # MATRIX BUTTON
launch_pressed = value or not button.is_momentary() # LAUNCH MSG
quant = self._get_launch_quant()
if not self.has_clip(): #Have CLIP
self._has_fired_slot = True
if button.is_momentary():
if(not self.has_clip()):
self._clip_slot.fire(record_length=self._get_fixed_length(), launch_quantization=quant)
else:
self._clip_slot.clip.set_fire_button_state(value != 0)
elif launch_pressed:
if(not self.has_clip()):
self._clip_slot.fire(record_length=self._get_fixed_length(), launch_quantization=quant)
else:
self._clip_slot.fire()
if launch_pressed and self.song().select_on_launch:
self.song().view.highlighted_clip_slot = self._clip_slot
self.application().view.show_view('Detail/Clip')
def _feedback_value(self):
ret = super(SpecialClipSlotComponent, self)._feedback_value()
if self._clip_slot and ret == 'ProSession.ClipStopped':
track = self._clip_slot.canonical_parent
if track.is_foldable:
if track.fold_state == 0:
return 'ProSession.ClipUnFoldedTrack'
else:
return 'ProSession.ClipFoldedTrack'
return ret
def _is_shifting(self):
return self._parent._is_shifting()
def _is_copypasting(self):
return self._parent._is_copypasting()
def _is_quantizing(self):
return self._parent._is_quantizing()
def _is_doubling(self):
return self._parent._is_doubling()
def _is_deleting(self):
return self._parent._is_deleting()
def _is_duplicating(self):
return self._parent._is_duplicating()
def _get_song(self):
return self._parent._get_song()
def _get_record_quantization(self):
return self._parent._get_record_quantization()
def _is_fixed_length_on(self):
return self._parent._is_fixed_length_on()
def _get_launch_quant(self):
return self._parent._get_launch_quant()
def _get_fixed_length(self):
return self._parent._get_fixed_length()
def _is_pro_mode_on(self):
return self._parent._is_pro_mode_on()
def _should_arm(self):
return self._parent._should_arm()
def _should_copy(self):
return self._parent._should_copy()
def _set_slot_copy_buffer(self, slot):
self._parent._set_slot_copy_buffer(slot)
def _get_slot_copy_buffer(self):
return self._parent._get_slot_copy_buffer()
def _print(self, msg):
self._parent._print(str(msg))
@subject_slot('value')
def _launch_button_value(self, value):
if self._is_pro_mode_on():
if self.is_enabled():
if self._is_deleting() and value:
if self._is_shifting():
self._parent._do_delete_scene(self._parent)
else:
self._do_delete_clip()
elif self._is_duplicating() and value:
if self._is_shifting():
self._parent._do_duplicate_scene()
else:
self._do_duplicate_clip()
elif self._is_copypasting() and value:
if self._is_shifting():
self._parent._do_launch_scene(value)
else:
self._do_copypaste_clip(self._clip_slot)
elif self._is_doubling() and value:
if self._is_shifting():
self._parent._do_capture_and_insert_scene()
else:
self._do_double_loop(self._clip_slot)
elif self._is_quantizing() and value:
if self._is_shifting():
self._parent._do_create_scene()
else:
self._do_quantize_clip(self._clip_slot)
elif self._is_shifting() and value:
self._do_select_clip(self._clip_slot)
else:
if value:
if self._should_arm():
self._do_track_arm()
self._do_launch_clip(value)
else:
super(SpecialClipSlotComponent, self)._launch_button_value(value)
class SpecialSceneComponent(SceneComponent):
clip_slot_component_type = SpecialClipSlotComponent
def __init__(self, *a, **k):
super(SpecialSceneComponent, self).__init__(*a, **k)
def _set_parent(self, parent):
self._parent = parent
def _is_shifting(self):
return self._parent._is_shifting()
def _is_copypasting(self):
return self._parent._is_copypasting()
def _is_deleting(self):
return self._parent._is_deleting()
def _is_duplicating(self):
return self._parent._is_duplicating()
def _is_doubling(self):
return self._parent._is_doubling()
def _is_quantizing(self):
return self._parent._is_quantizing()
def _get_song(self):
return self._parent._get_song()
def _get_record_quantization(self):
return self._parent._get_record_quantization()
def _should_arm(self):
return self._parent._should_arm()
def _is_fixed_length_on(self):
return self._parent._is_fixed_length_on()
def _get_fixed_length(self):
return self._parent._get_fixed_length()
def _get_launch_quant(self):
return self._parent._get_launch_quant()
def _is_pro_mode_on(self):
return self._parent._is_pro_mode_on()
def _set_slot_copy_buffer(self, slot):
self._parent._set_slot_copy_buffer(slot)
def _get_slot_copy_buffer(self):
return self._parent._get_slot_copy_buffer()
def _should_copy(self):
return self._parent._should_copy()
def _do_delete_scene(self, scene_for_overrides):
try:
if self._scene:
song = self.song()
song.delete_scene(list(song.scenes).index(self._scene))
self._print('Scene deleted')
except RuntimeError:
pass
def _do_duplicate_scene(self):
try:
song = self._get_song()
song.duplicate_scene(list(song.scenes).index(self._scene))
self._print('Scene duplicated')
except Live.Base.LimitationError:
pass
except RuntimeError:
pass
except IndexError:
pass
def _do_launch_scene(self, value):
launched = False
if value != 0:
self._scene.fire()
launched = True
if launched and self.song().select_on_launch:
self.song().view.selected_scene = self._scene
def _do_create_scene(self):
try:
song = self._get_song()
new_scene_index = list(song.scenes).index(self._scene) + 1
song.view.selected_scene = song.create_scene(new_scene_index)
self._print('Create scene ' + self.song().view.selected_scene.name)
except Live.Base.LimitationError:
pass
except RuntimeError:
pass
except IndexError:
pass
def _do_capture_and_insert_scene(self):
try:
song = self.song()
song.view.selected_scene = self._scene
song.capture_and_insert_scene(Live.Song.CaptureMode.all)
self._print('Captured to scene ' + self.song().view.selected_scene.name)
except Live.Base.LimitationError:
pass
except RuntimeError:
pass
except IndexError:
pass
def _print(self, msg):
self._parent._print(str(msg))
class SpecialProSessionComponent(SpecialSessionComponent):
scene_component_type = SpecialSceneComponent
""" Special session subclass that handles ConfigurableButtons """
def __init__(self, num_tracks, num_scenes, stop_clip_buttons, side_buttons, control_surface, main_selector, livesong = None):
self._pro_mode_on = False
if control_surface._mk2_rgb:
#use custom clip colour coding : blink and pulse for trig and play
SceneComponent.clip_slot_component_type = ClipSlotMK2
SpecialSessionComponent.__init__(self, num_tracks = num_tracks, num_scenes = num_scenes, stop_clip_buttons = stop_clip_buttons, control_surface= control_surface, main_selector= main_selector)
self._side_buttons = side_buttons
self._osd = None
self._song = livesong
self._slot_copy_buffer = None
self._shift_button = None
self._click_button = None
self._undo_button = None
self._delete_button = None
self._duplicate_button = None
self._double_button = None
self._quantize_button = None
self._record_button = None
self._shift_pressed = False
self._delete_pressed = False
self._duplicate_pressed = False
self._double_pressed = False
self._quantize_pressed = False
self._click_pressed = False
self._record_pressed = False
self._record_mode_on = False
self._is_arming = False
self._armed_track_count=0
self._last_undo_time = time.time()
self._last_shift_time = time.time()
self._last_quantize_time = time.time()
self._last_click_time = time.time()
self._last_fixed_time = time.time()
self._last_solo_time = time.time()
self._last_mute_time = time.time()
self._last_record_time = time.time()
self._end_undo_step_task = self._tasks.add(Task.sequence(Task.wait(1.5), Task.run(self.song().end_undo_step)))
self._end_undo_step_task.kill()
self._launch_quantization = self._get_song().clip_trigger_quantization
self._launch_quantization_on = self._launch_quantization !=_Q.q_no_q
self._song.add_clip_trigger_quantization_listener(self._on_clip_trigger_quantization_changed_in_live)
if(self._get_song().midi_recording_quantization== Rec_Q.rec_q_no_q):
self._record_quantization = Rec_Q.rec_q_sixtenth
else:
self._record_quantization = self._get_song().midi_recording_quantization
self._record_quantization_on = self._get_song().midi_recording_quantization != Rec_Q.rec_q_no_q
self._song.add_midi_recording_quantization_listener(self._on_record_quantization_changed_in_live)
self.song().add_session_record_listener(self._on_session_record_changed_in_live)
self._fixed_length = 1
self._fixed_length_on = False
self._tap_color_index = 0
self._shift_color_index = 0
self._tap_button = None
self._song.add_metronome_listener(self._on_metronome_status_changed)
self._session_record = SpecialProSessionRecordingComponent(target_track_component = TargetTrackComponent(), control_surface = self._control_surface)
self._session_record._set_parent(self)
if self._control_surface._mk2_rgb:
from .ColorsMK2 import CLIP_COLOR_TABLE, RGB_COLOR_TABLE
self.set_rgb_mode(CLIP_COLOR_TABLE, RGB_COLOR_TABLE)
self._setup_actions_buttons()
self._set_undo_button(self._side_buttons[0])
#INSTANT: UNDO - LONG: REDO
self._set_shift_button(self._side_buttons[1])
#SHIFT BTN
# PAD: SEL/VIEW - DOUBLE: CLEAR VIEW - LROW: LAUNCH QUANT
self._set_click_button(self._side_buttons[2])
# +PAD: COPY/PASTE CLIP +SHIFT PAD: LAUNCH SCN??? - DOUBLE: CLIC ON/OFF - LROW: TEMPO FUNCTIONS
self._set_quantize_button(self._side_buttons[3])
# +PAD: QUANT +SHIFT PAD: CREATE SCN??? - DOUBLE: REC QUANT ON/OFF - LROW: REC QUANT
self._set_double_button(self._side_buttons[4])
# +PAD: DOUBLE_MIDI +SHIFT PAD: CAPTURE_INS SCN??? - DOUBLE: FIX LENGTH QUANT ON/OFF - LROW: FIX LENGTH QUANT
self._set_delete_button(self._side_buttons[5])
# +PAD: DELETE CLIP - +SHIFT PAD: DELETE SCN - DOUBLE: UNMUTE - LROW: MUTE TRACK
self._set_duplicate_button(self._side_buttons[6])
# +PAD: DUPLICATE - +SHIFT PAD: DUPLICATE SCN - DOUBLE: UNSOLO - LROW: SOLO TRACK
self._set_record_button(self._side_buttons[7])
# +PAD: ARM+FIRE CLIP - SHIFT PAD: N/A - INSTANT: SES REC ON/OFF - DOUBLE: N/A - LROW: ARM TRACK
self.update()
def disconnect(self):
self._song.remove_clip_trigger_quantization_listener(self._on_clip_trigger_quantization_changed_in_live)
self._song.remove_midi_recording_quantization_listener(self._on_record_quantization_changed_in_live)
self.song().remove_session_record_listener(self._on_session_record_changed_in_live)
self._end_undo_step_task.kill()
self._end_undo_step_task = None
self._record_quantization_on = False
self._shift_pressed = False
self._delete_pressed = False
self._duplicate_pressed = False
self._double_pressed = False
self._quantize_pressed = False
self._slot_copy_buffer = None
self._click_button = None
self._undo_button = None
self._shift_button = None
self._delete_button = None
self._duplicate_button = None
self._double_button = None
self._quantize_button = None
self._record_button = None
self._tap_button = None
def _is_shifting(self):
return self._shift_pressed
def _is_copypasting(self):
return self._click_pressed
def _is_deleting(self):
return self._delete_pressed
def _is_duplicating(self):
return self._duplicate_pressed
def _is_doubling(self):
return self._double_pressed
def _is_quantizing(self):
return self._quantize_pressed
def _is_fixed_length_on(self):
return self._fixed_length_on
def _should_arm(self):
return self._record_pressed or self._record_mode_on
def _is_enabled(self):
return self.is_enabled()
def _is_pro_mode_on(self):
return self._pro_mode_on
def _set_pro_mode_on(self, pro_mode_on):
self._pro_mode_on = pro_mode_on
def _set_slot_copy_buffer(self, slot):
self._slot_copy_buffer = slot
def _get_slot_copy_buffer(self):
return self._slot_copy_buffer
def _should_copy(self):
return self._slot_copy_buffer is None
def _get_song(self):
return self._song
def _get_record_quantization(self):
return self._record_quantization
def _setup_actions_buttons(self):
for scene_index in xrange(self._num_scenes):
scene = self.scene(scene_index)
scene._set_parent(self)
for track_index in xrange(self._num_tracks):
slot = scene.clip_slot(track_index)
slot._set_parent(scene)
# UNDO button and its listener
def _set_undo_button(self, button=None):
assert isinstance(button, (ButtonElement, type(None)))
if (self._undo_button != None):
self._undo_button.remove_value_listener(self._undo_button_value)
self._undo_button = button
if (self._undo_button != None):
self._undo_button.add_value_listener(self._undo_button_value, identify_sender=True)
self._undo_button.turn_off()
def _undo_button_value(self, value, sender):
assert (value in range(128))
if self.is_enabled() and self._is_pro_mode_on() and self._undo_button != None:
now = time.time()
if ((value is not 0) or (not sender.is_momentary())):
self._last_undo_time = now
else:
if now - self._last_undo_time < LONG_PRESS:
if self.song().can_undo:
self.song().undo()
self._print("Undo")
else:
self._print("Can't Undo!")
else:
if self.song().can_redo:
self.song().redo()
self._print("Redo")
else:
self._print("Can`t Redo!")
self._update_undo_button()
def _update_undo_button(self):
if self.is_enabled() and self._is_pro_mode_on() and self._undo_button != None:
self._undo_button.set_on_off_values("ProSession.Undo")
if self.song().can_undo:
self._undo_button.turn_on()
else:
self._undo_button.turn_off()
# SHIFT Button
def _set_shift_button(self, button=None):
assert (isinstance(button, (ButtonElement, type(None))))
if (self._shift_button != button):
if (self._shift_button != None):
self._shift_button.remove_value_listener(self._shift_button_value)
self._shift_button = button
if (self._shift_button != None):
assert isinstance(button, ButtonElement)
self._shift_button.add_value_listener(self._shift_button_value, identify_sender=True)
self._shift_button.turn_off()
def _shift_button_value(self, value, sender):
assert (value in range(128))
if self.is_enabled() and self._is_pro_mode_on() and self._shift_button != None:
if ((value is not 0) or (not sender.is_momentary())):
self._print("Select clip - [ Set launch quantization -> now: "+ self._get_launch_quant_msg() +" ]")
self._shift_pressed = True
else:
self._shift_pressed = False
if (time.time() - self._last_shift_time) < SHORT_PRESS:
self.application().view.hide_view('Detail')
self._last_shift_time = time.time()
self.update()
def _update_shift_button(self):
if self.is_enabled() and self._is_pro_mode_on() and self._shift_button != None:
self._shift_button.set_on_off_values("ProSession.Shift")
if self._shift_pressed or self._launch_quantization_on:
self._shift_button.turn_on()
else:
self._shift_button.turn_off()
def _increment_launch_qntz_value(self):
if(self._launch_quantization_on):
quant_idx = LAUNCH_QNTZ_RATES.index(self._launch_quantization)
if(quant_idx<LAUNCH_QNTZ_RATES_LEN-1):
self.song().clip_trigger_quantization = LAUNCH_QNTZ_RATES[quant_idx+1]
def _decrement_launch_qntz_value(self):
if(self._launch_quantization_on):
quant_idx = LAUNCH_QNTZ_RATES.index(self._launch_quantization)
if(quant_idx>0):
self.song().clip_trigger_quantization = LAUNCH_QNTZ_RATES[quant_idx-1]
# CLICK button and its listener
def _set_click_button(self, button=None):
assert isinstance(button, (ButtonElement, type(None)))
if self._click_button != None:
self._click_button.remove_value_listener(self._click_value)
self._click_button = button
if self._click_button != None:
self._click_button.add_value_listener(self._click_value, identify_sender=True)
self._click_button.turn_off()
def _click_value(self, value, sender):
assert (value in range(128))
if self.is_enabled() and self._is_pro_mode_on() and self._click_button != None:
if ((value is not 0) or (not sender.is_momentary())):
self._click_pressed = True
if self._shift_pressed:
self._print("Launch scene - [ Tempo ]")
else:
self._print("Copy/paste clip - [ Tempo ]")
else:
self._click_pressed = False
self._tap_button = None
self._slot_copy_buffer = None
if (time.time() - self._last_click_time) < SHORT_PRESS:
self.song().metronome = not self.song().metronome
if self.song().metronome :
self._print("Metronome On")
else:
self._print("Metronome Off")
self._last_click_time = time.time()
self.update()
def _tap_tempo_value(self, value):
if self.is_enabled() and self._is_pro_mode_on():
if not self._end_undo_step_task.is_running:
self.song().begin_undo_step()
self._end_undo_step_task.restart()
self.song().tap_tempo()
def _update_click_button(self):
if self.is_enabled() and self._is_pro_mode_on() and self._click_button != None:
self._click_button.set_on_off_values("ProSession.Click")
if self.song().metronome:
self._click_button.turn_on()
else:
self._click_button.turn_off()
def _on_metronome_status_changed(self):
if self.is_enabled() and self._is_pro_mode_on():
self._update_click_button()
def _nudge_down(self, value):
if self.is_enabled() and self._is_pro_mode_on():
self.song().nudge_down = value > 0
def _nudge_up(self, value):
if self.is_enabled() and self._is_pro_mode_on():
self.song().nudge_up = value > 0
def _change_tempo(self, tempo_delta):
if self.is_enabled() and self._is_pro_mode_on():
new_tempo = int(self.song().tempo + tempo_delta)
if(new_tempo >=1 and new_tempo <999 ):
self.song().tempo = new_tempo
# QUANTIZE button and its listener
def _set_quantize_button(self, button=None):
assert (isinstance(button, (ButtonElement, type(None))))
if (self._quantize_button != button):
if (self._quantize_button != None):
self._quantize_button.remove_value_listener(self._quantize_button_value)
self._quantize_button = button
if (self._quantize_button != None):
assert isinstance(button, ButtonElement)
self._quantize_button.add_value_listener(self._quantize_button_value, identify_sender=True)
self._quantize_button.turn_off()
def _quantize_button_value(self, value, sender):
assert (value in range(128))
if self.is_enabled() and self._is_pro_mode_on() and self._quantize_button != None:
if ((value is not 0) or (not sender.is_momentary())):
self._quantize_pressed = True
if self._shift_pressed:
self._print("Create Scene - [ Record quantization -> now: "+ self._get_record_quant_msg() +" ]")
else:
self._print("Quantize clip - [ Record quantization -> now: "+ self._get_record_quant_msg() +" ]")
else:
self._quantize_pressed = False
if (time.time() - self._last_quantize_time) < SHORT_PRESS:
self._record_quantization_on = not self._record_quantization_on
self.song().midi_recording_quantization = self._record_quantization if self._record_quantization_on else Rec_Q.rec_q_no_q
self._last_quantize_time = time.time()
self.update()
def _update_quantize_button(self):
if self.is_enabled() and self._is_pro_mode_on() and self._quantize_button != None:
self._quantize_button.set_on_off_values("ProSession.Quantize")
if self._record_quantization_on:
self._quantize_button.turn_on()
else:
self._quantize_button.turn_off()
def _increment_rec_qntz_value(self):
rec_quant_value = self._get_song().midi_recording_quantization
quant_on = rec_quant_value !=Rec_Q.rec_q_no_q
if(quant_on):
quant_idx = REC_QNTZ_RATES.index(rec_quant_value)
if(quant_idx<REC_QNTZ_RATES_LEN-1):
self.song().midi_recording_quantization = REC_QNTZ_RATES[quant_idx+1]
def _decrement_rec_qntz_value(self):
rec_quant_value = self._get_song().midi_recording_quantization
quant_on = rec_quant_value !=Rec_Q.rec_q_no_q
if(quant_on):
quant_idx = REC_QNTZ_RATES.index(rec_quant_value)
if(quant_idx>0):
self.song().midi_recording_quantization = REC_QNTZ_RATES[quant_idx-1]
def _on_record_quantization_changed_in_live(self):
rec_quant_value = self._get_song().midi_recording_quantization
quant_on = rec_quant_value !=Rec_Q.rec_q_no_q
if quant_on:
self._record_quantization = rec_quant_value
self._record_quantization_on = quant_on
self._print("Record quantization: " + self._get_record_quant_msg())
self.update()
def _get_record_quant_msg(self):
if(self._record_quantization_on):
return ("ON: " + str(REC_QNTZ_NAMES[REC_QNTZ_RATES.index(self._record_quantization)]))
else:
return "OFF"
def _on_clip_trigger_quantization_changed_in_live(self):
launch_quant_value = self._get_song().clip_trigger_quantization
quant_on = launch_quant_value !=_Q.q_no_q
if quant_on:
self._launch_quantization = launch_quant_value
self._launch_quantization_on = quant_on
self._print("Launch quantization: " + self._get_launch_quant_msg())
self.update()
def _on_session_record_changed_in_live(self):
self.update()
def _get_launch_quant_msg(self):
if(self._launch_quantization_on):
return ("ON: " + str(LAUNCH_QNTZ_NAMES[LAUNCH_QNTZ_RATES.index(self._launch_quantization)]))
else:
return "OFF"
# DOUBLE button and its listener
def _set_double_button(self, button=None):
assert (isinstance(button, (ButtonElement, type(None))))
if (self._double_button != button):
if (self._double_button != None):
self._double_button.remove_value_listener(self._double_button_value)
self._double_button = button
if (self._double_button != None):
assert isinstance(button, ButtonElement)
self._double_button.add_value_listener(self._double_button_value, identify_sender=True)
self._double_button.turn_off()
def _double_button_value(self, value, sender):
assert (value in range(128))
if self.is_enabled() and self._is_pro_mode_on() and self._double_button != None:
if ((value is not 0) or (not sender.is_momentary())):
self._double_pressed = True
if self._shift_pressed:
self._print("Capture scene - [ Clip fixed length recording -> now: "+ self._get_fixed_length_msg() +" ]")
else:
self._print("Double midi clip - [ Clip fixed length recording -> now: "+ self._get_fixed_length_msg() +" ]")
else:
self._double_pressed = False
if (time.time() - self._last_fixed_time) < SHORT_PRESS:
self._fixed_length_on = not self._fixed_length_on
self._display_fixed_length_info()
self._last_fixed_time = time.time()
self.update()
def _update_double_button(self):
if self.is_enabled() and self._is_pro_mode_on() and self._double_button != None:
self._double_button.set_on_off_values("ProSession.Double")
if self._fixed_length_on:
self._double_button.turn_on()
else:
self._double_button.turn_off()
def _increment_fixed_length_value(self):
if(self._fixed_length_on):
if(self._fixed_length<MAX_FIXED_LENGTH):
if(self._fixed_length==0.25):
self._fixed_length = 0.5
elif(self._fixed_length==0.5):
self._fixed_length = 1
else:
self._fixed_length += 1
def _decrement_fixed_length_value(self):
if(self._fixed_length_on):
if(self._fixed_length>0.25):
if(self._fixed_length==0.5):
self._fixed_length = 0.25
elif(self._fixed_length==1):
self._fixed_length = 0.5
else:
self._fixed_length -= 1
# DELETE button and its listener
def _set_delete_button(self, button=None):
assert (isinstance(button, (ButtonElement, type(None))))
if (self._delete_button != button):
if (self._delete_button != None):
self._delete_button.remove_value_listener(self._delete_button_value)
self._delete_button = button
if (self._delete_button != None):
assert isinstance(button, ButtonElement)
self._delete_button.add_value_listener(self._delete_button_value, identify_sender=True)
self._delete_button.turn_off()
def _delete_button_value(self, value, sender):
assert (value in range(128))
if self.is_enabled() and self._is_pro_mode_on() and self._delete_button != None:
if ((value is not 0) or (not sender.is_momentary())):
self._delete_pressed = True
if self._shift_pressed:
self._print("Delete scene")
else:
self._print("Delete clip - [ Mute Tracks ]")
else:
self._delete_pressed = False
if (time.time() - self._last_mute_time) < SHORT_PRESS:
for track in tuple(self.song().tracks) + tuple(self.song().return_tracks):
if track.mute:
track.mute = False
self._last_mute_time = time.time()
self.update()
def _update_delete_button(self):
if self.is_enabled() and self._is_pro_mode_on() and self._delete_button != None:
self._delete_button.set_on_off_values("ProSession.Delete")
if self._delete_pressed:
self._delete_button.turn_on()
else:
self._delete_button.turn_off()
# DUPLICATE button and its listener
def _set_duplicate_button(self, button=None):
assert (isinstance(button, (ButtonElement, type(None))))
if (self._duplicate_button != button):
if (self._duplicate_button != None):
self._duplicate_button.remove_value_listener(self._duplicate_button_value)
self._duplicate_button = button
if (self._duplicate_button != None):
assert isinstance(button, ButtonElement)
self._duplicate_button.add_value_listener(self._duplicate_button_value, identify_sender=True)
self._duplicate_button.turn_off()
def _duplicate_button_value(self, value, sender):
assert (value in range(128))
if self.is_enabled() and self._is_pro_mode_on() and self._duplicate_button != None:
if ((value is not 0) or (not sender.is_momentary())):
self._duplicate_pressed = True