From 21e097c8fcbd3f45a48b08cea9f123f9b9a9ed13 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 18 Jul 2018 01:17:25 -0400 Subject: [PATCH] Add BooleanTrigger --- include/dsp/digital.hpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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;