commit 052cf903e28122fd9ad33d959f47de6664ee18ba
parent e791978fd4f9e5cc0cd7fd42d7ded315128d075e
Author: Matt Demanett <matt@demanett.net>
Date: Sun, 14 Jul 2019 23:51:01 -0400
Refactoring: make custom ParamQuantity subclasses inner classes where they are used.
Diffstat:
13 files changed, 117 insertions(+), 112 deletions(-)
diff --git a/src/AddrSeq.cpp b/src/AddrSeq.cpp
@@ -5,6 +5,29 @@
#define RANGE_OFFSET "range_offset"
#define RANGE_SCALE "range_scale"
+float AddrSeq::OutputParamQuantity::getDisplayValue() {
+ float v = getValue();
+ if (!module) {
+ return v;
+ }
+
+ AddrSeq* m = static_cast<AddrSeq*>(module);
+ v += m->_rangeOffset;
+ v *= m->_rangeScale;
+ return v;
+}
+
+void AddrSeq::OutputParamQuantity::setDisplayValue(float v) {
+ if (!module) {
+ return;
+ }
+
+ AddrSeq* m = static_cast<AddrSeq*>(module);
+ v /= m->_rangeScale;
+ v -= m->_rangeOffset;
+ setValue(v);
+}
+
void AddrSeq::onReset() {
_step = 0;
_clock.reset();
@@ -71,29 +94,6 @@ void AddrSeq::process(const ProcessArgs& args) {
outputs[OUT_OUTPUT].setVoltage(out);
}
-float AddrSeq::OutputParamQuantity::getDisplayValue() {
- float v = getValue();
- if (!module) {
- return v;
- }
-
- AddrSeq* m = dynamic_cast<AddrSeq*>(module);
- v += m->_rangeOffset;
- v *= m->_rangeScale;
- return v;
-}
-
-void AddrSeq::OutputParamQuantity::setDisplayValue(float v) {
- if (!module) {
- return;
- }
-
- AddrSeq* m = dynamic_cast<AddrSeq*>(module);
- v /= m->_rangeScale;
- v -= m->_rangeOffset;
- setValue(v);
-}
-
struct SelectOnClockMenuItem : MenuItem {
AddrSeq* _module;
diff --git a/src/FMOp.cpp b/src/FMOp.cpp
@@ -4,6 +4,39 @@
#define LINEAR_LEVEL "linearLevel"
+float FMOp::RatioParamQuantity::getDisplayValue() {
+ float v = getValue();
+ if (!module) {
+ return v;
+ }
+
+ if (v < 0.0f) {
+ return std::max(1.0f + v, 0.01f);
+ }
+ v *= 9.0f;
+ v += 1.0f;
+ return v;
+}
+
+void FMOp::RatioParamQuantity::setDisplayValue(float v) {
+ if (!module) {
+ return;
+ }
+
+ if (v < 1.0f) {
+ v = v - 1.0f;
+ }
+ else {
+ v -= 1.0f;
+ v /= 9.0f;
+ }
+ setValue(v);
+}
+
+bool FMOp::LevelParamQuantity::isLinear() {
+ return static_cast<FMOp*>(module)->_linearLevel;
+}
+
void FMOp::onReset() {
_steps = modulationSteps;
_envelope.reset();
diff --git a/src/FMOp.hpp b/src/FMOp.hpp
@@ -12,9 +12,6 @@ extern Model* modelFMOp;
namespace bogaudio {
-struct FMOpRatioParamQuantity;
-struct FMOpLevelParamQuantity;
-
struct FMOp : Module {
enum ParamsIds {
RATIO_PARAM,
@@ -83,11 +80,20 @@ struct FMOp : Module {
Amplifier _amplifier;
bool _linearLevel = false;
+ struct RatioParamQuantity : ParamQuantity {
+ float getDisplayValue() override;
+ void setDisplayValue(float v) override;
+ };
+
+ struct LevelParamQuantity : AmpliferParamQuantity {
+ bool isLinear() override;
+ };
+
FMOp()
: _envelope(true)
{
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
- configParam<FMOpRatioParamQuantity>(RATIO_PARAM, -1.0f, 1.0f, 0.0f, "Frequency ratio");
+ configParam<RatioParamQuantity>(RATIO_PARAM, -1.0f, 1.0f, 0.0f, "Frequency ratio");
configParam(FINE_PARAM, -1.0f, 1.0f, 0.0f, "Fine tune", " cents", 0.0f, 100.0f);
configParam<EnvelopeSegmentParamQuantity>(ATTACK_PARAM, 0.0f, 1.0f, 0.141421f, "Attack", " s");
configParam<EnvelopeSegmentParamQuantity>(DECAY_PARAM, 0.0f, 1.0f, 0.31623f, "Decay", " s");
@@ -95,7 +101,7 @@ struct FMOp : Module {
configParam<EnvelopeSegmentParamQuantity>(RELEASE_PARAM, 0.0f, 1.0f, 0.31623f, "Release", " s");
configParam(DEPTH_PARAM, 0.0f, 1.0f, 0.0f, "FM depth", "%", 0.0f, 100.0f);
configParam(FEEDBACK_PARAM, 0.0f, 1.0f, 0.0f, "Feedback", "%", 0.0f, 100.0f);
- configParam<FMOpLevelParamQuantity>(LEVEL_PARAM, 0.0f, 1.0f, 1.0f, "Level");
+ configParam<LevelParamQuantity>(LEVEL_PARAM, 0.0f, 1.0f, 1.0f, "Level");
configParam(ENV_TO_LEVEL_PARAM, 0.0f, 1.0f, 0.0f, "Level follows envelope");
configParam(ENV_TO_FEEDBACK_PARAM, 0.0f, 1.0f, 0.0f, "Feedback follows envelope");
configParam(ENV_TO_DEPTH_PARAM, 0.0f, 1.0f, 0.0f, "FM depth follows envelope");
@@ -111,41 +117,4 @@ struct FMOp : Module {
void process(const ProcessArgs& args) override;
};
-struct FMOpRatioParamQuantity : ParamQuantity {
- float getDisplayValue() override {
- float v = getValue();
- if (!module) {
- return v;
- }
-
- if (v < 0.0f) {
- return std::max(1.0f + v, 0.01f);
- }
- v *= 9.0f;
- v += 1.0f;
- return v;
- }
-
- void setDisplayValue(float v) override {
- if (!module) {
- return;
- }
-
- if (v < 1.0f) {
- v = v - 1.0f;
- }
- else {
- v -= 1.0f;
- v /= 9.0f;
- }
- setValue(v);
- }
-};
-
-struct FMOpLevelParamQuantity : AmpliferParamQuantity {
- bool isLinear() override {
- return static_cast<FMOp*>(module)->_linearLevel;
- }
-};
-
} // namespace bogaudio
diff --git a/src/VCA.cpp b/src/VCA.cpp
@@ -1,6 +1,10 @@
#include "VCA.hpp"
+bool VCA::LevelParamQuantity::isLinear() {
+ return static_cast<VCA*>(module)->isLinear();
+}
+
void VCA::onSampleRateChange() {
float sampleRate = APP->engine->getSampleRate();
_levelSL1.setParams(sampleRate, 5.0f, 1.0f);
diff --git a/src/VCA.hpp b/src/VCA.hpp
@@ -9,8 +9,6 @@ extern Model* modelVCA;
namespace bogaudio {
-struct VCALevelParamQuantity;
-
struct VCA : Module {
enum ParamsIds {
LEVEL1_PARAM,
@@ -43,10 +41,14 @@ struct VCA : Module {
Amplifier _amplifier2;
bogaudio::dsp::SlewLimiter _levelSL2;
+ struct LevelParamQuantity : AmpliferParamQuantity {
+ bool isLinear() override;
+ };
+
VCA() {
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
- configParam<VCALevelParamQuantity>(LEVEL1_PARAM, 0.0f, 1.0f, 0.8f, "Level 1");
- configParam<VCALevelParamQuantity>(LEVEL2_PARAM, 0.0f, 1.0f, 0.8f, "Level 2");
+ configParam<LevelParamQuantity>(LEVEL1_PARAM, 0.0f, 1.0f, 0.8f, "Level 1");
+ configParam<LevelParamQuantity>(LEVEL2_PARAM, 0.0f, 1.0f, 0.8f, "Level 2");
configParam(LINEAR_PARAM, 0.0f, 1.0f, 0.0f, "Linear");
onSampleRateChange();
@@ -58,10 +60,4 @@ struct VCA : Module {
void channelStep(Input& input, Output& output, Param& knob, Input& cv, Amplifier& amplifier, bogaudio::dsp::SlewLimiter& levelSL, bool linear);
};
-struct VCALevelParamQuantity : AmpliferParamQuantity {
- bool isLinear() override {
- return static_cast<VCA*>(module)->isLinear();
- }
-};
-
} // namespace bogaudio
diff --git a/src/VCM.cpp b/src/VCM.cpp
@@ -1,6 +1,10 @@
#include "VCM.hpp"
+bool VCM::LevelParamQuantity::isLinear() {
+ return static_cast<VCM*>(module)->isLinear();
+}
+
void VCM::process(const ProcessArgs& args) {
bool linear = isLinear();
lights[LINEAR_LIGHT].value = linear;
diff --git a/src/VCM.hpp b/src/VCM.hpp
@@ -10,8 +10,6 @@ extern Model* modelVCM;
namespace bogaudio {
-struct VCMLevelParamQuantity;
-
struct VCM : DisableOutputLimitModule {
enum ParamsIds {
LEVEL1_PARAM,
@@ -51,12 +49,16 @@ struct VCM : DisableOutputLimitModule {
Amplifier _amplifier3;
Amplifier _amplifier4;
+ struct LevelParamQuantity : AmpliferParamQuantity {
+ bool isLinear() override;
+ };
+
VCM() : DisableOutputLimitModule(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {
- configParam<VCMLevelParamQuantity>(LEVEL1_PARAM, 0.0f, 1.0f, 0.8f, "Level 1");
- configParam<VCMLevelParamQuantity>(LEVEL2_PARAM, 0.0f, 1.0f, 0.8f, "Level 2");
- configParam<VCMLevelParamQuantity>(LEVEL3_PARAM, 0.0f, 1.0f, 0.8f, "Level 3");
- configParam<VCMLevelParamQuantity>(LEVEL4_PARAM, 0.0f, 1.0f, 0.8f, "Level 4");
- configParam<VCMLevelParamQuantity>(MIX_PARAM, 0.0f, 1.0f, 0.8f, "Mix level");
+ configParam<LevelParamQuantity>(LEVEL1_PARAM, 0.0f, 1.0f, 0.8f, "Level 1");
+ configParam<LevelParamQuantity>(LEVEL2_PARAM, 0.0f, 1.0f, 0.8f, "Level 2");
+ configParam<LevelParamQuantity>(LEVEL3_PARAM, 0.0f, 1.0f, 0.8f, "Level 3");
+ configParam<LevelParamQuantity>(LEVEL4_PARAM, 0.0f, 1.0f, 0.8f, "Level 4");
+ configParam<LevelParamQuantity>(MIX_PARAM, 0.0f, 1.0f, 0.8f, "Mix level");
configParam(LINEAR_PARAM, 0.0f, 1.0f, 0.0f, "Linear");
onReset();
}
@@ -66,10 +68,4 @@ struct VCM : DisableOutputLimitModule {
float channelStep(Input& input, Param& knob, Input& cv, Amplifier& amplifier, bool linear);
};
-struct VCMLevelParamQuantity : AmpliferParamQuantity {
- bool isLinear() override {
- return static_cast<VCM*>(module)->isLinear();
- }
-};
-
} // namespace bogaudio
diff --git a/src/VCO.cpp b/src/VCO.cpp
@@ -2,6 +2,11 @@
#include "VCO.hpp"
#include "dsp/pitch.hpp"
+float VCO::VCOFrequencyParamQuantity::offset() {
+ VCO* vco = static_cast<VCO*>(module);
+ return vco->_slowMode ? vco->_slowModeOffset : 0.0f;
+}
+
void VCO::onReset() {
_syncTrigger.reset();
_modulationStep = modulationSteps;
diff --git a/src/VCO.hpp b/src/VCO.hpp
@@ -11,8 +11,6 @@ extern Model* modelVCO;
namespace bogaudio {
-struct VCOFrequencyParamQuantity;
-
struct VCO : Module {
enum ParamsIds {
FREQUENCY_PARAM,
@@ -72,6 +70,10 @@ struct VCO : Module {
PositiveZeroCrossing _syncTrigger;
bogaudio::dsp::SlewLimiter _squarePulseWidthSL;
+ struct VCOFrequencyParamQuantity : FrequencyParamQuantity {
+ float offset() override;
+ };
+
VCO() {
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
configParam<VCOFrequencyParamQuantity>(FREQUENCY_PARAM, -3.0f, 6.0f, 0.0f, "Frequency", " Hz");
@@ -94,11 +96,4 @@ struct VCO : Module {
void setFrequency(float frequency);
};
-struct VCOFrequencyParamQuantity : FrequencyParamQuantity {
- float offset() override {
- VCO* vco = static_cast<VCO*>(module);
- return vco->_slowMode ? vco->_slowModeOffset : 0.0f;
- }
-};
-
} // namespace bogaudio
diff --git a/src/XCO.cpp b/src/XCO.cpp
@@ -2,6 +2,11 @@
#include "XCO.hpp"
#include "dsp/pitch.hpp"
+float XCO::XCOFrequencyParamQuantity::offset() {
+ XCO* xco = static_cast<XCO*>(module);
+ return xco->_slowMode ? xco->_slowModeOffset : 0.0f;
+}
+
void XCO::onReset() {
_syncTrigger.reset();
_modulationStep = modulationSteps;
diff --git a/src/XCO.hpp b/src/XCO.hpp
@@ -11,8 +11,6 @@ extern Model* modelXCO;
namespace bogaudio {
-struct XCOFrequencyParamQuantity;
-
struct XCO : Module {
enum ParamsIds {
FREQUENCY_PARAM,
@@ -120,6 +118,10 @@ struct XCO : Module {
bogaudio::dsp::SlewLimiter _triangleMixSL;
bogaudio::dsp::SlewLimiter _sineMixSL;
+ struct XCOFrequencyParamQuantity : FrequencyParamQuantity {
+ float offset() override;
+ };
+
XCO() {
config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
configParam<XCOFrequencyParamQuantity>(FREQUENCY_PARAM, -3.0f, 6.0f, 0.0f, "Frequency", " Hz");
@@ -155,11 +157,4 @@ struct XCO : Module {
void setFrequency(float frequency);
};
-struct XCOFrequencyParamQuantity : FrequencyParamQuantity {
- float offset() override {
- XCO* xco = static_cast<XCO*>(module);
- return xco->_slowMode ? xco->_slowModeOffset : 0.0f;
- }
-};
-
} // namespace bogaudio
diff --git a/src/lfo_base.cpp b/src/lfo_base.cpp
@@ -2,6 +2,11 @@
#include "lfo_base.hpp"
#include "dsp/pitch.hpp"
+float LFOBase::LFOFrequencyParamQuantity::offset() {
+ LFOBase* lfo = static_cast<LFOBase*>(module);
+ return lfo->getPitchOffset();
+}
+
float LFOBase::getPitchOffset() {
float offset = -3.0f;
if (_slowMode) {
diff --git a/src/lfo_base.hpp b/src/lfo_base.hpp
@@ -17,6 +17,10 @@ struct LFOBase : Module {
bool _slowMode = false;
PitchModeListener* _pitchModeListener = NULL;
+ struct LFOFrequencyParamQuantity : FrequencyParamQuantity {
+ float offset() override;
+ };
+
LFOBase(int np, int ni, int no, int nl) {
config(np, ni, no, nl);
}
@@ -25,11 +29,5 @@ struct LFOBase : Module {
void setFrequency(Param& frequency, Input& pitch, Phasor& phasor);
};
-struct LFOFrequencyParamQuantity : FrequencyParamQuantity {
- float offset() override {
- LFOBase* lfo = static_cast<LFOBase*>(module);
- return lfo->getPitchOffset();
- }
-};
} // namespace bogaudio