Commit | Line | Data |
---|---|---|
d626bc9b MS |
1 | /** |
2 | * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND | |
3 | * | |
4 | * //\\ //\\ //\\ //\\ | |
5 | * ///\\\ ///\\\ ///\\\ ///\\\ | |
6 | * \\\/// \\\/// \\\/// \\\/// | |
7 | * \\// \\// \\// \\// | |
8 | * | |
9 | * EXPERTS ONLY!! EXPERTS ONLY!! | |
10 | * | |
11 | * Custom UI components using the framework. | |
12 | */ | |
d626bc9b | 13 | |
a8d55ade MS |
14 | class UIBlendMode extends UIWindow { |
15 | public UIBlendMode(float x, float y, float w, float h) { | |
4e6626a9 MS |
16 | super(lx.ui, "BLEND MODE", x, y, w, h); |
17 | List<UIScrollList.Item> items = new ArrayList<UIScrollList.Item>(); | |
a898d79b | 18 | for (LXTransition t : glucose.getTransitions()) { |
d626bc9b | 19 | items.add(new TransitionScrollItem(t)); |
a898d79b MS |
20 | } |
21 | final UIScrollList tList; | |
4e6626a9 | 22 | (tList = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 60)).setItems(items).addToContainer(this); |
a8d55ade | 23 | |
42a424d7 MS |
24 | lx.engine.getDeck(GLucose.RIGHT_DECK).addListener(new LXDeck.AbstractListener() { |
25 | public void faderTransitionDidChange(LXDeck deck, LXTransition transition) { | |
a898d79b | 26 | tList.redraw(); |
d626bc9b | 27 | } |
a898d79b MS |
28 | }); |
29 | } | |
a8d55ade | 30 | |
4e6626a9 | 31 | class TransitionScrollItem extends UIScrollList.AbstractItem { |
a8d55ade MS |
32 | private final LXTransition transition; |
33 | private String label; | |
34 | ||
35 | TransitionScrollItem(LXTransition transition) { | |
36 | this.transition = transition; | |
37 | label = className(transition, "Transition"); | |
38 | } | |
39 | ||
40 | public String getLabel() { | |
41 | return label; | |
42 | } | |
43 | ||
44 | public boolean isSelected() { | |
45 | return transition == glucose.getSelectedTransition(); | |
46 | } | |
47 | ||
48 | public boolean isPending() { | |
49 | return false; | |
50 | } | |
51 | ||
52 | public void onMousePressed() { | |
53 | glucose.setSelectedTransition(transition); | |
54 | } | |
d626bc9b | 55 | } |
a8d55ade | 56 | |
d626bc9b MS |
57 | } |
58 | ||
a8d55ade | 59 | class UICrossfader extends UIWindow { |
d626bc9b | 60 | |
a8d55ade | 61 | private final UIToggleSet displayMode; |
d626bc9b | 62 | |
a8d55ade | 63 | public UICrossfader(float x, float y, float w, float h) { |
4e6626a9 | 64 | super(lx.ui, "CROSSFADER", x, y, w, h); |
a8d55ade | 65 | |
4e6626a9 MS |
66 | new UISlider(4, UIWindow.TITLE_LABEL_HEIGHT, w-9, 32).setParameter(lx.engine.getDeck(GLucose.RIGHT_DECK).getFader()).addToContainer(this); |
67 | (displayMode = new UIToggleSet(4, UIWindow.TITLE_LABEL_HEIGHT + 36, w-9, 20)).setOptions(new String[] { "A", "COMP", "B" }).setValue("COMP").addToContainer(this); | |
d626bc9b MS |
68 | } |
69 | ||
88a3dd9e MS |
70 | public UICrossfader setDisplayMode(String value) { |
71 | displayMode.setValue(value); | |
72 | return this; | |
73 | } | |
74 | ||
a8d55ade MS |
75 | public String getDisplayMode() { |
76 | return displayMode.getValue(); | |
d626bc9b MS |
77 | } |
78 | } | |
79 | ||
80 | class UIEffects extends UIWindow { | |
81 | UIEffects(float x, float y, float w, float h) { | |
4e6626a9 | 82 | super(lx.ui, "FX", x, y, w, h); |
d626bc9b | 83 | |
4e6626a9 MS |
84 | int yp = UIWindow.TITLE_LABEL_HEIGHT; |
85 | List<UIScrollList.Item> items = new ArrayList<UIScrollList.Item>(); | |
d626bc9b MS |
86 | for (LXEffect fx : glucose.lx.getEffects()) { |
87 | items.add(new FXScrollItem(fx)); | |
88 | } | |
89 | final UIScrollList effectsList = new UIScrollList(1, yp, w-2, 60).setItems(items); | |
90 | effectsList.addToContainer(this); | |
4e6626a9 | 91 | yp += effectsList.getHeight() + 10; |
d626bc9b | 92 | |
4e6626a9 | 93 | final UIKnob[] parameterKnobs = new UIKnob[4]; |
d626bc9b | 94 | for (int ki = 0; ki < parameterKnobs.length; ++ki) { |
4e6626a9 | 95 | parameterKnobs[ki] = new UIKnob(5 + 34*(ki % 4), yp + (ki/4) * 48); |
d626bc9b MS |
96 | parameterKnobs[ki].addToContainer(this); |
97 | } | |
98 | ||
99 | GLucose.EffectListener fxListener = new GLucose.EffectListener() { | |
100 | public void effectSelected(LXEffect effect) { | |
101 | int i = 0; | |
102 | for (LXParameter p : effect.getParameters()) { | |
103 | if (i >= parameterKnobs.length) { | |
104 | break; | |
105 | } | |
4e6626a9 MS |
106 | if (p instanceof BasicParameter) { |
107 | parameterKnobs[i++].setParameter((BasicParameter) p); | |
108 | } | |
d626bc9b MS |
109 | } |
110 | while (i < parameterKnobs.length) { | |
111 | parameterKnobs[i++].setParameter(null); | |
112 | } | |
113 | } | |
114 | }; | |
115 | ||
116 | glucose.addEffectListener(fxListener); | |
117 | fxListener.effectSelected(glucose.getSelectedEffect()); | |
118 | ||
119 | } | |
120 | ||
4e6626a9 | 121 | class FXScrollItem extends UIScrollList.AbstractItem { |
d626bc9b MS |
122 | |
123 | private LXEffect effect; | |
124 | private String label; | |
125 | ||
126 | FXScrollItem(LXEffect effect) { | |
127 | this.effect = effect; | |
128 | label = className(effect, "Effect"); | |
129 | } | |
130 | ||
131 | public String getLabel() { | |
132 | return label; | |
133 | } | |
134 | ||
135 | public boolean isSelected() { | |
136 | return !effect.isEnabled() && (glucose.getSelectedEffect() == effect); | |
137 | } | |
138 | ||
139 | public boolean isPending() { | |
140 | return effect.isEnabled(); | |
141 | } | |
142 | ||
d626bc9b MS |
143 | public void onMousePressed() { |
144 | if (glucose.getSelectedEffect() == effect) { | |
145 | if (effect.isMomentary()) { | |
146 | effect.enable(); | |
147 | } else { | |
148 | effect.toggle(); | |
149 | } | |
8f7f055d MS |
150 | } else { |
151 | glucose.setSelectedEffect(effect); | |
d626bc9b MS |
152 | } |
153 | } | |
154 | ||
155 | public void onMouseReleased() { | |
156 | if (effect.isMomentary()) { | |
157 | effect.disable(); | |
158 | } | |
159 | } | |
160 | ||
161 | } | |
162 | ||
163 | } | |
164 | ||
165 | class UIOutput extends UIWindow { | |
166 | public UIOutput(float x, float y, float w, float h) { | |
4e6626a9 MS |
167 | super(lx.ui, "OUTPUT", x, y, w, h); |
168 | float yp = UIWindow.TITLE_LABEL_HEIGHT; | |
1f42cce7 | 169 | |
4e6626a9 | 170 | final UIScrollList outputs = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 80); |
1f42cce7 | 171 | |
4e6626a9 | 172 | List<UIScrollList.Item> items = new ArrayList<UIScrollList.Item>(); |
d626bc9b | 173 | for (final PandaDriver panda : pandaBoards) { |
1f42cce7 | 174 | items.add(new PandaScrollItem(panda)); |
d626bc9b MS |
175 | panda.setListener(new PandaDriver.Listener() { |
176 | public void onToggle(boolean active) { | |
1f42cce7 | 177 | outputs.redraw(); |
d626bc9b MS |
178 | } |
179 | }); | |
d626bc9b | 180 | } |
1f42cce7 MS |
181 | outputs.setItems(items).addToContainer(this); |
182 | } | |
183 | ||
4e6626a9 | 184 | class PandaScrollItem extends UIScrollList.AbstractItem { |
1f42cce7 MS |
185 | final PandaDriver panda; |
186 | PandaScrollItem(PandaDriver panda) { | |
187 | this.panda = panda; | |
188 | } | |
189 | ||
190 | public String getLabel() { | |
191 | return panda.ip; | |
192 | } | |
193 | ||
194 | public boolean isSelected() { | |
195 | return panda.isEnabled(); | |
196 | } | |
197 | ||
8f7f055d | 198 | public void onMousePressed() { |
1f42cce7 MS |
199 | panda.toggle(); |
200 | } | |
201 | } | |
d626bc9b MS |
202 | } |
203 | ||
204 | class UITempo extends UIWindow { | |
205 | ||
206 | private final UIButton tempoButton; | |
207 | ||
208 | UITempo(float x, float y, float w, float h) { | |
4e6626a9 MS |
209 | super(lx.ui, "TEMPO", x, y, w, h); |
210 | tempoButton = new UIButton(4, UIWindow.TITLE_LABEL_HEIGHT, w-10, 20) { | |
d626bc9b MS |
211 | protected void onToggle(boolean active) { |
212 | if (active) { | |
213 | lx.tempo.tap(); | |
214 | } | |
215 | } | |
216 | }.setMomentary(true); | |
217 | tempoButton.addToContainer(this); | |
4e6626a9 | 218 | new UITempoBlipper(8, UIWindow.TITLE_LABEL_HEIGHT + 5, 12, 12).addToContainer(this); |
d626bc9b MS |
219 | } |
220 | ||
4e6626a9 MS |
221 | class UITempoBlipper extends UIObject { |
222 | UITempoBlipper(float x, float y, float w, float h) { | |
223 | super(x, y, w, h); | |
224 | } | |
225 | ||
226 | void onDraw(UI ui, PGraphics pg) { | |
227 | tempoButton.setLabel("" + ((int)(lx.tempo.bpm() * 10)) / 10.); | |
228 | ||
229 | // Overlay tempo thing with openGL, redraw faster than button UI | |
230 | pg.fill(color(0, 0, 24 - 8*lx.tempo.rampf())); | |
231 | pg.noStroke(); | |
232 | pg.rect(0, 0, width, height); | |
233 | ||
234 | redraw(); | |
235 | } | |
d626bc9b | 236 | } |
4e6626a9 | 237 | |
d626bc9b MS |
238 | } |
239 | ||
240 | class UIMapping extends UIWindow { | |
241 | ||
242 | private static final String MAP_MODE_ALL = "ALL"; | |
243 | private static final String MAP_MODE_CHANNEL = "CHNL"; | |
244 | private static final String MAP_MODE_CUBE = "CUBE"; | |
245 | ||
246 | private static final String CUBE_MODE_ALL = "ALL"; | |
247 | private static final String CUBE_MODE_STRIP = "SNGL"; | |
248 | private static final String CUBE_MODE_PATTERN = "PTRN"; | |
249 | ||
250 | private final MappingTool mappingTool; | |
251 | ||
252 | private final UIIntegerBox channelBox; | |
253 | private final UIIntegerBox cubeBox; | |
254 | private final UIIntegerBox stripBox; | |
255 | ||
256 | UIMapping(MappingTool tool, float x, float y, float w, float h) { | |
4e6626a9 | 257 | super(lx.ui, "MAPPING", x, y, w, h); |
d626bc9b MS |
258 | mappingTool = tool; |
259 | ||
4e6626a9 | 260 | int yp = UIWindow.TITLE_LABEL_HEIGHT; |
78a44a1b | 261 | new UIToggleSet(4, yp, w-10, 20) { |
d626bc9b MS |
262 | protected void onToggle(String value) { |
263 | if (value == MAP_MODE_ALL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_ALL; | |
264 | else if (value == MAP_MODE_CHANNEL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_CHANNEL; | |
265 | else if (value == MAP_MODE_CUBE) mappingTool.mappingMode = mappingTool.MAPPING_MODE_SINGLE_CUBE; | |
266 | } | |
267 | }.setOptions(new String[] { MAP_MODE_ALL, MAP_MODE_CHANNEL, MAP_MODE_CUBE }).addToContainer(this); | |
268 | yp += 24; | |
78a44a1b | 269 | new UILabel(4, yp+8, w-10, 20).setLabel("CHANNEL ID").addToContainer(this); |
d626bc9b | 270 | yp += 24; |
78a44a1b | 271 | (channelBox = new UIIntegerBox(4, yp, w-10, 20) { |
d626bc9b MS |
272 | protected void onValueChange(int value) { |
273 | mappingTool.setChannel(value-1); | |
274 | } | |
275 | }).setRange(1, mappingTool.numChannels()).addToContainer(this); | |
276 | yp += 24; | |
277 | ||
78a44a1b | 278 | new UILabel(4, yp+8, w-10, 20).setLabel("CUBE ID").addToContainer(this); |
d626bc9b | 279 | yp += 24; |
78a44a1b | 280 | (cubeBox = new UIIntegerBox(4, yp, w-10, 20) { |
d626bc9b MS |
281 | protected void onValueChange(int value) { |
282 | mappingTool.setCube(value-1); | |
283 | } | |
284 | }).setRange(1, glucose.model.cubes.size()).addToContainer(this); | |
285 | yp += 24; | |
286 | ||
a8d55ade MS |
287 | yp += 10; |
288 | ||
4e6626a9 | 289 | new UIScrollList(1, yp, w-2, 60).setItems(Arrays.asList(new UIScrollList.Item[] { |
d626bc9b MS |
290 | new ColorScrollItem(ColorScrollItem.COLOR_RED), |
291 | new ColorScrollItem(ColorScrollItem.COLOR_GREEN), | |
292 | new ColorScrollItem(ColorScrollItem.COLOR_BLUE), | |
293 | })).addToContainer(this); | |
294 | yp += 64; | |
295 | ||
78a44a1b | 296 | new UILabel(4, yp+8, w-10, 20).setLabel("STRIP MODE").addToContainer(this); |
d626bc9b MS |
297 | yp += 24; |
298 | ||
78a44a1b | 299 | new UIToggleSet(4, yp, w-10, 20) { |
d626bc9b MS |
300 | protected void onToggle(String value) { |
301 | if (value == CUBE_MODE_ALL) mappingTool.cubeMode = mappingTool.CUBE_MODE_ALL; | |
302 | else if (value == CUBE_MODE_STRIP) mappingTool.cubeMode = mappingTool.CUBE_MODE_SINGLE_STRIP; | |
303 | else if (value == CUBE_MODE_PATTERN) mappingTool.cubeMode = mappingTool.CUBE_MODE_STRIP_PATTERN; | |
304 | } | |
305 | }.setOptions(new String[] { CUBE_MODE_ALL, CUBE_MODE_STRIP, CUBE_MODE_PATTERN }).addToContainer(this); | |
306 | ||
307 | yp += 24; | |
78a44a1b | 308 | new UILabel(4, yp+8, w-10, 20).setLabel("STRIP ID").addToContainer(this); |
d626bc9b MS |
309 | |
310 | yp += 24; | |
78a44a1b | 311 | (stripBox = new UIIntegerBox(4, yp, w-10, 20) { |
d626bc9b MS |
312 | protected void onValueChange(int value) { |
313 | mappingTool.setStrip(value-1); | |
314 | } | |
315 | }).setRange(1, Cube.STRIPS_PER_CUBE).addToContainer(this); | |
316 | ||
317 | } | |
318 | ||
319 | public void setChannelID(int value) { | |
320 | channelBox.setValue(value); | |
321 | } | |
322 | ||
323 | public void setCubeID(int value) { | |
324 | cubeBox.setValue(value); | |
325 | } | |
326 | ||
327 | public void setStripID(int value) { | |
328 | stripBox.setValue(value); | |
329 | } | |
330 | ||
4e6626a9 | 331 | class ColorScrollItem extends UIScrollList.AbstractItem { |
d626bc9b MS |
332 | |
333 | public static final int COLOR_RED = 1; | |
334 | public static final int COLOR_GREEN = 2; | |
335 | public static final int COLOR_BLUE = 3; | |
336 | ||
337 | private final int colorChannel; | |
338 | ||
339 | ColorScrollItem(int colorChannel) { | |
340 | this.colorChannel = colorChannel; | |
341 | } | |
342 | ||
343 | public String getLabel() { | |
344 | switch (colorChannel) { | |
345 | case COLOR_RED: return "Red"; | |
346 | case COLOR_GREEN: return "Green"; | |
347 | case COLOR_BLUE: return "Blue"; | |
348 | } | |
349 | return ""; | |
350 | } | |
351 | ||
352 | public boolean isSelected() { | |
353 | switch (colorChannel) { | |
354 | case COLOR_RED: return mappingTool.channelModeRed; | |
355 | case COLOR_GREEN: return mappingTool.channelModeGreen; | |
356 | case COLOR_BLUE: return mappingTool.channelModeBlue; | |
357 | } | |
358 | return false; | |
359 | } | |
360 | ||
a8d55ade | 361 | public void onMousePressed() { |
d626bc9b MS |
362 | switch (colorChannel) { |
363 | case COLOR_RED: mappingTool.channelModeRed = !mappingTool.channelModeRed; break; | |
364 | case COLOR_GREEN: mappingTool.channelModeGreen = !mappingTool.channelModeGreen; break; | |
365 | case COLOR_BLUE: mappingTool.channelModeBlue = !mappingTool.channelModeBlue; break; | |
366 | } | |
367 | } | |
368 | } | |
369 | } | |
370 | ||
371 | class UIDebugText extends UIContext { | |
372 | ||
373 | private String line1 = ""; | |
374 | private String line2 = ""; | |
375 | ||
376 | UIDebugText(float x, float y, float w, float h) { | |
4e6626a9 | 377 | super(lx.ui, x, y, w, h); |
d626bc9b MS |
378 | } |
379 | ||
380 | public UIDebugText setText(String line1) { | |
381 | return setText(line1, ""); | |
382 | } | |
383 | ||
384 | public UIDebugText setText(String line1, String line2) { | |
385 | if (!line1.equals(this.line1) || !line2.equals(this.line2)) { | |
386 | this.line1 = line1; | |
387 | this.line2 = line2; | |
388 | setVisible(line1.length() + line2.length() > 0); | |
389 | redraw(); | |
390 | } | |
391 | return this; | |
392 | } | |
393 | ||
4e6626a9 MS |
394 | protected void onDraw(UI ui, PGraphics pg) { |
395 | super.onDraw(ui, pg); | |
d626bc9b MS |
396 | if (line1.length() + line2.length() > 0) { |
397 | pg.noStroke(); | |
398 | pg.fill(#444444); | |
4e6626a9 MS |
399 | pg.rect(0, 0, width, height); |
400 | pg.textFont(ui.getItemFont()); | |
a8d55ade | 401 | pg.textSize(10); |
d626bc9b MS |
402 | pg.textAlign(LEFT, TOP); |
403 | pg.fill(#cccccc); | |
404 | pg.text(line1, 4, 4); | |
405 | pg.text(line2, 4, 24); | |
406 | } | |
407 | } | |
408 | } | |
409 | ||
34327c96 | 410 | class UISpeed extends UIWindow { |
fa4f822d MS |
411 | |
412 | final BasicParameter speed; | |
413 | ||
34327c96 | 414 | UISpeed(float x, float y, float w, float h) { |
4e6626a9 | 415 | super(lx.ui, "SPEED", x, y, w, h); |
fa4f822d | 416 | speed = new BasicParameter("SPEED", 0.5); |
4e6626a9 | 417 | speed.addListener(new LXParameterListener() { |
34327c96 MS |
418 | public void onParameterChanged(LXParameter parameter) { |
419 | lx.setSpeed(parameter.getValuef() * 2); | |
420 | } | |
4e6626a9 MS |
421 | }); |
422 | new UISlider(4, UIWindow.TITLE_LABEL_HEIGHT, w-10, 20).setParameter(speed).addToContainer(this); | |
34327c96 MS |
423 | } |
424 | } | |
425 | ||
a8d55ade MS |
426 | class UIMidi extends UIWindow { |
427 | ||
9692dc7b MS |
428 | private final UIToggleSet deckMode; |
429 | private final UIButton logMode; | |
a8d55ade | 430 | |
d6ac1ee8 | 431 | UIMidi(final MidiEngine midiEngine, float x, float y, float w, float h) { |
4e6626a9 | 432 | super(lx.ui, "MIDI", x, y, w, h); |
d6ac1ee8 | 433 | |
a8d55ade | 434 | // Processing compiler doesn't seem to get that list of class objects also conform to interface |
4e6626a9 | 435 | List<UIScrollList.Item> scrollItems = new ArrayList<UIScrollList.Item>(); |
d6ac1ee8 | 436 | for (SCMidiInput mc : midiEngine.getControllers()) { |
30bf6510 | 437 | scrollItems.add(mc); |
a8d55ade | 438 | } |
30bf6510 | 439 | final UIScrollList scrollList; |
4e6626a9 | 440 | (scrollList = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 100)).setItems(scrollItems).addToContainer(this); |
d6ac1ee8 MS |
441 | (deckMode = new UIToggleSet(4, 130, 90, 20) { |
442 | protected void onToggle(String value) { | |
443 | midiEngine.setFocusedDeck(value == "A" ? 0 : 1); | |
444 | } | |
445 | }).setOptions(new String[] { "A", "B" }).addToContainer(this); | |
4df91daf | 446 | (logMode = new UIButton(98, 130, w-103, 20)).setLabel("LOG").addToContainer(this); |
30bf6510 MS |
447 | |
448 | SCMidiInputListener listener = new SCMidiInputListener() { | |
449 | public void onEnabled(SCMidiInput controller, boolean enabled) { | |
450 | scrollList.redraw(); | |
451 | } | |
452 | }; | |
d6ac1ee8 | 453 | for (SCMidiInput mc : midiEngine.getControllers()) { |
30bf6510 MS |
454 | mc.addListener(listener); |
455 | } | |
d6ac1ee8 MS |
456 | |
457 | midiEngine.addListener(new MidiEngineListener() { | |
458 | public void onFocusedDeck(int deckIndex) { | |
459 | deckMode.setValue(deckIndex == 0 ? "A" : "B"); | |
460 | } | |
461 | }); | |
30bf6510 | 462 | |
9692dc7b MS |
463 | } |
464 | ||
465 | public boolean logMidi() { | |
466 | return logMode.isActive(); | |
a8d55ade MS |
467 | } |
468 | ||
42a424d7 MS |
469 | public LXDeck getFocusedDeck() { |
470 | return lx.engine.getDeck(deckMode.getValue() == "A" ? GLucose.LEFT_DECK : GLucose.RIGHT_DECK); | |
a8d55ade MS |
471 | } |
472 | } | |
473 | ||
d626bc9b MS |
474 | String className(Object p, String suffix) { |
475 | String s = p.getClass().getName(); | |
476 | int li; | |
477 | if ((li = s.lastIndexOf(".")) > 0) { | |
478 | s = s.substring(li + 1); | |
479 | } | |
480 | if (s.indexOf("SugarCubes$") == 0) { | |
481 | s = s.substring("SugarCubes$".length()); | |
482 | } | |
483 | if ((suffix != null) && ((li = s.indexOf(suffix)) != -1)) { | |
484 | s = s.substring(0, li); | |
485 | } | |
486 | return s; | |
487 | } |