-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.html
146 lines (142 loc) · 3.94 KB
/
test.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
<!DOCTYPE html>
<html>
<head>
<title>JZZ.midi.GM</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="node_modules/jzz/javascript/JZZ.js"></script>
<script src="node_modules/jzz-synth-tiny/javascript/JZZ.synth.Tiny.js"></script>
<script src="node_modules/jzz-gui-select/javascript/JZZ.gui.Select.js"></script>
<script src="node_modules/jzz-input-kbd/javascript/JZZ.input.Kbd.js"></script>
<script src="minified/JZZ.midi.GM.js"></script>
</head>
<body>
<h1>JZZ.midi.GM</h1>
<p>
<label for="midiout">MIDI Out:</label>
<select id="midiout"></select>
<label for="system">System:</label>
<select id="system">
<option value="GM">GM</option>
<option value="GM2">GM2</option>
<option value="GS">GS</option>
<option value="XG">XG</option>
</select>
<label for="msb">Bank MSB:</label>
<select id="msb"></select>
<label for="lsb">Bank LSB:</label>
<select id="lsb"></select>
<label for="prog">Program:</label>
<select id="prog"></select>
</p>
<p id="piano"></p>
<script><!--
JZZ.synth.Tiny.register('Web Audio');
var logger = JZZ.Widget({ _receive: function(msg) { console.log(msg.toString()); }});
JZZ.addMidiOut('console.log', logger);
var midiout = JZZ.gui.SelectMidiOut({ at: 'midiout' });
var piano = JZZ.input.Kbd({at: 'piano'});
piano.connect(midiout);
midiout.onSelect = function() {
setSystem();
setMsb();
setLsb();
setProg();
};
var mySystem, myMsb, myLsb, myProg;
var system = document.getElementById('system');
var msb = document.getElementById('msb');
var lsb = document.getElementById('lsb');
var prog = document.getElementById('prog');
var sys = { GM2: collect(JZZ.MIDI.GM.allGM2()), GS: collect(JZZ.MIDI.GM.allGS()), XG: collect(JZZ.MIDI.GM.allXG()) };
system.addEventListener("change", onSystem);
msb.addEventListener("change", onMsb);
lsb.addEventListener("change", onLsb);
prog.addEventListener("change", onProg);
midiout.select();
onSystem();
function onSystem() {
var i, x;
mySystem = system.value;
setSystem();
if (mySystem == 'GM') {
myMsb = undefined;
myLsb = undefined;
myProg = 0;
clear(msb);
clear(lsb);
clear(prog);
add(msb, 0, '00', true);
add(lsb, 0, '00', true);
for (i = 0; i < 128; i++) add(prog, i, i.toString(16).padStart(2, '0') + ' ' + JZZ.MIDI.programName(i));
setProg();
}
else {
x = sys[mySystem];
clear(msb);
for (i = 0; i < 128; i++) if (x[i]) add(msb, i, i.toString(16).padStart(2, '0'));
onMsb();
}
}
function onMsb() {
var i, x;
myMsb = msb.value;
setMsb();
x = sys[mySystem][myMsb];
clear(lsb);
for (i = 0; i < 128; i++) if (x[i]) add(lsb, i, i.toString(16).padStart(2, '0'));
onLsb();
}
function onLsb() {
var i, x;
myLsb = lsb.value;
setLsb();
x = sys[mySystem][myMsb][myLsb];
clear(prog);
for (i = 0; i < 128; i++) if (x[i]) add(prog, i, x[i]);
onProg();
}
function onProg() {
myProg = prog.value;
setProg();
}
function clear(sel) {
for (var i = sel.options.length; i > 0; i--) sel.remove(i - 1);
}
function add(sel, val, txt, dis) {
var opt = document.createElement('option');
opt.value = val;
opt.innerHTML = txt;
opt.disabled = !!dis;
sel.appendChild(opt);
}
function collect(a) {
var i;
var x = {};
for (i = 0; i < a.length; i++) {
if (!x[a[i][1]]) x[a[i][1]] = {};
if (!x[a[i][1]][a[i][2]]) x[a[i][1]][a[i][2]] = {};
x[a[i][1]][a[i][2]][a[i][0]] = a[i][0].toString(16).padStart(2, '0') + ' ' + JZZ.MIDI.programName(a[i][0], a[i][1], a[i][2]);
}
return x;
}
function setSystem() {
midiout.send({ GM: JZZ.MIDI.sxGM(), GM2: JZZ.MIDI.sxGM(2), GS: JZZ.MIDI.sxGS(), XG: JZZ.MIDI.sxXG() }[mySystem]);
}
function setMsb() {
if (typeof myMsb != 'undefined') midiout.bankMSB(0, myMsb);
}
function setLsb() {
if (typeof myLsb != 'undefined') midiout.bankLSB(0, myLsb);
}
function setProg() {
midiout.program(0, myProg);
}
--></script>
<p>
<em>NOTE: some instruments may not support certain systems or programs.</em>
</p>
<p>
<a href=https://jazz-soft.net>https://jazz-soft.net</a>
</p>
</body>
</html>