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 = 64;
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() {
83 String fps = "FPS: " + (((int)(frameRate * 10)) / 10.);
84 text(fps, lPos, height-6);
87 String target = "Target (-/+):";
88 text(target, lPos, height-6);
90 lPos += textWidth(target) + 4;
91 rect(lPos, height-16, 24, 13);
93 text("" + targetFramerate, lPos + (24 - textWidth("" + targetFramerate))/2, height-6);
95 String pandaOutput = "PandaOutput (p):";
96 text(pandaOutput, lPos, height-6);
97 lPos += textWidth(pandaOutput)+4;
99 for (PandaDriver p : pandaBoards) {
100 pandaLeft[pi++] = lPos;
101 fill(p.enabled ? #666666 : #000000);
102 rect(lPos, pandaTop, pandaWidth, pandaHeight);
103 fill(p.enabled ? #000000 : #666666);
104 text(p.ip, lPos + (pandaWidth - textWidth(p.ip)) / 2, height-6);
105 lPos += pandaWidth + 8;
110 protected int drawObjectList(int yPos, String title, Object[] items, Method stateMethod) {
111 int sz = (items != null) ? items.length : 0;
112 return drawObjectList(yPos, title, items, stateMethod, sz, 0);
115 protected int drawObjectList(int yPos, String title, Object[] items, Method stateMethod, int scrollLength, int scrollPos) {
116 return drawObjectList(yPos, title, items, classNameArray(items, null), stateMethod, scrollLength, scrollPos);
119 protected int drawObjectList(int yPos, String title, Object[] items, String[] names, Method stateMethod) {
120 int sz = (items != null) ? items.length : 0;
121 return drawObjectList(yPos, title, items, names, stateMethod, sz, 0);
124 protected void drawToggleButton(float x, float y, boolean eligible, color textColor) {
127 rect(x, y, toggleButtonSize, toggleButtonSize);
131 rect(x + 2, y + 2, toggleButtonSize - 4, toggleButtonSize - 4);
135 protected int drawObjectList(int yPos, String title, Object[] items, String[] names, Method stateMethod, int scrollLength, int scrollPos) {
140 text(title, leftTextPos, yPos += lineHeight);
142 boolean hasScroll = (scrollPos > 0) || (scrollLength < items.length);
147 for (int i = scrollPos; i < items.length && i < (scrollPos + scrollLength); ++i) {
149 int state = STATE_DEFAULT;
151 state = ((Integer) stateMethod.invoke(this, o)).intValue();
152 } catch (Exception x) {
153 throw new RuntimeException(x);
162 textColor = color(0, 0, 75 + 15*sin(millis()/200.));;
166 fill(even ? #666666 : #777777);
170 rect(leftPos, yPos+6, w, lineHeight);
172 text(names[i], leftTextPos, yPos += lineHeight);
173 if (lx.isAutoTransitionEnabled() && items[i] instanceof LXPattern) {
174 boolean eligible = ((LXPattern)items[i]).isEligible();
175 eligibleLeft = leftPos + w - (hasScroll ? scrollWidth : 0) - 15;
176 drawToggleButton(eligibleLeft, yPos-8, eligible, textColor);
183 fill(color(0, 0, 0, 50));
184 rect(leftPos + w - scrollWidth, yTop, scrollWidth, yHere - yTop);
186 rect(leftPos + w - scrollWidth + 2, yTop + (yHere-yTop) * (scrollPos / (float)items.length), scrollWidth - 4, (yHere - yTop) * (scrollLength / (float)items.length));
194 protected String[] classNameArray(Object[] objects, String suffix) {
195 if (objects == null) {
198 String[] names = new String[objects.length];
199 for (int i = 0; i < objects.length; ++i) {
200 names[i] = className(objects[i], suffix);
205 protected String className(Object p, String suffix) {
206 String s = p.getClass().getName();
208 if ((li = s.lastIndexOf(".")) > 0) {
209 s = s.substring(li + 1);
211 if (s.indexOf("SugarCubes$") == 0) {
212 s = s.substring("SugarCubes$".length());
214 if ((suffix != null) && ((li = s.indexOf(suffix)) != -1)) {
215 s = s.substring(0, li);
220 protected int objectClickIndex(int firstItemY) {
221 return (mouseY - firstItemY) / lineHeight;
224 abstract public void draw();
225 abstract public void mousePressed();
226 abstract public void mouseDragged();
227 abstract public void mouseReleased();
228 abstract public void mouseWheel(int delta);
232 * UI for control of patterns, transitions, effects.
234 class ControlUI extends OverlayUI {
235 private final String[] patternNames;
236 private final String[] transitionNames;
237 private final String[] effectNames;
239 private int firstPatternY;
240 private int firstPatternKnobY;
241 private int firstTransitionY;
242 private int firstTransitionKnobY;
243 private int firstEffectY;
244 private int firstEffectKnobY;
246 private int autoRotateX;
247 private int autoRotateY;
249 private final int PATTERN_LIST_LENGTH = 8;
250 private int patternScrollPos = 0;
254 private Method patternStateMethod;
255 private Method transitionStateMethod;
256 private Method effectStateMethod;
259 patternNames = classNameArray(patterns, "Pattern");
260 transitionNames = classNameArray(transitions, "Transition");
261 effectNames = classNameArray(effects, "Effect");
264 patternStateMethod = getClass().getMethod("getState", LXPattern.class);
265 effectStateMethod = getClass().getMethod("getState", LXEffect.class);
266 transitionStateMethod = getClass().getMethod("getState", LXTransition.class);
267 } catch (Exception x) {
268 throw new RuntimeException(x);
273 drawLogoAndBackground();
275 autoRotateX = leftPos + w - 29;
276 autoRotateY = yPos + 12;
277 drawToggleButton(autoRotateX, autoRotateY, lx.isAutoTransitionEnabled(), #999999);
278 fill(lx.isAutoTransitionEnabled() ? #222222: #999999);
279 text("A", autoRotateX + 2, autoRotateY + 9);
280 firstPatternY = yPos + lineHeight + 6;
281 yPos = drawObjectList(yPos, "PATTERN", patterns, patternNames, patternStateMethod, PATTERN_LIST_LENGTH, patternScrollPos);
282 yPos += controlSpacing;
283 firstPatternKnobY = yPos;
284 int xPos = leftTextPos;
285 for (int i = 0; i < glucose.NUM_PATTERN_KNOBS/2; ++i) {
286 drawKnob(xPos, yPos, knobSize, glucose.patternKnobs.get(i));
287 drawKnob(xPos, yPos + knobSize + knobSpacing + knobLabelHeight, knobSize, glucose.patternKnobs.get(glucose.NUM_PATTERN_KNOBS/2 + i));
288 xPos += knobSize + knobSpacing;
290 yPos += 2*(knobSize + knobLabelHeight) + knobSpacing;
292 yPos += sectionSpacing;
293 firstTransitionY = yPos + lineHeight + 6;
294 yPos = drawObjectList(yPos, "TRANSITION", transitions, transitionNames, transitionStateMethod);
295 yPos += controlSpacing;
296 firstTransitionKnobY = yPos;
298 for (VirtualTransitionKnob knob : glucose.transitionKnobs) {
299 drawKnob(xPos, yPos, knobSize, knob);
300 xPos += knobSize + knobSpacing;
302 yPos += knobSize + knobLabelHeight;
304 yPos += sectionSpacing;
305 firstEffectY = yPos + lineHeight + 6;
306 yPos = drawObjectList(yPos, "FX", effects, effectNames, effectStateMethod);
307 yPos += controlSpacing;
308 firstEffectKnobY = yPos;
310 for (VirtualEffectKnob knob : glucose.effectKnobs) {
311 drawKnob(xPos, yPos, knobSize, knob);
312 xPos += knobSize + knobSpacing;
314 yPos += knobSize + knobLabelHeight;
316 yPos += sectionSpacing;
317 yPos = drawObjectList(yPos, "TEMPO", null, null, null);
321 fill(tempoDown ? lightGreen : color(0, 0, 35 - 8*lx.tempo.rampf()));
322 rect(leftPos + 4, yPos, w - 8, tempoHeight);
325 text("" + ((int)(lx.tempo.bpmf() * 100) / 100.), leftPos + w/2., yPos + tempoHeight - 6);
328 drawToggleTip("Tap 'u' to hide");
331 public LXParameter getOrNull(List<LXParameter> items, int index) {
332 if (index < items.size()) {
333 return items.get(index);
338 public int getState(LXPattern p) {
339 if (p == lx.getPattern()) {
341 } else if (p == lx.getNextPattern()) {
342 return STATE_PENDING;
344 return STATE_DEFAULT;
347 public int getState(LXEffect e) {
349 return STATE_PENDING;
350 } else if (e == glucose.getSelectedEffect()) {
353 return STATE_DEFAULT;
356 public int getState(LXTransition t) {
357 if (t == lx.getTransition()) {
358 return STATE_PENDING;
359 } else if (t == glucose.getSelectedTransition()) {
362 return STATE_DEFAULT;
365 private void drawKnob(int xPos, int yPos, int knobSize, LXParameter knob) {
366 final float knobValue = knob.getValuef();
367 String knobLabel = knob.getLabel();
368 if (knobLabel == null) {
370 } else if (knobLabel.length() > 4) {
371 knobLabel = knobLabel.substring(0, 4);
377 // For some reason this arc call really crushes drawing performance. Presumably
378 // because openGL is drawing it and when we overlap the second set of arcs it
379 // does a bunch of depth buffer intersection tests? Ellipse with a trapezoid cut out is faster
380 // arc(xPos + knobSize/2, yPos + knobSize/2, knobSize, knobSize, HALF_PI + knobIndent, HALF_PI + knobIndent + (TWO_PI-2*knobIndent));
381 ellipse(xPos + knobSize/2, yPos + knobSize/2, knobSize, knobSize);
383 float endArc = HALF_PI + knobIndent + (TWO_PI-2*knobIndent)*knobValue;
385 arc(xPos + knobSize/2, yPos + knobSize/2, knobSize, knobSize, HALF_PI + knobIndent, endArc);
387 // Mask notch out of knob
388 fill(color(0, 0, 30));
390 vertex(xPos + knobSize/2, yPos + knobSize/2.);
391 vertex(xPos + knobSize/2 - 6, yPos + knobSize);
392 vertex(xPos + knobSize/2 + 6, yPos + knobSize);
395 // Center circle of knob
397 ellipse(xPos + knobSize/2, yPos + knobSize/2, knobSize/2, knobSize/2);
400 rect(xPos, yPos + knobSize + 2, knobSize, knobLabelHeight - 2);
404 text(knobLabel, xPos + knobSize/2, yPos + knobSize + knobLabelHeight - 2);
407 private int patternKnobIndex = -1;
408 private int transitionKnobIndex = -1;
409 private int effectKnobIndex = -1;
410 private boolean patternScrolling = false;
413 private int releaseEffect = -1;
414 private boolean tempoDown = false;
416 public void mousePressed() {
418 patternKnobIndex = transitionKnobIndex = effectKnobIndex = -1;
420 patternScrolling = false;
422 for (int p = 0; p < pandaLeft.length; ++p) {
423 int xp = pandaLeft[p];
424 if ((mouseX >= xp) &&
425 (mouseX < xp + pandaWidth) &&
426 (mouseY >= pandaTop) &&
427 (mouseY < pandaTop + pandaHeight)) {
428 pandaBoards[p].toggle();
432 if (mouseX < leftPos) {
436 if ((mouseX >= autoRotateX) &&
437 (mouseX < autoRotateX + toggleButtonSize) &&
438 (mouseY >= autoRotateY) &&
439 (mouseY < autoRotateY + toggleButtonSize)) {
440 if (lx.isAutoTransitionEnabled()) {
441 lx.disableAutoTransition();
442 println("Auto pattern transition disabled");
444 lx.enableAutoTransition(60000);
445 println("Auto pattern transition enabled");
450 if (mouseY > tempoY) {
451 if (mouseY - tempoY < tempoHeight) {
455 } else if ((mouseY >= firstEffectKnobY) && (mouseY < firstEffectKnobY + knobSize + knobLabelHeight)) {
456 effectKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
457 } else if (mouseY > firstEffectY) {
458 int effectIndex = objectClickIndex(firstEffectY);
459 if (effectIndex < effects.length) {
460 if (effects[effectIndex] == glucose.getSelectedEffect()) {
461 effects[effectIndex].enable();
462 releaseEffect = effectIndex;
464 glucose.setSelectedEffect(effectIndex);
466 } else if ((mouseY >= firstTransitionKnobY) && (mouseY < firstTransitionKnobY + knobSize + knobLabelHeight)) {
467 transitionKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
468 } else if (mouseY > firstTransitionY) {
469 int transitionIndex = objectClickIndex(firstTransitionY);
470 if (transitionIndex < transitions.length) {
471 glucose.setSelectedTransition(transitionIndex);
473 } else if ((mouseY >= firstPatternKnobY) && (mouseY < firstPatternKnobY + 2*(knobSize+knobLabelHeight) + knobSpacing)) {
474 patternKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
475 if (mouseY >= firstPatternKnobY + knobSize + knobLabelHeight + knobSpacing) {
476 patternKnobIndex += glucose.NUM_PATTERN_KNOBS / 2;
478 } else if (mouseY > firstPatternY) {
479 if ((patterns.length > PATTERN_LIST_LENGTH) && (mouseX > width - scrollWidth)) {
480 patternScrolling = true;
482 int patternIndex = objectClickIndex(firstPatternY);
483 if (patternIndex < patterns.length) {
484 if (lx.isAutoTransitionEnabled() && (mouseX > eligibleLeft)) {
485 patterns[patternIndex + patternScrollPos].toggleEligible();
487 lx.goIndex(patternIndex + patternScrollPos);
495 public void mouseDragged() {
496 int dy = lastY - mouseY;
499 if (patternKnobIndex >= 0 && patternKnobIndex < glucose.NUM_PATTERN_KNOBS) {
500 LXParameter p = glucose.patternKnobs.get(patternKnobIndex);
501 p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
502 } else if (effectKnobIndex >= 0 && effectKnobIndex < glucose.NUM_EFFECT_KNOBS) {
503 LXParameter p = glucose.effectKnobs.get(effectKnobIndex);
504 p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
505 } else if (transitionKnobIndex >= 0 && transitionKnobIndex < glucose.NUM_TRANSITION_KNOBS) {
506 LXParameter p = glucose.transitionKnobs.get(transitionKnobIndex);
507 p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
508 } else if (patternScrolling) {
509 int scroll = scrolldy / lineHeight;
510 scrolldy = scrolldy % lineHeight;
511 patternScrollPos = constrain(patternScrollPos - scroll, 0, patterns.length - PATTERN_LIST_LENGTH);
515 public void mouseReleased() {
516 patternScrolling = false;
518 if (releaseEffect >= 0) {
519 effects[releaseEffect].trigger();
524 public void mouseWheel(int delta) {
525 if (mouseY > firstPatternY) {
526 int patternIndex = objectClickIndex(firstPatternY);
527 if (patternIndex < PATTERN_LIST_LENGTH) {
528 patternScrollPos = constrain(patternScrollPos + delta, 0, patterns.length - PATTERN_LIST_LENGTH);
536 * UI for control of mapping.
538 class MappingUI extends OverlayUI {
540 private MappingTool mappingTool;
542 private final String MAPPING_MODE_ALL = "All On";
543 private final String MAPPING_MODE_CHANNEL = "Channel";
544 private final String MAPPING_MODE_SINGLE_CUBE = "Single Cube";
546 private final String[] mappingModes = {
548 MAPPING_MODE_CHANNEL,
549 MAPPING_MODE_SINGLE_CUBE
551 private final Method mappingModeStateMethod;
553 private final String CUBE_MODE_ALL = "All Strips";
554 private final String CUBE_MODE_SINGLE_STRIP = "Single Strip";
555 private final String CUBE_MODE_STRIP_PATTERN = "Strip Pattern";
556 private final String[] cubeModes = {
558 CUBE_MODE_SINGLE_STRIP,
559 CUBE_MODE_STRIP_PATTERN
561 private final Method cubeModeStateMethod;
563 private final String CHANNEL_MODE_RED = "Red";
564 private final String CHANNEL_MODE_GREEN = "Green";
565 private final String CHANNEL_MODE_BLUE = "Blue";
566 private final String[] channelModes = {
571 private final Method channelModeStateMethod;
573 private int firstMappingY;
574 private int firstCubeY;
575 private int firstChannelY;
576 private int channelFieldY;
577 private int cubeFieldY;
578 private int stripFieldY;
580 private boolean dragCube;
581 private boolean dragStrip;
582 private boolean dragChannel;
584 MappingUI(MappingTool mappingTool) {
585 this.mappingTool = mappingTool;
587 mappingModeStateMethod = getClass().getMethod("getMappingState", Object.class);
588 channelModeStateMethod = getClass().getMethod("getChannelState", Object.class);
589 cubeModeStateMethod = getClass().getMethod("getCubeState", Object.class);
590 } catch (Exception x) {
591 throw new RuntimeException(x);
595 public int getMappingState(Object mappingMode) {
596 boolean active = false;
597 if (mappingMode == MAPPING_MODE_ALL) {
598 active = mappingTool.mappingMode == mappingTool.MAPPING_MODE_ALL;
599 } else if (mappingMode == MAPPING_MODE_CHANNEL) {
600 active = mappingTool.mappingMode == mappingTool.MAPPING_MODE_CHANNEL;
601 } else if (mappingMode == MAPPING_MODE_SINGLE_CUBE) {
602 active = mappingTool.mappingMode == mappingTool.MAPPING_MODE_SINGLE_CUBE;
604 return active ? STATE_ACTIVE : STATE_DEFAULT;
607 public int getChannelState(Object channelMode) {
608 boolean active = false;
609 if (channelMode == CHANNEL_MODE_RED) {
610 active = mappingTool.channelModeRed;
611 } else if (channelMode == CHANNEL_MODE_GREEN) {
612 active = mappingTool.channelModeGreen;
613 } else if (channelMode == CHANNEL_MODE_BLUE) {
614 active = mappingTool.channelModeBlue;
616 return active ? STATE_ACTIVE : STATE_DEFAULT;
619 public int getCubeState(Object cubeMode) {
620 boolean active = false;
621 if (cubeMode == CUBE_MODE_ALL) {
622 active = mappingTool.cubeMode == mappingTool.CUBE_MODE_ALL;
623 } else if (cubeMode == CUBE_MODE_SINGLE_STRIP) {
624 active = mappingTool.cubeMode == mappingTool.CUBE_MODE_SINGLE_STRIP;
625 } else if (cubeMode == CUBE_MODE_STRIP_PATTERN) {
626 active = mappingTool.cubeMode == mappingTool.CUBE_MODE_STRIP_PATTERN;
628 return active ? STATE_ACTIVE : STATE_DEFAULT;
632 drawLogoAndBackground();
634 firstMappingY = yPos + lineHeight + 6;
635 yPos = drawObjectList(yPos, "MAPPING MODE", mappingModes, mappingModes, mappingModeStateMethod);
636 yPos += sectionSpacing;
638 firstCubeY = yPos + lineHeight + 6;
639 yPos = drawObjectList(yPos, "CUBE MODE", cubeModes, cubeModes, cubeModeStateMethod);
640 yPos += sectionSpacing;
642 firstChannelY = yPos + lineHeight + 6;
643 yPos = drawObjectList(yPos, "CHANNELS", channelModes, channelModes, channelModeStateMethod);
644 yPos += sectionSpacing;
646 channelFieldY = yPos + lineHeight + 6;
647 yPos = drawValueField(yPos, "CHANNEL ID", mappingTool.channelIndex + 1);
648 yPos += sectionSpacing;
650 cubeFieldY = yPos + lineHeight + 6;
651 yPos = drawValueField(yPos, "CUBE ID", glucose.model.getRawIndexForCube(mappingTool.cubeIndex));
652 yPos += sectionSpacing;
654 stripFieldY = yPos + lineHeight + 6;
655 yPos = drawValueField(yPos, "STRIP ID", mappingTool.stripIndex + 1);
657 drawToggleTip("Tap 'm' to return");
660 private int drawValueField(int yPos, String label, int value) {
665 text(label, leftTextPos, yPos);
668 rect(leftTextPos, yPos, w-8, lineHeight);
674 text("" + value, leftTextPos + (w-8)/2, yPos - 5);
681 public void mousePressed() {
682 dragCube = dragStrip = dragChannel = false;
685 if (mouseX < leftPos) {
689 if (mouseY >= stripFieldY) {
690 if (mouseY < stripFieldY + lineHeight) {
693 } else if (mouseY >= cubeFieldY) {
694 if (mouseY < cubeFieldY + lineHeight) {
697 } else if (mouseY >= channelFieldY) {
698 if (mouseY < channelFieldY + lineHeight) {
701 } else if (mouseY >= firstChannelY) {
702 int index = objectClickIndex(firstChannelY);
704 case 0: mappingTool.channelModeRed = !mappingTool.channelModeRed; break;
705 case 1: mappingTool.channelModeGreen = !mappingTool.channelModeGreen; break;
706 case 2: mappingTool.channelModeBlue = !mappingTool.channelModeBlue; break;
708 } else if (mouseY >= firstCubeY) {
709 int index = objectClickIndex(firstCubeY);
711 case 0: mappingTool.cubeMode = mappingTool.CUBE_MODE_ALL; break;
712 case 1: mappingTool.cubeMode = mappingTool.CUBE_MODE_SINGLE_STRIP; break;
713 case 2: mappingTool.cubeMode = mappingTool.CUBE_MODE_STRIP_PATTERN; break;
715 } else if (mouseY >= firstMappingY) {
716 int index = objectClickIndex(firstMappingY);
718 case 0: mappingTool.mappingMode = mappingTool.MAPPING_MODE_ALL; break;
719 case 1: mappingTool.mappingMode = mappingTool.MAPPING_MODE_CHANNEL; break;
720 case 2: mappingTool.mappingMode = mappingTool.MAPPING_MODE_SINGLE_CUBE; break;
725 public void mouseReleased() {}
726 public void mouseWheel(int delta) {}
728 public void mouseDragged() {
729 final int DRAG_THRESHOLD = 5;
730 int dy = lastY - mouseY;
731 if (abs(dy) >= DRAG_THRESHOLD) {
735 mappingTool.decCube();
737 mappingTool.incCube();
739 } else if (dragStrip) {
741 mappingTool.decStrip();
743 mappingTool.incStrip();
745 } else if (dragChannel) {
747 mappingTool.decChannel();
749 mappingTool.incChannel();
759 final ChannelMapping[] channelList;
760 final int debugX = 10;
761 final int debugY = 42;
762 final int debugXSpacing = 28;
763 final int debugYSpacing = 22;
764 final int[][] debugState = new int[17][6];
766 final int DEBUG_STATE_ANIM = 0;
767 final int DEBUG_STATE_WHITE = 1;
768 final int DEBUG_STATE_OFF = 2;
770 DebugUI(PandaMapping[] pandaMappings) {
771 int totalChannels = pandaMappings.length * PandaMapping.CHANNELS_PER_BOARD;
772 channelList = new ChannelMapping[totalChannels];
773 int channelIndex = 0;
774 for (PandaMapping pm : pandaMappings) {
775 for (ChannelMapping channel : pm.channelList) {
776 channelList[channelIndex++] = channel;
779 for (int i = 0; i < debugState.length; ++i) {
780 for (int j = 0; j < debugState[i].length; ++j) {
781 debugState[i][j] = DEBUG_STATE_ANIM;
791 fill(color(0, 0, 0, 80));
792 rect(4, 32, 172, 388);
795 for (ChannelMapping channel : channelList) {
797 drawNumBox(xPos, yPos, channelNum+1, debugState[channelNum][0]);
798 xPos += debugXSpacing;
800 switch (channel.mode) {
801 case ChannelMapping.MODE_CUBES:
803 boolean first = true;
804 for (int rawCubeIndex : channel.objectIndices) {
805 if (rawCubeIndex < 0) {
812 line(xPos - 12, yPos + 8, xPos, yPos + 8);
814 drawNumBox(xPos, yPos, rawCubeIndex, debugState[channelNum][stateIndex+1]);
816 xPos += debugXSpacing;
819 case ChannelMapping.MODE_BASS:
820 drawNumBox(xPos, yPos, "B", debugState[channelNum][1]);
822 case ChannelMapping.MODE_SPEAKER:
823 drawNumBox(xPos, yPos, "S" + channel.objectIndices[0], debugState[channelNum][1]);
825 case ChannelMapping.MODE_FLOOR:
826 drawNumBox(xPos, yPos, "F", debugState[channelNum][1]);
828 case ChannelMapping.MODE_NULL:
831 throw new RuntimeException("Unhandled channel mapping mode: " + channel.mode);
834 yPos += debugYSpacing;
837 drawNumBox(xBase, yPos, "A", debugState[channelNum][0]);
840 void drawNumBox(int xPos, int yPos, int label, int state) {
841 drawNumBox(xPos, yPos, "" + label, state);
844 void drawNumBox(int xPos, int yPos, String label, int state) {
846 color textColor = #cccccc;
848 case DEBUG_STATE_ANIM:
851 rect(xPos, yPos, 16, 8);
853 rect(xPos, yPos+8, 16, 8);
856 rect(xPos, yPos, 16, 16);
858 case DEBUG_STATE_WHITE:
861 rect(xPos, yPos, 16, 16);
864 case DEBUG_STATE_OFF:
866 rect(xPos, yPos, 16, 16);
872 text(label, xPos + 2, yPos + 12);
876 void maskColors(color[] colors) {
877 color white = #FFFFFF;
879 int channelIndex = 0;
881 for (ChannelMapping channel : channelList) {
882 switch (channel.mode) {
883 case ChannelMapping.MODE_CUBES:
885 for (int rawCubeIndex : channel.objectIndices) {
886 if (rawCubeIndex >= 0) {
887 state = debugState[channelIndex][cubeIndex];
888 if (state != DEBUG_STATE_ANIM) {
889 color debugColor = (state == DEBUG_STATE_WHITE) ? white : off;
890 Cube cube = glucose.model.getCubeByRawIndex(rawCubeIndex);
891 for (Point p : cube.points) {
892 colors[p.index] = debugColor;
900 case ChannelMapping.MODE_BASS:
901 state = debugState[channelIndex][1];
902 if (state != DEBUG_STATE_ANIM) {
903 color debugColor = (state == DEBUG_STATE_WHITE) ? white : off;
904 for (Point p : glucose.model.bassBox.points) {
905 colors[p.index] = debugColor;
910 case ChannelMapping.MODE_FLOOR:
911 state = debugState[channelIndex][1];
912 if (state != DEBUG_STATE_ANIM) {
913 color debugColor = (state == DEBUG_STATE_WHITE) ? white : off;
914 for (Point p : glucose.model.boothFloor.points) {
915 colors[p.index] = debugColor;
920 case ChannelMapping.MODE_SPEAKER:
921 state = debugState[channelIndex][1];
922 if (state != DEBUG_STATE_ANIM) {
923 color debugColor = (state == DEBUG_STATE_WHITE) ? white : off;
924 for (Point p : glucose.model.speakers.get(channel.objectIndices[0]).points) {
925 colors[p.index] = debugColor;
930 case ChannelMapping.MODE_NULL:
934 throw new RuntimeException("Unhandled channel mapping mode: " + channel.mode);
940 void mousePressed() {
941 int dx = (mouseX - debugX) / debugXSpacing;
942 int dy = (mouseY - debugY) / debugYSpacing;
943 if ((dy >= 0) && (dy < debugState.length)) {
944 if ((dx >= 0) && (dx < debugState[dy].length)) {
945 int newState = debugState[dy][dx] = (debugState[dy][dx] + 1) % 3;
947 for (int[] states : debugState) {
948 for (int i = 0; i < states.length; ++i) {
949 states[i] = newState;
952 } else if (dx == 0) {
953 for (int i = 0; i < debugState[dy].length; ++i) {
954 debugState[dy][i] = newState;