-
Notifications
You must be signed in to change notification settings - Fork 3
/
launchkey-leds.js
68 lines (57 loc) · 1008 Bytes
/
launchkey-leds.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
load("launchkey-vars.js");
var ledState = initArray(0, 128);
var pendingLedState = initArray(0, 128);
function mkColor(green, red)
{
return 0x10 * green + 0x01 * red;
}
function mkRed(value)
{
return mkColor(0, value);
}
function mkGreen(value)
{
return mkColor(value, 0);
}
function mkYellow(value)
{
return mkColor(value, value);
}
function clearLEDs(force)
{
for (var cc = 0; cc < ledState.length; ++cc) {
if (force) {
ledState[cc] = 1;
}
pendingLedState[cc] = 0;
}
}
function setLED(cc, value)
{
pendingLedState[cc] = value;
}
function updateLED(cc)
{
if (ledState[cc] != pendingLedState[cc]) {
host.getMidiOutPort(1).sendMidi(
pendingLedState[cc] ? STATUS.MIDI1.PAD_ON : STATUS.MIDI1.PAD_OFF,
cc,
pendingLedState[cc]
);
ledState[cc] = pendingLedState[cc];
}
}
function getLED(cc)
{
return ledState[cc];
}
function getPendingLED(cc)
{
return pendingLedState[cc];
}
function flushLEDs()
{
for (var cc = 0; cc < ledState.length; ++cc) {
updateLED(cc);
}
}