From dbbc955df628a2d815145241d91f9aceb62df217 Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 22 Mar 2022 11:46:19 +0000 Subject: [PATCH] Small headless optimizations Signed-off-by: falkTX --- plugins/Cardinal/src/HostAudio.cpp | 47 +++++++++++++++++++++---- plugins/Cardinal/src/HostCV.cpp | 12 +++++++ plugins/Cardinal/src/HostMIDI.cpp | 12 +++++++ plugins/Cardinal/src/HostParameters.cpp | 11 +++--- plugins/Cardinal/src/HostTime.cpp | 18 ++++++++++ plugins/Cardinal/src/Widgets.hpp | 2 ++ 6 files changed, 92 insertions(+), 10 deletions(-) diff --git a/plugins/Cardinal/src/HostAudio.cpp b/plugins/Cardinal/src/HostAudio.cpp index 4578a7f..6b022ad 100644 --- a/plugins/Cardinal/src/HostAudio.cpp +++ b/plugins/Cardinal/src/HostAudio.cpp @@ -29,6 +29,8 @@ struct HostAudio : TerminalModule { const int numParams; const int numInputs; const int numOutputs; + bool bypassed = false; + bool in2connected = false; int dataFrame = 0; int64_t lastBlockFrame = -1; @@ -74,8 +76,12 @@ struct HostAudio : TerminalModule { // only checked on input if (lastBlockFrame != blockFrame) { + bypassed = isBypassed(); dataFrame = 0; lastBlockFrame = blockFrame; + + if (numIO == 2) + in2connected = inputs[1].isConnected(); } // only incremented on output @@ -83,7 +89,7 @@ struct HostAudio : TerminalModule { DISTRHO_SAFE_ASSERT_INT2_RETURN(k < blockFrames, k, blockFrames,); // from host into cardinal, shows as output plug - if (isBypassed()) + if (bypassed) { for (int i=0; i { +#ifndef HEADLESS // for stereo meter int internalDataFrame = 0; float internalDataBuffer[2][128]; volatile bool resetMeters = true; float gainMeterL = 0.0f; float gainMeterR = 0.0f; +#endif HostAudio2() : HostAudio<2>() { +#ifndef HEADLESS std::memset(internalDataBuffer, 0, sizeof(internalDataBuffer)); +#endif } +#ifndef HEADLESS void onReset() override { HostAudio<2>::onReset(); @@ -138,6 +149,7 @@ struct HostAudio2 : HostAudio<2> { HostAudio<2>::onSampleRateChange(e); resetMeters = true; } +#endif void processTerminalOutput(const ProcessArgs&) override { @@ -147,7 +159,7 @@ struct HostAudio2 : HostAudio<2> { const int k = dataFrame++; DISTRHO_SAFE_ASSERT_INT2_RETURN(k < blockFrames, k, blockFrames,); - if (isBypassed()) + if (bypassed) return; float** const dataOuts = pcontext->dataOuts; @@ -155,9 +167,6 @@ struct HostAudio2 : HostAudio<2> { // gain (stereo variant only) const float gain = std::pow(params[0].getValue(), 2.f); - // left/mono check - const bool in2connected = inputs[1].isConnected(); - // read stereo values float valueL = inputs[0].getVoltageSum() * 0.1f; float valueR = inputs[1].getVoltageSum() * 0.1f; @@ -189,6 +198,7 @@ struct HostAudio2 : HostAudio<2> { dataOuts[1][k] += valueL; } +#ifndef HEADLESS const int j = internalDataFrame++; internalDataBuffer[0][j] = valueL; internalDataBuffer[1][j] = valueR; @@ -209,6 +219,7 @@ struct HostAudio2 : HostAudio<2> { resetMeters = false; } +#endif } }; @@ -223,7 +234,7 @@ struct HostAudio8 : HostAudio<8> { const int k = dataFrame++; DISTRHO_SAFE_ASSERT_INT2_RETURN(k < blockFrames, k, blockFrames,); - if (isBypassed()) + if (bypassed) return; float** const dataOuts = pcontext->dataOuts; @@ -244,6 +255,7 @@ struct HostAudio8 : HostAudio<8> { }; +#ifndef HEADLESS // -------------------------------------------------------------------------------------------------------------------- template @@ -343,7 +355,30 @@ struct HostAudioWidget8 : HostAudioWidget<8> { } }; +#else +// -------------------------------------------------------------------------------------------------------------------- + +struct HostAudioWidget2 : ModuleWidget { + HostAudioWidget2(HostAudio2* const module) { + setModule(module); + for (uint i=0; i<2; ++i) { + addInput(createInput({}, module, i)); + addOutput(createOutput({}, module, i)); + } + } +}; +struct HostAudioWidget8 : ModuleWidget { + HostAudioWidget8(HostAudio8* const module) { + setModule(module); + for (uint i=0; i<8; ++i) { + addInput(createInput({}, module, i)); + addOutput(createOutput({}, module, i)); + } + } +}; + // -------------------------------------------------------------------------------------------------------------------- +#endif Model* modelHostAudio2 = createModel("HostAudio2"); Model* modelHostAudio8 = createModel("HostAudio8"); diff --git a/plugins/Cardinal/src/HostCV.cpp b/plugins/Cardinal/src/HostCV.cpp index e2e61ae..191495f 100644 --- a/plugins/Cardinal/src/HostCV.cpp +++ b/plugins/Cardinal/src/HostCV.cpp @@ -124,6 +124,7 @@ struct HostCV : TerminalModule { } }; +#ifndef HEADLESS struct HostCVWidget : ModuleWidgetWith8HP { HostCVWidget(HostCV* const module) { @@ -184,6 +185,17 @@ struct HostCVWidget : ModuleWidgetWith8HP { )); } }; +#else +struct HostCVWidget : ModuleWidget { + HostCVWidget(HostCV* const module) { + setModule(module); + for (uint i=0; i({}, module, i)); + for (uint i=0; i({}, module, i)); + } +}; +#endif // -------------------------------------------------------------------------------------------------------------------- diff --git a/plugins/Cardinal/src/HostMIDI.cpp b/plugins/Cardinal/src/HostMIDI.cpp index 0ab992a..ac58411 100644 --- a/plugins/Cardinal/src/HostMIDI.cpp +++ b/plugins/Cardinal/src/HostMIDI.cpp @@ -695,6 +695,7 @@ struct HostMIDI : TerminalModule { // -------------------------------------------------------------------------------------------------------------------- +#ifndef HEADLESS struct HostMIDIWidget : ModuleWidgetWith9HP { HostMIDI* const module; @@ -829,6 +830,17 @@ struct HostMIDIWidget : ModuleWidgetWith9HP { )); } }; +#else +struct HostMIDIWidget : ModuleWidget { + HostMIDIWidget(HostMIDI* const module) { + setModule(module); + for (uint i=0; i({}, module, i)); + for (uint i=0; i({}, module, i)); + } +}; +#endif // -------------------------------------------------------------------------------------------------------------------- diff --git a/plugins/Cardinal/src/HostParameters.cpp b/plugins/Cardinal/src/HostParameters.cpp index a46f659..0bea835 100644 --- a/plugins/Cardinal/src/HostParameters.cpp +++ b/plugins/Cardinal/src/HostParameters.cpp @@ -20,8 +20,6 @@ // ----------------------------------------------------------------------------------------------------------- -USE_NAMESPACE_DISTRHO; - struct HostParameters : TerminalModule { enum ParamIds { NUM_PARAMS @@ -91,6 +89,8 @@ struct HostParameters : TerminalModule { } }; +// -------------------------------------------------------------------------------------------------------------------- + #ifndef HEADLESS struct CardinalParameterPJ301MPort : PJ301MPort { void onDragStart(const DragStartEvent& e) override { @@ -159,11 +159,14 @@ struct HostParametersWidget : ModuleWidgetWith9HP { struct HostParametersWidget : ModuleWidget { HostParametersWidget(HostParameters* const module) { setModule(module); - - for (int i=0; i<24; ++i) + for (uint i=0; i({}, module, i)); } }; #endif +// -------------------------------------------------------------------------------------------------------------------- + Model* modelHostParameters = createModel("HostParameters"); + +// -------------------------------------------------------------------------------------------------------------------- diff --git a/plugins/Cardinal/src/HostTime.cpp b/plugins/Cardinal/src/HostTime.cpp index e49b855..4e41628 100644 --- a/plugins/Cardinal/src/HostTime.cpp +++ b/plugins/Cardinal/src/HostTime.cpp @@ -17,6 +17,8 @@ #include "plugincontext.hpp" +// -------------------------------------------------------------------------------------------------------------------- + struct HostTime : TerminalModule { enum ParamIds { NUM_PARAMS @@ -166,6 +168,9 @@ struct HostTime : TerminalModule { {} }; +// -------------------------------------------------------------------------------------------------------------------- + +#ifndef HEADLESS struct HostTimeWidget : ModuleWidget { static constexpr const float startX = 10.0f; static constexpr const float startY_top = 71.0f; @@ -285,5 +290,18 @@ struct HostTimeWidget : ModuleWidget { ModuleWidget::drawLayer(args, layer); } }; +#else +struct HostTimeWidget : ModuleWidget { + HostTimeWidget(HostTime* const module) { + setModule(module); + for (uint i=0; i({}, module, i)); + } +}; +#endif + +// -------------------------------------------------------------------------------------------------------------------- Model* modelHostTime = createModel("HostTime"); + +// -------------------------------------------------------------------------------------------------------------------- diff --git a/plugins/Cardinal/src/Widgets.hpp b/plugins/Cardinal/src/Widgets.hpp index a727e98..730262a 100644 --- a/plugins/Cardinal/src/Widgets.hpp +++ b/plugins/Cardinal/src/Widgets.hpp @@ -25,6 +25,7 @@ using namespace rack; +#ifndef HEADLESS struct CardinalLedDisplayChoice : LedDisplayChoice { bool alignTextCenter = true; @@ -403,3 +404,4 @@ struct OpenGlWidgetWithBrowserPreview : OpenGlWidget { virtual void drawFramebufferForBrowserPreview() = 0; }; +#endif