Skip to content

Commit

Permalink
MIDI2 Context - continued
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Mar 9, 2024
1 parent 2dc82b2 commit 2952117
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
31 changes: 27 additions & 4 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -2744,19 +2744,42 @@
return 'NRPN ' + a + ' ' + b;
}
function _read_ctxt(msg) {
var mmm, kk, tt, st, s;
var mmm, kk, tt, st, n, a, s;
var gr = 'x';
var ch = 'x';
if (msg.isMidi2) {
tt = msg[0] >> 4;
gr = (msg[0] & 15).toString(16);
kk = gr;
if (!this._cc[kk]) this._cc[kk] = {};
if (tt == 2) {
mmm = JZZ.MIDI(msg.slice(1));
mmm = new MIDI(msg.slice(1));
}
else if (tt == 3) {
st = msg[1] >> 4;
n = msg[1] & 15;
a = msg.slice(2, 2 + n);
if (st == 0) {
mmm = new MIDI([0xf0].concat(a, [0xf7]));
this._cc[kk].sx = undefined;
}
else if (st == 1) {
this._cc[kk].sx = a;
}
else if (st == 2) {
if (this._cc[kk].sx) this._cc[kk].sx = this._cc[kk].sx.concat(a);
}
else if (st == 3) {
if (this._cc[kk].sx) {
a = this._cc[kk].sx.concat(a);
mmm = new MIDI([0xf0].concat(a, [0xf7]));
this._cc[kk].sx = undefined;
}
}
}
else return msg;
}
else mmm = msg;
if (!mmm || !mmm.length || mmm[0] < 0x80) return mmm;
if (!mmm || !mmm.length || mmm[0] < 0x80) return msg;
if (mmm[0] == 0xff) { this._clear(); return msg; }
st = mmm[0] >> 4;
ch = (mmm[0] & 15).toString(16);
Expand Down
12 changes: 12 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1743,6 +1743,18 @@ describe('JZZ.Context', function() {
ctxt.program(1, 1);
});
it('progName 2', function(done) {
var ctxt = JZZ.Context();
JZZ.MIDI.programName = function(a, b, c) { return a + ' ' + b + ' ' + c; };
ctxt.rpn(1, 2, 3);
ctxt.bank(1, 2, 3);
ctxt.connect(function(msg) {
assert.equal(msg.toString(), 'c1 01 -- Program Change (1 2 3)');
JZZ.MIDI.programName = undefined;
done();
});
ctxt.program(1, 1);
});
it('progName 3', function(done) {
var ctxt = JZZ.Context().MIDI2().gr(2);
JZZ.MIDI.programName = function(a, b, c) { return a + ' ' + b + ' ' + c; };
ctxt.rpn(1, 2, 3);
Expand Down

0 comments on commit 2952117

Please sign in to comment.