Skip to content

Commit

Permalink
Allow Buffers in umpData()
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Jan 17, 2024
1 parent 8588354 commit 1ba7777
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
8 changes: 3 additions & 5 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -3259,11 +3259,9 @@
}
function _bytes(s) {
var i;
var a = s;
if (typeof s == 'string') {
a = [];
for (i = 0; i < s.length; i++) a.push(s.charCodeAt(i));
}
var a = [];
if (typeof s == 'string') for (i = 0; i < s.length; i++) a.push(s.charCodeAt(i));
else for (i = 0; i < s.length; i++) a.push(s[i]);
for (i = 0; i < a.length; i++) if (a[i] != parseInt(a[i]) || a[i] < 0 || a[i] > 255) throw RangeError('Bad data');
return a;
}
Expand Down
2 changes: 1 addition & 1 deletion minified/JZZ.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ describe('UMP messages', function() {
assert.equal(JZZ.UMP.umpData(1, '')[0].toString(), '51000000 00000000 00000000 00000000 -- Data');
assert.equal(JZZ.UMP.umpData(1, '0')[0].toString(), '51010030 00000000 00000000 00000000 -- Data');
assert.equal(JZZ.UMP.umpData(1, [1, 2, 3, 4, 5])[0].toString(), '51050001 02030405 00000000 00000000 -- Data');
assert.equal(JZZ.UMP.umpData(1, Buffer.from([1, 2, 3, 4, 5]))[0].toString(), '51050001 02030405 00000000 00000000 -- Data');
assert.equal(JZZ.UMP.umpData(1, 1, [1, 2, 3, 4, 5])[0].toString(), '51050101 02030405 00000000 00000000 -- Data');
assert.throws(function() { JZZ.UMP.umpData(1, 'Я'); });
});
Expand Down Expand Up @@ -1606,14 +1607,14 @@ describe('JZZ.M1M2', function() {
port.connect(function(msg) { sample.compare(msg); });
port.send(0xf7).reset();
});
it('sysext', function(done) {
it('sysex', function(done) {
var sample = new test.Sample(done, [
[0x30, 0x16, 0x00, 0x20, 0x24, 0x00, 0x04, 0x6b],
[0x30, 0x26, 0x61, 0x72, 0x61, 0x6f, 0x6b, 0x65],
[0x30, 0x33, 0x2e, 0x2e, 0x2e, 0x00, 0x00, 0x00]
]);
var port = new JZZ.M1M2();
port.connect(function(msg) { console.log(msg.toString()); });
port.connect(function(msg) { msg.toString(); });
port.connect(function(msg) { sample.compare(msg); });
port.sxMidiSoft(4, 'karaoke...');
});
Expand Down

0 comments on commit 1ba7777

Please sign in to comment.