Skip to content

Commit

Permalink
Context rpn/nrpn
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Jul 28, 2021
1 parent ea41dc2 commit a95c4c3
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 1 deletion.
36 changes: 36 additions & 0 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -2478,6 +2478,25 @@
this._cc = [];
for (i = 0; i < 16; i++) this._cc[i] = {};
}
function _rpn_txt(msb, lsb) {
var a = typeof msb == 'undefined' ? '??' : __hex(msb);
var b = typeof lsb == 'undefined' ? '??' : __hex(lsb);
var c = {
'0000': 'Pitch Bend Sensitivity',
'0001': 'Channel Fine Tune',
'0002': 'Channel Coarse Tune',
'0003': 'Select Tuning Program',
'0004': 'Select Tuning Bank',
'0005': 'Vibrato Depth Range',
'7f7f': 'NONE'
}[a + '' + b];
return 'RPN ' + a + ' ' + b + (c ? ': ' + c : '');
}
function _nrpn_txt(msb, lsb) {
var a = typeof msb == 'undefined' ? '??' : __hex(msb);
var b = typeof lsb == 'undefined' ? '??' : __hex(lsb);
return 'NRPN ' + a + ' ' + b;
}
function _read_ctxt(msg) {
if (!msg.length || msg[0] < 0x80) return msg;
if (msg[0] == 0xff) { this._clear(); return msg; }
Expand All @@ -2492,6 +2511,23 @@
switch (msg[1]) {
case 0: this._cc[ch].bm = msg[2]; break;
case 32: this._cc[ch].bl = msg[2]; break;
case 98: this._cc[ch].nl = msg[2]; this._cc[ch].rn = 'n'; break;
case 99: this._cc[ch].nm = msg[2]; this._cc[ch].rn = 'n'; break;
case 100: this._cc[ch].rl = msg[2]; this._cc[ch].rn = 'r'; break;
case 101: this._cc[ch].rm = msg[2]; this._cc[ch].rn = 'r'; break;
case 6: case 38: case 96: case 97:
if (this._cc[ch].rn == 'r') {
msg._rm = this._cc[ch].rm;
msg._rl = this._cc[ch].rl;
msg.label(_rpn_txt(this._cc[ch].rm, this._cc[ch].rl));
}
if (this._cc[ch].rn == 'n') {
msg._nm = this._cc[ch].rm;
msg._nl = this._cc[ch].nl;
msg.label(_nrpn_txt(this._cc[ch].nm, this._cc[ch].nl));
}
this._cc[ch].rm = msg[2];
break;
}
}
return msg;
Expand Down
2 changes: 1 addition & 1 deletion minified/JZZ.js

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,77 @@ describe('JZZ.Context', function() {
});
ctxt.program(1, 1);
});
it('rpn 0', function(done) {
var ctxt = JZZ.Context();
ctxt.connect(function(msg) {
assert.equal(msg.toString(), 'b0 61 00 -- Data Decrement');
done();
});
ctxt.dataDecr(0);
});
it('rpn 1', function(done) {
var ctxt = JZZ.Context();
ctxt.rpnMSB(0, 0);
ctxt.connect(function(msg) {
assert.equal(msg.toString(), 'b0 61 00 -- Data Decrement (RPN 00 ??)');
done();
});
ctxt.dataDecr(0);
});
it('rpn 2', function(done) {
var ctxt = JZZ.Context();
ctxt.rpnLSB(0, 0);
ctxt.connect(function(msg) {
assert.equal(msg.toString(), 'b0 61 00 -- Data Decrement (RPN ?? 00)');
done();
});
ctxt.dataDecr(0);
});
it('rpn 3', function(done) {
var ctxt = JZZ.Context();
ctxt.rpn(0, 0, 1);
ctxt.connect(function(msg) {
assert.equal(msg.toString(), 'b0 26 00 -- Data Entry LSB (RPN 00 01: Channel Fine Tune)');
done();
});
ctxt.dataLSB(0, 0);
});
it('rpn 4', function(done) {
var ctxt = JZZ.Context();
ctxt.rpnNull(0);
ctxt.connect(function(msg) {
assert.equal(msg.toString(), 'b0 06 00 -- Data Entry MSB (RPN 7f 7f: NONE)');
done();
});
ctxt.dataMSB(0, 0);
});
it('nrpn 1', function(done) {
var ctxt = JZZ.Context();
ctxt.nrpnMSB(0, 0);
ctxt.connect(function(msg) {
assert.equal(msg.toString(), 'b0 61 00 -- Data Decrement (NRPN 00 ??)');
done();
});
ctxt.dataDecr(0);
});
it('nrpn 2', function(done) {
var ctxt = JZZ.Context();
ctxt.nrpnLSB(0, 0);
ctxt.connect(function(msg) {
assert.equal(msg.toString(), 'b0 61 00 -- Data Decrement (NRPN ?? 00)');
done();
});
ctxt.dataDecr(0);
});
it('nrpn 3', function(done) {
var ctxt = JZZ.Context();
ctxt.nrpn(0, 0, 1);
ctxt.connect(function(msg) {
assert.equal(msg.toString(), 'b0 26 00 -- Data Entry LSB (NRPN 00 01)');
done();
});
ctxt.dataLSB(0, 0);
});
});

describe('Engine: none', function() {
Expand Down

0 comments on commit a95c4c3

Please sign in to comment.