forked from hanshuebner/LiveOSC
-
Notifications
You must be signed in to change notification settings - Fork 15
/
LiveOSCCallbacks.py
1484 lines (1181 loc) · 59.1 KB
/
LiveOSCCallbacks.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
"""
# Copyright (C) 2007 Rob King ([email protected])
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# For questions regarding this module contact
# Rob King <[email protected]> or visit http://www.e-mu.org
This file contains all the current Live OSC callbacks.
"""
import Live
import RemixNet
import OSC
import LiveUtils
import sys
import re
import time
from Logger import log
class LiveOSCCallbacks:
def __init__(self, c_instance, oscEndpoint):
self.oscEndpoint = oscEndpoint
self.callbackManager = oscEndpoint.callbackManager
self.c_instance = c_instance
self.callbackManager.add("/live/tempo", self.tempoCB)
self.callbackManager.add("/live/time", self.timeCB)
self.callbackManager.add("/live/next/cue", self.nextCueCB)
self.callbackManager.add("/live/prev/cue", self.prevCueCB)
self.callbackManager.add("/live/play", self.playCB)
self.callbackManager.add("/live/play/continue", self.playContinueCB)
self.callbackManager.add("/live/play/selection", self.playSelectionCB)
self.callbackManager.add("/live/play/clip", self.playClipCB)
self.callbackManager.add("/live/play/scene", self.playSceneCB)
self.callbackManager.add("/live/scene/create", self.createSceneCB)
self.callbackManager.add("/live/stop", self.stopCB)
self.callbackManager.add("/live/stop/clip", self.stopClipCB)
self.callbackManager.add("/live/stop/track", self.stopTrackCB)
self.callbackManager.add("/live/scenes", self.scenesCB)
self.callbackManager.add("/live/tracks", self.tracksCB)
self.callbackManager.add("/live/name/scene", self.nameSceneCB)
self.callbackManager.add("/live/scene", self.sceneCB)
self.callbackManager.add("/live/name/sceneblock", self.nameSceneBlockCB)
self.callbackManager.add("/live/name/track", self.nameTrackCB)
self.callbackManager.add("/live/name/trackblock", self.nameTrackBlockCB)
self.callbackManager.add("/live/name/clip", self.nameClipCB)
self.callbackManager.add("/live/name/clipblock", self.nameClipBlockCB)
self.callbackManager.add("/live/arm", self.armTrackCB)
self.callbackManager.add("/live/mute", self.muteTrackCB)
self.callbackManager.add("/live/solo", self.soloTrackCB)
self.callbackManager.add("/live/volume", self.volumeCB)
self.callbackManager.add("/live/pan", self.panCB)
self.callbackManager.add("/live/send", self.sendCB)
self.callbackManager.add("/live/pitch", self.pitchCB)
self.callbackManager.add("/live/track/jump", self.trackJump)
self.callbackManager.add("/live/track/info", self.trackInfoCB)
self.callbackManager.add("/live/undo", self.undoCB)
self.callbackManager.add("/live/redo", self.redoCB)
self.callbackManager.add("/live/play/clipslot", self.playClipSlotCB)
self.callbackManager.add("/live/scene/view", self.viewSceneCB)
self.callbackManager.add("/live/track/view", self.viewTrackCB)
self.callbackManager.add("/live/return/view", self.viewTrackCB)
self.callbackManager.add("/live/master/view", self.mviewTrackCB)
self.callbackManager.add("/live/track/device/view", self.viewDeviceCB)
self.callbackManager.add("/live/return/device/view", self.viewDeviceCB)
self.callbackManager.add("/live/master/device/view", self.mviewDeviceCB)
self.callbackManager.add("/live/clip/view", self.viewClipCB)
self.callbackManager.add("/live/detail/view", self.detailViewCB)
self.callbackManager.add("/live/overdub", self.overdubCB)
self.callbackManager.add("/live/state", self.stateCB)
self.callbackManager.add("/live/clip/info", self.clipInfoCB)
self.callbackManager.add("/live/return/mute", self.muteTrackCB)
self.callbackManager.add("/live/return/solo", self.soloTrackCB)
self.callbackManager.add("/live/return/volume", self.volumeCB)
self.callbackManager.add("/live/return/pan", self.panCB)
self.callbackManager.add("/live/return/send", self.sendCB)
self.callbackManager.add("/live/master/volume", self.volumeCB)
self.callbackManager.add("/live/master/pan", self.panCB)
self.callbackManager.add("/live/devicelist", self.devicelistCB)
self.callbackManager.add("/live/return/devicelist", self.devicelistCB)
self.callbackManager.add("/live/master/devicelist", self.mdevicelistCB)
self.callbackManager.add("/live/device/range", self.devicerangeCB)
self.callbackManager.add("/live/return/device/range", self.devicerangeCB)
self.callbackManager.add("/live/master/device/range", self.mdevicerangeCB)
self.callbackManager.add("/live/device", self.deviceCB)
self.callbackManager.add("/live/return/device", self.deviceCB)
self.callbackManager.add("/live/master/device", self.mdeviceCB)
self.callbackManager.add("/live/clip/loopstate", self.loopStateCB)
self.callbackManager.add("/live/clip/loopstart", self.loopStartCB)
self.callbackManager.add("/live/clip/loopend", self.loopEndCB)
self.callbackManager.add("/live/clip/loopstate_id", self.loopStateCB)
self.callbackManager.add("/live/clip/loopstart_id", self.loopStartCB)
self.callbackManager.add("/live/clip/loopend_id", self.loopEndCB)
self.callbackManager.add("/live/clip/warping", self.warpingCB)
self.callbackManager.add("/live/clip/signature", self.sigCB)
self.callbackManager.add("/live/clip/add_note", self.addNoteCB)
self.callbackManager.add("/live/clip/notes", self.getNotesCB)
self.callbackManager.add("/live/clip/create", self.createClipCB)
self.callbackManager.add("/live/clip/delete", self.deleteClipCB)
self.callbackManager.add("/live/clip/mute", self.muteClipCB)
self.callbackManager.add("/live/master/crossfader", self.crossfaderCB)
self.callbackManager.add("/live/track/crossfader", self.trackxfaderCB)
self.callbackManager.add("/live/return/crossfader", self.trackxfaderCB)
self.callbackManager.add("/live/quantization", self.quantizationCB)
self.callbackManager.add("/live/selection", self.selectionCB)
self.callbackManager.add("/live/deactivate", self.deactivateCB)
self.callbackManager.add("/live/clear_inactive", self.clearInactiveCB)
self.callbackManager.add("/live/filter_clips", self.filterClipsCB)
self.callbackManager.add("/live/unfilter_group", self.unfilterGroupCB)
self.callbackManager.add("/live/distribute_groups", self.distributeGroupsCB)
self.callbackManager.add("/live/play/group_scene", self.playGroupSceneCB)
self.clip_notes_cache = {}
def sigCB(self, msg, source):
""" Called when a /live/clip/signature message is recieved
"""
track = msg[2]
clip = msg[3]
c = LiveUtils.getSong().tracks[track].clip_slots[clip].clip
if len(msg) == 4:
self.oscEndpoint.send("/live/clip/signature", (track, clip, c.signature_numerator, c.signature_denominator))
if len(msg) == 6:
self.oscEndpoint.send("/live/clip/signature", 1)
c.signature_denominator = msg[5]
c.signature_numerator = msg[4]
def warpingCB(self, msg, source):
""" Called when a /live/clip/warping message is recieved
"""
track = msg[2]
clip = msg[3]
if len(msg) == 4:
state = LiveUtils.getSong().tracks[track].clip_slots[clip].clip.warping
self.oscEndpoint.send("/live/clip/warping", (track, clip, int(state)))
elif len(msg) == 5:
LiveUtils.getSong().tracks[track].clip_slots[clip].clip.warping = msg[4]
def selectionCB(self, msg, source):
""" Called when a /live/selection message is received
"""
if len(msg) == 6:
self.c_instance.set_session_highlight(msg[2], msg[3], msg[4], msg[5], 0)
def trackxfaderCB(self, msg, source):
""" Called when a /live/track/crossfader or /live/return/crossfader message is received
"""
ty = msg[0] == '/live/return/crossfader' and 1 or 0
if len(msg) == 3:
track = msg[2]
if ty == 1:
assign = LiveUtils.getSong().return_tracks[track].mixer_device.crossfade_assign
name = LiveUtils.getSong().return_tracks[track].mixer_device.crossfade_assignments.values[assign]
self.oscEndpoint.send("/live/return/crossfader", (track, str(assign), str(name)))
else:
assign = LiveUtils.getSong().tracks[track].mixer_device.crossfade_assign
name = LiveUtils.getSong().tracks[track].mixer_device.crossfade_assignments.values[assign]
self.oscEndpoint.send("/live/track/crossfader", (track, str(assign), str(name)))
elif len(msg) == 4:
track = msg[2]
assign = msg[3]
if ty == 1:
LiveUtils.getSong().return_tracks[track].mixer_device.crossfade_assign = assign
else:
LiveUtils.getSong().tracks[track].mixer_device.crossfade_assign = assign
def tempoCB(self, msg, source):
"""Called when a /live/tempo message is received.
Messages:
/live/tempo Request current tempo, replies with /live/tempo (float tempo)
/live/tempo (float tempo) Set the tempo, replies with /live/tempo (float tempo)
"""
if len(msg) == 2 or (len(msg) == 3 and msg[2] == "query"):
self.oscEndpoint.send("/live/tempo", LiveUtils.getTempo())
elif len(msg) == 3:
tempo = msg[2]
LiveUtils.setTempo(tempo)
def timeCB(self, msg, source):
"""Called when a /live/time message is received.
Messages:
/live/time Request current song time, replies with /live/time (float time)
/live/time (float time) Set the time , replies with /live/time (float time)
"""
if len(msg) == 2 or (len(msg) == 3 and msg[2] == "query"):
self.oscEndpoint.send("/live/time", float(LiveUtils.currentTime()))
elif len(msg) == 3:
time = msg[2]
LiveUtils.currentTime(time)
def nextCueCB(self, msg, source):
"""Called when a /live/next/cue message is received.
Messages:
/live/next/cue Jumps to the next cue point
"""
LiveUtils.jumpToNextCue()
def prevCueCB(self, msg, source):
"""Called when a /live/prev/cue message is received.
Messages:
/live/prev/cue Jumps to the previous cue point
"""
LiveUtils.jumpToPrevCue()
def playCB(self, msg, source):
"""Called when a /live/play message is received.
Messages:
/live/play Starts the song playing
"""
LiveUtils.play()
def playContinueCB(self, msg, source):
"""Called when a /live/play/continue message is received.
Messages:
/live/play/continue Continues playing the song from the current point
"""
LiveUtils.continuePlaying()
def playSelectionCB(self, msg, source):
"""Called when a /live/play/selection message is received.
Messages:
/live/play/selection Plays the current selection
"""
LiveUtils.playSelection()
def playClipCB(self, msg, source):
"""Called when a /live/play/clip message is received.
Messages:
/live/play/clip (int track, int clip) Launches clip number clip in track number track
"""
if len(msg) == 4:
track = msg[2]
clip = msg[3]
LiveUtils.launchClip(track, clip)
def playSceneCB(self, msg, source):
"""Called when a /live/play/scene message is received.
Messages:
/live/play/scene (int scene) Launches scene number scene
"""
if len(msg) == 3:
scene = msg[2]
LiveUtils.launchScene(scene)
def createSceneCB(self, msg, source):
"""Called when a /live/scene/create message is received.
Messages:
/live/scene/create (int scene) create a scene at the index
"""
if len(msg) == 3:
scene = msg[2]
LiveUtils.createScene(scene)
def stopCB(self, msg, source):
"""Called when a /live/stop message is received.
Messages:
/live/stop Stops playing the song
"""
LiveUtils.stop()
def stopClipCB(self, msg, source):
"""Called when a /live/stop/clip message is received.
Messages:
/live/stop/clip (int track, int clip) Stops clip number clip in track number track
"""
if len(msg) == 4:
track = msg[2]
clip = msg[3]
LiveUtils.stopClip(track, clip)
def stopTrackCB(self, msg, source):
"""Called when a /live/stop/track message is received.
Messages:
/live/stop/track (int track, int clip) Stops track number track
"""
if len(msg) == 3:
track = msg[2]
LiveUtils.stopTrack(track)
def scenesCB(self, msg, source):
"""Called when a /live/scenes message is received.
Messages:
/live/scenes no argument or 'query' Returns the total number of scenes
"""
if len(msg) == 2 or (len(msg) == 3 and msg[2] == "query"):
sceneTotal = len(LiveUtils.getScenes())
self.oscEndpoint.send("/live/scenes", (sceneTotal))
return
def sceneCB(self, msg, source):
"""Called when a /live/scene message is received.
Messages:
/live/scene no argument or 'query' Returns the currently playing scene number
"""
if len(msg) == 2 or (len(msg) == 3 and msg[2] == "query"):
selected_scene = LiveUtils.getSong().view.selected_scene
scenes = LiveUtils.getScenes()
index = 0
selected_index = 0
for scene in scenes:
index = index + 1
if scene == selected_scene:
selected_index = index
self.oscEndpoint.send("/live/scene", (selected_index))
elif len(msg) == 3:
scene = msg[2]
LiveUtils.getSong().view.selected_scene = LiveUtils.getSong().scenes[scene]
def tracksCB(self, msg, source):
"""Called when a /live/tracks message is received.
Messages:
/live/tracks no argument or 'query' Returns the total number of scenes
"""
if len(msg) == 2 or (len(msg) == 3 and msg[2] == "query"):
trackTotal = len(LiveUtils.getTracks())
self.oscEndpoint.send("/live/tracks", (trackTotal))
return
def nameSceneCB(self, msg, source):
"""Called when a /live/name/scene message is received.
Messages:
/live/name/scene Returns a a series of all the scene names in the form /live/name/scene (int scene, string name)
/live/name/scene (int scene) Returns a single scene's name in the form /live/name/scene (int scene, string name)
/live/name/scene (int scene, string name)Sets scene number scene's name to name
"""
#Requesting all scene names
if len(msg) == 2 or (len(msg) == 3 and msg[2] == "query"):
bundle = OSC.OSCBundle()
sceneNumber = 0
for scene in LiveUtils.getScenes():
bundle.append("/live/name/scene", (sceneNumber, str(scene.name)))
sceneNumber = sceneNumber + 1
self.oscEndpoint.sendMessage(bundle)
return
#Requesting a single scene name
if len(msg) == 3:
sceneNumber = msg[2]
self.oscEndpoint.send("/live/name/scene", (sceneNumber, str(LiveUtils.getScene(sceneNumber).name)))
return
#renaming a scene
if len(msg) == 4:
sceneNumber = msg[2]
name = msg[3]
LiveUtils.getScene(sceneNumber).name = name
def nameSceneBlockCB(self, msg, source):
"""Called when a /live/name/sceneblock message is received.
/live/name/clipblock (int offset, int blocksize) Returns a list of blocksize scene names starting at offset
"""
if len(msg) == 4:
block = []
sceneOffset = msg[2]
blocksize = msg[3]
for scene in range(0, blocksize):
block.extend([str(LiveUtils.getScene(sceneOffset+scene).name)])
self.oscEndpoint.send("/live/name/sceneblock", block)
def nameTrackCB(self, msg, source):
"""Called when a /live/name/track message is received.
Messages:
/live/name/track Returns a a series of all the track names in the form /live/name/track (int track, string name)
/live/name/track (int track) Returns a single track's name in the form /live/name/track (int track, string name)
/live/name/track (int track, string name)Sets track number track's name to name
"""
#Requesting all track names
if len(msg) == 2 or (len(msg) == 3 and msg[2] == "query"):
trackNumber = 0
bundle = OSC.OSCBundle()
for track in LiveUtils.getTracks():
bundle.append("/live/name/track", (trackNumber, str(track.name)))
trackNumber = trackNumber + 1
self.oscEndpoint.sendMessage(bundle)
return
#Requesting a single track name
if len(msg) == 3:
trackNumber = msg[2]
self.oscEndpoint.send("/live/name/track", (trackNumber, str(LiveUtils.getTrack(trackNumber).name)))
return
#renaming a track
if len(msg) == 4:
trackNumber = msg[2]
name = msg[3]
LiveUtils.getTrack(trackNumber).name = name
def nameTrackBlockCB(self, msg, source):
"""Called when a /live/name/trackblock message is received.
/live/name/trackblock (int offset, int blocksize) Returns a list of blocksize track names starting at offset
"""
if len(msg) == 4:
block = []
trackOffset = msg[2]
blocksize = msg[3]
for track in range(0, blocksize):
block.extend([str(LiveUtils.getTrack(trackOffset+track).name)])
self.oscEndpoint.send("/live/name/trackblock", block)
def nameClipBlockCB(self, msg, source):
"""Called when a /live/name/clipblock message is received.
/live/name/clipblock (int track, int clip, blocksize x/tracks, blocksize y/clipslots) Returns a list of clip names for a block of clips (int blockX, int blockY, clipname)
"""
#Requesting a block of clip names X1 Y1 X2 Y2 where X1,Y1 is the first clip (track, clip) of the block, X2 the number of tracks to cover and Y2 the number of scenes
if len(msg) == 6:
block = []
trackOffset = msg[2]
clipOffset = msg[3]
blocksizeX = msg[4]
blocksizeY = msg[5]
for clip in range(0, blocksizeY):
for track in range(0, blocksizeX):
trackNumber = trackOffset+track
clipNumber = clipOffset+clip
if LiveUtils.getClip(trackNumber, clipNumber) != None:
block.extend([str(LiveUtils.getClip(trackNumber, clipNumber).name)])
else:
block.extend([""])
self.oscEndpoint.send("/live/name/clipblock", block)
def nameClipCB(self, msg, source):
"""Called when a /live/name/clip message is received.
Messages:
/live/name/clip Returns a a series of all the clip names in the form /live/name/clip (int track, int clip, string name)
/live/name/clip (int track, int clip) Returns a single clip's name in the form /live/name/clip (int clip, string name)
/live/name/clip (int track, int clip, string name)Sets clip number clip in track number track's name to name
"""
#Requesting all clip names
if len(msg) == 2 or (len(msg) == 3 and msg[2] == "query"):
trackNumber = 0
clipNumber = 0
for track in LiveUtils.getTracks():
bundle = OSC.OSCBundle()
for clipSlot in track.clip_slots:
if clipSlot.clip != None:
bundle.append("/live/name/clip", (trackNumber, clipNumber, str(clipSlot.clip.name), clipSlot.clip.color))
clipNumber = clipNumber + 1
self.oscEndpoint.sendMessage(bundle)
clipNumber = 0
trackNumber = trackNumber + 1
return
#Requesting a single clip name
if len(msg) == 4:
trackNumber = msg[2]
clipNumber = msg[3]
self.oscEndpoint.send("/live/name/clip", (trackNumber, clipNumber, str(LiveUtils.getClip(trackNumber, clipNumber).name), LiveUtils.getClip(trackNumber, clipNumber).color))
return
#renaming a clip
if len(msg) >= 5:
trackNumber = msg[2]
clipNumber = msg[3]
name = msg[4]
LiveUtils.getClip(trackNumber, clipNumber).name = name
if len(msg) >= 6:
trackNumber = msg[2]
clipNumber = msg[3]
color = msg[5]
LiveUtils.getClip(trackNumber, clipNumber).color = color
def addNoteCB(self, msg, source):
"""Called when a /live/clip/add_note message is received
Messages:
/live/clip/add_note (int pitch) (double time) (double duration) (int velocity) (bool muted) Add the given note to the clip
"""
trackNumber = msg[2]
clipNumber = msg[3]
pitch = msg[4]
time = msg[5]
duration = msg[6]
velocity = msg[7]
muted = msg[8]
LiveUtils.getClip(trackNumber, clipNumber).deselect_all_notes()
notes = ((pitch, time, duration, velocity, muted),)
LiveUtils.getClip(trackNumber, clipNumber).replace_selected_notes(notes)
self.oscEndpoint.send('/live/clip/note', (trackNumber, clipNumber, pitch, time, duration, velocity, muted))
def getNotesCB(self, msg, source):
"""Called when a /live/clip/notes message is received
Messages:
/live/clip/notes Return all notes in the clip in /live/clip/note messages. Each note is sent in the format
(int trackNumber) (int clipNumber) (int pitch) (double time) (double duration) (int velocity) (int muted)
"""
trackNumber = msg[2]
clipNumber = msg[3]
LiveUtils.getClip(trackNumber, clipNumber).select_all_notes()
bundle = OSC.OSCBundle()
for note in LiveUtils.getClip(trackNumber, clipNumber).get_selected_notes():
pitch = note[0]
time = note[1]
duration = note[2]
velocity = note[3]
muted = 0
if note[4]:
muted = 1
bundle.append('/live/clip/note', (trackNumber, clipNumber, pitch, time, duration, velocity, muted))
self.oscEndpoint.sendMessage(bundle)
def createClipCB(self, msg, source):
"""
Messages:
/live/clip/create (int track, int slot, float length)
Create a clip in [track, slot], length [length] beats
"""
clipSlots = LiveUtils.getClipSlots()
track_index = msg[2]
clipslot_index = msg[3]
length = msg[4]
track = LiveUtils.getTrack(track_index)
clipslot = track.clip_slots[clipslot_index]
clipslot.create_clip(length)
def deleteClipCB(self, msg, source):
"""
Messages:
/live/clip/delete (int track, int slot)
Delete clip at [track, slot]
"""
clipSlots = LiveUtils.getClipSlots()
track_index = msg[2]
clipslot_index = msg[3]
track = LiveUtils.getTrack(track_index)
clipslot = track.clip_slots[clipslot_index]
clipslot.delete_clip()
def armTrackCB(self, msg, source):
"""Called when a /live/arm message is received.
Messages:
/live/arm (int track) (int armed/disarmed) Arms track number track
"""
track = msg[2]
if len(msg) == 4:
if msg[3] == 1:
LiveUtils.armTrack(track)
else:
LiveUtils.disarmTrack(track)
# Return arm status
elif len(msg) == 3:
status = LiveUtils.getTrack(track).arm
self.oscEndpoint.send("/live/arm", (track, int(status)))
def muteTrackCB(self, msg, source):
"""Called when a /live/mute message is received.
Messages:
/live/mute (int track) Mutes track number track
"""
ty = msg[0] == '/live/return/mute' and 1 or 0
track = msg[2]
if len(msg) == 4:
if msg[3] == 1:
LiveUtils.muteTrack(track, ty)
else:
LiveUtils.unmuteTrack(track, ty)
elif len(msg) == 3:
if ty == 1:
status = LiveUtils.getSong().return_tracks[track].mute
self.oscEndpoint.send("/live/return/mute", (track, int(status)))
else:
status = LiveUtils.getTrack(track).mute
self.oscEndpoint.send("/live/mute", (track, int(status)))
def deactivateCB(self, msg, source):
for track in LiveUtils.getTracks():
for slot in track.clip_slots:
if slot.clip != None:
slot.clip.muted = True
def clearInactiveCB(self, msg, source):
log("clearing inactive")
for track in LiveUtils.getTracks():
for slot in track.clip_slots:
if slot.clip != None and slot.clip.muted:
slot.delete_clip()
def nameToMIDI(self, name):
""" Maps a MIDI note name (D3, C#6) to a value.
Assumes that middle C is C4. """
note_names = [
[ "C" ],
[ "C#", "Db" ],
[ "D" ],
[ "D#", "Eb" ],
[ "E" ],
[ "F" ],
[ "F#", "Gb" ],
[ "G" ],
[ "G#", "Ab" ],
[ "A" ],
[ "A#", "Bb" ],
[ "B" ]
]
for index, names in enumerate(note_names):
if name in names:
return index
return None
def unfilterGroupCB(self, msg, source):
track_index = msg[2]
tracks = LiveUtils.getTracks()
group = tracks[track_index]
if group.is_foldable:
for track in tracks[track_index+1:]:
if track.is_foldable:
break
else:
for clipslot in track.clip_slots:
if clipslot.clip is not None:
clipslot.clip.muted = False
else:
log("unfilterGroupCB: Target is not a group (ID %d)" % track_index)
def filterClipsCB(self, msg, source):
def bipolar_diverge(maximum):
""" returns [0, 1, -1, ...., maximum, -maximum ] """
sequence = list(sum(list(zip(list(range(maximum + 1)), list(range(0, -maximum - 1, -1)))), ()))
sequence.pop(0)
return sequence
def filter_tone_row(source, target, bend_limit = 7):
""" filters the notes in <source> by the permitted notes in <target>.
returns a tuple (<bool> acceptable, <int> pitch_bend) """
bends = bipolar_diverge(bend_limit)
for bend in bends:
if all(((note + bend) % 12) in target for note in source):
return (True, bend)
return (False, 0)
if not self.clip_notes_cache:
log("no cache found, creating")
self._filterClipsMakeCache()
try:
t0 = time.time()
note_names = msg[2:]
log("filtering clips according to %s" % note_names)
target = tuple(self.nameToMIDI(note) for note in note_names)
clip_states = {}
if target in self.clip_tone_row_cache:
log(" - found cached")
clip_states = self.clip_tone_row_cache[target]
else:
log(" - not found in cache, calculating")
for track_index, track in enumerate(LiveUtils.getTracks()):
for clip_index, slot in enumerate(track.clip_slots):
if slot.clip != None:
notes = self.clip_notes_cache[track_index][clip_index]
# log(" - found notes: %s" % notes)
if notes:
# don't transpose for now
acceptable, bend = filter_tone_row(notes, target, 0)
clip_states[slot.clip] = acceptable
self.clip_tone_row_cache[target] = clip_states
for clip, acceptable in clip_states.items():
clip.muted = not acceptable
except Exception, e:
log("filtering failed (%s); rebuilding cache" % e)
self._filterClipsMakeCache()
log("filtered clips (took %.3fs)" % (time.time() - t0))
def _filterClipsMakeCache(self, msg = None, source = None):
self.clip_notes_cache = {}
self.clip_tone_row_cache = {}
log("making clip filter cache")
t0 = time.time()
try:
for track_index, track in enumerate(LiveUtils.getTracks()):
self.clip_notes_cache[track_index] = {}
for clip_index, slot in enumerate(track.clip_slots):
if slot.clip is not None:
# match = re.search("(^|[_-])([A-G][A-G#b1-9-]*)$", slot.clip.name)
match = re.search("([_-])([A-G][A-G#b1-9-]*)$", slot.clip.name)
if match:
notes_found_str = match.group(2)
notes_found_str = re.sub("[1-9]", "", notes_found_str)
notes_found = notes_found_str.split("-")
notes = []
for note in notes_found:
note_midi = self.nameToMIDI(note)
if note_midi is not None:
notes.append(note_midi)
else:
log(" %s (%s): invalid notes" % (slot.clip.name, track.name))
# in case we have spurious/nonsense notes, filter them out
notes = filter(lambda n: n is not None, notes)
# log(" - %s: found notes: %s" % (slot.clip.name, notes))
self.clip_notes_cache[track_index][clip_index] = notes
else:
self.clip_notes_cache[track_index][clip_index] = None
slot.clip.muted = False
log("filtered clips (took %.3fs)" % (time.time() - t0))
except Exception, e:
log("Exception: %s" % e)
def soloTrackCB(self, msg, source):
"""Called when a /live/solo message is received.
Messages:
/live/solo (int track) Solos track number track
"""
ty = msg[0] == '/live/return/solo' and 1 or 0
track = msg[2]
if len(msg) == 4:
if msg[3] == 1:
LiveUtils.soloTrack(track, ty)
else:
LiveUtils.unsoloTrack(track, ty)
elif len(msg) == 3:
if ty == 1:
status = LiveUtils.getSong().return_tracks[track].solo
self.oscEndpoint.send("/live/return/solo", (track, int(status)))
else:
status = LiveUtils.getTrack(track).solo
self.oscEndpoint.send("/live/solo", (track, int(status)))
def volumeCB(self, msg, source):
"""Called when a /live/volume message is received.
Messages:
/live/volume (int track) Returns the current volume of track number track as: /live/volume (int track, float volume(0.0 to 1.0))
/live/volume (int track, float volume(0.0 to 1.0)) Sets track number track's volume to volume
"""
if msg[0] == '/live/return/volume':
ty = 1
elif msg[0] == '/live/master/volume':
ty = 2
else:
ty = 0
if len(msg) == 2 and ty == 2:
self.oscEndpoint.send("/live/master/volume", LiveUtils.getSong().master_track.mixer_device.volume.value)
elif len(msg) == 3 and ty == 2:
volume = float(msg[2])
LiveUtils.getSong().master_track.mixer_device.volume.value = volume
elif len(msg) == 4:
track = int(msg[2])
volume = float(msg[3])
if ty == 0:
LiveUtils.trackVolume(track, volume)
elif ty == 1:
LiveUtils.getSong().return_tracks[track].mixer_device.volume.value = volume
elif len(msg) == 3:
track = int(msg[2])
if ty == 1:
self.oscEndpoint.send("/live/return/volume", (track, LiveUtils.getSong().return_tracks[track].mixer_device.volume.value))
else:
self.oscEndpoint.send("/live/volume", (track, LiveUtils.trackVolume(track)))
def panCB(self, msg, source):
"""Called when a /live/pan message is received.
Messages:
/live/pan (int track) Returns the pan of track number track as: /live/pan (int track, float pan(-1.0 to 1.0))
/live/pan (int track, float pan(-1.0 to 1.0)) Sets track number track's pan to pan
"""
if msg[0] == '/live/return/pan':
ty = 1
elif msg[0] == '/live/master/pan':
ty = 2
else:
ty = 0
if len(msg) == 2 and ty == 2:
self.oscEndpoint.send("/live/master/pan", LiveUtils.getSong().master_track.mixer_device.panning.value)
elif len(msg) == 3 and ty == 2:
pan = msg[2]
LiveUtils.getSong().master_track.mixer_device.panning.value = pan
elif len(msg) == 4:
track = msg[2]
pan = msg[3]
if ty == 0:
LiveUtils.trackPan(track, pan)
elif ty == 1:
LiveUtils.getSong().return_tracks[track].mixer_device.panning.value = pan
elif len(msg) == 3:
track = msg[2]
if ty == 1:
self.oscEndpoint.send("/live/pan", (track, LiveUtils.getSong().return_tracks[track].mixer_device.panning.value))
else:
self.oscEndpoint.send("/live/pan", (track, LiveUtils.trackPan(track)))
def sendCB(self, msg, source):
"""Called when a /live/send message is received.
Messages:
/live/send (int track, int send) Returns the send level of send (send) on track number track as: /live/send (int track, int send, float level(0.0 to 1.0))
/live/send (int track, int send, float level(0.0 to 1.0)) Sets the send (send) of track number (track)'s level to (level)
"""
ty = msg[0] == '/live/return/send' and 1 or 0
track = msg[2]
if len(msg) == 5:
send = msg[3]
level = msg[4]
if ty == 1:
LiveUtils.getSong().return_tracks[track].mixer_device.sends[send].value = level
else:
LiveUtils.trackSend(track, send, level)
elif len(msg) == 4:
send = msg[3]
if ty == 1:
self.oscEndpoint.send("/live/return/send", (track, send, float(LiveUtils.getSong().return_tracks[track].mixer_device.sends[send].value)))
else:
self.oscEndpoint.send("/live/send", (track, send, float(LiveUtils.trackSend(track, send))))
elif len(msg) == 3:
if ty == 1:
sends = LiveUtils.getSong().return_tracks[track].mixer_device.sends
else:
sends = LiveUtils.getSong().tracks[track].mixer_device.sends
so = [track]
for i in range(len(sends)):
so.append(i)
so.append(float(sends[i].value))
if ty == 1:
self.oscEndpoint.send("/live/return/send", tuple(so))
else:
self.oscEndpoint.send("/live/send", tuple(so))
def pitchCB(self, msg, source):
"""Called when a /live/pitch message is received.
Messages:
/live/pitch (int track, int clip) Returns the pan of track number track as: /live/pan (int track, int clip, int coarse(-48 to 48), int fine (-50 to 50))
/live/pitch (int track, int clip, int coarse(-48 to 48), int fine (-50 to 50)) Sets clip number clip in track number track's pitch to coarse / fine
TODO: Unlike other callbacks, this does not include the track/pitch indices.
"""
if len(msg) == 6:
track = msg[2]
clip = msg[3]
coarse = msg[4]
fine = msg[5]
LiveUtils.clipPitch(track, clip, coarse, fine)
if len(msg) ==4:
track = msg[2]
clip = msg[3]
self.oscEndpoint.send("/live/pitch", LiveUtils.clipPitch(track, clip))
def trackJump(self, msg, source):
"""Called when a /live/track/jump message is received.
Messages:
/live/track/jump (int track, float beats) Jumps in track's currently running session clip by beats
"""
if len(msg) == 4:
track = msg[2]
beats = msg[3]
track = LiveUtils.getTrack(track)
track.jump_in_running_session_clip(beats)
def trackInfoCB(self, msg, source):
"""Called when a /live/track/info message is received.
Messages:
/live/track/info (int track) Returns clip slot status' for all clips in a track in the form /live/track/info (tracknumber, armed (clipnumber, state, length))
[state: 1 = Has Clip, 2 = Playing, 3 = Triggered]
"""
clipslots = LiveUtils.getClipSlots()
new = []
if len(msg) == 3:
new.append(clipslots[msg[2]])
tracknum = msg[2] - 1
else:
new = clipslots
tracknum = -1
for track in new:
tracknum = tracknum + 1