diff --git a/include/dsp/digital.hpp b/include/dsp/digital.hpp index 09d5626a..4f24380a 100644 --- a/include/dsp/digital.hpp +++ b/include/dsp/digital.hpp @@ -8,7 +8,6 @@ namespace rack { /** Turns HIGH when value reaches 1.f, turns LOW when value reaches 0.f. */ struct SchmittTrigger { - // UNKNOWN is used to represent a stable state when the previous state is not yet set enum State { UNKNOWN, LOW, @@ -58,6 +57,23 @@ struct SchmittTrigger { }; +struct BooleanTrigger { + bool lastState; + + BooleanTrigger() { + reset(); + } + void reset() { + lastState = true; + } + bool process(bool state) { + bool triggered = (state && !lastState); + lastState = state; + return triggered; + } +}; + + /** When triggered, holds a high value for a specified time before going low again */ struct PulseGenerator { float time;