From 9eccc5549b2a88cb49ba36cc4aa0cd035bc47107 Mon Sep 17 00:00:00 2001 From: stoermelder Date: Mon, 22 Apr 2024 19:19:59 +0200 Subject: [PATCH] MIdi-Cat Mem, Ctx - fixed broken button-prcessing #356 --- CHANGELOG.md | 12 ++++++++---- src/MidiCat.cpp | 12 ++++-------- src/MidiCatCtx.cpp | 12 ++++++++++++ src/MidiCatMem.cpp | 18 ++++++++++++++++++ src/components.hpp | 12 ++++-------- 5 files changed, 46 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a550d2c..7132a2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,10 @@ - Fixed knob reset on double-click in Semitone/Octave-mode (#387) - Module [GOTO](./docs/Goto.md) - Implemented smooth transition for "top left" jump destination (#388) +- Module [MIDI-CAT CTX](./docs/MidiCat.md#ctx-expander) + - Fixed broken button-handling when triggered by MIDI-mapping +- Module [MIDI-CAT MEM](./docs/MidiCat.md#mem-expander) + - Fixed broken button-handling when triggered by MIDI-mapping (#356) - Module [MIDI-MON](./docs/MidiMon.md) - Added support for CC 14-bit/RPN/NRPN messages - Module [MIDI-STEP](./docs/MidiStep.md) @@ -301,9 +305,6 @@ - Fixed crash on locking more than 32 parameters (#176) - Module [INTERMIX](./docs/Intermix.md) - Added support for polyphony (#199) -- Module [MEM](./docs/MidiCat.md#mem-expander) - - Added support for MIDI-CAT's new slew-limiting and scaling options ([manual](./docs/MidiCat.md#slew-limiting-and-input-scaling)) - - Added scanning for next or previous modules with stored mapping ([manual](./docs/MidiCat.md#mem-scan)) (#200) - Module [µMAP](./docs/CVMapMicro.md) - Added input voltage display - Module [MIDI-CAT](./docs/MidiCat.md) @@ -317,6 +318,9 @@ - Fixed broken "Re-send MIDI feedback" option - Added context menu option for re-sending MIDI feedback periodically ([manual](./docs/MidiCat.md#feedback-periodically)) - Added note-mode "Toggle + Velocity" ([manual](./docs/MidiCat.md#toggle-velocity)) +- Module [MIDI-CAT MEM](./docs/MidiCat.md#mem-expander) + - Added support for MIDI-CAT's new slew-limiting and scaling options ([manual](./docs/MidiCat.md#slew-limiting-and-input-scaling)) + - Added scanning for next or previous modules with stored mapping ([manual](./docs/MidiCat.md#mem-scan)) (#200) - Module [MIDI-STEP](./docs/MidiStep.md) - Added option for Akai MPD218 ([manual](./docs/MidiStep.md#akai-mpd218)) - Module [MIRROR](./docs/Mirror.md) @@ -350,7 +354,7 @@ ## 1.7.0 -- Module [MEM](./docs/MidiCat.md#mem-expander) +- Module [MIDI-CAT MEM](./docs/MidiCat.md#mem-expander) - New expander-module for MIDI-CAT, storage-unit for MIDI mapping-presets with MIDI-CAT - Module [SPIN](./docs/Spin.md) - New module, converts mouse-wheel or middle mouse-button events into triggers diff --git a/src/MidiCat.cpp b/src/MidiCat.cpp index c4a7c05..80b75fd 100644 --- a/src/MidiCat.cpp +++ b/src/MidiCat.cpp @@ -1671,15 +1671,11 @@ struct MidiCatWidget : ThemedModuleWidget, ParamWidgetContextExte Module* expMem; BufferedSwitchQuantity* expMemPrevQuantity; - dsp::SchmittTrigger expMemPrevTrigger; BufferedSwitchQuantity* expMemNextQuantity; - dsp::SchmittTrigger expMemNextTrigger; BufferedSwitchQuantity* expMemParamQuantity; - dsp::SchmittTrigger expMemParamTrigger; MidiCatCtxBase* expCtx; BufferedSwitchQuantity* expCtxMapQuantity; - dsp::SchmittTrigger expCtxMapTrigger; enum class LEARN_MODE { OFF = 0, @@ -1817,15 +1813,15 @@ struct MidiCatWidget : ThemedModuleWidget, ParamWidgetContextExte } } if (expMem) { - if (expMemPrevTrigger.process(expMemPrevQuantity->buffer)) { + if (expMemPrevQuantity->getBuffer()) { expMemPrevQuantity->resetBuffer(); expMemPrevModule(); } - if (expMemNextTrigger.process(expMemNextQuantity->buffer)) { + if (expMemNextQuantity->getBuffer()) { expMemNextQuantity->resetBuffer(); expMemNextModule(); } - if (expMemParamTrigger.process(expMemParamQuantity->buffer)) { + if (expMemParamQuantity->getBuffer()) { expMemParamQuantity->resetBuffer(); enableLearn(LEARN_MODE::MEM); } @@ -1841,7 +1837,7 @@ struct MidiCatWidget : ThemedModuleWidget, ParamWidgetContextExte } } if (expCtx) { - if (expCtxMapTrigger.process(expCtxMapQuantity->buffer)) { + if (expCtxMapQuantity->getBuffer()) { expCtxMapQuantity->resetBuffer(); module->enableLearn(-1, true); } diff --git a/src/MidiCatCtx.cpp b/src/MidiCatCtx.cpp index ebb7a6f..cece994 100644 --- a/src/MidiCatCtx.cpp +++ b/src/MidiCatCtx.cpp @@ -26,10 +26,14 @@ struct MidiCatCtxModule : MidiCatCtxBase { /** [Stored to JSON] */ std::string midiCatId; + dsp::ClockDivider processDivider; + dsp::SchmittTrigger mapTrigger; + MidiCatCtxModule() { panelTheme = pluginSettings.panelThemeDefault; config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); configSwitch(PARAM_MAP, 0.f, 1.f, 0.f, "Start parameter mapping"); + processDivider.setDivision(48); onReset(); } @@ -42,6 +46,14 @@ struct MidiCatCtxModule : MidiCatCtxBase { return midiCatId; } + void process(const ProcessArgs& args) override { + if (processDivider.process()) { + if (mapTrigger.process(params[PARAM_MAP].getValue())) { + reinterpret_cast(paramQuantities[PARAM_MAP])->setBuffer(); + } + } + } + json_t* dataToJson() override { json_t *rootJ = json_object(); json_object_set_new(rootJ, "panelTheme", json_integer(panelTheme)); diff --git a/src/MidiCatMem.cpp b/src/MidiCatMem.cpp index 420ec8c..a697f27 100644 --- a/src/MidiCatMem.cpp +++ b/src/MidiCatMem.cpp @@ -27,12 +27,18 @@ struct MidiCatMemModule : Module { /** [Stored to JSON] */ std::map, MemModule*> midiMap; + dsp::ClockDivider processDivider; + dsp::SchmittTrigger prevTrigger; + dsp::SchmittTrigger nextTrigger; + dsp::SchmittTrigger applyTrigger; + MidiCatMemModule() { panelTheme = pluginSettings.panelThemeDefault; config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); configSwitch(PARAM_PREV, 0.f, 1.f, 0.f, "Scan for previous module mapping"); configSwitch(PARAM_NEXT, 0.f, 1.f, 0.f, "Scan for next module mapping"); configSwitch(PARAM_APPLY, 0.f, 1.f, 0.f, "Apply mapping"); + processDivider.setDivision(48); onReset(); } @@ -51,6 +57,18 @@ struct MidiCatMemModule : Module { void process(const ProcessArgs& args) override { leftExpander.producerMessage = &midiMap; leftExpander.messageFlipRequested = true; + + if (processDivider.process()) { + if (prevTrigger.process(params[PARAM_PREV].getValue())) { + reinterpret_cast(paramQuantities[PARAM_PREV])->setBuffer(); + } + if (nextTrigger.process(params[PARAM_NEXT].getValue())) { + reinterpret_cast(paramQuantities[PARAM_NEXT])->setBuffer(); + } + if (applyTrigger.process(params[PARAM_APPLY].getValue())) { + reinterpret_cast(paramQuantities[PARAM_APPLY])->setBuffer(); + } + } } json_t* dataToJson() override { diff --git a/src/components.hpp b/src/components.hpp index 7001209..1b24880 100644 --- a/src/components.hpp +++ b/src/components.hpp @@ -369,14 +369,10 @@ struct TriggerParamQuantity : ParamQuantity { }; struct BufferedSwitchQuantity : SwitchQuantity { - float buffer = false; - void setValue(float value) override { - if (value >= 1.f) buffer = true; - SwitchQuantity::setValue(value); - } - void resetBuffer() { - buffer = false; - } + bool buffer = false; + inline bool getBuffer() { return buffer; } + inline void setBuffer() { buffer = true; } + inline void resetBuffer() { buffer = false; } };