/** (c) subpixel 2009 - http://subpixels.com * * class EffectParameters * 2009-01-20 Created by subpixel * * The idea here is that an efect can be on or off, have a * duration, speed, intensity, LFO(s), a marker for progress or * time passed, be repeatable, etc. * Multiple effects could be active for an object or channel * (including the master channel). */ static int shotDuration = 2000; // 2 seconds public class EffectParameters { Object parent; // Effect owner boolean active = false; // Is this effect active? (boolean XOR levels) boolean complete = false; // Set true when progress reaches 100% (1.0) float startTime; //TODO: not yet well defined float stopTime; //TODO: not yet well defined float duration; // Total play time for effect (0 for continuous) float elapsedTime; // Current play time since start float progress; // 0 to 1, float float1; float float2; int int1; int int2; //TODO: more parameters to come? // -------------------------------------------------------------------------- // Constructor // -------------------------------------------------------------------------- EffectParameters(Object parent) { this.parent = parent; } // -------------------------------------------------------------------------- // Update efefct parameters, LFO's, etc // -------------------------------------------------------------------------- void update() { float time = millis(); if (!active) return; if (complete) // ie we finished last update { stop(); return; } elapsedTime = time - startTime; progress = 0; if (duration != 0) { progress = elapsedTime / duration; if (progress >= 1) { progress = 1; // in case of overshoot complete = true; } } //println("progress: " + progress); //TODO: looping effects, LFO's, etc //if (restartTime != 0 && time >= restartTime) // start(); } // -------------------------------------------------------------------------- // Start the effect // -------------------------------------------------------------------------- void start() { println("start()"); startTime = millis(); //TODO: replace with scene clock? duration = 0; stopTime = 0; active = true; complete = false; } // -------------------------------------------------------------------------- // Stop the effect // -------------------------------------------------------------------------- void stop() { println("stop()"); stopTime = millis(); //TODO: replace with scene clock? active = false; } // -------------------------------------------------------------------------- // Start/stop the effect. Return whether the effect is then active. // -------------------------------------------------------------------------- boolean toggle() { println(parentName() + " toggle()"); if (active) stop(); else start(); return active; } // -------------------------------------------------------------------------- // Start the effect with a limited duration // -------------------------------------------------------------------------- void shot() { println(parentName() + " shot()"); start(); //TODO: turn on display of channel or object? duration = shotDuration; stopTime = startTime + duration; } String parentName() { if (parent instanceof Channel) { return ((Channel)parent).id; } return "(?effectParent?)"; } }