BogaudioModules

BogaudioModules for VCV Rack
Log | Files | Refs | README | LICENSE

commit 65ad1d5910168f90019e58dc8411c6b30f9a1b7f
parent 7182f375be4f4fddbc3ef24a82dfbcfe7c688687
Author: Matt Demanett <matt@demanett.net>
Date:   Wed, 10 Jun 2020 00:16:48 -0400

Break bizarre habit of defining methods in the header for certain Widgets (a couple random things).

Diffstat:
Msrc/addressable_sequence.cpp | 24++++++++++++++++++++++++
Msrc/addressable_sequence.hpp | 22++--------------------
Msrc/disable_output_limit.cpp | 8++++++++
Msrc/disable_output_limit.hpp | 7+------
Msrc/matrix_base.cpp | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/matrix_base.hpp | 61+++++--------------------------------------------------------
Asrc/rack_overrides.cpp | 34++++++++++++++++++++++++++++++++++
Msrc/rack_overrides.hpp | 30++----------------------------
Msrc/trigger_on_load.cpp | 8++++++++
Msrc/trigger_on_load.hpp | 7+------
Msrc/utils.hpp | 4++--
11 files changed, 149 insertions(+), 118 deletions(-)

diff --git a/src/addressable_sequence.cpp b/src/addressable_sequence.cpp @@ -120,3 +120,27 @@ int AddressableSequenceModule::nextStep( int AddressableSequenceModule::setStep(int c, int i, int n) { return _step[c] = i % n; } + + +void AddressableSequenceBaseModuleWidget::appendContextMenu(Menu* menu) { + AddressableSequenceModule* m = dynamic_cast<AddressableSequenceModule*>(module); + assert(m); + + menu->addChild(new MenuLabel()); + OptionsMenuItem* p = new OptionsMenuItem("Polyphony channels from"); + p->addItem(OptionMenuItem("CLOCK input", [m]() { return m->_polyInputID == m->_clockInputID; }, [m]() { m->_polyInputID = m->_clockInputID; })); + p->addItem(OptionMenuItem("SELECT input", [m]() { return m->_polyInputID == m->_selectInputID; }, [m]() { m->_polyInputID = m->_selectInputID; })); + OptionsMenuItem::addToMenu(p, menu); + + menu->addChild(new BoolOptionMenuItem("Reverse step on negative clock", [m]() { return &m->_reverseOnNegativeClock; })); + menu->addChild(new BoolOptionMenuItem("Triggered select mode", [m]() { return &m->_triggeredSelect; })); +} + + +void AddressableSequenceModuleWidget::appendContextMenu(Menu* menu) { + AddressableSequenceBaseModuleWidget::appendContextMenu(menu); + + AddressableSequenceModule* m = dynamic_cast<AddressableSequenceModule*>(module); + assert(m); + menu->addChild(new BoolOptionMenuItem("Select on clock mode", [m]() { return &m->_selectOnClock; })); +} diff --git a/src/addressable_sequence.hpp b/src/addressable_sequence.hpp @@ -47,29 +47,11 @@ struct AddressableSequenceModule : BGModule { }; struct AddressableSequenceBaseModuleWidget : ModuleWidget { - void appendContextMenu(Menu* menu) override { - AddressableSequenceModule* m = dynamic_cast<AddressableSequenceModule*>(module); - assert(m); - - menu->addChild(new MenuLabel()); - OptionsMenuItem* p = new OptionsMenuItem("Polyphony channels from"); - p->addItem(OptionMenuItem("CLOCK input", [m]() { return m->_polyInputID == m->_clockInputID; }, [m]() { m->_polyInputID = m->_clockInputID; })); - p->addItem(OptionMenuItem("SELECT input", [m]() { return m->_polyInputID == m->_selectInputID; }, [m]() { m->_polyInputID = m->_selectInputID; })); - OptionsMenuItem::addToMenu(p, menu); - - menu->addChild(new BoolOptionMenuItem("Reverse step on negative clock", [m]() { return &m->_reverseOnNegativeClock; })); - menu->addChild(new BoolOptionMenuItem("Triggered select mode", [m]() { return &m->_triggeredSelect; })); - } + void appendContextMenu(Menu* menu) override; }; struct AddressableSequenceModuleWidget : AddressableSequenceBaseModuleWidget { - void appendContextMenu(Menu* menu) override { - AddressableSequenceBaseModuleWidget::appendContextMenu(menu); - - AddressableSequenceModule* m = dynamic_cast<AddressableSequenceModule*>(module); - assert(m); - menu->addChild(new BoolOptionMenuItem("Select on clock mode", [m]() { return &m->_selectOnClock; })); - } + void appendContextMenu(Menu* menu) override; }; typedef OutputRangeModule<AddressableSequenceModule> OutputRangeAddressableSequenceModule; diff --git a/src/disable_output_limit.cpp b/src/disable_output_limit.cpp @@ -15,3 +15,11 @@ void DisableOutputLimitModule::dataFromJson(json_t* root) { _disableOutputLimit = json_is_true(dol); } } + + +void DisableOutputLimitModuleWidget::appendContextMenu(Menu* menu) { + DisableOutputLimitModule* m = dynamic_cast<DisableOutputLimitModule*>(module); + assert(m); + menu->addChild(new MenuLabel()); + menu->addChild(new BoolOptionMenuItem("Disable output limit", [m]() { return &m->_disableOutputLimit; })); +} diff --git a/src/disable_output_limit.hpp b/src/disable_output_limit.hpp @@ -12,12 +12,7 @@ struct DisableOutputLimitModule : BGModule { }; struct DisableOutputLimitModuleWidget : ModuleWidget { - void appendContextMenu(Menu* menu) override { - DisableOutputLimitModule* m = dynamic_cast<DisableOutputLimitModule*>(module); - assert(m); - menu->addChild(new MenuLabel()); - menu->addChild(new BoolOptionMenuItem("Disable output limit", [m]() { return &m->_disableOutputLimit; })); - } + void appendContextMenu(Menu* menu) override; }; } // namespace bogaudio diff --git a/src/matrix_base.cpp b/src/matrix_base.cpp @@ -35,6 +35,25 @@ void MatrixBaseModule::modulate() { } +void MatrixBaseModuleWidget::appendContextMenu(Menu* menu) { + MatrixBaseModule* m = dynamic_cast<MatrixBaseModule*>(module); + assert(m); + menu->addChild(new MenuLabel()); + + OptionsMenuItem* g = new OptionsMenuItem("Input gain"); + g->addItem(OptionMenuItem("Unity", [m]() { return (int)m->_inputGainDb == 0; }, [m]() { m->_inputGainDb = 0.0f; })); + g->addItem(OptionMenuItem("-3db", [m]() { return (int)m->_inputGainDb == -3; }, [m]() { m->_inputGainDb = -3.0f; })); + g->addItem(OptionMenuItem("-6db", [m]() { return (int)m->_inputGainDb == -6; }, [m]() { m->_inputGainDb = -6.0f; })); + g->addItem(OptionMenuItem("-12db", [m]() { return (int)m->_inputGainDb == -12; }, [m]() { m->_inputGainDb = -12.0f; })); + OptionsMenuItem::addToMenu(g, menu); + + OptionsMenuItem* c = new OptionsMenuItem("Output clipping"); + c->addItem(OptionMenuItem("Soft/saturated (better for audio)", [m]() { return m->_clippingMode == MatrixBaseModule::SOFT_CLIPPING; }, [m]() { m->_clippingMode = MatrixBaseModule::SOFT_CLIPPING; })); + c->addItem(OptionMenuItem("Hard/clipped (better for CV)", [m]() { return m->_clippingMode == MatrixBaseModule::HARD_CLIPPING; }, [m]() { m->_clippingMode = MatrixBaseModule::HARD_CLIPPING; })); + OptionsMenuItem::addToMenu(c, menu); +} + + int MatrixModule::channels() { return inputs[_firstInputID].getChannels(); } @@ -95,6 +114,33 @@ void KnobMatrixModule::dataFromJson(json_t* root) { } +void KnobMatrixModuleWidget::createKnob(math::Vec& position, KnobMatrixModule* module, int id) { + IndicatorKnob19* knob = dynamic_cast<IndicatorKnob19*>(createParam<IndicatorKnob19>(position, module, id)); + if (module) { + knob->setDrawColorsCallback([module]() { return module->_indicatorKnobs; }); + } + addParam(knob); + _knobs.push_back(knob); +} + +void KnobMatrixModuleWidget::redrawKnobs() { + for (IndicatorKnob19* knob : _knobs) { + knob->redraw(); + } +} + +void KnobMatrixModuleWidget::appendContextMenu(Menu* menu) { + KnobMatrixModule* m = dynamic_cast<KnobMatrixModule*>(module); + assert(m); + MatrixBaseModuleWidget::appendContextMenu(menu); + menu->addChild(new OptionMenuItem( + "Indicator knobs", + [m]() { return m->_indicatorKnobs; }, + [m, this]() { m->_indicatorKnobs = !m->_indicatorKnobs; this->redrawKnobs(); } + )); +} + + #define INVERTING "inverting" #define INVERTING_CLICK "click" #define INVERTING_PARAM "param" @@ -243,3 +289,19 @@ void SwitchMatrixModule::setColumnExclusive(bool e) { } } } + + +void SwitchMatrixModuleWidget::appendContextMenu(Menu* menu) { + SwitchMatrixModule* m = dynamic_cast<SwitchMatrixModule*>(module); + assert(m); + MatrixBaseModuleWidget::appendContextMenu(menu); + + OptionsMenuItem* i = new OptionsMenuItem("Inverting"); + i->addItem(OptionMenuItem("By param entry (right-click)", [m]() { return m->_inverting == SwitchMatrixModule::PARAM_INVERTING; }, [m]() { m->setInverting(SwitchMatrixModule::PARAM_INVERTING); })); + i->addItem(OptionMenuItem("On second click", [m]() { return m->_inverting == SwitchMatrixModule::CLICK_INVERTING; }, [m]() { m->setInverting(SwitchMatrixModule::CLICK_INVERTING); })); + i->addItem(OptionMenuItem("Disabled", [m]() { return m->_inverting == SwitchMatrixModule::NO_INVERTING; }, [m]() { m->setInverting(SwitchMatrixModule::NO_INVERTING); })); + OptionsMenuItem::addToMenu(i, menu); + + menu->addChild(new OptionMenuItem("Exclusive by rows", [m]() { return m->_rowExclusive; }, [m]() { m->setRowExclusive(!m->_rowExclusive); })); + menu->addChild(new OptionMenuItem("Exclusive by columns", [m]() { return m->_columnExclusive; }, [m]() { m->setColumnExclusive(!m->_columnExclusive); })); +} diff --git a/src/matrix_base.hpp b/src/matrix_base.hpp @@ -25,23 +25,7 @@ struct MatrixBaseModule : BGModule { }; struct MatrixBaseModuleWidget : ModuleWidget { - void appendContextMenu(Menu* menu) override { - MatrixBaseModule* m = dynamic_cast<MatrixBaseModule*>(module); - assert(m); - menu->addChild(new MenuLabel()); - - OptionsMenuItem* g = new OptionsMenuItem("Input gain"); - g->addItem(OptionMenuItem("Unity", [m]() { return (int)m->_inputGainDb == 0; }, [m]() { m->_inputGainDb = 0.0f; })); - g->addItem(OptionMenuItem("-3db", [m]() { return (int)m->_inputGainDb == -3; }, [m]() { m->_inputGainDb = -3.0f; })); - g->addItem(OptionMenuItem("-6db", [m]() { return (int)m->_inputGainDb == -6; }, [m]() { m->_inputGainDb = -6.0f; })); - g->addItem(OptionMenuItem("-12db", [m]() { return (int)m->_inputGainDb == -12; }, [m]() { m->_inputGainDb = -12.0f; })); - OptionsMenuItem::addToMenu(g, menu); - - OptionsMenuItem* c = new OptionsMenuItem("Output clipping"); - c->addItem(OptionMenuItem("Soft/saturated (better for audio)", [m]() { return m->_clippingMode == MatrixBaseModule::SOFT_CLIPPING; }, [m]() { m->_clippingMode = MatrixBaseModule::SOFT_CLIPPING; })); - c->addItem(OptionMenuItem("Hard/clipped (better for CV)", [m]() { return m->_clippingMode == MatrixBaseModule::HARD_CLIPPING; }, [m]() { m->_clippingMode = MatrixBaseModule::HARD_CLIPPING; })); - OptionsMenuItem::addToMenu(c, menu); - } + void appendContextMenu(Menu* menu) override; }; struct MatrixModule : MatrixBaseModule { @@ -88,31 +72,9 @@ struct KnobMatrixModule : MatrixModule { struct KnobMatrixModuleWidget : MatrixBaseModuleWidget { std::vector<IndicatorKnob19*> _knobs; - void createKnob(math::Vec& position, KnobMatrixModule* module, int id) { - IndicatorKnob19* knob = dynamic_cast<IndicatorKnob19*>(createParam<IndicatorKnob19>(position, module, id)); - if (module) { - knob->setDrawColorsCallback([module]() { return module->_indicatorKnobs; }); - } - addParam(knob); - _knobs.push_back(knob); - } - - void redrawKnobs() { - for (IndicatorKnob19* knob : _knobs) { - knob->redraw(); - } - } - - void appendContextMenu(Menu* menu) override { - KnobMatrixModule* m = dynamic_cast<KnobMatrixModule*>(module); - assert(m); - MatrixBaseModuleWidget::appendContextMenu(menu); - menu->addChild(new OptionMenuItem( - "Indicator knobs", - [m]() { return m->_indicatorKnobs; }, - [m, this]() { m->_indicatorKnobs = !m->_indicatorKnobs; this->redrawKnobs(); } - )); - } + void createKnob(math::Vec& position, KnobMatrixModule* module, int id); + void redrawKnobs(); + void appendContextMenu(Menu* menu) override; }; struct SwitchMatrixModule : MatrixModule { @@ -150,20 +112,7 @@ struct SwitchMatrixModuleWidget : MatrixBaseModuleWidget { addParam(s); } - void appendContextMenu(Menu* menu) override { - SwitchMatrixModule* m = dynamic_cast<SwitchMatrixModule*>(module); - assert(m); - MatrixBaseModuleWidget::appendContextMenu(menu); - - OptionsMenuItem* i = new OptionsMenuItem("Inverting"); - i->addItem(OptionMenuItem("By param entry (right-click)", [m]() { return m->_inverting == SwitchMatrixModule::PARAM_INVERTING; }, [m]() { m->setInverting(SwitchMatrixModule::PARAM_INVERTING); })); - i->addItem(OptionMenuItem("On second click", [m]() { return m->_inverting == SwitchMatrixModule::CLICK_INVERTING; }, [m]() { m->setInverting(SwitchMatrixModule::CLICK_INVERTING); })); - i->addItem(OptionMenuItem("Disabled", [m]() { return m->_inverting == SwitchMatrixModule::NO_INVERTING; }, [m]() { m->setInverting(SwitchMatrixModule::NO_INVERTING); })); - OptionsMenuItem::addToMenu(i, menu); - - menu->addChild(new OptionMenuItem("Exclusive by rows", [m]() { return m->_rowExclusive; }, [m]() { m->setRowExclusive(!m->_rowExclusive); })); - menu->addChild(new OptionMenuItem("Exclusive by columns", [m]() { return m->_columnExclusive; }, [m]() { m->setColumnExclusive(!m->_columnExclusive); })); - } + void appendContextMenu(Menu* menu) override; }; } // namespace bogaudio diff --git a/src/rack_overrides.cpp b/src/rack_overrides.cpp @@ -0,0 +1,34 @@ +#include "rack_overrides.hpp" + +using namespace bogaudio; + +bool Trigger::process(float in) { + if (state) { + if (in <= _lowThreshold) { + state = false; + } + } + else { + if (in >= _highThreshold) { + state = true; + return true; + } + } + return false; +} + + +bool NegativeTrigger::process(float in) { + if (state) { + if (in >= _lowThreshold) { + state = false; + } + } + else { + if (in <= _highThreshold) { + state = true; + return true; + } + } + return false; +} diff --git a/src/rack_overrides.hpp b/src/rack_overrides.hpp @@ -16,20 +16,7 @@ struct Trigger : rack::dsp::SchmittTrigger { reset(); } - bool process(float in) { - if (state) { - if (in <= _lowThreshold) { - state = false; - } - } - else { - if (in >= _highThreshold) { - state = true; - return true; - } - } - return false; - } + bool process(float in); }; struct NegativeTrigger : rack::dsp::SchmittTrigger { @@ -44,20 +31,7 @@ struct NegativeTrigger : rack::dsp::SchmittTrigger { reset(); } - bool process(float in) { - if (state) { - if (in >= _lowThreshold) { - state = false; - } - } - else { - if (in <= _highThreshold) { - state = true; - return true; - } - } - return false; - } + bool process(float in); }; inline float getZoom() { diff --git a/src/trigger_on_load.cpp b/src/trigger_on_load.cpp @@ -23,3 +23,11 @@ void TriggerOnLoadModule::dataFromJson(json_t* root) { _shouldTriggerOnLoad = json_is_true(stol); } } + + +void TriggerOnLoadModuleWidget::appendContextMenu(Menu* menu) { + TriggerOnLoadModule* m = dynamic_cast<TriggerOnLoadModule*>(module); + assert(m); + menu->addChild(new MenuLabel()); + menu->addChild(new BoolOptionMenuItem(_menuItemLabel.c_str(), [m]() { return &m->_triggerOnLoad; })); +} diff --git a/src/trigger_on_load.hpp b/src/trigger_on_load.hpp @@ -23,12 +23,7 @@ struct TriggerOnLoadModuleWidget : ModuleWidget { : _menuItemLabel(menuItemLabel) {} - void appendContextMenu(Menu* menu) override { - TriggerOnLoadModule* m = dynamic_cast<TriggerOnLoadModule*>(module); - assert(m); - menu->addChild(new MenuLabel()); - menu->addChild(new BoolOptionMenuItem(_menuItemLabel.c_str(), [m]() { return &m->_triggerOnLoad; })); - } + void appendContextMenu(Menu* menu) override; }; } // namespace bogaudio diff --git a/src/utils.hpp b/src/utils.hpp @@ -23,11 +23,11 @@ Model* createModel( struct SpinLock { std::atomic_flag locked = ATOMIC_FLAG_INIT ; - void lock() { + inline void lock() { while (locked.test_and_set(std::memory_order_acquire)) {} } - void unlock() { + inline void unlock() { locked.clear(std::memory_order_release); } };