This repository has been archived by the owner on Jan 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
midi.input.js
99 lines (84 loc) · 2.1 KB
/
midi.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
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
var midi = require('midi'),
_ = require('underscore');
var input = new midi.input();
function initializeMidi() {
if(input.getPortCount()) {
input.openPort(0);
input.emit('ready', input.getPortName(0));
} else {
setTimeout(initializeMidi, 5000);
}
}
initializeMidi();
var CCMap = {
47: [0, 'rwd'],
48: [0, 'fwd'],
45: [0, 'play'],
49: [0, 'loop'],
46: [0, 'stop'],
44: [0, 'rec']
};
var ControllerLayout = {
fader: _.range(2, 6+1, 1).concat(8,9,12,13).map(function(ccNumber, i) {
CCMap[ccNumber] = [i+1, 'fade'];
return {
cc: ccNumber,
type: 'number',
name: 'fade' + (i+1)
};
}),
knob: _.range(14, 22+1, 1).map(function(ccNumber, i) {
CCMap[ccNumber] = [i+1, 'knob'];
return {
cc: ccNumber,
type: 'number',
name: 'knob' + (i+1)
};
}),
btnhi: _.range(23, 31+1, 1).map(function(ccNumber, i) {
CCMap[ccNumber] = [i+1, 'b_hi'];
return {
cc: ccNumber,
type: 'boolean',
name: 'b_hi' + (i+1)
};
}),
btnlo: _.range(33, 41+1, 1).map(function(ccNumber, i) {
CCMap[ccNumber] = [i+1, 'b_lo'];
return {
cc: ccNumber,
type: 'boolean',
name: 'b_lo' + (i+1)
};
}),
rwd: { cc: 47, type: 'boolean', name: 'rewind' },
fwd: { cc: 48, type: 'boolean', name: 'forward' },
play: { cc: 45, type: 'boolean', name: 'play' },
loop: { cc: 49, type: 'boolean', name: 'loop' },
stop: { cc: 46, type: 'boolean', name: 'stop' },
rec: { cc: 44, type: 'boolean', name: 'record' }
};
var controls = [];
// main controls
controls[0] = {
rwd: { cc: 47, type: 'boolean', name: 'rewind' },
fwd: { cc: 48, type: 'boolean', name: 'forward' },
play: { cc: 45, type: 'boolean', name: 'play' },
loop: { cc: 49, type: 'boolean', name: 'loop' },
stop: { cc: 46, type: 'boolean', name: 'stop' },
rec: { cc: 44, type: 'boolean', name: 'record' }
};
_.range(1, 10, 1).forEach(function(ctlIndex, index) {
controls[ctlIndex] = {
fade: ControllerLayout.fader[index],
knob: ControllerLayout.knob[index],
b_lo: ControllerLayout.btnlo[index],
b_hi: ControllerLayout.btnhi[index]
};
});
module.exports = {
input: input,
cc: CCMap,
layout: ControllerLayout,
controls: controls
};