1 import java.lang.reflect.*;
4 * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
7 * ///\\\ ///\\\ ///\\\ ///\\\
8 * \\\/// \\\/// \\\/// \\\///
11 * EXPERTS ONLY!! EXPERTS ONLY!!
13 * Overlay UI that indicates pattern control, etc. This will be moved
14 * into the Processing library once it is stabilized and need not be
17 abstract class OverlayUI {
18 protected final PFont titleFont = createFont("Myriad Pro", 10);
19 protected final color titleColor = #AAAAAA;
20 protected final PFont itemFont = createFont("Lucida Grande", 11);
21 protected final PFont knobFont = titleFont;
22 protected final int w = 140;
23 protected final int leftPos;
24 protected final int leftTextPos;
25 protected final int lineHeight = 20;
26 protected final int sectionSpacing = 12;
27 protected final int controlSpacing = 18;
28 protected final int tempoHeight = 20;
29 protected final int knobSize = 28;
30 protected final float knobIndent = .4;
31 protected final int knobSpacing = 6;
32 protected final int knobLabelHeight = 14;
33 protected final int scrollWidth = 14;
34 protected final color lightBlue = #666699;
35 protected final color lightGreen = #669966;
36 protected final int toggleButtonSize = 10;
40 protected final int STATE_DEFAULT = 0;
41 protected final int STATE_ACTIVE = 1;
42 protected final int STATE_PENDING = 2;
44 protected int[] pandaLeft = new int[pandaBoards.length];
45 protected final int pandaWidth = 56;
46 protected final int pandaHeight = 13;
47 protected final int pandaTop = height-16;
49 protected int eligibleLeft;
51 protected OverlayUI() {
53 leftTextPos = leftPos + 4;
54 logo = loadImage("logo-sm.png");
57 protected void drawLogoAndBackground() {
59 stroke(color(0, 0, 100));
60 // fill(color(0, 0, 50, 50)); // alpha is bad for perf
61 fill(color(0, 0, 30));
62 rect(leftPos-1, -1, w+2, height+2);
65 protected void drawToggleTip(String s) {
69 text(s, leftTextPos, height-6);
72 protected void drawHelpTip() {
75 text("Tap 'u' to restore UI", width-4, height-6);
78 public void drawFPS() {
82 text("FPS: " + (((int)(frameRate * 10)) / 10.), 4, height-6);
83 text("Target (-/+):", 50, height-6);
85 rect(104, height-16, 20, 13);
87 text("" + targetFramerate, 108, height-6);
88 text("PandaOutput (p):", 134, height-6);
91 for (PandaDriver p : pandaBoards) {
92 pandaLeft[pi++] = lPos;
93 fill(p.enabled ? #666666 : #000000);
94 rect(lPos, pandaTop, pandaWidth, pandaHeight);
95 fill(p.enabled ? #000000 : #666666);
96 text(p.ip, lPos + 4, height-6);
102 protected int drawObjectList(int yPos, String title, Object[] items, Method stateMethod) {
103 int sz = (items != null) ? items.length : 0;
104 return drawObjectList(yPos, title, items, stateMethod, sz, 0);
107 protected int drawObjectList(int yPos, String title, Object[] items, Method stateMethod, int scrollLength, int scrollPos) {
108 return drawObjectList(yPos, title, items, classNameArray(items, null), stateMethod, scrollLength, scrollPos);
111 protected int drawObjectList(int yPos, String title, Object[] items, String[] names, Method stateMethod) {
112 int sz = (items != null) ? items.length : 0;
113 return drawObjectList(yPos, title, items, names, stateMethod, sz, 0);
116 protected void drawToggleButton(float x, float y, boolean eligible, color textColor) {
119 rect(x, y, toggleButtonSize, toggleButtonSize);
123 rect(x + 2, y + 2, toggleButtonSize - 4, toggleButtonSize - 4);
127 protected int drawObjectList(int yPos, String title, Object[] items, String[] names, Method stateMethod, int scrollLength, int scrollPos) {
132 text(title, leftTextPos, yPos += lineHeight);
134 boolean hasScroll = (scrollPos > 0) || (scrollLength < items.length);
139 for (int i = scrollPos; i < items.length && i < (scrollPos + scrollLength); ++i) {
141 int state = STATE_DEFAULT;
143 state = ((Integer) stateMethod.invoke(this, o)).intValue();
144 } catch (Exception x) {
145 throw new RuntimeException(x);
154 textColor = color(0, 0, 75 + 15*sin(millis()/200.));;
158 fill(even ? #666666 : #777777);
162 rect(leftPos, yPos+6, w, lineHeight);
164 text(names[i], leftTextPos, yPos += lineHeight);
165 if (lx.isAutoTransitionEnabled() && items[i] instanceof LXPattern) {
166 boolean eligible = ((LXPattern)items[i]).isEligible();
167 eligibleLeft = leftPos + w - (hasScroll ? scrollWidth : 0) - 15;
168 drawToggleButton(eligibleLeft, yPos-8, eligible, textColor);
175 fill(color(0, 0, 0, 50));
176 rect(leftPos + w - scrollWidth, yTop, scrollWidth, yHere - yTop);
178 rect(leftPos + w - scrollWidth + 2, yTop + (yHere-yTop) * (scrollPos / (float)items.length), scrollWidth - 4, (yHere - yTop) * (scrollLength / (float)items.length));
186 protected String[] classNameArray(Object[] objects, String suffix) {
187 if (objects == null) {
190 String[] names = new String[objects.length];
191 for (int i = 0; i < objects.length; ++i) {
192 names[i] = className(objects[i], suffix);
197 protected String className(Object p, String suffix) {
198 String s = p.getClass().getName();
200 if ((li = s.lastIndexOf(".")) > 0) {
201 s = s.substring(li + 1);
203 if (s.indexOf("SugarCubes$") == 0) {
204 s = s.substring("SugarCubes$".length());
206 if ((suffix != null) && ((li = s.indexOf(suffix)) != -1)) {
207 s = s.substring(0, li);
212 protected int objectClickIndex(int firstItemY) {
213 return (mouseY - firstItemY) / lineHeight;
216 abstract public void draw();
217 abstract public void mousePressed();
218 abstract public void mouseDragged();
219 abstract public void mouseReleased();
220 abstract public void mouseWheel(int delta);
224 * UI for control of patterns, transitions, effects.
226 class ControlUI extends OverlayUI {
227 private final String[] patternNames;
228 private final String[] transitionNames;
229 private final String[] effectNames;
231 private int firstPatternY;
232 private int firstPatternKnobY;
233 private int firstTransitionY;
234 private int firstTransitionKnobY;
235 private int firstEffectY;
236 private int firstEffectKnobY;
238 private int autoRotateX;
239 private int autoRotateY;
241 private final int PATTERN_LIST_LENGTH = 8;
242 private int patternScrollPos = 0;
246 private Method patternStateMethod;
247 private Method transitionStateMethod;
248 private Method effectStateMethod;
251 patternNames = classNameArray(patterns, "Pattern");
252 transitionNames = classNameArray(transitions, "Transition");
253 effectNames = classNameArray(effects, "Effect");
256 patternStateMethod = getClass().getMethod("getState", LXPattern.class);
257 effectStateMethod = getClass().getMethod("getState", LXEffect.class);
258 transitionStateMethod = getClass().getMethod("getState", LXTransition.class);
259 } catch (Exception x) {
260 throw new RuntimeException(x);
265 drawLogoAndBackground();
267 autoRotateX = leftPos + w - 29;
268 autoRotateY = yPos + 12;
269 drawToggleButton(autoRotateX, autoRotateY, lx.isAutoTransitionEnabled(), #999999);
270 fill(lx.isAutoTransitionEnabled() ? #222222: #999999);
271 text("A", autoRotateX + 2, autoRotateY + 9);
272 firstPatternY = yPos + lineHeight + 6;
273 yPos = drawObjectList(yPos, "PATTERN", patterns, patternNames, patternStateMethod, PATTERN_LIST_LENGTH, patternScrollPos);
274 yPos += controlSpacing;
275 firstPatternKnobY = yPos;
276 int xPos = leftTextPos;
277 for (int i = 0; i < glucose.NUM_PATTERN_KNOBS/2; ++i) {
278 drawKnob(xPos, yPos, knobSize, glucose.patternKnobs.get(i));
279 drawKnob(xPos, yPos + knobSize + knobSpacing + knobLabelHeight, knobSize, glucose.patternKnobs.get(glucose.NUM_PATTERN_KNOBS/2 + i));
280 xPos += knobSize + knobSpacing;
282 yPos += 2*(knobSize + knobLabelHeight) + knobSpacing;
284 yPos += sectionSpacing;
285 firstTransitionY = yPos + lineHeight + 6;
286 yPos = drawObjectList(yPos, "TRANSITION", transitions, transitionNames, transitionStateMethod);
287 yPos += controlSpacing;
288 firstTransitionKnobY = yPos;
290 for (VirtualTransitionKnob knob : glucose.transitionKnobs) {
291 drawKnob(xPos, yPos, knobSize, knob);
292 xPos += knobSize + knobSpacing;
294 yPos += knobSize + knobLabelHeight;
296 yPos += sectionSpacing;
297 firstEffectY = yPos + lineHeight + 6;
298 yPos = drawObjectList(yPos, "FX", effects, effectNames, effectStateMethod);
299 yPos += controlSpacing;
300 firstEffectKnobY = yPos;
302 for (VirtualEffectKnob knob : glucose.effectKnobs) {
303 drawKnob(xPos, yPos, knobSize, knob);
304 xPos += knobSize + knobSpacing;
306 yPos += knobSize + knobLabelHeight;
308 yPos += sectionSpacing;
309 yPos = drawObjectList(yPos, "TEMPO", null, null, null);
313 fill(tempoDown ? lightGreen : color(0, 0, 35 - 8*lx.tempo.rampf()));
314 rect(leftPos + 4, yPos, w - 8, tempoHeight);
317 text("" + ((int)(lx.tempo.bpmf() * 100) / 100.), leftPos + w/2., yPos + tempoHeight - 6);
320 drawToggleTip("Tap 'u' to hide");
323 public LXParameter getOrNull(List<LXParameter> items, int index) {
324 if (index < items.size()) {
325 return items.get(index);
330 public int getState(LXPattern p) {
331 if (p == lx.getPattern()) {
333 } else if (p == lx.getNextPattern()) {
334 return STATE_PENDING;
336 return STATE_DEFAULT;
339 public int getState(LXEffect e) {
341 return STATE_PENDING;
342 } else if (e == glucose.getSelectedEffect()) {
345 return STATE_DEFAULT;
348 public int getState(LXTransition t) {
349 if (t == lx.getTransition()) {
350 return STATE_PENDING;
351 } else if (t == glucose.getSelectedTransition()) {
354 return STATE_DEFAULT;
357 private void drawKnob(int xPos, int yPos, int knobSize, LXParameter knob) {
358 final float knobValue = knob.getValuef();
359 String knobLabel = knob.getLabel();
360 if (knobLabel == null) {
362 } else if (knobLabel.length() > 4) {
363 knobLabel = knobLabel.substring(0, 4);
369 // For some reason this arc call really crushes drawing performance. Presumably
370 // because openGL is drawing it and when we overlap the second set of arcs it
371 // does a bunch of depth buffer intersection tests? Ellipse with a trapezoid cut out is faster
372 // arc(xPos + knobSize/2, yPos + knobSize/2, knobSize, knobSize, HALF_PI + knobIndent, HALF_PI + knobIndent + (TWO_PI-2*knobIndent));
373 ellipse(xPos + knobSize/2, yPos + knobSize/2, knobSize, knobSize);
375 float endArc = HALF_PI + knobIndent + (TWO_PI-2*knobIndent)*knobValue;
377 arc(xPos + knobSize/2, yPos + knobSize/2, knobSize, knobSize, HALF_PI + knobIndent, endArc);
379 // Mask notch out of knob
380 fill(color(0, 0, 30));
382 vertex(xPos + knobSize/2, yPos + knobSize/2.);
383 vertex(xPos + knobSize/2 - 6, yPos + knobSize);
384 vertex(xPos + knobSize/2 + 6, yPos + knobSize);
387 // Center circle of knob
389 ellipse(xPos + knobSize/2, yPos + knobSize/2, knobSize/2, knobSize/2);
392 rect(xPos, yPos + knobSize + 2, knobSize, knobLabelHeight - 2);
396 text(knobLabel, xPos + knobSize/2, yPos + knobSize + knobLabelHeight - 2);
399 private int patternKnobIndex = -1;
400 private int transitionKnobIndex = -1;
401 private int effectKnobIndex = -1;
402 private boolean patternScrolling = false;
405 private int releaseEffect = -1;
406 private boolean tempoDown = false;
408 public void mousePressed() {
410 patternKnobIndex = transitionKnobIndex = effectKnobIndex = -1;
412 patternScrolling = false;
414 for (int p = 0; p < pandaLeft.length; ++p) {
415 int xp = pandaLeft[p];
416 if ((mouseX >= xp) &&
417 (mouseX < xp + pandaWidth) &&
418 (mouseY >= pandaTop) &&
419 (mouseY < pandaTop + pandaHeight)) {
420 pandaBoards[p].toggle();
424 if (mouseX < leftPos) {
428 if ((mouseX >= autoRotateX) &&
429 (mouseX < autoRotateX + toggleButtonSize) &&
430 (mouseY >= autoRotateY) &&
431 (mouseY < autoRotateY + toggleButtonSize)) {
432 if (lx.isAutoTransitionEnabled()) {
433 lx.disableAutoTransition();
434 println("Auto pattern transition disabled");
436 lx.enableAutoTransition(60000);
437 println("Auto pattern transition enabled");
442 if (mouseY > tempoY) {
443 if (mouseY - tempoY < tempoHeight) {
447 } else if ((mouseY >= firstEffectKnobY) && (mouseY < firstEffectKnobY + knobSize + knobLabelHeight)) {
448 effectKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
449 } else if (mouseY > firstEffectY) {
450 int effectIndex = objectClickIndex(firstEffectY);
451 if (effectIndex < effects.length) {
452 if (effects[effectIndex] == glucose.getSelectedEffect()) {
453 effects[effectIndex].enable();
454 releaseEffect = effectIndex;
456 glucose.setSelectedEffect(effectIndex);
458 } else if ((mouseY >= firstTransitionKnobY) && (mouseY < firstTransitionKnobY + knobSize + knobLabelHeight)) {
459 transitionKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
460 } else if (mouseY > firstTransitionY) {
461 int transitionIndex = objectClickIndex(firstTransitionY);
462 if (transitionIndex < transitions.length) {
463 glucose.setSelectedTransition(transitionIndex);
465 } else if ((mouseY >= firstPatternKnobY) && (mouseY < firstPatternKnobY + 2*(knobSize+knobLabelHeight) + knobSpacing)) {
466 patternKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
467 if (mouseY >= firstPatternKnobY + knobSize + knobLabelHeight + knobSpacing) {
468 patternKnobIndex += glucose.NUM_PATTERN_KNOBS / 2;
470 } else if (mouseY > firstPatternY) {
471 if ((patterns.length > PATTERN_LIST_LENGTH) && (mouseX > width - scrollWidth)) {
472 patternScrolling = true;
474 int patternIndex = objectClickIndex(firstPatternY);
475 if (patternIndex < patterns.length) {
476 if (lx.isAutoTransitionEnabled() && (mouseX > eligibleLeft)) {
477 patterns[patternIndex + patternScrollPos].toggleEligible();
479 lx.goIndex(patternIndex + patternScrollPos);
487 public void mouseDragged() {
488 int dy = lastY - mouseY;
491 if (patternKnobIndex >= 0 && patternKnobIndex < glucose.NUM_PATTERN_KNOBS) {
492 LXParameter p = glucose.patternKnobs.get(patternKnobIndex);
493 p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
494 } else if (effectKnobIndex >= 0 && effectKnobIndex < glucose.NUM_EFFECT_KNOBS) {
495 LXParameter p = glucose.effectKnobs.get(effectKnobIndex);
496 p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
497 } else if (transitionKnobIndex >= 0 && transitionKnobIndex < glucose.NUM_TRANSITION_KNOBS) {
498 LXParameter p = glucose.transitionKnobs.get(transitionKnobIndex);
499 p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
500 } else if (patternScrolling) {
501 int scroll = scrolldy / lineHeight;
502 scrolldy = scrolldy % lineHeight;
503 patternScrollPos = constrain(patternScrollPos - scroll, 0, patterns.length - PATTERN_LIST_LENGTH);
507 public void mouseReleased() {
508 patternScrolling = false;
510 if (releaseEffect >= 0) {
511 effects[releaseEffect].trigger();
516 public void mouseWheel(int delta) {
517 if (mouseY > firstPatternY) {
518 int patternIndex = objectClickIndex(firstPatternY);
519 if (patternIndex < PATTERN_LIST_LENGTH) {
520 patternScrollPos = constrain(patternScrollPos + delta, 0, patterns.length - PATTERN_LIST_LENGTH);
528 * UI for control of mapping.
530 class MappingUI extends OverlayUI {
532 private MappingTool mappingTool;
534 private final String MAPPING_MODE_ALL = "All On";
535 private final String MAPPING_MODE_CHANNEL = "Channel";
536 private final String MAPPING_MODE_SINGLE_CUBE = "Single Cube";
538 private final String[] mappingModes = {
540 MAPPING_MODE_CHANNEL,
541 MAPPING_MODE_SINGLE_CUBE
543 private final Method mappingModeStateMethod;
545 private final String CUBE_MODE_ALL = "All Strips";
546 private final String CUBE_MODE_SINGLE_STRIP = "Single Strip";
547 private final String CUBE_MODE_STRIP_PATTERN = "Strip Pattern";
548 private final String[] cubeModes = {
550 CUBE_MODE_SINGLE_STRIP,
551 CUBE_MODE_STRIP_PATTERN
553 private final Method cubeModeStateMethod;
555 private final String CHANNEL_MODE_RED = "Red";
556 private final String CHANNEL_MODE_GREEN = "Green";
557 private final String CHANNEL_MODE_BLUE = "Blue";
558 private final String[] channelModes = {
563 private final Method channelModeStateMethod;
565 private int firstMappingY;
566 private int firstCubeY;
567 private int firstChannelY;
568 private int channelFieldY;
569 private int cubeFieldY;
570 private int stripFieldY;
572 private boolean dragCube;
573 private boolean dragStrip;
574 private boolean dragChannel;
576 MappingUI(MappingTool mappingTool) {
577 this.mappingTool = mappingTool;
579 mappingModeStateMethod = getClass().getMethod("getMappingState", Object.class);
580 channelModeStateMethod = getClass().getMethod("getChannelState", Object.class);
581 cubeModeStateMethod = getClass().getMethod("getCubeState", Object.class);
582 } catch (Exception x) {
583 throw new RuntimeException(x);
587 public int getMappingState(Object mappingMode) {
588 boolean active = false;
589 if (mappingMode == MAPPING_MODE_ALL) {
590 active = mappingTool.mappingMode == mappingTool.MAPPING_MODE_ALL;
591 } else if (mappingMode == MAPPING_MODE_CHANNEL) {
592 active = mappingTool.mappingMode == mappingTool.MAPPING_MODE_CHANNEL;
593 } else if (mappingMode == MAPPING_MODE_SINGLE_CUBE) {
594 active = mappingTool.mappingMode == mappingTool.MAPPING_MODE_SINGLE_CUBE;
596 return active ? STATE_ACTIVE : STATE_DEFAULT;
599 public int getChannelState(Object channelMode) {
600 boolean active = false;
601 if (channelMode == CHANNEL_MODE_RED) {
602 active = mappingTool.channelModeRed;
603 } else if (channelMode == CHANNEL_MODE_GREEN) {
604 active = mappingTool.channelModeGreen;
605 } else if (channelMode == CHANNEL_MODE_BLUE) {
606 active = mappingTool.channelModeBlue;
608 return active ? STATE_ACTIVE : STATE_DEFAULT;
611 public int getCubeState(Object cubeMode) {
612 boolean active = false;
613 if (cubeMode == CUBE_MODE_ALL) {
614 active = mappingTool.cubeMode == mappingTool.CUBE_MODE_ALL;
615 } else if (cubeMode == CUBE_MODE_SINGLE_STRIP) {
616 active = mappingTool.cubeMode == mappingTool.CUBE_MODE_SINGLE_STRIP;
617 } else if (cubeMode == CUBE_MODE_STRIP_PATTERN) {
618 active = mappingTool.cubeMode == mappingTool.CUBE_MODE_STRIP_PATTERN;
620 return active ? STATE_ACTIVE : STATE_DEFAULT;
624 drawLogoAndBackground();
626 firstMappingY = yPos + lineHeight + 6;
627 yPos = drawObjectList(yPos, "MAPPING MODE", mappingModes, mappingModes, mappingModeStateMethod);
628 yPos += sectionSpacing;
630 firstCubeY = yPos + lineHeight + 6;
631 yPos = drawObjectList(yPos, "CUBE MODE", cubeModes, cubeModes, cubeModeStateMethod);
632 yPos += sectionSpacing;
634 firstChannelY = yPos + lineHeight + 6;
635 yPos = drawObjectList(yPos, "CHANNELS", channelModes, channelModes, channelModeStateMethod);
636 yPos += sectionSpacing;
638 channelFieldY = yPos + lineHeight + 6;
639 yPos = drawValueField(yPos, "CHANNEL ID", mappingTool.channelIndex + 1);
640 yPos += sectionSpacing;
642 cubeFieldY = yPos + lineHeight + 6;
643 yPos = drawValueField(yPos, "CUBE ID", glucose.model.getRawIndexForCube(mappingTool.cubeIndex));
644 yPos += sectionSpacing;
646 stripFieldY = yPos + lineHeight + 6;
647 yPos = drawValueField(yPos, "STRIP ID", mappingTool.stripIndex + 1);
649 drawToggleTip("Tap 'm' to return");
652 private int drawValueField(int yPos, String label, int value) {
657 text(label, leftTextPos, yPos);
660 rect(leftTextPos, yPos, w-8, lineHeight);
666 text("" + value, leftTextPos + (w-8)/2, yPos - 5);
673 public void mousePressed() {
674 dragCube = dragStrip = dragChannel = false;
677 if (mouseX < leftPos) {
681 if (mouseY >= stripFieldY) {
682 if (mouseY < stripFieldY + lineHeight) {
685 } else if (mouseY >= cubeFieldY) {
686 if (mouseY < cubeFieldY + lineHeight) {
689 } else if (mouseY >= channelFieldY) {
690 if (mouseY < channelFieldY + lineHeight) {
693 } else if (mouseY >= firstChannelY) {
694 int index = objectClickIndex(firstChannelY);
696 case 0: mappingTool.channelModeRed = !mappingTool.channelModeRed; break;
697 case 1: mappingTool.channelModeGreen = !mappingTool.channelModeGreen; break;
698 case 2: mappingTool.channelModeBlue = !mappingTool.channelModeBlue; break;
700 } else if (mouseY >= firstCubeY) {
701 int index = objectClickIndex(firstCubeY);
703 case 0: mappingTool.cubeMode = mappingTool.CUBE_MODE_ALL; break;
704 case 1: mappingTool.cubeMode = mappingTool.CUBE_MODE_SINGLE_STRIP; break;
705 case 2: mappingTool.cubeMode = mappingTool.CUBE_MODE_STRIP_PATTERN; break;
707 } else if (mouseY >= firstMappingY) {
708 int index = objectClickIndex(firstMappingY);
710 case 0: mappingTool.mappingMode = mappingTool.MAPPING_MODE_ALL; break;
711 case 1: mappingTool.mappingMode = mappingTool.MAPPING_MODE_CHANNEL; break;
712 case 2: mappingTool.mappingMode = mappingTool.MAPPING_MODE_SINGLE_CUBE; break;
717 public void mouseReleased() {}
718 public void mouseWheel(int delta) {}
720 public void mouseDragged() {
721 final int DRAG_THRESHOLD = 5;
722 int dy = lastY - mouseY;
723 if (abs(dy) >= DRAG_THRESHOLD) {
727 mappingTool.decCube();
729 mappingTool.incCube();
731 } else if (dragStrip) {
733 mappingTool.decStrip();
735 mappingTool.incStrip();
737 } else if (dragChannel) {
739 mappingTool.decChannel();
741 mappingTool.incChannel();
751 final ChannelMapping[] channelList;
752 final int debugX = 10;
753 final int debugY = 42;
754 final int debugXSpacing = 28;
755 final int debugYSpacing = 22;
756 final int[][] debugState;
758 final int DEBUG_STATE_ANIM = 0;
759 final int DEBUG_STATE_WHITE = 1;
760 final int DEBUG_STATE_OFF = 2;
762 DebugUI(PandaMapping[] pandaMappings) {
763 int totalChannels = pandaMappings.length * PandaMapping.CHANNELS_PER_BOARD;
764 debugState = new int[totalChannels+1][ChannelMapping.CUBES_PER_CHANNEL+1];
766 channelList = new ChannelMapping[totalChannels];
767 int channelIndex = 0;
768 for (PandaMapping pm : pandaMappings) {
769 for (ChannelMapping channel : pm.channelList) {
770 channelList[channelIndex++] = channel;
773 for (int i = 0; i < debugState.length; ++i) {
774 for (int j = 0; j < debugState[i].length; ++j) {
775 debugState[i][j] = DEBUG_STATE_ANIM;
785 fill(color(0, 0, 0, 80));
786 rect(4, 32, 172, 388);
789 for (ChannelMapping channel : channelList) {
791 drawNumBox(xPos, yPos, channelNum+1, debugState[channelNum][0]);
792 xPos += debugXSpacing;
794 switch (channel.mode) {
795 case ChannelMapping.MODE_CUBES:
797 boolean first = true;
798 for (int rawCubeIndex : channel.objectIndices) {
799 if (rawCubeIndex < 0) {
806 line(xPos - 12, yPos + 8, xPos, yPos + 8);
808 drawNumBox(xPos, yPos, rawCubeIndex, debugState[channelNum][stateIndex+1]);
810 xPos += debugXSpacing;
813 case ChannelMapping.MODE_BASS:
814 drawNumBox(xPos, yPos, "B", debugState[channelNum][1]);
816 case ChannelMapping.MODE_SPEAKER:
817 drawNumBox(xPos, yPos, "S" + channel.objectIndices[0], debugState[channelNum][1]);
819 case ChannelMapping.MODE_FLOOR:
820 drawNumBox(xPos, yPos, "F", debugState[channelNum][1]);
822 case ChannelMapping.MODE_NULL:
825 throw new RuntimeException("Unhandled channel mapping mode: " + channel.mode);
828 yPos += debugYSpacing;
831 drawNumBox(xBase, yPos, "A", debugState[channelNum][0]);
834 void drawNumBox(int xPos, int yPos, int label, int state) {
835 drawNumBox(xPos, yPos, "" + label, state);
838 void drawNumBox(int xPos, int yPos, String label, int state) {
840 color textColor = #cccccc;
842 case DEBUG_STATE_ANIM:
845 rect(xPos, yPos, 16, 8);
847 rect(xPos, yPos+8, 16, 8);
850 rect(xPos, yPos, 16, 16);
852 case DEBUG_STATE_WHITE:
855 rect(xPos, yPos, 16, 16);
858 case DEBUG_STATE_OFF:
860 rect(xPos, yPos, 16, 16);
866 text(label, xPos + 2, yPos + 12);
870 void maskColors(color[] colors) {
871 color white = #FFFFFF;
873 int channelIndex = 0;
875 for (ChannelMapping channel : channelList) {
876 switch (channel.mode) {
877 case ChannelMapping.MODE_CUBES:
879 for (int rawCubeIndex : channel.objectIndices) {
880 if (rawCubeIndex >= 0) {
881 state = debugState[channelIndex][cubeIndex];
882 if (state != DEBUG_STATE_ANIM) {
883 color debugColor = (state == DEBUG_STATE_WHITE) ? white : off;
884 Cube cube = glucose.model.getCubeByRawIndex(rawCubeIndex);
885 for (Point p : cube.points) {
886 colors[p.index] = debugColor;
894 case ChannelMapping.MODE_BASS:
895 state = debugState[channelIndex][1];
896 if (state != DEBUG_STATE_ANIM) {
897 color debugColor = (state == DEBUG_STATE_WHITE) ? white : off;
898 for (Point p : glucose.model.bassBox.points) {
899 colors[p.index] = debugColor;
904 case ChannelMapping.MODE_FLOOR:
905 state = debugState[channelIndex][1];
906 if (state != DEBUG_STATE_ANIM) {
907 color debugColor = (state == DEBUG_STATE_WHITE) ? white : off;
908 for (Point p : glucose.model.boothFloor.points) {
909 colors[p.index] = debugColor;
914 case ChannelMapping.MODE_SPEAKER:
915 state = debugState[channelIndex][1];
916 if (state != DEBUG_STATE_ANIM) {
917 color debugColor = (state == DEBUG_STATE_WHITE) ? white : off;
918 for (Point p : glucose.model.speakers.get(channel.objectIndices[0]).points) {
919 colors[p.index] = debugColor;
924 case ChannelMapping.MODE_NULL:
928 throw new RuntimeException("Unhandled channel mapping mode: " + channel.mode);
934 void mousePressed() {
935 int dx = (mouseX - debugX) / debugXSpacing;
936 int dy = (mouseY - debugY) / debugYSpacing;
937 if ((dy >= 0) && (dy < debugState.length)) {
938 if ((dx >= 0) && (dx < debugState[dy].length)) {
939 int newState = debugState[dy][dx] = (debugState[dy][dx] + 1) % 3;
940 if (dy == debugState.length-1) {
941 for (int[] states : debugState) {
942 for (int i = 0; i < states.length; ++i) {
943 states[i] = newState;
946 } else if (dx == 0) {
947 for (int i = 0; i < debugState[dy].length; ++i) {
948 debugState[dy][i] = newState;