LXEffect[] effects;
OverlayUI ui;
+boolean debugMode = false;
+
void setup() {
startMillis = lastMillis = millis();
// Create the GLucose engine to run the cubes
glucose = new GLucose(this, new SCMapping());
lx = glucose.lx;
+ lx.enableKeyboardTempo();
logTime("Built GLucose engine");
// Set the patterns
logTime("Built patterns");
glucose.lx.addEffects(effects = effects(glucose));
logTime("Built effects");
- transitions = transitions(glucose);
+ glucose.setTransitions(transitions = transitions(glucose));
logTime("Built transitions");
// Build overlay UI
logTime("Built overlay UI");
// MIDI devices
- SCMidiDevices.initializeStandardDevices(glucose, ui.patternKnobs, ui.transitionKnobs, ui.effectKnobs);
+ for (MidiInputDevice d : RWMidi.getInputDevices()) {
+ d.createInput(this);
+ }
+ SCMidiDevices.initializeStandardDevices(glucose);
logTime("Setup MIDI devices");
println("Total setup: " + (millis() - startMillis) + "ms");
}
+void controllerChangeReceived(rwmidi.Controller cc) {
+ if (debugMode) {
+ println("CC: " + cc.toString());
+ }
+}
+
+void noteOnReceived(Note note) {
+ if (debugMode) {
+ println("Note On: " + note.toString());
+ }
+}
+
+void noteOffReceived(Note note) {
+ if (debugMode) {
+ println("Note Off: " + note.toString());
+ }
+}
+
void logTime(String evt) {
int now = millis();
println(evt + ": " + (now - lastMillis) + "ms");
boolean knobsOn = true;
void keyPressed() {
switch (key) {
+ case 'd':
+ debugMode = !debugMode;
+ println("Debug output: " + (debugMode ? "ON" : "OFF"));
+ break;
case 'u':
uiOn = !uiOn;
break;
- case 'k':
- knobsOn = !knobsOn;
- break;
}
}
private Method patternStateMethod;
private Method transitionStateMethod;
private Method effectStateMethod;
-
- private final int NUM_PATTERN_KNOBS = 8;
- private final int NUM_TRANSITION_KNOBS = 4;
- private final int NUM_EFFECT_KNOBS = 4;
-
- private int activeTransitionIndex = 0;
- private int activeEffectIndex = 0;
-
- public final VirtualPatternKnob[] patternKnobs;
- public final VirtualTransitionKnob[] transitionKnobs;
- public final VirtualEffectKnob[] effectKnobs;
OverlayUI() {
leftPos = width - w;
transitionNames = classNameArray(transitions, "Transition");
effectNames = classNameArray(effects, "Effect");
- patternKnobs = new VirtualPatternKnob[NUM_PATTERN_KNOBS];
- for (int i = 0; i < patternKnobs.length; ++i) {
- patternKnobs[i] = new VirtualPatternKnob(i);
- }
-
- transitionKnobs = new VirtualTransitionKnob[NUM_TRANSITION_KNOBS];
- for (int i = 0; i < transitionKnobs.length; ++i) {
- transitionKnobs[i] = new VirtualTransitionKnob(i);
- }
-
- effectKnobs = new VirtualEffectKnob[NUM_EFFECT_KNOBS];
- for (int i = 0; i < effectKnobs.length; ++i) {
- effectKnobs[i] = new VirtualEffectKnob(i);
- }
-
try {
patternStateMethod = getClass().getMethod("getState", LXPattern.class);
effectStateMethod = getClass().getMethod("getState", LXEffect.class);
yPos += controlSpacing;
firstPatternKnobY = yPos;
int xPos = leftTextPos;
- for (int i = 0; i < NUM_PATTERN_KNOBS/2; ++i) {
- drawKnob(xPos, yPos, knobSize, patternKnobs[i]);
- drawKnob(xPos, yPos + knobSize + knobSpacing + knobLabelHeight, knobSize, patternKnobs[NUM_PATTERN_KNOBS/2 + i]);
+ for (int i = 0; i < glucose.NUM_PATTERN_KNOBS/2; ++i) {
+ drawKnob(xPos, yPos, knobSize, glucose.patternKnobs.get(i));
+ drawKnob(xPos, yPos + knobSize + knobSpacing + knobLabelHeight, knobSize, glucose.patternKnobs.get(glucose.NUM_PATTERN_KNOBS/2 + i));
xPos += knobSize + knobSpacing;
}
yPos += 2*(knobSize + knobLabelHeight) + knobSpacing;
yPos += controlSpacing;
firstTransitionKnobY = yPos;
xPos = leftTextPos;
- for (int i = 0; i < transitionKnobs.length; ++i) {
- drawKnob(xPos, yPos, knobSize, transitionKnobs[i]);
+ for (VirtualTransitionKnob knob : glucose.transitionKnobs) {
+ drawKnob(xPos, yPos, knobSize, knob);
xPos += knobSize + knobSpacing;
}
yPos += knobSize + knobLabelHeight;
yPos += controlSpacing;
firstEffectKnobY = yPos;
xPos = leftTextPos;
- for (int i = 0; i < effectKnobs.length; ++i) {
- drawKnob(xPos, yPos, knobSize, effectKnobs[i]);
+ for (VirtualEffectKnob knob : glucose.effectKnobs) {
+ drawKnob(xPos, yPos, knobSize, knob);
xPos += knobSize + knobSpacing;
}
yPos += knobSize + knobLabelHeight;
public int getState(LXEffect e) {
if (e.isEnabled()) {
return STATE_PENDING;
- } else if (effects[activeEffectIndex] == e) {
+ } else if (e == glucose.getSelectedEffect()) {
return STATE_ACTIVE;
}
return STATE_DEFAULT;
public int getState(LXTransition t) {
if (t == lx.getTransition()) {
return STATE_PENDING;
- } else if (t == transitions[activeTransitionIndex]) {
+ } else if (t == glucose.getSelectedTransition()) {
return STATE_ACTIVE;
}
return STATE_DEFAULT;
}
return s;
}
-
- class VirtualPatternKnob extends LXVirtualParameter {
- private final int index;
-
- VirtualPatternKnob(int index) {
- this.index = index;
- }
-
- public LXParameter getRealParameter() {
- List<LXParameter> parameters = glucose.getPattern().getParameters();
- if (index < parameters.size()) {
- return parameters.get(index);
- }
- return null;
- }
- }
-
- class VirtualTransitionKnob extends LXVirtualParameter {
- private final int index;
-
- VirtualTransitionKnob(int index) {
- this.index = index;
- }
-
- public LXParameter getRealParameter() {
- List<LXParameter> parameters = transitions[activeTransitionIndex].getParameters();
- if (index < parameters.size()) {
- return parameters.get(index);
- }
- return null;
- }
- }
-
- class VirtualEffectKnob extends LXVirtualParameter {
- private final int index;
-
- VirtualEffectKnob(int index) {
- this.index = index;
- }
-
- public LXParameter getRealParameter() {
- List<LXParameter> parameters = effects[activeEffectIndex].getParameters();
- if (index < parameters.size()) {
- return parameters.get(index);
- }
- return null;
- }
- }
private int patternKnobIndex = -1;
private int transitionKnobIndex = -1;
} else if (mouseY > firstEffectY) {
int effectIndex = (mouseY - firstEffectY) / lineHeight;
if (effectIndex < effects.length) {
- if (activeEffectIndex == effectIndex) {
+ if (effects[effectIndex] == glucose.getSelectedEffect()) {
effects[effectIndex].enable();
releaseEffect = effectIndex;
}
- activeEffectIndex = effectIndex;
+ glucose.setSelectedEffect(effectIndex);
}
} else if ((mouseY >= firstTransitionKnobY) && (mouseY < firstTransitionKnobY + knobSize + knobLabelHeight)) {
transitionKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
} else if (mouseY > firstTransitionY) {
int transitionIndex = (mouseY - firstTransitionY) / lineHeight;
if (transitionIndex < transitions.length) {
- activeTransitionIndex = transitionIndex;
+ glucose.setSelectedTransition(transitionIndex);
}
} else if ((mouseY >= firstPatternKnobY) && (mouseY < firstPatternKnobY + 2*(knobSize+knobLabelHeight) + knobSpacing)) {
patternKnobIndex = (mouseX - leftTextPos) / (knobSize + knobSpacing);
if (mouseY >= firstPatternKnobY + knobSize + knobLabelHeight + knobSpacing) {
- patternKnobIndex += NUM_PATTERN_KNOBS / 2;
+ patternKnobIndex += glucose.NUM_PATTERN_KNOBS / 2;
}
} else if (mouseY > firstPatternY) {
int patternIndex = (mouseY - firstPatternY) / lineHeight;
if (patternIndex < patterns.length) {
- patterns[patternIndex].setTransition(transitions[activeTransitionIndex]);
lx.goIndex(patternIndex);
}
}
public void mouseDragged() {
int dy = lastY - mouseY;
lastY = mouseY;
- if (patternKnobIndex >= 0 && patternKnobIndex < NUM_PATTERN_KNOBS) {
- LXParameter p = patternKnobs[patternKnobIndex];
+ if (patternKnobIndex >= 0 && patternKnobIndex < glucose.NUM_PATTERN_KNOBS) {
+ LXParameter p = glucose.patternKnobs.get(patternKnobIndex);
p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
- } else if (effectKnobIndex >= 0 && effectKnobIndex < NUM_EFFECT_KNOBS) {
- LXParameter p = effectKnobs[effectKnobIndex];
+ } else if (effectKnobIndex >= 0 && effectKnobIndex < glucose.NUM_EFFECT_KNOBS) {
+ LXParameter p = glucose.effectKnobs.get(effectKnobIndex);
p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
- } else if (transitionKnobIndex >= 0 && transitionKnobIndex < NUM_TRANSITION_KNOBS) {
- LXParameter p = transitionKnobs[transitionKnobIndex];
+ } else if (transitionKnobIndex >= 0 && transitionKnobIndex < glucose.NUM_TRANSITION_KNOBS) {
+ LXParameter p = glucose.transitionKnobs.get(transitionKnobIndex);
p.setValue(constrain(p.getValuef() + dy*.01, 0, 1));
}
}