BogaudioModules

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

commit 1b243dfe08758575c3f501088537d1f5f2b22ef8
parent b4808db9fd141ff66a5dc1edb4089985e19666f7
Author: Matt Demanett <matt@demanett.net>
Date:   Mon, 15 Jul 2019 01:04:58 -0400

Make custom MenuItems inner classes of the widgets where they are used; this will preclude accidental name clashes.

Diffstat:
Msrc/AddrSeq.cpp | 61++++++++++++++++++++++++++++++-------------------------------
Msrc/Analyzer.cpp | 40++++++++++++++++++++--------------------
Msrc/AnalyzerXL.cpp | 200++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/FMOp.cpp | 36++++++++++++++++++------------------
Msrc/UMix.cpp | 72++++++++++++++++++++++++++++++++++++------------------------------------
Msrc/Walk2.cpp | 112++++++++++++++++++++++++++++++++++++++++----------------------------------------
Msrc/disable_output_limit.hpp | 30+++++++++++++++---------------
Msrc/select_on_clock.hpp | 30+++++++++++++++---------------
Msrc/trigger_on_load.hpp | 30+++++++++++++++---------------
9 files changed, 305 insertions(+), 306 deletions(-)

diff --git a/src/AddrSeq.cpp b/src/AddrSeq.cpp @@ -89,29 +89,6 @@ void AddrSeq::process(const ProcessArgs& args) { outputs[OUT_OUTPUT].setVoltage(out); } - -struct AddrSeqRangeMenuItem : MenuItem { - AddrSeq* _module; - float _offset, _scale; - - AddrSeqRangeMenuItem(AddrSeq* module, const char* label, float offset, float scale) - : _module(module) - , _offset(offset) - , _scale(scale) - { - this->text = label; - } - - void onAction(const event::Action& e) override { - _module->_rangeOffset = _offset; - _module->_rangeScale = _scale; - } - - void step() override { - rightText = (_module->_rangeOffset == _offset && _module->_rangeScale == _scale) ? "✔" : ""; - } -}; - struct AddrSeqWidget : SelectOnClockModuleWidget { static constexpr int hp = 6; @@ -194,20 +171,42 @@ struct AddrSeqWidget : SelectOnClockModuleWidget { addChild(createLight<SmallLight<GreenLight>>(out8LightPosition, module, AddrSeq::OUT8_LIGHT)); } + struct RangeMenuItem : MenuItem { + AddrSeq* _module; + float _offset, _scale; + + RangeMenuItem(AddrSeq* module, const char* label, float offset, float scale) + : _module(module) + , _offset(offset) + , _scale(scale) + { + this->text = label; + } + + void onAction(const event::Action& e) override { + _module->_rangeOffset = _offset; + _module->_rangeScale = _scale; + } + + void step() override { + rightText = (_module->_rangeOffset == _offset && _module->_rangeScale == _scale) ? "✔" : ""; + } + }; + void appendContextMenu(Menu* menu) override { SelectOnClockModuleWidget::appendContextMenu(menu); AddrSeq* m = dynamic_cast<AddrSeq*>(module); assert(m); menu->addChild(new MenuLabel()); - menu->addChild(new AddrSeqRangeMenuItem(m, "Range: +/-10V", 0.0f, 10.0f)); - menu->addChild(new AddrSeqRangeMenuItem(m, "Range: +/-5V", 0.0f, 5.0f)); - menu->addChild(new AddrSeqRangeMenuItem(m, "Range: +/-3V", 0.0f, 3.0f)); - menu->addChild(new AddrSeqRangeMenuItem(m, "Range: +/-1V", 0.0f, 1.0f)); - menu->addChild(new AddrSeqRangeMenuItem(m, "Range: 0V-10V", 1.0f, 5.0f)); - menu->addChild(new AddrSeqRangeMenuItem(m, "Range: 0V-5V", 1.0f, 2.5f)); - menu->addChild(new AddrSeqRangeMenuItem(m, "Range: 0V-3V", 1.0f, 1.5f)); - menu->addChild(new AddrSeqRangeMenuItem(m, "Range: 0V-1V", 1.0f, 0.5f)); + menu->addChild(new RangeMenuItem(m, "Range: +/-10V", 0.0f, 10.0f)); + menu->addChild(new RangeMenuItem(m, "Range: +/-5V", 0.0f, 5.0f)); + menu->addChild(new RangeMenuItem(m, "Range: +/-3V", 0.0f, 3.0f)); + menu->addChild(new RangeMenuItem(m, "Range: +/-1V", 0.0f, 1.0f)); + menu->addChild(new RangeMenuItem(m, "Range: 0V-10V", 1.0f, 5.0f)); + menu->addChild(new RangeMenuItem(m, "Range: 0V-5V", 1.0f, 2.5f)); + menu->addChild(new RangeMenuItem(m, "Range: 0V-3V", 1.0f, 1.5f)); + menu->addChild(new RangeMenuItem(m, "Range: 0V-1V", 1.0f, 0.5f)); } }; diff --git a/src/Analyzer.cpp b/src/Analyzer.cpp @@ -81,26 +81,6 @@ void Analyzer::process(const ProcessArgs& args) { lights[WINDOW_KAISER_LIGHT].value = _core._window == AnalyzerCore::WINDOW_KAISER; } -struct RangeDbMenuItem : MenuItem { - Analyzer* _module; - const float _rangeDb; - - RangeDbMenuItem(Analyzer* module, const char* label, float rangeDb) - : _module(module) - , _rangeDb(rangeDb) - { - this->text = label; - } - - void onAction(const event::Action& e) override { - _module->_rangeDb = _rangeDb; - } - - void step() override { - rightText = _module->_rangeDb == _rangeDb ? "✔" : ""; - } -}; - struct AnalyzerWidget : ModuleWidget { static constexpr int hp = 20; @@ -176,6 +156,26 @@ struct AnalyzerWidget : ModuleWidget { addChild(createLight<SmallLight<GreenLight>>(windowKaiserLightPosition, module, Analyzer::WINDOW_KAISER_LIGHT)); } + struct RangeDbMenuItem : MenuItem { + Analyzer* _module; + const float _rangeDb; + + RangeDbMenuItem(Analyzer* module, const char* label, float rangeDb) + : _module(module) + , _rangeDb(rangeDb) + { + this->text = label; + } + + void onAction(const event::Action& e) override { + _module->_rangeDb = _rangeDb; + } + + void step() override { + rightText = _module->_rangeDb == _rangeDb ? "✔" : ""; + } + }; + void appendContextMenu(Menu* menu) override { Analyzer* a = dynamic_cast<Analyzer*>(module); assert(a); diff --git a/src/AnalyzerXL.cpp b/src/AnalyzerXL.cpp @@ -139,106 +139,6 @@ void AnalyzerXL::process(const ProcessArgs& args) { } } -struct RangeMenuItem : MenuItem { - AnalyzerXL* _module; - const float _range; - - RangeMenuItem(AnalyzerXL* module, const char* label, float range) - : _module(module) - , _range(range) - { - this->text = label; - } - - void onAction(const event::Action& e) override { - _module->_range = _range; - } - - void step() override { - rightText = _module->_range == _range ? "✔" : ""; - } -}; - -struct RangeDbMenuItem : MenuItem { - AnalyzerXL* _module; - const float _rangeDb; - - RangeDbMenuItem(AnalyzerXL* module, const char* label, float rangeDb) - : _module(module) - , _rangeDb(rangeDb) - { - this->text = label; - } - - void onAction(const event::Action& e) override { - _module->_rangeDb = _rangeDb; - } - - void step() override { - rightText = _module->_rangeDb == _rangeDb ? "✔" : ""; - } -}; - -struct SmoothMenuItem : MenuItem { - AnalyzerXL* _module; - const float _smooth; - - SmoothMenuItem(AnalyzerXL* module, const char* label, float smooth) - : _module(module) - , _smooth(smooth) - { - this->text = label; - } - - void onAction(const event::Action& e) override { - _module->_smooth = _smooth; - } - - void step() override { - rightText = _module->_smooth == _smooth ? "✔" : ""; - } -}; - -struct QualityMenuItem : MenuItem { - AnalyzerXL* _module; - const AnalyzerCore::Quality _quality; - - QualityMenuItem(AnalyzerXL* module, const char* label, AnalyzerCore::Quality quality) - : _module(module) - , _quality(quality) - { - this->text = label; - } - - void onAction(const event::Action& e) override { - _module->_quality = _quality; - } - - void step() override { - rightText = _module->_quality == _quality ? "✔" : ""; - } -}; - -struct WindowMenuItem : MenuItem { - AnalyzerXL* _module; - const AnalyzerCore::Window _window; - - WindowMenuItem(AnalyzerXL* module, const char* label, AnalyzerCore::Window window) - : _module(module) - , _window(window) - { - this->text = label; - } - - void onAction(const event::Action& e) override { - _module->_window = _window; - } - - void step() override { - rightText = _module->_window == _window ? "✔" : ""; - } -}; - struct AnalyzerXLWidget : ModuleWidget { static constexpr int hp = 42; @@ -283,6 +183,106 @@ struct AnalyzerXLWidget : ModuleWidget { addInput(createInput<Port24>(signalhInputPosition, module, AnalyzerXL::SIGNALH_INPUT)); } + struct RangeMenuItem : MenuItem { + AnalyzerXL* _module; + const float _range; + + RangeMenuItem(AnalyzerXL* module, const char* label, float range) + : _module(module) + , _range(range) + { + this->text = label; + } + + void onAction(const event::Action& e) override { + _module->_range = _range; + } + + void step() override { + rightText = _module->_range == _range ? "✔" : ""; + } + }; + + struct RangeDbMenuItem : MenuItem { + AnalyzerXL* _module; + const float _rangeDb; + + RangeDbMenuItem(AnalyzerXL* module, const char* label, float rangeDb) + : _module(module) + , _rangeDb(rangeDb) + { + this->text = label; + } + + void onAction(const event::Action& e) override { + _module->_rangeDb = _rangeDb; + } + + void step() override { + rightText = _module->_rangeDb == _rangeDb ? "✔" : ""; + } + }; + + struct SmoothMenuItem : MenuItem { + AnalyzerXL* _module; + const float _smooth; + + SmoothMenuItem(AnalyzerXL* module, const char* label, float smooth) + : _module(module) + , _smooth(smooth) + { + this->text = label; + } + + void onAction(const event::Action& e) override { + _module->_smooth = _smooth; + } + + void step() override { + rightText = _module->_smooth == _smooth ? "✔" : ""; + } + }; + + struct QualityMenuItem : MenuItem { + AnalyzerXL* _module; + const AnalyzerCore::Quality _quality; + + QualityMenuItem(AnalyzerXL* module, const char* label, AnalyzerCore::Quality quality) + : _module(module) + , _quality(quality) + { + this->text = label; + } + + void onAction(const event::Action& e) override { + _module->_quality = _quality; + } + + void step() override { + rightText = _module->_quality == _quality ? "✔" : ""; + } + }; + + struct WindowMenuItem : MenuItem { + AnalyzerXL* _module; + const AnalyzerCore::Window _window; + + WindowMenuItem(AnalyzerXL* module, const char* label, AnalyzerCore::Window window) + : _module(module) + , _window(window) + { + this->text = label; + } + + void onAction(const event::Action& e) override { + _module->_window = _window; + } + + void step() override { + rightText = _module->_window == _window ? "✔" : ""; + } + }; + void appendContextMenu(Menu* menu) override { AnalyzerXL* a = dynamic_cast<AnalyzerXL*>(module); assert(a); diff --git a/src/FMOp.cpp b/src/FMOp.cpp @@ -221,24 +221,6 @@ void FMOp::process(const ProcessArgs& args) { outputs[AUDIO_OUTPUT].setVoltage(_feedbackDelayedSample = amplitude * sample); } -struct LinearLevelMenuItem : MenuItem { - FMOp* _module; - - LinearLevelMenuItem(FMOp* module, const char* label) - : _module(module) - { - this->text = label; - } - - void onAction(const event::Action& e) override { - _module->_linearLevel = !_module->_linearLevel; - } - - void step() override { - rightText = _module->_linearLevel ? "✔" : ""; - } -}; - struct FMOpWidget : ModuleWidget { static constexpr int hp = 10; @@ -315,6 +297,24 @@ struct FMOpWidget : ModuleWidget { addChild(createLight<SmallLight<GreenLight>>(envToDepthLightPosition, module, FMOp::ENV_TO_DEPTH_LIGHT)); } + struct LinearLevelMenuItem : MenuItem { + FMOp* _module; + + LinearLevelMenuItem(FMOp* module, const char* label) + : _module(module) + { + this->text = label; + } + + void onAction(const event::Action& e) override { + _module->_linearLevel = !_module->_linearLevel; + } + + void step() override { + rightText = _module->_linearLevel ? "✔" : ""; + } + }; + void appendContextMenu(Menu* menu) override { FMOp* fmop = dynamic_cast<FMOp*>(module); assert(fmop); diff --git a/src/UMix.cpp b/src/UMix.cpp @@ -65,42 +65,6 @@ void UMix::process(const ProcessArgs& args) { } } -struct AverageMenuItem : MenuItem { - UMix* _module; - - AverageMenuItem(UMix* module, const char* label) - : _module(module) - { - this->text = label; - } - - void onAction(const event::Action& e) override { - _module->_sum = !_module->_sum; - } - - void step() override { - rightText = !_module->_sum ? "✔" : ""; - } -}; - -struct CVModeMenuItem : MenuItem { - UMix* _module; - - CVModeMenuItem(UMix* module, const char* label) - : _module(module) - { - this->text = label; - } - - void onAction(const event::Action& e) override { - _module->_cvMode = !_module->_cvMode; - } - - void step() override { - rightText = _module->_cvMode ? "✔" : ""; - } -}; - struct UMixWidget : ModuleWidget { static constexpr int hp = 3; @@ -147,6 +111,42 @@ struct UMixWidget : ModuleWidget { addOutput(createOutput<Port24>(outOutputPosition, module, UMix::OUT_OUTPUT)); } + struct AverageMenuItem : MenuItem { + UMix* _module; + + AverageMenuItem(UMix* module, const char* label) + : _module(module) + { + this->text = label; + } + + void onAction(const event::Action& e) override { + _module->_sum = !_module->_sum; + } + + void step() override { + rightText = !_module->_sum ? "✔" : ""; + } + }; + + struct CVModeMenuItem : MenuItem { + UMix* _module; + + CVModeMenuItem(UMix* module, const char* label) + : _module(module) + { + this->text = label; + } + + void onAction(const event::Action& e) override { + _module->_cvMode = !_module->_cvMode; + } + + void step() override { + rightText = _module->_cvMode ? "✔" : ""; + } + }; + void appendContextMenu(Menu* menu) override { UMix* umix = dynamic_cast<UMix*>(module); assert(umix); diff --git a/src/Walk2.cpp b/src/Walk2.cpp @@ -419,62 +419,6 @@ struct Walk2Display : TransparentWidget { } }; -struct ZoomOutMenuItem : MenuItem { - Walk2* _module; - const bool _zoomOut; - - ZoomOutMenuItem(Walk2* module, const char* label, bool zoomOut) - : _module(module) - , _zoomOut(zoomOut) - { - this->text = label; - } - - void onAction(const event::Action& e) override { - _module->_zoomOut = _zoomOut; - } - - void step() override { - rightText = _module->_zoomOut == _zoomOut ? "✔" : ""; - } -}; - -struct GridMenuItem : MenuItem { - Walk2* _module; - - GridMenuItem(Walk2* module, const char* label) : _module(module) { - this->text = label; - } - - void onAction(const event::Action& e) override { - _module->_drawGrid = !_module->_drawGrid; - } - - void step() override { - rightText = _module->_drawGrid ? "✔" : ""; - } -}; - -struct ColorMenuItem : MenuItem { - Walk2* _module; - const Walk2::TraceColor _color; - - ColorMenuItem(Walk2* module, const char* label, Walk2::TraceColor color) - : _module(module) - , _color(color) - { - this->text = label; - } - - void onAction(const event::Action& e) override { - _module->_traceColor = _color; - } - - void step() override { - rightText = _module->_traceColor == _color ? "✔" : ""; - } -}; - struct Walk2Widget : ModuleWidget { static constexpr int hp = 14; @@ -545,6 +489,62 @@ struct Walk2Widget : ModuleWidget { addOutput(createOutput<Port24>(distanceOutputPosition, module, Walk2::DISTANCE_OUTPUT)); } + struct ZoomOutMenuItem : MenuItem { + Walk2* _module; + const bool _zoomOut; + + ZoomOutMenuItem(Walk2* module, const char* label, bool zoomOut) + : _module(module) + , _zoomOut(zoomOut) + { + this->text = label; + } + + void onAction(const event::Action& e) override { + _module->_zoomOut = _zoomOut; + } + + void step() override { + rightText = _module->_zoomOut == _zoomOut ? "✔" : ""; + } + }; + + struct GridMenuItem : MenuItem { + Walk2* _module; + + GridMenuItem(Walk2* module, const char* label) : _module(module) { + this->text = label; + } + + void onAction(const event::Action& e) override { + _module->_drawGrid = !_module->_drawGrid; + } + + void step() override { + rightText = _module->_drawGrid ? "✔" : ""; + } + }; + + struct ColorMenuItem : MenuItem { + Walk2* _module; + const Walk2::TraceColor _color; + + ColorMenuItem(Walk2* module, const char* label, Walk2::TraceColor color) + : _module(module) + , _color(color) + { + this->text = label; + } + + void onAction(const event::Action& e) override { + _module->_traceColor = _color; + } + + void step() override { + rightText = _module->_traceColor == _color ? "✔" : ""; + } + }; + void appendContextMenu(Menu* menu) override { Walk2* w = dynamic_cast<Walk2*>(module); assert(w); diff --git a/src/disable_output_limit.hpp b/src/disable_output_limit.hpp @@ -11,25 +11,25 @@ struct DisableOutputLimitModule : Module { void dataFromJson(json_t* root) override; }; -struct DisableOutputLimitMenuItem : MenuItem { - DisableOutputLimitModule* _module; +struct DisableOutputLimitModuleWidget : ModuleWidget { + struct DisableOutputLimitMenuItem : MenuItem { + DisableOutputLimitModule* _module; - DisableOutputLimitMenuItem(DisableOutputLimitModule* module, const char* label) - : _module(module) - { - this->text = label; - } + DisableOutputLimitMenuItem(DisableOutputLimitModule* module, const char* label) + : _module(module) + { + this->text = label; + } - void onAction(const event::Action& e) override { - _module->_disableOutputLimit = !_module->_disableOutputLimit; - } + void onAction(const event::Action& e) override { + _module->_disableOutputLimit = !_module->_disableOutputLimit; + } - void step() override { - rightText = _module->_disableOutputLimit ? "✔" : ""; - } -}; + void step() override { + rightText = _module->_disableOutputLimit ? "✔" : ""; + } + }; -struct DisableOutputLimitModuleWidget : ModuleWidget { void appendContextMenu(Menu* menu) override { DisableOutputLimitModule* dolm = dynamic_cast<DisableOutputLimitModule*>(module); assert(dolm); diff --git a/src/select_on_clock.hpp b/src/select_on_clock.hpp @@ -13,25 +13,25 @@ struct SelectOnClockModule : Module { void dataFromJson(json_t* root) override; }; -struct SelectOnClockMenuItem : MenuItem { - SelectOnClockModule* _module; +struct SelectOnClockModuleWidget : ModuleWidget { + struct SelectOnClockMenuItem : MenuItem { + SelectOnClockModule* _module; - SelectOnClockMenuItem(SelectOnClockModule* module, const char* label) - : _module(module) - { - this->text = label; - } + SelectOnClockMenuItem(SelectOnClockModule* module, const char* label) + : _module(module) + { + this->text = label; + } - void onAction(const event::Action& e) override { - _module->_selectOnClock = !_module->_selectOnClock; - } + void onAction(const event::Action& e) override { + _module->_selectOnClock = !_module->_selectOnClock; + } - void step() override { - rightText = _module->_selectOnClock ? "✔" : ""; - } -}; + void step() override { + rightText = _module->_selectOnClock ? "✔" : ""; + } + }; -struct SelectOnClockModuleWidget : ModuleWidget { void appendContextMenu(Menu* menu) override { SelectOnClockModule* m = dynamic_cast<SelectOnClockModule*>(module); assert(m); diff --git a/src/trigger_on_load.hpp b/src/trigger_on_load.hpp @@ -16,25 +16,25 @@ struct TriggerOnLoadModule : Module { virtual bool shouldTriggerOnNextLoad() = 0; }; -struct TriggerOnLoadMenuItem : MenuItem { - TriggerOnLoadModule* _module; +struct TriggerOnLoadModuleWidget : ModuleWidget { + struct TriggerOnLoadMenuItem : MenuItem { + TriggerOnLoadModule* _module; - TriggerOnLoadMenuItem(TriggerOnLoadModule* module, const char* label) - : _module(module) - { - this->text = label; - } + TriggerOnLoadMenuItem(TriggerOnLoadModule* module, const char* label) + : _module(module) + { + this->text = label; + } - void onAction(const event::Action& e) override { - _module->_triggerOnLoad = !_module->_triggerOnLoad; - } + void onAction(const event::Action& e) override { + _module->_triggerOnLoad = !_module->_triggerOnLoad; + } - void step() override { - rightText = _module->_triggerOnLoad ? "✔" : ""; - } -}; + void step() override { + rightText = _module->_triggerOnLoad ? "✔" : ""; + } + }; -struct TriggerOnLoadModuleWidget : ModuleWidget { void appendContextMenu(Menu* menu) override { TriggerOnLoadModule* m = dynamic_cast<TriggerOnLoadModule*>(module); assert(m);