Add mappings for panda board UI and PandaDriver class
[SugarCubes.git] / _Internals.pde
CommitLineData
49815cc0 1/**
1ecdb44a
MS
2 * DOUBLE BLACK DIAMOND DOUBLE BLACK DIAMOND
3 *
4 * //\\ //\\ //\\ //\\
5 * ///\\\ ///\\\ ///\\\ ///\\\
6 * \\\/// \\\/// \\\/// \\\///
7 * \\// \\// \\// \\//
8 *
9 * EXPERTS ONLY!! EXPERTS ONLY!!
10 *
49815cc0
MS
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
16import glucose.*;
17import glucose.control.*;
3f8be614 18import glucose.effect.*;
f3f5a876 19import glucose.model.*;
49815cc0 20import glucose.pattern.*;
f3f5a876 21import glucose.transform.*;
49815cc0 22import glucose.transition.*;
49815cc0 23import heronarts.lx.*;
3f8be614 24import heronarts.lx.control.*;
49815cc0 25import heronarts.lx.effect.*;
49815cc0 26import heronarts.lx.modulator.*;
f3f5a876 27import heronarts.lx.pattern.*;
49815cc0
MS
28import heronarts.lx.transition.*;
29import ddf.minim.*;
30import ddf.minim.analysis.*;
31import processing.opengl.*;
5d70e4d7 32import rwmidi.*;
49815cc0
MS
33
34final int VIEWPORT_WIDTH = 900;
35final int VIEWPORT_HEIGHT = 700;
36final int TARGET_FRAMERATE = 45;
37
38int startMillis, lastMillis;
39GLucose glucose;
40HeronLX lx;
41LXPattern[] patterns;
42LXTransition[] transitions;
43LXEffect[] effects;
44OverlayUI ui;
e73ef85d
MS
45OscP5 osc;
46PandaDriver pandaFront;
47PandaDriver pandaRear;
48
49boolean pandaBoardsEnabled = false;
49815cc0
MS
50
51void setup() {
52 startMillis = lastMillis = millis();
53
54 // Initialize the Processing graphics environment
55 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
56 frameRate(TARGET_FRAMERATE);
3f8be614 57 noSmooth();
49815cc0
MS
58 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
59 logTime("Created viewport");
60
61 // Create the GLucose engine to run the cubes
1ecdb44a 62 glucose = new GLucose(this, new SCMapping());
49815cc0
MS
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");
e73ef85d
MS
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");
49815cc0
MS
81
82 // Build overlay UI
83 ui = new OverlayUI();
84 logTime("Built overlay UI");
1ecdb44a 85
49815cc0 86 // MIDI devices
809f3518 87 SCMidiDevices.initializeStandardDevices(glucose, ui.patternKnobs, ui.transitionKnobs, ui.effectKnobs);
3f8be614 88 logTime("Setup MIDI devices");
49815cc0
MS
89
90 println("Total setup: " + (millis() - startMillis) + "ms");
e73ef85d 91 println("Hit the 'p' key to toggle Panda Board output");
49815cc0
MS
92}
93
94void logTime(String evt) {
95 int now = millis();
96 println(evt + ": " + (now - lastMillis) + "ms");
97 lastMillis = now;
98}
99
100void 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.
e73ef85d
MS
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 }
49815cc0
MS
110}
111
112void drawUI() {
113 if (uiOn) {
114 ui.draw();
115 } else {
116 ui.drawHelpTip();
117 }
118 ui.drawFPS();
119}
120
121boolean uiOn = true;
3f8be614 122boolean knobsOn = true;
49815cc0 123void keyPressed() {
3f8be614 124 switch (key) {
e73ef85d
MS
125 case 'p':
126 pandaBoardsEnabled = !pandaBoardsEnabled;
127 println("PandaBoard Output: " + (pandaBoardsEnabled ? "ON" : "OFF"));
128 break;
3f8be614
MS
129 case 'u':
130 uiOn = !uiOn;
131 break;
132 case 'k':
133 knobsOn = !knobsOn;
134 break;
49815cc0
MS
135 }
136}
137
138