Lots of code cleanup, removed Panda code, all grizzly, cleaning up mapping
[SugarCubes.git] / _Internals.pde
index 0100c051c82d0b4bc8b6125829c5bff708e664b3..7eb5f938a11f976c9baccc3771dd029115b3494c 100644 (file)
@@ -49,15 +49,13 @@ Model model;
 LXPattern[] patterns;
 Effects effects;
 MappingTool mappingTool;
-PandaDriver[] pandaBoards;
+GrizzlyOutput[] grizzlies;
 PresetManager presetManager;
 MidiEngine midiEngine;
 
 // Display configuration mode
 boolean mappingMode = false;
 boolean debugMode = false;
-DebugUI debugUI;
-boolean uiOn = true;
 boolean simulationOn = true;
 boolean diagnosticsOn = false;
 LXPattern restoreToPattern = null;
@@ -153,54 +151,58 @@ void setup() {
   logTime("Setup MIDI devices");
 
   // Build output driver
+  grizzlies = new GrizzlyOutput[]{};
   try {
-    GrizzlyOutput[] grizzlies = buildGrizzlies();
+    grizzlies = buildGrizzlies();
     for (LXOutput output : grizzlies) {
       lx.addOutput(output);
     }
   } catch (Exception x) {
     x.printStackTrace();
   }
+  logTime("Built Grizzly Outputs");
+  
+  // Mapping tools
+  mappingTool = new MappingTool(glucose);
   
-  PandaMapping[] pandaMappings = buildPandaList();
-  pandaBoards = new PandaDriver[pandaMappings.length];
-  int pbi = 0;
-  for (PandaMapping pm : pandaMappings) {
-    pandaBoards[pbi++] = new PandaDriver(pm.ip, glucose.model, pm);
-  }
-  mappingTool = new MappingTool(glucose, pandaMappings);
-  logTime("Built PandaDriver");
-
   // Build overlay UI
-  debugUI = new DebugUI(pandaMappings);
-  UIContext[] contexts = new UIContext[] {
+  UILayer[] layers = new UILayer[] {
+    // Camera layer
+    new UICameraLayer(lx.ui)
+      .setCenter(TRAILER_WIDTH/2., glucose.model.yMax/2, TRAILER_DEPTH/2.)
+      .setRadius(290).addComponent(new UICubesLayer()),
+    
+    // Left controls
     uiPatternA = new UIPatternDeck(lx.ui, lx.engine.getDeck(GLucose.LEFT_DECK), "PATTERN A", 4, 4, 140, 324),
     new UIBlendMode(4, 332, 140, 86),
     new UIEffects(4, 422, 140, 144),
     new UITempo(4, 570, 140, 50),
     uiSpeed = new UISpeed(4, 624, 140, 50),
         
+    // Right controls
     new UIPatternDeck(lx.ui, lx.engine.getDeck(GLucose.RIGHT_DECK), "PATTERN B", width-144, 4, 140, 324),
     uiMidi = new UIMidi(midiEngine, width-144, 332, 140, 158),
-    new UIOutput(width-144, 494, 140, 106),
+    new UIOutput(grizzlies, width-144, 494, 140, 106),
     
+    // Crossfader
     uiCrossfader = new UICrossfader(width/2-90, height-90, 180, 86),
     
+    // Overlays
     uiDebugText = new UIDebugText(148, height-138, width-304, 44),
     uiMapping = new UIMapping(mappingTool, 4, 4, 140, 324)
   };
-  uiMapping.setVisible(false);
-  lx.ui.addLayer(new UICameraLayer(lx.ui).setCenter(TRAILER_WIDTH/2., glucose.model.yMax/2, TRAILER_DEPTH/2.).setRadius(290).addComponent(new UICubesLayer()));
-  for (UIContext context : contexts) {
-    lx.ui.addLayer(context);
+  uiMapping.setVisible(false);  
+  for (UILayer layer : layers) {
+    lx.ui.addLayer(layer);
   }
-  logTime("Built overlay UI");
+  logTime("Built UI");
 
   // Load logo image
   logo = loadImage("data/logo.png");
+  logTime("Loaded logo image");
       
   println("Total setup: " + (millis() - startMillis) + "ms");
-  println("Hit the 'p' key to toggle Panda Board output");
+  println("Hit the 'o' key to toggle live output");
 }
 
 /**
@@ -213,11 +215,7 @@ void draw() {
   background(40);
   
   // Send colors
-  color[] sendColors = glucose.getColors();
-  if (debugMode) {
-    debugUI.maskColors(sendColors);
-  }
-  
+  color[] sendColors = glucose.getColors();  
   long gammaStart = System.nanoTime();
   // Gamma correction here. Apply a cubic to the brightness
   // for better representation of dynamic range
@@ -228,23 +226,15 @@ void draw() {
   }
   long gammaNanos = System.nanoTime() - gammaStart;
 
-  long sendStart = System.nanoTime();
-  for (PandaDriver p : pandaBoards) {
-    p.send(sendColors);
-  }
-  long sendNanos = System.nanoTime() - sendStart;
-
+  // Always draw FPS meter
   drawFPS();
-  if (debugMode) {
-    debugUI.draw();
-  }
 
   // TODO(mcslee): fix
   long drawNanos = System.nanoTime() - drawStart;
   
   long simulationNanos = 0, uiNanos = 0;
   if (diagnosticsOn) {
-    drawDiagnostics(drawNanos, simulationNanos, uiNanos, gammaNanos, sendNanos);
+    drawDiagnostics(drawNanos, simulationNanos, uiNanos, gammaNanos);
   }  
 }
 
@@ -257,9 +247,6 @@ class UICubesLayer extends UICameraComponent {
     } else if (displayMode == "B") {
       simulationColors = lx.engine.getDeck(GLucose.RIGHT_DECK).getColors();
     }
-    if (debugMode) {
-      debugUI.maskColors(simulationColors);
-    }
 
     long simulationStart = System.nanoTime();
     if (simulationOn) {
@@ -275,7 +262,7 @@ class UICubesLayer extends UICameraComponent {
   }      
 }
 
-void drawDiagnostics(long drawNanos, long simulationNanos, long uiNanos, long gammaNanos, long sendNanos) {
+void drawDiagnostics(long drawNanos, long simulationNanos, long uiNanos, long gammaNanos) {
   float ws = 4 / 1000000.;
   int thirtyfps = 1000000000 / 30;
   int sixtyfps = 1000000000 / 60;
@@ -288,7 +275,7 @@ void drawDiagnostics(long drawNanos, long simulationNanos, long uiNanos, long ga
   noStroke();
   int xp = x;
   float hv = 0;
-  for (long val : new long[] {lx.timer.drawNanos, simulationNanos, uiNanos, gammaNanos, sendNanos }) {
+  for (long val : new long[] {lx.timer.drawNanos, simulationNanos, uiNanos, gammaNanos, lx.timer.outputNanos }) {
     fill(lx.hsb(hv % 360, 100, 80));
     rect(xp, y, val * ws, h-1);
     hv += 140;
@@ -579,9 +566,10 @@ void keyPressed() {
         lx.engine.setThreaded(!lx.engine.isThreaded());
       }
       break;
+    case 'o':
     case 'p':
-      for (PandaDriver p : pandaBoards) {
-        p.toggle();
+      for (LXOutput output : grizzlies) {
+        output.enabled.toggle();
       }
       break;
     case 'q':
@@ -594,20 +582,6 @@ void keyPressed() {
         simulationOn = !simulationOn;
       }
       break;
-    case 'u':
-      if (!midiEngine.isQwertyEnabled()) {
-        uiOn = !uiOn;
-      }
-      break;
-  }
-}
-
-/**
- * Top-level mouse event handling
- */
-void mousePressed() {
-  if (debugMode) {
-    debugUI.mousePressed();
   }
 }