forked from sydlawrence/OversizedLaunchpad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.js
51 lines (37 loc) · 1.15 KB
/
input.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
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, midi = require('midi')
, config = require('./config').config
, io = require('socket.io').listen(config.input_socket);
io.set('log level', 1);
console.log(config);
var connections = [];
io.sockets.on('connection', function (socket) {
connections.push(socket);
socket.on('disconnect', function() {
connections.forEach(function(connection, i) {
if (connection === socket) {
connections.splice(i, 1);
}
});
});
});
// Set up a new input.
var input = new midi.input();
// Configure a callback.
input.on('message', function(deltaTime, message) {
connections.forEach(function(connection) {
connection.emit('midijs', { message: message, deltaTime:deltaTime });
});
});
// Open the first available input port.
input.openPort(config.midiPort);
// Sysex, timing, and active sensing messages are ignored
// by default. To enable these message types, pass false for
// the appropriate type in the function below.
// Order: (Sysex, Timing, Active Sensing)
//input.ignoreTypes(false, false, false);
// ... receive MIDI messages ...