Fix bug with preset storing
[SugarCubes.git] / _Internals.pde
index 79d12e5574bd631b284ca351ce3196036c0cc876..f809e9389bc9159b838c128e51a7fb960393e98a 100644 (file)
@@ -30,6 +30,7 @@ import ddf.minim.*;
 import ddf.minim.analysis.*;
 import processing.opengl.*;
 import rwmidi.*;
+import java.lang.reflect.*;
 
 final int VIEWPORT_WIDTH = 900;
 final int VIEWPORT_HEIGHT = 700;
@@ -49,6 +50,7 @@ int startMillis, lastMillis;
 GLucose glucose;
 HeronLX lx;
 LXPattern[] patterns;
+Effects effects;
 MappingTool mappingTool;
 PandaDriver[] pandaBoards;
 PresetManager presetManager;
@@ -100,7 +102,19 @@ LXPattern[] _rightPatterns(GLucose glucose) {
   }
   return rightPatterns;
 }
-  
+
+LXEffect[] _effectsArray(Effects effects) {
+  List<LXEffect> effectList = new ArrayList<LXEffect>();
+  for (Field f : effects.getClass().getDeclaredFields()) {
+    try {
+      Object val = f.get(effects);
+      if (val instanceof LXEffect) {
+        effectList.add((LXEffect)val);
+      }
+    } catch (IllegalAccessException iax) {}
+  }
+  return effectList.toArray(new LXEffect[]{});
+} 
 
 void logTime(String evt) {
   int now = millis();
@@ -131,7 +145,7 @@ void setup() {
   logTime("Built patterns");
   glucose.setTransitions(transitions(glucose));
   logTime("Built transitions");
-  glucose.lx.addEffects(effects(glucose));
+  glucose.lx.addEffects(_effectsArray(effects = new Effects()));
   logTime("Built effects");
 
   // Preset manager
@@ -208,9 +222,9 @@ void draw() {
   simulationColors = sendColors = glucose.getColors();
   String displayMode = uiCrossfader.getDisplayMode();
   if (displayMode == "A") {
-    simulationColors = lx.engine.getDeck(0).getColors();
+    simulationColors = lx.engine.getDeck(GLucose.LEFT_DECK).getColors();
   } else if (displayMode == "B") {
-    simulationColors = lx.engine.getDeck(1).getColors();
+    simulationColors = lx.engine.getDeck(GLucose.RIGHT_DECK).getColors();
   }
   if (debugMode) {
     debugUI.maskColors(simulationColors);
@@ -471,7 +485,7 @@ void keyPressed() {
       frameRate(++targetFramerate);
       break; 
     case 'b':
-      EFF_boom.trigger();
+      effects.boom.trigger();
       break;    
     case 'd':
       if (!midiEngine.isQwertyEnabled()) {