-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
record.js
41 lines (30 loc) · 1 KB
/
record.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
const midi = require('midi');
// create a readable stream
var stream1 = midi.createReadStream();
var input = new midi.input();
let inputIndex;
for(var n=0;n<input.getPortCount(); n++) {
if(input.getPortName(n) === 'K-Board' || input.getPortName(n).indexOf('UM-1')===0) {
inputIndex = n;
}
}
console.log("Opening",input.getPortName(inputIndex));
// createReadStream also accepts an optional `input` param
input.openPort(inputIndex);
const midimessages = [];
let previousTime = new Date().getTime();
input.on('message', (deltatime, msg) => {
const now = new Date().getTime();
midimessages.push([
now - previousTime
, msg]);
previousTime = now;
});
process.on('SIGINT', function() {
console.log("Caught interrupt signal");
for(let n=0;n<midimessages.length;n++) {
midimessages[n][0]/=1000;
}
require('fs').writeFileSync('recording.json', JSON.stringify(midimessages, null, 1));
process.exit();
});