-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunchkey_common.js
71 lines (57 loc) · 1.49 KB
/
launchkey_common.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
var ledstate = initArray(-1, 18);
var pendingLedstate = initArray(0, 18);
var selectedPage = 0;
var numParameterPages = 0;
function mixColour(red, green, blink)
{
return (blink ? 8 : 12) | red | (green * 16);
}
function updateOutputState()
{
for(var i=0; i<8; i++)
{
pendingLedstate[i] = (selectedPage == i)
? mixColour(3, 3, false)
: (i < numParameterPages) ? mixColour(1, 1, false) : 0;
var j = i + 9;
pendingLedstate[j] = (modSourceStates.values[i])
? (blink ? mixColour(1, 3, false) : mixColour(0, 1, false))
: 0;
}
}
function flushOutputState()
{
for(var i=0; i<9; i++)
{
if (pendingLedstate[i] != ledstate[i])
{
ledstate[i] = pendingLedstate[i];
host.getMidiOutPort(1).sendMidi(0x90, 96 + i, ledstate[i]);
}
var j = i + 9;
if (pendingLedstate[j] != ledstate[j])
{
ledstate[j] = pendingLedstate[j];
host.getMidiOutPort(1).sendMidi(0x90, 112 + i, ledstate[j]);
}
}
}
/* Simple buffer array with setter. */
function BufferedElementArray(initialVal, count)
{
this.values = initArray(initialVal, count);
}
/* Return a setter function for the specific index. */
BufferedElementArray.prototype.setter = function(index)
{
var obj = this;
return function(data)
{
obj.set(index, data);
}
};
BufferedElementArray.prototype.set = function(index, data)
{
this.values[index] = data;
};
var modSourceStates = new BufferedElementArray(false, 8);