commit 0405b8b8f93285f96e85279b5056731c61c2b233
parent da503df0fc49576bf6f9c5d6378412454444d5ca
Author: Matt Demanett <matt@demanett.net>
Date: Wed, 30 Jan 2019 21:53:10 -0500
Fix triggers to adhere to rack standard, where low threshold is 0.1V rather than 0V. #34
Diffstat:
16 files changed, 63 insertions(+), 16 deletions(-)
diff --git a/src/AD.hpp b/src/AD.hpp
@@ -44,7 +44,7 @@ struct AD : Module {
int _modulationStep = 0;
bool _loopMode = false;
bool _linearMode = false;
- SchmittTrigger _trigger;
+ Trigger _trigger;
PulseGenerator _eocPulseGen;
bool _on = false;
ADSR _envelope;
diff --git a/src/ADSR.hpp b/src/ADSR.hpp
@@ -39,7 +39,7 @@ struct ADSR : Module {
const int modulationSteps = 100;
int _modulationStep = 0;
bool _linearMode = false;
- SchmittTrigger _gateTrigger;
+ Trigger _gateTrigger;
bogaudio::dsp::ADSR _envelope;
ADSR() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {
diff --git a/src/DGate.hpp b/src/DGate.hpp
@@ -39,7 +39,7 @@ struct DGate : TriggerOnLoadModule {
};
bool _firstStep = true;
- SchmittTrigger _trigger;
+ Trigger _trigger;
PulseGenerator _triggerOuptutPulseGen;
Stage _stage;
float _stageProgress;
diff --git a/src/FMOp.hpp b/src/FMOp.hpp
@@ -72,7 +72,7 @@ struct FMOp : Module {
Phasor _phasor;
SineTableOscillator _sineTable;
CICDecimator _decimator;
- SchmittTrigger _gateTrigger;
+ Trigger _gateTrigger;
SlewLimiter _feedbackSL;
SlewLimiter _depthSL;
SlewLimiter _levelSL;
diff --git a/src/FlipFlop.cpp b/src/FlipFlop.cpp
@@ -37,7 +37,7 @@ void FlipFlop::channelStep(
Output& aOutput,
Output& bOutput,
PositiveZeroCrossing& trigger,
- SchmittTrigger& resetTrigger,
+ Trigger& resetTrigger,
bool& flipped
) {
bool triggered = trigger.next(triggerInput.value);
diff --git a/src/FlipFlop.hpp b/src/FlipFlop.hpp
@@ -37,9 +37,9 @@ struct FlipFlop : Module {
bool _flipped1;
bool _flipped2;
PositiveZeroCrossing _trigger1;
- SchmittTrigger _resetTrigger1;
+ Trigger _resetTrigger1;
PositiveZeroCrossing _trigger2;
- SchmittTrigger _resetTrigger2;
+ Trigger _resetTrigger2;
FlipFlop() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {
onReset();
@@ -53,7 +53,7 @@ struct FlipFlop : Module {
Output& aOutput,
Output& bOutput,
PositiveZeroCrossing& trigger,
- SchmittTrigger& resetTrigger,
+ Trigger& resetTrigger,
bool& flipped
);
};
diff --git a/src/Manual.hpp b/src/Manual.hpp
@@ -33,7 +33,7 @@ struct Manual : TriggerOnLoadModule {
};
bool _firstStep = true;
- SchmittTrigger _trigger;
+ Trigger _trigger;
PulseGenerator _pulse;
Manual() : TriggerOnLoadModule(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {
diff --git a/src/Mute8.hpp b/src/Mute8.hpp
@@ -72,7 +72,7 @@ struct Mute8 : Module {
Amplifier _amplifiers[8];
SlewLimiter _slewLimiters[8];
- SchmittTrigger _triggers[8];
+ Trigger _triggers[8];
Mute8() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {
onReset();
diff --git a/src/SampleHold.hpp b/src/SampleHold.hpp
@@ -38,7 +38,7 @@ struct SampleHold : Module {
NUM_LIGHTS
};
- SchmittTrigger _trigger1, _trigger2;
+ Trigger _trigger1, _trigger2;
float _value1, _value2;
WhiteNoiseGenerator _noise;
diff --git a/src/Switch.hpp b/src/Switch.hpp
@@ -33,7 +33,7 @@ struct Switch : Module {
NUM_LIGHTS
};
- SchmittTrigger _trigger;
+ Trigger _trigger;
bool _latchedHigh = false;
Switch() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {
diff --git a/src/Test.hpp b/src/Test.hpp
@@ -212,7 +212,7 @@ struct Test : Module {
PucketteEnvelopeFollower _pef;
#elif RAVG
RunningAverage _average;
- SchmittTrigger _reset;
+ Trigger _reset;
#elif SATURATOR
Saturator _saturator;
#endif
diff --git a/src/Test2.hpp b/src/Test2.hpp
@@ -64,7 +64,7 @@ struct Test2 : Module {
int _steps = maxSteps;
#elif ADSR_ENVELOPE
ADSR _adsr;
- SchmittTrigger _trigger;
+ Trigger _trigger;
#elif LIMITER
Limiter _limiter;
#endif
diff --git a/src/bogaudio.hpp b/src/bogaudio.hpp
@@ -10,6 +10,7 @@
#include "rack.hpp"
#include "dsp/digital.hpp"
+#include "rack_overrides.hpp"
#include "trigger_on_load.hpp"
#include "widgets.hpp"
#include "utils.hpp"
diff --git a/src/dadsrh_core.hpp b/src/dadsrh_core.hpp
@@ -64,7 +64,7 @@ struct DADSRHCore {
bool _firstStep = true;
bool& _triggerOnLoad;
bool& _shouldTriggerOnLoad;
- SchmittTrigger _trigger;
+ Trigger _trigger;
PulseGenerator _triggerOuptutPulseGen;
Stage _stage;
float _envelope, _stageProgress, _holdProgress, _releaseLevel;
diff --git a/src/rack_overrides.hpp b/src/rack_overrides.hpp
@@ -0,0 +1,46 @@
+#pragma once
+
+#include "rack.hpp"
+
+using namespace rack;
+
+namespace bogaudio {
+
+struct Trigger : SchmittTrigger {
+ float _highThreshold;
+ float _lowThreshold;
+
+ Trigger(float highThreshold = 1.0f, float lowThreshold = 0.1f)
+ : _highThreshold(highThreshold)
+ , _lowThreshold(lowThreshold)
+ {
+ reset();
+ }
+
+ bool process(float in) {
+ switch (state) {
+ case LOW:
+ if (in >= _highThreshold) {
+ state = HIGH;
+ return true;
+ }
+ break;
+ case HIGH:
+ if (in <= _lowThreshold) {
+ state = LOW;
+ }
+ break;
+ default:
+ if (in >= _highThreshold) {
+ state = HIGH;
+ }
+ else if (in <= _lowThreshold) {
+ state = LOW;
+ }
+ break;
+ }
+ return false;
+ }
+};
+
+} // namespace bogaudio
diff --git a/src/shaper_core.hpp b/src/shaper_core.hpp
@@ -49,7 +49,7 @@ struct ShaperCore {
bool _firstStep = true;
bool& _triggerOnLoad;
bool& _shouldTriggerOnLoad;
- SchmittTrigger _trigger;
+ Trigger _trigger;
PulseGenerator _triggerOuptutPulseGen;
Stage _stage;
float _stageProgress;