From dec723f4b621855731111f58148ed22fa096572f Mon Sep 17 00:00:00 2001 From: Sema Date: Tue, 27 Jun 2023 00:06:28 -0400 Subject: [PATCH] Added helpers --- javascript/JZZ.js | 5 +++++ test/common.js | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/javascript/JZZ.js b/javascript/JZZ.js index 9974246..11146c7 100644 --- a/javascript/JZZ.js +++ b/javascript/JZZ.js @@ -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; } @@ -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 = { }; diff --git a/test/common.js b/test/common.js index 21ffbf3..05319aa 100644 --- a/test/common.js +++ b/test/common.js @@ -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() {