From 91dbc821012637df1b3a47ae9d37ac4a61a44db5 Mon Sep 17 00:00:00 2001 From: hemmer <915048+hemmer@users.noreply.github.com> Date: Fri, 15 Nov 2024 13:33:39 +0000 Subject: [PATCH] Clamp Bandit CVs Add soft clipping option to context menu --- .github/workflows/build-plugin.yml | 84 ------------------------------ src/Bandit.cpp | 36 +++++++++++-- 2 files changed, 32 insertions(+), 88 deletions(-) delete mode 100644 .github/workflows/build-plugin.yml diff --git a/.github/workflows/build-plugin.yml b/.github/workflows/build-plugin.yml deleted file mode 100644 index 961853e..0000000 --- a/.github/workflows/build-plugin.yml +++ /dev/null @@ -1,84 +0,0 @@ -name: Build VCV Rack Plugin -on: [push, pull_request] - -env: - rack-sdk-version: 2.5.1 - rack-plugin-toolchain-dir: /home/build/rack-plugin-toolchain - -defaults: - run: - shell: bash - -jobs: - build: - name: ${{ matrix.platform }} - runs-on: ubuntu-latest - container: - image: ghcr.io/qno/rack-plugin-toolchain-win-linux - options: --user root - strategy: - fail-fast: false - matrix: - platform: [win-x64, lin-x64] - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - name: Build plugin - run: | - export PLUGIN_DIR=$GITHUB_WORKSPACE - pushd ${{ env.rack-plugin-toolchain-dir }} - make plugin-build-${{ matrix.platform }} - - name: Upload artifact - uses: actions/upload-artifact@v3 - with: - path: ${{ env.rack-plugin-toolchain-dir }}/plugin-build - name: ${{ matrix.platform }} - - build-mac: - name: mac - runs-on: macos-12 - strategy: - fail-fast: false - matrix: - platform: [x64, arm64] - steps: - - uses: actions/checkout@v3 - with: - submodules: recursive - - name: Get Rack-SDK - run: | - pushd $HOME - curl -o Rack-SDK.zip https://vcvrack.com/downloads/Rack-SDK-${{ env.rack-sdk-version }}-mac-${{ matrix.platform }}.zip - unzip Rack-SDK.zip - - name: Build plugin - run: | - CROSS_COMPILE_TARGET_x64=x86_64-apple-darwin - CROSS_COMPILE_TARGET_arm64=arm64-apple-darwin - export RACK_DIR=$HOME/Rack-SDK - export CROSS_COMPILE=$CROSS_COMPILE_TARGET_${{ matrix.platform }} - make dep - make dist - echo "Plugin architecture '$(lipo -archs plugin.dylib)'" - - name: Upload artifact - uses: actions/upload-artifact@v3 - with: - path: dist/*.vcvplugin - name: mac-${{ matrix.platform }} - - publish: - name: Publish plugin - runs-on: ubuntu-latest - needs: [build, build-mac] - steps: - - uses: actions/download-artifact@v3 - with: - path: _artifacts - - uses: "marvinpinto/action-automatic-releases@latest" - with: - repo_token: "${{ secrets.GITHUB_TOKEN }}" - automatic_release_tag: "latest" - prerelease: true - title: "Development Build" - files: | - _artifacts/**/*.vcvplugin diff --git a/src/Bandit.cpp b/src/Bandit.cpp index 09ad573..501c633 100644 --- a/src/Bandit.cpp +++ b/src/Bandit.cpp @@ -47,6 +47,7 @@ struct Bandit : Module { const float clipTime = 0.25f; dsp::ClockDivider ledUpdateClock; const int ledUpdateRate = 64; + bool applySaturation = true; Bandit() { config(PARAMS_LEN, INPUTS_LEN, OUTPUTS_LEN, LIGHTS_LEN); @@ -156,19 +157,19 @@ struct Bandit : Module { const float_4 inHigh = inputs[HIGH_INPUT].getPolyVoltageSimd(c); const float_4 inAll = inputs[ALL_INPUT].getPolyVoltageSimd(c); - const float_4 lowGain = params[LOW_GAIN_PARAM].getValue() * inputs[LOW_CV_INPUT].getNormalPolyVoltageSimd(10.f, c) / 10.f; + const float_4 lowGain = params[LOW_GAIN_PARAM].getValue() * clamp(inputs[LOW_CV_INPUT].getNormalPolyVoltageSimd(10.f, c) / 10.f, 0.f, 1.f); const float_4 outLow = 0.7 * 2 * filterLow[c / 4][1].process(filterLow[c / 4][0].process((inLow + inAll) * lowGain)); outputs[LOW_OUTPUT].setVoltageSimd(outLow, c); - const float_4 lowMidGain = params[LOW_MID_GAIN_PARAM].getValue() * inputs[LOW_MID_CV_INPUT].getNormalPolyVoltageSimd(10.f, c) / 10.f; + const float_4 lowMidGain = params[LOW_MID_GAIN_PARAM].getValue() * clamp(inputs[LOW_MID_CV_INPUT].getNormalPolyVoltageSimd(10.f, c) / 10.f, 0.f, 1.f); const float_4 outLowMid = 2 * filterLowMid[c / 4][1].process(filterLowMid[c / 4][0].process((inLowMid + inAll) * lowMidGain)); outputs[LOW_MID_OUTPUT].setVoltageSimd(outLowMid, c); - const float_4 highMidGain = params[HIGH_MID_GAIN_PARAM].getValue() * inputs[HIGH_MID_CV_INPUT].getNormalPolyVoltageSimd(10.f, c) / 10.f; + const float_4 highMidGain = params[HIGH_MID_GAIN_PARAM].getValue() * clamp(inputs[HIGH_MID_CV_INPUT].getNormalPolyVoltageSimd(10.f, c) / 10.f, 0.f, 1.f); const float_4 outHighMid = 2 * filterHighMid[c / 4][1].process(filterHighMid[c / 4][0].process((inHighMid + inAll) * highMidGain)); outputs[HIGH_MID_OUTPUT].setVoltageSimd(outHighMid, c); - const float_4 highGain = params[HIGH_GAIN_PARAM].getValue() * inputs[HIGH_CV_INPUT].getNormalPolyVoltageSimd(10.f, c) / 10.f; + const float_4 highGain = params[HIGH_GAIN_PARAM].getValue() * clamp(inputs[HIGH_CV_INPUT].getNormalPolyVoltageSimd(10.f, c) / 10.f, 0.f, 1.f); const float_4 outHigh = 0.7 * 2 * filterHigh[c / 4][1].process(filterHigh[c / 4][0].process((inHigh + inAll) * highGain)); outputs[HIGH_OUTPUT].setVoltageSimd(outHigh, c); @@ -179,6 +180,10 @@ struct Bandit : Module { mixOutput[c / 4] += inputs[HIGH_RETURN_INPUT].getNormalPolyVoltageSimd(outHigh * !outputs[HIGH_OUTPUT].isConnected(), c); mixOutput[c / 4] = mixOutput[c / 4] * clamp(inputs[ALL_CV_INPUT].getNormalPolyVoltageSimd(10.f, c) / 10.f, 0.f, 1.f); + if (applySaturation) { + mixOutput[c / 4] = Saturator::process(mixOutput[c / 4] / 10.f) * 10.f; + } + outputs[MIX_OUTPUT].setVoltageSimd(mixOutput[c / 4], c); } @@ -249,6 +254,20 @@ struct Bandit : Module { lights[MIX_CLIP_LIGHT + 2].setBrightness(0.f); } } + + void dataFromJson(json_t* rootJ) override { + json_t* applySaturationJ = json_object_get(rootJ, "applySaturation"); + if (applySaturationJ) { + applySaturation = json_boolean_value(applySaturationJ); + } + } + + json_t* dataToJson() override { + json_t* rootJ = json_object(); + json_object_set_new(rootJ, "applySaturation", json_boolean(applySaturation)); + + return rootJ; + } }; @@ -289,6 +308,15 @@ struct BanditWidget : ModuleWidget { addChild(createLightCentered>(mm2px(Vec(37.781, 111.125)), module, Bandit::MIX_CLIP_LIGHT)); addChild(createLightCentered>(mm2px(Vec(37.781, 115.875)), module, Bandit::MIX_LIGHT)); } + + void appendContextMenu(Menu* menu) override { + Bandit* module = dynamic_cast(this->module); + assert(module); + + menu->addChild(new MenuSeparator()); + menu->addChild(createBoolPtrMenuItem("Soft clip at ±10V", "", &module->applySaturation)); + + } }; Model* modelBandit = createModel("Bandit"); \ No newline at end of file