Update to new libraries, add knobs for effects and transitions
[SugarCubes.git] / _Internals.pde
1 /**
2 * If you are an artist, you may ignore this file! It just sets
3 * up the framework to run the patterns. Should not need modification
4 * for general animation work.
5 */
6
7 import glucose.*;
8 import glucose.control.*;
9 import glucose.effect.*;
10 import glucose.pattern.*;
11 import glucose.transition.*;
12 import glucose.model.*;
13 import heronarts.lx.*;
14 import heronarts.lx.control.*;
15 import heronarts.lx.effect.*;
16 import heronarts.lx.pattern.*;
17 import heronarts.lx.modulator.*;
18 import heronarts.lx.transition.*;
19 import ddf.minim.*;
20 import ddf.minim.analysis.*;
21 import processing.opengl.*;
22 import java.lang.reflect.*;
23
24 final int VIEWPORT_WIDTH = 900;
25 final int VIEWPORT_HEIGHT = 700;
26 final int TARGET_FRAMERATE = 45;
27
28 int startMillis, lastMillis;
29 GLucose glucose;
30 HeronLX lx;
31 LXPattern[] patterns;
32 LXTransition[] transitions;
33 LXEffect[] effects;
34 OverlayUI ui;
35
36 void setup() {
37 startMillis = lastMillis = millis();
38
39 // Initialize the Processing graphics environment
40 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
41 frameRate(TARGET_FRAMERATE);
42 noSmooth();
43 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
44 logTime("Created viewport");
45
46 // Create the GLucose engine to run the cubes
47 glucose = new GLucose(this);
48 lx = glucose.lx;
49 logTime("Built GLucose engine");
50
51 // Set the patterns
52 glucose.lx.setPatterns(patterns = patterns(glucose));
53 logTime("Built patterns");
54 glucose.lx.addEffects(effects = effects(glucose));
55 logTime("Built effects");
56 transitions = transitions(glucose);
57 logTime("Built transitions");
58
59 // Build overlay UI
60 ui = new OverlayUI();
61 logTime("Built overlay UI");
62
63 // MIDI devices
64 SCMidiDevices.initializeStandardDevices(glucose);
65 logTime("Setup MIDI devices");
66
67 println("Total setup: " + (millis() - startMillis) + "ms");
68 }
69
70 void logTime(String evt) {
71 int now = millis();
72 println(evt + ": " + (now - lastMillis) + "ms");
73 lastMillis = now;
74 }
75
76 void draw() {
77 // The glucose engine deals with the core simulation here, we don't need
78 // to do anything specific. This method just needs to exist.
79 }
80
81 void drawUI() {
82 if (uiOn) {
83 ui.draw();
84 } else {
85 ui.drawHelpTip();
86 }
87 ui.drawFPS();
88 }
89
90 boolean uiOn = true;
91 boolean knobsOn = true;
92 void keyPressed() {
93 switch (key) {
94 case 'u':
95 uiOn = !uiOn;
96 break;
97 case 'k':
98 knobsOn = !knobsOn;
99 break;
100 }
101 }
102
103