Skip to content

Commit

Permalink
All MIDI 1.0 helpers are available in MIDI 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Sep 29, 2023
1 parent 654f002 commit 5965c8a
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ by running `npm remove midi-test --save-dev`.

```html
<script src="https://cdn.jsdelivr.net/npm/jzz"></script> // the latest version, or
<script src="https://cdn.jsdelivr.net/npm/[email protected].0"></script> // any particular version
<script src="https://cdn.jsdelivr.net/npm/[email protected].1"></script> // any particular version
//...
```

##### CDN (unpkg)

```html
<script src="https://unpkg.com/jzz"></script> // the latest version, or
<script src="https://unpkg.com/[email protected].0"></script> // any particular version
<script src="https://unpkg.com/[email protected].1"></script> // any particular version
//...
```

Expand Down
34 changes: 28 additions & 6 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
})(this, function() {

var _scope = typeof window === 'undefined' ? global : window;
var _version = '1.7.0';
var _version = '1.7.1';
var i, j, k, m, n;

/* istanbul ignore next */
Expand Down Expand Up @@ -1994,14 +1994,14 @@
mode3: function(c) { return [ _helperCH.omni(c, false), _helperCH.poly(c) ]; },
mode4: function(c) { return [ _helperCH.omni(c, false), _helperCH.mono(c) ]; }
};
var _helperGNC = { // compound messages no channel
var _helperSXX = { // compound messages no channel
sxMasterTuning: function(n, m, l) { return [_helperSX.sxMasterCoarseTuning.call(this, n), _helperSX.sxMasterFineTuning.call(this, m, l)]; },
sxMasterTuningF: function(x) { return [_helperSX.sxMasterCoarseTuningF.call(this, x), _helperSX.sxMasterFineTuningF.call(this, x)]; },
gsMasterTuningF: function(x) { return [_helperSX.gsMasterCoarseTuningF.call(this, x), _helperSX.gsMasterFineTuningF.call(this, x)]; },
xgMasterTuningF: function(x) { return [_helperSX.xgMasterCoarseTuningF.call(this, x), _helperSX.xgMasterFineTuningF.call(this, x)]; },
sxMasterTuningA: function(a) { return _helperGNC.sxMasterTuningF.call(this, MIDI.shift(a)); },
gsMasterTuningA: function(a) { return _helperGNC.gsMasterTuningF.call(this, MIDI.shift(a)); },
xgMasterTuningA: function(a) { return _helperGNC.xgMasterTuningF.call(this, MIDI.shift(a)); },
sxMasterTuningA: function(a) { return _helperSXX.sxMasterTuningF.call(this, MIDI.shift(a)); },
gsMasterTuningA: function(a) { return _helperSXX.gsMasterTuningF.call(this, MIDI.shift(a)); },
xgMasterTuningA: function(a) { return _helperSXX.xgMasterTuningF.call(this, MIDI.shift(a)); },
gsScaleTuning: function(c, a) { var out = []; if (a.length != 12) throw RangeError('Wrong input size: ' + a.length);
for (var i = 0; i < 12; i++) out.push(_helperSX.gsOctaveTuning.call(this, c, i, a[i])); return out; },
gsScaleTuningF: function(c, a) { var out = []; if (a.length != 12) throw RangeError('Wrong input size: ' + a.length);
Expand Down Expand Up @@ -2244,7 +2244,7 @@
_for(_helperNC, function(n) { _copyHelperNC(n, _helperNC[n]); });
_for(_helperSX, function(n) { _copyHelperNC(n, _helperSX[n]); });
_for(_helperSMF, function(n) { _copyHelperSMF(n, _helperSMF[n]); });
_for(_helperGNC, function(n) { _copyHelperGNC(n, _helperGNC[n]); });
_for(_helperSXX, function(n) { _copyHelperGNC(n, _helperSXX[n]); });
_for(_helperMPE, function(n) { _copyHelperMPE(n, _helperMPE[n]); });
_for(_helperCH, function(n) { _copyHelperCH(n, _helperCH[n]); });
_for(_helperGCH, function(n) { _copyHelperGCH(n, _helperGCH[n]); });
Expand Down Expand Up @@ -3178,6 +3178,27 @@
return g;
};
}
function _copyHelperSXX(name, func) {
UMP[name] = function() {
var args = Array.prototype.slice.call(arguments);
if (typeof this._gr != 'undefined') args = [this._gr].concat(args);
var m = func.apply(this, args.slice(1));
var a = [];
for (var i = 0; i < m.length; i++) a = a.concat(_sliceSX(_4b(args[0]), m[i]));
return a;
};
_helpersUmp[name] = function() {
var args = Array.prototype.slice.call(arguments);
if (typeof this._gr != 'undefined') args = [this._gr].concat(args);
var m = func.apply(this, args.slice(1));
var g = this;
for (var i = 0; i < m.length; i++) {
var a = _sliceSX(_4b(args[0]), m[i]);
for (var j = 0; j < a.length; j++) g = g.send(a[j]);
}
return g;
};
}
function _copyHelperM1N(name, func) {
UMP[name] = function() {
var args = Array.prototype.slice.call(arguments);
Expand Down Expand Up @@ -3233,6 +3254,7 @@
_for(_helperCH, function(n) { _copyHelperM1C(n, _helperCH[n]); });
_for(_helperGCH, function(n) { _copyHelperM1CX(n, _helperGCH[n]); });
_for(_helperSX, function(n) { _copyHelperSX(n, _helperSX[n]); });
_for(_helperSXX, function(n) { _copyHelperSXX(n, _helperSXX[n]); });

function _copyUmpHelpers(M) {
_for(_helpersUmp, function(n) { M.prototype[n] = _helpersUmp[n]; });
Expand Down
2 changes: 1 addition & 1 deletion minified/JZZ.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jzz",
"version": "1.7.0",
"version": "1.7.1",
"description": "MIDI library for Node.js and web-browsers",
"main": "javascript/JZZ.js",
"scripts": {
Expand Down
31 changes: 31 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,11 @@ describe('UMP messages', function() {
it('sxMidiSoft', function() {
assert.equal(JZZ.UMP.sxMidiSoft(5, 4, 'karaoke...').toString(), '35160020 2400046b -- SysEx,35266172 616f6b65 -- SysEx,35332e2e 2e000000 -- SysEx');
});
it('xgMasterTuningA', function() {
var s = '30164310 4c000006 -- SysEx,30314000 00000000 -- SysEx,30164310 4c000000 -- SysEx,30340004 00000000 -- SysEx';
assert.equal(JZZ.UMP.xgMasterTuningA(0, 440).toString(), s);
assert.equal(JZZ.UMP.gr(0).xgMasterTuningA(440).toString(), s);
});
it('umpClock', function() {
assert.equal(JZZ.UMP.umpClock(96).toString(), '00100060 -- JR Clock');
});
Expand Down Expand Up @@ -1465,6 +1470,32 @@ describe('JZZ.Widget', function() {
assert.equal(port.connected(), 1);
port.sxGS(1).gr(2).sxGS().disconnect();
});
it('xgMasterTuningA', function(done) {
var sample = new test.Sample(done, [
[48, 22, 67, 16, 76, 0, 0, 6],
[48, 49, 64, 0, 0, 0, 0, 0],
[48, 22, 67, 16, 76, 0, 0, 0],
[48, 52, 0, 4, 0, 0, 0, 0],
[48, 22, 67, 16, 76, 0, 0, 6],
[48, 49, 64, 0, 0, 0, 0, 0],
[48, 22, 67, 16, 76, 0, 0, 0],
[48, 52, 0, 4, 0, 0, 0, 0]
]);
var port = JZZ.Widget().MIDI2();
port.connect(function(msg) { sample.compare(msg); });
assert.equal(port.connected(), 1);
port.xgMasterTuningA(0, 440).gr(0).xgMasterTuningA(440).disconnect();
});

it('xgMasterTuningA', function() {
var s = '30164310 4c000006 -- SysEx,30314000 00000000 -- SysEx,30164310 4c000000 -- SysEx,30340004 00000000 -- SysEx';
assert.equal(JZZ.UMP.xgMasterTuningA(0, 440).toString(), s);
assert.equal(JZZ.UMP.gr(0).xgMasterTuningA(440).toString(), s);
});




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
2 changes: 1 addition & 1 deletion web-midi-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"web-midi-api"
],
"dependencies": {
"jzz": "^1.7.0"
"jzz": "^1.7.1"
},
"contributors": [
{
Expand Down

0 comments on commit 5965c8a

Please sign in to comment.