-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
660 lines (551 loc) · 23.7 KB
/
app.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
/* Underpass is Copyright (C) 2021 Markus Noga
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
let audioContext; // Global audio context
const enableAudioButton = document.querySelector('button#enableAudio');
const mainControlsSection = document.querySelector('section#mainControls');
enableAudioButton.onclick=function() {
navigator.mediaDevices.getUserMedia({video: false, audio: true}).then( stream => {
enableAudioButton.style.display="none";
mainControlsSection.style.display="block";
navigator.mediaDevices.ondevicechange();
navigator.requestMIDIAccess({ sysex : true }).then(midiAccessSuccess).catch(function(err) {
alert("Cannot select MIDI devices in this browser. Try Chrome. Error " + err.name + ": " + err.message)
});
}).catch( err => {
console.log("error enabling audio:" + err);
alert("Cannot enable audio in this browser:" + err);
});
}
// Audio devices
//
const audioInputSelect = document.querySelector('select#audioInput');
//const audioOutputSelect = document.querySelector('select#audioOutput');
const audioSelectors = [audioInputSelect /*, audioOutputSelect */];
function audioInputChanged() {
const audioSource = audioInputSelect.value;
var audioSourceName = "undefined";
if(audioInputSelect.options[audioInputSelect.selectedIndex])
audioSourceName=audioInputSelect.options[audioInputSelect.selectedIndex].text;
console.log("New audio source: "+audioSourceName)
const constraints = {
audio: {
deviceId: audioSource ? {exact: audioSource} : undefined,
sampleRate : { exact: 48000 },
sampleSize : { exact: 16 },
// see https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints for additional options
},
};
navigator.mediaDevices.getUserMedia(constraints).then((stream) => {
recorderInit(stream);
}).catch((err) => {
alert('Unable to access audio.\n\n' + err);
console.log('Unable to access audio: ' + err);
});
}
//audioInputSelect.onclick=audioInputChanged;
audioInputSelect.onchange=audioInputChanged;
function enumerateDevicesSuccess(deviceInfos) {
// Store current selection if this is called multiple times
const values = audioSelectors.map(select => select.value);
// Clear out old options, if any
audioSelectors.forEach(select => {
while (select.firstChild) {
select.removeChild(select.firstChild);
}
});
// Populate options for each selector box
for (let i = 0; i !== deviceInfos.length; ++i) {
const deviceInfo = deviceInfos[i];
const option = document.createElement('option');
option.value = deviceInfo.deviceId;
if (deviceInfo.kind === 'audioinput') {
option.text = deviceInfo.label || `audio input ${audioInputSelect.length + 1}`;
audioInputSelect.appendChild(option);
} /* else if (deviceInfo.kind === 'audiooutput') {
option.text = deviceInfo.label || `audio output ${audioOutputSelect.length + 1}`;
audioOutputSelect.appendChild(option);
} else */ {
// console.log('Ignoring unknown device: ', deviceInfo);
}
}
// Re-select previously selected options, if any, otherwise default to first Model:Samples entry
audioSelectors.forEach((select, selectorIndex) => {
const val=values[selectorIndex];
select.value="";
if(val) {
for(var i=0; i<select.childNodes.length; i++) {
const child=select.childNodes[i];
if(child.value === val) {
select.value=val;
break;
}
}
}
if(!select.value) {
for(var i=0; i<select.childNodes.length; i++) {
const child=select.childNodes[i];
if(child.text.includes("Model:Samples")) {
select.value=child.value;
break;
}
}
}
if(select.value!=val && select.onchange)
select.onchange();
});
}
navigator.mediaDevices.ondevicechange=function () {
navigator.mediaDevices.enumerateDevices().then(enumerateDevicesSuccess).catch(function(err) {
alert("Cannot select audio devices in this browser. Try Chrome. Error " + err.name + ": " + err.message)
});
}
// MIDI devices
// See https://www.midi.org/specifications/midi1-specifications/m1-v4-2-1-midi-1-0-detailed-specification-96-1-4
//
let midiAccess; // Active MIDI access
let midiFromDevice; // Active MIDI input from the device
let midiToDevice; // Active MIDI output to the device
const midiFromDeviceSelect = document.querySelector('select#midiFromDevice');
const midiToDeviceSelect = document.querySelector('select#midiToDevice');
const midiSelectors = [midiFromDeviceSelect, midiToDeviceSelect];
function midiFromDeviceChanged() {
const sel=midiFromDeviceSelect.value;
const oldMidiFromDevice=midiFromDevice;
midiFromDevice=midiAccess.inputs.get(sel);
if(oldMidiFromDevice && oldMidiFromDevice!==midiFromDevice)
oldMidiFromDevice.onmidimessage=null;
if(midiFromDevice) {
console.log("New MIDI from device: "+midiFromDevice.name);
midiFromDevice.onmidimessage=midiInputMessage;
} else
console.log("No MIDI from device");
}
midiFromDeviceSelect.onclick=midiFromDeviceChanged
midiFromDeviceSelect.onchange=midiFromDeviceChanged
// Initial midiFromDeviceSelect.onchange() call from midiAccessSuccess()
function midiToDeviceChanged() {
const sel=midiToDeviceSelect.value
midiToDevice=midiAccess.outputs.get(sel);
if(midiToDevice)
console.log("New MIDI to device: "+midiToDevice.name);
else
console.log("No MIDI to device");
}
midiToDeviceSelect.onclick=midiToDeviceChanged
midiToDeviceSelect.onchange=midiToDeviceChanged
// Initial midiToDeviceSelect.onchange() call from midiAccessSuccess()
function midiAccessSuccess(ma) {
midiAccess=ma;
// Store current selection if this is called multiple times
const values = midiSelectors.map(select => select.value);
// Clear out old options, if any
midiSelectors.forEach(select => {
while (select.firstChild) {
select.removeChild(select.firstChild);
}
});
// Populate new options for each selector box
ma.inputs.forEach( function(key,port) {
const option = document.createElement('option');
option.value = port;
option.text = key.name;
midiFromDeviceSelect.appendChild(option);
})
ma.outputs.forEach( function(key,port) {
const option = document.createElement('option');
option.value = port;
option.text = key.name;
midiToDeviceSelect.appendChild(option);
})
// Re-select previously selected options, if any, otherwise default to first Model:Samples entry
midiSelectors.forEach((select, selectorIndex) => {
const val=values[selectorIndex];
select.value="";
if(val) {
for(var i=0; i<select.childNodes.length; i++) {
const child=select.childNodes[i];
if(child.value === val) {
select.value=val;
break;
}
}
}
if(!select.value) {
for(var i=0; i<select.childNodes.length; i++) {
const child=select.childNodes[i];
if(child.text.includes("Model:Samples")) {
select.value=child.value;
break;
}
}
}
if(select.value !== val && select.onchange)
select.onchange();
});
midiAccess.onstatechange=function() { midiAccessSuccess(midiAccess) }
}
var midiSampleDumpPackets;
var midiSampleDumpPacketsTotal=0;
var midiSampleDumpPacketsSent=0;
var midiSampleDumpPacketsAcknowledged=0;
function midiInputMessage(event) {
//console.log("MIDI received "+midiMessageToString(event.data));
const d=event.data;
if(d.length!=6 || d[0]!=0xf0 || d[1]!=0x7e || d[2]!=0x00 && d[5]!=0xf7) {
console.log("Ignoring unknown MIDI message "+midiMessageToString(d));
return;
}
if(d[3]==0x7f) { // ack
midiSampleDumpPacketsAcknowledged++;
const progress=midiSampleDumpPacketsAcknowledged/midiSampleDumpPacketsTotal;
//console.log("Progress: "+progress+" with "+midiSampleDumpPacketsAcknowledged+" of "+midiSampleDumpPacketsSent);
recorderShowMidiSDProgress(progress);
if(midiSampleDumpPacketsSent<midiSampleDumpPacketsTotal) {
midiToDevice.send(midiSampleDumpPackets[midiSampleDumpPacketsSent-1]); // packet 0 is the header
midiSampleDumpPacketsSent++;
} else if(recCurStatusNode.textContent != "Uploaded") {
console.log("Data transfer complete");
recCurStatusNode.textContent = "Uploaded";
recButton.disabled=false;
stopButton.disabled=true;
stopButton.style.background = "";
sampleID.value=parseInt(sampleID.value)+1;
} else {
; // ignore
}
} else if(d[3]==0x7c) { // wait
; // ignore
} else {
console.log("Ignoring unknown MIDI message "+midiMessageToString(d));
return;
}
}
function midiSendSampleDump(sampleNumber, sampleRate, samples) {
let header =newMidiSDHeader(0, sampleNumber, 16, sampleRate, samples.length, 0, samples.length-1, 0x7f);
let packets=newMidiSDDataPackets(0, 16, samples);
recorderShowMidiSDProgress(0);
midiSampleDumpPackets=packets;
midiSampleDumpPacketsTotal=packets.length+1;
midiSampleDumpPacketsSent=1;
midiSampleDumpPacketsAcknowledged=0;
midiToDevice.send(header);
// body packets are sent asynchronously, returns immediately after sending header
}
function newMidiSDHeader(deviceID, sampleNumber, sampleBits, sampleRate, sampleLength, loopStart, loopEnd, loopType) {
let samplePeriod = 1000000000 / sampleRate;
let header = new Uint8Array(21);
header[ 0]= 0xf0; // begin system exclusive
header[ 1]= 0x7e; // sample dump
header[ 2]= deviceID & 0x7f; // device ID
header[ 3]= 0x01; // header
header[ 4]= sampleNumber & 0x7f; // sample number lsb
header[ 5]=(sampleNumber >> 7) & 0x7f; // sample number msb
header[ 6]= sampleBits & 0x7f; // sample format, length in bits
header[ 7]= samplePeriod & 0x7f; // sample period, lsb first
header[ 8]=(samplePeriod >> 7) & 0x7f; //
header[ 9]=(samplePeriod >> 14) & 0x7f; //
header[10]= sampleLength & 0x7f; // sample length, lsb first
header[11]=(sampleLength >> 7) & 0x7f; //
header[12]=(sampleLength >> 14) & 0x7f; //
header[13]= loopStart & 0x7f; // loop start, lsb first
header[14]=(loopStart >> 7) & 0x7f; //
header[15]=(loopStart >> 14) & 0x7f; //
header[16]= loopEnd & 0x7f; // loop end, lsb first
header[17]=(loopEnd >> 7) & 0x7f; //
header[18]=(loopEnd >> 14) & 0x7f; //
header[19]= loopType & 0x7f; // loop type, 0=fwd, 1=back/fwd, 7f=0ff
header[20]= 0xf7; // end system exclusive
return header;
}
function newMidiSDDataPackets(deviceID, sampleBits, samples) {
let packets =[];
let saIndex =0;
while(saIndex<samples.length) {
let packet=new Uint8Array(127);
let packetID=packets.length;
let pIndex=0;
packet[pIndex++]=0xf0; // begin system exclusive
packet[pIndex++]=0x7e; // sample dump
packet[pIndex++]=deviceID & 0x7f; // device ID
packet[pIndex++]=0x02; // data packet
packet[pIndex++]=packetID & 0x7f; // packet ID lsb (msb not transmitted)
// build package body of 120 bytes until total length of body + header = 125 reached.
// 120 is divisible by 1,2,3 and 4, so all normal sample lengths divide into the
// package body evenly, without a remainder splitting into the next packet.
while (pIndex<125) {
// pad last packet with zeros if necessary
let sampleFloat=saIndex<samples.length ? samples[saIndex++] : 0;
// convert sample value into PCM representation from 0..1
let sampleFloatClamped=(Math.max(-1, Math.min(1, sampleFloat ))+1)*0.5;
let sampleUnsigned=(((1<<(sampleBits))-1) * sampleFloatClamped ).toFixed();
let bitsRemaining=sampleBits;
// Pad on the right to split evenly into 7-bit MIDI values
let shiftNeeded=(7 - (bitsRemaining % 7)) % 7;
sampleUnsigned<<=shiftNeeded;
bitsRemaining+=shiftNeeded;
// Add to packet a sequence of 7-bit MIDI values
while(bitsRemaining>0) {
let pDatum=(sampleUnsigned >> (bitsRemaining - 7)) & 0x7f;
packet[pIndex++]=pDatum;
bitsRemaining-=7;
}
}
let checksum=0;
for(let i=1; i<pIndex; i++)
checksum ^= packet[i];
packet[pIndex++]=checksum & 0x7f; // checksum
packet[pIndex++]=0xf7; // end system exclusive
packets.push(packet);
}
return packets;
}
function midiMessageToString(p) {
if(p.length==0)
return "";
var buf=p[0].toString(16);
for(var i=1; i<p.length; i++)
buf=buf.concat(" "+p[i].toString(16));
return buf;
}
// Level meter
//
const levelMeterSpan = document.querySelector('span#levelMeterInner');
function levelMeterShow(db) {
// translate -92 ... +20 db to %
const perc=100*((db+92)/(92+20));
levelMeterSpan.style.width=perc + "%"
//levelMeterSpan.textContent=Math.floor(db);
}
// Audio recorder
//
const recButton = document.querySelector('button#record');
const stopButton = document.querySelector('button#stop');
recButton.onclick =recorderStart;
stopButton.onclick=recorderStop;
stopButton.disabled=true;
const sampleIDSelect = document.querySelector('input#sampleID');
const recTable = document.querySelector('table#recordings');
const recTrPrototype = document.querySelector('tr#recordingPrototype');
var recCurNode=null;
var recCurFileNameNode=null;
var recCurDurationNode=null;
var recCurStatusNode=null;
var recCurProgressInnerNode=null;
let recSourceNode=null;
let recRmsDbNode=null;
let recSavingNode=null;
let recBuffers = [[], []];
let recLength = 0;
let numChannels = 2;
let timeout = null;
let maxTime=10;
function recorderInit(stream) {
recorderShutdown();
audioContext = new AudioContext();
document.addEventListener('unload', recorderShutdown);
recSourceNode = audioContext.createMediaStreamSource(stream);
audioContext.audioWorklet.addModule('processors.js').then(() => {
recRmsDbNode = new AudioWorkletNode(audioContext, 'rms-db-processor');
recRmsDbNode.port.onmessage = (event) => {
levelMeterShow(event.data);
};
recSourceNode.connect(recRmsDbNode);
recRmsDbNode.connect(audioContext.destination);
recSavingNode = new AudioWorkletNode(audioContext, 'saving-processor');
recSavingNode.port.onmessage = (event) => {
const channels=event.data;
for(var i=0; i<channels.length; i++) {
const channel=channels[i];
recBuffers[i].push(channel);
if(i==0)
recLength+=channel.length;
}
recorderShowDuration(recLength);
};
});
}
function recorderShutdown(stream) {
if(audioContext) {
audioContext.close();
audioContext=null;
}
}
function recorderStart() {
// create new recordings node
recCurNode=recTrPrototype.cloneNode(true);
recCurNode.removeAttribute("id");
recCurFileNameNode=recCurNode.getElementsByClassName("recFileName")[0];
recCurFileNameNode.textContent="inbox/"+sampleID.value;
recCurDurationNode=recCurNode.getElementsByClassName("recDuration")[0];
recCurStatusNode=recCurNode.getElementsByClassName("recStatus")[0];
recCurProgressInnerNode=recCurNode.getElementsByClassName("progressInner")[0];
// insert at top of the recordings list, dropping at the bottom if necessary
if(!recTable.childNodes || recTable.childNodes.length===0)
recTable.appendChild(recCurNode);
else
recTable.insertBefore(recCurNode, recTable.childNodes[0]);
if(recTable.childNodes.length>6)
recTable.removeChild(recTable.childNodes[recTable.childNodes.length-1])
// start actual recording
recorderShowDuration(0);
recBuffers = [[], []];
recLength = 0;
recSourceNode.connect(recSavingNode);
recSavingNode.connect(audioContext.destination);
timeout = setTimeout(() => {
recorderStop();
}, maxTime*audioContext.sampleRate);
// update UI buttons
recButton.style.background = "#f6660f";
recButton.disabled=true;
stopButton.disabled=false;
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function recorderStop() {
clearTimeout(timeout);
timeout = null;
recSourceNode.disconnect(recSavingNode);
recSavingNode.disconnect(audioContext.destination);
sleep(100); // wait for events to catch up
recButton.style.background = "";
stopButton.style.background = "#f6660f";
recCurStatusNode.textContent= "Uploading...";
let buffers= numChannels == 2 ? [mergeBuffers(recBuffers[0], recLength), mergeBuffers(recBuffers[0], recLength)] : [mergeBuffers(recBuffers[0], recLength)];
let monosummed = numChannels == 2 ? monosum(buffers[0], buffers[1]) : buffers[0];
console.log("Captured " + monosummed.length + " samples");
if(midiToDevice) {
midiSendSampleDump(sampleID.value, audioContext.sampleRate, monosummed);
} else
alert("No midi output device");
// const d=new Date();
// const wavFileName = str2(d.getFullYear())+ str2(d.getMonth()+1) + str2(d.getDate()) +"-" + str2(d.getHours()) + str2(d.getMinutes()) + str2(d.getSeconds()) + '.wav';
// var blob=exportWAV(wavFileName, 1, audioContext.sampleRate, samples);
// var url = URL.createObjectURL(blob);
// console.log("Opening "+blob.name);
// window.open(url,'_blank')
}
function recorderShowDuration(numSamples) {
const duration=numSamples/audioContext.sampleRate;
const minutes=Math.floor(duration/60);
const seconds=Math.floor(duration - 60*minutes);
const millis =Math.floor(1000*(duration - 60*minutes - seconds));
const pretty= str2(minutes) + ":" + str2(seconds) + "." + str3(millis);
recCurDurationNode.textContent= pretty;
}
function recorderShowMidiSDProgress(value) {
if(value==0)
recCurProgressInnerNode.style.backgroundColor="#f6660f";
else if(value>1)
value=1;
recCurProgressInnerNode.style.width=(100*value)+"%";
recCurProgressInnerNode.textContent=Math.floor(100*value)+"%";
if(Math.floor(10000*value)==10000) {
recCurProgressInnerNode.style.backgroundColor="slategray";
}
}
function mergeBuffers(recBuffers, recLength) {
let result = new Float32Array(recLength);
let offset = 0;
for (let i = 0; i < recBuffers.length; i++) {
result.set(recBuffers[i], offset);
offset += recBuffers[i].length;
}
return result;
}
function interleave(inputL, inputR) {
let len = inputL.length + inputR.length;
let result = new Float32Array(len);
let index = 0;
let inputIndex = 0;
while (index < len) {
result[index++] = inputL[inputIndex ];
result[index++] = inputR[inputIndex++];
}
return result;
}
function monosum(inputL, inputR) {
let len = inputL.length;
let result = new Float32Array(len);
for(let i=0; i<len; i++) {
result[i] = 0.5 * ( inputL[i] + inputR[i] );
}
return result;
}
function recShowLegal() {
alert("Underpass (C) 2021 by Markus Noga. Use at your own risk. This is free software distributed without any warranty under GNU GPL v3, see https://www.gnu.org/licenses/. All trademarks, names, logos, or company names are the property of their respective owners, and are used for identification only.");
}
// .wav file exporter
//
function exportWAV(fileName, numChannels, sampleRate, samples) {
let dataView = encodeWAV(1, audioContext.sampleRate, samples);
let blob = new Blob([ dataView ], { type: 'audio/wav' });
blob.name = fileName;
return blob;
}
function encodeWAV(numChannels, sampleRate, samples){
var buffer = new ArrayBuffer(44 + samples.length * 2);
var view = new DataView(buffer);
writeString(view, 0, 'RIFF'); // RIFF identifier
view.setUint32(4, 36 + samples.length * 2, true); // file length
writeString(view, 8, 'WAVE'); // RIFF type
writeString(view, 12, 'fmt '); // format chunk identifier
view.setUint32(16, 16, true); // format chunk length
view.setUint16(20, 1, true); // sample format (raw)
view.setUint16(22, numChannels, true); // channel count
view.setUint32(24, audioContext.sampleRate, true); // sample rate
view.setUint32(28, audioContext.sampleRate * 4, true); // byte rate (sample rate * block align)
view.setUint16(32, numChannels * 2, true); // block align (channel count * bytes per sample)
view.setUint16(34, 16, true); // bits per sample
writeString(view, 36, 'data'); // data chunk identifier
view.setUint32(40, samples.length * 2, true); // data chunk length
floatTo16BitPCM(view, 44, samples);
return view;
}
function writeString(view, offset, string){
for (var i = 0; i < string.length; i++) {
view.setUint8(offset + i, string.charCodeAt(i));
}
}
function floatTo16BitPCM(output, offset, input){
for (var i = 0; i < input.length; i++, offset+=2){
var s = Math.max(-1, Math.min(1, input[i]));
output.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7FFF, true);
}
}
function str2(n) {
if(n>100) {
n=n % 100;
}
return n<10 ? ("0" + n.toString()) : n.toString();
}
function str3(n) {
if(n>1000) {
n=n % 1000;
}
return n<10 ? ("00" + n.toString()) : (n<100 ? ("0" + n.toString()) : n.toString());
}
// Legal notice
//
const legalButton = document.querySelector('td#legalButton');
const legalNotice = document.querySelector('table#legalNotice');
const legalCloseButton = document.querySelector('i#legalClose');
legalButton.onclick = function() {
if(legalNotice.style.display==="block")
legalNotice.style.display="none";
else
legalNotice.style.display="block";
}
legalCloseButton.onclick = function() {
legalNotice.style.display="none";
}