-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
101 lines (91 loc) · 3.29 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var midi = require('midi');
var debug = require('debug')('ddx3216http')
var argparse = require('argparse');
const parse = new argparse.ArgumentParser({description: 'DDX3216http'});
parse.add_argument("-l","--list", { help: 'List MIDI devices', action: 'store_const', const: true, default: false });
parse.add_argument("-d","--dev", { help: 'Use Device number (1..16)', type: 'int', default: undefined });
parse.add_argument("-i","--input", { help: 'Use Device <INPUT> for input', type: 'int', default: 1 });
parse.add_argument("-o","--output", { help: 'Use Device <INPUT> for output', type: 'int', default: 0 });
var args = parse.parse_args();
var output = new midi.output();
var input = new midi.input();
if (args.list) {
console.log("Device List:");
var inputCount = input.getPortCount();
for (var i = 0; i < inputCount; i++) console.log("Input "+i+": "+input.getPortName(i));
var outputCount = output.getPortCount();
for (var i = 0; i < outputCount; i++) console.log("Output "+i+": "+input.getPortName(i));
process.exit(0);
}
if (output.getPortCount() < 1) {
console.log("No midi outs.");
process.exit(1);
}
console.log("Sending on MIDI port", args.output, ":", output.getPortName(args.output));
output.openPort(args.output);
if (input.getPortCount() < (args.input + 1)) {
console.log("Input Port", args.input, "not available. Not listening.");
} else {
console.log("Receiving on MIDI port", args.input, input.getPortName(args.input));
input.openPort(args.input);
input.ignoreTypes(false,true,true);
}
if (args.dev !== undefined) {
console.log("Using Device ", args.dev);
args.dev -= 1;
} else {
console.log("Sending for all devices");
}
var behringer = require('./behringer');
var desk = new behringer(output, args.dev, input);
app.use("/", express.static("public_html"));
io.on('connection', function(socket){
debug('a user connected');
socket.on('aux', function (message) {
var cmd = JSON.parse(message);
debug("Ch", cmd.channel, "Aux", cmd.parameter, "@", cmd.value);
desk.channel(cmd.channel).setAuxSend(cmd.parameter, cmd.value);
});
socket.on('vol', function (message) {
var cmd = JSON.parse(message);
debug("Ch", cmd.channel, "@", cmd.value);
desk.channel(cmd.channel).setVolume(cmd.value);
});
socket.on('get', function (message, cb) {
var cmd = JSON.parse(message);
debug("Get", cmd);
var channel = desk.channel(cmd.channel);
switch (cmd.setting) {
case "vol":
cb(channel.getVolume());
break;
case "aux":
cb(channel.getAuxSend(cmd.parameter));
break;
}
});
});
desk.ping();
desk.events.on('midi', function(param) {
var ch = param.channel.channel+1;
debug('Forward Midi to Web: ', ch);
var parameter = param.parameter;
if (parameter !== undefined) {
parameter += 1;
}
io.emit('midi', {
channelNumber: ch,
setting: param.setting,
parameter: parameter,
value: param.value
});
})
desk.requestMeterData();
var port = 9080;
http.listen(port, function(){
console.log('listening on *:'+port+', you can open http://localhost:'+port+' to connect.');
});