Skip to content

Commit

Permalink
Updated _M2
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Aug 16, 2023
1 parent 2906657 commit b4ecb4b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
40 changes: 32 additions & 8 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,14 +509,27 @@
throw RangeError('Bad channel value (must not be less than 0 or more than 15): ' + c);
}

// _M2: MIDI 2.0 object
function _M2() {
_R.apply(this);
this._handles = [];
this._outs = [];
}
_M2.prototype = new _R();

// _M2: MIDI 2.0 object
function _M2() {
_R.apply(this);
this._handles = [];
this._outs = [];
}
_M2.prototype = new _R();
_M2.prototype._receive = function(msg) { this._emit(msg); };
_M2.prototype.send = function() {
this._push(_receive, [UMP.apply(null, arguments)]);
return this._thenable();
};
_M2.prototype._emit = function(msg) {
var i;
for (i = 0; i < this._handles.length; i++) this._handles[i].apply(this, [UMP(msg)._stamp(this)]);
for (i = 0; i < this._outs.length; i++) {
var m = UMP(msg);
if (!m._stamped(this._outs[i])) this._outs[i].send(m._stamp(this));
}
};

// _W: Watcher object ~ MIDIAccess.onstatechange
function _W() {
_R.apply(this);
Expand Down Expand Up @@ -1285,6 +1298,16 @@
}
JZZ.Widget = Widget;
_J.prototype.Widget = JZZ.Widget;

function Widget2(arg) {
var self = new _M2();
if (arg instanceof Object) _for(arg, function(k) { self[k] = arg[k]; });
self._resume();
return self;
}
JZZ.Widget2 = Widget2;
_J.prototype.Widget2 = JZZ.Widget2;

JZZ.addMidiIn = function(name, widget) {
var info = _clone(widget._info || {});
info.name = name;
Expand Down Expand Up @@ -2962,6 +2985,7 @@
UMP[name] = function() {
return new UMP(func.apply(this, arguments));
};
_helpersUmp[name] = function() { return this.send(func.apply(this, arguments)); };
}
function _copyHelperGC(name, func) {
UMP[name] = function() {
Expand Down
12 changes: 12 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,18 @@ describe('JZZ.Widget', function() {
});
});

describe('JZZ.Widget2', function() {
it('connect', function(done) {
var port1 = JZZ.Widget2({ _receive: function(msg) { this._emit(msg); done(); }});
var port2 = JZZ.Widget2();
var port3 = JZZ.Widget2();
//port1.connect(port2);
//port2.connect(port3);
//port3.connect(port1);
port1.noop();
});
});

describe('JZZ.Context', function() {
it('reset', function() {
var ctxt = JZZ.Context();
Expand Down

0 comments on commit b4ecb4b

Please sign in to comment.