SugarCubes sketch initial code dump
[SugarCubes.git] / _Internals.pde
CommitLineData
49815cc0
MS
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
7import glucose.*;
8import glucose.control.*;
9import glucose.pattern.*;
10import glucose.transition.*;
11import glucose.model.*;
12import heronarts.lx.*;
13import heronarts.lx.effect.*;
14import heronarts.lx.pattern.*;
15import heronarts.lx.modulator.*;
16import heronarts.lx.transition.*;
17import ddf.minim.*;
18import ddf.minim.analysis.*;
19import processing.opengl.*;
20import java.lang.reflect.*;
21
22final int VIEWPORT_WIDTH = 900;
23final int VIEWPORT_HEIGHT = 700;
24final int TARGET_FRAMERATE = 45;
25
26int startMillis, lastMillis;
27GLucose glucose;
28HeronLX lx;
29LXPattern[] patterns;
30LXTransition[] transitions;
31LXEffect[] effects;
32OverlayUI ui;
33int activeTransitionIndex = 0;
34
35void setup() {
36 startMillis = lastMillis = millis();
37
38 // Initialize the Processing graphics environment
39 size(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, OPENGL);
40 frameRate(TARGET_FRAMERATE);
41 // hint(ENABLE_OPENGL_4X_SMOOTH); // no discernable improvement?
42 logTime("Created viewport");
43
44 // Create the GLucose engine to run the cubes
45 glucose = new GLucose(this);
46 lx = glucose.lx;
47 logTime("Built GLucose engine");
48
49 // Set the patterns
50 glucose.lx.setPatterns(patterns = patterns(glucose));
51 logTime("Built patterns");
52 glucose.lx.addEffects(effects = effects(glucose));
53 logTime("Built effects");
54 transitions = transitions(glucose);
55 logTime("Built transitions");
56
57 // Build overlay UI
58 ui = new OverlayUI();
59 logTime("Built overlay UI");
60
61 // MIDI devices
62 MidiKnobController.initializeStandardDevices(glucose);
63 logTime("Setup MIDI controllers");
64
65 println("Total setup: " + (millis() - startMillis) + "ms");
66}
67
68void logTime(String evt) {
69 int now = millis();
70 println(evt + ": " + (now - lastMillis) + "ms");
71 lastMillis = now;
72}
73
74void draw() {
75 // The glucose engine deals with the core simulation here, we don't need
76 // to do anything specific. This method just needs to exist.
77}
78
79void drawUI() {
80 if (uiOn) {
81 ui.draw();
82 } else {
83 ui.drawHelpTip();
84 }
85 ui.drawFPS();
86}
87
88boolean uiOn = true;
89void keyPressed() {
90 if (key == 'u') {
91 uiOn = !uiOn;
92 }
93}
94
95