-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-src.js
43 lines (43 loc) · 1.31 KB
/
test-src.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
var readline = require('readline');
var mt = require('.');
console.log('midi-test v.' + mt.version);
var src = mt.MidiSrc('VIRTUAL MIDI-In');
console.log('Opening ' + src.name + ':', src.connect());
if (!src.connected) {
console.log('Could not open ' + src.name + '!');
process.exit(0);
}
console.log('Enter MIDI sequence or Ctrl-C to terminate...');
console.log('Multiple messages can be separated by comma,');
console.log('e.g.: c0 10, 90 40 7f');
var rl = readline.createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', function(line){
var i, j, chunk, msg, x;
var group = [];
var data = line.split(/,\s*/);
for (i = 0; i < data.length; i++) {
if (data[i] == '') continue;
chunk = data[i].split(/\s+/);
msg = [];
for (j = 0; j < chunk.length; j++) {
if (chunk[j] == '') continue;
x = parseInt(chunk[j], 16);
if (x >= 0 && x <= 255) msg.push(x);
else {
console.log('Invalid hex MIDI value:', chunk[j]);
return;
}
}
if (msg.length) group.push(msg);
}
if (!group.length) return;
for (i = 0; i < group.length; i++) {
data = [];
msg = group[i];
for (j = 0; j < msg.length; j++) {
data.push(('0' + msg[j].toString(16)).substr(-2));
}
console.log('Sending:', data.join(' '));
src.emit(msg);
}
});