Skip to content

Commit

Permalink
M1M2
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Oct 23, 2023
1 parent 28e3397 commit dd903c9
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
25 changes: 25 additions & 0 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -3461,6 +3461,31 @@
JZZ.M2M1 = M2M1;
_J.prototype.M2M1 = JZZ.M2M1;

function _m1m2(msg) {
if (!msg.isMidi2) {
var gr = msg.gr >= 0 && msg.gr <= 15 ? msg.gr : 0;
if (msg[0] >= 0x80 && msg[0] < 0xf0) {
this._emit(JZZ.MIDI2([0x20 + gr].concat(msg.slice(), _zeros).slice(0, 4)));
}
else if (msg[0] > 0xf0 && msg[0] <= 0xff && msg[0] != 0xf7) {
this._emit(JZZ.MIDI2([0x10 + gr].concat(msg.slice(), _zeros).slice(0, 4)));
}
else if (msg.isFullSysEx()) {
var a = _sliceSX(gr, msg.slice());
for (var i = 0; i < a.length; i++) this._emit(JZZ.MIDI2(a[i]));
}
}
else this._emit(msg);
}
function M1M2() {
var self = new _M();
self._receive = _m1m2;
self._resume();
return self;
}
JZZ.M1M2 = M1M2;
_J.prototype.M1M2 = JZZ.M1M2;

JZZ.lib = {};
JZZ.lib.now = _now;
JZZ.lib.schedule = _schedule;
Expand Down
35 changes: 34 additions & 1 deletion test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,9 @@ describe('UMP messages', function() {
assert.equal(JZZ.UMP.umpProgram(1, 2, 3, 4, 5).toString(), '41c20001 03000405 -- Program Change');
assert.throws(function() { JZZ.UMP.umpProgram(1, 2, 3, 4); });
});

it('data', function() {
assert.equal(JZZ.UMP(0x50, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0).toString(), '50000000 00000000 00000000 00000000 -- Data');
});
it('unknown', function() {
assert.equal(JZZ.UMP([0xd0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).toString(), 'd0000700 00000000 00000000 00000000');
assert.equal(JZZ.UMP([0xd0, 0x10, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]).toString(), 'd0100007 00000000 00000000 00000000');
Expand Down Expand Up @@ -1510,6 +1512,37 @@ describe('JZZ.Widget', function() {
});
});

describe('JZZ.M1M2', function() {
it('noteO/Off', function(done) {
var sample = new test.Sample(done, [
[0x21, 0x91, 0x3c, 0x7f], [0x20, 0x81, 0x3c, 0x00],
[0x20, 0x91, 0x3c, 0x7f], [0x20, 0x81, 0x3c, 0x00]
]);
var port = new JZZ.M1M2();
port.connect(function(msg) { sample.compare(msg); });
var msg = JZZ.MIDI.noteOn(1, 'C5');
msg.gr = 1;
port.send(msg).noteOff(1, 'C5', 0).MIDI2().noteOn(0, 1, 'C5').noteOff(0, 1, 'C5', 0);
});
it('reset', function(done) {
var sample = new test.Sample(done, [ [0x10, 0xff, 0x00, 0x00] ]);
var port = new JZZ.M1M2();
port.connect(function(msg) { sample.compare(msg); });
port.send(0xf7).reset();
});
it('sysext', 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) { sample.compare(msg); });
port.sxMidiSoft(4, 'karaoke...');
});
});

describe('JZZ.M2M1', function() {
it('noteO/Off', function(done) {
var sample = new test.Sample(done, [
Expand Down

0 comments on commit dd903c9

Please sign in to comment.