Skip to content

Commit

Permalink
Added clone tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Aug 31, 2019
1 parent 0ee538a commit 5e48cac
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 2 deletions.
2 changes: 2 additions & 0 deletions test/engine3.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ describe('Engine: webmidi', function() {
test.virtual_midi_out();
test.virtual_midi_in_busy();
test.virtual_midi_out_busy();
test.clone_midi_in();
test.clone_midi_out();
test.add_midi_in();
test.add_midi_out();
test.remove_midi_in();
Expand Down
63 changes: 61 additions & 2 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ module.exports = function(JZZ, PARAMS, DRIVER) {
var src = DRIVER.MidiSrc(name);
src.connect();
src.busy = true;
engine.openMidiIn(name).or(function() { src.connect(); done(); });
engine.openMidiIn(name).or(function() { src.disconnect(); done(); });
});
},

Expand All @@ -178,7 +178,66 @@ module.exports = function(JZZ, PARAMS, DRIVER) {
var dst = DRIVER.MidiDst(name);
dst.connect();
dst.busy = true;
engine.openMidiOut(name).or(function() { dst.connect(); done(); });
engine.openMidiOut(name).or(function() { dst.disconnect(); done(); });
});
},

clone_midi_in: function() {
it('Clone MIDI-In', function(done) {
var port1, port2;
var name = 'Virtual MIDI-In clone';
var src = DRIVER.MidiSrc(name);
src.connect();
port1 = engine.openMidiIn(name);
port2 = engine.openMidiIn(name);
assert.notEqual(port1, port2);
var count = 3;
function onmidi(msg) {
count--;
if (!count) {
port2.close();
src.disconnect();
done();
}
}
port1.connect(onmidi);
port2.connect(onmidi);
setTimeout(function() {
src.emit([0x90, 0x40, 0x7f]);
setTimeout(function() {
port1.close();
src.emit([0x80, 0x40, 0x7f]);
}, 10);
}, 10);
});
},

clone_midi_out: function() {
it('Clone MIDI-Out', function(done) {
var port1, port2;
var name = 'Virtual MIDI-Out clone';
var dst = DRIVER.MidiDst(name);
dst.connect();
port1 = engine.openMidiOut(name);
port2 = engine.openMidiOut(name);
assert.notEqual(port1, port2);
var count = 3;
dst.receive = function(msg) {
count--;
if (!count) {
port2.close();
dst.disconnect();
done();
}
}
setTimeout(function() {
port1.send([0x90, 0x40, 0x7f]);
port2.send([0x90, 0x50, 0x7f]);
setTimeout(function() {
port1.close();
port2.send([0x80, 0x50, 0x7f]);
}, 10);
}, 10);
});
},

Expand Down

0 comments on commit 5e48cac

Please sign in to comment.