Skip to content

Commit

Permalink
Add a PleaseQuit module (#106)
Browse files Browse the repository at this point in the history
* Add a PleaseQuit module

* update workflow
  • Loading branch information
baconpaul authored Jul 8, 2024
1 parent 3e29a3f commit 8c3d0e7
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 37 deletions.
57 changes: 21 additions & 36 deletions .github/workflows/build-plugin.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 }}
Expand All @@ -76,33 +69,32 @@ 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
key: ${{ github.sha }}-${{ github.run_id }}
- 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:
Expand All @@ -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: |
Expand All @@ -123,15 +115,15 @@ 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 }}
body: |
${{ 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
Expand All @@ -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
Expand All @@ -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 }}

6 changes: 6 additions & 0 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
]
}
1 change: 1 addition & 0 deletions src/BaconPlugs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
2 changes: 2 additions & 0 deletions src/BaconPlugs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ extern Model *modelPatchNameDisplay;

extern Model *modelBaconTest;

extern Model *modelPleaseQuit;

#endif
70 changes: 70 additions & 0 deletions src/PleaseQuit.cpp
Original file line number Diff line number Diff line change
@@ -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<bp::BaconModule> 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<PJ301MPort>::X), outy + 20);
bg->addPlugLabel(ppos, BaconBackground::SIG_IN, "bye!");
addInput(createInput<PJ301MPort>(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<PleaseQuitWidget::SD, PleaseQuitWidget>("PleaseQuit");
60 changes: 60 additions & 0 deletions src/PleaseQuit.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

#include <algorithm>
#include <vector>
#include "rack.hpp"

template <typename TBase> 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<float> 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();
}
}
}
};

0 comments on commit 8c3d0e7

Please sign in to comment.