-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
851 lines (771 loc) · 25.9 KB
/
index.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
// import Plotly from 'plotly-dist-min';
// if you change the version, you need to change the reverse proxy conf too in etc/nginx.conf
const backend = '/v1';
// depending on what the proxy support
const https_headers = { headers: { 'Accept-Encoding': 'bz2, gzip, deflate', 'Content-Type': 'application/json' } };
const hide = (elem) => {
if (elem) {
elem.hidden = true;
} else {
console.error('Trying to hide an empty element');
}
};
const show = (elem) => {
if (elem) {
elem.hidden = false;
} else {
console.error('Trying to show an empty element');
}
};
// structure of the index.html
// topbar
// select
// +----- a file
// +----- for a speaker
// +----- for a headset
// adapt
// +----- generic peq
// +----- parametricEQ
// +----- Rme
// +----- Roon
// convert
// +----- to format
// +--- APO
// +----- download
// +--- AUPreset
// +----- download
// +--- RmeTotalMixChannelEQ
// +----- download
// +--- RmeTotalMixRoomEQ
// +----- download
const stepSelect = document.querySelector('#stepSelect');
const formUpload = stepSelect.querySelector('#uploadEQ');
const formUploadInput = formUpload.querySelector('input[type=file]');
const formUploadFilename = stepSelect.querySelector('#file-name');
const plots = document.querySelector('#plots');
const selectSpeakers = document.querySelector('#selectSpeakers');
const selectSpeakerEQ = document.querySelector('#selectSpeakerEQ');
const stepConvert = document.querySelector('#stepConvert');
const formConvert = stepConvert.querySelector('#convertEQ');
const formConvertSelect = formConvert.querySelector('#selectFormat');
const formConvertSubmit = formConvert.querySelector('#submitButton');
// ----------------------------------------------------------------------
// state abstraction
// ----------------------------------------------------------------------
class EQState {
constructor(hash, name) {
if (hash.length === 128) {
this._hash = hash;
this._name = name;
} else {
console.log('Length of hash is ' + hash.length);
}
}
set hash(h) {
if (h.length === 128) {
this._hash = h;
} else {
console.log('Len of hash is not correct ' + h.length);
}
}
get hash() {
return this._hash;
}
set name(n) {
this._name = n;
}
get name() {
return this._name;
}
valid() {
return true; // this._hash.length === 128 && this._name.length > 0;
}
}
class State {
constructor() {
this._items = [];
}
length() {
return this._items.length;
}
setItems(item) {
this._items.push(item);
}
reset() {
this._items = [];
}
hash(k) {
return this._items[k].hash;
}
name(k) {
return this._items[k].name;
}
}
const state = new State();
// ----------------------------------------------------------------------
// helper functions
// ----------------------------------------------------------------------
function importIncludes() {
// helper for including html fragments (menu, symbols)
const components = document.querySelectorAll('.includes');
const loadComponent = async (c) => {
const { name, ext } = c.dataset;
const response = await fetch(`${name}.${ext}`);
c.innerHTML = await response.text();
};
[...components].forEach(loadComponent);
}
function assignDiv(selector, dataList, defText, selected) {
// populate form inputs from a list
while (selector.firstChild) {
selector.firstChild.remove();
}
const defOption = document.createElement('option');
defOption.value = '';
defOption.text = defText;
selector.appendChild(defOption);
for (const element of dataList) {
const currentOption = document.createElement('option');
currentOption.value = element;
currentOption.text = element.replace('Vendors-', '').replace('vendor-pattern-', 'Pattern ');
if (element === selected) {
currentOption.selected = true;
}
if (dataList.length === 1) {
currentOption.disabled = true;
}
selector.appendChild(currentOption);
}
}
function toggleTab(panel, tabId, blockId) {
// make tabId active and not the others
const tabs = panel.querySelectorAll('.panel-tabs a');
tabs.forEach((tab) => {
if (tab.id === tabId) {
tab.classList.add('is-active');
} else {
if (tab.classList.contains('is-active')) {
tab.classList.remove('is-active');
}
}
});
// show blockId and hide others
const blocks = panel.querySelectorAll('div .panel-block');
blocks.forEach((block) => {
if (block.id === blockId) {
block.style.display = 'block';
show(block);
} else {
block.style.display = 'none';
hide(block);
}
});
}
function tabsAddEvents(panel) {
// add click event to each tabs of the panel
if (panel) {
const tabs = panel.querySelectorAll('.panel-tabs a');
tabs.forEach((tab) => {
tab.onclick = () => {
toggleTab(panel, tab.id, tab.dataset.target);
};
});
// call the first one by default
if (tabs.length > 0) {
toggleTab(panel, tabs[0].id, tabs[0].dataset.target);
}
}
}
function cleanupPanel(panel) {
panel.querySelectorAll('div.panel-block').forEach((node) => {
panel.removeChild(node);
});
}
// ----------------------------------------------------------------------
// backend calls
// ----------------------------------------------------------------------
async function uploadFiles(form) {
const url = backend + '/eq/upload';
const formData = new FormData();
for (const file of form.files) {
formData.append('files', file);
}
const fetchOptions = {
method: 'post',
mode: 'cors',
body: formData,
};
const response = await fetch(url, fetchOptions);
return await response.json();
}
async function setSpeakerEQ(speakerName) {
const url = backend + '/speaker/' + speakerName + '/eqdata';
const response = await fetch(url, https_headers);
const data = await response.json();
const labels = data.map((v) => v['name']);
if (selectSpeakerEQ) {
assignDiv(selectSpeakerEQ, labels, 'Select an EQ ...', '');
show(selectSpeakerEQ);
} else {
hide(selectSpeakerEQ);
}
selectSpeakerEQ.onchange = async () => {
const selectedSpeakerEQ = selectSpeakerEQ.value;
if (selectedSpeakerEQ !== '') {
let hash = '';
// must be a filter function somewhere
data.forEach((v) => {
if (v['name'] === selectedSpeakerEQ) {
hash = v['hash'];
}
});
const eq = new EQState(hash, speakerName + ' - ' + selectedSpeakerEQ);
state.reset();
state.setItems(eq);
await plotState();
show(stepConvert);
} else {
hide(plots);
await convertCleanup();
}
};
return true;
}
async function loadFromSpinorama() {
const url = backend + '/speakers';
const response = await fetch(url, https_headers);
const data = await response.json();
if (selectSpeakers) {
assignDiv(selectSpeakers, data, 'Select a speaker ...', '');
}
selectSpeakers.onchange = async () => {
const selectedSpeaker = selectSpeakers.value;
if (selectedSpeaker !== '') {
await setSpeakerEQ(selectedSpeaker);
hide(plots);
hide(stepConvert);
}
};
return true;
}
// ----------------------------------------------------------------------
// poor man xml encoder
// ----------------------------------------------------------------------
function xml2html(s) {
return s.replace(/[<>"'&]/g, function (char) {
switch (char) {
case '<':
return '<';
case '>':
return '>';
case '"':
return '"';
case "'":
return ''';
case '&':
return '&';
}
});
}
function text2code(text) {
const space4 = '  ';
let code = '';
let indent = 0;
const lines = text.split('\n');
lines.forEach((line) => {
let space = '';
const pos = line.indexOf('<');
if (pos !== -1 && pos + 1 < line.length && line[pos + 1] !== '/') {
indent += 1;
}
if (line.indexOf('</') !== -1 || line.indexOf('/>') !== -1) {
indent = Math.max(0, indent - 1);
}
for (let i = 0; i < indent; i++) {
space += space4;
}
if (line.indexOf('<?xml') === 0 || line.indexOf('<!DOCTYPE') === 0 || line.indexOf('<Preset>') === 0) {
space = '';
indent = 0;
}
const encoded = xml2html(line);
code += space + encoded + '<br/>';
});
return code;
}
// ----------------------------------------------------------------------
// display each format
// ----------------------------------------------------------------------
class Format {
// each format need to support display (the converted format) and download
async display(/*fileName, div, hash*/) {}
async download(/*fileName, hash*/) {}
}
function downloadViaData(fileName, returnType, data) {
let element = document.createElement('a');
element.setAttribute('href', 'data:text/' + returnType + ';charset=utf-8, ' + encodeURIComponent(data));
element.setAttribute('download', fileName);
console.log('download: ' + fileName);
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
class APO extends Format {
async display(fileName, div, hash) {
const url = backend + '/eq/target/apo';
const response = await fetch(url + '?eq_hash=' + hash, https_headers);
const data = await response.json();
div.querySelector('code').innerHTML = text2code(data);
div.querySelector('#download').onclick = () => {
this.download(fileName, hash);
};
show(div);
}
async download(fileName, hash) {
const url = backend + '/eq/target/apo';
const response = await fetch(url + '?eq_hash=' + hash, https_headers);
const data = await response.json();
downloadViaData(fileName, 'plain', data);
}
}
const apo = new APO();
class AUPreset extends Format {
async display(fileName, div, hash) {
const url = backend + '/eq/target/aupreset';
const response = await fetch(url + '?eq_hash=' + hash, https_headers);
const data = await response.json();
div.querySelector('code').innerHTML = text2code(data[1]);
div.querySelector('#download').onclick = () => {
this.download(fileName, hash);
};
show(div);
}
async download(fileName, hash) {
const url = backend + '/eq/target/aupreset';
const response = await fetch(url + 'eq_?hash=' + hash, https_headers);
const data = await response.json();
let aupresetName = fileName;
if (aupresetName.length > 4) {
aupresetName = fileName.slice(0, -4) + '.aupreset';
}
downloadViaData(aupresetName, 'xml', data);
}
}
const aupreset = new AUPreset();
class RMETotalMixChannel extends Format {
async display(fileName, div, hash) {
const url = backend + '/eq/target/rme_totalmix_channel';
const response = await fetch(url + '?eq_hash=' + hash, https_headers);
const data = await response.json();
div.querySelector('code').innerHTML = text2code(data);
div.querySelector('#download').onclick = () => {
this.download(fileName, hash);
};
show(div);
}
async download(fileName, hash) {
const url = backend + '/eq/target/rme_totalmix_channel';
const response = await fetch(url + '?eq_hash=' + hash, https_headers);
const data = await response.json();
let tmeqName = fileName;
if (tmeqName.length > 4) {
tmeqName = fileName.slice(0, -4) + '.tmeq';
}
downloadViaData(tmeqName, 'xml', data);
}
}
const rmetotalmixchannel = new RMETotalMixChannel();
class RmeTotalMixRoom extends Format {
async display(fileName, div, hash0, hash1) {
const url = backend + '/eq/target/rme_totalmix_room';
const response = await fetch(url + '?eq_hash_left=' + hash0 + '&eq_hash_right=' + hash1, https_headers);
const data = await response.json();
div.querySelector('code').innerHTML = text2code(data);
div.querySelector('#download').onclick = () => {
this.download(fileName, hash0, hash1);
};
show(div);
}
async download(fileName, hash0, hash1) {
const url = backend + '/eq/target/rme_totalmix_channel';
const response = await fetch(url + '?eq_hash_left=' + hash0 + '&eq_hash_right=' + hash1, https_headers);
const data = await response.json();
let tmreqName = fileName;
if (tmreqName.length > 4) {
tmreqName = fileName.slice(0, -4) + '.tmreq';
}
downloadViaData(tmreqName, 'xml', data);
}
}
const rmetotalmixroom = new RmeTotalMixRoom();
// ----------------------------------------------------------------------
// plot EQ
// ----------------------------------------------------------------------
function screen2wh() {
const ww = window.innerWidth;
// const wh = window.innerHeight;
const margin = 0;
let w;
let h;
w = Math.min(Math.max(300, ww - margin), 800);
h = w / 2;
return [w, h];
}
function peq2graph(freq, spl) {
const [w, h] = screen2wh();
const data = [
{
x: freq,
y: spl,
type: 'scatter',
},
];
const layout = {
width: w,
height: h,
xaxis: {
title: {
text: 'Freq (Hz)',
},
type: 'log',
range: [Math.log10(20), Math.log10(20000)],
showline: true,
dtick: 'D1',
},
yaxis: {
title: {
text: 'SPL (dB)',
},
},
margin: {
l: 30,
r: 120,
t: 10,
b: 60,
},
};
const config = {
responsive: true,
displayModeBar: false,
};
return [data, layout, config];
}
function iir2graph(freq, spls) {
const [w, h] = screen2wh();
const data = [];
// spls is a js object without any method ....
for (let i = 0; i < 32; i++) {
const value = spls[i];
if (value === undefined) {
break;
}
data.push({
x: freq,
y: value,
showlegend: false,
type: 'scatter',
});
}
const layout = {
width: w,
height: h,
xaxis: {
title: {
text: 'Freq (Hz)',
},
type: 'log',
range: [Math.log10(20), Math.log10(20000)],
showline: true,
dtick: 'D1',
},
yaxis: {
title: {
text: 'SPL (dB)',
},
},
margin: {
l: 30,
r: 120,
t: 10,
b: 60,
},
};
const config = {
responsive: false,
displayModeBar: false,
};
return [data, layout, config];
}
async function plotlyPEQ(div, hash) {
const url = backend + '/eq/graph_spl';
if (hash === null || hash.length !== 128) {
return;
}
const response = await fetch(url + '?eq_hash=' + hash, https_headers);
const data = await response.json();
const specs = peq2graph(data.freq, data.spl);
Plotly.newPlot(div, specs[0], specs[1], specs[2]);
return true;
}
async function plotlyIIR(div, hash) {
const url = backend + '/eq/graph_spl_details';
if (hash === null || hash.length !== 128) {
return;
}
const response = await fetch(url + '?eq_hash=' + hash, https_headers);
const data = await response.json();
const specs = iir2graph(data.freq, data.spl);
Plotly.newPlot(div, specs[0], specs[1], specs[2]);
return true;
}
// ----------------------------------------------------------------------
// display the plots for each EQ in the state
// ----------------------------------------------------------------------
async function plotState() {
let contentTabs = '';
let contentBlocks = '';
for (let k = 0; k < state.length(); k++) {
let classActive = '';
let active = '';
let hidden = 'hidden';
if (k === 0) {
active = ' is-active';
classActive = ' class="is-active"';
hidden = '';
}
contentTabs += `
<a ${classActive} id="name${k}" data-target="plot${k}">${state.name(k)}</a>
`;
contentBlocks += `
<div class="panel-block ${active}" id="plot${k}" ${hidden}>
<div class="columns is-desktop">
<div class="column is-half" id="plotIIR"></div>
<div class="column is-half" id="plotPEQ"></div>
</div>
</div>
`;
}
const contentPlots = `
<nav class="panel is-info">
<p class="panel-heading">Plots</p>
<p class="panel-tabs">
${contentTabs}
</p>
${contentBlocks}
</nav>
`;
show(plots);
plots.innerHTML = contentPlots;
for (let k = 0; k < state.length(); k++) {
const plot = plots.querySelector('#plot' + k);
const plotPEQ = plot.querySelector('#plotPEQ');
const plotIIR = plot.querySelector('#plotIIR');
const status1 = await plotlyPEQ(plotPEQ, state.hash(k));
const status2 = await plotlyIIR(plotIIR, state.hash(k));
if (!status1) {
console.log('Plotting PEQ failed for hash=' + state.hash(k));
}
if (!status2) {
console.log('Plotting IIR failed for hash=' + state.hash(k));
}
}
tabsAddEvents(plots);
show(stepConvert);
}
// ----------------------------------------------------------------------
// display the eq in each format for each EQ in the state
// ----------------------------------------------------------------------
async function convertCleanup() {
const panel = stepConvert.querySelector('#convertEQ');
cleanupPanel(panel);
}
async function convertState(method) {
let contentTabs = '';
for (let k = 0; k < state.length(); k++) {
let classActive = '';
if (k === 0) {
classActive = ' class="is-active"';
}
contentTabs += `<a${classActive} id="name${k}" data-target="convert${k}">${state.name(k)}</a>`;
}
// show
show(stepConvert);
// set new tabs
stepConvert.querySelector('#tabs').innerHTML = contentTabs;
// remove old blocks if we have some
const panel = stepConvert.querySelector('#convertEQ');
cleanupPanel(panel);
// add new blocks
for (let k = 0; k < state.length(); k++) {
const fragment = new DocumentFragment();
const div = document.createElement('div');
div.setAttribute('class', 'panel-block');
div.setAttribute('id', 'convert' + k);
div.innerHTML = `
<div id="APO" hidden>
<code class="is-size-7">
</code>
<div class="control">
<button class="button is-link" id="download">Download</button>
</div>
</div>
<div id="AUPreset" hidden>
<code class="is-size-7">
</code>
<div class="control">
<button class="button is-link" id="download">Download</button>
</div>
</div>
<div id="Rme-TotalMix-Channel" hidden>
<code class="is-size-7">
</code>
<div class="control">
<div class="button is-link" id="download">Download</div>
</div>
</div>
<div id="Rme-TotalMix-Room" hidden>
<code class="is-size-7">
</code>
<div class="control">
<button class="button is-link" id="download">Download</button>
</div>
</div>
`;
fragment.appendChild(div);
panel.appendChild(fragment);
}
for (let k = 0; k < state.length(); k++) {
const hash = state.hash(k);
const name = state.name(k);
const convert = panel.querySelector('#convert' + k);
const eApo = convert.querySelector('#APO');
const eAUPreset = convert.querySelector('#AUPreset');
const eRmeTotalMixChannel = convert.querySelector('#Rme-TotalMix-Channel');
const eRmeTotalMixRoom = convert.querySelector('#Rme-TotalMix-Room');
// need some polymorphism
if (method === 'apo') {
await apo.display(name, eApo, hash);
} else if (method === 'aupreset') {
await aupreset.display(name, eAUPreset, hash);
} else if (method === 'rmetmeq') {
await rmetotalmixchannel.display(name, eRmeTotalMixChannel, hash);
} else if (method === 'rmetmreq') {
let l = 0;
let r = 1;
const optionsLeft = stepConvert.querySelector('#selectLeftChannel').options;
const indexLeft = optionsLeft.selectedIndex;
if (indexLeft !== -1) {
l = parseInt(optionsLeft[indexLeft].value);
}
const optionsRight = stepConvert.querySelector('#selectRightChannel').options;
const indexRight = optionsRight.selectedIndex;
if (indexRight !== -1) {
r = parseInt(optionsRight[indexRight].value);
}
const hashL = state.hash(l);
let hashR = hashL;
if (state.length() > 1) {
hashR = state.hash(r);
}
await rmetotalmixroom.display('roomeq.txt', eRmeTotalMixRoom, hashL, hashR);
}
}
tabsAddEvents(panel);
}
// ----------------------------------------------------------------------
// onload
// ----------------------------------------------------------------------
window.onload = () => {
if (window.trustedTypes && window.trustedTypes.createPolicy && !window.trustedTypes.defaultPolicy) {
window.trustedTypes.createPolicy('default', {
createHTML: (string) => string,
});
}
importIncludes();
// load initial data
const statusLoadSpinorama = loadFromSpinorama();
if (!statusLoadSpinorama) {
console.log('Load speaker database failed!');
}
// Upload
formUploadInput.onchange = async () => {
const responses = await uploadFiles(formUploadInput);
let error = false;
state.reset();
let contentMsg = '<ol>';
for (const k in responses) {
const response = responses[k];
if (response.status === 'ok') {
const eq = new EQState(response['hash'], response['name']);
if (eq.valid()) {
state.setItems(eq);
contentMsg += '<li> ok: ' + eq.name + '</li>';
} else {
contentMsg += '<li> ko: ' + eq.name + ' (' + response.message + ')</li>';
error = true;
}
}
}
contentMsg += '</ol>';
formUploadFilename.innerHTML = contentMsg;
if (error) {
hide(plots);
await convertCleanup();
} else {
await plotState();
show(stepConvert);
}
};
formConvertSelect.onchange = async () => {
const value = formConvertSelect.value;
const leftChannel = stepConvert.querySelector('#leftChannel');
const rightChannel = stepConvert.querySelector('#rightChannel');
if (value === 'rmetmreq') {
if (state.length() > 1) {
const selectLeftChannel = leftChannel.querySelector('#selectLeftChannel');
const selectRightChannel = rightChannel.querySelector('#selectRightChannel');
for (let k = 0; k < state.length(); k++) {
const option = document.createElement('option');
option.setAttribute('value', k.toString());
option.innerHTML = state.name(k);
const option2 = option.cloneNode(true);
if (k === 0) {
selectRightChannel.appendChild(option);
option2.setAttribute('selected', 'true');
selectLeftChannel.appendChild(option2);
} else if (k === 1) {
selectLeftChannel.appendChild(option);
option2.setAttribute('selected', 'true');
selectRightChannel.appendChild(option2);
} else {
selectLeftChannel.appendChild(option);
selectRightChannel.appendChild(option2);
}
}
} else if (state.length() === 1) {
const selectLeftChannel = leftChannel.querySelector('#selectLeftChannel');
const selectRightChannel = rightChannel.querySelector('#selectRightChannel');
const optionL = document.createElement('option');
optionL.setAttribute('value', '0');
optionL.innerHTML = state.name(0);
const optionR = optionL.cloneNode(true);
optionL.setAttribute('selected', 'true');
optionR.setAttribute('selected', 'true');
selectLeftChannel.appendChild(optionL);
selectRightChannel.appendChild(optionR);
}
show(leftChannel);
show(rightChannel);
} else {
hide(leftChannel);
hide(rightChannel);
}
};
formConvertSubmit.onclick = async () => {
await convertState(formConvertSelect.value);
show(stepConvert);
};
document.querySelectorAll('.panel').forEach((panel) => {
tabsAddEvents(panel);
});
};