-
Notifications
You must be signed in to change notification settings - Fork 1
/
launchkey_common.js
179 lines (158 loc) · 3.88 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
// Controller Script for Launchkey series in Biwig Studio
// Copyright (C) 2015 SAILLANT
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
var ledstate = initArray(-1, 18);
var pendingLedstate = initArray(0, 18);
var selectedPage = 0;
var numParameterPages = 0;
var clipHasContent = initArray( false, 8 );
var clipIsPlaiyng = initArray( false, 8 );
var clipIsRecording = initArray( false, 8 );
var clipIsQueued = initArray( false, 8 );
var cursorScene=0
var canScrollUp = false
var canScrollDown = true
function mixColour(red, green, blink)
{
return (blink ? 8 : 12) | red | (green * 16);
}
function updateOutputState()
{
if(!control_launcher){
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;
}
}
else
{
for(var i=0; i<9;i++)
{
if(!clipHasContent[i])
{
pendingLedstate[i]=mixColour(0,0,false)
}
else
{
if(clipIsPlaiyng[i])
{
pendingLedstate[i]=mixColour(0,3,false);
}
else if(clipIsQueued[i])
{
pendingLedstate[i]=(blink ? mixColour(1, 3, false) : mixColour(0, 1, false));
}
else if(clipIsRecording[i])
{
pendingLedstate[i]=mixColour(3,0,false);
}
else
{
pendingLedstate[i]=mixColour(3,3,false);
}
}
var j = i+9;
if(i==cursorScene)
{
pendingLedstate[j]=mixColour(0,3,false);
}
else
{
pendingLedstate[j]=mixColour(0,0,false);
}
}
}
}
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);
function getClipObserverFunc( state )
{
return function( scene, value )
{
switch( state )
{
case 1: // has content
{
clipHasContent[scene*8] = value;
return;
}
case 2: // is playing
{
clipIsPlaiyng[scene*8] = value;
return;
}
case 3: // is recording
{
clipIsRecording[scene*8] = value;
return;
}
case 4: // is queued
{
clipIsQueued[scene*8] = value;
return;
}
default:
return;
}
}
}
function canScrollScenesUpOb( state )
{
canScrollUp = state;
}
function canScrollScenesDownOb( state )
{
canScrollDown = state;
}