2 * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
5 * ///\\\ ///\\\ ///\\\ ///\\\
6 * \\\/// \\\/// \\\/// \\\///
9 * EXPERTS ONLY!! EXPERTS ONLY!!
11 * Overlay UI that indicates pattern control, etc. This will be moved
12 * into the Processing library once it is stabilized and need not be
17 private final PFont titleFont = createFont("Myriad Pro", 10);
18 private final PFont itemFont = createFont("Lucida Grande", 11);
19 private final PFont knobFont = titleFont;
20 private final int w = 140;
21 private final int leftPos;
22 private final int leftTextPos;
23 private final int lineHeight = 20;
24 private final int sectionSpacing = 12;
25 private final int controlSpacing = 18;
26 private final int tempoHeight = 20;
27 private final int knobSize = 28;
28 private final float knobIndent = .4;
29 private final int knobSpacing = 6;
30 private final int knobLabelHeight = 14;
31 private final color lightBlue = #666699;
32 private final color lightGreen = #669966;
34 private final String[] patternNames;
35 private final String[] transitionNames;
36 private final String[] effectNames;
40 private int firstPatternY;
41 private int firstPatternKnobY;
42 private int firstTransitionY;
43 private int firstTransitionKnobY;
44 private int firstEffectY;
45 private int firstEffectKnobY;
49 private Method patternStateMethod;
50 private Method transitionStateMethod;
51 private Method effectStateMethod;
53 private final int NUM_PATTERN_KNOBS = 8;
54 private final int NUM_TRANSITION_KNOBS = 4;
55 private final int NUM_EFFECT_KNOBS = 4;
57 private int activeTransitionIndex = 0;
58 private int activeEffectIndex = 0;
60 public final VirtualPatternKnob[] patternKnobs;
61 public final VirtualTransitionKnob[] transitionKnobs;
62 public final VirtualEffectKnob[] effectKnobs;
66 leftTextPos = leftPos + 4;
67 logo = loadImage("logo-sm.png");
69 patternNames = classNameArray(patterns, "Pattern");
70 transitionNames = classNameArray(transitions, "Transition");
71 effectNames = classNameArray(effects, "Effect");
73 patternKnobs = new VirtualPatternKnob[NUM_PATTERN_KNOBS];
74 for (int i = 0; i < patternKnobs.length; ++i) {
75 patternKnobs[i] = new VirtualPatternKnob(i);
78 transitionKnobs = new VirtualTransitionKnob[NUM_TRANSITION_KNOBS];
79 for (int i = 0; i < transitionKnobs.length; ++i) {
80 transitionKnobs[i] = new VirtualTransitionKnob(i);
83 effectKnobs = new VirtualEffectKnob[NUM_EFFECT_KNOBS];
84 for (int i = 0; i < effectKnobs.length; ++i) {
85 effectKnobs[i] = new VirtualEffectKnob(i);
89 patternStateMethod = getClass().getMethod("getState", LXPattern.class);
90 effectStateMethod = getClass().getMethod("getState", LXEffect.class);
91 transitionStateMethod = getClass().getMethod("getState", LXTransition.class);
92 } catch (Exception x) {
93 throw new RuntimeException(x);
100 text("Tap 'u' to restore UI", width-4, height-6);
106 stroke(color(0, 0, 100));
107 // fill(color(0, 0, 50, 50)); // alpha is bad for perf
108 fill(color(0, 0, 30));
109 rect(leftPos-1, -1, w+2, height+2);
112 firstPatternY = yPos + lineHeight + 6;
113 yPos = drawObjectList(yPos, "PATTERN", patterns, patternNames, patternStateMethod);
114 yPos += controlSpacing;
115 firstPatternKnobY = yPos;
116 int xPos = leftTextPos;
117 for (int i = 0; i < NUM_PATTERN_KNOBS/2; ++i) {
118 drawKnob(xPos, yPos, knobSize, patternKnobs[i]);
119 drawKnob(xPos, yPos + knobSize + knobSpacing + knobLabelHeight, knobSize, patternKnobs[NUM_PATTERN_KNOBS/2 + i]);
120 xPos += knobSize + knobSpacing;
122 yPos += 2*(knobSize + knobLabelHeight) + knobSpacing;
124 yPos += sectionSpacing;
125 firstTransitionY = yPos + lineHeight + 6;
126 yPos = drawObjectList(yPos, "TRANSITION", transitions, transitionNames, transitionStateMethod);
127 yPos += controlSpacing;
128 firstTransitionKnobY = yPos;
130 for (int i = 0; i < transitionKnobs.length; ++i) {
131 drawKnob(xPos, yPos, knobSize, transitionKnobs[i]);
132 xPos += knobSize + knobSpacing;
134 yPos += knobSize + knobLabelHeight;
136 yPos += sectionSpacing;
137 firstEffectY = yPos + lineHeight + 6;
138 yPos = drawObjectList(yPos, "FX", effects, effectNames, effectStateMethod);
139 yPos += controlSpacing;
140 firstEffectKnobY = yPos;
142 for (int i = 0; i < effectKnobs.length; ++i) {
143 drawKnob(xPos, yPos, knobSize, effectKnobs[i]);
144 xPos += knobSize + knobSpacing;
146 yPos += knobSize + knobLabelHeight;
148 yPos += sectionSpacing;
149 yPos = drawObjectList(yPos, "TEMPO", null, null, null);
153 fill(tempoDown ? lightGreen : color(0, 0, 35 - 8*lx.tempo.rampf()));
154 rect(leftPos + 4, yPos, w - 8, tempoHeight);
157 text("" + ((int)(lx.tempo.bpmf() * 100) / 100.), leftPos + w/2., yPos + tempoHeight - 6);
163 text("Tap 'u' to hide UI", leftTextPos, height-6);
166 public LXParameter getOrNull(List<LXParameter> items, int index) {
167 if (index < items.size()) {
168 return items.get(index);
173 public void drawFPS() {
177 text("FPS: " + (((int)(frameRate * 10)) / 10.), 4, height-6);
180 private final int STATE_DEFAULT = 0;
181 private final int STATE_ACTIVE = 1;
182 private final int STATE_PENDING = 2;
184 public int getState(LXPattern p) {
185 if (p == lx.getPattern()) {
187 } else if (p == lx.getNextPattern()) {
188 return STATE_PENDING;
190 return STATE_DEFAULT;
193 public int getState(LXEffect e) {
195 return STATE_PENDING;
196 } else if (effects[activeEffectIndex] == e) {
199 return STATE_DEFAULT;
202 public int getState(LXTransition t) {
203 if (t == lx.getTransition()) {
204 return STATE_PENDING;
205 } else if (t == transitions[activeTransitionIndex]) {
208 return STATE_DEFAULT;
211 protected int drawObjectList(int yPos, String title, Object[] items, Method stateMethod) {
212 return drawObjectList(yPos, title, items, classNameArray(items, null), stateMethod);
215 private int drawObjectList(int yPos, String title, Object[] items, String[] names, Method stateMethod) {
220 text(title, leftTextPos, yPos += lineHeight);
225 for (int i = 0; i < items.length; ++i) {
227 int state = STATE_DEFAULT;
229 state = ((Integer) stateMethod.invoke(this, o)).intValue();
230 } catch (Exception x) {
231 throw new RuntimeException(x);
240 textColor = color(0, 0, 75 + 15*sin(millis()/200.));;
244 fill(even ? #666666 : #777777);
247 rect(leftPos, yPos+6, width, lineHeight);
249 text(names[i], leftTextPos, yPos += lineHeight);
256 private void drawKnob(int xPos, int yPos, int knobSize, LXParameter knob) {
260 final float knobValue = knob.getValuef();
261 String knobLabel = knob.getLabel();
262 if (knobLabel == null) {
264 } else if (knobLabel.length() > 4) {
265 knobLabel = knobLabel.substring(0, 4);
271 // For some reason this arc call really crushes drawing performance. Presumably
272 // because openGL is drawing it and when we overlap the second set of arcs it
273 // does a bunch of depth buffer intersection tests? Ellipse with a trapezoid cut out is faster
274 // arc(xPos + knobSize/2, yPos + knobSize/2, knobSize, knobSize, HALF_PI + knobIndent, HALF_PI + knobIndent + (TWO_PI-2*knobIndent));
275 ellipse(xPos + knobSize/2, yPos + knobSize/2, knobSize, knobSize);
277 float endArc = HALF_PI + knobIndent + (TWO_PI-2*knobIndent)*knobValue;
279 arc(xPos + knobSize/2, yPos + knobSize/2, knobSize, knobSize, HALF_PI + knobIndent, endArc);
281 // Mask notch out of knob
282 fill(color(0, 0, 30));
284 vertex(xPos + knobSize/2, yPos + knobSize/2.);
285 vertex(xPos + knobSize/2 - 6, yPos + knobSize);
286 vertex(xPos + knobSize/2 + 6, yPos + knobSize);
289 // Center circle of knob
291 ellipse(xPos + knobSize/2, yPos + knobSize/2, knobSize/2, knobSize/2);
294 rect(xPos, yPos + knobSize + 2, knobSize, knobLabelHeight - 2);
298 text(knobLabel, xPos + knobSize/2, yPos + knobSize + knobLabelHeight - 2);
302 private String[] classNameArray(Object[] objects, String suffix) {
303 if (objects == null) {
306 String[] names = new String[objects.length];
307 for (int i = 0; i < objects.length; ++i) {
308 names[i] = className(objects[i], suffix);
313 private String className(Object p, String suffix) {
314 String s = p.getClass().getName();
316 if ((li = s.lastIndexOf(".")) > 0) {
317 s = s.substring(li + 1);
319 if (s.indexOf("SugarCubes$") == 0) {
320 s = s.substring("SugarCubes$".length());
322 if ((suffix != null) && ((li = s.indexOf(suffix)) != -1)) {
323 s = s.substring(0, li);
328 class VirtualPatternKnob extends LXVirtualParameter {
329 private final int index;
331 VirtualPatternKnob(int index) {
335 public LXParameter getRealParameter() {
336 List<LXParameter> parameters = glucose.getPattern().getParameters();
337 if (index < parameters.size()) {
338 return parameters.get(index);
344 class VirtualTransitionKnob extends LXVirtualParameter {
345 private final int index;
347 VirtualTransitionKnob(int index) {
351 public LXParameter getRealParameter() {
352 List<LXParameter> parameters = transitions[activeTransitionIndex].getParameters();
353 if (index < parameters.size()) {
354 return parameters.get(index);
360 class VirtualEffectKnob extends LXVirtualParameter {
361 private final int index;
363 VirtualEffectKnob(int index) {
367 public LXParameter getRealParameter() {
368 List<LXParameter> parameters = effects[activeEffectIndex].getParameters();
369 if (index < parameters.size()) {
370 return parameters.get(index);
376 private int patternKnobIndex = -1;
377 private int transitionKnobIndex = -1;
378 private int effectKnobIndex = -1;
381 private int releaseEffect = -1;
382 private boolean tempoDown = false;
384 public void mousePressed() {
386 patternKnobIndex = transitionKnobIndex = effectKnobIndex = -1;
388 if (mouseY > tempoY) {
389 if (mouseY - tempoY < tempoHeight) {
393 } else if ((mouseY >= firstEffectKnobY) && (mouseY < firstEffectKnobY + knobSize + knobLabelHeight)) {
394 effectKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
395 } else if (mouseY > firstEffectY) {
396 int effectIndex = (mouseY - firstEffectY) / lineHeight;
397 if (effectIndex < effects.length) {
398 if (activeEffectIndex == effectIndex) {
399 effects[effectIndex].enable();
400 releaseEffect = effectIndex;
402 activeEffectIndex = effectIndex;
404 } else if ((mouseY >= firstTransitionKnobY) && (mouseY < firstTransitionKnobY + knobSize + knobLabelHeight)) {
405 transitionKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
406 } else if (mouseY > firstTransitionY) {
407 int transitionIndex = (mouseY - firstTransitionY) / lineHeight;
408 if (transitionIndex < transitions.length) {
409 activeTransitionIndex = transitionIndex;
411 } else if ((mouseY >= firstPatternKnobY) && (mouseY < firstPatternKnobY + 2*(knobSize+knobLabelHeight) + knobSpacing)) {
412 patternKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
413 if (mouseY >= firstPatternKnobY + knobSize + knobLabelHeight + knobSpacing) {
414 patternKnobIndex += NUM_PATTERN_KNOBS / 2;
416 } else if (mouseY > firstPatternY) {
417 int patternIndex = (mouseY - firstPatternY) / lineHeight;
418 if (patternIndex < patterns.length) {
419 patterns[patternIndex].setTransition(transitions[activeTransitionIndex]);
420 lx.goIndex(patternIndex);
425 public void mouseDragged() {
426 int dy = lastY - mouseY;
428 if (patternKnobIndex >= 0 && patternKnobIndex < NUM_PATTERN_KNOBS) {
429 LXParameter p = patternKnobs[patternKnobIndex];
430 p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
431 } else if (effectKnobIndex >= 0 && effectKnobIndex < NUM_EFFECT_KNOBS) {
432 LXParameter p = effectKnobs[effectKnobIndex];
433 p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
434 } else if (transitionKnobIndex >= 0 && transitionKnobIndex < NUM_TRANSITION_KNOBS) {
435 LXParameter p = transitionKnobs[transitionKnobIndex];
436 p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
440 public void mouseReleased() {
442 if (releaseEffect >= 0) {
443 effects[releaseEffect].trigger();
450 void mousePressed() {
451 if (mouseX > ui.leftPos) {
456 void mouseReleased() {
457 if (mouseX > ui.leftPos) {
462 void mouseDragged() {
463 if (mouseX > ui.leftPos) {