-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.js
1851 lines (1479 loc) · 52.1 KB
/
renderer.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
// ******* RENDERER
// ******** GLOBAL VARIABLES
var settings = getSettingsFromMain().then(function(){
startUp();
});
console.log("RENDERER SETTINGS", settings)
var live = false; //start false until it is initialized properly
var show = {}; //global variable for storing active show data
var tempPatch = {}; //used to temporarily store the patch while working on it...
var copied_levels = {}; //used for temporarily copying one set of levels to another via the UI LX_Popup
var lxInterval = []; //interval timer for slider GUI updates
var timers = []; //for tracking setTimout (audio) timers
var lxActiveCue = 0;
var afTimer = null;
var sndActiveCue = 0;
var activeSounds = [];
//global UI
var previousStatus = ""; //for statusBar updates
//jquery READY function
$(function() {
// ******** GUI LISTENERS
$( window ).resize(function() {
resizeScreen();
});
function resizeScreen(){
var win_height = $(window).height();
//subtract a bunch of other objects, then devide by 2...
var container_height = (win_height - $(".chan_sliders").parent().height() - $(".navbar").height() - $(".footer").height() - 10) / 2;
$(".lx_container, .snd_container").css("height", container_height);
}
resizeScreen(); //call it once to get started...
$("#testbutton1").click(function(){
console.log("test button 1 clicked");
visitor.event("easycue", "testbutton_click").send();
});
$("#testbutton2").click(function(){
console.log("test button 2 clicked");
});
$("#testbutton3").click(function(){
console.log("test button 2 clicked");
});
$("#but1").click(function(){
readShowFile();
});
$("#but2").click(function(){
saveFile();
});
// $("#updatePatch").click(function(){
// updateTempPatch();
// });
$("#savePatch").click(function(){
savePatch();
});
$('#patchlist').on('change', '.patch_dimmer', function(e){
console.log("patch changed");
// error check the value
var val = $(this).val();
val = parseInt(val);
if(isNaN(val)){
$(this).val(1);
}else if(val>512){
$(this).val(512);
}else if(val<0){
$(this).val(1);
}else{
$(this).val(val);
}
var ch = parseInt($(this).closest(".patch_row").data("ch"));
console.log("updating patch row", ch);
updatePatchRowRange(ch);
checkRangeConflicts();
});
$('#patchlist').on('change', '.ch_type', function(e){
console.log("patch TYPE changed");
var ch = parseInt($(this).closest(".patch_row").data("ch"));
console.log("updating patch row", ch);
updatePatchRowRange(ch);
checkRangeConflicts();
});
$("#lx_add_cue").click(function(){
// console.log("lx_new_cue clicked");
addLxCue();
});
$("#lx_save_cue").click(function(){
// console.log("lx_save_cue clicked: ");
console.log(show.lx[$("#lx_save_cue_num").val()]);
if(typeof show.lx[$("#lx_save_cue_num").val()] !== "undefined"){ //if the cue exists in the first place...
bootbox.confirm("Are you sure you want to save the current lighting levels <br>over existing Cue# " + $("#lx_save_cue_num").val() + "?", function(result){
console.log('confirmed?: ' + result);
if(result=== true) saveLxCue($("#lx_save_cue_num").val());
});
}else{
bootbox.alert("Sorry - No such Cue#");
}
});
$("#lx_go_cue").click(function(){
// console.log("lx_GO_cue clicked");
lxCueGo();
});
$("#lx_move_down").click(function(){
// console.log("lx_move_down clicked");
lxMove(1);
});
$("#lx_move_up").click(function(){
// console.log("lx_move_up clicked");
lxMove(-1);
});
$("#lx_delete").click(function(){
// console.log("lx_delete clicked");
lxDelete();
});
$('.chan_level, #lx_next_cue, #lx_save_cue_num, #snd_next_cue').focus(function() {
this.select();
});
$('table.chan_sliders').on("change", ".chan_level", function() {
// $(".chan_level[data-chan='"+chan+"']").val(newvalue);
if($(this).val()==="")
$(this).val(0);
var chan = $(this).data("chan");
var newvalue = $(this).val();
var patchedChan = show.patch[chan].dim;
console.log("chan_level CHANGE",chan, newvalue, patchedChan);
api.send( 'updateUniverse', {patchedChan : patchedChan, newvalue : percent_to_dmx(newvalue)} );
getLive();
});
$( "body" ).on("contextmenu", ".chan_slider" , function(event) {
var chan = $(this).data("chan");
showLxPopup(chan, false);
});
$( "#lx_datagrid" ).on("contextmenu", "input[data-part='chan']", function(event) {
var chan = $(this).data("chan");
var lxgrid_cue = $(this).closest("tr").data("lx");
showLxPopup(chan, lxgrid_cue);
});
$("#lxPopup").mouseleave(function(event) {
if($(this).data("lxgrid_cue")===false){
$(this).hide();
}else{
//if it's a lx_grid popup, then also update the 'show' lx data as well to match the ui
popup = $("#lxPopup");
var cueNum = popup.data("lxgrid_cue");
var chan = popup.data("chan");
var level_data = $( "#lx_datagrid tr[data-lx='"+cueNum+"'] input[data-chan='"+chan+"']").data("levels");
updateLxData(cueNum, "chan", level_data.Intensity, chan, level_data);
$(this).hide();
}
});
$("body").on({
copy : function(){
console.log("copy!!!");
},
paste : function(){
console.log("paste!!!");
},
cut : function(){
console.log("cut!!!");
}
});
function showLxPopup(chan, lxgrid_cue){
//show the popup
var popup = $("#lxPopup");
popup.empty();
//store the referring info in the popup so it can update the appropriate objects when sliders move...
popup.data("chan", chan);
popup.data("lxgrid_cue", lxgrid_cue);
if(lxgrid_cue === false){ //if it's a slider popup
//get the stored data from the corresponding chan_level box
var level_data = $(".chan_level[data-chan='"+chan+"']").data('levels');
console.log("level_data");
console.log(level_data);
}else{
var level_data = $( "#lx_datagrid tr[data-lx='"+lxgrid_cue+"'] input[data-chan='"+chan+"']").data("levels");
console.log("level_data");
console.log(level_data);
}
//reset some things:
popup.css("border-color", "#ddd");
//popuplate the popup
var col = {};
var custom_inputs = "";
var dimmer_offset = 0;
$.each(level_data, function(ch, level){
custom_inputs += '<label for="'+ch+'">'+ch+'</label>';
custom_inputs += '<input type="range" min="0" max="100" name="'+ch+'" data-dimmeroffset="'+dimmer_offset+'" value="'+level+'">';
if(["Red", "Green", "Blue"].indexOf(ch) > -1){
col[ch] = level;
}
dimmer_offset+=1;
});
// console.log(col);
popup.html(custom_inputs);
popup.css("left",event.pageX-10);
popup.css("top",event.pageY-10);
if(Object.keys(col).length === 3){
popup.css("border-color", colorLevelsToHex(col.Red, col.Green, col.Blue));
}
popup.show();
popup.find("input").first().focus();
}
//deal with the possible channel level sliders in the popup, and save their values to live channel data
$("#lxPopup").on("input change", "input", function(){
popup = $("#lxPopup");
var chan = popup.data("chan");
var level = parseInt($(this).val());
var ch_type = $(this).prop('name');
var dimmer_offset = $(this).data('dimmeroffset');
var existing_levels = {};
console.log(chan, level ,ch_type, dimmer_offset);
var patchedChan = show.patch[chan].dim + dimmer_offset;
console.log("patched chan: " + patchedChan);
api.send( 'updateUniverse', {patchedChan : patchedChan, newvalue : percent_to_dmx(level)} );
// depending on what type of popup it is, change different things...
if(popup.data('lxgrid_cue') === false){ //if it's a slider popup
//update the chan_level data param to match
existing_levels = $(".chan_level[data-chan='"+chan+"']").data('levels');
existing_levels[ch_type] = level;
$(".chan_level[data-chan='"+chan+"']").data("levels", existing_levels);
//update the UI based on slider changes
if(ch_type === "Intensity"){
$(".chan_slider[data-chan='"+chan+"']").slider( "value", level);
$(".chan_level[data-chan='"+chan+"']").val(level);
}
else if(["Red", "Green", "Blue"].indexOf(ch_type) > -1){
//update colour display
var newCol = colorLevelsToHex(
popup.find("input[name='Red']").val(),
popup.find("input[name='Green']").val(),
popup.find("input[name='Blue']").val()
);
popup.css("border-color", newCol);
$(".chan_slider[data-chan='"+chan+"'] div.ui-slider-range").css("background-color", newCol);
}
}
else{ //it's a lx_grid popup, so update different stuff...
console.log("lxGrid popup slider event");
var lxgrid_input = $( "#lx_datagrid tr[data-lx='"+popup.data('lxgrid_cue')+"'] input[data-chan='"+chan+"']");
//update the chan_level data param to match
existing_levels = lxgrid_input.data('levels');
existing_levels[ch_type] = level;
lxgrid_input.data("levels", existing_levels); //write it back
//update the UI based on slider changes
if(ch_type === "Intensity"){
lxgrid_input.val(level);
}
else if(["Red", "Green", "Blue"].indexOf(ch_type) > -1){
//update colour display
var newCol = colorLevelsToHex(
popup.find("input[name='Red']").val(),
popup.find("input[name='Green']").val(),
popup.find("input[name='Blue']").val()
);
popup.css("border-color", newCol);
lxgrid_input.css("border-bottom-color", newCol);
}
}
});
$('#lx_next_cue').keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
$("#lx_go_cue").trigger("click");
}
});
$('#snd_next_cue').keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
$(this).trigger("blur");
$("#snd_go_cue").trigger("click");
// sndCueGo();
}
});
// When you click on item, record into data("initialText") content of this item.
$('#lx_datagrid').on('focus', 'input', function() {
$(this).data("initialText", $(this).val());
this.select();
});
// When you leave an item...
$('#lx_datagrid').on('blur', 'input', function() {
if ($(this).data("initialText") !== $(this).val()) { // ...if content is different...
console.log($(this).val());
var cueNum = $(this).closest("tr").data("lx");
var dataPart = $(this).data("part");
var value =(dataPart=="name" || dataPart=="desc") ? $(this).val() : parseInt($(this).val());
var chan = (dataPart=="chan") ? $(this).data("chan") : null;
if(chan!== null){
var existing_levels = $(this).data('levels'); //update the chan_level data param to match
existing_levels.Intensity = value;
$(this).data("levels", existing_levels); //write it back
}
updateLxData(cueNum, dataPart, value, chan, existing_levels);
}
});
$('#lx_datagrid').on('focus','tr', function() {
// console.log("row got focus");
$("#lx_datagrid tr").removeClass('selected');
$(this).addClass("selected");
});
$('#lx_datagrid').on('dblclick','.lx_goto', function() {
console.log("goto row clicked");
$("#lx_next_cue").val($(this).closest("tr").data("lx"));
$("#lx_go_cue").trigger("click");
});
//***** hotkey listeners
$(window).keydown(function(e) {
// console.log(e.keyCode);
// LIGHTS
if(e.ctrlKey && e.altKey){
console.log("ctl&alt --> lights");
if(e.keyCode == $.ui.keyCode.ENTER) {
$("#lx_go_cue").trigger("click");
}
if(e.keyCode >= 48 && e.keyCode <= 57) { //number keys
hotkeyNum = String.fromCharCode(e.which);
console.log("hotkeyNum: " + hotkeyNum);
$("#lx_next_cue").val(hotkeyNum);
$("#lx_go_cue").trigger("click");
}
if(e.keyCode == 67) { //'c' key for COPY popup params
console.log("copying: ");
if($("#lxPopup").is(":visible")){
$("#lxPopup input").each(function(){
copied_levels[$(this).prop('name')] = parseInt($(this).val());
});
console.log(copied_levels);
$("#lxPopup").hide();
}
}
if(e.keyCode == 86) { //'v' key for PASTE popup params
console.log("PASTING: ");
if($("#lxPopup").is(":visible")){
console.log(copied_levels);
$.each(copied_levels, function(ch, value){
$("#lxPopup input[name='"+ch+"']").val(value).change();
});
$("#lxPopup").hide();
}
}
}
//SOUND
if(e.ctrlKey && e.shiftKey){
console.log("ctl&shift --> sound");
if(e.keyCode == $.ui.keyCode.ENTER) {
$("#snd_go_cue").trigger("click");
}
if(e.keyCode >= 48 && e.keyCode <= 57) { //number keys
hotkeyNum = String.fromCharCode(e.which);
console.log("hotkeyNum: " + hotkeyNum);
sndCueGo(hotkeyNum);
}
}
//generic
if (e.keyCode == $.ui.keyCode.ESCAPE) {
sndStopAll();
}
});
//***** sound buttons
$("#snd_add_cue").click(function(){
addSndCue();
});
$("#snd_move_down").click(function(){
sndMove(1);
});
$("#snd_move_up").click(function(){
sndMove(-1);
});
$("#snd_delete").click(function(){
sndDelete();
});
$("#snd_go_cue").click(function(){
// sndActiveCue = $("#snd_next_cue").val();
sndCueGo();
});
$("#snd_stop_all").click(function(){
sndStopAll();
});
$("#snd_fade_all").click(function(){
sndFadeAll();
});
$( "#snd_next_cue" ).on('blur', function() {
sndActiveCue = $(this).val();
setSndCueStatus($(this).val(), "active");
});
$('#snd_datagrid').on('focus','tr', function() {
// console.log("row got focus");
$("#snd_datagrid tr").removeClass('selected');
$(this).addClass("selected");
});
// When you click on item, record into data("initialText") content of this item.
$('#snd_datagrid').on('focus', 'input', function() {
$(this).data("initialText", $(this).val());
this.select();
});
// When you leave an item...
$('#snd_datagrid').on('blur', 'input', function() {
if ($(this).data("initialText") !== $(this).val()) { // ...if content is different...
console.log($(this).val());
var cueNum = $(this).closest("tr").data("snd");
var dataPart = $(this).data("part");
var value = $(this).val();
updateSndData(cueNum, dataPart, value);
}
});
$("#snd_datagrid").on('click','.snd_file_btn', function(){
console.log("open button clicked");
// var file = readFile();
// console.log(file);
// if(file === false) return;
var cueNum = $(this).data("snd");
chooseSoundFile(cueNum);
});
$("#snd_datagrid").on('dblclick','.snd_file_play', function(){
console.log("PLAY button clicked");
var cueNum = $(this).closest("tr").data("snd");
sndCueGo(cueNum);
});
//testing randomizing function - - changes the values randomly every 3 sec
// var randomInterval = setInterval(function(){
// console.log("randomInterval");
// for (var ch = 0; ch <= show.channels-0; ch++) {
// var randomnumber = Math.floor(Math.random() * (100 - 1 + 1)) + 1;
// dmx.update("demo", {[ch]:randomnumber});
// }
// }, 3000);
//******* patch listeners
$("#patch_reset").click(function(){ patchReset(); });
$("#patch_clear").click(function(){ patchReset(true); });
// $(".patch_slider").on("change", function(){
// //validate max/min and numeric
// var val = $(this).val();
// val = parseInt(val);
// if(isNaN(val)){
// $(this).val("");
// }else if(val>show.channels){
// $(this).val(show.channels);
// }else if(val<0){
// $(this).val("");
// }else{
// $(this).val(val);
// }
// });
// var prev_val;
// $(".patch_row select").focus(function() {
// prev_val = $(this).val();
// })
// .change(function(){
// var row = $(this).closest(".patch_row");
// console.log(row);
// var currentVal = row.find("input.patch_slider").val();
// console.log("row value: " + currentVal);
// if(typeof currentVal !== "undefined" && currentVal !== "" && currentVal!==0){
// var dimmer = row.data('dim');
// var type = $(this).val();
// console.log("newtype = " + type);
// var type_channels = show.types[type].channels;
// // console.log(type_channels);
// // //also change the next few rows if needed, and bump up the counter...
// for (var i = 0; i < type_channels.length; i++) {
// row = $(".patch_row[data-dim='"+parseInt(dimmer + i)+"']");
// // // console.log(row);
// // row.find("input.patch_slider").val(currentVal+1+i);
// row.find("option[value='"+type+"']").prop("selected", true);
// row.find(".ch_details").text(type_channels[i]);
// if(i>0){ //for any channels above the first channel
// // console.log("disabling ch: " + i);
// row.find("input.patch_slider").val(""); //clear it out instead
// // row.find("input.patch_slider").attr('disabled', 'disabled');
// // row.find("select").attr('disabled', 'disabled');
// }
// }
// }else{
// $(this).val(prev_val);
// console.log("returning false");
// bootbox.alert("Please select a channel number first, then choose a type.");
// return false;
// }
// updateTempPatch();
// });
});
//********* GUI UPDATING FUNCTIONS
function initializeShow(newShow){
console.log("INITIALIZING SHOW");
show = newShow; //update the RENDERER GLOBAL
if(typeof show.lx !== "undefined"){
setupGui();
updateLxCuelist();
// updateAllSliders();
getLive();
updateSndCuelist();
updateStatusBar();
// updatePatchList();
lxActiveCue = 0;
$("#lx_next_cue").val(lxActiveCue);
lxCueGo(0); //jump into the first cue
$("#lx_save_cue_num").val(lxActiveCue);
}
}
function setupGui(){
$("#slider_row").empty();
$("#input_row").empty();
$(".lx_container .ch_head").remove();
for (var i = 0; i <= show.channels-1; i++) {
var slider = $('<td>'+(i+1)+'<div data-chan='+(i)+' class="chan_slider"></div></td>');
$("#slider_row").append(slider);
var input = $('<td><input data-chan='+i+' class="chan_level" type="number" min="0" max="100"></td>');
$("#input_row").append(input);
var lxdata_heading = $('<th class="ch_head t_sm">' + (i+1) + '</th>');
$(".lx_container tr").append(lxdata_heading);
}
//******* update UI to initial settings
$('[data-toggle="tooltip"]').tooltip();
$(".chan_slider").slider({
orientation: "vertical",
range: "min",
min: 0,
max: 100,
value: 0,
slide: function( event, ui ) {
// console.log("chan_slider SLIDE", ui.value);
var newvalue = ui.value;
var chan = parseInt($(this).data('chan'));
var level_box = $(".chan_level[data-chan='"+chan+"']");
level_box.val(newvalue);
//update new levels-data array as well
var levels = level_box.data("levels");
levels.Intensity = newvalue;
level_box.data("levels", levels);
// for (var i = 0; i < show.patch[chan]['dims'].length; i++) {
var patchedChan = show.patch[chan].dim;
// console.log("patched chan: " + patchedChan);
// universe.update({[patchedChan]: percent_to_dmx(newvalue)});
api.send( 'updateUniverse', {patchedChan : patchedChan, newvalue : percent_to_dmx(newvalue)} );
// }
}
});
}
function updateStatusBar(){
var def = " ";
var left = "LX Cue: " + lxActiveCue;
// var mid = settings.activeFile;
var right = "Sound Cue: " + sndActiveCue;
$("#status-left").html(left);
// $("#status-mid").html(mid);
$("#status-right").html(right);
}
function startLxUpdate(){
$(".chan_sliders input").prop( "disabled", true );
var interval = setInterval(function(){
// updateAllSliders();
getLive();
}, 100);
lxInterval.push(interval);
}
function stopLxUpdate(){
console.log("stopping the LXUpdate interval: " + lxInterval);
$.each(lxInterval, function(i, interval){
clearInterval(interval);
var index = lxInterval.indexOf(interval);
if (index !== -1) {
lxInterval.splice(index, 1);
}
});
// updateAllSliders();
getLive();
$(".chan_sliders input").prop( "disabled", false );
}
function updateAllSliders(){
// console.log("updating all sliders");
// for (var ch = 0; ch < show.channels; ch++) {
// updateSlider(ch, dmx_to_percent(live[show.patch[ch].dim - 1]));
$.each( show.patch, function( ch, instrument ){
// console.log(show.patch[ch]);
updateSlider(ch, instrument);
});
}
function updateSlider(chan, instrument){
// console.log("updating slider", chan, instrument);
var level_data = {};
var instrument_type = instrument.type;
//for each possible channel in that type, get the corresponding live dimmer value
$.each(show.types[instrument_type].channels, function(i, channel){
level_data[channel] = dmx_to_percent(live[instrument.dim + i]);
});
// console.log("level_data: ");
// console.log(level_data);
$(".chan_slider[data-chan="+chan+"]").slider( "value", level_data.Intensity );
$(".chan_level[data-chan="+chan+"]").val(level_data.Intensity);
// // update the 'data' values of the chan_level, for popup and saving access...
$(".chan_level[data-chan="+chan+"]").data('levels', level_data);
//update the colour of the sliders if RGB exists in the levels
if ("Red" in level_data && "Green" in level_data && "Blue" in level_data){
var newCol = colorLevelsToHex(level_data.Red, level_data.Green, level_data.Blue);
$(".chan_slider[data-chan='"+chan+"'] div.ui-slider-range").css("background-color", newCol);
}
}
function addLxCueRow(num,data){
console.log("adding row: " + data.levels);
console.log(data);
var row = '<tr data-lx='+num+'>';
row += '<td class="t_sm lx_goto no_selection" title="Double-Click to go to this cue.">'+num+'</td>';
row += '<td><input class="t_med" data-part="name" type="text" value="'+data.name+'"></td>';
row += '<td><input class="t_lng" data-part="desc" type="text" value="'+data.desc+'"></td>';
row += '<td><input class="t_sm" data-part="in" type="number" value="'+data.in+'" min="0"></td>';
row += '<td><input class="t_sm" data-part="out" type="number" value="'+data.out+'" min="0"></td>';
row += '<td><input class="t_sm" data-part="af" type="number" value="'+data.af+'" min="0"></td>';
row += '<td><input class="t_sm" data-part="snd" type="number" value="'+data.snd+'" min="0"></td>';
row += "</tr>";
row = $(row);//make an object
// for (var i = 0; i < Object.keys(data.levels).length; i++) {
for (var i = 0; i < show.channels; i++) {
// console.log("adding cue data");
var levels = {"Intensity":0};
var style_str = "";
if(typeof data.levels[i] !== 'undefined'){
levels = data.levels[i];
if("Red" in levels && "Green" in levels && "Blue" in levels){
//update colour display of box if colors are present in the levels data
var newCol = colorLevelsToHex(levels.Red, levels.Green, levels.Blue);
style_str = "style='border-bottom-color:" + newCol +"'";
}
}
var cel = $('<td></td>');
var input = $('<input class="t_sm" type="number" data-part="chan" data-chan="'+i+'" value="'+levels.Intensity+'" min="0" max="100" ' + style_str + '>');
input.data("levels", levels);
cel.append(input);
row.append(cel);
}
$("#lx_datagrid tbody").append(row);
}
function updateLxCuelist(){
// console.log("updating show:");
// console.log(show);
$("#lx_datagrid tbody").empty();
for (var i = 0; i < show.lx.length; i++) {
var cue = show.lx[i];
addLxCueRow(i,cue);
}
// setLxCueStatus(lxActiveCue, "active");
// $("#lx_next_cue").val(lxActiveCue+1);
}
function lxFinishedCue(){
console.log("lxFinishedCue")
stopLxUpdate();
setLxCueStatus(lxActiveCue, "active");
$("#lx_next_cue").val(lxActiveCue+1);
$("#lx_save_cue_num").val(lxActiveCue);
//if there's an AF (autofollow) value set, then start the background timer to trigger THAT cue x seconds AFTER THIS cue is finished...
var afTime = parseInt(show.lx[lxActiveCue].af);
console.log("afTime="+afTime);
console.log("afCue: " + show.lx[lxActiveCue+1]);
if(Number.isFinite(afTime) && show.lx[lxActiveCue+1]) {
console.log("starting autofollow timer...");
var waitTime = afTime*1000;
statusNotice("Autofollow next LX cue in " + (waitTime/1000) + " seconds...", "good", false);
setLxCueStatus(lxActiveCue+1, "af_waiting");
afTimer = setTimeout(function(){
lxCueGo();
}, waitTime);
}
}
function setLxCueStatus(cue, status){
if(status!=="af_waiting"){
$("#lx_datagrid tr").removeClass('lx_active');
$("#lx_datagrid tr").removeClass('lx_fading');
}
if(afTimer === null){ //if there's no waiting af-timer, remove the class from all rows
$("#lx_datagrid tr").removeClass('lx_af_waiting');
}
$("#lx_datagrid tr[data-lx='"+cue+"']").addClass('lx_'+status);
}
// **** sound
function addSndCueRow(num,data){
// console.log("adding Snd row: ");
// console.log(data);
var row = '<tr data-snd='+num+'>';
row += '<td class="t_sm">'+num+'</td>';
row += '<td class="t_sm"><span data-snd='+num+' class="glyphicon glyphicon-volume-up snd_file_play" title="Double-Click to play this sound."></span></td>';
row += '<td class="t_lng"><input class="t_lng" data-part="name" type="text" value="'+data.name+'"></td>';
row += '<td class="t_lng2"><input class="t_lng2" data-part="desc" type="text" value="'+data.desc+'"></td>';
row += '<td class="t_sm"><input class="t_sm" data-part="startvol" type="number" value="'+data.startvol+'" min="0" max="100"></td>';
row += '<td class="t_sm"><input class="t_sm" data-part="in" type="number" value="'+data.in+'" min="0"></td>';
row += '<td class="t_sm"><input class="t_sm" data-part="vol" type="number" value="'+data.vol+'" min="0" max="100"></td>';
row += '<td class="t_sm"><input class="t_sm" data-part="hold" type="number" value="'+data.hold+'" min="0"></td>';
row += '<td class="t_sm"><input class="t_sm" data-part="out" type="number" value="'+data.out+'" min="0"></td>';
row += '<td class="t_sm"><input class="t_sm" data-part="endvol" type="number" value="'+data.endvol+'" min="0" max="100"></td>';
row += '<td class="t_lng2"><span class="t_lng2 file_span" data-part="file">'+data.file+'</span></td>';
row += '<td class="t_sm"><span data-snd='+num+' class="glyphicon glyphicon-folder-open snd_file_btn"></span></td>';
$("#snd_datagrid tbody").append(row);
}
function updateSndCuelist(){
// console.log("updating show:");
// console.log(show);
$("#snd_datagrid tbody").empty();
for (var i = 0; i < show.snd.length; i++) {
var cue = show.snd[i];
addSndCueRow(i,cue);
}
setSndCueStatus(sndActiveCue, "active");
$("#snd_next_cue").val(sndActiveCue);
}
// function sndFinishedCue(){
// setSndCueStatus(sndActiveCue, "active");
// $("#snd_next_cue").val(lxActiveCue+1);
// $("#snd_save_cue_num").val(lxActiveCue);
// }
function setSndCueStatus(cue, status){
if(cue===null){ //clear it all
$("#snd_datagrid tr").attr('class', function(i, c){
return c && c.replace(/(^|\s)snd_\S+/g, '');
});
}else{ //otherwise only the one we're addressing
$("#snd_datagrid tr[data-snd='"+cue+"']").attr('class', function(i, c){
return c && c.replace(/(^|\s)snd_\S+/g, '');
});
}
if(status !== "clear")
$("#snd_datagrid tr[data-snd='"+cue+"']").addClass('snd_'+status); //add the new class
//update the 'active' sound cue appearance
$("#snd_datagrid tr").removeClass('snd_active');
$("#snd_datagrid tr[data-snd='"+sndActiveCue+"']").addClass('snd_active'); // and re-add the activeCue if needed
$("#snd_next_cue").val(sndActiveCue);
updateStatusBar();
}
//****** CUE PLAYBACK FUNCTIONS
function lxCueGo(time){
if(typeof show.lx[$("#lx_next_cue").val()] === 'undefined'){
console.log("NO CUE THERE... not proceeding");
}else{
clearTimeout(afTimer);//clear any previously waitin autofollows, ie.cancel them
afTimer=null;
lxActiveCue = parseInt($("#lx_next_cue").val());
startLxUpdate();
setLxCueStatus(lxActiveCue, "fading");
//if a time is passed to the function, use it instead of the cue time
time = (typeof time === "undefined") ? (show.lx[lxActiveCue].in * 1000) : time;
//pad stored cues with 0s so that all channels fade, even if there is no stored level for it.
var levels = show.lx[lxActiveCue].levels;
var fullLevels = {};
// for (var i = 0; i < show.channels; i++) {
$.each( show.patch, function( i, instrument ){
if(typeof levels[i] === 'undefined'){ //if there's no corresponding level data in the show file, set the basic value to 0
fullLevels[instrument.dim] = 0;
}
else{//there IS level data for this channel in the patch, so update the fullLevels accordingly for each sub-dimmer-channel
$.each(levels[i], function(ch, level){
// var level = (typeof levels[i] === 'undefined') ? 0 : levels[i].Intensity;
var dimmer_offset = show.types[instrument.type].channels.indexOf(ch);
// console.log(" dimmer:" + instrument.dim + " dimmer_offset:" + dimmer_offset + " ch:" + ch + " level:" + level);
fullLevels[instrument.dim + dimmer_offset] = percent_to_dmx(level); //offset by one to account for patch dmx numbers (1-512) vs. actual output array (0-511)
});
}
});
//ACTUALLY RUN THE FADE
console.log("attempting to start fade with this data:");
console.log(fullLevels);
// new A().add(fullLevels, time).run(universe, lxFinishedCue); // NOTE --> NOW MOVED TO MAIN
api.send( 'runDmxAnimation', {levels: fullLevels, time: time} );
//also trigger a sound cue if there is one linked
if(show.lx[lxActiveCue].snd !== undefined && show.lx[lxActiveCue].snd !== ""){
var sqNum = show.lx[lxActiveCue].snd;
if(show.snd[sqNum] !== undefined){
sndCueGo(sqNum);
}
}
}
updateStatusBar();
}
function sndCueGo(sqNum){
//use the given cue num, or the 'sndActiveCue'
if(sqNum===undefined){
sqNum = +sndActiveCue;
var nextCue = +sqNum + 1;
if(show.snd[nextCue] !== undefined)
sndActiveCue = nextCue; //bump up the active cue num
}
if(show.snd[sqNum] === undefined || show.snd[sqNum].file=="") return;
console.log("starting to play: " + sqNum + " and setting sndActiveCue to: " + sndActiveCue);
try {
var rnd = Math.floor(Math.random() * (3 - 1 + 1)) + 1;
var soundPath = show.snd[sqNum].file
//test if saved file starts with "/resources"
console.log("examining soundpath: ", soundPath, soundPath.indexOf("resources/"));
// if it's NOT in the development location (ie. installed somewhere) and it's got a resources path, adjust to be relative to install location
if(globals.resourcesPath.indexOf('P_SYNC')==-1 && soundPath.indexOf("resources/") == 0){
// soundPath.replace('resources', globals.resourcesPath);
soundPath = soundPath.replace('resources/', '../');
}
console.log("trying to open sound file: ", soundPath);
var sound = new Howl({
src: soundPath,
volume: (show.snd[sqNum].in > 0) ? show.snd[sqNum].startvol / 100 : show.snd[sqNum].vol / 100 //use the startvol if there's a fade-in time, or just the main VOL if there isn't. convert percent vol to 0 - 1.0
});
sound.idNum = sqNum;
sound.on('end', function(){
console.log('sound ended');
// if(activeSounds[0]===undefined) return;
setSndCueStatus(sound.idNum, "clear");
activeSounds.shift(); //remove it from the list of active sounds
});
sound.on('stop', function(){
console.log('sound stopped');
// if(activeSounds[0]===undefined) return;
setSndCueStatus(sound.idNum, "clear");
activeSounds.shift(); //remove it from the list of active sounds
});
sound.on('fade', function(){ //add the fade callback function (to stop playback)
console.log('sound fade finished');
if(sound.volume() == 0){
sound.stop();
}else{
console.log('volume still above 0, so must be playing...');
setSndCueStatus(sound.idNum, "playing");
}
});
sound.play(); //play and get the ID