-
Notifications
You must be signed in to change notification settings - Fork 0
/
exquisitecoasts.js
1288 lines (1103 loc) · 46 KB
/
exquisitecoasts.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
var patchNameField;
var authorField;
var patchNotesField;
var shareButton;
var pedalboardPresetField;
var pedalboardPresetSaveButton;
var clockSpeedField;
var clockSpeedTypeField;
var clockSpeedMultiplierField
var midiALFOSpeedField;
var midiALFOSpeedTypeField;
var midiALFOSpeedMultiplierField;
var midiBLFOSpeedField;
var midiBLFOSpeedTypeField;
var midiBLFOSpeedMultiplierField;
var instrument0CoastCheckbox;
var instrumentStregaCheckbox;
var instrument0CTRLCheckbox;
var instrumentDFAMCheckbox;
var instrumentMavisCheckbox;
var instrumentMother32Checkbox;
var instrumentSubharmoniconCheckbox;
var instrumentWerkstattCheckbox;
var instrumentExpandedRackCheckbox;
var instrumentExternalCVCheckbox;
var instrument0Coast;
var instrumentStrega;
var instrument0CTRL;
var instrumentDFAM;
var instrumentMavis;
var instrumentMother32;
var instrumentSubharmonicon;
var instrumentWerkstatt;
var instrumentExpandedRack;
var instrumentExternalCV;
var noInstruments;
var coastExpressLinkImage;
var coastExpressLinkAnchor;
var coastExpressShareLinkInput;
var knobFields = {};
var jackFields = {};
var midiFields = {};
var plusButtons = {};
var workingPatch = {};
var superTopSecretCode = localStorage.getItem('superTopSecretCode');
var jackDestinations = {
'0-Coast': ['TEMPO Input', 'Voltage MATH: Channel 1 Input', 'Voltage MATH: Channel 2 Input', 'Oscillator: 1/V OCTave Input', 'Oscillator: Linear FM Input', 'Overtone: CV Input', 'Multiply: CV Input', 'Slope: Rise/Fall Time CV Input', 'Slope: Trigger Input', 'Contour: Decay Time CV Input', 'Contour: Gate Input', 'Balance: Channel External Input', 'Balance: CV Input', 'Dynamics: CV Input'],
'Strega': ['External: Substance In', 'Activation: CV In', 'Tonic: Tonic Modulation Interference Input', 'Tones: CV In', 'Tones: 1V/ Octave', 'Time/Filter: Time Modulation Input', 'Time/Filter: Time CV In', 'Time/Filter: Time Unity CV In', 'Time/Filter: Decay CV In', 'Time/Filter: Absorb CV In', 'Time/Filter: Blend CV In', 'Time/Filter: Filter CV In', 'Agitation Generator: Begin and End In', 'Agitation Generator: Speed CV In'],
'0-CTRL': ['Clock Input', 'Dynamic Reset Input', 'Stop Input', 'Direction Input', 'Strength CV Input', 'Time CV Input'],
'DFAM': ['Trigger', 'VCA CV', 'Velocity', 'VCA Decay', 'Ext Audio', 'VCF Decay', 'Noise Level', 'VCO Decay', 'VCF Mod', 'VCO 1 CV', 'VCO 2 CV', '1⭢2 FM Amount', 'Tempo', 'Run/Stop', 'Adv/Clock'],
'Mavis': ['Fold In', '1V/Oct', 'PWM', 'One (-5)', 'LFO Rate', 'Cutoff', 'Gate', 'VCA CV', 'TWO', 'S+H (VCO)', 'S+H Gate (LFO)', 'Attn (+5)', 'Mult'],
'Mother 32': ['Ext. Audio', 'Mix CV', 'VCA CV', 'VCF Cutoff', 'VCF Res.', 'VCO 1V/Oct', 'CVO Lin FM'],
'Subharmonicon': ['VCO 1', 'VCO 1 Sub', 'VCO 1 PWM', 'VCA', 'VCO 2', 'VCO 2 Sub', 'VCO 2 PWM', 'Cutoff', 'Play', 'Reset', 'Trigger', 'Rhythm 1', 'Rhythm 2', 'Rhythm 3', 'Rhythm 4', 'Clock'],
'Werkstatt': ['VCA CV In', 'VCF CV In', 'VCO Lin FM In', 'VCO Exp FM In', 'LFO FM In', 'Gate In', 'VCF Aud In'],
'Expanded Rack': ['Filter: Audio In', 'Filter: Freq CV', 'Filter: Freq CV (attenuated)', 'Drive: Low/1', 'Drive: High/2', 'Mimeophon: L (Mono) Input', 'Mimeophon: R Input', 'Mimeophon: Repeats: CV Input', 'Mimeophon: Zone: CV Input', 'Mimeophon: Mix: CV Input', 'Mimeophon: Rate: CV Input', 'Mimeophon: Rate: µ Input', 'Mimeophon: Halo: CV Input', 'Mimeophon: Color: CV Input', 'Mimeophon: Tempo: Input', 'Mimeophon: Flip: Input', 'Mimeophon: Hold: Input', 'Attenuator 1: In', 'Attenuator 2: In', 'Attenuator 3: In', 'Att-Off 1: In', 'Att-Off 2: In', 'LPG 1: Signal In', 'LPG 1: CV In', 'LPG 2: Signal In', 'LPG 2: CV In', 'Sample & Hold: Signal In', 'Sample & Hold: S&H', 'Sample & Hold: T&H', 'Slew 1: Signal In', 'Piezo Amp: In', 'Disting 1: Z', 'Disting 1: X', 'Disting 1: Y', 'Disting 2: Z', 'Disting 2: X', 'Disting 2: Y', 'TP8: Top Left', 'TP8: Top Right', 'TP8: Top Diamond', 'TP8: Middle Left', 'TP8: Middle Right', 'TP8: Bottom Diamond', 'TP8: Bottom Left', 'TP8: Bottom Right', 'Pedalboard: Pedal 1', 'Pedalboard: Pedal2'],
'External CV': ['Sync In'],
'System': ['Audio Out']
}
window.onload = function() {
if (location.href.indexOf('localhost') !== -1) {
var liveScript = document.createElement('script');
liveScript.src = 'https://livejs.com/live.js';
document.head.appendChild(liveScript);
}
if (screen.width < 768 && window.innerHeight > window.innerWidth) {
alert("Please rotate your phone. Exqusite Coast only displays well on phones when in landscape mode.");
}
if (location.href.indexOf('localhost') === -1 && location.protocol !== 'https:') {
location.replace(`https:${location.href.substring(location.protocol.length)}`);
}
else {
if (superTopSecretCode) {
document.getElementById('secretcheckboxes').classList.remove('supertopsecret');
document.getElementById('secretwerkstattkey').classList.remove('supertopsecret');
}
// *************************** Header ***************************
// ********* Menu *********
var headerArea = document.getElementById('header');
var menuButton = document.getElementById('menu_button');
menuButton.addEventListener('touch', openMenu);
menuButton.addEventListener('click', openMenu);
function openMenu(event) {
event.preventDefault()
if (!menuButton.classList.contains('open')) {
menuButton.classList.add('open');
headerArea.style.height = (document.getElementById('welcome_message').clientHeight + 130) + 'px';
}
else {
menuButton.classList.remove('open');
headerArea.style.height = 'var(--headerheight)';
}
}
// ********* Arrows *********
var arrow1 = document.getElementById('arrow1');
var arrow2 = document.getElementById('arrow2');
function rotateArrows() {
setTimeout(function() {
arrow1.style.transform = 'rotate(' + ((Math.random() * 100) - 50) + 'deg)';
arrow2.style.transform = 'rotate(' + ((Math.random() * 100) + 300) + 'deg)';
rotateArrows();
// }, (Math.random() * 10000) + 15000);
}, 3400);
}
rotateArrows();
// *************************** Patch Info ***************************
patchNameField = document.getElementById('patch_name');
authorField = document.getElementById('author');
patchNotesField = document.getElementById('patch_notes');
pedalboardPresetField = document.getElementById('pedalboard_preset');
pedalboardPresetSaveButton = document.getElementById('pedalboard_preset_save_button');
shareButton = document.getElementById('get_share_link');
instrument0CoastCheckbox = document.getElementById('instrument_checkbox_0coast');
instrumentStregaCheckbox = document.getElementById('instrument_checkbox_strega');
instrument0CTRLCheckbox = document.getElementById('instrument_checkbox_0ctrl');
instrumentDFAMCheckbox = document.getElementById('instrument_checkbox_dfam');
instrumentMavisCheckbox = document.getElementById('instrument_checkbox_mavis');
instrumentMother32Checkbox = document.getElementById('instrument_checkbox_mother32');
instrumentSubharmoniconCheckbox = document.getElementById('instrument_checkbox_subharmonicon');
instrumentWerkstattCheckbox = document.getElementById('instrument_checkbox_werkstatt');
instrumentExpandedRackCheckbox = document.getElementById('instrument_checkbox_expandedrack');
instrumentExternalCVCheckbox = document.getElementById('instrument_checkbox_externalcv');
instrument0CoastCheckbox.addEventListener('change', function() { saveInstrument(instrument0CoastCheckbox); collapseInstruments() });
instrumentStregaCheckbox.addEventListener('change', function() { saveInstrument(instrumentStregaCheckbox); collapseInstruments() });
instrument0CTRLCheckbox.addEventListener('change', function() { saveInstrument(instrument0CTRLCheckbox); collapseInstruments() });
instrumentDFAMCheckbox.addEventListener('change', function() { saveInstrument(instrumentDFAMCheckbox); collapseInstruments() });
instrumentMavisCheckbox.addEventListener('change', function() { saveInstrument(instrumentMavisCheckbox); collapseInstruments() });
instrumentMother32Checkbox.addEventListener('change', function() { saveInstrument(instrumentMother32Checkbox); collapseInstruments() });
instrumentSubharmoniconCheckbox.addEventListener('change', function() { saveInstrument(instrumentSubharmoniconCheckbox); collapseInstruments() });
instrumentWerkstattCheckbox.addEventListener('change', function() { saveInstrument(instrumentWerkstattCheckbox); collapseInstruments() });
instrumentExpandedRackCheckbox.addEventListener('change', function() { saveInstrument(instrumentExpandedRackCheckbox); collapseInstruments() });
instrumentExternalCVCheckbox.addEventListener('change', function() { saveInstrument(instrumentExternalCVCheckbox); collapseInstruments() });
instrument0Coast = document.getElementById('instrument_0coast');
instrumentStrega = document.getElementById('instrument_strega');
instrument0CTRL = document.getElementById('instrument_0ctrl');
instrumentDFAM = document.getElementById('instrument_dfam');
instrumentMavis = document.getElementById('instrument_mavis');
instrumentMother32 = document.getElementById('instrument_mother32');
instrumentSubharmonicon = document.getElementById('instrument_subharmonicon');
instrumentWerkstatt = document.getElementById('instrument_werkstatt');
instrumentExpandedRack = document.getElementById('instrument_expandedrack');
instrumentExternalCV = document.getElementById('instrument_externalcv');
noInstruments = document.getElementById('no_instruments');
// ********* Patch Name Menu *********
patchNameField.addEventListener('change', function() {
var value = patchNameField.value;
if (value === 'New Patch') {
var newPatchName = '';
var foundDuplicate = false;
var message = 'Enter a name for the new patch';
while (newPatchName === '' || foundDuplicate) {
newPatchName = prompt(message);
if (newPatchName === '') {
message = 'Patch name cannot be blank. Enter a name for the new patch or press Cancel to abort.';
}
else {
foundDuplicate = Object.keys(localStorage).indexOf(newPatchName) !== -1;
message = 'There is already a patch named ' + newPatchName + '. Enter a new name for the new patch or press Cancel to abort.';
}
}
if (newPatchName === null) {
patchNameField.value = workingPatch.patchName;
}
else {
makeNewPatch(newPatchName);
}
}
else if (value === 'Save As...') {
var newPatchName = '';
var defaultName = workingPatch.patchName + ' copy';
var foundDuplicate = false;
var message = 'Enter a name for the patch copy';
while (newPatchName === '' || foundDuplicate) {
newPatchName = prompt(message, defaultName);
if (newPatchName === '') {
message = 'Patch name cannot be blank. Enter a name for the patch copy or press Cancel to abort.';
}
else {
foundDuplicate = Object.keys(localStorage).indexOf(newPatchName) !== -1;
message = 'There is already a patch named ' + newPatchName + '. Enter a new name for the patch copy or press Cancel to abort.';
defaultName = newPatchName;
}
}
if (newPatchName === null) {
patchNameField.value = workingPatch.patchName;
}
else {
makeNewPatch(newPatchName, true);
}
}
else if (value === 'Rename') {
var newPatchName = '';
var defaultName = workingPatch.patchName;
var foundDuplicate = false;
var message = 'Enter a new name for the patch.';
while (newPatchName === '' || foundDuplicate) {
newPatchName = prompt(message, defaultName);
if (newPatchName === '') {
message = 'Patch name cannot be blank. Enter a new name for the patch or press Cancel to abort.';
}
else {
foundDuplicate = Object.keys(localStorage).indexOf(newPatchName) !== -1;
message = 'There is already a patch named ' + newPatchName + '. Enter a new name for the patch or press Cancel to abort.';
defaultName = newPatchName;
}
}
if (newPatchName === null) {
patchNameField.value = workingPatch.patchName;
}
else {
localStorage.removeItem(workingPatch.patchName);
workingPatch.patchName = newPatchName;
localStorage.setItem('workingPatchName', newPatchName);
savePatch();
location.reload();
}
}
else if (value === 'Delete') {
var confirmation = confirm('Press OK to delete ' + workingPatch.patchName + '. THIS CANNOT BE UNDONE!');
if (confirmation == true) {
localStorage.removeItem(workingPatch.patchName);
var allLocalStorage = Object.keys(localStorage);
var foundAPatch = false;
for (var i = 0; i < allLocalStorage.length; i++) {
var name = allLocalStorage[i];
if (name !== 'workingAuthor' && name !== 'workingPatchName' && name !== 'legacyPatches' && name !== 'superTopSecretCode') {
localStorage.setItem('workingPatchName', name);
foundAPatch = true;
break;
}
}
if (!foundAPatch) {
makeNewPatch('Untitled 1');
}
location.reload();
}
else {
patchNameField.value = workingPatch.patchName;
}
}
else if (value === '---------') {
}
else {
localStorage.setItem('workingPatchName', value);
location.reload();
}
});
// ********* Author Info *********
authorField.addEventListener('keyup', function() {
workingPatch.author = author.value;
localStorage.setItem('workingAuthor', author.value);
savePatch();
});
// ********* Patch Notes *********
patchNotesField.addEventListener('keyup', function() {
workingPatch.patchNotes = patchNotesField.value;
savePatch();
});
// ********* Pedalboard Preset *********
pedalboardPresetField.addEventListener('keyup', function() {
workingPatch.pedalboardPreset = pedalboardPresetField.value;
if (pedalboardPresetField.value.trim() === '') {
delete workingPatch.pedalboardPreset;
}
changeActive(pedalboardPresetField);
savePatch();
});
pedalboardPresetField.ondragover = function() {
this.className = 'hover';
return false;
};
pedalboardPresetField.ondragend = function() {
this.className = '';
return false;
};
pedalboardPresetField.ondrop = function(e) {
this.className = '';
e.preventDefault();
var file = e.dataTransfer.files[0],
reader = new FileReader();
reader.onload = function(event) {
pedalboardPresetField.value = event.target.result;
workingPatch.pedalboardPreset = pedalboardPresetField.value;
changeActive(pedalboardPresetField);
savePatch();
};
reader.readAsText(file);
return false;
};
pedalboardPresetSaveButton.addEventListener('click', function() {
var presetFile = new Blob([pedalboardPresetField.value], {type: 'text/plain'});
var tempAnchor = document.createElement("a"),
tempAnchorURL = URL.createObjectURL(presetFile);
tempAnchor.href = tempAnchorURL;
tempAnchor.download = workingPatch.patchName + '_pedalboard_preset';
document.body.appendChild(tempAnchor);
tempAnchor.click();
});
// ********* Sharing *********
shareButton.addEventListener('touch', function() { sharePatch() });
shareButton.addEventListener('click', function() { sharePatch() });
// *************************** Selects: Jack, Knob, MIDI Input ***************************
var allSelects = document.getElementsByTagName('select');
for (var i = 0; i < allSelects.length; i++) {
var element = allSelects[i];
if (element.classList.contains('knobs')) {
knobFields[element.id] = document.getElementById(element.id);
}
else if (element.classList.contains('jacks')) {
jackFields[element.id] = document.getElementById(element.id);
}
else if (element.classList.contains('midi')) {
midiFields[element.id] = document.getElementById(element.id);
}
}
for (const key in knobFields) {
const field = knobFields[key];
field.addEventListener('change', function() { saveKnob(field) });
}
for (const key in jackFields) {
const field = jackFields[key];
field.addEventListener('change', function() { saveJack(field) });
}
for (const key in midiFields) {
const field = midiFields[key];
field.addEventListener('change', function() { saveMIDI(field) });
}
// *************************** Plus Buttons ***************************
var allJacksPlusButtons = document.getElementsByClassName('plus');
for (var i = 0; i < allJacksPlusButtons.length; i++) {
var element = allJacksPlusButtons[i];
plusButtons[element.id] = document.getElementById(element.id);
}
for (const key in plusButtons) {
const field = plusButtons[key];
field.addEventListener('touch', function() { newJackConnection(key) });
field.addEventListener('click', function() { newJackConnection(key) });
}
// *************************** Special Fields ***************************
// ********* 0-Coast clock *********
clockSpeedField = document.getElementById('nocoast_clock_speed');
clockSpeedTypeField = document.getElementById('nocoast_clock_speed_type');
clockSpeedMultiplierField = document.getElementById('nocoast_clock_speed_multiplier');
midiALFOSpeedField = document.getElementById('nocoast_midi_a_speed');
midiALFOSpeedTypeField = document.getElementById('nocoast_midi_a_speed_type');
midiALFOSpeedMultiplierField = document.getElementById('nocoast_midi_a_multiplier');
midiBLFOSpeedField = document.getElementById('nocoast_midi_b_speed');
midiBLFOSpeedTypeField = document.getElementById('nocoast_midi_b_speed_type');
midiBLFOSpeedMultiplierField = document.getElementById('nocoast_midi_b_multiplier');
clockSpeedField.addEventListener('keyup', function() { saveClock(clockSpeedField, true) });
clockSpeedTypeField.addEventListener('change', function() { saveClock(clockSpeedTypeField, false, clockSpeedMultiplierField) });
clockSpeedMultiplierField.addEventListener('change', function() { saveClock(clockSpeedMultiplierField, false) });
midiBLFOSpeedField.addEventListener('keyup', function() { saveClock(midiBLFOSpeedField, true) });;
midiBLFOSpeedTypeField.addEventListener('change', function() { saveClock(midiBLFOSpeedTypeField, false, midiBLFOSpeedMultiplierField) });
midiBLFOSpeedMultiplierField.addEventListener('change', function() { saveClock(midiBLFOSpeedMultiplierField, false) });
// ********* Coast Express *********
var coastExpressHelp = document.getElementById('coast_express_help');
var coastExpressHelpToggle = document.getElementById('coast_express_help_toggle');
coastExpressHelpToggle.addEventListener('click', function() {
if (coastExpressHelp.classList.contains('collapse')) {
coastExpressHelp.classList.remove('collapse');
coastExpressHelpToggle.classList.add('open');
}
else {
coastExpressHelp.classList.add('collapse');
coastExpressHelpToggle.classList.remove('open');
}
});
coastExpressLinkImage = document.getElementById('coast_express_link');
coastExpressLinkAnchor = document.getElementById('coast_express_link_anchor');
coastExpressShareLinkInput = document.getElementById('coast_express_share_link');
coastExpressShareLinkInput.addEventListener('focus', function() {
var promptText = 'Paste Share Link from ce.rustle.works here.'
var promptDefault = '';
if (workingPatch.midiInput && workingPatch.midiInput.coastExpressLink) {
promptText += ' Remove the link below if you wish to remove the previously shared link.';
promptDefault = workingPatch.midiInput.coastExpressLink;
}
var link = prompt(promptText, promptDefault);
coastExpressShareLinkInput.blur();
if (link === '' && promptDefault !== '') {
delete workingPatch.midiInput['coastExpressLink'];
savePatch();
insertCoastExpressShareLink();
}
else if (link || link === '') {
var compressedPatch = link.split('/?patch=')[1];
if (!compressedPatch) {
alert('The text entered does not seem to ba a Coast Express Share Link. Please try again.')
coastExpressShareLinkInput.focus();
}
else {
if (!workingPatch.midiInput) {
workingPatch.midiInput = {}
}
workingPatch.midiInput.coastExpressLink = compressedPatch;
savePatch();
insertCoastExpressShareLink();
}
}
});
// *************************** First Run or Load Share or Load Patch ***************************
// *** Forget select positions if Firefox
if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1){
Array.from(document.getElementsByTagName('select')).forEach(element => {
const classes = element.classList;
if (classes.contains('knobs') || classes.contains('clocks')) {
element.value = '';
}
});
document.getElementById('nocoast_clock_speed').value = '';
document.getElementById('nocoast_midi_b_speed').value = '';
}
var savedWorkingPatchName;
var sharedPatchCode = window.location.search.replace('?patch=', '');
var sharedPatchUncompressed = LZString.decompressFromEncodedURIComponent(sharedPatchCode);
var sharedPatchUncompressedObject;
if (sharedPatchUncompressed && sharedPatchUncompressed.indexOf('"a":"') !== -1) {
try {
sharedPatchUncompressedObject = JSON.parse(sharedPatchUncompressed);
} catch (error) {
alert('The shared patch appears to be invalid. Please check the URL and try again');
history.pushState(sharedPatchCode, '', window.location.pathname);
}
savedWorkingPatchName = loadLegacyShareLink(sharedPatchCode, sharedPatchUncompressedObject);
}
else if (sharedPatchUncompressed) {
stringCodes.forEach(code => {
var regex = new RegExp(code[0], 'g');
sharedPatchUncompressed = sharedPatchUncompressed.replace(regex, code[1]);
});
try {
sharedPatchUncompressedObject = JSON.parse(sharedPatchUncompressed);
} catch (error) {
console.log(sharedPatchUncompressed);
console.log(error);
alert('The shared patch appears to be invalid. Please check the URL and try again');
history.pushState(sharedPatchCode, '', window.location.pathname);
}
if (sharedPatchUncompressedObject) {
savedWorkingPatchName = sharedPatchUncompressedObject.patchName;
var cancelLoad = false;
while (Object.keys(localStorage).indexOf(savedWorkingPatchName) !== -1 && !cancelLoad) {
var newPatchName = prompt('You already have a patch named ' + savedWorkingPatchName + '. Please enter a new name for the shared patch.', savedWorkingPatchName);
if (newPatchName === null) {
cancelLoad = true;
}
else if (newPatchName !== '') {
savedWorkingPatchName = newPatchName;
}
}
if (!cancelLoad) {
sharedPatchUncompressedObject.patchName = savedWorkingPatchName;
localStorage.setItem('workingPatchName', savedWorkingPatchName);
localStorage.setItem(savedWorkingPatchName, JSON.stringify(sharedPatchUncompressedObject));
}
else {
savedWorkingPatchName = undefined;
}
history.pushState(sharedPatchCode, '', window.location.pathname);
}
}
if (!savedWorkingPatchName) {
savedWorkingPatchName = localStorage['workingPatchName'];
}
if (savedWorkingPatchName) {
workingPatch = JSON.parse(localStorage[savedWorkingPatchName]);
var allLocalStorage = Object.keys(localStorage);
allLocalStorage.sort();
for (var i = 0; i < allLocalStorage.length; i++) {
var name = allLocalStorage[i];
if (name !== 'workingAuthor' && name !== 'workingPatchName' && name !== 'legacyPatches' && name !== 'superTopSecretCode') {
addPatchNameToSelect(name, false);
}
}
loadSavedPatch();
}
else {
makeNewPatch('Untitled 1');
setTimeout(function() {
menuButton.click();
}, 1100);
}
setTimeout(() => {
var isChrome = navigator.userAgent.indexOf('Chrome') > -1;
var isSafari = navigator.userAgent.indexOf("Safari") > -1;
var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
var isIPad = navigator.userAgent.match(/Mac/) && navigator.maxTouchPoints && navigator.maxTouchPoints > 2;
if (isIOS || isIPad) {
if (window.navigator.standalone !== true) {
alert('The use of the Safari browser is strongly discouraged for Exquisite Coasts. Safari deletes local storage data after seven days so you are at risk of losing all your saved patches. To safely use Exquisite Coasts on your iPhone or iPad you must save the website to your homescreen. To do that, tap the share icon in the Safari menu bar and select "Add to Homescreen."');
}
}
else if (isSafari) {
if (!isChrome) {
alert('The use of the Safari browser is strongly discouraged for Exquisite Coasts. Safari deletes local storage data after seven days so you are at risk of losing all your saved patches. The Firefox or Chrome browsers are recommended for all macOS users.');
}
}
}, 2500);
}
} // *** /window.onload
// *************************** Save & Load Patches ***************************
function savePatch() {
localStorage.setItem(workingPatch.patchName, JSON.stringify(workingPatch));
}
function loadSavedPatch() {
if (workingPatch.version) {
patchNameField.value = workingPatch.patchName;
if (workingPatch.author) {
authorField.value = workingPatch.author;
}
if (workingPatch.patchNotes) {
patchNotesField.value = workingPatch.patchNotes;
}
if (workingPatch.pedalboardPreset) {
pedalboardPresetField.value = workingPatch.pedalboardPreset;
changeActive(pedalboardPresetField);
}
if (workingPatch.instruments && workingPatch.instruments.indexOf('0-Coast') !== -1) {
instrument0CoastCheckbox.checked = true;
}
else {
instrument0CoastCheckbox.checked = false;
}
if (workingPatch.instruments && workingPatch.instruments.indexOf('Strega') !== -1) {
instrumentStregaCheckbox.checked = true;
}
else {
instrumentStregaCheckbox.checked = false;
}
if (workingPatch.instruments && workingPatch.instruments.indexOf('0-CTRL') !== -1) {
instrument0CTRLCheckbox.checked = true;
}
else {
instrument0CTRLCheckbox.checked = false;
}
if (workingPatch.instruments && workingPatch.instruments.indexOf('DFAM') !== -1) {
instrumentDFAMCheckbox.checked = true;
}
else {
instrumentDFAMCheckbox.checked = false;
}
if (workingPatch.instruments && workingPatch.instruments.indexOf('Mavis') !== -1) {
instrumentMavisCheckbox.checked = true;
}
else {
instrumentMavisCheckbox.checked = false;
}
if (workingPatch.instruments && workingPatch.instruments.indexOf('Mother 32') !== -1) {
instrumentMother32Checkbox.checked = true;
}
else {
instrumentMother32Checkbox.checked = false;
}
if (workingPatch.instruments && workingPatch.instruments.indexOf('Subharmonicon') !== -1) {
instrumentSubharmoniconCheckbox.checked = true;
}
else {
instrumentSubharmoniconCheckbox.checked = false;
}
if (workingPatch.instruments && workingPatch.instruments.indexOf('Werkstatt') !== -1) {
instrumentWerkstattCheckbox.checked = true;
}
else {
instrumentWerkstattCheckbox.checked = false;
}
if (superTopSecretCode) {
if (workingPatch.instruments && workingPatch.instruments.indexOf('Expanded Rack') !== -1) {
instrumentExpandedRackCheckbox.checked = true;
}
else {
instrumentExpandedRackCheckbox.checked = false;
}
if (workingPatch.instruments && workingPatch.instruments.indexOf('External CV') !== -1) {
instrumentExternalCVCheckbox.checked = true;
}
else {
instrumentExternalCVCheckbox.checked = false;
}
}
if (workingPatch.clockSpeeds) {
if (workingPatch.clockSpeeds.nocoast_clock_speed) {
clockSpeedField.value = workingPatch.clockSpeeds.nocoast_clock_speed;
changeActive(clockSpeedField);
}
clockSpeedTypeField.value = workingPatch.clockSpeeds.nocoast_clock_speed_type;
toggleMultiplierFieldVisibility(clockSpeedTypeField, clockSpeedMultiplierField)
if (workingPatch.clockSpeeds.nocoast_clock_speed_multiplier) {
clockSpeedMultiplierField.value = workingPatch.clockSpeeds.nocoast_clock_speed_multiplier;
}
if (workingPatch.clockSpeeds.nocoast_midi_b_speed) {
midiBLFOSpeedField.value = workingPatch.clockSpeeds.nocoast_midi_b_speed;
changeActive(midiBLFOSpeedField);
}
midiBLFOSpeedTypeField.value = workingPatch.clockSpeeds.nocoast_midi_b_speed_type;
toggleMultiplierFieldVisibility(midiBLFOSpeedTypeField, midiBLFOSpeedMultiplierField)
if (workingPatch.clockSpeeds.nocoast_midi_b_multiplier) {
midiBLFOSpeedMultiplierField.value = workingPatch.clockSpeeds.nocoast_midi_b_multiplier;
}
}
for (const key in workingPatch.knobs) {
if (workingPatch.knobs[key] === '7:00') {
workingPatch.knobs[key] = 'min';
savePatch();
}
else if (workingPatch.knobs[key] === '5:00') {
workingPatch.knobs[key] = 'max';
savePatch();
}
else if (workingPatch.knobs[key] === '') {
delete workingPatch.knobs[key];
savePatch();
}
knobFields[key].value = workingPatch.knobs[key];
changeActive(knobFields[key]);
}
for (const key in workingPatch.midiInput) {
if (key !== 'coastExpressLink') {
midiFields[key].value = workingPatch.midiInput[key];
changeActive(midiFields[key]);
}
}
collapseInstruments();
insertAllJackDestinations();
selectAllJacks();
insertCoastExpressShareLink();
}
else {
convertOnePointOhPatch();
}
shareButton.innerHTML = 'Get Share Link';
}
function selectAllJacks(update) {
for (const key in workingPatch.jacks) {
var connections = workingPatch.jacks[key];
if (!workingPatch.jacks[key].length) {
delete workingPatch.jacks[key];
savePatch();
}
for (var i = 0; i < connections.length; i++) {
if (connections[i].indexOf('Disting:') !== -1) {
connections[i] = connections[i].replace('Disting:', 'Disting 1:');
}
var jackSelect = jackFields[key + '_' + i];
if (!jackSelect) {
if (!update) {
newJackConnection(key + '_plus');
}
jackSelect = document.getElementById(key + '_' + i)
}
jackSelect.value = connections[i];
if (i === 0) {
changeActive(jackSelect);
}
}
}
}
function makeNewPatch(name, shouldcopy) {
if (!shouldcopy) {
workingPatch = {}
workingPatch.version = "2.0"
}
workingPatch.patchName = name;
var savedAuthor = localStorage.getItem('workingAuthor');
if (savedAuthor) {
workingPatch.author = savedAuthor;
if (name === 'Untitled 1') {
authorField.value = savedAuthor
}
}
localStorage.setItem('workingPatchName', name);
savePatch();
addPatchNameToSelect('Untitled 1', true);
if (name !== 'Untitled 1') {
location.reload();
}
}
function addPatchNameToSelect(name, selected) {
var option = document.createElement('option');
option.textContent = name;
option.value = name;
if (selected) {
option.selected = true;
}
patchNameField.add(option);
}
// *************************** Saving Fields to workingPatch ***************************
function saveInstrument(field) {
var instrumentGuide = {
'instrument_checkbox_0coast': '0-Coast',
'instrument_checkbox_strega': 'Strega',
'instrument_checkbox_0ctrl': '0-CTRL',
'instrument_checkbox_dfam': 'DFAM',
'instrument_checkbox_mavis': 'Mavis',
'instrument_checkbox_mother32': 'Mother 32',
'instrument_checkbox_subharmonicon': 'Subharmonicon',
'instrument_checkbox_werkstatt': 'Werkstatt',
'instrument_checkbox_expandedrack': 'Expanded Rack',
'instrument_checkbox_externalcv': 'External CV'
}
if (!workingPatch.instruments) {
workingPatch.instruments = [];
}
if (field.checked) {
if (workingPatch.instruments.indexOf(field.id) === -1) {
workingPatch.instruments.push(instrumentGuide[field.id])
}
}
else {
var index = workingPatch.instruments.indexOf(instrumentGuide[field.id]);
if (index !== -1) {
workingPatch.instruments.splice(index, 1);
}
}
insertAllJackDestinations();
selectAllJacks(true);
savePatch();
}
function saveKnob(field) {
if (!workingPatch.knobs) {
workingPatch.knobs = {};
}
if (field.value === '') {
delete workingPatch.knobs[field.id];
savePatch();
}
else {
workingPatch.knobs[field.id] = field.value;
}
changeActive(field);
savePatch();
}
function saveJack(field) {
if (!workingPatch.jacks) {
workingPatch.jacks = {};
}
var jackName = field.id.replace(/_[0-9]/, '');
var connectionNumber = field.id.replace(/.*_/, '');
if (workingPatch.jacks[jackName]) {
if (field.value !== '') {
workingPatch.jacks[jackName][connectionNumber] = field.value;
}
else {
const isNotLastItem = connectionNumber < workingPatch.jacks[jackName].length - 1;
workingPatch.jacks[jackName].splice(connectionNumber, 1);
if (isNotLastItem) {
location.reload();
}
}
}
else {
workingPatch.jacks[jackName] = [field.value]
}
if (parseInt(connectionNumber) === 0) {
if ((field.value === '' && !workingPatch.jacks[jackName].length) || field.value !== '') {
changeActive(field);
}
}
if (!workingPatch.jacks[jackName].length) {
delete workingPatch.jacks[jackName];
}
savePatch();
}
function saveClock(field, changeactive, mulitiplierfield) {
if (!workingPatch.clockSpeeds) {
workingPatch.clockSpeeds = {};
}
workingPatch.clockSpeeds[field.id] = field.value;
if (changeactive) {
changeActive(field);
}
if (mulitiplierfield) {
toggleMultiplierFieldVisibility(field, mulitiplierfield);
}
savePatch();
}
function toggleMultiplierFieldVisibility(field, mulitiplierfield) {
if (field.value === 'bpm') {
mulitiplierfield.classList.remove('hidden')
}
else {
mulitiplierfield.classList.add('hidden')
}
}
function saveMIDI(field) {
if (!workingPatch.midiInput) {
workingPatch.midiInput = {};
}
workingPatch.midiInput[field.id] = field.value;
changeActive(field);
savePatch();
}
// *************************** Interface Manipulation ***************************
function collapseInstruments() {
var instrumentsSelected = false;
if (instrument0CoastCheckbox.checked) {
instrument0Coast.classList.remove('collapse');
instrumentsSelected = true;
}
else {
instrument0Coast.classList.add('collapse');
}
if (instrumentStregaCheckbox.checked) {
instrumentStrega.classList.remove('collapse');
instrumentsSelected = true;
}
else {
instrumentStrega.classList.add('collapse');
}
if (instrument0CTRLCheckbox.checked) {
instrument0CTRL.classList.remove('collapse');
instrumentsSelected = true;
}
else {
instrument0CTRL.classList.add('collapse');
}
if (instrumentDFAMCheckbox.checked) {
instrumentDFAM.classList.remove('collapse');
instrumentsSelected = true;
}
else {
instrumentDFAM.classList.add('collapse');
}
if (instrumentMavisCheckbox.checked) {
instrumentMavis.classList.remove('collapse');
instrumentsSelected = true;
}
else {
instrumentMavis.classList.add('collapse');
}
if (instrumentMother32Checkbox.checked) {
instrumentMother32.classList.remove('collapse');
instrumentsSelected = true;
}
else {
instrumentMother32.classList.add('collapse');
}
if (instrumentSubharmoniconCheckbox.checked) {
instrumentSubharmonicon.classList.remove('collapse');
instrumentsSelected = true;
}
else {
instrumentSubharmonicon.classList.add('collapse');
}
if (instrumentWerkstattCheckbox.checked) {
instrumentWerkstatt.classList.remove('collapse');
instrumentsSelected = true;
}
else {
instrumentWerkstatt.classList.add('collapse');
}
if (instrumentExpandedRackCheckbox.checked) {
instrumentExpandedRack.classList.remove('collapse');
instrumentsSelected = true;
}
else {
instrumentExpandedRack.classList.add('collapse');
}
if (instrumentExternalCVCheckbox.checked) {