Add mappings for panda board UI and PandaDriver class
[SugarCubes.git] / _Overlay.pde
index e21c9cdff0f5f4bd222ace65c4d2b770e7680edd..acf8505f7dc995833ecd67681dbb2a7e6627b7e3 100644 (file)
@@ -1,4 +1,15 @@
+import java.lang.reflect.*;
+
 /**
+ *     DOUBLE BLACK DIAMOND        DOUBLE BLACK DIAMOND
+ *
+ *         //\\   //\\                 //\\   //\\  
+ *        ///\\\ ///\\\               ///\\\ ///\\\
+ *        \\\/// \\\///               \\\/// \\\///
+ *         \\//   \\//                 \\//   \\//
+ *
+ *        EXPERTS ONLY!!              EXPERTS ONLY!!
+ *
  * Overlay UI that indicates pattern control, etc. This will be moved
  * into the Processing library once it is stabilized and need not be
  * regularly modified.
@@ -41,14 +52,16 @@ class OverlayUI {
   private Method transitionStateMethod;
   private Method effectStateMethod;
   
+  private final int NUM_PATTERN_KNOBS = 8;
   private final int NUM_TRANSITION_KNOBS = 4;
   private final int NUM_EFFECT_KNOBS = 4;
   
   private int activeTransitionIndex = 0;
   private int activeEffectIndex = 0;
   
-  private final VirtualTransitionKnob[] transitionKnobs;
-  private final VirtualEffectKnob[] effectKnobs;
+  public final VirtualPatternKnob[] patternKnobs;
+  public final VirtualTransitionKnob[] transitionKnobs;
+  public final VirtualEffectKnob[] effectKnobs;
     
   OverlayUI() {
     leftPos = width - w;
@@ -59,6 +72,11 @@ class OverlayUI {
     transitionNames = classNameArray(transitions, "Transition");
     effectNames = classNameArray(effects, "Effect");
 
+    patternKnobs = new VirtualPatternKnob[NUM_PATTERN_KNOBS];
+    for (int i = 0; i < patternKnobs.length; ++i) {
+      patternKnobs[i] = new VirtualPatternKnob(i);
+    }
+
     transitionKnobs = new VirtualTransitionKnob[NUM_TRANSITION_KNOBS];
     for (int i = 0; i < transitionKnobs.length; ++i) {
       transitionKnobs[i] = new VirtualTransitionKnob(i);
@@ -98,9 +116,9 @@ class OverlayUI {
     yPos += controlSpacing;
     firstPatternKnobY = yPos;
     int xPos = leftTextPos;
-    for (int i = 0; i < glucose.NUM_PATTERN_KNOBS/2; ++i) {
-      drawKnob(xPos, yPos, knobSize, glucose.patternKnobs[i]);
-      drawKnob(xPos, yPos + knobSize + knobSpacing + knobLabelHeight, knobSize, glucose.patternKnobs[glucose.NUM_PATTERN_KNOBS/2 + i]);
+    for (int i = 0; i < NUM_PATTERN_KNOBS/2; ++i) {
+      drawKnob(xPos, yPos, knobSize, patternKnobs[i]);
+      drawKnob(xPos, yPos + knobSize + knobSpacing + knobLabelHeight, knobSize, patternKnobs[NUM_PATTERN_KNOBS/2 + i]);
       xPos += knobSize + knobSpacing;
     }
     yPos += 2*(knobSize + knobLabelHeight) + knobSpacing;
@@ -144,7 +162,7 @@ class OverlayUI {
     fill(#999999);
     textFont(itemFont);
     textAlign(LEFT);
-    text("Tap 'u' to hide UI (~+3FPS)", leftTextPos, height-6);
+    text("Tap 'u' to hide UI", leftTextPos, height-6);
   }
   
   public LXParameter getOrNull(List<LXParameter> items, int index) {
@@ -250,6 +268,7 @@ class OverlayUI {
     }
     
     ellipseMode(CENTER);
+    noStroke();
     fill(#222222);
     // For some reason this arc call really crushes drawing performance. Presumably
     // because openGL is drawing it and when we overlap the second set of arcs it
@@ -261,18 +280,17 @@ class OverlayUI {
     fill(lightGreen);
     arc(xPos + knobSize/2, yPos + knobSize/2, knobSize, knobSize, HALF_PI + knobIndent, endArc);
     
-    // Center circle of knob
-    fill(#333333);
-    ellipse(xPos + knobSize/2, yPos + knobSize/2, knobSize/2, knobSize/2);
-
     // Mask notch out of knob
     fill(color(0, 0, 30));
     beginShape();
-    vertex(xPos + knobSize/2 - 3, yPos + knobSize - 8);
-    vertex(xPos + knobSize/2 - 5, yPos + knobSize);
-    vertex(xPos + knobSize/2 + 5, yPos + knobSize);
-    vertex(xPos + knobSize/2 + 3, yPos + knobSize - 8);
+    vertex(xPos + knobSize/2, yPos + knobSize/2.);
+    vertex(xPos + knobSize/2 - 6, yPos + knobSize);
+    vertex(xPos + knobSize/2 + 6, yPos + knobSize);
     endShape();
+
+    // Center circle of knob
+    fill(#333333);
+    ellipse(xPos + knobSize/2, yPos + knobSize/2, knobSize/2, knobSize/2);    
     
     fill(0);
     rect(xPos, yPos + knobSize + 2, knobSize, knobLabelHeight - 2);
@@ -309,6 +327,22 @@ class OverlayUI {
     return s;
   }
 
+  class VirtualPatternKnob extends LXVirtualParameter {
+    private final int index;
+    
+    VirtualPatternKnob(int index) {
+      this.index = index;
+    }
+    
+    public LXParameter getRealParameter() {
+      List<LXParameter> parameters = glucose.getPattern().getParameters();
+      if (index < parameters.size()) {
+        return parameters.get(index);
+      }
+      return null;
+    }
+  }
+
   class VirtualTransitionKnob extends LXVirtualParameter {
     private final int index;
     
@@ -379,7 +413,7 @@ class OverlayUI {
     } else if ((mouseY >= firstPatternKnobY) && (mouseY < firstPatternKnobY + 2*(knobSize+knobLabelHeight) + knobSpacing)) {
       patternKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
       if (mouseY >= firstPatternKnobY + knobSize + knobLabelHeight + knobSpacing) {
-        patternKnobIndex += glucose.NUM_PATTERN_KNOBS / 2;
+        patternKnobIndex += NUM_PATTERN_KNOBS / 2;
       }      
     } else if (mouseY > firstPatternY) {
       int patternIndex = (mouseY - firstPatternY) / lineHeight;
@@ -393,8 +427,8 @@ class OverlayUI {
   public void mouseDragged() {
     int dy = lastY - mouseY;
     lastY = mouseY;
-    if (patternKnobIndex >= 0 && patternKnobIndex < glucose.NUM_PATTERN_KNOBS) {
-      LXParameter p = glucose.patternKnobs[patternKnobIndex];
+    if (patternKnobIndex >= 0 && patternKnobIndex < NUM_PATTERN_KNOBS) {
+      LXParameter p = patternKnobs[patternKnobIndex];
       p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
     } else if (effectKnobIndex >= 0 && effectKnobIndex < NUM_EFFECT_KNOBS) {
       LXParameter p = effectKnobs[effectKnobIndex];