-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
90 lines (73 loc) · 1.68 KB
/
index.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
import GenericMIDIController from 'generic-midi-controller'
export default function LaunchControlXL (opts = {}) {
const controller = GenericMIDIController(inputs(), outputs())
const bank = (opts.bank || 1) - 1
controller.reset = reset
return controller
function reset () {
controller.send([176, 0, 0])
}
function inputs () {
var buttons = []
var faders = []
var knobs = []
for (var j = 0; j < 4; j++) {
for (var i = 41; i <= 44; i++) {
buttons.push(map(i + j * 16))
}
}
for (var i = 77; i <= 84; i++) {
faders.push(smooth(i))
}
for (var i = 13; i <= 20; i++) {
knobs.push(smooth(i))
}
for (var i = 29; i <= 36; i++) {
knobs.push(smooth(i))
}
for (var i = 49; i <= 56; i++) {
knobs.push(smooth(i))
}
return {
buttons,
faders,
knobs
}
function map (id) {
return msg => {
if (msg[1] !== id) return
if (msg[0] !== 152 + bank && msg[0] !== 136 + bank) return
return msg[2]
}
}
function smooth (id) {
return msg => {
if (msg[1] !== id) return
if (msg[0] !== 184 + bank) return
return msg[2]
}
}
}
function outputs () {
var buttons = []
var knobs = []
for (var i = 41; i <= 92; i++) {
buttons.push(btn(i))
}
for (var i = 0; i <= 23; i++) {
knobs.push(knob(i))
}
return {
buttons,
knobs
}
function btn (id) {
return (value, send) => send([152 + bank, id, value])
}
function knob (id) {
return (value, send) => send([
240, 0, 32, 41, 2, 17, 120, 8 + bank, id, value, 247
])
}
}
}