Add mappings for panda board UI and PandaDriver class
[SugarCubes.git] / _Internals.pde
1 /**
2 * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
3 *
4 * //\\ //\\ //\\ //\\
5 * ///\\\ ///\\\ ///\\\ ///\\\
6 * \\\/// \\\/// \\\/// \\\///
7 * \\// \\// \\// \\//
8 *
9 * EXPERTS ONLY!! EXPERTS ONLY!!
10 *
11 * If you are an artist, you may ignore this file! It just sets
12 * up the framework to run the patterns. Should not need modification
13 * for general animation work.
14 */
15
16 import glucose.*;
17 import glucose.control.*;
18 import glucose.effect.*;
19 import glucose.model.*;
20 import glucose.pattern.*;
21 import glucose.transform.*;
22 import glucose.transition.*;
23 import heronarts.lx.*;
24 import heronarts.lx.control.*;
25 import heronarts.lx.effect.*;
26 import heronarts.lx.modulator.*;
27 import heronarts.lx.pattern.*;
28 import heronarts.lx.transition.*;
29 import ddf.minim.*;
30 import ddf.minim.analysis.*;
31 import processing.opengl.*;
32 import rwmidi.*;
33
34 final int VIEWPORT_WIDTH = 900;
35 final int VIEWPORT_HEIGHT = 700;
36 final int TARGET_FRAMERATE = 45;
37
38 int startMillis, lastMillis;
39 GLucose glucose;
40 HeronLX lx;
41 LXPattern[] patterns;
42 LXTransition[] transitions;
43 LXEffect[] effects;
44 OverlayUI ui;
45 OscP5 osc;
46 PandaDriver pandaFront;
47 PandaDriver pandaRear;
48
49 boolean pandaBoardsEnabled = false;
50
51 void setup() {
52 startMillis = lastMillis = millis();
53
54 // Initialize the Processing graphics environment
55 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
56 frameRate(TARGET_FRAMERATE);
57 noSmooth();
58 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
59 logTime("Created viewport");
60
61 // Create the GLucose engine to run the cubes
62 glucose = new GLucose(this, new SCMapping());
63 lx = glucose.lx;
64 logTime("Built GLucose engine");
65
66 // Set the patterns
67 glucose.lx.setPatterns(patterns = patterns(glucose));
68 logTime("Built patterns");
69 glucose.lx.addEffects(effects = effects(glucose));
70 logTime("Built effects");
71 transitions = transitions(glucose);
72 logTime("Built transitions");
73
74 // Build output driver
75 int[][] frontChannels = glucose.mapping.buildFrontChannelList();
76 int[][] rearChannels = glucose.mapping.buildRearChannelList();
77 int[][] flippedRGB = glucose.mapping.buildFlippedRGBList();
78 pandaFront = new PandaDriver(new NetAddress("192.168.1.28", 9001), glucose.model, frontChannels, flippedRGB);
79 pandaRear = new PandaDriver(new NetAddress("192.168.1.29", 9001), glucose.model, rearChannels, flippedRGB);
80 logTime("Build PandaDriver");
81
82 // Build overlay UI
83 ui = new OverlayUI();
84 logTime("Built overlay UI");
85
86 // MIDI devices
87 SCMidiDevices.initializeStandardDevices(glucose, ui.patternKnobs, ui.transitionKnobs, ui.effectKnobs);
88 logTime("Setup MIDI devices");
89
90 println("Total setup: " + (millis() - startMillis) + "ms");
91 println("Hit the 'p' key to toggle Panda Board output");
92 }
93
94 void logTime(String evt) {
95 int now = millis();
96 println(evt + ": " + (now - lastMillis) + "ms");
97 lastMillis = now;
98 }
99
100 void draw() {
101 // The glucose engine deals with the core simulation here, we don't need
102 // to do anything specific. This method just needs to exist.
103
104 // TODO(mcslee): move into GLucose engine
105 if (pandaBoardsEnabled) {
106 color[] colors = glucose.getColors();
107 pandaFront.send(colors);
108 pandaRear.send(colors);
109 }
110 }
111
112 void drawUI() {
113 if (uiOn) {
114 ui.draw();
115 } else {
116 ui.drawHelpTip();
117 }
118 ui.drawFPS();
119 }
120
121 boolean uiOn = true;
122 boolean knobsOn = true;
123 void keyPressed() {
124 switch (key) {
125 case 'p':
126 pandaBoardsEnabled = !pandaBoardsEnabled;
127 println("PandaBoard Output: " + (pandaBoardsEnabled ? "ON" : "OFF"));
128 break;
129 case 'u':
130 uiOn = !uiOn;
131 break;
132 case 'k':
133 knobsOn = !knobsOn;
134 break;
135 }
136 }
137
138