Merge branch 'panda-refactor' of https://github.com/sugarcubes/SugarCubes
authorMark Slee <mcslee@Mark-Slees-MacBook-Pro.local>
Sat, 15 Jun 2013 02:09:05 +0000 (19:09 -0700)
committerMark Slee <mcslee@Mark-Slees-MacBook-Pro.local>
Sat, 15 Jun 2013 02:09:05 +0000 (19:09 -0700)
Conflicts:
_Internals.pde
_Overlay.pde
code/GLucose.jar

SugarCubes.pde
_Internals.pde
_Overlay.pde
code/GLucose.jar
code/HeronLX.jar

index 5504001bf88d3834f2d82b3b40f12340c35b00cf..3f6cc8f4e47494ad81954d9065c4fcc5c84985f8 100644 (file)
@@ -1,7 +1,7 @@
 /**
  *           +-+-+-+-+-+               +-+-+-+-+-+
  *          /         /|               |\         \
- *         /         / +               + \         \
+ *         /         / +               <+ \         \
  *        +-+-+-+-+-+  |   +-+-+-+-+   |  +-+-+-+-+-+
  *        |         |  +  /         \  +  |         |
  *        +   THE   + /  /           \  \ +  CUBES  +
index 4ab6f76d7d45be3bbc57266ad073f521466a610f..0249603b3f209e0fffc1013290aeca8a4368bcab 100644 (file)
@@ -51,6 +51,8 @@ boolean mappingMode = false;
 
 boolean pandaBoardsEnabled = false;
 
+boolean debugMode = false;
+
 void setup() {
   startMillis = lastMillis = millis();
 
@@ -64,6 +66,7 @@ void setup() {
   // Create the GLucose engine to run the cubes
   glucose = new GLucose(this, new SCMapping());
   lx = glucose.lx;
+  lx.enableKeyboardTempo();
   logTime("Built GLucose engine");
   
   // Set the patterns
@@ -71,7 +74,7 @@ void setup() {
   logTime("Built patterns");
   glucose.lx.addEffects(effects = effects(glucose));
   logTime("Built effects");
-  transitions = transitions(glucose);
+  glucose.setTransitions(transitions = transitions(glucose));
   logTime("Built transitions");
     
   // Build output driver
@@ -89,13 +92,34 @@ void setup() {
   logTime("Built overlay UI");
     
   // MIDI devices
-  SCMidiDevices.initializeStandardDevices(glucose, controlUI.patternKnobs, controlUI.transitionKnobs, controlUI.effectKnobs);
+  for (MidiInputDevice d : RWMidi.getInputDevices()) {
+    d.createInput(this);
+  }
+  SCMidiDevices.initializeStandardDevices(glucose);
   logTime("Setup MIDI devices");
   
   println("Total setup: " + (millis() - startMillis) + "ms");
   println("Hit the 'p' key to toggle Panda Board output");
 }
 
+void controllerChangeReceived(rwmidi.Controller cc) {
+  if (debugMode) {
+    println("CC: " + cc.toString());
+  }
+}
+
+void noteOnReceived(Note note) {
+  if (debugMode) {
+    println("Note On: " + note.toString());
+  }
+}
+
+void noteOffReceived(Note note) {
+  if (debugMode) {
+    println("Note Off: " + note.toString());
+  }
+}
+
 void logTime(String evt) {
   int now = millis();
   println(evt + ": " + (now - lastMillis) + "ms");
@@ -131,6 +155,9 @@ void keyPressed() {
     mappingTool.keyPressed();
   }
   switch (key) {
+    case 'd':
+      debugMode = !debugMode;
+      println("Debug output: " + (debugMode ? "ON" : "OFF"));
     case 'm':
       mappingMode = !mappingMode;
       if (mappingMode) {
index 06d106a255a4df53caaf2d484d0bb22196204c58..d33e4a14d33a9e4ac9318a3d6f1c48788d8f7d9b 100644 (file)
@@ -174,38 +174,12 @@ class ControlUI extends OverlayUI {
   private Method patternStateMethod;
   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;
-  
-  public final VirtualPatternKnob[] patternKnobs;
-  public final VirtualTransitionKnob[] transitionKnobs;
-  public final VirtualEffectKnob[] effectKnobs;
-      
+
   ControlUI() {    
     patternNames = classNameArray(patterns, "Pattern");
     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);
-    }
-
-    effectKnobs = new VirtualEffectKnob[NUM_EFFECT_KNOBS];
-    for (int i = 0; i < effectKnobs.length; ++i) {
-      effectKnobs[i] = new VirtualEffectKnob(i);
-    }
-
     try {
       patternStateMethod = getClass().getMethod("getState", LXPattern.class);
       effectStateMethod = getClass().getMethod("getState", LXEffect.class);
@@ -223,9 +197,9 @@ class ControlUI extends OverlayUI {
     yPos += controlSpacing;
     firstPatternKnobY = yPos;
     int xPos = leftTextPos;
-    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]);
+    for (int i = 0; i < glucose.NUM_PATTERN_KNOBS/2; ++i) {
+      drawKnob(xPos, yPos, knobSize, glucose.patternKnobs.get(i));
+      drawKnob(xPos, yPos + knobSize + knobSpacing + knobLabelHeight, knobSize, glucose.patternKnobs.get(glucose.NUM_PATTERN_KNOBS/2 + i));
       xPos += knobSize + knobSpacing;
     }
     yPos += 2*(knobSize + knobLabelHeight) + knobSpacing;
@@ -236,8 +210,8 @@ class ControlUI extends OverlayUI {
     yPos += controlSpacing;
     firstTransitionKnobY = yPos;
     xPos = leftTextPos;
-    for (int i = 0; i < transitionKnobs.length; ++i) {
-      drawKnob(xPos, yPos, knobSize, transitionKnobs[i]);
+    for (VirtualTransitionKnob knob : glucose.transitionKnobs) {
+      drawKnob(xPos, yPos, knobSize, knob);
       xPos += knobSize + knobSpacing;
     }
     yPos += knobSize + knobLabelHeight;
@@ -248,8 +222,8 @@ class ControlUI extends OverlayUI {
     yPos += controlSpacing;
     firstEffectKnobY = yPos;    
     xPos = leftTextPos;
-    for (int i = 0; i < effectKnobs.length; ++i) {
-      drawKnob(xPos, yPos, knobSize, effectKnobs[i]);
+    for (VirtualEffectKnob knob : glucose.effectKnobs) {    
+      drawKnob(xPos, yPos, knobSize, knob);
       xPos += knobSize + knobSpacing;
     }
     yPos += knobSize + knobLabelHeight;
@@ -288,7 +262,7 @@ class ControlUI extends OverlayUI {
   public int getState(LXEffect e) {
     if (e.isEnabled()) {
       return STATE_PENDING;
-    } else if (effects[activeEffectIndex] == e) {
+    } else if (e == glucose.getSelectedEffect()) {
       return STATE_ACTIVE;
     }
     return STATE_DEFAULT;
@@ -297,7 +271,7 @@ class ControlUI extends OverlayUI {
   public int getState(LXTransition t) {
     if (t == lx.getTransition()) {
       return STATE_PENDING;
-    } else if (t == transitions[activeTransitionIndex]) {
+    } else if (t == glucose.getSelectedTransition()) {
       return STATE_ACTIVE;
     }
     return STATE_DEFAULT;
@@ -344,54 +318,6 @@ class ControlUI extends OverlayUI {
     textFont(knobFont);
     text(knobLabel, xPos + knobSize/2, yPos + knobSize + knobLabelHeight - 2);
   }
-
-  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;
-    
-    VirtualTransitionKnob(int index) {
-      this.index = index;
-    }
-    
-    public LXParameter getRealParameter() {
-      List<LXParameter> parameters = transitions[activeTransitionIndex].getParameters();
-      if (index < parameters.size()) {
-        return parameters.get(index);
-      }
-      return null;
-    }
-  }
-
-  class VirtualEffectKnob extends LXVirtualParameter {
-    private final int index;
-    
-    VirtualEffectKnob(int index) {
-      this.index = index;
-    }
-    
-    public LXParameter getRealParameter() {
-      List<LXParameter> parameters = effects[activeEffectIndex].getParameters();
-      if (index < parameters.size()) {
-        return parameters.get(index);
-      }
-      return null;
-    }
-  }
   
   private int patternKnobIndex = -1;
   private int transitionKnobIndex = -1;
@@ -415,28 +341,27 @@ class ControlUI extends OverlayUI {
     } else if (mouseY > firstEffectY) {
       int effectIndex = objectClickIndex(firstEffectY);
       if (effectIndex < effects.length) {
-        if (activeEffectIndex == effectIndex) {
+        if (effects[effectIndex] == glucose.getSelectedEffect()) {
           effects[effectIndex].enable();
           releaseEffect = effectIndex;
         }
-        activeEffectIndex = effectIndex;        
+        glucose.setSelectedEffect(effectIndex);
       }
     } else if ((mouseY >= firstTransitionKnobY) && (mouseY < firstTransitionKnobY + knobSize + knobLabelHeight)) {
       transitionKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
     } else if (mouseY > firstTransitionY) {
       int transitionIndex = objectClickIndex(firstTransitionY);
       if (transitionIndex < transitions.length) {
-        activeTransitionIndex = transitionIndex;
+        glucose.setSelectedTransition(transitionIndex);
       }
     } else if ((mouseY >= firstPatternKnobY) && (mouseY < firstPatternKnobY + 2*(knobSize+knobLabelHeight) + knobSpacing)) {
       patternKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
       if (mouseY >= firstPatternKnobY + knobSize + knobLabelHeight + knobSpacing) {
-        patternKnobIndex += NUM_PATTERN_KNOBS / 2;
+        patternKnobIndex += glucose.NUM_PATTERN_KNOBS / 2;
       }      
     } else if (mouseY > firstPatternY) {
       int patternIndex = objectClickIndex(firstPatternY);
       if (patternIndex < patterns.length) {
-        patterns[patternIndex].setTransition(transitions[activeTransitionIndex]);
         lx.goIndex(patternIndex);
       }
     }
@@ -445,14 +370,14 @@ class ControlUI extends OverlayUI {
   public void mouseDragged() {
     int dy = lastY - mouseY;
     lastY = mouseY;
-    if (patternKnobIndex >= 0 && patternKnobIndex < NUM_PATTERN_KNOBS) {
-      LXParameter p = patternKnobs[patternKnobIndex];
+    if (patternKnobIndex >= 0 && patternKnobIndex < glucose.NUM_PATTERN_KNOBS) {
+      LXParameter p = glucose.patternKnobs.get(patternKnobIndex);
       p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
-    } else if (effectKnobIndex >= 0 && effectKnobIndex < NUM_EFFECT_KNOBS) {
-      LXParameter p = effectKnobs[effectKnobIndex];
+    } else if (effectKnobIndex >= 0 && effectKnobIndex < glucose.NUM_EFFECT_KNOBS) {
+      LXParameter p = glucose.effectKnobs.get(effectKnobIndex);
       p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
-    } else if (transitionKnobIndex >= 0 && transitionKnobIndex < NUM_TRANSITION_KNOBS) {
-      LXParameter p = transitionKnobs[transitionKnobIndex];
+    } else if (transitionKnobIndex >= 0 && transitionKnobIndex < glucose.NUM_TRANSITION_KNOBS) {
+      LXParameter p = glucose.transitionKnobs.get(transitionKnobIndex);
       p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
     }
   }
index fdf9ec33188b2f8a7920ddd72181c3641c65f9ef..fe2ba46acbc8c9023cc3456713fe752a021ebc5a 100644 (file)
Binary files a/code/GLucose.jar and b/code/GLucose.jar differ
index e6ac53e47ae04653ee7759bff74f262a8011fd44..608c30c076596b559a19d96b3bde7d980fab3d6c 100644 (file)
Binary files a/code/HeronLX.jar and b/code/HeronLX.jar differ