Skip to content

Commit

Permalink
Added umpProgram()
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Oct 11, 2023
1 parent 5965c8a commit 6d62841
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
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.7.1"></script> // any particular version
<script src="https://cdn.jsdelivr.net/npm/jzz@1.7.2"></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.7.1"></script> // any particular version
<script src="https://unpkg.com/jzz@1.7.2"></script> // any particular version
//...
```

Expand Down
13 changes: 11 additions & 2 deletions javascript/JZZ.js
Expand Up @@ -14,7 +14,7 @@
})(this, function() {

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

/* istanbul ignore next */
Expand Down Expand Up @@ -1899,7 +1899,7 @@
return _helperSX.sxScaleTuning2.call(this, a, v, c); },
sxGM: function(gm) { if (typeof gm == 'undefined') gm = 1; return [0xF0, 0x7E, this._sxid, 0x09, gm ? gm == 2 ? 3 : 1 : 2, 0xf7]; },
sxGS: function(arg) { var arr = typeof arg == 'undefined' ? [0x40, 0, 0x7F, 0] : arg instanceof Array ? arg : arguments;
var c = 0; var a = [0xF0, 0x41, this._sxid, 0x42, 0x12];
var c = 0; var a = [0xf0, 0x41, this._sxid, 0x42, 0x12];
for (var i = 0; i < arr.length; i++) { var x = _7b(arr[i]); a.push(x); c += x; }
c %= 128; a.push(c ? 128 - c : 0); a.push(0xf7); return a; },
sxXG: function(arg) { var arr = typeof arg == 'undefined' ? [0, 0, 0x7E, 0] : arg instanceof Array ? arg : arguments;
Expand Down Expand Up @@ -3055,6 +3055,11 @@
v = v || 0; t = t || 0; a = a || 0;
v = _16b(v); a = _16b(a);
return [0x40 + _4b(g), 0x80 + _ch(c), _7bn(n), _8b(t), v >> 8, v & 255, a >> 8, a & 255];
},
umpProgram: function(g, c, n, msb, lsb) {
return typeof msb == 'undefined' && typeof lsb == 'undefined' ?
[0x40 + _4b(g), 0xc0 + _ch(c), 0, 0, _7bn(n), 0, 0, 0] :
[0x40 + _4b(g), 0xc0 + _ch(c), 0, 1, _7bn(n), 0, _7bn(msb), _7bn(lsb)];
}
};
var _helperGCX = {
Expand Down Expand Up @@ -3271,6 +3276,9 @@
UMP.prototype.getTimeSignature = function() {
if (this.isTimeSignature()) return [this[4], 1 << this[5]];
};
UMP.prototype.getTicksPQN = function() {
if (this.isTicksPQN()) return (this[2] << 8) + this[3];
};
UMP.prototype.getDelta = function() {
if (this.isDelta()) return ((this[1] & 15) << 16) + (this[2] << 8) + this[3];
};
Expand All @@ -3281,6 +3289,7 @@
UMP.prototype.isTimeSignature = function() {
return (this[0] >> 4) == 13 && (this[1] >> 4) == 1 && this[2] == 0 && this[3] == 1;
};
UMP.prototype.isTicksPQN = function() { return this[0] == 0 && (this[1] >> 4) == 3; };
UMP.prototype.isDelta = function() { return this[0] == 0 && (this[1] >> 4) == 4; };
UMP.prototype.isStartClip = function() { return this.match([0xf0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); };
UMP.prototype.isEndClip = function() { return this.match([0xf0, 0x21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); };
Expand Down
2 changes: 1 addition & 1 deletion minified/JZZ.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "jzz",
"version": "1.7.1",
"version": "1.7.2",
"description": "MIDI library for Node.js and web-browsers",
"main": "javascript/JZZ.js",
"scripts": {
Expand All @@ -22,7 +22,7 @@
"jazz-midi": "^1.7.9"
},
"devDependencies": {
"eslint": "^8.50.0",
"eslint": "^8.51.0",
"grunt": "^1.6.1",
"grunt-contrib-jshint": "^3.2.0",
"grunt-contrib-uglify": "^5.2.2",
Expand Down
10 changes: 9 additions & 1 deletion test/common.js
Expand Up @@ -878,12 +878,15 @@ describe('UMP messages', function() {
assert.equal(JZZ.UMP.umpTimestamp(96).toString(), '00200060 -- JR Timestamp');
});
it('umpTicksPQN', function() {
assert.equal(JZZ.UMP.umpTicksPQN(96).toString(), '00300060 -- Ticks Per Quarter Note');
var msg = JZZ.UMP.umpTicksPQN(96);
assert.equal(msg.getTicksPQN(), 96);
assert.equal(msg.toString(), '00300060 -- Ticks Per Quarter Note');
assert.throws(function() { JZZ.UMP.umpTicksPQN(0x10000); });
});
it('umpDelta', function() {
var msg = JZZ.UMP.umpDelta(96);
assert.equal(msg.getDelta(), 96);
assert.equal(typeof msg.getTicksPQN(), 'undefined');
assert.equal(msg.toString(), '00400060 -- Delta Ticks');
assert.equal(JZZ.UMP.umpDelta().toString(), '00400000 -- Delta Ticks');
assert.throws(function() { JZZ.UMP.umpDelta(0x100000); });
Expand Down Expand Up @@ -1034,6 +1037,11 @@ describe('UMP messages', function() {
assert.equal(JZZ.UMP.umpNoteOff(1, 2, 61).toString(), s);
assert.equal(JZZ.UMP.umpNoteOff(1, 2, 'C#5', 0).toString(), s);
});
it('umpProgram', function() {
assert.equal(JZZ.UMP.umpProgram(1, 2, 3).toString(), '41c20000 03000000 -- Program Change');
assert.equal(JZZ.UMP.umpProgram(1, 2, 3, 4, 5).toString(), '41c20001 03000405 -- Program Change');
assert.throws(function() { JZZ.UMP.umpProgram(1, 2, 3, 4); });
});

it('unknown', function() {
assert.equal(JZZ.UMP([0xd0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).toString(), 'd0000700 00000000 00000000 00000000');
Expand Down
2 changes: 1 addition & 1 deletion web-midi-api/package.json
Expand Up @@ -13,7 +13,7 @@
"web-midi-api"
],
"dependencies": {
"jzz": "^1.7.1"
"jzz": "^1.7.2"
},
"contributors": [
{
Expand Down

0 comments on commit 6d62841

Please sign in to comment.