forked from einfachfelixverdammt/Maschine-Jam-for-Bitwig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SceneLaunchView.js
202 lines (177 loc) · 6.25 KB
/
SceneLaunchView.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/**
* @param {TrackBank} trackBank
* @param {int} numTracks
* @param {int} numScenes
*/
function SceneLaunchView(trackBank, numScenes, numTracks) {
var active = true;
var exist = [];
var hasclips = [];
var globalScrollPosition = 0;
var sceneBank = host.createSceneBank(numScenes);
//var allSceneBank = host.createSceneBank(0);
sceneBank.addScrollPositionObserver(function (scrollPosition) {
globalScrollPosition = scrollPosition;
for (var i = 0; i < numScenes; i++) {
sendToJam(i, getSceneColor(i, scrollPosition));
}
}, 0);
this.enter = function () {
active = true;
//numTracks
for(var i=0;i<numScenes;i++) {
sendToJam(i, getSceneColor(i, globalScrollPosition));
}
};
this.exit = function () {
active = false;
};
for (var i = 0; i < numScenes; i++) {
registerScene(i);
exist.push(false);
}
this.update = function () {
//numTracks
for(var i=0;i<numScenes;i++) {
sendToJam(i, getSceneColor(i));
}
};
this.sceneStates = function () {
return exist;
};
var sendToJam = function (index, color) {
if (!active) {
return;
}
controls.sceneRow.sendValue(index, color);
};
function getSceneColor(sceneindex) {
if (hasclips[sceneindex] > 0) {
if (sceneindex < 8)
{
return JAMColorBase.WHITE;
} else if (sceneindex < 16)
{
return JAMColorBase.YELLOW;
} else if (sceneindex < 24)
{
return JAMColorBase.LIME;
} else if (sceneindex < 32)
{
return JAMColorBase.GREEN;
} else {
return JAMColorBase.MINT;
}
} else if (exist[sceneindex]) {
return JAMColorBase.FUCHSIA;
}
return JAMColor.OFF;
}
//added: scene coloring by scene index
function getSceneColor(sceneindex, scrollPosition) {
if(undefined === scrollPosition){
scrollPosition = 0;
}
if (hasclips[sceneindex] > 0) {
if (sceneindex + scrollPosition < 8) {
return JAMColorBase.ORANGE;
} else if (sceneindex + scrollPosition < 16) {
return JAMColorBase.YELLOW;
} else if (sceneindex + scrollPosition < 24) {
return JAMColorBase.LIME;
} else if (sceneindex + scrollPosition < 32) {
return JAMColorBase.GREEN;
} else {
return JAMColorBase.MINT;
}
} else if (exist[sceneindex]) {
return JAMColorBase.FUCHSIA;
}
return JAMColor.OFF;
}
function registerScene(sceneindex) {
var scene = sceneBank.getScene(sceneindex);
//does scene exist ?
scene.exists().addValueObserver(function (pExists) {
exist[sceneindex] = pExists;
sendToJam(sceneindex, getSceneColor(sceneindex, globalScrollPosition));
});
//has scene clips?
scene.addClipCountObserver(function (count) {
hasclips[sceneindex] = count;
sendToJam(sceneindex, getSceneColor(sceneindex, globalScrollPosition));
});
}
this.navigate = function (direction) {
switch (direction) {
case DirectionPad.TOP:
if (gGlipOrientation === ORIENTATION.TrackBased) {
if (modifiers.isShiftDown()) {
sceneBank.scrollUp();
} else {
sceneBank.scrollPageUp();
}
}
break;
case DirectionPad.DOWN:
if (gGlipOrientation === ORIENTATION.TrackBased) {
if (modifiers.isShiftDown()) {
sceneBank.scrollDown();
} else {
sceneBank.scrollPageDown();
}
}
break;
case DirectionPad.LEFT:
if (gGlipOrientation === ORIENTATION.SceneBased) {
if (modifiers.isShiftDown()) {
sceneBank.scrollUp();
} else {
sceneBank.scrollPageUp();
}
}
break;
case DirectionPad.RIGHT:
if (gGlipOrientation === ORIENTATION.SceneBased) {
if (modifiers.isShiftDown()) {
sceneBank.scrollDown();
} else {
sceneBank.scrollPageDown();
}
}
break;
}
};
this.handleEvent = function (index, value) {
if (exist[index]) {
var color = getSceneColor(index);
sendToJam(index, value === 0 ? color : color + 1);
}
if (value === 0) {
return;
}
if (modifiers.isDpadRightDown() || !exist[index] || modifiers.isShiftDown()) {
applicationControl.invokeAction("Create Scene");
} else {
sceneBank.launchScene(index);
}
var scene = sceneBank.getScene(index);
//added: duplicate or remove
if (modifiers.isDuplicateDown()) {
applicationControl.focusClipLauncher();
scene.showInEditor();
scene.selectInEditor();
applicationControl.getApplication().duplicate();
} else if (modifiers.isClearDown()) {
host.showPopupNotification("clear down has not been tested extensively");
applicationControl.focusClipLauncher();
scene.showInEditor();
scene.selectInEditor();
applicationControl.getApplication().remove();
}
};
//trackBank.addSceneCountObserver( function(scenecount) {
// println(" Scene Counts = " + scenecount);
//allSceneBank = host.createSceneBank(scenecount);
//});
}