-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
test.js
67 lines (60 loc) · 1.6 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var JZZ = require('.');
var outs;
var ins;
function tryMidiOut() {
for (var i = 0; i < outs.length; i++) {
var ff = function(x) {
return function() {
console.log('testing MIDI Out:', x);
JZZ().openMidiOut(x).or('Cannot open ' + x)
.program(0, 0).noteOn(0,'C5',127)
.wait(600)
.noteOff(0,'C5')
.wait(200)
.program(0, 8).noteOn(0,'C5',127)
.wait(600)
.noteOff(0,'C5')
.and(function() {
this.close();
setTimeout(nextstep, 1600);
});
}
}(outs[i].name);
steps.splice(i, 0, ff);
}
nextstep();
}
function tryMidiIn() {
for (var i = 0; i < ins.length; i++) {
var ff = function(x) {
return function() {
console.log('\ntesting MIDI In', x);
JZZ().openMidiIn(x).or('Cannot open ' + x)
.connect(function(msg){ console.log(x + ': ' + msg); })
.wait(3000)
.and(function() {
console.log('done');
this.close();
setTimeout(nextstep, 500);
});
}
}(ins[i].name);
steps.splice(i, 0, ff);
}
nextstep();
}
function wait() {
console.log('\ntimeout...\n');
setTimeout(nextstep, 1000);
}
var steps = [tryMidiOut, tryMidiIn, wait, tryMidiOut, tryMidiIn];
JZZ.addMidiOut('Console Log', JZZ.Widget({ _receive: function(msg) { console.log(msg.toString()); }}));
JZZ().or('Cannot start MIDI engine!').and(function(){
outs = this.info().outputs;
ins = this.info().inputs;
nextstep();
});
function nextstep() {
if (!steps.length) return;
steps.splice(0, 1)[0]();
}