Add 't' button to toggle optional threading mode, TestPerformancePattern
[SugarCubes.git] / _Internals.pde
index d24f13b3910c364055c769102ad0f5ddfef9aa86..d616264b7bbb73f62f0677a8875b09f8356ef0e2 100644 (file)
@@ -52,6 +52,7 @@ LXPattern[] patterns;
 MappingTool mappingTool;
 PandaDriver[] pandaBoards;
 MidiEngine midiEngine;
+color[] threadColors;
 
 // Display configuration mode
 boolean mappingMode = false;
@@ -120,12 +121,9 @@ void setup() {
   glucose = new GLucose(this, buildModel());
   lx = glucose.lx;
   lx.enableKeyboardTempo();
+  threadColors = new color[lx.total];
   logTime("Built GLucose engine");
   
-  // MIDI devices
-  midiEngine = new MidiEngine();
-  logTime("Setup MIDI devices");
-
   // Set the patterns
   Engine engine = lx.engine;
   engine.setPatterns(patterns = _leftPatterns(glucose));
@@ -135,7 +133,11 @@ void setup() {
   logTime("Built transitions");
   glucose.lx.addEffects(effects(glucose));
   logTime("Built effects");
-    
+
+  // MIDI devices
+  midiEngine = new MidiEngine();
+  logTime("Setup MIDI devices");
+
   // Build output driver
   PandaMapping[] pandaMappings = buildPandaList();
   pandaBoards = new PandaDriver[pandaMappings.length];
@@ -196,16 +198,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,20 +256,14 @@ 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) {
@@ -458,6 +457,11 @@ void keyPressed() {
         }
       }
       break;
+    case 't':
+      if (!midiEngine.isQwertyEnabled()) {
+        lx.engine.setThreaded(!lx.engine.isThreaded());
+      }
+      break;
     case 'p':
       for (PandaDriver p : pandaBoards) {
         p.toggle();
@@ -512,7 +516,7 @@ void mouseReleased() {
   }
 }
 
-void mouseWheel(int delta) {delta*=20;
+void mouseWheel(int delta) {
   boolean wheeled = false;
   for (UIContext context : overlays) {
     wheeled |= context.mouseWheel(mouseX, mouseY, delta);