Skip to content

Commit

Permalink
UMP constructor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Jun 26, 2023
1 parent 48367b7 commit 3109ec8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -2850,15 +2850,15 @@
// 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();
_for(arg, function(i) { if (i != '_from') self[i] = arg[i]; });
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++) {
Expand Down
15 changes: 14 additions & 1 deletion test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 3109ec8

Please sign in to comment.