Skip to content

Commit

Permalink
match()
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Aug 24, 2021
1 parent a1c632c commit 103de55
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 9 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/jzz@1.3.9"></script> // any particular version
<script src="https://cdn.jsdelivr.net/npm/jzz@1.4.0"></script> // any particular version
//...
```

##### CDN (unpkg)

```html
<script src="https://unpkg.com/jzz"></script> // the latest version, or
<script src="https://unpkg.com/jzz@1.3.9"></script> // any particular version
<script src="https://unpkg.com/jzz@1.4.0"></script> // any particular version
//...
```

Expand Down
26 changes: 25 additions & 1 deletion javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
})(this, function() {

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

/* istanbul ignore next */
var _time = Date.now || function () { return new Date().getTime(); };
var _startTime = _time();
/* istanbul ignore next */
var _now = typeof performance != 'undefined' && performance.now ?
function() { return performance.now(); } : function() { return _time() - _startTime; };
var _schedule = function(f) {
Expand Down Expand Up @@ -2234,6 +2236,28 @@
MIDI.prototype.isKeySignature = function() {
return this.ff == 0x59;
};
MIDI.prototype.isGmReset = function() {
return this.match([0xf0, 0x7e, [0, 0], 0x09, [0, 0], 0xf7]);
};
MIDI.prototype.isGsReset = function() {
return this.match([0xf0, 0x41, [0, 0], 0x42, 0x12, 0x40, 0, 0x7f, 0, 0x41, 0xf7]);
};
MIDI.prototype.isXgReset = function() {
return this.match([0xf0, 0x43, [0x10, 0xf0], 0x4c, 0, 0, 0x7e, 0, 0xf7]);
};
MIDI.prototype.match = function(a, n) {
var i, m;
for (i = 0; i < a.length; i++) {
m = a[i][1];
if (typeof m == 'undefined') {
if (this[i] != a[i]) return false;
}
else {
if ((this[i] & m) != (a[i][0] & m)) return false;
}
}
return true;
};

function _s2a(x) {
var a = [];
Expand Down
2 changes: 1 addition & 1 deletion minified/JZZ.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jzz",
"version": "1.3.9",
"version": "1.4.0",
"description": "MIDI library for Node.js and web-browsers",
"main": "javascript/JZZ.js",
"scripts": {
Expand All @@ -25,10 +25,10 @@
"grunt": "^1.4.1",
"grunt-contrib-jshint": "^3.0.0",
"grunt-contrib-uglify": "^5.0.1",
"midi-test": "^1.1.7",
"mocha": "^9.0.3",
"midi-test": "^1.1.8",
"mocha": "^9.1.0",
"nyc": "^15.1.0",
"web-midi-test": "^1.1.7"
"web-midi-test": "^1.1.8"
},
"runkitExampleFilename": "runkit.js",
"repository": {
Expand Down
21 changes: 21 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ describe('MIDI messages', function() {
msg._unstamp();
assert.equal(msg.toString(), 'empty');
});
it('match', function() {
var msg = JZZ.MIDI(0x91, 'C5', 0x7f);
assert.equal(msg.match(msg), true);
assert.equal(msg.match([0x91, 0x3c, 0x7f]), true);
assert.equal(msg.match([0x91]), true);
assert.equal(msg.match([0x90, 0x3c, 0x7f]), false);
assert.equal(msg.match([[0x94, 0x70], 0x3c, 0x7f]), true);
assert.equal(msg.match([[0x94, 0x7f], 0x3c, 0x7f]), false);
});
it('label', function() {
assert.equal(JZZ.MIDI(0x90, 'C#5', 0x7f).label('C#').label('Db').toString(), '90 3d 7f -- Note On (C#, Db)');
});
Expand Down Expand Up @@ -601,11 +610,23 @@ describe('MIDI messages', function() {
assert.equal(JZZ.MIDI.sxGM(1).toString(), 'f0 7e 7f 09 01 f7');
assert.equal(JZZ.MIDI.sxGM(true).toString(), 'f0 7e 7f 09 01 f7');
assert.equal(JZZ.MIDI.sxGM(2).toString(), 'f0 7e 7f 09 03 f7');
assert.equal(JZZ.MIDI.sxGM().isGmReset(), true);
assert.equal(JZZ.MIDI.sxGM().isGsReset(), false);
assert.equal(JZZ.MIDI.sxGM().isXgReset(), false);
});
it('sxGS', function() {
assert.equal(JZZ.MIDI.sxId(0x10).sxGS().toString(), 'f0 41 10 42 12 40 00 7f 00 41 f7');
assert.equal(JZZ.MIDI.sxId(0x10).sxGS(0x40, 0x01, 0x33, 0x0c).toString(), 'f0 41 10 42 12 40 01 33 0c 00 f7');
assert.equal(JZZ.MIDI.sxGS([0x40, 0x01, 0x33, 0x0c]).toString(), 'f0 41 7f 42 12 40 01 33 0c 00 f7');
assert.equal(JZZ.MIDI.sxGS().isGmReset(), false);
assert.equal(JZZ.MIDI.sxGS().isGsReset(), true);
assert.equal(JZZ.MIDI.sxGS().isXgReset(), false);
});
it('sxXG', function() {
var msg = JZZ.MIDI([0xf0, 0x43, 0x10, 0x4c, 0x00, 0x00, 0x7e, 0x00, 0xf7]);
assert.equal(msg.isGmReset(), false);
assert.equal(msg.isGsReset(), false);
assert.equal(msg.isXgReset(), true);
});
it('sxMidiSoft', function() {
assert.equal(JZZ.MIDI.sxMidiSoft(0).toString(), 'f0 00 20 24 00 00 f7 -- [K:00]');
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.3.8"
"jzz": "^1.4.0"
},
"contributors": [
{
Expand Down

0 comments on commit 103de55

Please sign in to comment.