-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCAnalyzer.js
3156 lines (2518 loc) · 95.3 KB
/
SCAnalyzer.js
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
/*
author: zak45
date: 03/11/2022
version:2.0.0
Chataigne Module for Song Analysis using Vamp plugin .
This work mainly for mp3 file.
Manage the segmenter plugin from QM.
Manage the Rhythm Diff plugin from BBC.
Can create corresponding actions for LedFX / WLEd if required.
Automatic show creation feature.
Play all sequences from start to end.
Delay effects max 640 ms. To help in case of BT speakers.
Create mapping for vocal part of a song.
Send WLED audio sync from mapping.
Easing set to Hold for the created keys.
root.globalSettings.interface.useOpenGLRenderer need to be set to 0 (false)
*/
// Sonic Visualiser : to be adapted by OS if want to use it (optional)
var sonicVisu = "C:/Program Files/Sonic Visualiser/Sonic Visualiser.exe";
// Main module parameters
var sequence = "";
var targetFile = "";
// segmenter
var shouldProcessSeg = false;
var segAnalyzerIsRunning = false;
var featureType = "";
var nSegmentTypes = 0;
var neighbourhoodLimit = 0;
var creColEffect = false;
var linkToGroupNumber = 0;
//rhythm
var shouldProcessRhythm = false;
var rhythmAnalyzerIsRunning = false;
var SubBands = 0;
var Threshold = 0;
var MovingAvgWindowLength = 0;
var OnsetPeackWindowLength = 0;
var MinBPM = 0;
var MaxBPM = 0;
// Sonic exe file name (required)
var SCAnalyzerExeName = "sonic-annotator.exe";
// Output file, if blank, sonic-annotator will consider to be the audio file name under temp directory
var SCAoutputFile = "";
// Transform file name/location
var SCAtransform = "";
// Vamp Plugin name
var SCAvampPluginName = "";
// writer option with overwrite
var SCAoutputOptions = "-w jams --jams-force --jams-one-file ";
// Final options
var SCAnalyzerOptions = "-d "+SCAvampPluginName+" "+SCAoutputOptions+' "'+SCAoutputFile+'" ';
// TEMP dir (required)
var tempDIR = "";
//HOME Location
//%USERPROFILE% for WIN and $HOME for others
var homeDIR = "";
//
var moduleDIR = "";
// Transform file
var origTransform = "";
var pathTransform = "";
// Ledfx test
var ledfxAuto = false;
// Ledfx Scene test
var useScenes = false;
var writeLedFXFileScenes = true;
//
var writeLedFXFileEffects = true;
// Enum list update
runrefreshLedFXDevicesList = false;
runrefreshLedFXScenesList = false;
// WLED test
var wledAuto = false;
// var bkpWLEDValue = "";
// for playing all sequences in sequential way
var deltaTime = 0;
var numberToPlay = 0;
var lastsequence = 0;
var playseq = root.sequences.getItemAt(0);
// Enum param file : used to store Enum parameters modified / changed by end user
var enumFile = "SCAnalyzerEnumeffects.json";
// Enum param file : used to store Enum parameters modified / changed by end user
var enumScenesFile = "SCAnalyzerEnumscenes.json";
// to made some logic only once at init
var isInit = true;
// increase timeout as we want to run Sonic in synchronus way (blocking)
script.setExecutionTimeout(300);
// Module test
var wledExist = null;
var ledfxExist = null;
var spleeterExist = null;
var SCAnalyzerUtilExist = null;
// Create a show
var keepJson = 0;
var newAudio = "";
var moreInfo = "";
var showCreation = false;
var spleeterIsRunning = false;
var createShowStep2 = false;
var createShowStep3 = false;
var createShowStep4 = false;
var createShowStep5 = false;
var spleeterOccurrence = 0;
var spleeterMaxOccurrences = 240;
//We create necessary entries in modules & sequences. We need OS / Sound Card and Sequence with Trigger / Audio.
function init()
{
script.log("-- Custom command called init()");
var infos = util.getOSInfos();
script.log("Hello "+infos.username);
script.log("We run under : "+infos.name);
homeDIR = util.getDocumentsDirectory();
moduleDIR = util.getParentDirectory("SCAnalyzer.js");
// we check required TMP folder
analyzerTMP();
script.log("Temp folder : "+tempDIR);
if (tempDIR == "")
{
util.showMessageBox("Sonic Analyzer !", "TMP, TMPDIR or TEMP env variable not found", "warning", "OK");
}
// modules test
var osExist = root.modules.getItemWithName("OS");
var SCexist = root.modules.getItemWithName("Sound Card");
var SCAexist = root.modules.getItemWithName("SCAnalyzer");
wledExist = root.modules.getItemWithName("WLED");
spleeterExist = root.modules.getItemWithName("Spleeter");
if (SCexist.name == "soundCard")
{
script.log("Module Sound Card exist");
} else {
var newSCModule = root.modules.addItem("Sound Card");
}
if (osExist.name == "os")
{
script.log("Module OS exist");
} else {
var newOSModule = root.modules.addItem("OS");
}
var wledcontainer = local.parameters.getChild("WLED Params");
if (wledExist.name == "wled")
{
script.log("Module WLED present");
wledcontainer.setCollapsed(false);
} else {
script.log("No module WLED");
wledcontainer.setCollapsed(true);
}
var spleetercontainer = local.parameters.getChild("Spleeter Params");
if (spleeterExist.name == "spleeter")
{
script.log("Module Spleeter present");
spleetercontainer.setCollapsed(false);
} else {
script.log("No module Spleeter");
spleetercontainer.setCollapsed(true);
}
// test sequence
var SQexist = root.sequences.getItemWithName("Sequence");
if (SQexist.name == "sequence")
{
script.log("Sequences Sequence exist");
} else {
var newSequence = root.sequences.addItem();
var newTSequence = newSequence.layers.addItem("Trigger");
var newASequence = newSequence.layers.addItem("Audio");
}
//
script.setUpdateRate(1);
}
// Triggered once by second (rate = 1)
// for playback, sequence start from index 0, when one sequence reach end time, we switch to index +1
function update ()
{
// Initialize once some Param
if (isInit === true)
{
script.log('Initialize');
// load saved Enum
analyzerLoadenum();
analyzerLoadenumScenes();
// generate WLEDAudioSync enum list
generateAudioSyncList();
// LedFX enum
ledfxExist = root.modules.getItemWithName("LedFX");
if (ledfxExist.name == "ledFX")
{
script.log("Module LedFX present");
local.parameters.ledFXParams.setCollapsed(false);
generateLedFXScenesList();
generateLedFXDevicesList();
} else {
script.log("No module LedFX");
}
// set folder for nc3 files
if (local.parameters.sonicParams.transformFile.get() == "qmsegmenter.nc3")
{
local.parameters.sonicParams.transformFile.set( moduleDIR+ "/qmsegmenter.nc3");
}
if (local.parameters.sonicParams.rhythmTransformFile.get() == "bbcrhythm.nc3")
{
local.parameters.sonicParams.rhythmTransformFile.set(moduleDIR+ "/bbcrhythm.nc3");
}
// set sonic annotator folder
if (local.parameters.sonicParams.sonicAnnotatorLocation.get() == "sonic-annotator.exe")
{
local.parameters.sonicParams.sonicAnnotatorLocation.set(homeDIR + "/Chataigne/xtra/vamp-plugins/x64/sonic-annotator-1.5-win64/" + "sonic-annotator.exe");
}
SCAnalyzerUtilExist = root.modules.getItemWithName("SCAnalyzer_util");
if (SCAnalyzerUtilExist.name == "sCAnalyzer_util")
{
script.log("Module sCAnalyzer_util exist");
} else {
root.modules.addItem("SCAnalyzer_util");
}
isInit = false;
} else {
// start long process on it's own thread to run in blocking mode but not block the main UI
if (shouldProcessSeg === true)
{
shouldProcessSeg = false;
runsegAnalyzer (sequence, targetFile, featureType, nSegmentTypes, neighbourhoodLimit);
}
// start long process on it's own thread to run in blocking mode but not block the main UI
if (shouldProcessRhythm === true)
{
shouldProcessRhythm = false;
runrhythmAnalyzer (sequence, targetFile, SubBands, Threshold, MovingAvgWindowLength, OnsetPeackWindowLength, MinBPM, MaxBPM);
}
// check some process finished
if (spleeterIsRunning)
{
checkSpleeter();
}
if (createShowStep2 === true)
{
checkStep1();
} else if (createShowStep3 === true) {
checkStep2();
/*
} else if (createShowStep4 === true) {
checkStep3();
*/
} else if (createShowStep5 === true) {
checkStep3();
} else if (createShowLast === true) {
checkLast();
}
// Enum ledFx list update
if (runrefreshLedFXScenesList === true) {
runrefreshLedFXScenesList = false;
script.log("Update LedFX scenes list");
refreshScenes();
generateLedFXScenesList();
} else if (runrefreshLedFXDevicesList === true)
{
runrefreshLedFXDevicesList = false;
script.log("Update LedFX devices list");
refreshDevices();
generateLedFXDevicesList();
}
// Sequence mngt
// Play all enabled sequences
if (lastsequence < numberToPlay)
{
if (playseq.enabled.get() == 1)
{
if (playseq.currentTime.get() == playseq.totalTime.get())
{
script.log("Reach end of time");
lastsequence += 1;
if (lastsequence == numberToPlay)
{
numberToPlay = 0;
script.log("End Sequences");
} else {
playseq = root.sequences.getItemAt(lastsequence);
script.log("Sequence to play : " +playseq.name);
}
} else if (playseq.isPlaying.get() == 0) {
playseq.play.trigger();
script.log("Play sequence : " +playseq.name);
}
} else {
script.log("Sequence to bypass : " +playseq.name);
lastsequence += 1;
playseq = root.sequences.getItemAt(lastsequence);
if (lastsequence == numberToPlay)
{
numberToPlay = 0;
script.log("End Sequences");
}
}
}
}
}
/*
// execution depend on the user response
function messageBoxCallback (id, result)
{
script.log("Message box callback : " + id + " : " + result);
if (id == "msgDefaultEffects")
{
script.log('defaultEffects Call back');
if (result == 1)
{
script.log('Delete all effects and loading default one');
analyzerLoaddefault();
}
}
}
*/
function moduleParameterChanged (param)
{
script.log("Module Param changed : " + param.name);
if ( isInit === false )
{
if (param.name == "transformFile")
{
origTransform = param.getAbsolutePath();
} else if (param.name == "createActions") {
ledfxExist = root.modules.getItemWithName("LedFX");
if (ledfxExist.name == "undefined")
{
util.showMessageBox("Sonic Analyzer !", "No LEDFX Module ", "warning", "Got it");
param.set(0);
}
ledfxAuto = param.get();
} else if (param.name == "createWLEDActions") {
wledExist = root.modules.getItemWithName("WLED");
if (wledExist.name == "undefined")
{
util.showMessageBox("Sonic Analyzer !", "No WLED Module ", "warning", "Got it");
param.set(0);
}
wledAuto = param.get();
} else if (param.name == "createVocal") {
spleeterExist = root.modules.getItemWithName("Spleeter");
if (spleeterExist.name == "undefined")
{
util.showMessageBox("Sonic Analyzer !", "No Spleeter Module ", "warning", "Got it");
param.set(0);
}
} else if (param.name == "wledLive") {
// wledAuto = param.get();
} else if (param.name == "sonicAnnotatorInfo") {
util.gotoURL('https://vamp-plugins.org/sonic-annotator/');
} else if (param.name == "associatedEffects") {
if (writeLedFXFileEffects == true)
{
util.writeFile(moduleDIR+"/"+enumFile,local.parameters.ledFXParams.associatedEffects.getAllOptions(),true);
}
} else if (param.name == "associatedScenes") {
if (writeLedFXFileScenes == true)
{
util.writeFile(moduleDIR+"/"+enumScenesFile,local.parameters.ledFXParams.associatedScenes.getAllOptions(),true);
}
} else if (param.name == "loadDefault") {
//util.showYesNoCancelBox("msgDefaultEffects", "Confirm ?", "Do you really want to load default effects ?", "warning", "Yes", "No", "Cancel...");
script.log('Delete all effects and loading default one');
analyzerLoaddefault();
util.showMessageBox("SCAnalyzer", "Loading default effects ....", "warning", "Ok");
} else if (param.name.contains("scGroup")){
createCustomVariables(param.name);
} else if (param.name == "activateColors") {
activateColors();
} else if (param.name == "deActivateColors") {
deActivateColors();
} else if (param.name == "loopColors") {
if (param.get() == 1)
{
if (local.parameters.groupParams.linkToGroupNumber.get() == "0")
{
util.showMessageBox("SCAnalyzer","Link to an existing group need to be set","warning", "Ok");
}
}
} else if (param.name == "allIP") {
if (param.get() == 1)
{
if (local.parameters.groupParams.linkToGroupNumber.get() == "0")
{
util.showMessageBox("SCAnalyzer","Link to an existing group need to be set","warning", "Ok");
}
}
} else if (param.name == "resetEffects") {
resetEffects();
} else if (param.name == "resetPalettes") {
resetPalettes();
} else if (param.name == "split") {
if (local.parameters.mappingParams.sequential.get() == 1)
{
local.parameters.mappingParams.sequential.set(0);
}
} else if (param.name == "sequential") {
if (local.parameters.mappingParams.split.get() == 1)
{
local.parameters.mappingParams.split.set(0);
}
} else if (param.name == "replayFile") {
generateAudioSyncList();
} else if (param.name == "runSonicVisualiser") {
//execute Sonic Visualiser
if (util.fileExists(sonicVisu))
{
var launchresult = root.modules.os.launchProcess(sonicVisu, false);
} else {
script.log('No Sonic app found');
}
} else if (param.name == "duration") {
generateAudioSyncList();
} else if (param.name == "defaultEffectIndex") {
defaultIndexEffects();
} else if (param.name == "updateLists") {
runrefreshLedFXDevicesList = true;
runrefreshLedFXScenesList = true;
} else if (param.name == "defaultARIndex") {
defaultAREffects();
} else if (param.name == "defaultVirtualDeviceName") {
generateLedFXDevicesList();
} else if (param.name == "defaultSceneName") {
generateLedFXScenesList();
}
}
}
// check to see if something to do
function segAnalyzer (inkeepData, insequence, intargetFile, infeatureType, innSegmentTypes, inneighbourhoodLimit)
{
segAnalyzerIsRunning = true;
if (insequence == "" && intargetFile == "" )
{
script.log("Nothing to do !!");
segAnalyzerIsRunning = false;
} else {
keepJson = inkeepData;
sequence = insequence;
targetFile = intargetFile;
featureType = infeatureType;
nSegmentTypes = innSegmentTypes;
neighbourhoodLimit = inneighbourhoodLimit;
util.showMessageBox("Sonic Analyzer ! QM-SEGMENTER ", "This could take a while ...." + moreInfo, "info", "Got it");
shouldProcessSeg = true;
}
}
// Run Sonic: wait and read received data from Segmenter
function runsegAnalyzer (sequence, targetFile, featureType, nSegmentTypes, neighbourhoodLimit)
{
segAnalyzerIsRunning = true;
// Sonic executable
SCAnalyzerExeName = local.parameters.sonicParams.sonicAnnotatorLocation.getAbsolutePath();
// check to see if Sonic exe exist
if (util.fileExists(SCAnalyzerExeName) == 1)
{
// we have some work to do, target first else file
if (sequence.contains("/"))
{
script.log('Retreive data from sequence : ' + sequence);
var splitseq = sequence.split("/");
var sequenceName = splitseq[2];
var audioName = splitseq[4];
// set newSequence to existing one
var newSequence = root.sequences.getItemWithName(sequenceName);
// set newAudio to existing one
newAudio = newSequence.layers.getItemWithName(audioName);
// targetFile
var targetFile = newAudio.clips.audioClip.filePath.getAbsolutePath();
script.log('Target file from sequence : ' + targetFile);
} else if (targetFile != ""){
script.log('Create new sequence from filename :'+targetFile);
// create new sequence / audio clip
var newSequence = root.sequences.addItem('Sequence');
newAudio = newSequence.layers.addItem('Audio');
var newAudioClip = newAudio.clips.addItem('audioClip');
newAudioClip.filePath.set(targetFile);
} else {
segAnalyzerIsRunning = false;
script.logError("Something wrong with segAnalyzer....");
return;
}
// transform file to read
origTransform = local.parameters.sonicParams.transformFile.getAbsolutePath();
// plugin name
SCAvampPluginName = "vamp:qm-vamp-plugins:qm-segmenter:segmentation";
// result output file
SCAoutputFile = local.parameters.sonicParams.outputFolder.getAbsolutePath();
// if output file not set, we set it as audio clip file name under tmp folder
if (SCAoutputFile == "")
{
SCAoutputFile = tempDIR + "/SCAnalyzer_seg_" + getFilename(targetFile).replace(".mp3", "").replace(".wav", "") + ".json";
} else {
SCAoutputFile = SCAoutputFile + "/SCAnalyzer_seg_" + getFilename(targetFile).replace(".mp3", "").replace(".wav", "") + ".json";
}
// check to see if transform file is necessary
if (origTransform == "")
{
script.log("Using default parameters for the plugin, if you want to customize, select a transform");
SCAnalyzerOptions = "-d "+SCAvampPluginName+" "+SCAoutputOptions+' "'+SCAoutputFile+'" ';
} else {
script.log("Using transform file : "+origTransform);
segAnalyzerTransform (featureType, nSegmentTypes, neighbourhoodLimit);
SCAnalyzerOptions = "-t "+'"'+pathTransform+'"'+" "+SCAoutputOptions+' "'+SCAoutputFile+'" ';
}
// Run only if necessary
if (keepJson == 0)
{
//set output file to blank to avoid reading old values in case sonic-annotator not run as should.
util.writeFile(SCAoutputFile, "", true);
var exeCMD = '"'+SCAnalyzerExeName+'" '+SCAnalyzerOptions+'"'+targetFile+'"';
script.log('command to run : '+ exeCMD);
// we execute the Sonic-annotator in blocking mode
var launchresult = root.modules.os.launchProcess(exeCMD, true);
script.log("Sonic Analyzer return code : "+launchresult);
if (launchresult == "")
{
segAnalyzerIsRunning = false;
util.showMessageBox("Sonic Analyzer !", "Something wrong....", "warning", "OK");
return;
}
}
// read the result
script.log("we read from : " + SCAoutputFile);
var SCAJSONContent = util.readFile(SCAoutputFile,true);
if (SCAJSONContent.annotations[0].annotation_metadata.annotator.output_id != "segmentation")
{
segAnalyzerIsRunning = false;
script.log("Json file with no data for segmentation !!!");
util.showMessageBox("Sonic Analyzer !", "Json file with no data for segmentation !!!", "warning", "OK");
return;
}
// set flag for ledfx and/or wled auto actions creation
var ledfxExist = root.modules.getItemWithName("LedFX");
if (ledfxExist.name == "ledFX")
{
ledfxAuto = local.parameters.ledFXParams.createActions.get();
useScenes = local.parameters.ledFXParams.useScenes.get();
}
var wledExist = root.modules.getItemWithName("WLED");
if (wledExist.name == "wled")
{
wledAuto = local.parameters.wledParams.createWLEDActions.get();
}
// create the container for result values
local.values.removeContainer("Vamp plugin");
var newContainer = local.values.addContainer("Vamp plugin");
// create Vamp plugin values
newContainer.addStringParameter("File Name","",SCAJSONContent.file_metadata.identifiers.filename);
newContainer.addStringParameter("duration","",SCAJSONContent.file_metadata.duration);
newContainer.addStringParameter("artist","",SCAJSONContent.file_metadata.artist);
newContainer.addStringParameter("title","",SCAJSONContent.file_metadata.title);
// create Triggers from the json result file
var newLayersTrigger = newSequence.layers.addItem('Trigger');
var prefix = "QM";
// retreive groupName if necessary
var groupName = "NotSet";
if (creColEffect === false)
{
linkToGroupNumber = local.parameters.groupParams.linkToGroupNumber.get();
}
if (linkToGroupNumber != 0 || creColEffect === true)
{
// check if custom variables exist for this group
// retreive groupe name
var groupNamevar = local.parameters.getChild("groupParams/" + linkToGroupNumber);
if (groupNamevar.name != "undefined")
{
var groupName = groupNamevar.get();
if (groupName == "")
{
groupName = "NotSet";
}
}
}
groupName = groupName.replace(" ","").toLowerCase();
var groupExist = root.customVariables.getItemWithName(groupName);
if (creColEffect === true)
{
prefix = "CALC" + linkToGroupNumber;
}
for (var i = 0; i < SCAJSONContent.annotations.length; i += 1)
{
// set annotations in values
var newannotationsContainer = newContainer.addContainer("annotations");
newannotationsContainer.addStringParameter("tools","",SCAJSONContent.annotations[i].annotation_metadata.annotation_tools);
newannotationsContainer.addStringParameter("data source","",SCAJSONContent.annotations[i].annotation_metadata.data_source);
// set annotator in values
var newannotatorContainer = newannotationsContainer.addContainer("annotator");
newannotatorContainer.addStringParameter("plugin_id ","",SCAJSONContent.annotations[i].annotation_metadata.annotator.plugin_id);
newannotatorContainer.addStringParameter("output_id ","",SCAJSONContent.annotations[i].annotation_metadata.annotator.output_id);
newannotatorContainer.addStringParameter("plugin_version ","",SCAJSONContent.annotations[i].annotation_metadata.annotator.plugin_version);
newannotatorContainer.addStringParameter("step_size ","",SCAJSONContent.annotations[i].annotation_metadata.annotator.step_size);
newannotatorContainer.addStringParameter("block_size ","",SCAJSONContent.annotations[i].annotation_metadata.annotator.block_size);
newannotatorContainer.addStringParameter("sample_rate ","",SCAJSONContent.annotations[i].annotation_metadata.annotator.sample_rate);
newannotatorContainer.addStringParameter("transform_id ","",SCAJSONContent.annotations[i].annotation_metadata.annotator.transform_id);
// set parameters in values
var newparametersContainer = newannotatorContainer.addContainer("parameters");
newparametersContainer.addStringParameter("featureType ","",SCAJSONContent.annotations[i].annotation_metadata.annotator.parameters.featureType);
newparametersContainer.addStringParameter("nSegmentTypes ","",SCAJSONContent.annotations[i].annotation_metadata.annotator.parameters.nSegmentTypes);
newparametersContainer.addStringParameter("neighbourhoodLimit ","",SCAJSONContent.annotations[i].annotation_metadata.annotator.parameters.neighbourhoodLimit);
script.log("Occurence : " + i + " data length : " + SCAJSONContent.annotations[i].data.length);
var newColor = [];
var newEffect = 0;
var newPalette = 0;
// main Triggers / cues loop
for (var j = 0; j < SCAJSONContent.annotations[i].data.length; j += 1)
{
// no cue if create triggers for color/effect
if (creColEffect === false)
{
// set Cue time /name if cue not already exist for this time
var cueExist = newSequence.cues.getItemWithName(j);
if (cueExist.name == "undefined")
{
var newCue = newSequence.cues.addItem();
newCue.time.set(SCAJSONContent.annotations[i].data[j].time);
newCue.setName(j);
} else {
if (cueExist.time.get() != SCAJSONContent.annotations[i].data[j].time)
{
var newCue = newSequence.cues.addItem();
newCue.time.set(SCAJSONContent.annotations[i].data[j].time);
newCue.setName(j);
}
}
}
// create new Trigger
var newTrigger = newLayersTrigger.triggers.addItem();
// set main Trigger values
newTrigger.time.set(SCAJSONContent.annotations[i].data[j].time);
newTrigger.flagY.set(100000%j);
newTrigger.setName(SCAJSONContent.annotations[i].data[j].label);
// set Trigger color and create action for ledFX / WLED if requested, depend on segment name
if (SCAJSONContent.annotations[i].data[j].label.contains("A"))
{
//newTrigger.color.set([1,0,0,1]);
newColor = local.parameters.defaultColors.segmentA.get();
newTrigger.color.set(newColor);
newEffect = local.parameters.defaultEffects.effectA.get();
newPalette = local.parameters.defaultPalettes.paletteA.get();
if (creColEffect === true && groupExist.name != "undefined")
{
analyzerCreConseq("A", groupName);
} else {
// Create init consequences put WLED on live mode if requested
if (j == 0 && (wledExist.name == "wled") && (local.parameters.wledParams.wledLive.get() == 1))
{
analyzerWLEDInitConseq();
// put delay between actions
newTrigger.consequences.stagger.set(.100);
}
// Create consequences priority to WLED
if (wledAuto)
{
analyzerWLEDConseq(newColor,newEffect,newPalette);
}
if (ledfxAuto)
{
analyzerLedFXConseq("A");
}
}
} else if (SCAJSONContent.annotations[i].data[j].label.contains("B")) {
//newTrigger.color.set([1,.30,1,1]);
newColor = local.parameters.defaultColors.segmentB.get();
newTrigger.color.set(newColor);
newEffect = local.parameters.defaultEffects.effectB.get();
newPalette = local.parameters.defaultPalettes.paletteB.get();
if (creColEffect === true && groupExist.name != "undefined")
{
analyzerCreConseq("B", groupName);
} else {
// Create consequences priority to WLED
if (wledAuto)
{
analyzerWLEDConseq(newColor,newEffect,newPalette);
}
if (ledfxAuto)
{
analyzerLedFXConseq("B");
}
}
} else if (SCAJSONContent.annotations[i].data[j].label.contains("C")) {
//newTrigger.color.set([1,.11,.81,1]);
newColor = local.parameters.defaultColors.segmentC.get();
newTrigger.color.set(newColor);
newEffect = local.parameters.defaultEffects.effectC.get();
newPalette = local.parameters.defaultPalettes.paletteC.get();
if (creColEffect === true && groupExist.name != "undefined")
{
analyzerCreConseq("C", groupName);
} else {
// Create consequences priority to WLED
if (wledAuto)
{
analyzerWLEDConseq(newColor,newEffect,newPalette);
}
if (ledfxAuto)
{
analyzerLedFXConseq("C");
}
}
} else if (SCAJSONContent.annotations[i].data[j].label.contains("D")) {
//newTrigger.color.set([.1,.1,1,1]);
newColor = local.parameters.defaultColors.segmentD.get();
newTrigger.color.set(newColor);
newEffect = local.parameters.defaultEffects.effectD.get();
newPalette = local.parameters.defaultPalettes.paletteD.get();
if (creColEffect === true && groupExist.name != "undefined")
{
analyzerCreConseq("D", groupName);
} else {
// Create consequences priority to WLED
if (wledAuto)
{
analyzerWLEDConseq(newColor,newEffect,newPalette);
}
if (ledfxAuto)
{
analyzerLedFXConseq("D");
}
}
} else if (SCAJSONContent.annotations[i].data[j].label.contains("E")) {
//newTrigger.color.set([.1,.1,.1,1]);
newColor = local.parameters.defaultColors.segmentE.get();
newTrigger.color.set(newColor);
newEffect = local.parameters.defaultEffects.effectE.get();
newPalette = local.parameters.defaultPalettes.paletteE.get();
if (creColEffect === true && groupExist.name != "undefined")
{
analyzerCreConseq("E", groupName);
} else {
// Create consequences priority to WLED
if (wledAuto)
{
analyzerWLEDConseq(newColor,newEffect,newPalette);
}
if (ledfxAuto)
{
analyzerLedFXConseq("E");
}
}
} else if (SCAJSONContent.annotations[i].data[j].label.contains("F")) {
//newTrigger.color.set([.1,.01,.51,1]);
newColor = local.parameters.defaultColors.segmentF.get();
newTrigger.color.set(newColor);
newEffect = local.parameters.defaultEffects.effectF.get();
newPalette = local.parameters.defaultPalettes.paletteF.get();
if (creColEffect === true && groupExist.name != "undefined")
{
analyzerCreConseq("F", groupName);
} else {
// Create consequences priority to WLED
if (wledAuto)
{
analyzerWLEDConseq(newColor,newEffect,newPalette);
}
if (ledfxAuto)
{
analyzerLedFXConseq("F");
}
}
} else if (SCAJSONContent.annotations[i].data[j].label.contains("G")) {
//newTrigger.color.set([1,.15,.51,1]);
newColor = local.parameters.defaultColors.segmentG.get();
newTrigger.color.set(newColor);
newEffect = local.parameters.defaultEffects.effectG.get();
newPalette = local.parameters.defaultPalettes.paletteG.get();
if (creColEffect === true && groupExist.name != "undefined")
{
analyzerCreConseq("G", groupName);
} else {
// Create consequences priority to WLED
if (wledAuto)
{
analyzerWLEDConseq(newColor,newEffect,newPalette);
}