Skip to content

Commit

Permalink
Populating program names
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Jun 29, 2024
1 parent 498c39d commit deee422
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"jzz": "^1.8.5"
},
"devDependencies": {
"eslint": "^9.5.0",
"eslint": "^9.6.0",
"grunt": "^1.6.1",
"grunt-contrib-jshint": "^3.2.0",
"grunt-contrib-uglify": "^5.2.2",
Expand Down
54 changes: 43 additions & 11 deletions test.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ <h1>JZZ.midi.GM</h1>
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);
onSystem();

function onSystem() {
var i;
var i, x;
mySystem = system.value;
if (mySystem == 'GM') {
myMsb = undefined;
Expand All @@ -61,23 +65,51 @@ <h1>JZZ.midi.GM</h1>
for (i = 0; i < 128; i++) add(prog, i, i.toString(16).padStart(2, '0') + ' ' + JZZ.MIDI.programName(i));
}
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;
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;
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;
}
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);
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]] = JZZ.MIDI.programName(a[i][0], a[i][1], a[i][2]);
}
return x;
}
//console.log(JZZ.MIDI.GM.allGM2());
//console.log(JZZ.MIDI.GM.allGS());
//console.log(JZZ.MIDI.GM.allXG());

--></script>

<p>
Expand Down

0 comments on commit deee422

Please sign in to comment.