Skip to content

Commit

Permalink
More UMP helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Aug 21, 2023
1 parent a33db27 commit 31d1d38
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
28 changes: 28 additions & 0 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@
if (!m._stamped(this._outs[i])) this._outs[i].send(m._stamp(this));
}
};
_M2.prototype._image = _M.prototype._image;
_M2.prototype.connect = _M.prototype.connect;
_M2.prototype.disconnect = _M.prototype.disconnect;
_M2.prototype.connected = _M.prototype.connected;
Expand Down Expand Up @@ -2998,12 +2999,20 @@
_helpersUmp[name] = function() { return this.send(func.apply(this, arguments)); };
}
function _copyHelperGC(name, func) {
/*
UMP[name] = function() {
var args = Array.prototype.slice.call(arguments);
if (typeof this._gr != 'undefined') args = [this._gr].concat(args);
if (typeof this._ch != 'undefined') args = [args[0]].concat([this._ch]).concat(args.slice(1));
return new UMP(func.apply(this, args));
};
_helpersUmp[name] = function() {
var args = Array.prototype.slice.call(arguments);
if (typeof this._gr != 'undefined') args = [this._gr].concat(args);
if (typeof this._ch != 'undefined') args = [args[0]].concat([this._ch]).concat(args.slice(1));
return this.send(func.apply(this, args));
};
*/
}
function _copyHelperGN(name, func) {
UMP[name] = function() {
Expand All @@ -3030,6 +3039,14 @@
if (typeof this._gr != 'undefined') args = [this._gr].concat(args);
return _sliceSX(args[0], func.apply(this, args.slice(1)));
};
_helpersUmp[name] = function() {
var args = Array.prototype.slice.call(arguments);
if (typeof this._gr != 'undefined') args = [this._gr].concat(args);
var a = _sliceSX(args[0], func.apply(this, args.slice(1)));
var g = this;
for (var i = 0; i < a.length; i++) g = g.send(a[i]);
return g;
};
}
function _copyHelperM1(name, func) {
UMP[name] = function() {
Expand All @@ -3038,13 +3055,24 @@
if (typeof this._ch != 'undefined') args = [args[0]].concat([this._ch]).concat(args.slice(1));
return new UMP([0x20 + args[0]].concat(func.apply(this, args.slice(1)), [0]).slice(0, 4));
};
_helpersUmp[name] = function() {
var args = Array.prototype.slice.call(arguments);
if (typeof this._gr != 'undefined') args = [this._gr].concat(args);
if (typeof this._ch != 'undefined') args = [args[0]].concat([this._ch]).concat(args.slice(1));
return this.send([0x20 + args[0]].concat(func.apply(this, args.slice(1)), [0]).slice(0, 4));
};
}
function _copyHelperM1N(name, func) {
UMP[name] = function() {
var args = Array.prototype.slice.call(arguments);
if (typeof this._gr != 'undefined') args = [this._gr].concat(args);
return new UMP([0x10 + args[0]].concat(func.apply(this, args.slice(1)), [0, 0]).slice(0, 4));
};
_helpersUmp[name] = function() {
var args = Array.prototype.slice.call(arguments);
if (typeof this._gr != 'undefined') args = [this._gr].concat(args);
return this.send([0x10 + args[0]].concat(func.apply(this, args.slice(1)), [0, 0]).slice(0, 4));
};
}
_for(_helperNN, function(n) { _copyHelperNN(n, _helperNN[n]); });
_for(_helperGC, function(n) { _copyHelperGC(n, _helperGC[n]); });
Expand Down
31 changes: 31 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,37 @@ describe('JZZ.Widget2', function() {
port2.connect(function(msg) { sample.compare(msg); });
port1.gr().gr(1).gr(1).gr().noop();
});
it('reset', function(done) {
var sample = new test.Sample(done, [
[17, 255, 0, 0],
[18, 255, 0, 0]
]);
var port = JZZ.Widget2();
port.connect(function(msg) { sample.compare(msg); });
port.reset(1).gr(2).reset();
});
it('noteOn', function(done) {
var sample = new test.Sample(done, [
[33, 146, 61, 126],
[33, 146, 61, 126],
[33, 146, 61, 126],
[33, 146, 61, 126]
]);
var port = JZZ.Widget2();
port.connect(function(msg) { sample.compare(msg); });
port.noteOn(1, 2, 'C#5', 126).gr(1).noteOn(2, 'C#5', 126).ch(2).noteOn('C#5', 126).gr().noteOn(1, 'C#5', 126);
});
it('sxGS', function(done) {
var sample = new test.Sample(done, [
[49, 22, 65, 127, 66, 18, 64, 0],
[49, 51, 127, 0, 65, 0, 0, 0],
[50, 22, 65, 127, 66, 18, 64, 0],
[50, 51, 127, 0, 65, 0, 0, 0]
]);
var port = JZZ.Widget2();
port.connect(function(msg) { sample.compare(msg); });
port.sxGS(1).gr(2).sxGS();
});
it('umpBPM', function(done) {
var sample = new test.Sample(done, [
[209, 16, 0, 0, 2, 250, 240, 128, 0, 0, 0, 0, 0, 0, 0, 0],
Expand Down

0 comments on commit 31d1d38

Please sign in to comment.