Skip to content

Commit

Permalink
Context - bank
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Jul 27, 2021
1 parent 354ee10 commit 8335d8e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 25 deletions.
56 changes: 32 additions & 24 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -1249,12 +1249,14 @@
JZZ.JZZ = JZZ;
JZZ.version = _version;
JZZ.info = function() { return _J.prototype.info(); };
JZZ.Widget = function(arg) {
var obj = new _M();
if (arg instanceof Object) _for(arg, function(k) { obj[k] = arg[k]; });
obj._resume();
return obj;
};

function Widget(arg) {
var self = new _M();
if (arg instanceof Object) _for(arg, function(k) { self[k] = arg[k]; });
self._resume();
return self;
}
JZZ.Widget = Widget;
_J.prototype.Widget = JZZ.Widget;
JZZ.addMidiIn = function(name, widget) {
var info = _clone(widget._info || {});
Expand Down Expand Up @@ -2471,34 +2473,40 @@
JZZ.MIDI = MIDI;
_J.prototype.MIDI = MIDI;

function Context() {
var self = this instanceof Context ? this : self = new Context();
if (this == self) {
self._clear();
self._resume();
}
return self;
function _clear_ctxt() {
var i;
this._cc = [];
for (i = 0; i < 16; i++) this._cc[i] = {};
}
Context.prototype = new _M();
Context.prototype.constructor = Context;
Context.prototype._receive = function(msg) { this._emit(this._read(msg)); };
Context.prototype._read = function(msg) {
function _read_ctxt(msg) {
if (!msg.length || msg[0] < 0x80) return msg;
if (msg[0] == 0xff) { this._clear(); return msg; }
var ch = msg[0] & 15;
var st = msg[0] >> 4;
if (st == 12) {
if (JZZ.MIDI.programName) {
msg.label(JZZ.MIDI.programName(msg[1]));
msg._bm = this._cc[ch].bm;
msg._bl = this._cc[ch].bl;
msg.label(JZZ.MIDI.programName(msg[1], msg._bm, msg._bl));
}
}
if (st == 11) {
switch (msg[1]) {
case 0: this._cc[ch].bm = msg[2]; break;
case 32: this._cc[ch].bl = msg[2]; break;
}
}
return msg;
};
Context.prototype._clear = function() {
var i;
this._cc = [];
for (i = 0; i < 16; i++) this._cc[i] = {};
};
}
function Context() {
var self = new _M();
self._clear = _clear_ctxt;
self._read = _read_ctxt;
self._receive = function(msg) { this._emit(this._read(msg)); };
self._clear();
self._resume();
return self;
}
JZZ.Context = Context;
_J.prototype.Context = Context;

Expand Down
2 changes: 1 addition & 1 deletion minified/JZZ.js

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,36 @@ describe('JZZ.Context', function() {
var ctxt = JZZ.Context();
ctxt.noteOn(0, 0, 0).reset();
});
it('progName 0', function(done) {
var ctxt = JZZ.Context();
ctxt.connect(function(msg) {
assert.equal(msg.toString(), 'c0 00 -- Program Change');
done();
});
ctxt.program(0, 0);
});
it('progName 1', function(done) {
var ctxt = JZZ.Context();
JZZ.MIDI.programName = function(a, b, c) { return a + ' ' + b + ' ' + c; };
ctxt.connect(function(msg) {
assert.equal(msg.toString(), 'c1 01 -- Program Change (1 undefined undefined)');
JZZ.MIDI.programName = undefined;
done();
});
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);
});
});

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

0 comments on commit 8335d8e

Please sign in to comment.