-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
1935 lines (1610 loc) · 75.5 KB
/
index.html
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
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Configuratore SimpleFader</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #121212;
color: #f5f5f5;
text-align: center;
margin: 0;
padding: 0;
}
label[for="fader-number"] {
margin-bottom: 5px;
}
label {
display: block;
padding-top: 15px;
box-sizing: border-box;
}
.container {
max-width: 800px;
margin: 50px auto;
padding: 20px;
background-color: #1e1e1e;
border-radius: 18px;
box-shadow: 0 0 20px 5px rgba(0, 0, 0, 0.6); /* Ombra più grande e intensa */
border: 2px solid rgb(0, 0, 171);
}
.midi-container {
display: none; /* Nascondi il contenitore di default */
max-width: 600px;
margin: 30px auto;
padding: 5px;
border-radius: 18px;
overflow: visible; /* Permette la crescita naturale */
}
h1 {
font-size: 32px;
margin-bottom: 30px;
letter-spacing: 2px;
color: white;
/* text-shadow: -1px -1px 0 grey, 1px -1px 0 grey, -1px 1px 0 grey, 1px 1px 0 grey; */
}
h3 {
font-size: 20px;
color: #ffa726;
margin-top: 30px;
margin-bottom: 10px;
text-align: left;
}
button {
padding: 10px 20px;
font-size: 16px;
background-color: #6200ea;
color: white;
border: none;
border-radius: 15px;
cursor: pointer;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
}
button:hover {
background-color: #3700b3;
box-shadow: 0 0 15px rgba(255, 255, 255, 0.8); /* Alone più evidente */
}
.button2 {
cursor: pointer;
padding: 15px; /* Aumenta lo spazio interno */
border: 2px solid #777;
border-radius: 50%;
font-size: 16px; /* Aumenta la dimensione del testo */
width: 2px; /* Imposta una larghezza maggiore */
height: 2px; /* Imposta un'altezza maggiore */
}
.button2:hover {
box-shadow: 0 0 15px rgba(255, 255, 0.8); /* Alone più evidente */
}
.color-box {
width: 20px;
height: 20px;
margin: 2px;
display: inline-block;
cursor: pointer;
border-radius: 50%; /* Trasforma in cerchio */
position: relative;
border: 2px solid #777;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
}
.color-menu {
display: none;
position: absolute;
top: 100%;
left: 0;
background-color: #222;
border: 2px solid #555;
padding: 10px;
border-radius: 5px;
z-index: 10; /* Per evitare sovrapposizioni */
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
}
.color-option {
width: 20px;
height: 20px;
cursor: pointer;
border-radius: 50%; /* Trasforma in cerchio */
border: 1px solid #000;
box-shadow: 0 0 5px rgba(255, 255, 255, 0.5); /* Alone di default */
}
.color-option:hover {
box-shadow: 0 0 15px rgba(255, 255, 255, 0.8); /* Alone più evidente */
}
.color-box:hover {
box-shadow: 0 0 15px rgba(255, 255, 0.8); /* Alone più evidente */
}
.color-menu.active {
display: flex;
flex-wrap: wrap;
gap: 10px; /* Spazio tra i pulsanti nel menu colori */
}
.menu-container {
display: flex;
flex-direction: column;
align-items: center;
}
.fader-label {
font-weight: bold;
}
#fader-number {
display: block;
margin: 0 auto;
margin-bottom: 20px;
}
.row {
display: flex;
gap: 20px; /* Spazio tra gli elementi della stessa riga */
align-items: center;
position: relative; /* Per il posizionamento del menu colori */
margin-bottom: 40px; /* Spazio aggiuntivo tra le righe */
}
.row2 {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 8px; /* Ridotto lo spazio tra i pulsanti */
align-items: center;
margin-bottom: 15px; /* Meno spazio tra le righe */
}
.dropdown-button {
background-color: #333; /* Colore uniforme senza gradiente */
color: white;
padding: 12px 24px;
border: 2px solid #04007a; /* Bordo originale */
border-radius: 10px; /* Angoli arrotondati */
cursor: pointer;
font-size: 16px;
font-weight: bold;
letter-spacing: 1px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2); /* Effetto leggero 3D */
}
.dropdown-button:hover {
box-shadow: 0 6px 14px rgba(0, 0, 0, 0.5); /* Ombra più intensa */
}
.dropdown-menu {
background-color: white; /* Sfondo del menu bianco */
border: 1px solid #ccc; /* Bordo sottile per definizione */
border-radius: 10px;
padding: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15); /* Leggera ombra per profondità */
}
/* Definizioni duplicate di .coloreBordo e select (mantenute una volta sola) */
.coloreBordo {
width: calc(100% - 20px);
background-color: #333; /* Colore uniforme senza gradiente */
color: white;
padding: 10px;
margin-top: 8px;
border: 2px solid #00537a; /* Bordo originale */
border-radius: 10px; /* Angoli arrotondati */
cursor: pointer;
font-size: 16px;
font-weight: bold;
letter-spacing: 1px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2); /* Effetto leggero 3D */
}
select {
width: calc(100% - 20px);
background-color: #333; /* Colore uniforme senza gradiente */
color: white;
padding: 10px;
margin-top: 8px;
border: 2px solid #6200ea; /* Bordo originale */
border-radius: 10px; /* Angoli arrotondati */
cursor: pointer;
font-size: 16px;
font-weight: bold;
letter-spacing: 1px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2); /* Effetto leggero 3D */
margin-left: 10px;
margin-right: 10px;
margin-bottom: 10px;
}
#status {
margin: 20px 0;
font-size: 14px;
color: #ffa726;
}
h4 {
font-size: 14px;
font-style: italic;
color: #bbb;
margin-top: 15px;
text-align: center;
}
/* --- Regole per il Toggle Switch (già presenti nel tema, mantenute) --- */
.toggle-wrapper {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
margin-top: 10px;
}
.toggle-switch {
position: relative;
display: inline-block;
width: 50px;
height: 26px;
}
.toggle-switch input {
opacity: 0;
width: 0;
height: 0;
}
.toggle-slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #626262;
transition: 0.3s;
border-radius: 13px;
}
.toggle-slider::before {
position: absolute;
content: "";
height: 20px;
width: 20px;
left: 3px;
bottom: 3px;
background-color: rgb(231, 231, 231);
border-radius: 50%;
transition: 0.3s;
}
.toggle-switch:hover .toggle-slider {
background-color: #787878;
}
input:checked + .toggle-slider {
background-color: #006b15;
}
.toggle-switch:hover input:checked + .toggle-slider {
background-color: #00851b;
}
input:checked + .toggle-slider::before {
transform: translateX(24px);
}
/* --- Aggiunte per i controlli MIDI dinamici --- */
/* Contenitore per i controlli MIDI (usato con appendChild) */
#controlContainer {
margin-top: 20px;
}
/* Container dei pulsanti: allineati a sinistra */
#buttonContainer {
margin: 20px 0;
display: flex;
justify-content: flex-start; /* Allinea a sinistra */
gap: 10px;
}
/* Pulsanti interni al container dei controlli (estensione delle regole esistenti) */
#buttonContainer button.active {
background-color: #006b15;
box-shadow: 0 0 15px rgba(0, 255, 0, 0.8);
}
.midi-list {
list-style: none;
padding: 0;
max-height: none; /* Evita qualsiasi limite in altezza */
overflow: visible; /* Permette la crescita naturale */
overflow-y: auto;
text-align: left;
}
.midi-list li {
background: #252525;
margin: 5px 0;
padding: 10px;
border-radius: 10px;
border-left: 5px solid #6200ea;
font-size: 14px;
font-family: monospace;
}
#midi-messages {
white-space: pre;
text-align: center;
letter-spacing: 1px;
font-size: medium;
/* color: #33FF33; */
}
.inverti {
display: none;
}
.tab-container {
display: flex;
justify-content: left;
margin-top: 20px;
}
.tab {
padding: 10px 20px;
font-size: 16px;
background-color: transparent;
color: white;
border: none;
border-bottom: 3px solid transparent;
cursor: pointer;
transition: border-bottom 0.3s;
background-color: #383838;
border-radius: 15px 15px 0 0; /* Arrotonda solo gli angoli superiori */
}
.tab.active {
background-color: #505050;
border-radius: 15px 15px 0 0; /* Arrotonda solo gli angoli superiori */
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
background-color: #505050;
border-radius: 0 15px 15px 15px; /* Arrotonda solo gli angoli superiori */
}
</style>
</head>
<body>
<div class="container">
<h1>Configuratore SimpleFader</h1>
<button id="connect">Connetti</button>
<div id="status"></div>
<div class ='inverti'>
<button id="invertLed">💡 Inverti Comportamento LED</button>
<h4>Mantieni il LED spento o acceso</h4>
<div class="toggle-wrapper">
<label class="toggle-switch">
<input type="checkbox" id="invertFader">
<span class="toggle-slider"></span>
</label>
</div>
<h4>Attiva se vuoi invertire la direzione del fader</h4>
</div>
<h3 style="text-align: left;">Comportamento Pulsante</h3>
<select class="dropdown-button" id="buttonBehavior">
<option value="1" selected>Seleziona una Opzione</option>
<option value="switch">Cambia Numero di Fader</option>
<option value="keyboard">Pulsante Tastiera</option>
<option value="controlChange">Control Change o Program Change</option>
</select>
<div id="controlContainer"></div>
<div id="additionalOptions"></div>
<div class="midi-container">
<h4>Log Messaggi in Ingresso</h4>
<ul id="midi-messages" class="midi-list"></ul>
</div>
</div>
<script>
let midiAccess = null;
let selectedOutput = null;
let btnCC, btnPC;
let additionalOptions = document.getElementById("additionalOptions");
let ccContent = document.createElement("div");
let pcContent = document.createElement("div");
const colors = ['white', 'red', 'orange', 'yellow', 'lime', 'cyan', 'blue', 'magenta', 'pink', 'lightskyblue', 'sandybrown', 'lightgreen', 'hotpink'];
// color = colors[0]; // Define a default color
const languages = [
{ code: "US", name: "English (US)" },
{ code: "IT", name: "Italiano (IT)" },
{ code: "HU", name: "Magyar (HU)" },
{ code: "ES", name: "Español (ES)" },
{ code: "FR", name: "Français (FR)" },
{ code: "PT", name: "Português (PT)" },
{ code: "SE", name: "Svenska (SE)" },
{ code: "DK", name: "Dansk (DK)" },
{ code: "DE", name: "Deutsch (DE)" }
];
document.addEventListener("DOMContentLoaded", () => {
const buttonBehavior = document.getElementById("buttonBehavior");
// const additionalOptions = document.getElementById("additionalOptions");
const controlContainer = document.getElementById("controlContainer");
function getBrowserLanguage() {
const supportedLanguages = ["US", "IT", "HU", "ES", "FR", "PT", "SE", "DK", "DE"];
const browserLang = navigator.language || (navigator.languages && navigator.languages[0]) || "US";
// Prendi la parte del paese (es. "it-IT" -> "IT")
const code = browserLang.split('-')[1] ? browserLang.split('-')[1].toUpperCase() : browserLang.toUpperCase();
return supportedLanguages.includes(code) ? code : "US";
}
function updateKeyboardKeys(language, keySelect) {
const keys = getKeysByLanguage(language);
keySelect.innerHTML = ""; // Pulisce le opzioni esistenti
// Creazione dell'opzione predefinita
const defaultOption = document.createElement("option");
defaultOption.value = "";
defaultOption.textContent = "Seleziona un tasto";
defaultOption.disabled = true;
defaultOption.selected = true;
keySelect.appendChild(defaultOption);
// Aggiunta delle opzioni basate sulle chiavi della lingua selezionata
keys.forEach(key => {
const option = document.createElement("option");
option.value = key;
option.textContent = key;
keySelect.appendChild(option);
});
}
function updateAdditionalOptions() {
additionalOptions.innerHTML = ""; // Clear previous options
controlContainer.innerHTML = ""; // Clear previous options
if (buttonBehavior.value === "keyboard") {
// Etichetta per il tasto della tastiera
const keyLabel = document.createElement("label");
keyLabel.setAttribute("for", "keyboardKeys");
keyLabel.textContent = "Tasto della tastiera da emulare: ";
additionalOptions.appendChild(keyLabel);
// Selettore del tasto della tastiera
const keySelect = document.createElement("select");
keySelect.className = "coloreBordo";
keySelect.id = "keyboardKeys";
additionalOptions.appendChild(keySelect);
// Etichetta per la lingua della tastiera
const langLabel = document.createElement("label");
langLabel.setAttribute("for", "keyboardLanguage");
langLabel.textContent = "Seleziona la lingua della tastiera: ";
additionalOptions.appendChild(langLabel);
// Selettore della lingua della tastiera
const langSelect = document.createElement("select");
langSelect.className = "coloreBordo";
langSelect.id = "keyboardLanguage";
languages.forEach(lang => {
const option = document.createElement("option");
option.value = lang.code;
option.textContent = lang.name;
langSelect.appendChild(option);
});
additionalOptions.appendChild(langSelect);
// Imposta il valore di default del menu sulla lingua del browser
const defaultLang = getBrowserLanguage();
langSelect.value = defaultLang; // Imposta l'opzione predefinita
// Aggiorna la lista dei tasti in base alla lingua selezionata
langSelect.addEventListener("change", () => {
updateKeyboardKeys(langSelect.value, keySelect);
});
// Carica la lista dei tasti iniziali per la lingua predefinita
// updateKeyboardKeys(langSelect.value || "US", keySelect);
// Determina la lingua da usare (valore selezionato o lingua del browser con fallback)
updateKeyboardKeys(defaultLang, keySelect);
addKeyboardKeysListener();
funzione();
} else if (buttonBehavior.value === "controlChange") {
const tabContainer = document.createElement("div");
tabContainer.className = "tab-container";
const btnCC = document.createElement("buttonn");
btnCC.className = "tab active";
btnCC.textContent = "Control Change";
tabContainer.appendChild(btnCC);
const btnPC = document.createElement("buttonn");
btnPC.className = "tab";
btnPC.textContent = "Program Change";
tabContainer.appendChild(btnPC);
controlContainer.appendChild(tabContainer);
// const ccContent = document.createElement("div");
ccContent.className = "tab-content active";
controlContainer.appendChild(ccContent);
// const pcContent = document.createElement("div");
pcContent.className = "tab-content";
controlContainer.appendChild(pcContent);
// Aggiungiamo i listener ai pulsanti
btnCC.addEventListener("click", () => {
btnCC.classList.add("active");
btnPC.classList.remove("active");
ccContent.classList.add("active");
pcContent.classList.remove("active");
buildControlChangeMenus();
});
btnPC.addEventListener("click", () => {
btnPC.classList.add("active");
btnCC.classList.remove("active");
pcContent.classList.add("active");
ccContent.classList.remove("active");
buildProgramChangeMenus();
});
// Di default mostriamo il menu per CC
buildControlChangeMenus();
funzione();
buttonBehavior.addEventListener("change", updateAdditionalOptions);
// funzione();
}
else if (buttonBehavior.value === "switch") {
const faderLabel = document.createElement("label");
faderLabel.setAttribute("for", "fader-number");
faderLabel.textContent = "Numero Fader: ";
additionalOptions.appendChild(faderLabel);
const faderSelect = document.createElement("select");
faderSelect.id = "fader-number";
faderSelect.innerHTML = `
<option value="" disabled selected>Seleziona Numero di Fader</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
`;
additionalOptions.appendChild(faderSelect);
const menusContainer = document.createElement("div");
menusContainer.id = "menus";
menusContainer.className = "menu-container";
additionalOptions.appendChild(menusContainer);
faderSelect.addEventListener("change", () => updateMenus(faderSelect.value));
const saveButton = document.createElement("button");
saveButton.textContent = "Salva nel Dispositivo";
saveButton.style.backgroundColor = "#ffa726";
saveButton.style.color = "#121212";
saveButton.style.margin = "20px 0 0 0";
saveButton.addEventListener("mouseover", () => {
saveButton.style.backgroundColor = "#ff9800";
});
saveButton.addEventListener("mouseout", () => {
saveButton.style.backgroundColor = "#ffa726";
});
saveButton.addEventListener("click", () => {
if (!selectedOutput) {
alert("Nessun dispositivo MIDI connesso!");
return;
}
const message = [0x90, 20, 20];
selectedOutput.send(message);
console.log(`Inviato: ${message.join(", ")}`);
});
additionalOptions.appendChild(saveButton);
const subtitle = document.createElement("h4");
subtitle.textContent = "Salva la configurazione corrente nel dispositivo in modo che permanga al riavvio";
additionalOptions.appendChild(subtitle);
}
}
// Imposta il pulsante attivo (stile)
function setActiveButton(activeButton) {
[btnCC, btnPC].forEach(btn => {
if (btn === activeButton) {
btn.classList.add("active");
} else {
btn.classList.remove("active");
}
});
}
// Costruisce i menu per Control Change (CC)
function buildControlChangeMenus() {
// additionalOptions.innerHTML = "";
ccContent.innerHTML = "";
// Primo menu: Canale MIDI
const channelLabel = document.createElement("label");
channelLabel.setAttribute("for", "controlChangeChannel");
channelLabel.textContent = "Canale MIDI Control Change:";
ccContent.appendChild(channelLabel);
const channelSelect = document.createElement("select");
channelSelect.className = "coloreBordo";
channelSelect.id = "controlChangeChannel";
// Opzione di default (disabilitata e selezionata)
const defaultChannelOption = document.createElement("option");
defaultChannelOption.value = "1";
defaultChannelOption.textContent = "1 (Default)";
defaultChannelOption.disabled = true;
defaultChannelOption.selected = true;
channelSelect.appendChild(defaultChannelOption);
for (let i = 1; i <= 16; i++) {
const option = document.createElement("option");
option.value = i;
option.textContent = i;
channelSelect.appendChild(option);
}
ccContent.appendChild(channelSelect);
// Secondo menu: Valore MIDI Control Change
const valueLabel = document.createElement("label");
valueLabel.setAttribute("for", "controlChangeValue");
valueLabel.textContent = "Valore MIDI Control Change:";
ccContent.appendChild(valueLabel);
const valueSelect = document.createElement("select");
valueSelect.className = "coloreBordo";
valueSelect.id = "controlChangeValue";
const defaultValueOption = document.createElement("option");
defaultValueOption.value = "2";
defaultValueOption.textContent = "2 (Default)";
defaultValueOption.disabled = true;
defaultValueOption.selected = true;
valueSelect.appendChild(defaultValueOption);
for (let i = 0; i <= 127; i++) {
const option = document.createElement("option");
option.value = i;
option.textContent = i;
valueSelect.appendChild(option);
}
ccContent.appendChild(valueSelect);
// Aggiungiamo i listener per i menu
channelSelect.addEventListener("change", pulsanteCCListener);
valueSelect.addEventListener("change", pulsanteCCListener);
pulsanteCCListener();
pulsanteToggle();
// funzione();
}
// Costruisce i menu per Program Change (PC)
function buildProgramChangeMenus() {
// additionalOptions.innerHTML = "";
pcContent.innerHTML = "";
// Primo menu: Canale MIDI Program Change
const channelLabel = document.createElement("label");
channelLabel.setAttribute("for", "programChangeChannel");
channelLabel.textContent = "Canale MIDI Program Change:";
pcContent.appendChild(channelLabel);
const channelSelect = document.createElement("select");
channelSelect.className = "coloreBordo";
channelSelect.id = "programChangeChannel";
const defaultChannelOption = document.createElement("option");
defaultChannelOption.value = "1";
defaultChannelOption.textContent = "1 (Default)";
defaultChannelOption.disabled = true;
defaultChannelOption.selected = true;
channelSelect.appendChild(defaultChannelOption);
for (let i = 1; i <= 16; i++) {
const option = document.createElement("option");
option.value = i;
option.textContent = i;
channelSelect.appendChild(option);
}
pcContent.appendChild(channelSelect);
// Secondo menu: Valore MIDI Program Change
const valueLabel = document.createElement("label");
valueLabel.setAttribute("for", "programChangeValue");
valueLabel.textContent = "Valore MIDI Program Change:";
pcContent.appendChild(valueLabel);
const valueSelect = document.createElement("select");
valueSelect.className = "coloreBordo";
valueSelect.id = "programChangeValue";
const defaultValueOption = document.createElement("option");
defaultValueOption.value = "0";
defaultValueOption.textContent = "0 (Default)";
defaultValueOption.disabled = true;
defaultValueOption.selected = true;
valueSelect.appendChild(defaultValueOption);
for (let i = 0; i <= 127; i++) {
const option = document.createElement("option");
option.value = i;
option.textContent = i;
valueSelect.appendChild(option);
}
pcContent.appendChild(valueSelect);
// Aggiungiamo i listener per i menu
channelSelect.addEventListener("change", pulsantePCListener);
valueSelect.addEventListener("change", pulsantePCListener);
pulsantePCListener();
// funzione();
}
function pulsanteToggle() {
// **Pulsante Toggle**
const toggleWrapper = document.createElement("div");
toggleWrapper.className = "toggle-wrapper";
const toggleLabel = document.createElement("label");
toggleLabel.className = "toggle-switch";
const toggleInput = document.createElement("input");
toggleInput.type = "checkbox";
toggleInput.id = "midiToggle";
const toggleSpan = document.createElement("span");
toggleSpan.className = "toggle-slider";
toggleLabel.appendChild(toggleInput);
toggleLabel.appendChild(toggleSpan);
toggleWrapper.appendChild(toggleLabel);
// **Messaggio informativo sotto il toggle**
const toggleInfo = document.createElement("h4");
toggleInfo.className = "toggle-info";
toggleInfo.textContent =
"Attiva se vuoi inviare tramite il pulsante di SimpleFader valori alternati di velocity 127-0 anziché sempre 127";
toggleWrapper.appendChild(toggleInfo);
ccContent.appendChild(toggleWrapper);
// Event listener per il toggle
toggleInput.addEventListener("change", () => {
if (toggleInput.checked) {
sendMidiAlternateCC(0x91, 0x1E, 0x1E);
} else {
sendMidiAlternateCC(0x90, 0x1E, 0x1E);
}
});
}
function funzione() {
additionalOptions.appendChild(document.createElement("hr")).style.cssText = "margin: 20px 0; border: 1px solid #6200ea;";
const led = document.createElement("h3");
led.style.textAlign = "left";
led.textContent = "Colore LED";
additionalOptions.appendChild(led);
// Contenitore per i pulsanti dei colori
let row = document.createElement('div');
row.className = "row2";
colors.forEach((color, index) => {
let colorButton = document.createElement('button');
colorButton.className = "button2";
colorButton.id = `colorButton${index + 1}`;
colorButton.textContent = "";
colorButton.style.margin = "0 5px";
colorButton.style.backgroundColor = color;
colorButton.onclick = () => {
sendColor(color);
colorButton.style.backgroundColor = color; // Aggiorna il colore del pulsante selezionato
};
row.appendChild(colorButton);
});
additionalOptions.appendChild(row); // Aggiunge la riga con i pulsanti colore
additionalOptions.appendChild(document.createElement("hr")).style.cssText = "margin: 20px 0; border: 1px solid #6200ea;";
const h3 = document.createElement("h3");
h3.style.textAlign = "left";
h3.textContent = "Comportamento Fader";
additionalOptions.appendChild(h3);
const startValueLabel = document.createElement("label");
startValueLabel.setAttribute("for", "startValue");
startValueLabel.textContent = "Canale MIDI Control Change:";
additionalOptions.appendChild(startValueLabel);
const startValueSelect = document.createElement("select");
startValueSelect.id = "startValue";
additionalOptions.appendChild(startValueSelect);
const defaultStartOption = document.createElement("option");
defaultStartOption.value = "1";
defaultStartOption.textContent = "1 (Default)";
defaultStartOption.disabled = true;
defaultStartOption.selected = true;
startValueSelect.appendChild(defaultStartOption);
for (let i = 1; i <= 16; i++) {
const option = document.createElement("option");
option.value = i;
option.textContent = i;
startValueSelect.appendChild(option);
}
const endValueLabel = document.createElement("label");
endValueLabel.setAttribute("for", "endValue");
endValueLabel.textContent = "Valore MIDI Control Change:";
additionalOptions.appendChild(endValueLabel);
const endValueSelect = document.createElement("select");
endValueSelect.id = "endValue";
additionalOptions.appendChild(endValueSelect);
const defaultEndOption = document.createElement("option");
defaultEndOption.value = "7";
defaultEndOption.textContent = "7 (Default)";
defaultEndOption.disabled = true;
defaultEndOption.selected = true;
endValueSelect.appendChild(defaultEndOption);
for (let i = 0; i <= 127; i++) {
const option = document.createElement("option");
option.value = i;
option.textContent = i;
endValueSelect.appendChild(option);
}
startValueSelect.addEventListener("change", sendMIDIFader);
endValueSelect.addEventListener("change", sendMIDIFader);
sendMIDIFader();
const saveButton = document.createElement("button");
saveButton.textContent = "Salva nel Dispositivo";
saveButton.style.backgroundColor = "#ffa726";
saveButton.style.color = "#121212";
saveButton.style.margin = "30px 0 0 0";
saveButton.style.transition = "background-color 0.3s";
saveButton.addEventListener("mouseover", () => {
saveButton.style.backgroundColor = "#ff9800";
});
saveButton.addEventListener("mouseout", () => {
saveButton.style.backgroundColor = "#ffa726";
});
saveButton.addEventListener("click", () => {
if (!selectedOutput) {
alert("Nessun dispositivo MIDI connesso!");
return;
}
const message = [0x90, 20, 20];
selectedOutput.send(message);
console.log(`Inviato: ${message.join(", ")}`);
});
additionalOptions.appendChild(saveButton);
const subtitle = document.createElement("h4");
subtitle.textContent = "Salva la configurazione corrente nel dispositivo in modo che permanga al riavvio";
additionalOptions.appendChild(subtitle);
}
function sendMIDIFaderNumberMessage(faderNumber) {
if (!selectedOutput) {
// alert("Nessun dispositivo MIDI connesso!");
return;
}
const message = [0xC0, parseInt(faderNumber, 10)];
selectedOutput.send(message);
console.log(`Inviato: ${message.join(", ")}`);
}
function sendMIDIMessage(faderIndex) {
if (!selectedOutput) {
// alert("Nessun dispositivo MIDI connesso!");
return;
}
const channelSelect = document.querySelector(`.fader-section:nth-child(${faderIndex}) select:nth-child(1)`);
const valueSelect = document.querySelector(`.fader-section:nth-child(${faderIndex}) select:nth-child(2)`);
const colorButton = document.getElementById(`colorButton${faderIndex}`);
if (!channelSelect || !valueSelect || !colorButton) {
alert("Seleziona un canale MIDI, un valore MIDI Control Change e un colore.");
return;
}
const midiChannel = parseInt(channelSelect.value, 10) - 1;
const midiValue = parseInt(valueSelect.value, 10);
const color = colors.indexOf(colorButton.style.backgroundColor);
const message = [0xA0 | midiChannel, midiValue, (color << 3) | (faderIndex - 1)];
selectedOutput.send(message);
console.log(`Inviato: ${message.join(", ")}`);
}
function toggleColorMenu(menuId) {
let menu = document.getElementById(menuId);
const isActive = menu.classList.contains('active');
closeAllColorMenus();
if (!isActive) menu.classList.add('active');
}
function closeAllColorMenus() {
let menus = document.querySelectorAll('.color-menu');
menus.forEach(menu => menu.classList.remove('active'));
}
function selectColor(faderIndex, color) {