From 3109ec8bd5ed1e7d89361a576c6d65a490b2cf81 Mon Sep 17 00:00:00 2001 From: Sema Date: Mon, 26 Jun 2023 00:18:54 -0400 Subject: [PATCH] UMP constructor fix --- javascript/JZZ.js | 4 ++-- test/common.js | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/javascript/JZZ.js b/javascript/JZZ.js index c950073..9974246 100644 --- a/javascript/JZZ.js +++ b/javascript/JZZ.js @@ -2850,7 +2850,7 @@ // JZZ.UMP function UMP(arg) { - var self = this instanceof UMP ? this : self = new UMP([0, 0, 0, 0]); + var self = this instanceof UMP ? this : self = new UMP(); var i; if (arg instanceof UMP) { self._from = arg._from.slice(); @@ -2858,7 +2858,7 @@ return self; } else self._from = []; - if (typeof arg == 'undefined') return self; + if (typeof arg == 'undefined') arg = [0, 0, 0, 0]; var arr = arg instanceof Array ? arg : arguments; self.length = 0; for (i = 0; i < arr.length; i++) { diff --git a/test/common.js b/test/common.js index 677ea44..21ffbf3 100644 --- a/test/common.js +++ b/test/common.js @@ -765,14 +765,24 @@ describe('MIDI messages', function() { describe('UMP messages', function() { it('throw', function() { + assert.throws(function() { JZZ.UMP(1); }); assert.throws(function() { JZZ.UMP([1]); }); assert.throws(function() { JZZ.UMP([1, 2, 3, 'error']); }); assert.throws(function() { JZZ.UMP([1, 2, 3, 4, 5, 6, 7, 8]); }); }); it('noop', function() { + var s = '00000000'; var msg =JZZ.UMP.noop(); - assert.equal(msg.toString(), '00000000'); assert.equal(typeof msg.getGroup(), 'undefined'); + assert.equal(msg.toString(), s); + msg = new JZZ.UMP(msg); + assert.equal(msg.toString(), s); + msg = new JZZ.UMP(); + assert.equal(msg.toString(), s); + msg = new JZZ.UMP([0, 0, 0, 0]); + assert.equal(msg.toString(), s); + msg = new JZZ.UMP(0, 0, 0, 0); + assert.equal(msg.toString(), s); }); it('noteOn', function() { var s = '21923d7f'; @@ -833,6 +843,9 @@ describe('UMP messages', function() { it('sxGS', function() { assert.equal(JZZ.UMP.sxGS(5).toString(), '3516417f 42124000,35337f00 41000000'); }); + it('sxMidiSoft', function() { + assert.equal(JZZ.UMP.sxMidiSoft(5, 4, 'karaoke...').toString(), '35160020 2400046b,35266172 616f6b65,35332e2e 2e000000'); + }); }); describe('SMF events', function() {