Basic preset stuff and onTransitionEnd message
[SugarCubes.git] / _Internals.pde
index 45a93632086ce7071482da8dd52861d77aefa21f..9d6b11889bd413b34ef8f8c9097ef720edbfea68 100644 (file)
@@ -39,8 +39,8 @@ final float TRAILER_WIDTH = 240;
 final float TRAILER_DEPTH = 97;
 final float TRAILER_HEIGHT = 33;
 
-final int MaxCubeHeight = 7;
-final int NumBackTowers = 9;
+final int MaxCubeHeight = 5;
+final int NumBackTowers = 11;
 
 int targetFramerate = 60;
 int startMillis, lastMillis;
@@ -52,6 +52,7 @@ LXPattern[] patterns;
 MappingTool mappingTool;
 PandaDriver[] pandaBoards;
 MidiEngine midiEngine;
+PresetManager presetManager;
 
 // Display configuration mode
 boolean mappingMode = false;
@@ -60,6 +61,7 @@ DebugUI debugUI;
 boolean uiOn = true;
 LXPattern restoreToPattern = null;
 PImage logo;
+float[] hsb = new float[3];
 
 // Handles to UI objects
 UIContext[] overlays;
@@ -135,6 +137,10 @@ void setup() {
   // MIDI devices
   midiEngine = new MidiEngine();
   logTime("Setup MIDI devices");
+  
+  // Preset manager
+  presetManager = new PresetManager();
+  logTime("Loaded presets");
 
   // Build output driver
   PandaMapping[] pandaMappings = buildPandaList();
@@ -196,16 +202,19 @@ void setup() {
 void draw() {
   // Draws the simulation and the 2D UI overlay
   background(40);
-  color[] colors = glucose.getColors();
 
+  color[] simulationColors;
+  color[] sendColors;
+  simulationColors = sendColors = glucose.getColors();
   String displayMode = uiCrossfader.getDisplayMode();
   if (displayMode == "A") {
-    colors = lx.engine.getDeck(0).getColors();
+    simulationColors = lx.engine.getDeck(0).getColors();
   } else if (displayMode == "B") {
-    colors = lx.engine.getDeck(1).getColors();
+    simulationColors = lx.engine.getDeck(1).getColors();
   }
   if (debugMode) {
-    debugUI.maskColors(colors);
+    debugUI.maskColors(simulationColors);
+    debugUI.maskColors(sendColors);
   }
 
   camera(
@@ -251,29 +260,20 @@ void draw() {
   strokeWeight(2);
   beginShape(POINTS);
   for (Point p : glucose.model.points) {
-    stroke(colors[p.index]);
-    vertex(p.fx, p.fy, p.fz);
+    stroke(simulationColors[p.index]);
+    vertex(p.x, p.y, p.z);
   }
   endShape();
   
   // 2D Overlay UI
   drawUI();
     
-  // Send output colors
-  color[] sendColors = glucose.getColors();
-  if (debugMode) {
-    debugUI.maskColors(sendColors);
-  }
-  
   // Gamma correction here. Apply a cubic to the brightness
   // for better representation of dynamic range
   for (int i = 0; i < sendColors.length; ++i) {
-    float b = brightness(sendColors[i]) / 100.f;
-    sendColors[i] = color(
-      hue(sendColors[i]),
-      saturation(sendColors[i]),
-      (b*b*b) * 100.
-    );
+    lx.RGBtoHSB(sendColors[i], hsb);
+    float b = hsb[2];
+    sendColors[i] = lx.hsb(360.*hsb[0], 100.*hsb[1], 100.*(b*b*b));
   }
   
   // TODO(mcslee): move into GLucose engine
@@ -458,6 +458,11 @@ void keyPressed() {
         }
       }
       break;
+    case 't':
+      if (!midiEngine.isQwertyEnabled()) {
+        lx.engine.setThreaded(!lx.engine.isThreaded());
+      }
+      break;
     case 'p':
       for (PandaDriver p : pandaBoards) {
         p.toggle();