Few tiny cleanups
[SugarCubes.git] / _UIImplementation.pde
index c749ad4b891e72f12ed00c87e992ba96f2d4c827..ba0f110bc826a00aec85ce91e1b7ad52e9520c37 100644 (file)
  * Custom UI components using the framework.
  */
 
+class UICubesLayer extends UICameraComponent {
+  void onDraw(UI ui) {
+    color[] simulationColors = lx.getColors();
+    String displayMode = uiCrossfader.getDisplayMode();
+    if (displayMode == "A") {
+      simulationColors = lx.engine.getDeck(LEFT_DECK).getColors();
+    } else if (displayMode == "B") {
+      simulationColors = lx.engine.getDeck(RIGHT_DECK).getColors();
+    }
+
+    long simulationStart = System.nanoTime();
+    if (simulationOn) {
+      drawSimulation(simulationColors);
+    }
+    simulationNanos = System.nanoTime() - simulationStart;
+    
+    camera();
+    javax.media.opengl.GL gl = ((PGraphicsOpenGL)g).beginGL();
+    gl.glClear(javax.media.opengl.GL.GL_DEPTH_BUFFER_BIT);
+    ((PGraphicsOpenGL)g).endGL();
+    strokeWeight(1);
+  }
+  
+  void drawSimulation(color[] simulationColors) {
+    translate(0, 30, 0);
+  
+    noStroke();
+    fill(#141414);
+    drawBox(0, -TRAILER_HEIGHT, 0, 0, 0, 0, TRAILER_WIDTH, TRAILER_HEIGHT, TRAILER_DEPTH, TRAILER_HEIGHT/2.);
+    fill(#070707);
+    stroke(#222222);
+    beginShape();
+    vertex(0, 0, 0);
+    vertex(TRAILER_WIDTH, 0, 0);
+    vertex(TRAILER_WIDTH, 0, TRAILER_DEPTH);
+    vertex(0, 0, TRAILER_DEPTH);
+    endShape();
+  
+    // Draw the logo on the front of platform  
+    pushMatrix();
+    translate(0, 0, -1);
+    float s = .07;
+    scale(s, -s, s);
+    image(logo, TRAILER_WIDTH/2/s-logo.width/2, TRAILER_HEIGHT/2/s-logo.height/2-2/s);
+    popMatrix();
+    
+    noStroke();
+    for (Cube c : model.cubes) {
+      drawCube(c);
+    }
+  
+    noFill();
+    strokeWeight(2);
+    beginShape(POINTS);
+    for (LXPoint p : model.points) {
+      stroke(simulationColors[p.index]);
+      vertex(p.x, p.y, p.z);
+    }
+    endShape();
+  }
+  
+  void drawCube(Cube c) {
+    float in = .15;
+    noStroke();
+    fill(#393939);  
+    drawBox(c.x+in, c.y+in, c.z+in, c.rx, c.ry, c.rz, Cube.EDGE_WIDTH-in*2, Cube.EDGE_HEIGHT-in*2, Cube.EDGE_WIDTH-in*2, Cube.CHANNEL_WIDTH-in);
+  }
+  
+  void drawBox(float x, float y, float z, float rx, float ry, float rz, float xd, float yd, float zd, float sw) {
+    pushMatrix();
+    translate(x, y, z);
+    rotate(rx / 180. * PI, -1, 0, 0);
+    rotate(ry / 180. * PI, 0, -1, 0);
+    rotate(rz / 180. * PI, 0, 0, -1);
+    for (int i = 0; i < 4; ++i) {
+      float wid = (i % 2 == 0) ? xd : zd;
+      
+      beginShape();
+      vertex(0, 0);
+      vertex(wid, 0);
+      vertex(wid, yd);
+      vertex(wid - sw, yd);
+      vertex(wid - sw, sw);
+      vertex(0, sw);
+      endShape();
+      beginShape();
+      vertex(0, sw);
+      vertex(0, yd);
+      vertex(wid - sw, yd);
+      vertex(wid - sw, yd - sw);
+      vertex(sw, yd - sw);
+      vertex(sw, sw);
+      endShape();
+  
+      translate(wid, 0, 0);
+      rotate(HALF_PI, 0, -1, 0);
+    }
+    popMatrix();
+  }
+}
+
 class UIBlendMode extends UIWindow {
   public UIBlendMode(float x, float y, float w, float h) {
     super(lx.ui, "BLEND MODE", x, y, w, h);
     List<UIScrollList.Item> items = new ArrayList<UIScrollList.Item>();
-    for (LXTransition t : glucose.getTransitions()) {
+    for (LXTransition t : transitions) {
       items.add(new TransitionScrollItem(t));
     }
     final UIScrollList tList;
     (tList = new UIScrollList(1, UIWindow.TITLE_LABEL_HEIGHT, w-2, 60)).setItems(items).addToContainer(this);
 
-    lx.engine.getDeck(GLucose.RIGHT_DECK).addListener(new LXDeck.AbstractListener() {
+    lx.engine.getDeck(RIGHT_DECK).addListener(new LXDeck.AbstractListener() {
       public void faderTransitionDidChange(LXDeck deck, LXTransition transition) {
         tList.redraw();
       }
@@ -30,11 +131,11 @@ class UIBlendMode extends UIWindow {
 
   class TransitionScrollItem extends UIScrollList.AbstractItem {
     private final LXTransition transition;
-    private String label;
+    private final String label;
     
     TransitionScrollItem(LXTransition transition) {
       this.transition = transition;
-      label = className(transition, "Transition");
+      this.label = className(transition, "Transition");
     }
     
     public String getLabel() {
@@ -42,7 +143,7 @@ class UIBlendMode extends UIWindow {
     }
     
     public boolean isSelected() {
-      return transition == glucose.getSelectedTransition();
+      return this.transition == lx.engine.getDeck(RIGHT_DECK).getFaderTransition();
     }
     
     public boolean isPending() {
@@ -50,7 +151,7 @@ class UIBlendMode extends UIWindow {
     }
     
     public void onMousePressed() {
-      glucose.setSelectedTransition(transition);
+      lx.engine.getDeck(RIGHT_DECK).setFaderTransition(this.transition);
     }
   }
 
@@ -63,7 +164,7 @@ class UICrossfader extends UIWindow {
   public UICrossfader(float x, float y, float w, float h) {
     super(lx.ui, "CROSSFADER", x, y, w, h);
 
-    new UISlider(4, UIWindow.TITLE_LABEL_HEIGHT, w-9, 32).setParameter(lx.engine.getDeck(GLucose.RIGHT_DECK).getFader()).addToContainer(this);
+    new UISlider(4, UIWindow.TITLE_LABEL_HEIGHT, w-9, 32).setParameter(lx.engine.getDeck(RIGHT_DECK).getFader()).addToContainer(this);
     (displayMode = new UIToggleSet(4, UIWindow.TITLE_LABEL_HEIGHT + 36, w-9, 20)).setOptions(new String[] { "A", "COMP", "B" }).setValue("COMP").addToContainer(this);
   }
   
@@ -83,8 +184,9 @@ class UIEffects extends UIWindow {
 
     int yp = UIWindow.TITLE_LABEL_HEIGHT;
     List<UIScrollList.Item> items = new ArrayList<UIScrollList.Item>();
-    for (LXEffect fx : glucose.lx.getEffects()) {
-      items.add(new FXScrollItem(fx));
+    int i = 0;
+    for (LXEffect fx : effectsArr) {
+      items.add(new FXScrollItem(fx, i++));
     }    
     final UIScrollList effectsList = new UIScrollList(1, yp, w-2, 60).setItems(items);
     effectsList.addToContainer(this);
@@ -96,10 +198,10 @@ class UIEffects extends UIWindow {
       parameterKnobs[ki].addToContainer(this);
     }
     
-    GLucose.EffectListener fxListener = new GLucose.EffectListener() {
-      public void effectSelected(LXEffect effect) {
+    LXParameterListener fxListener = new LXParameterListener() {
+      public void onParameterChanged(LXParameter parameter) {
         int i = 0;
-        for (LXParameter p : effect.getParameters()) {
+        for (LXParameter p : getSelectedEffect().getParameters()) {
           if (i >= parameterKnobs.length) {
             break;
           }
@@ -113,19 +215,21 @@ class UIEffects extends UIWindow {
       }
     };
     
-    glucose.addEffectListener(fxListener);
-    fxListener.effectSelected(glucose.getSelectedEffect());
+    selectedEffect.addListener(fxListener);
+    fxListener.onParameterChanged(null);
 
   }
   
   class FXScrollItem extends UIScrollList.AbstractItem {
     
-    private LXEffect effect;
-    private String label;
+    private final LXEffect effect;
+    private final int index;
+    private final String label;
     
-    FXScrollItem(LXEffect effect) {
+    FXScrollItem(LXEffect effect, int index) {
       this.effect = effect;
-      label = className(effect, "Effect");
+      this.index = index;
+      this.label = className(effect, "Effect");
     }
     
     public String getLabel() {
@@ -133,7 +237,7 @@ class UIEffects extends UIWindow {
     }
     
     public boolean isSelected() {
-      return !effect.isEnabled() && (glucose.getSelectedEffect() == effect);
+      return !effect.isEnabled() && (effect == getSelectedEffect());
     }
     
     public boolean isPending() {
@@ -141,14 +245,14 @@ class UIEffects extends UIWindow {
     }
     
     public void onMousePressed() {
-      if (glucose.getSelectedEffect() == effect) {
+      if (effect == getSelectedEffect()) {
         if (effect.isMomentary()) {
           effect.enable();
         } else {
           effect.toggle();
         }
       } else {
-        glucose.setSelectedEffect(effect);
+        selectedEffect.setValue(index);
       }
     }
     
@@ -197,7 +301,7 @@ class UIOutput extends UIWindow {
     }
     
     public void onMousePressed() {
-      output.enabled.setOn(!isSelected());
+      output.enabled.setValue(!isSelected());
     }
   } 
 }
@@ -282,7 +386,7 @@ class UIMapping extends UIWindow {
       protected void onValueChange(int value) {
         mappingTool.setCube(value-1);
       }
-    }).setRange(1, glucose.model.cubes.size()).addToContainer(this);
+    }).setRange(1, model.cubes.size()).addToContainer(this);
     yp += 24;
     
     yp += 10;
@@ -468,7 +572,7 @@ class UIMidi extends UIWindow {
   }
   
   public LXDeck getFocusedDeck() {
-    return lx.engine.getDeck(deckMode.getValue() == "A" ? GLucose.LEFT_DECK : GLucose.RIGHT_DECK);
+    return lx.engine.getDeck(deckMode.getValue() == "A" ? LEFT_DECK : RIGHT_DECK);
   }
 }