Skip to content

Commit

Permalink
Add a PleaseQuit module
Browse files Browse the repository at this point in the history
  • Loading branch information
baconpaul committed Jul 8, 2024
1 parent 3e29a3f commit 0251585
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 1 deletion.
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 0251585

Please sign in to comment.