| @@ -8,7 +8,6 @@ namespace rack { | |||||
| /** Turns HIGH when value reaches 1.f, turns LOW when value reaches 0.f. */ | /** Turns HIGH when value reaches 1.f, turns LOW when value reaches 0.f. */ | ||||
| struct SchmittTrigger { | struct SchmittTrigger { | ||||
| // UNKNOWN is used to represent a stable state when the previous state is not yet set | |||||
| enum State { | enum State { | ||||
| UNKNOWN, | UNKNOWN, | ||||
| LOW, | 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 */ | /** When triggered, holds a high value for a specified time before going low again */ | ||||
| struct PulseGenerator { | struct PulseGenerator { | ||||
| float time; | float time; | ||||