From 8c3d0e78366cd8cf5e25c4f4d6b199da9f60109e Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 7 Jul 2024 21:02:42 -0400 Subject: [PATCH] Add a PleaseQuit module (#106) * Add a PleaseQuit module * update workflow --- .github/workflows/build-plugin.yml | 57 +++++++++--------------- libs/sst/sst-basic-blocks | 2 +- plugin.json | 6 +++ src/BaconPlugs.cpp | 1 + src/BaconPlugs.hpp | 2 + src/PleaseQuit.cpp | 70 ++++++++++++++++++++++++++++++ src/PleaseQuit.hpp | 60 +++++++++++++++++++++++++ 7 files changed, 161 insertions(+), 37 deletions(-) create mode 100644 src/PleaseQuit.cpp create mode 100644 src/PleaseQuit.hpp diff --git a/.github/workflows/build-plugin.yml b/.github/workflows/build-plugin.yml index e1e4749..f3ee2ff 100644 --- a/.github/workflows/build-plugin.yml +++ b/.github/workflows/build-plugin.yml @@ -1,15 +1,8 @@ name: Build VCV Rack Plugin -on: - push: - branches: - - main - - 'releases/**' - tags: - - 'v**' - pull_request: +on: [push, pull_request] env: - rack-sdk-version: 2.4.0 + rack-sdk-version: latest rack-plugin-toolchain-dir: /home/build/rack-plugin-toolchain defaults: @@ -22,8 +15,8 @@ jobs: name: Modify plugin version runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 + - uses: actions/checkout@v4 + - uses: actions/cache@v4 id: plugin-version-cache with: path: plugin.json @@ -46,12 +39,12 @@ jobs: strategy: fail-fast: false matrix: - platform: [win, lin] + platform: [win-x64, lin-x64] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive - - uses: actions/cache@v3 + - uses: actions/cache@v4 id: plugin-version-cache with: path: plugin.json @@ -60,9 +53,9 @@ jobs: run: | export PLUGIN_DIR=$GITHUB_WORKSPACE pushd ${{ env.rack-plugin-toolchain-dir }} - make plugin-build-${{ matrix.platform }}-x64 + make plugin-build-${{ matrix.platform }} - name: Upload artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: path: ${{ env.rack-plugin-toolchain-dir }}/plugin-build name: ${{ matrix.platform }} @@ -76,10 +69,10 @@ jobs: matrix: platform: [x64, arm64] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive - - uses: actions/cache@v3 + - uses: actions/cache@v4 id: plugin-version-cache with: path: plugin.json @@ -87,22 +80,21 @@ jobs: - 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 + wget -O Rack-SDK.zip https://vcvrack.com/downloads/Rack-SDK-${{ env.rack-sdk-version }}-mac-x64+arm64.zip unzip Rack-SDK.zip - name: Build plugin run: | - export RACK_DIR=$HOME/Rack-SDK 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 -j 4 dep - make -j 4 dist - echo "Plugin architecture '$(lipo -archs plugin.dylib)'" + make dep + make dist + echo "Plugin architecture '$(lipo -archs plugin*.dylib)'" - name: Upload artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - path: dist + path: dist/*.vcvplugin name: mac-${{ matrix.platform }} publish: @@ -113,7 +105,7 @@ jobs: runs-on: ubuntu-latest needs: [build, build-mac] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: FranzDiebold/github-env-vars-action@v2 - name: Check if plugin version matches tag run: | @@ -123,7 +115,7 @@ jobs: exit 1 fi - name: Create Release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 with: tag_name: ${{ github.ref }} name: Release ${{ env.CI_REF_NAME }} @@ -131,7 +123,7 @@ jobs: ${{ env.GITHUB_REPOSITORY_NAME }} VCV Rack Plugin ${{ env.CI_REF_NAME }} draft: false prerelease: false - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: path: _artifacts - name: Upload release assets @@ -150,7 +142,7 @@ jobs: runs-on: ubuntu-latest needs: [build, build-mac] steps: - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: path: _artifacts - name: Delete old release assets @@ -166,10 +158,3 @@ jobs: file: _artifacts/**/*.vcvplugin tag: Nightly file_glob: true - - name: Tag Repo - uses: richardsimko/update-tag@v1 - with: - tag_name: Nightly - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - diff --git a/libs/sst/sst-basic-blocks b/libs/sst/sst-basic-blocks index 0960274..144a13d 160000 --- a/libs/sst/sst-basic-blocks +++ b/libs/sst/sst-basic-blocks @@ -1 +1 @@ -Subproject commit 096027468b156618a511ce535abe7dd63ed1e4e3 +Subproject commit 144a13d743b1b600be2f6eeb06a65f6dad1ab868 diff --git a/plugin.json b/plugin.json index a4602db..825479d 100644 --- a/plugin.json +++ b/plugin.json @@ -126,6 +126,12 @@ "description": "BaconPaul's Test Widgets", "tags": [ ], "hidden": true + }, + { + "slug": "PleaseQuit", + "name": "PleaseQuit", + "description": "Send me a trigger to quit rack", + "tags": ["Utility"] } ] } diff --git a/src/BaconPlugs.cpp b/src/BaconPlugs.cpp index b180f75..a13ea44 100644 --- a/src/BaconPlugs.cpp +++ b/src/BaconPlugs.cpp @@ -33,6 +33,7 @@ __attribute__((__visibility__("default"))) void init(rack::Plugin *p) p->addModel(modelPatchNameDisplay); p->addModel(modelBaconTest); + p->addModel(modelPleaseQuit); baconpaul::rackplugs::BaconStyle::get(); } diff --git a/src/BaconPlugs.hpp b/src/BaconPlugs.hpp index 74559a5..5d04f4c 100644 --- a/src/BaconPlugs.hpp +++ b/src/BaconPlugs.hpp @@ -49,4 +49,6 @@ extern Model *modelPatchNameDisplay; extern Model *modelBaconTest; +extern Model *modelPleaseQuit; + #endif diff --git a/src/PleaseQuit.cpp b/src/PleaseQuit.cpp new file mode 100644 index 0000000..2ff7102 --- /dev/null +++ b/src/PleaseQuit.cpp @@ -0,0 +1,70 @@ + +#include "PleaseQuit.hpp" +#include "BaconPlugs.hpp" + +#include "BaconModule.hpp" +#include "BaconModuleWidget.h" + +namespace bp = baconpaul::rackplugs; + +struct PleaseQuitWidget : bp::BaconModuleWidget +{ + typedef PleaseQuit SD; + PleaseQuitWidget(SD *module); + + BufferedDrawFunctionWidget *bdw{nullptr}; + + void drawLabel(NVGcontext *vg) + { + nvgSave(vg); + nvgRotate(vg, M_PI_2); + + auto memFont = + InternalFontMgr::get(vg, baconpaul::rackplugs::BaconStyle::get()->fontName()); + auto labelColor = baconpaul::rackplugs::BaconStyle::get()->getColor( + baconpaul::rackplugs::BaconStyle::DEFAULT_MUTED_LABEL); + + nvgBeginPath(vg); + nvgFontFaceId(vg, memFont); + nvgFontSize(vg, 12); + nvgFillColor(vg, labelColor); + nvgTextAlign(vg, NVG_ALIGN_MIDDLE | NVG_ALIGN_LEFT); + + auto plabel = std::string("PleaseQuit is a utility module to shut down rack"); + nvgText(vg, 5, -box.size.x * 0.77, plabel.c_str(), nullptr); + + nvgBeginPath(vg); + nvgFontFaceId(vg, memFont); + nvgFontSize(vg, 24); + nvgFillColor(vg, labelColor); + nvgTextAlign(vg, NVG_ALIGN_MIDDLE | NVG_ALIGN_LEFT); + + auto flabel = std::string("Rack Quits on Trigger"); + nvgText(vg, 5, -box.size.x * 0.30, flabel.c_str(), nullptr); + nvgRestore(vg); + }; +}; + +PleaseQuitWidget::PleaseQuitWidget(SD *module) +{ + setModule(module); + box.size = Vec(SCREW_WIDTH * 3, RACK_HEIGHT); + + BaconBackground *bg = new BaconBackground(box.size, "Quit"); + addChild(bg->wrappedInFramebuffer()); + + int outy = 30; + //int gap = 10; + //int margin = 3; + + // plug label is 29 x 49 + Vec ppos = Vec(bg->cx(SizeTable::X), outy + 20); + bg->addPlugLabel(ppos, BaconBackground::SIG_IN, "bye!"); + addInput(createInput(ppos, module, SD::PLEASE_QUIT)); + + bdw = new BufferedDrawFunctionWidget(rack::Vec(0, outy + 70), rack::Vec(box.size.x, box.size.y - 70 - 25), + [this](auto *vg) { drawLabel(vg); }); + addChild(bdw); +} + +Model *modelPleaseQuit = createModel("PleaseQuit"); diff --git a/src/PleaseQuit.hpp b/src/PleaseQuit.hpp new file mode 100644 index 0000000..8693de6 --- /dev/null +++ b/src/PleaseQuit.hpp @@ -0,0 +1,60 @@ + +#include +#include +#include "rack.hpp" + +template struct PleaseQuit : virtual TBase +{ + enum ParamIds + { + NUM_PARAMS + }; + + enum InputIds + { + PLEASE_QUIT, + NUM_INPUTS + }; + + enum OutputIds + { + NUM_OUTPUTS + }; + + enum LightIds + { + NUM_LIGHTS + }; + + using TBase::inputs; + using TBase::lights; + using TBase::outputs; + using TBase::params; + + std::vector ring[16]; + size_t ringSize; + size_t pos[16]; + + PleaseQuit() : TBase() + { + TBase::config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); + TBase::configInput(PLEASE_QUIT, "Trigger Me to Quit"); + } + + rack::dsp::SchmittTrigger inTrig; + uint64_t samplesGoneBy{0}; + void process(const typename TBase::ProcessArgs &args) override + { + if (samplesGoneBy < 12000) + { + samplesGoneBy ++; + } + else + { + if (inTrig.process(inputs[PLEASE_QUIT].getVoltageSum())) + { + APP->window->close(); + } + } + } +};