From 24fc03308b0fe0ee37c0143ce0e3c868a1a971be Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Mon, 21 Oct 2013 18:43:25 -0700 Subject: [PATCH] Make cleaner interface to effects in code --- SugarCubes.pde | 27 +++++++++++++-------------- _Internals.pde | 20 +++++++++++++++++--- _MIDI.pde | 24 ++++++++++++------------ 3 files changed, 42 insertions(+), 29 deletions(-) diff --git a/SugarCubes.pde b/SugarCubes.pde index 9faf3ec..6877613 100644 --- a/SugarCubes.pde +++ b/SugarCubes.pde @@ -129,18 +129,17 @@ LXTransition[] transitions(GLucose glucose) { } // Handles to globally triggerable effects -BoomEffect EFF_boom; -FlashEffect EFF_flash; -ColorFuckerEffect EFF_colorFucker; -BlurEffect EFF_blur; -QuantizeEffect EFF_quantize; - -LXEffect[] effects(GLucose glucose) { - return new LXEffect[] { - EFF_flash = new FlashEffect(lx), - EFF_boom = new BoomEffect(glucose), - (EFF_blur = new BlurEffect(glucose)).enable(), - (EFF_quantize = new QuantizeEffect(glucose)).enable(), - (EFF_colorFucker = new ColorFuckerEffect(glucose)).enable(), - }; +class Effects { + FlashEffect flash = new FlashEffect(lx); + BoomEffect boom = new BoomEffect(glucose); + BlurEffect blur = new BlurEffect(glucose); + QuantizeEffect quantize = new QuantizeEffect(glucose); + ColorFuckerEffect colorFucker = new ColorFuckerEffect(glucose); + + Effects() { + blur.enable(); + quantize.enable(); + colorFucker.enable(); + } } + diff --git a/_Internals.pde b/_Internals.pde index 79d12e5..41532f7 100644 --- a/_Internals.pde +++ b/_Internals.pde @@ -30,6 +30,7 @@ import ddf.minim.*; import ddf.minim.analysis.*; import processing.opengl.*; import rwmidi.*; +import java.lang.reflect.*; final int VIEWPORT_WIDTH = 900; final int VIEWPORT_HEIGHT = 700; @@ -49,6 +50,7 @@ int startMillis, lastMillis; GLucose glucose; HeronLX lx; LXPattern[] patterns; +Effects effects; MappingTool mappingTool; PandaDriver[] pandaBoards; PresetManager presetManager; @@ -100,7 +102,19 @@ LXPattern[] _rightPatterns(GLucose glucose) { } return rightPatterns; } - + +LXEffect[] _effectsArray(Effects effects) { + List effectList = new ArrayList(); + for (Field f : effects.getClass().getDeclaredFields()) { + try { + Object val = f.get(effects); + if (val instanceof LXEffect) { + effectList.add((LXEffect)val); + } + } catch (IllegalAccessException iax) {} + } + return effectList.toArray(new LXEffect[]{}); +} void logTime(String evt) { int now = millis(); @@ -131,7 +145,7 @@ void setup() { logTime("Built patterns"); glucose.setTransitions(transitions(glucose)); logTime("Built transitions"); - glucose.lx.addEffects(effects(glucose)); + glucose.lx.addEffects(_effectsArray(effects = new Effects())); logTime("Built effects"); // Preset manager @@ -471,7 +485,7 @@ void keyPressed() { frameRate(++targetFramerate); break; case 'b': - EFF_boom.trigger(); + effects.boom.trigger(); break; case 'd': if (!midiEngine.isQwertyEnabled()) { diff --git a/_MIDI.pde b/_MIDI.pde index 6467c4c..727742f 100644 --- a/_MIDI.pde +++ b/_MIDI.pde @@ -407,26 +407,26 @@ public class APC40MidiInput extends GenericDeviceMidiInput { case 7: switch (channel) { case 0: - EFF_colorFucker.hueShift.setValue(value); + effects.colorFucker.hueShift.setValue(value); return true; case 1: - EFF_colorFucker.desat.setValue(value); + effects.colorFucker.desat.setValue(value); return true; case 2: - EFF_colorFucker.sharp.setValue(value); + effects.colorFucker.sharp.setValue(value); return true; case 3: - EFF_blur.amount.setValue(value); + effects.blur.amount.setValue(value); return true; case 4: - EFF_quantize.amount.setValue(value); + effects.quantize.amount.setValue(value); return true; } break; // Master bright case 14: - EFF_colorFucker.level.setValue(value); + effects.colorFucker.level.setValue(value); return true; // Crossfader @@ -479,10 +479,10 @@ public class APC40MidiInput extends GenericDeviceMidiInput { case 49: // SOLO/CUE switch (nChan) { case 4: - EFF_colorFucker.mono.setValue(1); + effects.colorFucker.mono.setValue(1); return true; case 5: - EFF_colorFucker.invert.setValue(1); + effects.colorFucker.invert.setValue(1); return true; case 6: lx.cycleBaseHue(60000); @@ -491,11 +491,11 @@ public class APC40MidiInput extends GenericDeviceMidiInput { break; case 82: // scene 1 - EFF_boom.trigger(); + effects.boom.trigger(); return true; case 83: // scene 2 - EFF_flash.trigger(); + effects.flash.trigger(); return true; case 90: @@ -576,10 +576,10 @@ public class APC40MidiInput extends GenericDeviceMidiInput { case 49: // SOLO/CUE switch (nChan) { case 4: - EFF_colorFucker.mono.setValue(0); + effects.colorFucker.mono.setValue(0); return true; case 5: - EFF_colorFucker.invert.setValue(0); + effects.colorFucker.invert.setValue(0); return true; case 6: lx.setBaseHue(lx.getBaseHue()); -- 2.34.1