diff --git a/javascript/JZZ.js b/javascript/JZZ.js index 34d36be..0b25667 100644 --- a/javascript/JZZ.js +++ b/javascript/JZZ.js @@ -2721,8 +2721,9 @@ JZZ.MIDI = MIDI; _J.prototype.MIDI = MIDI; - function _clear_ctxt() { - this._cc = {}; + function _clear_ctxt(gr) { + if (typeof gr == 'undefined') this._cc = {}; + else this._cc[gr] = {}; } function _rpn_txt(msb, lsb) { var a = typeof msb == 'undefined' ? '??' : __hex(msb); @@ -2839,15 +2840,15 @@ if (s) msg.label(s); } else if (mmm[3] == 9) { - if (mmm[4] == 1) { msg.label('GM1 System On'); this._clear(); this._gm = '1'; } - else if (mmm[4] == 2) { msg.label('GM System Off'); this._clear(); this._gm = '0'; } - else if (mmm[4] == 3) { msg.label('GM2 System On'); this._clear(); this._gm = '2'; } + if (mmm[4] == 1) { msg.label('GM1 System On'); this._clear(gr); this._cc[gr].gm = '1'; } + else if (mmm[4] == 2) { msg.label('GM System Off'); this._clear(gr); this._cc[gr].gm = '0'; } + else if (mmm[4] == 3) { msg.label('GM2 System On'); this._clear(gr); this._cc[gr].gm = '2'; } } } else if (mmm[1] == 0x43) { if ((mmm[2] & 0xf0) == 0x10 && mmm[3] == 0x4c) { if (mmm[4] == 0 && mmm[5] == 0 && mmm[6] == 0x7e && mmm[7] == 0) { - msg.label('XG System On'); this._clear(); this._gm = 'Y'; + msg.label('XG System On'); this._clear(gr); this._cc[gr].gm = 'Y'; } else if (mmm[4] == 0 && mmm[5] == 0 && mmm[6] == 0) msg.label('XG Master Tuning'); else if (mmm[4] == 0 && mmm[5] == 0 && mmm[6] == 4) msg.label('XG Master Volume'); @@ -2861,7 +2862,7 @@ if (mmm[5] == 0x40) { if (mmm[6] == 0) { if (mmm[7] == 0x7f && mmm[8] == 0 && mmm[9] == 0x41) { - msg.label('GS Reset'); this._clear(); this._gm = 'R'; + msg.label('GS Reset'); this._clear(gr); this._cc[gr].gm = 'R'; } else if (mmm[7] == 0) msg.label('GS Master Tuning'); else if (mmm[7] == 4) msg.label('GS Master Volume'); @@ -2883,6 +2884,11 @@ self._clear = _clear_ctxt; self._read = _read_ctxt; self._receive = function(msg) { this._emit(this._read(msg)); }; + self.gm = function(g) { + if (typeof g == 'undefined') g = 'x'; + if (this._cc[g]) return this._cc[g].gm || 0; + return 0; + }; self._clear(); self._resume(); return self; diff --git a/test/common.js b/test/common.js index 780be95..a75444c 100644 --- a/test/common.js +++ b/test/common.js @@ -1842,32 +1842,34 @@ describe('JZZ.Context', function() { var msg = JZZ.MIDI.sxGM(1); ctxt._receive(msg); assert.equal(msg.toString(), 'f0 7e 7f 09 01 f7 (GM1 System On)'); - assert.equal(ctxt._gm, '1'); + assert.equal(ctxt.gm(), '1'); // MIDI 2.0 msg = JZZ.MIDI2.sxGM(0, 1)[0]; ctxt._receive(msg); assert.equal(msg.toString(), '30047e7f 09010000 -- SysEx (GM1 System On)'); + assert.equal(ctxt.gm(0), '1'); + assert.equal(ctxt.gm(1), '0'); }); it('GM2', function() { var ctxt = JZZ.Context(); var msg = JZZ.MIDI.sxGM(2); ctxt._receive(msg); assert.equal(msg.toString(), 'f0 7e 7f 09 03 f7 (GM2 System On)'); - assert.equal(ctxt._gm, '2'); + assert.equal(ctxt.gm(), '2'); }); it('GM off', function() { var ctxt = JZZ.Context(); var msg = JZZ.MIDI.sxGM(0); ctxt._receive(msg); assert.equal(msg.toString(), 'f0 7e 7f 09 02 f7 (GM System Off)'); - assert.equal(ctxt._gm, '0'); + assert.equal(ctxt.gm(), '0'); }); it('GS', function() { var ctxt = JZZ.Context(); var msg = JZZ.MIDI.sxGS(); ctxt._receive(msg); assert.equal(msg.toString(), 'f0 41 7f 42 12 40 00 7f 00 41 f7 (GS Reset)'); - assert.equal(ctxt._gm, 'R'); + assert.equal(ctxt.gm(), 'R'); msg = JZZ.MIDI.sxGS(0x40, 0, 0, 0, 0x04, 0, 0); ctxt._receive(msg); assert.equal(msg.toString(), 'f0 41 7f 42 12 40 00 00 00 04 00 00 3c f7 (GS Master Tuning)'); @@ -1904,13 +1906,14 @@ describe('JZZ.Context', function() { assert.equal(msg[0].toString(), '3216417f 42124010 -- SysEx'); ctxt._receive(msg[1]); assert.equal(msg[1].toString(), '32331500 1b000000 -- SysEx (GS Drum Part Change)'); + assert.equal(ctxt.gm(2), '0'); }); it('XG', function() { var ctxt = JZZ.Context(); var msg = JZZ.MIDI.sxXG(); ctxt._receive(msg); assert.equal(msg.toString(), 'f0 43 10 4c 00 00 7e 00 f7 (XG System On)'); - assert.equal(ctxt._gm, 'Y'); + assert.equal(ctxt.gm('x'), 'Y'); msg = JZZ.MIDI.sxXG(0, 0, 0, 0x40, 0, 0, 0); ctxt._receive(msg); assert.equal(msg.toString(), 'f0 43 10 4c 00 00 00 40 00 00 00 f7 (XG Master Tuning)');