Skip to content

Commit

Permalink
Added helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Jun 27, 2023
1 parent 3109ec8 commit dec723f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -1652,6 +1652,7 @@
function _8b(n) { if (n != parseInt(n) || n < 0 || n > 0xff) _throw(n); return parseInt(n); }
function _14b(n) { if (n != parseInt(n) || n < 0 || n > 0x3fff) _throw(n); return parseInt(n); }
function _16b(n) { if (n != parseInt(n) || n < 0 || n > 0xffff) throw RangeError('Expected a 16-bit value: ' + n); return parseInt(n); }
function _20b(n) { if (n != parseInt(n) || n < 0 || n > 0xfffff) throw RangeError('Expected a 20-bit value: ' + n); return parseInt(n); }
function _21b(n) { if (n != parseInt(n) || n < 0 || n > 0x1fffff) _throw(n); return parseInt(n); }
function _7bn(n) { return _7b(MIDI.noteValue(n), n); }
function _lsb(n) { return _14b(n) & 0x7f; }
Expand Down Expand Up @@ -2915,6 +2916,10 @@

var _helperNN = {
noop: function() { return [0, 0, 0, 0]; },
ticksPQN: function(n) { n = _16b(n); return [0, 0x30, n >> 8, n & 0xff]; },
delta: function(n) { n = _20b(n); return [0, 0x40 + (n >> 16), (n >> 8) & 0xff, n & 0xff]; },
clipStart: function() { return [0xf0, 0x20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; },
clipEnd: function() { return [0xf0, 0x21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; },
};
var _helperGC = {
};
Expand Down
16 changes: 16 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,22 @@ describe('UMP messages', function() {
it('sxMidiSoft', function() {
assert.equal(JZZ.UMP.sxMidiSoft(5, 4, 'karaoke...').toString(), '35160020 2400046b,35266172 616f6b65,35332e2e 2e000000');
});
it('ticksPQN', function() {
assert.equal(JZZ.UMP.ticksPQN(96).toString(), '00300060');
assert.throws(function() { JZZ.UMP.ticksPQN(0x10000); });
});
it('delta', function() {
assert.equal(JZZ.UMP.delta(96).toString(), '00400060');
assert.throws(function() { JZZ.UMP.delta(0x100000); });
});
it('clipStart', function() {
var msg = JZZ.UMP.clipStart();
assert.equal(typeof msg.getGroup(), 'undefined');
assert.equal(msg.toString(), 'f0200000 00000000 00000000 00000000');
});
it('clipEnd', function() {
assert.equal(JZZ.UMP.clipEnd().toString(), 'f0210000 00000000 00000000 00000000');
});
});

describe('SMF events', function() {
Expand Down

0 comments on commit dec723f

Please sign in to comment.