Commit | Line | Data |
---|---|---|
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 | ||
16 | import glucose.*; | |
17 | import glucose.control.*; | |
3f8be614 | 18 | import glucose.effect.*; |
f3f5a876 | 19 | import glucose.model.*; |
49815cc0 | 20 | import glucose.pattern.*; |
f3f5a876 | 21 | import glucose.transform.*; |
49815cc0 | 22 | import glucose.transition.*; |
49815cc0 | 23 | import heronarts.lx.*; |
3f8be614 | 24 | import heronarts.lx.control.*; |
49815cc0 | 25 | import heronarts.lx.effect.*; |
49815cc0 | 26 | import heronarts.lx.modulator.*; |
f3f5a876 | 27 | import heronarts.lx.pattern.*; |
49815cc0 MS |
28 | import heronarts.lx.transition.*; |
29 | import ddf.minim.*; | |
30 | import ddf.minim.analysis.*; | |
31 | import processing.opengl.*; | |
5d70e4d7 | 32 | import rwmidi.*; |
49815cc0 MS |
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; | |
e73ef85d MS |
45 | OscP5 osc; |
46 | PandaDriver pandaFront; | |
47 | PandaDriver pandaRear; | |
48 | ||
49 | boolean pandaBoardsEnabled = false; | |
49815cc0 MS |
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); | |
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 | ||
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. | |
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 | ||
112 | void drawUI() { | |
113 | if (uiOn) { | |
114 | ui.draw(); | |
115 | } else { | |
116 | ui.drawHelpTip(); | |
117 | } | |
118 | ui.drawFPS(); | |
119 | } | |
120 | ||
121 | boolean uiOn = true; | |
3f8be614 | 122 | boolean knobsOn = true; |
49815cc0 | 123 | void 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 |