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 drawDanText() {
82 text(DanTextLine1, 4, height-50);
83 text(DanTextLine2, 4, height-30);
86 public void drawFPS() {
92 String fps = "FPS: " + (((int)(frameRate * 10)) / 10.);
93 text(fps, lPos, height-6);
96 String target = "Target (-/+):";
97 text(target, lPos, height-6);
99 lPos += textWidth(target) + 4;
100 rect(lPos, height-16, 24, 13);
102 text("" + targetFramerate, lPos + (24 - textWidth("" + targetFramerate))/2, height-6);
104 String pandaOutput = "PandaOutput (p):";
105 text(pandaOutput, lPos, height-6);
106 lPos += textWidth(pandaOutput)+4;
108 for (PandaDriver p : pandaBoards) {
109 pandaLeft[pi++] = lPos;
110 fill(p.enabled ? #666666 : #000000);
111 rect(lPos, pandaTop, pandaWidth, pandaHeight);
112 fill(p.enabled ? #000000 : #666666);
113 text(p.ip, lPos + (pandaWidth - textWidth(p.ip)) / 2, height-6);
114 lPos += pandaWidth + 8;
119 protected int drawObjectList(int yPos, String title, Object[] items, Method stateMethod) {
120 int sz = (items != null) ? items.length : 0;
121 return drawObjectList(yPos, title, items, stateMethod, sz, 0);
124 protected int drawObjectList(int yPos, String title, Object[] items, Method stateMethod, int scrollLength, int scrollPos) {
125 return drawObjectList(yPos, title, items, classNameArray(items, null), stateMethod, scrollLength, scrollPos);
128 protected int drawObjectList(int yPos, String title, Object[] items, String[] names, Method stateMethod) {
129 int sz = (items != null) ? items.length : 0;
130 return drawObjectList(yPos, title, items, names, stateMethod, sz, 0);
133 protected void drawToggleButton(float x, float y, boolean eligible, color textColor) {
136 rect(x, y, toggleButtonSize, toggleButtonSize);
140 rect(x + 2, y + 2, toggleButtonSize - 4, toggleButtonSize - 4);
144 protected int drawObjectList(int yPos, String title, Object[] items, String[] names, Method stateMethod, int scrollLength, int scrollPos) {
149 text(title, leftTextPos, yPos += lineHeight);
151 boolean hasScroll = (scrollPos > 0) || (scrollLength < items.length);
156 for (int i = scrollPos; i < items.length && i < (scrollPos + scrollLength); ++i) {
158 int state = STATE_DEFAULT;
160 state = ((Integer) stateMethod.invoke(this, o)).intValue();
161 } catch (Exception x) {
162 throw new RuntimeException(x);
171 textColor = color(0, 0, 75 + 15*sin(millis()/200.));;
175 fill(even ? #666666 : #777777);
179 rect(leftPos, yPos+6, w, lineHeight);
181 text(names[i], leftTextPos, yPos += lineHeight);
182 if (lx.isAutoTransitionEnabled() && items[i] instanceof LXPattern) {
183 boolean eligible = ((LXPattern)items[i]).isEligible();
184 eligibleLeft = leftPos + w - (hasScroll ? scrollWidth : 0) - 15;
185 drawToggleButton(eligibleLeft, yPos-8, eligible, textColor);
192 fill(color(0, 0, 0, 50));
193 rect(leftPos + w - scrollWidth, yTop, scrollWidth, yHere - yTop);
195 rect(leftPos + w - scrollWidth + 2, yTop + (yHere-yTop) * (scrollPos / (float)items.length), scrollWidth - 4, (yHere - yTop) * (scrollLength / (float)items.length));
203 protected String[] classNameArray(Object[] objects, String suffix) {
204 if (objects == null) {
207 String[] names = new String[objects.length];
208 for (int i = 0; i < objects.length; ++i) {
209 names[i] = className(objects[i], suffix);
214 protected String className(Object p, String suffix) {
215 String s = p.getClass().getName();
217 if ((li = s.lastIndexOf(".")) > 0) {
218 s = s.substring(li + 1);
220 if (s.indexOf("SugarCubes$") == 0) {
221 s = s.substring("SugarCubes$".length());
223 if ((suffix != null) && ((li = s.indexOf(suffix)) != -1)) {
224 s = s.substring(0, li);
229 protected int objectClickIndex(int firstItemY) {
230 return (mouseY - firstItemY) / lineHeight;
233 abstract public void draw();
234 abstract public void mousePressed();
235 abstract public void mouseDragged();
236 abstract public void mouseReleased();
237 abstract public void mouseWheel(int delta);
241 * UI for control of patterns, transitions, effects.
243 class ControlUI extends OverlayUI {
244 private final String[] patternNames;
245 private final String[] transitionNames;
246 private final String[] effectNames;
248 private int firstPatternY;
249 private int firstPatternKnobY;
250 private int firstTransitionY;
251 private int firstTransitionKnobY;
252 private int firstEffectY;
253 private int firstEffectKnobY;
255 private int autoRotateX;
256 private int autoRotateY;
258 private final int PATTERN_LIST_LENGTH = 8;
259 private int patternScrollPos = 0;
263 private Method patternStateMethod;
264 private Method transitionStateMethod;
265 private Method effectStateMethod;
268 patternNames = classNameArray(patterns, "Pattern");
269 transitionNames = classNameArray(transitions, "Transition");
270 effectNames = classNameArray(effects, "Effect");
273 patternStateMethod = getClass().getMethod("getState", LXPattern.class);
274 effectStateMethod = getClass().getMethod("getState", LXEffect.class);
275 transitionStateMethod = getClass().getMethod("getState", LXTransition.class);
276 } catch (Exception x) {
277 throw new RuntimeException(x);
282 drawLogoAndBackground();
284 autoRotateX = leftPos + w - 29;
285 autoRotateY = yPos + 12;
286 drawToggleButton(autoRotateX, autoRotateY, lx.isAutoTransitionEnabled(), #999999);
287 fill(lx.isAutoTransitionEnabled() ? #222222: #999999);
288 text("A", autoRotateX + 2, autoRotateY + 9);
289 firstPatternY = yPos + lineHeight + 6;
290 yPos = drawObjectList(yPos, "PATTERN", patterns, patternNames, patternStateMethod, PATTERN_LIST_LENGTH, patternScrollPos);
291 yPos += controlSpacing;
292 firstPatternKnobY = yPos;
293 int xPos = leftTextPos;
294 for (int i = 0; i < glucose.NUM_PATTERN_KNOBS/2; ++i) {
295 drawKnob(xPos, yPos, knobSize, glucose.patternKnobs.get(i));
296 drawKnob(xPos, yPos + knobSize + knobSpacing + knobLabelHeight, knobSize, glucose.patternKnobs.get(glucose.NUM_PATTERN_KNOBS/2 + i));
297 xPos += knobSize + knobSpacing;
299 yPos += 2*(knobSize + knobLabelHeight) + knobSpacing;
301 yPos += sectionSpacing;
302 firstTransitionY = yPos + lineHeight + 6;
303 yPos = drawObjectList(yPos, "TRANSITION", transitions, transitionNames, transitionStateMethod);
304 yPos += controlSpacing;
305 firstTransitionKnobY = yPos;
307 for (VirtualTransitionKnob knob : glucose.transitionKnobs) {
308 drawKnob(xPos, yPos, knobSize, knob);
309 xPos += knobSize + knobSpacing;
311 yPos += knobSize + knobLabelHeight;
313 yPos += sectionSpacing;
314 firstEffectY = yPos + lineHeight + 6;
315 yPos = drawObjectList(yPos, "FX", effects, effectNames, effectStateMethod);
316 yPos += controlSpacing;
317 firstEffectKnobY = yPos;
319 for (VirtualEffectKnob knob : glucose.effectKnobs) {
320 drawKnob(xPos, yPos, knobSize, knob);
321 xPos += knobSize + knobSpacing;
323 yPos += knobSize + knobLabelHeight;
325 yPos += sectionSpacing;
326 yPos = drawObjectList(yPos, "TEMPO", null, null, null);
330 fill(tempoDown ? lightGreen : color(0, 0, 35 - 8*lx.tempo.rampf()));
331 rect(leftPos + 4, yPos, w - 8, tempoHeight);
334 text("" + ((int)(lx.tempo.bpmf() * 100) / 100.), leftPos + w/2., yPos + tempoHeight - 6);
337 drawToggleTip("Tap 'u' to hide");
340 public LXParameter getOrNull(List<LXParameter> items, int index) {
341 if (index < items.size()) {
342 return items.get(index);
347 public int getState(LXPattern p) {
348 if (p == lx.getPattern()) {
350 } else if (p == lx.getNextPattern()) {
351 return STATE_PENDING;
353 return STATE_DEFAULT;
356 public int getState(LXEffect e) {
358 return STATE_PENDING;
359 } else if (e == glucose.getSelectedEffect()) {
362 return STATE_DEFAULT;
365 public int getState(LXTransition t) {
366 if (t == lx.getTransition()) {
367 return STATE_PENDING;
368 } else if (t == glucose.getSelectedTransition()) {
371 return STATE_DEFAULT;
374 private void drawKnob(int xPos, int yPos, int knobSize, LXParameter knob) {
375 final float knobValue = knob.getValuef();
376 String knobLabel = knob.getLabel();
377 if (knobLabel == null) {
379 } else if (knobLabel.length() > 4) {
380 knobLabel = knobLabel.substring(0, 4);
386 // For some reason this arc call really crushes drawing performance. Presumably
387 // because openGL is drawing it and when we overlap the second set of arcs it
388 // does a bunch of depth buffer intersection tests? Ellipse with a trapezoid cut out is faster
389 // arc(xPos + knobSize/2, yPos + knobSize/2, knobSize, knobSize, HALF_PI + knobIndent, HALF_PI + knobIndent + (TWO_PI-2*knobIndent));
390 ellipse(xPos + knobSize/2, yPos + knobSize/2, knobSize, knobSize);
392 float endArc = HALF_PI + knobIndent + (TWO_PI-2*knobIndent)*knobValue;
394 arc(xPos + knobSize/2, yPos + knobSize/2, knobSize, knobSize, HALF_PI + knobIndent, endArc);
396 // Mask notch out of knob
397 fill(color(0, 0, 30));
399 vertex(xPos + knobSize/2, yPos + knobSize/2.);
400 vertex(xPos + knobSize/2 - 6, yPos + knobSize);
401 vertex(xPos + knobSize/2 + 6, yPos + knobSize);
404 // Center circle of knob
406 ellipse(xPos + knobSize/2, yPos + knobSize/2, knobSize/2, knobSize/2);
409 rect(xPos, yPos + knobSize + 2, knobSize, knobLabelHeight - 2);
413 text(knobLabel, xPos + knobSize/2, yPos + knobSize + knobLabelHeight - 2);
416 private int patternKnobIndex = -1;
417 private int transitionKnobIndex = -1;
418 private int effectKnobIndex = -1;
419 private boolean patternScrolling = false;
422 private int releaseEffect = -1;
423 private boolean tempoDown = false;
425 public void mousePressed() {
427 patternKnobIndex = transitionKnobIndex = effectKnobIndex = -1;
429 patternScrolling = false;
431 for (int p = 0; p < pandaLeft.length; ++p) {
432 int xp = pandaLeft[p];
433 if ((mouseX >= xp) &&
434 (mouseX < xp + pandaWidth) &&
435 (mouseY >= pandaTop) &&
436 (mouseY < pandaTop + pandaHeight)) {
437 pandaBoards[p].toggle();
441 if (mouseX < leftPos) {
445 if ((mouseX >= autoRotateX) &&
446 (mouseX < autoRotateX + toggleButtonSize) &&
447 (mouseY >= autoRotateY) &&
448 (mouseY < autoRotateY + toggleButtonSize)) {
449 if (lx.isAutoTransitionEnabled()) {
450 lx.disableAutoTransition();
451 println("Auto pattern transition disabled");
453 lx.enableAutoTransition(60000);
454 println("Auto pattern transition enabled");
459 if (mouseY > tempoY) {
460 if (mouseY - tempoY < tempoHeight) {
464 } else if ((mouseY >= firstEffectKnobY) && (mouseY < firstEffectKnobY + knobSize + knobLabelHeight)) {
465 effectKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
466 } else if (mouseY > firstEffectY) {
467 int effectIndex = objectClickIndex(firstEffectY);
468 if (effectIndex < effects.length) {
469 if (effects[effectIndex] == glucose.getSelectedEffect()) {
470 effects[effectIndex].enable();
471 releaseEffect = effectIndex;
473 glucose.setSelectedEffect(effectIndex);
475 } else if ((mouseY >= firstTransitionKnobY) && (mouseY < firstTransitionKnobY + knobSize + knobLabelHeight)) {
476 transitionKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
477 } else if (mouseY > firstTransitionY) {
478 int transitionIndex = objectClickIndex(firstTransitionY);
479 if (transitionIndex < transitions.length) {
480 glucose.setSelectedTransition(transitionIndex);
482 } else if ((mouseY >= firstPatternKnobY) && (mouseY < firstPatternKnobY + 2*(knobSize+knobLabelHeight) + knobSpacing)) {
483 patternKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
484 if (mouseY >= firstPatternKnobY + knobSize + knobLabelHeight + knobSpacing) {
485 patternKnobIndex += glucose.NUM_PATTERN_KNOBS / 2;
487 } else if (mouseY > firstPatternY) {
488 if ((patterns.length > PATTERN_LIST_LENGTH) && (mouseX > width - scrollWidth)) {
489 patternScrolling = true;
491 int patternIndex = objectClickIndex(firstPatternY);
492 if (patternIndex < patterns.length) {
493 if (lx.isAutoTransitionEnabled() && (mouseX > eligibleLeft)) {
494 patterns[patternIndex + patternScrollPos].toggleEligible();
496 lx.goIndex(patternIndex + patternScrollPos);
504 public void mouseDragged() {
505 int dy = lastY - mouseY;
508 if (patternKnobIndex >= 0 && patternKnobIndex < glucose.NUM_PATTERN_KNOBS) {
509 LXParameter p = glucose.patternKnobs.get(patternKnobIndex);
510 p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
511 } else if (effectKnobIndex >= 0 && effectKnobIndex < glucose.NUM_EFFECT_KNOBS) {
512 LXParameter p = glucose.effectKnobs.get(effectKnobIndex);
513 p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
514 } else if (transitionKnobIndex >= 0 && transitionKnobIndex < glucose.NUM_TRANSITION_KNOBS) {
515 LXParameter p = glucose.transitionKnobs.get(transitionKnobIndex);
516 p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
517 } else if (patternScrolling) {
518 int scroll = scrolldy / lineHeight;
519 scrolldy = scrolldy % lineHeight;
520 patternScrollPos = constrain(patternScrollPos - scroll, 0, patterns.length - PATTERN_LIST_LENGTH);
524 public void mouseReleased() {
525 patternScrolling = false;
527 if (releaseEffect >= 0) {
528 effects[releaseEffect].trigger();
533 public void mouseWheel(int delta) {
534 if (mouseY > firstPatternY) {
535 int patternIndex = objectClickIndex(firstPatternY);
536 if (patternIndex < PATTERN_LIST_LENGTH) {
537 patternScrollPos = constrain(patternScrollPos + delta, 0, patterns.length - PATTERN_LIST_LENGTH);
545 * UI for control of mapping.
547 class MappingUI extends OverlayUI {
549 private MappingTool mappingTool;
551 private final String MAPPING_MODE_ALL = "All On";
552 private final String MAPPING_MODE_CHANNEL = "Channel";
553 private final String MAPPING_MODE_SINGLE_CUBE = "Single Cube";
555 private final String[] mappingModes = {
557 MAPPING_MODE_CHANNEL,
558 MAPPING_MODE_SINGLE_CUBE
560 private final Method mappingModeStateMethod;
562 private final String CUBE_MODE_ALL = "All Strips";
563 private final String CUBE_MODE_SINGLE_STRIP = "Single Strip";
564 private final String CUBE_MODE_STRIP_PATTERN = "Strip Pattern";
565 private final String[] cubeModes = {
567 CUBE_MODE_SINGLE_STRIP,
568 CUBE_MODE_STRIP_PATTERN
570 private final Method cubeModeStateMethod;
572 private final String CHANNEL_MODE_RED = "Red";
573 private final String CHANNEL_MODE_GREEN = "Green";
574 private final String CHANNEL_MODE_BLUE = "Blue";
575 private final String[] channelModes = {
580 private final Method channelModeStateMethod;
582 private int firstMappingY;
583 private int firstCubeY;
584 private int firstChannelY;
585 private int channelFieldY;
586 private int cubeFieldY;
587 private int stripFieldY;
589 private boolean dragCube;
590 private boolean dragStrip;
591 private boolean dragChannel;
593 MappingUI(MappingTool mappingTool) {
594 this.mappingTool = mappingTool;
596 mappingModeStateMethod = getClass().getMethod("getMappingState", Object.class);
597 channelModeStateMethod = getClass().getMethod("getChannelState", Object.class);
598 cubeModeStateMethod = getClass().getMethod("getCubeState", Object.class);
599 } catch (Exception x) {
600 throw new RuntimeException(x);
604 public int getMappingState(Object mappingMode) {
605 boolean active = false;
606 if (mappingMode == MAPPING_MODE_ALL) {
607 active = mappingTool.mappingMode == mappingTool.MAPPING_MODE_ALL;
608 } else if (mappingMode == MAPPING_MODE_CHANNEL) {
609 active = mappingTool.mappingMode == mappingTool.MAPPING_MODE_CHANNEL;
610 } else if (mappingMode == MAPPING_MODE_SINGLE_CUBE) {
611 active = mappingTool.mappingMode == mappingTool.MAPPING_MODE_SINGLE_CUBE;
613 return active ? STATE_ACTIVE : STATE_DEFAULT;
616 public int getChannelState(Object channelMode) {
617 boolean active = false;
618 if (channelMode == CHANNEL_MODE_RED) {
619 active = mappingTool.channelModeRed;
620 } else if (channelMode == CHANNEL_MODE_GREEN) {
621 active = mappingTool.channelModeGreen;
622 } else if (channelMode == CHANNEL_MODE_BLUE) {
623 active = mappingTool.channelModeBlue;
625 return active ? STATE_ACTIVE : STATE_DEFAULT;
628 public int getCubeState(Object cubeMode) {
629 boolean active = false;
630 if (cubeMode == CUBE_MODE_ALL) {
631 active = mappingTool.cubeMode == mappingTool.CUBE_MODE_ALL;
632 } else if (cubeMode == CUBE_MODE_SINGLE_STRIP) {
633 active = mappingTool.cubeMode == mappingTool.CUBE_MODE_SINGLE_STRIP;
634 } else if (cubeMode == CUBE_MODE_STRIP_PATTERN) {
635 active = mappingTool.cubeMode == mappingTool.CUBE_MODE_STRIP_PATTERN;
637 return active ? STATE_ACTIVE : STATE_DEFAULT;
641 drawLogoAndBackground();
644 firstMappingY = yPos + lineHeight + 6;
645 yPos = drawObjectList(yPos, "MAPPING MODE", mappingModes, mappingModes, mappingModeStateMethod);
646 yPos += sectionSpacing;
648 firstCubeY = yPos + lineHeight + 6;
649 yPos = drawObjectList(yPos, "CUBE MODE", cubeModes, cubeModes, cubeModeStateMethod);
650 yPos += sectionSpacing;
652 firstChannelY = yPos + lineHeight + 6;
653 yPos = drawObjectList(yPos, "CHANNELS", channelModes, channelModes, channelModeStateMethod);
654 yPos += sectionSpacing;
656 channelFieldY = yPos + lineHeight + 6;
657 yPos = drawValueField(yPos, "CHANNEL ID", mappingTool.channelIndex + 1);
658 yPos += sectionSpacing;
660 cubeFieldY = yPos + lineHeight + 6;
661 yPos = drawValueField(yPos, "CUBE ID", glucose.model.getRawIndexForCube(mappingTool.cubeIndex));
662 yPos += sectionSpacing;
664 stripFieldY = yPos + lineHeight + 6;
665 yPos = drawValueField(yPos, "STRIP ID", mappingTool.stripIndex + 1);
667 drawToggleTip("Tap 'm' to return");
670 private int drawValueField(int yPos, String label, int value) {
675 text(label, leftTextPos, yPos);
678 rect(leftTextPos, yPos, w-8, lineHeight);
684 text("" + value, leftTextPos + (w-8)/2, yPos - 5);
691 public void mousePressed() {
692 dragCube = dragStrip = dragChannel = false;
695 if (mouseX < leftPos) {
699 if (mouseY >= stripFieldY) {
700 if (mouseY < stripFieldY + lineHeight) {
703 } else if (mouseY >= cubeFieldY) {
704 if (mouseY < cubeFieldY + lineHeight) {
707 } else if (mouseY >= channelFieldY) {
708 if (mouseY < channelFieldY + lineHeight) {
711 } else if (mouseY >= firstChannelY) {
712 int index = objectClickIndex(firstChannelY);
714 case 0: mappingTool.channelModeRed = !mappingTool.channelModeRed; break;
715 case 1: mappingTool.channelModeGreen = !mappingTool.channelModeGreen; break;
716 case 2: mappingTool.channelModeBlue = !mappingTool.channelModeBlue; break;
718 } else if (mouseY >= firstCubeY) {
719 int index = objectClickIndex(firstCubeY);
721 case 0: mappingTool.cubeMode = mappingTool.CUBE_MODE_ALL; break;
722 case 1: mappingTool.cubeMode = mappingTool.CUBE_MODE_SINGLE_STRIP; break;
723 case 2: mappingTool.cubeMode = mappingTool.CUBE_MODE_STRIP_PATTERN; break;
725 } else if (mouseY >= firstMappingY) {
726 int index = objectClickIndex(firstMappingY);
728 case 0: mappingTool.mappingMode = mappingTool.MAPPING_MODE_ALL; break;
729 case 1: mappingTool.mappingMode = mappingTool.MAPPING_MODE_CHANNEL; break;
730 case 2: mappingTool.mappingMode = mappingTool.MAPPING_MODE_SINGLE_CUBE; break;
735 public void mouseReleased() {}
736 public void mouseWheel(int delta) {}
738 public void mouseDragged() {
739 final int DRAG_THRESHOLD = 5;
740 int dy = lastY - mouseY;
741 if (abs(dy) >= DRAG_THRESHOLD) {
745 mappingTool.decCube();
747 mappingTool.incCube();
749 } else if (dragStrip) {
751 mappingTool.decStrip();
753 mappingTool.incStrip();
755 } else if (dragChannel) {
757 mappingTool.decChannel();
759 mappingTool.incChannel();
769 final ChannelMapping[] channelList;
770 final int debugX = 5;
771 final int debugY = 5;
772 final int debugXSpacing = 28;
773 final int debugYSpacing = 21;
774 final int[][] debugState;
775 final int[] indexState;
777 final int CUBE_STATE_UNUSED = 0;
778 final int CUBE_STATE_USED = 1;
779 final int CUBE_STATE_DUPLICATED = 2;
781 final int DEBUG_STATE_ANIM = 0;
782 final int DEBUG_STATE_WHITE = 1;
783 final int DEBUG_STATE_OFF = 2;
784 final int DEBUG_STATE_UNUSED = 3;
786 DebugUI(PandaMapping[] pandaMappings) {
787 int totalChannels = pandaMappings.length * PandaMapping.CHANNELS_PER_BOARD;
788 debugState = new int[totalChannels+1][ChannelMapping.CUBES_PER_CHANNEL+1];
789 indexState = new int[glucose.model.cubes.size()+1];
791 channelList = new ChannelMapping[totalChannels];
792 int channelIndex = 0;
793 for (PandaMapping pm : pandaMappings) {
794 for (ChannelMapping channel : pm.channelList) {
795 channelList[channelIndex++] = channel;
798 for (int i = 0; i < debugState.length; ++i) {
799 for (int j = 0; j < debugState[i].length; ++j) {
800 debugState[i][j] = DEBUG_STATE_ANIM;
804 for (int rawIndex = 0; rawIndex < glucose.model.cubes.size()+1; ++rawIndex) {
805 indexState[rawIndex] = CUBE_STATE_UNUSED;
807 for (ChannelMapping channel : channelList) {
808 for (int rawCubeIndex : channel.objectIndices) {
809 if (rawCubeIndex > 0)
810 ++indexState[rawCubeIndex];
821 rect(0, 0, debugX + 5*debugXSpacing, height);
824 for (ChannelMapping channel : channelList) {
826 drawNumBox(xPos, yPos, channelNum+1, debugState[channelNum][0]);
827 xPos += debugXSpacing;
829 switch (channel.mode) {
830 case ChannelMapping.MODE_CUBES:
832 boolean first = true;
833 for (int rawCubeIndex : channel.objectIndices) {
834 if (rawCubeIndex < 0) {
841 line(xPos - 12, yPos + 8, xPos, yPos + 8);
843 drawNumBox(xPos, yPos, rawCubeIndex, debugState[channelNum][stateIndex+1], indexState[rawCubeIndex]);
845 xPos += debugXSpacing;
848 case ChannelMapping.MODE_BASS:
849 drawNumBox(xPos, yPos, "B", debugState[channelNum][1]);
851 case ChannelMapping.MODE_SPEAKER:
852 drawNumBox(xPos, yPos, "S" + channel.objectIndices[0], debugState[channelNum][1]);
854 case ChannelMapping.MODE_STRUTS_AND_FLOOR:
855 drawNumBox(xPos, yPos, "F", debugState[channelNum][1]);
857 case ChannelMapping.MODE_NULL:
860 throw new RuntimeException("Unhandled channel mapping mode: " + channel.mode);
863 yPos += debugYSpacing;
866 drawNumBox(xBase, yPos, "A", debugState[channelNum][0]);
867 yPos += debugYSpacing * 2;
871 text("Unused Cubes", xBase, yPos + 12);
872 yPos += debugYSpacing;
875 for (int rawIndex = 1; rawIndex <= glucose.model.cubes.size(); ++rawIndex) {
876 if (indexState[rawIndex] == CUBE_STATE_UNUSED) {
877 drawNumBox(xBase + (xIndex * debugXSpacing), yPos, rawIndex, DEBUG_STATE_UNUSED);
881 yPos += debugYSpacing + 2;
888 void drawNumBox(int xPos, int yPos, int label, int state) {
889 drawNumBox(xPos, yPos, "" + label, state);
892 void drawNumBox(int xPos, int yPos, String label, int state) {
893 drawNumBox(xPos, yPos, "" + label, state, CUBE_STATE_USED);
896 void drawNumBox(int xPos, int yPos, int label, int state, int cubeState) {
897 drawNumBox(xPos, yPos, "" + label, state, cubeState);
900 void drawNumBox(int xPos, int yPos, String label, int state, int cubeState) {
902 color textColor = #cccccc;
904 case DEBUG_STATE_ANIM:
907 rect(xPos, yPos, 16, 8);
909 rect(xPos, yPos+8, 16, 8);
913 case DEBUG_STATE_WHITE:
918 case DEBUG_STATE_OFF:
921 case DEBUG_STATE_UNUSED:
927 if (cubeState >= CUBE_STATE_DUPLICATED) {
928 stroke(textColor = #FF0000);
931 rect(xPos, yPos, 16, 16);
934 text(label, xPos + 2, yPos + 12);
937 void maskColors(color[] colors) {
938 color white = #FFFFFF;
940 int channelIndex = 0;
942 for (ChannelMapping channel : channelList) {
943 switch (channel.mode) {
944 case ChannelMapping.MODE_CUBES:
946 for (int rawCubeIndex : channel.objectIndices) {
947 if (rawCubeIndex >= 0) {
948 state = debugState[channelIndex][cubeIndex];
949 if (state != DEBUG_STATE_ANIM) {
950 color debugColor = (state == DEBUG_STATE_WHITE) ? white : off;
951 Cube cube = glucose.model.getCubeByRawIndex(rawCubeIndex);
952 for (Point p : cube.points) {
953 colors[p.index] = debugColor;
961 case ChannelMapping.MODE_BASS:
962 state = debugState[channelIndex][1];
963 if (state != DEBUG_STATE_ANIM) {
964 color debugColor = (state == DEBUG_STATE_WHITE) ? white : off;
965 for (Strip s : glucose.model.bassBox.boxStrips) {
966 for (Point p : s.points) {
967 colors[p.index] = debugColor;
973 case ChannelMapping.MODE_STRUTS_AND_FLOOR:
974 state = debugState[channelIndex][1];
975 if (state != DEBUG_STATE_ANIM) {
976 color debugColor = (state == DEBUG_STATE_WHITE) ? white : off;
977 for (Point p : glucose.model.boothFloor.points) {
978 colors[p.index] = debugColor;
980 for (Strip s : glucose.model.bassBox.struts) {
981 for (Point p : s.points) {
982 colors[p.index] = debugColor;
988 case ChannelMapping.MODE_SPEAKER:
989 state = debugState[channelIndex][1];
990 if (state != DEBUG_STATE_ANIM) {
991 color debugColor = (state == DEBUG_STATE_WHITE) ? white : off;
992 for (Point p : glucose.model.speakers.get(channel.objectIndices[0]).points) {
993 colors[p.index] = debugColor;
998 case ChannelMapping.MODE_NULL:
1002 throw new RuntimeException("Unhandled channel mapping mode: " + channel.mode);
1008 void mousePressed() {
1009 int dx = (mouseX - debugX) / debugXSpacing;
1010 int dy = (mouseY - debugY) / debugYSpacing;
1011 if ((dy >= 0) && (dy < debugState.length)) {
1012 if ((dx >= 0) && (dx < debugState[dy].length)) {
1013 int newState = debugState[dy][dx] = (debugState[dy][dx] + 1) % 3;
1014 if (dy == debugState.length-1) {
1015 for (int[] states : debugState) {
1016 for (int i = 0; i < states.length; ++i) {
1017 states[i] = newState;
1020 } else if (dx == 0) {
1021 for (int i = 0; i < debugState[dy].length; ++i) {
1022 debugState[dy][i] = newState;