forked from visigoth/SugarCubes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_UIImplementation.pde
551 lines (449 loc) · 15.8 KB
/
_UIImplementation.pde
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
/**
* DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
*
* //\\ //\\ //\\ //\\
* ///\\\ ///\\\ ///\\\ ///\\\
* \\\/// \\\/// \\\/// \\\///
* \\// \\// \\// \\//
*
* EXPERTS ONLY!! EXPERTS ONLY!!
*
* Custom UI components using the framework.
*/
class UIPatternDeck extends UIWindow {
LXDeck deck;
public UIPatternDeck(LXDeck deck, String label, float x, float y, float w, float h) {
super(label, x, y, w, h);
this.deck = deck;
int yp = titleHeight;
List<ScrollItem> items = new ArrayList<ScrollItem>();
for (LXPattern p : deck.getPatterns()) {
items.add(new PatternScrollItem(p));
}
final UIScrollList patternList = new UIScrollList(1, yp, w-2, 140).setItems(items);
patternList.addToContainer(this);
yp += patternList.h + 10;
final UIParameterKnob[] parameterKnobs = new UIParameterKnob[12];
for (int ki = 0; ki < parameterKnobs.length; ++ki) {
parameterKnobs[ki] = new UIParameterKnob(5 + 34*(ki % 4), yp + (ki/4) * 48);
parameterKnobs[ki].addToContainer(this);
}
LXDeck.Listener lxListener = new LXDeck.AbstractListener() {
public void patternWillChange(LXDeck deck, LXPattern pattern, LXPattern nextPattern) {
patternList.redraw();
}
public void patternDidChange(LXDeck deck, LXPattern pattern) {
patternList.redraw();
int pi = 0;
for (LXParameter parameter : pattern.getParameters()) {
if (pi >= parameterKnobs.length) {
break;
}
parameterKnobs[pi++].setParameter(parameter);
}
while (pi < parameterKnobs.length) {
parameterKnobs[pi++].setParameter(null);
}
}
};
deck.addListener(lxListener);
lxListener.patternDidChange(deck, deck.getActivePattern());
}
class PatternScrollItem extends AbstractScrollItem {
private LXPattern pattern;
private String label;
PatternScrollItem(LXPattern pattern) {
this.pattern = pattern;
label = className(pattern, "Pattern");
}
public String getLabel() {
return label;
}
public boolean isSelected() {
return deck.getActivePattern() == pattern;
}
public boolean isPending() {
return deck.getNextPattern() == pattern;
}
public void onMousePressed() {
deck.goPattern(pattern);
}
}
}
class UIBlendMode extends UIWindow {
public UIBlendMode(float x, float y, float w, float h) {
super("BLEND MODE", x, y, w, h);
List<ScrollItem> items = new ArrayList<ScrollItem>();
for (LXTransition t : glucose.getTransitions()) {
items.add(new TransitionScrollItem(t));
}
final UIScrollList tList;
(tList = new UIScrollList(1, titleHeight, w-2, 60)).setItems(items).addToContainer(this);
lx.engine.getDeck(GLucose.RIGHT_DECK).addListener(new LXDeck.AbstractListener() {
public void faderTransitionDidChange(LXDeck deck, LXTransition transition) {
tList.redraw();
}
});
}
class TransitionScrollItem extends AbstractScrollItem {
private final LXTransition transition;
private String label;
TransitionScrollItem(LXTransition transition) {
this.transition = transition;
label = className(transition, "Transition");
}
public String getLabel() {
return label;
}
public boolean isSelected() {
return transition == glucose.getSelectedTransition();
}
public boolean isPending() {
return false;
}
public void onMousePressed() {
glucose.setSelectedTransition(transition);
}
}
}
class UICrossfader extends UIWindow {
private final UIToggleSet displayMode;
public UICrossfader(float x, float y, float w, float h) {
super("CROSSFADER", x, y, w, h);
new UIParameterSlider(4, titleHeight, w-9, 32).setParameter(lx.engine.getDeck(GLucose.RIGHT_DECK).getFader()).addToContainer(this);
(displayMode = new UIToggleSet(4, titleHeight + 36, w-9, 20)).setOptions(new String[] { "A", "COMP", "B" }).setValue("COMP").addToContainer(this);
}
public UICrossfader setDisplayMode(String value) {
displayMode.setValue(value);
return this;
}
public String getDisplayMode() {
return displayMode.getValue();
}
}
class UIEffects extends UIWindow {
UIEffects(float x, float y, float w, float h) {
super("FX", x, y, w, h);
int yp = titleHeight;
List<ScrollItem> items = new ArrayList<ScrollItem>();
for (LXEffect fx : glucose.lx.getEffects()) {
items.add(new FXScrollItem(fx));
}
final UIScrollList effectsList = new UIScrollList(1, yp, w-2, 60).setItems(items);
effectsList.addToContainer(this);
yp += effectsList.h + 10;
final UIParameterKnob[] parameterKnobs = new UIParameterKnob[4];
for (int ki = 0; ki < parameterKnobs.length; ++ki) {
parameterKnobs[ki] = new UIParameterKnob(5 + 34*(ki % 4), yp + (ki/4) * 48);
parameterKnobs[ki].addToContainer(this);
}
GLucose.EffectListener fxListener = new GLucose.EffectListener() {
public void effectSelected(LXEffect effect) {
int i = 0;
for (LXParameter p : effect.getParameters()) {
if (i >= parameterKnobs.length) {
break;
}
parameterKnobs[i++].setParameter(p);
}
while (i < parameterKnobs.length) {
parameterKnobs[i++].setParameter(null);
}
}
};
glucose.addEffectListener(fxListener);
fxListener.effectSelected(glucose.getSelectedEffect());
}
class FXScrollItem extends AbstractScrollItem {
private LXEffect effect;
private String label;
FXScrollItem(LXEffect effect) {
this.effect = effect;
label = className(effect, "Effect");
}
public String getLabel() {
return label;
}
public boolean isSelected() {
return !effect.isEnabled() && (glucose.getSelectedEffect() == effect);
}
public boolean isPending() {
return effect.isEnabled();
}
public void onMousePressed() {
if (glucose.getSelectedEffect() == effect) {
if (effect.isMomentary()) {
effect.enable();
} else {
effect.toggle();
}
} else {
glucose.setSelectedEffect(effect);
}
}
public void onMouseReleased() {
if (effect.isMomentary()) {
effect.disable();
}
}
}
}
class UIOutput extends UIWindow {
public UIOutput(float x, float y, float w, float h) {
super("OUTPUT", x, y, w, h);
float yp = titleHeight;
final UIScrollList outputs = new UIScrollList(1, titleHeight, w-2, 80);
List<ScrollItem> items = new ArrayList<ScrollItem>();
for (final PandaDriver panda : pandaBoards) {
items.add(new PandaScrollItem(panda));
panda.setListener(new PandaDriver.Listener() {
public void onToggle(boolean active) {
outputs.redraw();
}
});
}
outputs.setItems(items).addToContainer(this);
}
class PandaScrollItem extends AbstractScrollItem {
final PandaDriver panda;
PandaScrollItem(PandaDriver panda) {
this.panda = panda;
}
public String getLabel() {
return panda.ip;
}
public boolean isSelected() {
return panda.isEnabled();
}
public void onMousePressed() {
panda.toggle();
}
}
}
class UITempo extends UIWindow {
private final UIButton tempoButton;
UITempo(float x, float y, float w, float h) {
super("TEMPO", x, y, w, h);
tempoButton = new UIButton(4, titleHeight, w-10, 20) {
protected void onToggle(boolean active) {
if (active) {
lx.tempo.tap();
}
}
}.setMomentary(true);
tempoButton.addToContainer(this);
}
public void draw() {
tempoButton.setLabel("" + ((int)(lx.tempo.bpm() * 10)) / 10.);
super.draw();
// Overlay tempo thing with openGL, redraw faster than button UI
fill(color(0, 0, 24 - 8*lx.tempo.rampf()));
noStroke();
rect(x + 8, y + titleHeight + 5, 12, 12);
}
}
class UIMapping extends UIWindow {
private static final String MAP_MODE_ALL = "ALL";
private static final String MAP_MODE_CHANNEL = "CHNL";
private static final String MAP_MODE_CUBE = "CUBE";
private static final String CUBE_MODE_ALL = "ALL";
private static final String CUBE_MODE_STRIP = "SNGL";
private static final String CUBE_MODE_PATTERN = "PTRN";
private final MappingTool mappingTool;
private final UIIntegerBox channelBox;
private final UIIntegerBox cubeBox;
private final UIIntegerBox stripBox;
UIMapping(MappingTool tool, float x, float y, float w, float h) {
super("MAPPING", x, y, w, h);
mappingTool = tool;
int yp = titleHeight;
new UIToggleSet(4, yp, w-10, 20) {
protected void onToggle(String value) {
if (value == MAP_MODE_ALL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_ALL;
else if (value == MAP_MODE_CHANNEL) mappingTool.mappingMode = mappingTool.MAPPING_MODE_CHANNEL;
else if (value == MAP_MODE_CUBE) mappingTool.mappingMode = mappingTool.MAPPING_MODE_SINGLE_CUBE;
}
}.setOptions(new String[] { MAP_MODE_ALL, MAP_MODE_CHANNEL, MAP_MODE_CUBE }).addToContainer(this);
yp += 24;
new UILabel(4, yp+8, w-10, 20).setLabel("CHANNEL ID").addToContainer(this);
yp += 24;
(channelBox = new UIIntegerBox(4, yp, w-10, 20) {
protected void onValueChange(int value) {
mappingTool.setChannel(value-1);
}
}).setRange(1, mappingTool.numChannels()).addToContainer(this);
yp += 24;
new UILabel(4, yp+8, w-10, 20).setLabel("CUBE ID").addToContainer(this);
yp += 24;
(cubeBox = new UIIntegerBox(4, yp, w-10, 20) {
protected void onValueChange(int value) {
mappingTool.setCube(value-1);
}
}).setRange(1, glucose.model.cubes.size()).addToContainer(this);
yp += 24;
yp += 10;
new UIScrollList(1, yp, w-2, 60).setItems(Arrays.asList(new ScrollItem[] {
new ColorScrollItem(ColorScrollItem.COLOR_RED),
new ColorScrollItem(ColorScrollItem.COLOR_GREEN),
new ColorScrollItem(ColorScrollItem.COLOR_BLUE),
})).addToContainer(this);
yp += 64;
new UILabel(4, yp+8, w-10, 20).setLabel("STRIP MODE").addToContainer(this);
yp += 24;
new UIToggleSet(4, yp, w-10, 20) {
protected void onToggle(String value) {
if (value == CUBE_MODE_ALL) mappingTool.cubeMode = mappingTool.CUBE_MODE_ALL;
else if (value == CUBE_MODE_STRIP) mappingTool.cubeMode = mappingTool.CUBE_MODE_SINGLE_STRIP;
else if (value == CUBE_MODE_PATTERN) mappingTool.cubeMode = mappingTool.CUBE_MODE_STRIP_PATTERN;
}
}.setOptions(new String[] { CUBE_MODE_ALL, CUBE_MODE_STRIP, CUBE_MODE_PATTERN }).addToContainer(this);
yp += 24;
new UILabel(4, yp+8, w-10, 20).setLabel("STRIP ID").addToContainer(this);
yp += 24;
(stripBox = new UIIntegerBox(4, yp, w-10, 20) {
protected void onValueChange(int value) {
mappingTool.setStrip(value-1);
}
}).setRange(1, Cube.STRIPS_PER_CUBE).addToContainer(this);
}
public void setChannelID(int value) {
channelBox.setValue(value);
}
public void setCubeID(int value) {
cubeBox.setValue(value);
}
public void setStripID(int value) {
stripBox.setValue(value);
}
class ColorScrollItem extends AbstractScrollItem {
public static final int COLOR_RED = 1;
public static final int COLOR_GREEN = 2;
public static final int COLOR_BLUE = 3;
private final int colorChannel;
ColorScrollItem(int colorChannel) {
this.colorChannel = colorChannel;
}
public String getLabel() {
switch (colorChannel) {
case COLOR_RED: return "Red";
case COLOR_GREEN: return "Green";
case COLOR_BLUE: return "Blue";
}
return "";
}
public boolean isSelected() {
switch (colorChannel) {
case COLOR_RED: return mappingTool.channelModeRed;
case COLOR_GREEN: return mappingTool.channelModeGreen;
case COLOR_BLUE: return mappingTool.channelModeBlue;
}
return false;
}
public void onMousePressed() {
switch (colorChannel) {
case COLOR_RED: mappingTool.channelModeRed = !mappingTool.channelModeRed; break;
case COLOR_GREEN: mappingTool.channelModeGreen = !mappingTool.channelModeGreen; break;
case COLOR_BLUE: mappingTool.channelModeBlue = !mappingTool.channelModeBlue; break;
}
}
}
}
class UIDebugText extends UIContext {
private String line1 = "";
private String line2 = "";
UIDebugText(float x, float y, float w, float h) {
super(x, y, w, h);
}
public UIDebugText setText(String line1) {
return setText(line1, "");
}
public UIDebugText setText(String line1, String line2) {
if (!line1.equals(this.line1) || !line2.equals(this.line2)) {
this.line1 = line1;
this.line2 = line2;
setVisible(line1.length() + line2.length() > 0);
redraw();
}
return this;
}
protected void onDraw(PGraphics pg) {
super.onDraw(pg);
if (line1.length() + line2.length() > 0) {
pg.noStroke();
pg.fill(#444444);
pg.rect(0, 0, w, h);
pg.textFont(defaultItemFont);
pg.textSize(10);
pg.textAlign(LEFT, TOP);
pg.fill(#cccccc);
pg.text(line1, 4, 4);
pg.text(line2, 4, 24);
}
}
}
class UISpeed extends UIWindow {
final BasicParameter speed;
UISpeed(float x, float y, float w, float h) {
super("SPEED", x, y, w, h);
speed = new BasicParameter("SPEED", 0.5);
new UIParameterSlider(4, titleHeight, w-10, 20)
.setParameter(speed.addListener(new LXParameterListener() {
public void onParameterChanged(LXParameter parameter) {
lx.setSpeed(parameter.getValuef() * 2);
}
})).addToContainer(this);
}
}
class UIMidi extends UIWindow {
private final UIToggleSet deckMode;
private final UIButton logMode;
UIMidi(final MidiEngine midiEngine, float x, float y, float w, float h) {
super("MIDI", x, y, w, h);
// Processing compiler doesn't seem to get that list of class objects also conform to interface
List<ScrollItem> scrollItems = new ArrayList<ScrollItem>();
for (SCMidiInput mc : midiEngine.getControllers()) {
scrollItems.add(mc);
}
final UIScrollList scrollList;
(scrollList = new UIScrollList(1, titleHeight, w-2, 100)).setItems(scrollItems).addToContainer(this);
(deckMode = new UIToggleSet(4, 130, 90, 20) {
protected void onToggle(String value) {
midiEngine.setFocusedDeck(value == "A" ? 0 : 1);
}
}).setOptions(new String[] { "A", "B" }).addToContainer(this);
(logMode = new UIButton(98, 130, w-103, 20)).setLabel("LOG").addToContainer(this);
SCMidiInputListener listener = new SCMidiInputListener() {
public void onEnabled(SCMidiInput controller, boolean enabled) {
scrollList.redraw();
}
};
for (SCMidiInput mc : midiEngine.getControllers()) {
mc.addListener(listener);
}
midiEngine.addListener(new MidiEngineListener() {
public void onFocusedDeck(int deckIndex) {
deckMode.setValue(deckIndex == 0 ? "A" : "B");
}
});
}
public boolean logMidi() {
return logMode.isActive();
}
public LXDeck getFocusedDeck() {
return lx.engine.getDeck(deckMode.getValue() == "A" ? GLucose.LEFT_DECK : GLucose.RIGHT_DECK);
}
}
String className(Object p, String suffix) {
String s = p.getClass().getName();
int li;
if ((li = s.lastIndexOf(".")) > 0) {
s = s.substring(li + 1);
}
if (s.indexOf("SugarCubes$") == 0) {
s = s.substring("SugarCubes$".length());
}
if ((suffix != null) && ((li = s.indexOf(suffix)) != -1)) {
s = s.substring(0, li);
}
return s;
}