From 7d802e6e8779b8a6f8a0b50760dc971c30abd539 Mon Sep 17 00:00:00 2001 From: Christoph Scholtes Date: Mon, 19 Feb 2018 20:38:03 -0700 Subject: [PATCH] Update to Rack API v0.6. --- Makefile | 29 +++------------ src/ASR.cpp | 39 ++++++++++---------- src/AToD.cpp | 83 +++++++++++++++++++++--------------------- src/Bitshift.cpp | 45 ++++++++++++----------- src/BlankPanel.cpp | 65 +++++++++++++++++++-------------- src/Boolean3.cpp | 51 +++++++++++++------------- src/Comparator.cpp | 60 ++++++++++++++++--------------- src/Contrast.cpp | 45 ++++++++++++----------- src/Crackle.cpp | 44 ++++++++++++----------- src/DToA.cpp | 85 +++++++++++++++++++++++--------------------- src/Delta.cpp | 60 ++++++++++++++++--------------- src/Dust.cpp | 39 ++++++++++---------- src/Exponent.cpp | 45 ++++++++++++----------- src/FlipFlop.cpp | 43 +++++++++++----------- src/FlipPan.cpp | 49 +++++++++++++------------ src/GateJunction.cpp | 76 ++++++++++++++++++++------------------- src/HetrickCV.cpp | 46 ++++++++++++------------ src/HetrickCV.hpp | 65 +++++++++++---------------------- src/LogicCombine.cpp | 49 ++++++++++++------------- src/RandomGates.cpp | 74 +++++++++++++++++++------------------- src/Rotator.cpp | 54 ++++++++++++++-------------- src/Scanner.cpp | 68 ++++++++++++++++++----------------- src/TwoToFour.cpp | 42 +++++++++++----------- src/Waveshape.cpp | 45 ++++++++++++----------- 24 files changed, 656 insertions(+), 645 deletions(-) diff --git a/Makefile b/Makefile index 7401984..8400397 100755 --- a/Makefile +++ b/Makefile @@ -1,28 +1,9 @@ SLUG = HetrickCV -VERSION = 0.5.4 +VERSION = 0.6.0dev -# FLAGS will be passed to both C and C++ compiler -FLAGS += -CFLAGS += -CXXFLAGS += +SOURCES += $(wildcard src/*.cpp) -# Careful about linking to libraries, since you can't assume much about the user's environment and library search path. -# Static libraries are fine. -LDFLAGS += +DISTRIBUTABLES += $(wildcard LICENSE*) res -# Add .cpp and .c files to the build -SOURCES = $(wildcard src/*.cpp) - - -# Must include the VCV plugin Makefile framework -include ../../plugin.mk - - -# Convenience target for including files in the distributable release -.PHONY: dist -dist: all - mkdir -p dist/$(SLUG) - cp LICENSE* dist/$(SLUG)/ - cp plugin.* dist/$(SLUG)/ - cp -R res dist/$(SLUG)/ - cd dist && zip -5 -r $(SLUG)-$(VERSION)-$(ARCH).zip $(SLUG) +RACK_DIR ?= ../.. +include $(RACK_DIR)/plugin.mk diff --git a/src/ASR.cpp b/src/ASR.cpp index 4c785fc..d2af997 100644 --- a/src/ASR.cpp +++ b/src/ASR.cpp @@ -1,18 +1,18 @@ #include "HetrickCV.hpp" -struct ASR : Module +struct ASR : Module { - enum ParamIds + enum ParamIds { NUM_PARAMS }; - enum InputIds + enum InputIds { MAIN_INPUT, CLK_INPUT, NUM_INPUTS }; - enum OutputIds + enum OutputIds { STAGE1_OUTPUT, STAGE2_OUTPUT, @@ -20,7 +20,7 @@ struct ASR : Module STAGE4_OUTPUT, NUM_OUTPUTS }; - enum LightIds + enum LightIds { OUT1_POS_LIGHT, OUT1_NEG_LIGHT, OUT2_POS_LIGHT, OUT2_NEG_LIGHT, @@ -32,9 +32,9 @@ struct ASR : Module SchmittTrigger clockTrigger; float stages[4] = {}; - ASR() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) + ASR() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { - + } void step() override; @@ -46,7 +46,7 @@ struct ASR : Module }; -void ASR::step() +void ASR::step() { if (clockTrigger.process(inputs[CLK_INPUT].value)) { @@ -74,11 +74,10 @@ void ASR::step() lights[OUT4_NEG_LIGHT].setBrightnessSmooth(fmaxf(0.0, -stages[3] / 5.0)); } +struct ASRWidget : ModuleWidget { ASRWidget(ASR *module); }; -ASRWidget::ASRWidget() +ASRWidget::ASRWidget(ASR *module) : ModuleWidget(module) { - auto *module = new ASR(); - setModule(module); box.size = Vec(6 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -88,21 +87,23 @@ ASRWidget::ASRWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //////PARAMS////// //////INPUTS////// - addInput(createInput(Vec(10, 100), module, ASR::MAIN_INPUT)); - addInput(createInput(Vec(55, 100), module, ASR::CLK_INPUT)); + addInput(Port::create(Vec(10, 100), Port::INPUT, module, ASR::MAIN_INPUT)); + addInput(Port::create(Vec(55, 100), Port::INPUT, module, ASR::CLK_INPUT)); for(int i = 0; i < 4; i++) { const int yPos = i*45; - addOutput(createOutput(Vec(33, 150 + yPos), module, ASR::STAGE1_OUTPUT + i)); - addChild(createLight>(Vec(70, 158 + yPos), module, ASR::OUT1_POS_LIGHT + i*2)); + addOutput(Port::create(Vec(33, 150 + yPos), Port::OUTPUT, module, ASR::STAGE1_OUTPUT + i)); + addChild(ModuleLightWidget::create>(Vec(70, 158 + yPos), module, ASR::OUT1_POS_LIGHT + i*2)); } } + +Model *modelASR = Model::create("HetrickCV", "ASR", "ASR", SEQUENCER_TAG); diff --git a/src/AToD.cpp b/src/AToD.cpp index 9dd8e31..3d8ad9f 100644 --- a/src/AToD.cpp +++ b/src/AToD.cpp @@ -1,8 +1,8 @@ #include "HetrickCV.hpp" -struct AnalogToDigital : Module +struct AnalogToDigital : Module { - enum ParamIds + enum ParamIds { SCALE_PARAM, OFFSET_PARAM, @@ -11,14 +11,14 @@ struct AnalogToDigital : Module NUM_PARAMS }; - enum InputIds + enum InputIds { MAIN_INPUT, SYNC_INPUT, NUM_INPUTS }; - enum OutputIds + enum OutputIds { OUT1_OUTPUT, OUT2_OUTPUT, @@ -30,7 +30,7 @@ struct AnalogToDigital : Module OUT8_OUTPUT, NUM_OUTPUTS }; - enum LightIds + enum LightIds { OUT1_LIGHT, OUT2_LIGHT, @@ -51,19 +51,19 @@ struct AnalogToDigital : Module NUM_LIGHTS }; - + SchmittTrigger clockTrigger; SchmittTrigger modeTrigger; SchmittTrigger rectTrigger; - + int mode = 0; int rectMode = 0; float outs[8] = {}; - AnalogToDigital() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) + AnalogToDigital() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { - + } void step() override; @@ -72,30 +72,30 @@ struct AnalogToDigital : Module void processBiOff(float _input); void processBiSig(float _input); - void reset() override + void reset() override { mode = 0; rectMode = 0; } - void randomize() override + void randomize() override { mode = round(randomf() * 2.0f); rectMode = round(randomf() * 2.0f); } - - json_t *toJson() override + + json_t *toJson() override { json_t *rootJ = json_object(); json_object_set_new(rootJ, "mode", json_integer(mode)); json_object_set_new(rootJ, "rectMode", json_integer(rectMode)); return rootJ; } - void fromJson(json_t *rootJ) override + void fromJson(json_t *rootJ) override { json_t *modeJ = json_object_get(rootJ, "mode"); if (modeJ) mode = json_integer_value(modeJ); - + json_t *rectModeJ = json_object_get(rootJ, "rectMode"); if (rectModeJ) rectMode = json_integer_value(rectModeJ); @@ -108,7 +108,7 @@ struct AnalogToDigital : Module }; -void AnalogToDigital::step() +void AnalogToDigital::step() { if (modeTrigger.process(params[MODE_PARAM].value)) mode = (mode + 1) % 3; if (rectTrigger.process(params[RECTIFY_PARAM].value)) rectMode = (rectMode + 1) % 3; @@ -131,14 +131,14 @@ void AnalogToDigital::step() input += params[OFFSET_PARAM].value; if (rectMode == 1) input = input > 0.0f? input : 0.0f; else if (rectMode == 2) input = std::abs(input); - + if(mode == 0) processUni8(input); else if (mode == 1) processBiOff(input); else if (mode == 2) processBiSig(input); } for(int i = 0; i < 8; i++) - { + { outputs[OUT1_OUTPUT + i].value = outs[i]; lights[OUT1_LIGHT + i].value = outs[i]; } @@ -192,10 +192,11 @@ void AnalogToDigital::processBiSig(float _input) outs[6] = (bits & 0b01000000) > 0.0f ? 5.0f : 0.0f; } -AnalogToDigitalWidget::AnalogToDigitalWidget() + +struct AnalogToDigitalWidget : ModuleWidget { AnalogToDigitalWidget(AnalogToDigital *module); }; + +AnalogToDigitalWidget::AnalogToDigitalWidget(AnalogToDigital *module) : ModuleWidget(module) { - auto *module = new AnalogToDigital(); - setModule(module); box.size = Vec(12 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -205,32 +206,32 @@ AnalogToDigitalWidget::AnalogToDigitalWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //////PARAMS////// - addParam(createParam(Vec(16, 270), module, AnalogToDigital::MODE_PARAM, 0.0, 1.0, 0.0)); - addParam(createParam(Vec(65, 270), module, AnalogToDigital::RECTIFY_PARAM, 0.0, 1.0, 0.0)); - + addParam(ParamWidget::create(Vec(16, 270), module, AnalogToDigital::MODE_PARAM, 0.0, 1.0, 0.0)); + addParam(ParamWidget::create(Vec(65, 270), module, AnalogToDigital::RECTIFY_PARAM, 0.0, 1.0, 0.0)); + //////BLINKENLIGHTS////// int modeLightX = 12; - addChild(createLight>(Vec(modeLightX, 306), module, AnalogToDigital::MODE_UNI8_LIGHT)); - addChild(createLight>(Vec(modeLightX, 319), module, AnalogToDigital::MODE_BOFF_LIGHT)); - addChild(createLight>(Vec(modeLightX, 332), module, AnalogToDigital::MODE_BSIG_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(modeLightX, 306), module, AnalogToDigital::MODE_UNI8_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(modeLightX, 319), module, AnalogToDigital::MODE_BOFF_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(modeLightX, 332), module, AnalogToDigital::MODE_BSIG_LIGHT)); int rectLightX = 64; - addChild(createLight>(Vec(rectLightX, 306), module, AnalogToDigital::RECT_NONE_LIGHT)); - addChild(createLight>(Vec(rectLightX, 319), module, AnalogToDigital::RECT_HALF_LIGHT)); - addChild(createLight>(Vec(rectLightX, 332), module, AnalogToDigital::RECT_FULL_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(rectLightX, 306), module, AnalogToDigital::RECT_NONE_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(rectLightX, 319), module, AnalogToDigital::RECT_HALF_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(rectLightX, 332), module, AnalogToDigital::RECT_FULL_LIGHT)); //////INPUTS////// - addInput(createInput(Vec(7, 70), module, AnalogToDigital::MAIN_INPUT)); - addInput(createInput(Vec(42, 152), module, AnalogToDigital::SYNC_INPUT)); + addInput(Port::create(Vec(7, 70), Port::INPUT, module, AnalogToDigital::MAIN_INPUT)); + addInput(Port::create(Vec(42, 152), Port::INPUT, module, AnalogToDigital::SYNC_INPUT)); - addParam(createParam(Vec(44, 73), module, AnalogToDigital::SCALE_PARAM, -1.0, 1.0, 0.2)); - addParam(createParam(Vec(80, 73), module, AnalogToDigital::OFFSET_PARAM, -5.0, 5.0, 0.0)); + addParam(ParamWidget::create(Vec(44, 73), module, AnalogToDigital::SCALE_PARAM, -1.0, 1.0, 0.2)); + addParam(ParamWidget::create(Vec(80, 73), module, AnalogToDigital::OFFSET_PARAM, -5.0, 5.0, 0.0)); const int outXPos = 145; const int outLightX = 120; @@ -240,9 +241,11 @@ AnalogToDigitalWidget::AnalogToDigitalWidget() const int lightY = 59 + (40 * i); //////OUTPUTS////// - addOutput(createOutput(Vec(outXPos, yPos), module, AnalogToDigital::OUT1_OUTPUT + i)); + addOutput(Port::create(Vec(outXPos, yPos), Port::OUTPUT, module, AnalogToDigital::OUT1_OUTPUT + i)); //////BLINKENLIGHTS////// - addChild(createLight>(Vec(outLightX, lightY), module, AnalogToDigital::OUT1_LIGHT + i)); + addChild(ModuleLightWidget::create>(Vec(outLightX, lightY), module, AnalogToDigital::OUT1_LIGHT + i)); } } + +Model *modelAnalogToDigital = Model::create("HetrickCV", "AnalogToDigital", "Analog to Digital", LOGIC_TAG); diff --git a/src/Bitshift.cpp b/src/Bitshift.cpp index 27eb41d..da99bd6 100644 --- a/src/Bitshift.cpp +++ b/src/Bitshift.cpp @@ -1,29 +1,29 @@ #include "HetrickCV.hpp" -struct Bitshift : Module +struct Bitshift : Module { - enum ParamIds + enum ParamIds { AMOUNT_PARAM, SCALE_PARAM, RANGE_PARAM, NUM_PARAMS }; - enum InputIds + enum InputIds { MAIN_INPUT, AMOUNT_INPUT, NUM_INPUTS }; - enum OutputIds + enum OutputIds { MAIN_OUTPUT, NUM_OUTPUTS }; - Bitshift() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) + Bitshift() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) { - + } void step() override; @@ -35,7 +35,7 @@ struct Bitshift : Module }; -void Bitshift::step() +void Bitshift::step() { float input = inputs[MAIN_INPUT].value; @@ -63,7 +63,7 @@ void Bitshift::step() if(mode5V) output *= 5.0f; else output *= 10.0f; - + outputs[MAIN_OUTPUT].value = output; } @@ -76,10 +76,11 @@ struct CKSSRot : SVGSwitch, ToggleSwitch { } }; -BitshiftWidget::BitshiftWidget() + +struct BitshiftWidget : ModuleWidget { BitshiftWidget(Bitshift *module); }; + +BitshiftWidget::BitshiftWidget(Bitshift *module) : ModuleWidget(module) { - auto *module = new Bitshift(); - setModule(module); box.size = Vec(6 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -89,20 +90,22 @@ BitshiftWidget::BitshiftWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //////PARAMS////// - addParam(createParam(Vec(27, 62), module, Bitshift::AMOUNT_PARAM, -5.0, 5.0, 0.0)); - addParam(createParam(Vec(36, 112), module, Bitshift::SCALE_PARAM, -1.0, 1.0, 1.0)); - addParam(createParam(Vec(35, 200), module, Bitshift::RANGE_PARAM, 0.0, 1.0, 0.0)); + addParam(ParamWidget::create(Vec(27, 62), module, Bitshift::AMOUNT_PARAM, -5.0, 5.0, 0.0)); + addParam(ParamWidget::create(Vec(36, 112), module, Bitshift::SCALE_PARAM, -1.0, 1.0, 1.0)); + addParam(ParamWidget::create(Vec(35, 200), module, Bitshift::RANGE_PARAM, 0.0, 1.0, 0.0)); //////INPUTS////// - addInput(createInput(Vec(33, 235), module, Bitshift::MAIN_INPUT)); - addInput(createInput(Vec(33, 145), module, Bitshift::AMOUNT_INPUT)); + addInput(Port::create(Vec(33, 235), Port::INPUT, module, Bitshift::MAIN_INPUT)); + addInput(Port::create(Vec(33, 145), Port::INPUT, module, Bitshift::AMOUNT_INPUT)); //////OUTPUTS////// - addOutput(createOutput(Vec(33, 285), module, Bitshift::MAIN_OUTPUT)); + addOutput(Port::create(Vec(33, 285), Port::OUTPUT, module, Bitshift::MAIN_OUTPUT)); } + +Model *modelBitshift = Model::create("HetrickCV", "Bitshift", "Bitshift", DISTORTION_TAG, EFFECT_TAG); diff --git a/src/BlankPanel.cpp b/src/BlankPanel.cpp index d5d46b6..0a1cc6e 100644 --- a/src/BlankPanel.cpp +++ b/src/BlankPanel.cpp @@ -2,22 +2,22 @@ #define NUM_PANELS 5 -struct BlankPanel : Module +struct BlankPanel : Module { - enum ParamIds + enum ParamIds { NUM_PARAMS }; - enum InputIds + enum InputIds { NUM_INPUTS }; - enum OutputIds + enum OutputIds { NUM_OUTPUTS }; - - enum LightIds + + enum LightIds { NUM_LIGHTS }; @@ -28,22 +28,22 @@ struct BlankPanel : Module void step() override {} - void reset() override + void reset() override { panel = 0; } - void randomize() override + void randomize() override { panel = round(randomf() * (NUM_PANELS - 1.0f)); } - - json_t *toJson() override + + json_t *toJson() override { json_t *rootJ = json_object(); json_object_set_new(rootJ, "panel", json_integer(panel)); return rootJ; } - void fromJson(json_t *rootJ) override + void fromJson(json_t *rootJ) override { json_t *panelJ = json_object_get(rootJ, "panel"); if (panelJ) @@ -51,10 +51,21 @@ struct BlankPanel : Module } }; -BlankPanelWidget::BlankPanelWidget() + +struct BlankPanelWidget : ModuleWidget +{ + SVGPanel *panel1; + SVGPanel *panel2; + SVGPanel *panel3; + SVGPanel *panel4; + SVGPanel *panel5; + BlankPanelWidget(BlankPanel *module); + void step() override; + Menu *createContextMenu() override; +}; + +BlankPanelWidget::BlankPanelWidget(BlankPanel *module) : ModuleWidget(module) { - auto *module = new BlankPanel(); - setModule(module); box.size = Vec(6 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); panel1 = new SVGPanel(); @@ -82,13 +93,13 @@ BlankPanelWidget::BlankPanelWidget() panel5->setBackground(SVG::load(assetPlugin(plugin, "res/Blanks/BlankPanel1.svg"))); addChild(panel5); - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); } -void BlankPanelWidget::step() +void BlankPanelWidget::step() { BlankPanel *blank = dynamic_cast(module); assert(blank); @@ -102,7 +113,7 @@ void BlankPanelWidget::step() ModuleWidget::step(); } -struct Panel1Item : MenuItem +struct Panel1Item : MenuItem { BlankPanel *blank; void onAction(EventAction &e) override { blank->panel = 0; } @@ -112,7 +123,7 @@ struct Panel1Item : MenuItem } }; -struct Panel2Item : MenuItem +struct Panel2Item : MenuItem { BlankPanel *blank; void onAction(EventAction &e) override { blank->panel = 1; } @@ -122,7 +133,7 @@ struct Panel2Item : MenuItem } }; -struct Panel3Item : MenuItem +struct Panel3Item : MenuItem { BlankPanel *blank; void onAction(EventAction &e) override { blank->panel = 2; } @@ -132,7 +143,7 @@ struct Panel3Item : MenuItem } }; -struct Panel4Item : MenuItem +struct Panel4Item : MenuItem { BlankPanel *blank; void onAction(EventAction &e) override { blank->panel = 3; } @@ -142,7 +153,7 @@ struct Panel4Item : MenuItem } }; -struct Panel5Item : MenuItem +struct Panel5Item : MenuItem { BlankPanel *blank; void onAction(EventAction &e) override { blank->panel = 4; } @@ -152,7 +163,7 @@ struct Panel5Item : MenuItem } }; -Menu *BlankPanelWidget::createContextMenu() +Menu *BlankPanelWidget::createContextMenu() { Menu *menu = ModuleWidget::createContextMenu(); @@ -168,4 +179,6 @@ Menu *BlankPanelWidget::createContextMenu() menu->addChild(construct(&MenuEntry::text, "Plain Jane", &Panel5Item::blank, blank)); return menu; -} \ No newline at end of file +} + +Model *modelBlankPanel = Model::create("HetrickCV", "BlankPanel", "Blank Panel"); diff --git a/src/Boolean3.cpp b/src/Boolean3.cpp index d104f42..35da514 100644 --- a/src/Boolean3.cpp +++ b/src/Boolean3.cpp @@ -1,19 +1,19 @@ #include "HetrickCV.hpp" -struct Boolean3 : Module +struct Boolean3 : Module { - enum ParamIds + enum ParamIds { NUM_PARAMS }; - enum InputIds + enum InputIds { INA_INPUT, INB_INPUT, INC_INPUT, NUM_INPUTS }; - enum OutputIds + enum OutputIds { OR_OUTPUT, AND_OUTPUT, @@ -23,8 +23,8 @@ struct Boolean3 : Module XNOR_OUTPUT, NUM_OUTPUTS }; - - enum LightIds + + enum LightIds { OR_LIGHT, AND_LIGHT, @@ -44,9 +44,9 @@ struct Boolean3 : Module bool inC = false; float outs[6] = {}; - Boolean3() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) + Boolean3() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { - + } void step() override; @@ -58,7 +58,7 @@ struct Boolean3 : Module }; -void Boolean3::step() +void Boolean3::step() { inA = ins[0].process(inputs[INA_INPUT].value); inB = ins[1].process(inputs[INB_INPUT].value); @@ -86,7 +86,7 @@ void Boolean3::step() outs[4] = 5.0f - outs[1]; outs[5] = 5.0f - outs[2]; } - + outputs[OR_OUTPUT].value = outs[0]; outputs[AND_OUTPUT].value = outs[1]; @@ -103,11 +103,10 @@ void Boolean3::step() lights[XNOR_LIGHT].value = outs[5]; } +struct Boolean3Widget : ModuleWidget { Boolean3Widget(Boolean3 *module); }; -Boolean3Widget::Boolean3Widget() +Boolean3Widget::Boolean3Widget(Boolean3 *module) : ModuleWidget(module) { - auto *module = new Boolean3(); - setModule(module); box.size = Vec(6 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -117,25 +116,27 @@ Boolean3Widget::Boolean3Widget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //////INPUTS////// - addInput(createInput(Vec(10, 105), module, Boolean3::INA_INPUT)); - addInput(createInput(Vec(10, 195), module, Boolean3::INB_INPUT)); - addInput(createInput(Vec(10, 285), module, Boolean3::INC_INPUT)); - addChild(createLight>(Vec(18, 92), module, Boolean3::INA_LIGHT)); - addChild(createLight>(Vec(18, 182), module, Boolean3::INB_LIGHT)); - addChild(createLight>(Vec(18, 272), module, Boolean3::INC_LIGHT)); + addInput(Port::create(Vec(10, 105), Port::INPUT, module, Boolean3::INA_INPUT)); + addInput(Port::create(Vec(10, 195), Port::INPUT, module, Boolean3::INB_INPUT)); + addInput(Port::create(Vec(10, 285), Port::INPUT, module, Boolean3::INC_INPUT)); + addChild(ModuleLightWidget::create>(Vec(18, 92), module, Boolean3::INA_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(18, 182), module, Boolean3::INB_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(18, 272), module, Boolean3::INC_LIGHT)); //////OUTPUTS////// for(int i = 0; i < 6; i++) { const int yPos = i*45; - addOutput(createOutput(Vec(45, 60 + yPos), module, Boolean3::OR_OUTPUT + i)); - addChild(createLight>(Vec(74, 68 + yPos), module, Boolean3::OR_LIGHT + i)); + addOutput(Port::create(Vec(45, 60 + yPos), Port::OUTPUT, module, Boolean3::OR_OUTPUT + i)); + addChild(ModuleLightWidget::create>(Vec(74, 68 + yPos), module, Boolean3::OR_LIGHT + i)); } } + +Model *modelBoolean3 = Model::create("HetrickCV", "Boolean3", "Boolean Logic", LOGIC_TAG); diff --git a/src/Comparator.cpp b/src/Comparator.cpp index 1dea408..4993520 100644 --- a/src/Comparator.cpp +++ b/src/Comparator.cpp @@ -1,20 +1,20 @@ #include "HetrickCV.hpp" -struct Comparator : Module +struct Comparator : Module { - enum ParamIds + enum ParamIds { AMOUNT_PARAM, SCALE_PARAM, NUM_PARAMS }; - enum InputIds + enum InputIds { MAIN_INPUT, AMOUNT_INPUT, NUM_INPUTS }; - enum OutputIds + enum OutputIds { GT_GATE_OUTPUT, GT_TRIG_OUTPUT, @@ -24,7 +24,7 @@ struct Comparator : Module NUM_OUTPUTS }; - enum LightIds + enum LightIds { GT_LIGHT, LT_LIGHT, @@ -32,9 +32,9 @@ struct Comparator : Module NUM_LIGHTS }; - Comparator() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) + Comparator() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { - + } TriggerGenWithSchmitt ltTrig, gtTrig; @@ -48,7 +48,7 @@ struct Comparator : Module }; -void Comparator::step() +void Comparator::step() { float input = inputs[MAIN_INPUT].value; @@ -57,7 +57,7 @@ void Comparator::step() const bool greaterThan = (input > compare); const bool lessThan = (input < compare); - + outputs[GT_TRIG_OUTPUT].value = gtTrig.process(greaterThan) ? 5.0f : 0.0f; outputs[LT_TRIG_OUTPUT].value = ltTrig.process(lessThan) ? 5.0f : 0.0f; outputs[GT_GATE_OUTPUT].value = greaterThan ? 5.0f : 0.0f; @@ -67,17 +67,17 @@ void Comparator::step() allTrigs = clampf(allTrigs, 0.0f, 5.0f); outputs[ZEROX_OUTPUT].value = allTrigs; - + lights[GT_LIGHT].setBrightnessSmooth(outputs[GT_GATE_OUTPUT].value); lights[LT_LIGHT].setBrightnessSmooth(outputs[LT_GATE_OUTPUT].value); lights[ZEROX_LIGHT].setBrightnessSmooth(allTrigs); } -ComparatorWidget::ComparatorWidget() +struct ComparatorWidget : ModuleWidget { ComparatorWidget(Comparator *module); }; + +ComparatorWidget::ComparatorWidget(Comparator* module) : ModuleWidget(module) { - auto *module = new Comparator(); - setModule(module); box.size = Vec(6 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -87,28 +87,30 @@ ComparatorWidget::ComparatorWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //////PARAMS////// - addParam(createParam(Vec(27, 62), module, Comparator::AMOUNT_PARAM, -5.0, 5.0, 0.0)); - addParam(createParam(Vec(36, 112), module, Comparator::SCALE_PARAM, -1.0, 1.0, 1.0)); + addParam(ParamWidget::create(Vec(27, 62), module, Comparator::AMOUNT_PARAM, -5.0, 5.0, 0.0)); + addParam(ParamWidget::create(Vec(36, 112), module, Comparator::SCALE_PARAM, -1.0, 1.0, 1.0)); //////INPUTS////// - addInput(createInput(Vec(33, 195), module, Comparator::MAIN_INPUT)); - addInput(createInput(Vec(33, 145), module, Comparator::AMOUNT_INPUT)); + addInput(Port::create(Vec(33, 195), Port::INPUT, module, Comparator::MAIN_INPUT)); + addInput(Port::create(Vec(33, 145), Port::INPUT, module, Comparator::AMOUNT_INPUT)); //////OUTPUTS////// - addOutput(createOutput(Vec(12, 285), module, Comparator::LT_GATE_OUTPUT)); - addOutput(createOutput(Vec(53, 285), module, Comparator::GT_GATE_OUTPUT)); - addOutput(createOutput(Vec(12, 315), module, Comparator::LT_TRIG_OUTPUT)); - addOutput(createOutput(Vec(53, 315), module, Comparator::GT_TRIG_OUTPUT)); - addOutput(createOutput(Vec(32.5, 245), module, Comparator::ZEROX_OUTPUT)); + addOutput(Port::create(Vec(12, 285), Port::OUTPUT, module, Comparator::LT_GATE_OUTPUT)); + addOutput(Port::create(Vec(53, 285), Port::OUTPUT, module, Comparator::GT_GATE_OUTPUT)); + addOutput(Port::create(Vec(12, 315), Port::OUTPUT, module, Comparator::LT_TRIG_OUTPUT)); + addOutput(Port::create(Vec(53, 315), Port::OUTPUT, module, Comparator::GT_TRIG_OUTPUT)); + addOutput(Port::create(Vec(32.5, 245), Port::OUTPUT, module, Comparator::ZEROX_OUTPUT)); //////BLINKENLIGHTS////// - addChild(createLight>(Vec(22, 275), module, Comparator::LT_LIGHT)); - addChild(createLight>(Vec(62, 275), module, Comparator::GT_LIGHT)); - addChild(createLight>(Vec(42, 275), module, Comparator::ZEROX_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(22, 275), module, Comparator::LT_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(62, 275), module, Comparator::GT_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(42, 275), module, Comparator::ZEROX_LIGHT)); } + +Model *modelComparator = Model::create("HetrickCV", "Comparator", "Comparator", LOGIC_TAG); diff --git a/src/Contrast.cpp b/src/Contrast.cpp index 38b7608..21ada38 100644 --- a/src/Contrast.cpp +++ b/src/Contrast.cpp @@ -1,29 +1,29 @@ #include "HetrickCV.hpp" -struct Contrast : Module +struct Contrast : Module { - enum ParamIds + enum ParamIds { AMOUNT_PARAM, SCALE_PARAM, RANGE_PARAM, NUM_PARAMS }; - enum InputIds + enum InputIds { MAIN_INPUT, AMOUNT_INPUT, NUM_INPUTS }; - enum OutputIds + enum OutputIds { MAIN_OUTPUT, NUM_OUTPUTS }; - Contrast() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) + Contrast() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) { - + } void step() override; @@ -35,7 +35,7 @@ struct Contrast : Module }; -void Contrast::step() +void Contrast::step() { float input = inputs[MAIN_INPUT].value; @@ -53,7 +53,7 @@ void Contrast::step() if(mode5V) output *= 5.0f; else output *= 10.0f; - + outputs[MAIN_OUTPUT].value = output; } @@ -66,10 +66,11 @@ struct CKSSRot : SVGSwitch, ToggleSwitch { } }; -ContrastWidget::ContrastWidget() + +struct ContrastWidget : ModuleWidget { ContrastWidget(Contrast *module); }; + +ContrastWidget::ContrastWidget(Contrast *module) : ModuleWidget(module) { - auto *module = new Contrast(); - setModule(module); box.size = Vec(6 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -79,20 +80,22 @@ ContrastWidget::ContrastWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //////PARAMS////// - addParam(createParam(Vec(27, 62), module, Contrast::AMOUNT_PARAM, 0, 5.0, 0.0)); - addParam(createParam(Vec(36, 112), module, Contrast::SCALE_PARAM, -1.0, 1.0, 1.0)); - addParam(createParam(Vec(35, 200), module, Contrast::RANGE_PARAM, 0.0, 1.0, 0.0)); + addParam(ParamWidget::create(Vec(27, 62), module, Contrast::AMOUNT_PARAM, 0, 5.0, 0.0)); + addParam(ParamWidget::create(Vec(36, 112), module, Contrast::SCALE_PARAM, -1.0, 1.0, 1.0)); + addParam(ParamWidget::create(Vec(35, 200), module, Contrast::RANGE_PARAM, 0.0, 1.0, 0.0)); //////INPUTS////// - addInput(createInput(Vec(33, 235), module, Contrast::MAIN_INPUT)); - addInput(createInput(Vec(33, 145), module, Contrast::AMOUNT_INPUT)); + addInput(Port::create(Vec(33, 235), Port::INPUT, module, Contrast::MAIN_INPUT)); + addInput(Port::create(Vec(33, 145), Port::INPUT, module, Contrast::AMOUNT_INPUT)); //////OUTPUTS////// - addOutput(createOutput(Vec(33, 285), module, Contrast::MAIN_OUTPUT)); + addOutput(Port::create(Vec(33, 285), Port::OUTPUT, module, Contrast::MAIN_OUTPUT)); } + +Model *modelContrast = Model::create("HetrickCV", "Contrast", "Contrast", EFFECT_TAG); diff --git a/src/Crackle.cpp b/src/Crackle.cpp index fe01e1d..910da99 100644 --- a/src/Crackle.cpp +++ b/src/Crackle.cpp @@ -1,19 +1,19 @@ #include "HetrickCV.hpp" -struct Crackle : Module +struct Crackle : Module { - enum ParamIds + enum ParamIds { RATE_PARAM, BROKEN_PARAM, NUM_PARAMS }; - enum InputIds + enum InputIds { RATE_INPUT, NUM_INPUTS }; - enum OutputIds + enum OutputIds { MAIN_OUTPUT, NUM_OUTPUTS @@ -23,10 +23,10 @@ struct Crackle : Module float densityScaled = 1.0; float y1 = 0.2643; float y2 = 0.0; - + float lasty1 = 0.2643f; - Crackle() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) + Crackle() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) { y1 = randomf(); y2 = 0.0f; @@ -49,19 +49,19 @@ struct Crackle : Module }; -void Crackle::step() +void Crackle::step() { const float densityInput = params[RATE_PARAM].value + inputs[RATE_INPUT].value; - + if(lastDensity != densityInput) { densityScaled = clampf(densityInput, 0.0f, 2.0f)/2.0f; densityScaled = powf(densityScaled, 3.0f) + 1.0f; lastDensity = densityInput; } - + const bool brokenMode = (params[BROKEN_PARAM].value == 0.0); - + if(brokenMode) { const float y0 = fabs(y1 * densityScaled - y2 - 0.05f); @@ -81,10 +81,10 @@ void Crackle::step() } -CrackleWidget::CrackleWidget() +struct CrackleWidget : ModuleWidget { CrackleWidget(Crackle *module); }; + +CrackleWidget::CrackleWidget(Crackle *module) : ModuleWidget(module) { - auto *module = new Crackle(); - setModule(module); box.size = Vec(6 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -94,18 +94,20 @@ CrackleWidget::CrackleWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //////PARAMS////// - addParam(createParam(Vec(28, 87), module, Crackle::RATE_PARAM, 0.0, 2.0, 1.7)); - addParam(createParam(Vec(37, 220), module, Crackle::BROKEN_PARAM, 0.0, 1.0, 1.0)); + addParam(ParamWidget::create(Vec(28, 87), module, Crackle::RATE_PARAM, 0.0, 2.0, 1.7)); + addParam(ParamWidget::create(Vec(37, 220), module, Crackle::BROKEN_PARAM, 0.0, 1.0, 1.0)); //////INPUTS////// - addInput(createInput(Vec(33, 146), module, Crackle::RATE_INPUT)); + addInput(Port::create(Vec(33, 146), Port::INPUT, module, Crackle::RATE_INPUT)); //////OUTPUTS////// - addOutput(createOutput(Vec(33, 285), module, Crackle::MAIN_OUTPUT)); + addOutput(Port::create(Vec(33, 285), Port::OUTPUT, module, Crackle::MAIN_OUTPUT)); } + +Model *modelCrackle = Model::create("HetrickCV", "Crackle", "Crackle", NOISE_TAG); diff --git a/src/DToA.cpp b/src/DToA.cpp index 7e66e83..ebfef3c 100644 --- a/src/DToA.cpp +++ b/src/DToA.cpp @@ -1,8 +1,8 @@ #include "HetrickCV.hpp" -struct DigitalToAnalog : Module +struct DigitalToAnalog : Module { - enum ParamIds + enum ParamIds { SCALE_PARAM, OFFSET_PARAM, @@ -11,7 +11,7 @@ struct DigitalToAnalog : Module NUM_PARAMS }; - enum InputIds + enum InputIds { IN1_INPUT, IN2_INPUT, @@ -26,12 +26,12 @@ struct DigitalToAnalog : Module NUM_INPUTS }; - enum OutputIds + enum OutputIds { MAIN_OUTPUT, NUM_OUTPUTS }; - enum LightIds + enum LightIds { IN1_LIGHT, IN2_LIGHT, @@ -54,11 +54,11 @@ struct DigitalToAnalog : Module NUM_LIGHTS }; - + SchmittTrigger clockTrigger; SchmittTrigger modeTrigger; SchmittTrigger rectTrigger; - + int mode = 0; int rectMode = 0; @@ -66,9 +66,9 @@ struct DigitalToAnalog : Module bool ins[8] = {}; - DigitalToAnalog() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) + DigitalToAnalog() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { - + } void step() override; @@ -77,30 +77,30 @@ struct DigitalToAnalog : Module void processBiOff(); void processBiSig(); - void reset() override + void reset() override { mode = 0; rectMode = 0; } - void randomize() override + void randomize() override { mode = round(randomf() * 2.0f); rectMode = round(randomf() * 2.0f); } - - json_t *toJson() override + + json_t *toJson() override { json_t *rootJ = json_object(); json_object_set_new(rootJ, "mode", json_integer(mode)); json_object_set_new(rootJ, "rectMode", json_integer(rectMode)); return rootJ; } - void fromJson(json_t *rootJ) override + void fromJson(json_t *rootJ) override { json_t *modeJ = json_object_get(rootJ, "mode"); if (modeJ) mode = json_integer_value(modeJ); - + json_t *rectModeJ = json_object_get(rootJ, "rectMode"); if (rectModeJ) rectMode = json_integer_value(rectModeJ); @@ -113,7 +113,7 @@ struct DigitalToAnalog : Module }; -void DigitalToAnalog::step() +void DigitalToAnalog::step() { if (modeTrigger.process(params[MODE_PARAM].value)) mode = (mode + 1) % 3; if (rectTrigger.process(params[RECTIFY_PARAM].value)) rectMode = (rectMode + 1) % 3; @@ -134,11 +134,11 @@ void DigitalToAnalog::step() mainOutput = 0.0f; for(int i = 0; i < 8; i++) - { + { ins[i] = inputs[IN1_INPUT + i].value > 1.0f; lights[IN1_LIGHT + i].value = ins[i] ? 1.0f : 0.0f; } - + if(mode == 0) processUni8(); else if (mode == 1) processBiOff(); else if (mode == 2) processBiSig(); @@ -203,10 +203,11 @@ void DigitalToAnalog::processBiSig() if(ins[7]) mainOutput *= -1.0f; } -DigitalToAnalogWidget::DigitalToAnalogWidget() + +struct DigitalToAnalogWidget : ModuleWidget { DigitalToAnalogWidget(DigitalToAnalog *module); }; + +DigitalToAnalogWidget::DigitalToAnalogWidget(DigitalToAnalog *module) : ModuleWidget(module) { - auto *module = new DigitalToAnalog(); - setModule(module); box.size = Vec(12 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -216,35 +217,35 @@ DigitalToAnalogWidget::DigitalToAnalogWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //////PARAMS////// - addParam(createParam(Vec(85, 270), module, DigitalToAnalog::MODE_PARAM, 0.0, 1.0, 0.0)); - addParam(createParam(Vec(135, 270), module, DigitalToAnalog::RECTIFY_PARAM, 0.0, 1.0, 0.0)); - + addParam(ParamWidget::create(Vec(85, 270), module, DigitalToAnalog::MODE_PARAM, 0.0, 1.0, 0.0)); + addParam(ParamWidget::create(Vec(135, 270), module, DigitalToAnalog::RECTIFY_PARAM, 0.0, 1.0, 0.0)); + //////BLINKENLIGHTS////// int modeLightX = 82; - addChild(createLight>(Vec(modeLightX, 306), module, DigitalToAnalog::MODE_UNI8_LIGHT)); - addChild(createLight>(Vec(modeLightX, 319), module, DigitalToAnalog::MODE_BOFF_LIGHT)); - addChild(createLight>(Vec(modeLightX, 332), module, DigitalToAnalog::MODE_BSIG_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(modeLightX, 306), module, DigitalToAnalog::MODE_UNI8_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(modeLightX, 319), module, DigitalToAnalog::MODE_BOFF_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(modeLightX, 332), module, DigitalToAnalog::MODE_BSIG_LIGHT)); int rectLightX = 134; - addChild(createLight>(Vec(rectLightX, 306), module, DigitalToAnalog::RECT_NONE_LIGHT)); - addChild(createLight>(Vec(rectLightX, 319), module, DigitalToAnalog::RECT_HALF_LIGHT)); - addChild(createLight>(Vec(rectLightX, 332), module, DigitalToAnalog::RECT_FULL_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(rectLightX, 306), module, DigitalToAnalog::RECT_NONE_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(rectLightX, 319), module, DigitalToAnalog::RECT_HALF_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(rectLightX, 332), module, DigitalToAnalog::RECT_FULL_LIGHT)); - addOutput(createOutput(Vec(78, 70), module, DigitalToAnalog::MAIN_OUTPUT)); - addChild(createLight>(Vec(87, 111), module, DigitalToAnalog::OUT_POS_LIGHT)); + addOutput(Port::create(Vec(78, 70), Port::OUTPUT, module, DigitalToAnalog::MAIN_OUTPUT)); + addChild(ModuleLightWidget::create>(Vec(87, 111), module, DigitalToAnalog::OUT_POS_LIGHT)); //////INPUTS////// - addInput(createInput(Vec(112, 152), module, DigitalToAnalog::SYNC_INPUT)); + addInput(Port::create(Vec(112, 152), Port::INPUT, module, DigitalToAnalog::SYNC_INPUT)); - addParam(createParam(Vec(114, 73), module, DigitalToAnalog::SCALE_PARAM, -1.0, 1.0, 0.2)); - addParam(createParam(Vec(150, 73), module, DigitalToAnalog::OFFSET_PARAM, -5.0, 5.0, 0.0)); + addParam(ParamWidget::create(Vec(114, 73), module, DigitalToAnalog::SCALE_PARAM, -1.0, 1.0, 0.2)); + addParam(ParamWidget::create(Vec(150, 73), module, DigitalToAnalog::OFFSET_PARAM, -5.0, 5.0, 0.0)); const int inXPos = 10; const int inLightX = 50; @@ -254,9 +255,11 @@ DigitalToAnalogWidget::DigitalToAnalogWidget() const int lightY = 59 + (40 * i); //////OUTPUTS////// - addInput(createInput(Vec(inXPos, yPos), module, DigitalToAnalog::IN1_INPUT + i)); + addInput(Port::create(Vec(inXPos, yPos), Port::INPUT, module, DigitalToAnalog::IN1_INPUT + i)); //////BLINKENLIGHTS////// - addChild(createLight>(Vec(inLightX, lightY), module, DigitalToAnalog::IN1_LIGHT + i)); + addChild(ModuleLightWidget::create>(Vec(inLightX, lightY), module, DigitalToAnalog::IN1_LIGHT + i)); } } + +Model *modelDigitalToAnalog = Model::create("HetrickCV", "DigitalToAnalog", "Digital to Analog", LOGIC_TAG); diff --git a/src/Delta.cpp b/src/Delta.cpp index 4ab8275..0ba44c2 100644 --- a/src/Delta.cpp +++ b/src/Delta.cpp @@ -1,20 +1,20 @@ #include "HetrickCV.hpp" -struct Delta : Module +struct Delta : Module { - enum ParamIds + enum ParamIds { AMOUNT_PARAM, SCALE_PARAM, NUM_PARAMS }; - enum InputIds + enum InputIds { MAIN_INPUT, AMOUNT_INPUT, NUM_INPUTS }; - enum OutputIds + enum OutputIds { GT_GATE_OUTPUT, GT_TRIG_OUTPUT, @@ -25,7 +25,7 @@ struct Delta : Module NUM_OUTPUTS }; - enum LightIds + enum LightIds { GT_LIGHT, LT_LIGHT, @@ -33,9 +33,9 @@ struct Delta : Module NUM_LIGHTS }; - Delta() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) + Delta() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { - + } TriggerGenWithSchmitt ltTrig, gtTrig; @@ -52,7 +52,7 @@ struct Delta : Module }; -void Delta::step() +void Delta::step() { float input = inputs[MAIN_INPUT].value; @@ -77,17 +77,17 @@ void Delta::step() outputs[CHANGE_OUTPUT].value = allTrigs; outputs[DELTA_OUTPUT].value = deltaOutput; - + lights[GT_LIGHT].setBrightnessSmooth(outputs[GT_GATE_OUTPUT].value); lights[LT_LIGHT].setBrightnessSmooth(outputs[LT_GATE_OUTPUT].value); lights[CHANGE_LIGHT].setBrightnessSmooth(allTrigs); } -DeltaWidget::DeltaWidget() +struct DeltaWidget : ModuleWidget { DeltaWidget(Delta *module); }; + +DeltaWidget::DeltaWidget(Delta *module) : ModuleWidget(module) { - auto *module = new Delta(); - setModule(module); box.size = Vec(6 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -97,29 +97,31 @@ DeltaWidget::DeltaWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //////PARAMS////// - addParam(createParam(Vec(27, 62), module, Delta::AMOUNT_PARAM, 0.0, 5.0, 0.0)); - addParam(createParam(Vec(36, 112), module, Delta::SCALE_PARAM, -1.0, 1.0, 1.0)); + addParam(ParamWidget::create(Vec(27, 62), module, Delta::AMOUNT_PARAM, 0.0, 5.0, 0.0)); + addParam(ParamWidget::create(Vec(36, 112), module, Delta::SCALE_PARAM, -1.0, 1.0, 1.0)); //////INPUTS////// - addInput(createInput(Vec(12, 195), module, Delta::MAIN_INPUT)); - addInput(createInput(Vec(33, 145), module, Delta::AMOUNT_INPUT)); + addInput(Port::create(Vec(12, 195), Port::INPUT, module, Delta::MAIN_INPUT)); + addInput(Port::create(Vec(33, 145), Port::INPUT, module, Delta::AMOUNT_INPUT)); //////OUTPUTS////// - addOutput(createOutput(Vec(53, 195), module, Delta::DELTA_OUTPUT)); - addOutput(createOutput(Vec(12, 285), module, Delta::LT_GATE_OUTPUT)); - addOutput(createOutput(Vec(53, 285), module, Delta::GT_GATE_OUTPUT)); - addOutput(createOutput(Vec(12, 315), module, Delta::LT_TRIG_OUTPUT)); - addOutput(createOutput(Vec(53, 315), module, Delta::GT_TRIG_OUTPUT)); - addOutput(createOutput(Vec(32.5, 245), module, Delta::CHANGE_OUTPUT)); + addOutput(Port::create(Vec(53, 195), Port::OUTPUT, module, Delta::DELTA_OUTPUT)); + addOutput(Port::create(Vec(12, 285), Port::OUTPUT, module, Delta::LT_GATE_OUTPUT)); + addOutput(Port::create(Vec(53, 285), Port::OUTPUT, module, Delta::GT_GATE_OUTPUT)); + addOutput(Port::create(Vec(12, 315), Port::OUTPUT, module, Delta::LT_TRIG_OUTPUT)); + addOutput(Port::create(Vec(53, 315), Port::OUTPUT, module, Delta::GT_TRIG_OUTPUT)); + addOutput(Port::create(Vec(32.5, 245), Port::OUTPUT, module, Delta::CHANGE_OUTPUT)); //////BLINKENLIGHTS////// - addChild(createLight>(Vec(22, 275), module, Delta::LT_LIGHT)); - addChild(createLight>(Vec(62, 275), module, Delta::GT_LIGHT)); - addChild(createLight>(Vec(42, 275), module, Delta::CHANGE_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(22, 275), module, Delta::LT_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(62, 275), module, Delta::GT_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(42, 275), module, Delta::CHANGE_LIGHT)); } + +Model *modelDelta = Model::create("HetrickCV", "Delta", "Delta", LOGIC_TAG); diff --git a/src/Dust.cpp b/src/Dust.cpp index b4c9b41..703dd3c 100755 --- a/src/Dust.cpp +++ b/src/Dust.cpp @@ -1,19 +1,19 @@ #include "HetrickCV.hpp" -struct Dust : Module +struct Dust : Module { - enum ParamIds + enum ParamIds { RATE_PARAM, BIPOLAR_PARAM, NUM_PARAMS }; - enum InputIds + enum InputIds { RATE_INPUT, NUM_INPUTS }; - enum OutputIds + enum OutputIds { DUST_OUTPUT, NUM_OUTPUTS @@ -23,9 +23,9 @@ struct Dust : Module float densityScaled = 0.0; float threshold = 0.0; - Dust() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) + Dust() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) { - + } void step() override; @@ -37,10 +37,10 @@ struct Dust : Module }; -void Dust::step() +void Dust::step() { float densityInput = params[RATE_PARAM].value + inputs[RATE_INPUT].value; - + if(lastDensity != densityInput) { densityScaled = clampf(densityInput, 0.0f, 4.0f) / 4.0f; @@ -72,11 +72,10 @@ void Dust::step() } } +struct DustWidget : ModuleWidget { DustWidget(Dust *module); }; -DustWidget::DustWidget() +DustWidget::DustWidget(Dust *module) : ModuleWidget(module) { - auto *module = new Dust(); - setModule(module); box.size = Vec(6 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -86,18 +85,20 @@ DustWidget::DustWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //////PARAMS////// - addParam(createParam(Vec(28, 87), module, Dust::RATE_PARAM, 0, 4.0, 0.0)); - addParam(createParam(Vec(37, 220), module, Dust::BIPOLAR_PARAM, 0.0, 1.0, 0.0)); + addParam(ParamWidget::create(Vec(28, 87), module, Dust::RATE_PARAM, 0, 4.0, 0.0)); + addParam(ParamWidget::create(Vec(37, 220), module, Dust::BIPOLAR_PARAM, 0.0, 1.0, 0.0)); //////INPUTS////// - addInput(createInput(Vec(33, 146), module, Dust::RATE_INPUT)); + addInput(Port::create(Vec(33, 146), Port::INPUT, module, Dust::RATE_INPUT)); //////OUTPUTS////// - addOutput(createOutput(Vec(33, 285), module, Dust::DUST_OUTPUT)); + addOutput(Port::create(Vec(33, 285), Port::OUTPUT, module, Dust::DUST_OUTPUT)); } + +Model *modelDust = Model::create("HetrickCV", "Dust", "Dust", NOISE_TAG, GRANULAR_TAG); diff --git a/src/Exponent.cpp b/src/Exponent.cpp index e649edc..648e4ae 100644 --- a/src/Exponent.cpp +++ b/src/Exponent.cpp @@ -1,29 +1,29 @@ #include "HetrickCV.hpp" -struct Exponent : Module +struct Exponent : Module { - enum ParamIds + enum ParamIds { AMOUNT_PARAM, SCALE_PARAM, RANGE_PARAM, NUM_PARAMS }; - enum InputIds + enum InputIds { MAIN_INPUT, AMOUNT_INPUT, NUM_INPUTS }; - enum OutputIds + enum OutputIds { MAIN_OUTPUT, NUM_OUTPUTS }; - Exponent() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) + Exponent() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) { - + } void step() override; @@ -35,7 +35,7 @@ struct Exponent : Module }; -void Exponent::step() +void Exponent::step() { float input = inputs[MAIN_INPUT].value; const bool negativeInput = input < 0.0f; @@ -59,7 +59,7 @@ void Exponent::step() if (negativeInput) output *= -1.0f; if(mode5V) output *= 5.0f; else output *= 10.0f; - + outputs[MAIN_OUTPUT].value = output; } @@ -72,10 +72,11 @@ struct CKSSRot : SVGSwitch, ToggleSwitch { } }; -ExponentWidget::ExponentWidget() + +struct ExponentWidget : ModuleWidget { ExponentWidget(Exponent *module); }; + +ExponentWidget::ExponentWidget(Exponent *module) : ModuleWidget(module) { - auto *module = new Exponent(); - setModule(module); box.size = Vec(6 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -85,20 +86,22 @@ ExponentWidget::ExponentWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //////PARAMS////// - addParam(createParam(Vec(27, 62), module, Exponent::AMOUNT_PARAM, -5.0, 5.0, 0.0)); - addParam(createParam(Vec(36, 112), module, Exponent::SCALE_PARAM, -1.0, 1.0, 1.0)); - addParam(createParam(Vec(35, 200), module, Exponent::RANGE_PARAM, 0.0, 1.0, 0.0)); + addParam(ParamWidget::create(Vec(27, 62), module, Exponent::AMOUNT_PARAM, -5.0, 5.0, 0.0)); + addParam(ParamWidget::create(Vec(36, 112), module, Exponent::SCALE_PARAM, -1.0, 1.0, 1.0)); + addParam(ParamWidget::create(Vec(35, 200), module, Exponent::RANGE_PARAM, 0.0, 1.0, 0.0)); //////INPUTS////// - addInput(createInput(Vec(33, 235), module, Exponent::MAIN_INPUT)); - addInput(createInput(Vec(33, 145), module, Exponent::AMOUNT_INPUT)); + addInput(Port::create(Vec(33, 235), Port::INPUT, module, Exponent::MAIN_INPUT)); + addInput(Port::create(Vec(33, 145), Port::INPUT, module, Exponent::AMOUNT_INPUT)); //////OUTPUTS////// - addOutput(createOutput(Vec(33, 285), module, Exponent::MAIN_OUTPUT)); + addOutput(Port::create(Vec(33, 285), Port::OUTPUT, module, Exponent::MAIN_OUTPUT)); } + +Model *modelExponent = Model::create("HetrickCV", "Exponent", "Exponent", WAVESHAPER_TAG); diff --git a/src/FlipFlop.cpp b/src/FlipFlop.cpp index e236508..dad5408 100644 --- a/src/FlipFlop.cpp +++ b/src/FlipFlop.cpp @@ -1,18 +1,18 @@ #include "HetrickCV.hpp" -struct FlipFlop : Module +struct FlipFlop : Module { - enum ParamIds + enum ParamIds { NUM_PARAMS }; - enum InputIds + enum InputIds { INT_INPUT, IND_INPUT, NUM_INPUTS }; - enum OutputIds + enum OutputIds { FFT_OUTPUT, FFD_OUTPUT, @@ -20,8 +20,8 @@ struct FlipFlop : Module FFDNOT_OUTPUT, NUM_OUTPUTS }; - - enum LightIds + + enum LightIds { FFT_LIGHT, FFD_LIGHT, @@ -37,7 +37,7 @@ struct FlipFlop : Module bool toggle = false; bool dataIn = false; - FlipFlop() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) + FlipFlop() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { reset(); } @@ -60,7 +60,7 @@ struct FlipFlop : Module }; -void FlipFlop::step() +void FlipFlop::step() { dataIn = (inputs[IND_INPUT].value >= 1.0f); lights[DATA_LIGHT].value = dataIn ? 5.0f : 0.0f; @@ -88,11 +88,10 @@ void FlipFlop::step() lights[FFDNOT_LIGHT].value = outs[3]; } +struct FlipFlopWidget : ModuleWidget { FlipFlopWidget(FlipFlop *module); }; -FlipFlopWidget::FlipFlopWidget() +FlipFlopWidget::FlipFlopWidget(FlipFlop *module) : ModuleWidget(module) { - auto *module = new FlipFlop(); - setModule(module); box.size = Vec(6 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -102,23 +101,25 @@ FlipFlopWidget::FlipFlopWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //////PARAMS////// //////INPUTS////// - addInput(createInput(Vec(10, 100), module, FlipFlop::INT_INPUT)); - addInput(createInput(Vec(55, 100), module, FlipFlop::IND_INPUT)); - addChild(createLight>(Vec(18, 87), module, FlipFlop::TOGGLE_LIGHT)); - addChild(createLight>(Vec(63, 87), module, FlipFlop::DATA_LIGHT)); + addInput(Port::create(Vec(10, 100), Port::INPUT, module, FlipFlop::INT_INPUT)); + addInput(Port::create(Vec(55, 100), Port::INPUT, module, FlipFlop::IND_INPUT)); + addChild(ModuleLightWidget::create>(Vec(18, 87), module, FlipFlop::TOGGLE_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(63, 87), module, FlipFlop::DATA_LIGHT)); for(int i = 0; i < 4; i++) { const int yPos = i*45; - addOutput(createOutput(Vec(33, 150 + yPos), module, FlipFlop::FFT_OUTPUT + i)); - addChild(createLight>(Vec(70, 158 + yPos), module, FlipFlop::FFT_LIGHT + i)); + addOutput(Port::create(Vec(33, 150 + yPos), Port::OUTPUT, module, FlipFlop::FFT_OUTPUT + i)); + addChild(ModuleLightWidget::create>(Vec(70, 158 + yPos), module, FlipFlop::FFT_LIGHT + i)); } } + +Model *modelFlipFlop = Model::create("HetrickCV", "FlipFlop", "Flip-Flop", LOGIC_TAG); diff --git a/src/FlipPan.cpp b/src/FlipPan.cpp index 9afdc94..c544796 100644 --- a/src/FlipPan.cpp +++ b/src/FlipPan.cpp @@ -1,35 +1,35 @@ #include "HetrickCV.hpp" -struct FlipPan : Module +struct FlipPan : Module { - enum ParamIds + enum ParamIds { AMOUNT_PARAM, SCALE_PARAM, STYLE_PARAM, NUM_PARAMS }; - enum InputIds + enum InputIds { LEFT_INPUT, RIGHT_INPUT, AMOUNT_INPUT, NUM_INPUTS }; - enum OutputIds + enum OutputIds { LEFT_OUTPUT, RIGHT_OUTPUT, NUM_OUTPUTS }; - FlipPan() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) + FlipPan() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) { - + } void step() override; - + float paraPanShape(const float _input) const { return (4.0f - _input) * _input * 0.3333333f; @@ -42,7 +42,7 @@ struct FlipPan : Module }; -void FlipPan::step() +void FlipPan::step() { float inL = inputs[LEFT_INPUT].value; float inR = inputs[RIGHT_INPUT].value; @@ -77,10 +77,11 @@ struct CKSSRot : SVGSwitch, ToggleSwitch { } }; -FlipPanWidget::FlipPanWidget() + +struct FlipPanWidget : ModuleWidget { FlipPanWidget(FlipPan *module); }; + +FlipPanWidget::FlipPanWidget(FlipPan *module) : ModuleWidget(module) { - auto *module = new FlipPan(); - setModule(module); box.size = Vec(6 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -90,22 +91,24 @@ FlipPanWidget::FlipPanWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //////PARAMS////// - addParam(createParam(Vec(27, 62), module, FlipPan::AMOUNT_PARAM, 0.0, 5.0, 2.5)); - addParam(createParam(Vec(36, 112), module, FlipPan::SCALE_PARAM, -1.0, 1.0, 1.0)); - addParam(createParam(Vec(35, 200), module, FlipPan::STYLE_PARAM, 0.0, 1.0, 0.0)); + addParam(ParamWidget::create(Vec(27, 62), module, FlipPan::AMOUNT_PARAM, 0.0, 5.0, 2.5)); + addParam(ParamWidget::create(Vec(36, 112), module, FlipPan::SCALE_PARAM, -1.0, 1.0, 1.0)); + addParam(ParamWidget::create(Vec(35, 200), module, FlipPan::STYLE_PARAM, 0.0, 1.0, 0.0)); //////INPUTS////// - addInput(createInput(Vec(10, 235), module, FlipPan::LEFT_INPUT)); - addInput(createInput(Vec(55, 235), module, FlipPan::RIGHT_INPUT)); - addInput(createInput(Vec(33, 145), module, FlipPan::AMOUNT_INPUT)); + addInput(Port::create(Vec(10, 235), Port::INPUT, module, FlipPan::LEFT_INPUT)); + addInput(Port::create(Vec(55, 235), Port::INPUT, module, FlipPan::RIGHT_INPUT)); + addInput(Port::create(Vec(33, 145), Port::INPUT, module, FlipPan::AMOUNT_INPUT)); //////OUTPUTS////// - addOutput(createOutput(Vec(10, 285), module, FlipPan::LEFT_OUTPUT)); - addOutput(createOutput(Vec(55, 285), module, FlipPan::RIGHT_OUTPUT)); + addOutput(Port::create(Vec(10, 285), Port::OUTPUT, module, FlipPan::LEFT_OUTPUT)); + addOutput(Port::create(Vec(55, 285), Port::OUTPUT, module, FlipPan::RIGHT_OUTPUT)); } + +Model *modelFlipPan = Model::create("HetrickCV", "FlipPan", "Flip Pan", PANNING_TAG); diff --git a/src/GateJunction.cpp b/src/GateJunction.cpp index 407eebc..0b77ea8 100644 --- a/src/GateJunction.cpp +++ b/src/GateJunction.cpp @@ -1,8 +1,8 @@ #include "HetrickCV.hpp" -struct GateJunction : Module +struct GateJunction : Module { - enum ParamIds + enum ParamIds { MUTE1_PARAM, MUTE2_PARAM, @@ -24,7 +24,7 @@ struct GateJunction : Module NUM_PARAMS }; - enum InputIds + enum InputIds { IN1_INPUT, IN2_INPUT, @@ -37,7 +37,7 @@ struct GateJunction : Module NUM_INPUTS }; - enum OutputIds + enum OutputIds { OUT1_OUTPUT, OUT2_OUTPUT, @@ -49,7 +49,7 @@ struct GateJunction : Module OUT8_OUTPUT, NUM_OUTPUTS }; - enum LightIds + enum LightIds { MUTE1_LIGHT, MUTE2_LIGHT, @@ -86,41 +86,41 @@ struct GateJunction : Module bool muteState[8] = {}; SchmittTrigger muteTrigger[8]; - + bool invState[8] = {}; SchmittTrigger invTrigger[8]; - GateJunction() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) + GateJunction() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { reset(); } void step() override; - void reset() override + void reset() override { - for (int i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) { muteState[i] = false; invState[i] = false; } } - void randomize() override + void randomize() override { - for (int i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) { muteState[i] = (randomf() < 0.5); invState[i] = (randomf() < 0.5); } } - - json_t *toJson() override + + json_t *toJson() override { json_t *rootJ = json_object(); // states json_t *muteStatesJ = json_array(); json_t *invStatesJ = json_array(); - for (int i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) { json_t *muteStateJ = json_boolean(muteState[i]); json_array_append_new(muteStatesJ, muteStateJ); @@ -131,23 +131,23 @@ struct GateJunction : Module json_object_set_new(rootJ, "invStates", invStatesJ); return rootJ; } - void fromJson(json_t *rootJ) override + void fromJson(json_t *rootJ) override { // states json_t *muteStatesJ = json_object_get(rootJ, "muteStates"); json_t *invStatesJ = json_object_get(rootJ, "invStates"); - if (muteStatesJ) + if (muteStatesJ) { - for (int i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) { json_t *stateJ = json_array_get(muteStatesJ, i); if (stateJ) muteState[i] = json_boolean_value(stateJ); } } - if (invStatesJ) + if (invStatesJ) { - for (int i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) { json_t *stateJ = json_array_get(invStatesJ, i); if (stateJ) @@ -163,7 +163,7 @@ struct GateJunction : Module }; -void GateJunction::step() +void GateJunction::step() { ins[0] = (inputs[IN1_INPUT].value >= 1.0f) ? 5.0f : 0.0f; @@ -184,10 +184,10 @@ void GateJunction::step() { if (muteTrigger[i].process(params[MUTE1_PARAM + i].value)) muteState[i] ^= true; if (invTrigger[i].process(params[INV1_PARAM + i].value)) invState[i] ^= true; - + if(invState[i]) ins[i] = 5.0f - ins[i]; if(muteState[i]) ins[i] = 0.0f; - + outputs[OUT1_OUTPUT + i].value = ins[i]; lights[OUT1_LIGHT + i].value = ins[i]; @@ -203,10 +203,10 @@ struct MuteLight : BASE { } }; -GateJunctionWidget::GateJunctionWidget() +struct GateJunctionWidget : ModuleWidget { GateJunctionWidget(GateJunction *module); }; + +GateJunctionWidget::GateJunctionWidget(GateJunction *module) : ModuleWidget(module) { - auto *module = new GateJunction(); - setModule(module); box.size = Vec(12 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -216,10 +216,10 @@ GateJunctionWidget::GateJunctionWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //////PARAMS////// @@ -233,18 +233,20 @@ GateJunctionWidget::GateJunctionWidget() const int lightY = 59 + (40 * i); //////INPUTS////// - addInput(createInput(Vec(inXPos, yPos), module, GateJunction::IN1_INPUT + i)); + addInput(Port::create(Vec(inXPos, yPos), Port::INPUT, module, GateJunction::IN1_INPUT + i)); //////OUTPUTS////// - addOutput(createOutput(Vec(outXPos, yPos), module, GateJunction::OUT1_OUTPUT + i)); + addOutput(Port::create(Vec(outXPos, yPos), Port::OUTPUT, module, GateJunction::OUT1_OUTPUT + i)); //////BLINKENLIGHTS////// - addChild(createLight>(Vec(outLightX, lightY), module, GateJunction::OUT1_LIGHT + i)); + addChild(ModuleLightWidget::create>(Vec(outLightX, lightY), module, GateJunction::OUT1_LIGHT + i)); + + addParam(ParamWidget::create(Vec(50, 1 + yPos), module, GateJunction::MUTE1_PARAM + i, 0.0, 1.0, 0.0)); + addParam(ParamWidget::create(Vec(85, 1 + yPos), module, GateJunction::INV1_PARAM + i, 0.0, 1.0, 0.0)); - addParam(createParam(Vec(50, 1 + yPos), module, GateJunction::MUTE1_PARAM + i, 0.0, 1.0, 0.0)); - addParam(createParam(Vec(85, 1 + yPos), module, GateJunction::INV1_PARAM + i, 0.0, 1.0, 0.0)); - - addChild(createLight>(Vec(52.2, 3 + yPos), module, GateJunction::MUTE1_LIGHT + i)); - addChild(createLight>(Vec(87.2, 3 + yPos), module, GateJunction::INV1_LIGHT + i)); + addChild(ModuleLightWidget::create>(Vec(52.2, 3 + yPos), module, GateJunction::MUTE1_LIGHT + i)); + addChild(ModuleLightWidget::create>(Vec(87.2, 3 + yPos), module, GateJunction::INV1_LIGHT + i)); } } + +Model *modelGateJunction = Model::create("HetrickCV", "Gate Junction", "Gate Junction", SWITCH_TAG, LOGIC_TAG); diff --git a/src/HetrickCV.cpp b/src/HetrickCV.cpp index 23f4750..086fab5 100755 --- a/src/HetrickCV.cpp +++ b/src/HetrickCV.cpp @@ -6,35 +6,33 @@ Plugin *plugin; void init(rack::Plugin *p) { plugin = p; - p->slug = "HetrickCV"; -#ifdef VERSION + p->slug = TOSTRING(SLUG); plugin->version = TOSTRING(VERSION); -#endif p->website = "https://github.com/mhetrick/hetrickcv"; p->manual = "https://github.com/mhetrick/hetrickcv/blob/master/README.md"; - p->addModel(createModel("HetrickCV", "2To4", "2 To 4 Mix Matrix", MIXER_TAG)); - p->addModel(createModel("HetrickCV", "AnalogToDigital", "Analog to Digital", LOGIC_TAG)); - p->addModel(createModel("HetrickCV", "ASR", "ASR", SEQUENCER_TAG)); - p->addModel(createModel("HetrickCV", "Bitshift", "Bitshift", DISTORTION_TAG, EFFECT_TAG)); - p->addModel(createModel("HetrickCV", "BlankPanel", "Blank Panel")); - p->addModel(createModel("HetrickCV", "Boolean3", "Boolean Logic", LOGIC_TAG)); - p->addModel(createModel("HetrickCV", "Comparator", "Comparator", LOGIC_TAG)); - p->addModel(createModel("HetrickCV", "Contrast", "Contrast", EFFECT_TAG)); - p->addModel(createModel("HetrickCV", "Crackle", "Crackle", NOISE_TAG)); - p->addModel(createModel("HetrickCV", "Delta", "Delta", LOGIC_TAG)); - p->addModel(createModel("HetrickCV", "DigitalToAnalog", "Digital to Analog", LOGIC_TAG)); - p->addModel(createModel("HetrickCV", "Dust", "Dust", NOISE_TAG, GRANULAR_TAG)); - p->addModel(createModel("HetrickCV", "Exponent", "Exponent", WAVESHAPER_TAG)); - p->addModel(createModel("HetrickCV", "FlipFlop", "Flip-Flop", LOGIC_TAG)); - p->addModel(createModel("HetrickCV", "FlipPan", "Flip Pan", PANNING_TAG)); - p->addModel(createModel("HetrickCV", "Gate Junction", "Gate Junction", SWITCH_TAG, LOGIC_TAG)); - p->addModel(createModel("HetrickCV", "Logic Combine", "OR Logic (Gate Combiner)", LOGIC_TAG)); - p->addModel(createModel("HetrickCV", "RandomGates", "Random Gates", RANDOM_TAG)); - p->addModel(createModel("HetrickCV", "Rotator", "Rotator", SWITCH_TAG)); - p->addModel(createModel("HetrickCV", "Scanner", "Scanner", MIXER_TAG)); - p->addModel(createModel("HetrickCV", "Waveshaper", "Waveshaper", WAVESHAPER_TAG, DISTORTION_TAG, EFFECT_TAG)); + p->addModel(modelTwoToFour); + p->addModel(modelAnalogToDigital); + p->addModel(modelASR); + p->addModel(modelBitshift); + p->addModel(modelBlankPanel); + p->addModel(modelBoolean3); + p->addModel(modelComparator); + p->addModel(modelContrast); + p->addModel(modelCrackle); + p->addModel(modelDelta); + p->addModel(modelDigitalToAnalog); + p->addModel(modelDust); + p->addModel(modelExponent); + p->addModel(modelFlipFlop); + p->addModel(modelFlipPan); + p->addModel(modelGateJunction); + p->addModel(modelLogicCombine); + p->addModel(modelRandomGates); + p->addModel(modelRotator); + p->addModel(modelScanner); + p->addModel(modelWaveshape); // Any other plugin initialization may go here. // As an alternative, consider lazy-loading assets and lookup tables within this file or the individual module files to reduce startup times of Rack. } diff --git a/src/HetrickCV.hpp b/src/HetrickCV.hpp index e3bb0bd..b63df6a 100755 --- a/src/HetrickCV.hpp +++ b/src/HetrickCV.hpp @@ -9,47 +9,24 @@ using namespace rack; extern Plugin *plugin; -//////////////////// -// module widgets -//////////////////// - -struct DustWidget : ModuleWidget { DustWidget();}; -struct CrackleWidget : ModuleWidget { CrackleWidget();}; - -struct ASRWidget : ModuleWidget { ASRWidget();}; -struct TwoToFourWidget : ModuleWidget { TwoToFourWidget();}; - -struct FlipFlopWidget : ModuleWidget { FlipFlopWidget();}; -struct Boolean3Widget : ModuleWidget { Boolean3Widget();}; -struct GateJunctionWidget : ModuleWidget { GateJunctionWidget();}; -struct LogicCombineWidget : ModuleWidget { LogicCombineWidget();}; - -struct ComparatorWidget : ModuleWidget { ComparatorWidget();}; -struct DeltaWidget : ModuleWidget { DeltaWidget();}; - -struct AnalogToDigitalWidget : ModuleWidget { AnalogToDigitalWidget();}; -struct DigitalToAnalogWidget : ModuleWidget { DigitalToAnalogWidget();}; -struct BitshiftWidget : ModuleWidget { BitshiftWidget();}; - -struct RotatorWidget : ModuleWidget { RotatorWidget();}; -struct ScannerWidget : ModuleWidget { ScannerWidget();}; -struct RandomGatesWidget : ModuleWidget { RandomGatesWidget();}; - -struct ContrastWidget : ModuleWidget { ContrastWidget();}; -struct ExponentWidget : ModuleWidget { ExponentWidget();}; -struct WaveshapeWidget : ModuleWidget { WaveshapeWidget();}; - -struct FlipPanWidget : ModuleWidget { FlipPanWidget();}; - - -struct BlankPanelWidget : ModuleWidget -{ - SVGPanel *panel1; - SVGPanel *panel2; - SVGPanel *panel3; - SVGPanel *panel4; - SVGPanel *panel5; - BlankPanelWidget(); - void step() override; - Menu *createContextMenu() override; -}; \ No newline at end of file +extern Model *modelTwoToFour; +extern Model *modelAnalogToDigital; +extern Model *modelASR; +extern Model *modelBitshift; +extern Model *modelBlankPanel; +extern Model *modelBoolean3; +extern Model *modelComparator; +extern Model *modelContrast; +extern Model *modelCrackle; +extern Model *modelDelta; +extern Model *modelDigitalToAnalog; +extern Model *modelDust; +extern Model *modelExponent; +extern Model *modelFlipFlop; +extern Model *modelFlipPan; +extern Model *modelGateJunction; +extern Model *modelLogicCombine; +extern Model *modelRandomGates; +extern Model *modelRotator; +extern Model *modelScanner; +extern Model *modelWaveshape; \ No newline at end of file diff --git a/src/LogicCombine.cpp b/src/LogicCombine.cpp index 63244fe..31a532f 100644 --- a/src/LogicCombine.cpp +++ b/src/LogicCombine.cpp @@ -1,12 +1,12 @@ #include "HetrickCV.hpp" -struct LogicCombine : Module +struct LogicCombine : Module { - enum ParamIds + enum ParamIds { NUM_PARAMS }; - enum InputIds + enum InputIds { IN1_INPUT, IN2_INPUT, @@ -18,15 +18,15 @@ struct LogicCombine : Module IN8_INPUT, NUM_INPUTS }; - enum OutputIds + enum OutputIds { OR_OUTPUT, NOR_OUTPUT, TRIG_OUTPUT, NUM_OUTPUTS }; - - enum LightIds + + enum LightIds { OR_LIGHT, NOR_LIGHT, @@ -45,9 +45,9 @@ struct LogicCombine : Module TriggerGenerator trigger; - LogicCombine() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) + LogicCombine() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { - + } void step() override; @@ -59,7 +59,7 @@ struct LogicCombine : Module }; -void LogicCombine::step() +void LogicCombine::step() { orState = false; trigState = false; @@ -80,7 +80,7 @@ void LogicCombine::step() { trigger.trigger(); lights[TRIG_LIGHT].value = 5.0f; - } + } outs[2] = trigger.process() ? 5.0f : 0.0f; @@ -96,11 +96,10 @@ void LogicCombine::step() lights[TRIG_LIGHT].setBrightnessSmooth(outs[2]); } +struct LogicCombineWidget : ModuleWidget { LogicCombineWidget(LogicCombine *module); }; -LogicCombineWidget::LogicCombineWidget() +LogicCombineWidget::LogicCombineWidget(LogicCombine *module) : ModuleWidget(module) { - auto *module = new LogicCombine(); - setModule(module); box.size = Vec(8 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -110,10 +109,10 @@ LogicCombineWidget::LogicCombineWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //////PARAMS////// @@ -124,16 +123,18 @@ LogicCombineWidget::LogicCombineWidget() for(int i = 0; i < LogicCombine::NUM_INPUTS; i++) { - addInput(createInput(Vec(10, 50 + (i*inSpacing)), module, LogicCombine::IN1_INPUT + i)); + addInput(Port::create(Vec(10, 50 + (i*inSpacing)), Port::INPUT, module, LogicCombine::IN1_INPUT + i)); } //////OUTPUTS////// - addOutput(createOutput(Vec(outPos, 150), module, LogicCombine::OR_OUTPUT)); - addOutput(createOutput(Vec(outPos, 195), module, LogicCombine::NOR_OUTPUT)); - addOutput(createOutput(Vec(outPos, 240), module, LogicCombine::TRIG_OUTPUT)); + addOutput(Port::create(Vec(outPos, 150), Port::OUTPUT, module, LogicCombine::OR_OUTPUT)); + addOutput(Port::create(Vec(outPos, 195), Port::OUTPUT, module, LogicCombine::NOR_OUTPUT)); + addOutput(Port::create(Vec(outPos, 240), Port::OUTPUT, module, LogicCombine::TRIG_OUTPUT)); //////BLINKENLIGHTS////// - addChild(createLight>(Vec(lightPos, 158), module, LogicCombine::OR_LIGHT)); - addChild(createLight>(Vec(lightPos, 203), module, LogicCombine::NOR_LIGHT)); - addChild(createLight>(Vec(lightPos, 248), module, LogicCombine::TRIG_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(lightPos, 158), module, LogicCombine::OR_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(lightPos, 203), module, LogicCombine::NOR_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(lightPos, 248), module, LogicCombine::TRIG_LIGHT)); } + +Model *modelLogicCombine = Model::create("HetrickCV", "Logic Combine", "OR Logic (Gate Combiner)", LOGIC_TAG); diff --git a/src/RandomGates.cpp b/src/RandomGates.cpp index d5d668f..ed3bab2 100644 --- a/src/RandomGates.cpp +++ b/src/RandomGates.cpp @@ -1,8 +1,8 @@ #include "HetrickCV.hpp" -struct RandomGates : Module +struct RandomGates : Module { - enum ParamIds + enum ParamIds { MIN_PARAM, MAX_PARAM, @@ -10,7 +10,7 @@ struct RandomGates : Module MODE_PARAM_INVIS, NUM_PARAMS }; - enum InputIds + enum InputIds { CLOCK_INPUT, @@ -18,7 +18,7 @@ struct RandomGates : Module MAXI_INPUT, NUM_INPUTS }; - enum OutputIds + enum OutputIds { OUT1_OUTPUT, OUT2_OUTPUT, @@ -30,14 +30,14 @@ struct RandomGates : Module OUT8_OUTPUT, NUM_OUTPUTS }; - enum LightIds + enum LightIds { CLOCK_LIGHT, MODE_TRIG_LIGHT, MODE_GATE_LIGHT, MODE_HOLD_LIGHT, - + OUT1_LIGHT, OUT2_LIGHT, OUT3_LIGHT, @@ -50,13 +50,13 @@ struct RandomGates : Module NUM_LIGHTS }; - RandomGates() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) + RandomGates() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { - + } void step() override; - + int clampInt(const int _in, const int min = 0, const int max = 7) { if (_in > max) return max; @@ -73,26 +73,26 @@ struct RandomGates : Module bool active[8] = {}; int mode = 0; - json_t *toJson() override + json_t *toJson() override { json_t *rootJ = json_object(); json_object_set_new(rootJ, "mode", json_integer(mode)); return rootJ; } - void fromJson(json_t *rootJ) override + void fromJson(json_t *rootJ) override { json_t *modeJ = json_object_get(rootJ, "mode"); if (modeJ) mode = json_integer_value(modeJ); } - - void reset() override + + void reset() override { mode = 0; } - - void randomize() override + + void randomize() override { mode = round(randomf() * 2.0f); } @@ -104,7 +104,7 @@ struct RandomGates : Module }; -void RandomGates::step() +void RandomGates::step() { int max = round(params[MAX_PARAM].value + inputs[MAXI_INPUT].value); int min = round(params[MIN_PARAM].value + inputs[MINI_INPUT].value); @@ -116,7 +116,7 @@ void RandomGates::step() const bool clockHigh = inputs[CLOCK_INPUT].value > 1.0f; - if (modeTrigger.process(params[MODE_PARAM].value)) + if (modeTrigger.process(params[MODE_PARAM].value)) { mode = (mode + 1) % 3; } @@ -133,7 +133,7 @@ void RandomGates::step() active[i] = randNum == i; } } - + lights[MODE_TRIG_LIGHT].setBrightness(mode == 0 ? 1.0f : 0.0f); lights[MODE_HOLD_LIGHT].setBrightness(mode == 1 ? 1.0f : 0.0f); lights[MODE_GATE_LIGHT].setBrightness(mode == 2 ? 1.0f : 0.0f); @@ -177,10 +177,10 @@ void RandomGates::step() } -RandomGatesWidget::RandomGatesWidget() +struct RandomGatesWidget : ModuleWidget { RandomGatesWidget(RandomGates *module); }; + +RandomGatesWidget::RandomGatesWidget(RandomGates *module) : ModuleWidget(module) { - auto *module = new RandomGates(); - setModule(module); box.size = Vec(12 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -190,10 +190,10 @@ RandomGatesWidget::RandomGatesWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //const int inXPos = 10; const int outXPos = 145; @@ -201,18 +201,18 @@ RandomGatesWidget::RandomGatesWidget() const int inLightX = 45; - addInput(createInput(Vec(58, 90), module, RandomGates::CLOCK_INPUT)); - addParam(createParam(Vec(10, 145), module, RandomGates::MIN_PARAM, 0, 7.0, 0.0)); - addParam(createParam(Vec(10, 205), module, RandomGates::MAX_PARAM, 0, 7.0, 7.0)); - addInput(createInput(Vec(58, 150), module, RandomGates::MINI_INPUT)); - addInput(createInput(Vec(58, 210), module, RandomGates::MAXI_INPUT)); + addInput(Port::create(Vec(58, 90), Port::INPUT, module, RandomGates::CLOCK_INPUT)); + addParam(ParamWidget::create(Vec(10, 145), module, RandomGates::MIN_PARAM, 0, 7.0, 0.0)); + addParam(ParamWidget::create(Vec(10, 205), module, RandomGates::MAX_PARAM, 0, 7.0, 7.0)); + addInput(Port::create(Vec(58, 150), Port::INPUT, module, RandomGates::MINI_INPUT)); + addInput(Port::create(Vec(58, 210), Port::INPUT, module, RandomGates::MAXI_INPUT)); - addParam(createParam(Vec(56, 270), module, RandomGates::MODE_PARAM, 0.0, 1.0, 0.0)); + addParam(ParamWidget::create(Vec(56, 270), module, RandomGates::MODE_PARAM, 0.0, 1.0, 0.0)); //////BLINKENLIGHTS////// - addChild(createLight>(Vec(inLightX, 306), module, RandomGates::MODE_TRIG_LIGHT)); - addChild(createLight>(Vec(inLightX, 319), module, RandomGates::MODE_HOLD_LIGHT)); - addChild(createLight>(Vec(inLightX, 332), module, RandomGates::MODE_GATE_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(inLightX, 306), module, RandomGates::MODE_TRIG_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(inLightX, 319), module, RandomGates::MODE_HOLD_LIGHT)); + addChild(ModuleLightWidget::create>(Vec(inLightX, 332), module, RandomGates::MODE_GATE_LIGHT)); for(int i = 0; i < 8; i++) { @@ -220,9 +220,11 @@ RandomGatesWidget::RandomGatesWidget() const int lightY = 59 + (40 * i); //////OUTPUTS////// - addOutput(createOutput(Vec(outXPos, yPos), module, i)); + addOutput(Port::create(Vec(outXPos, yPos), Port::OUTPUT, module, i)); //////BLINKENLIGHTS////// - addChild(createLight>(Vec(outLightX, lightY), module, RandomGates::OUT1_LIGHT + i)); + addChild(ModuleLightWidget::create>(Vec(outLightX, lightY), module, RandomGates::OUT1_LIGHT + i)); } } + +Model *modelRandomGates = Model::create("HetrickCV", "RandomGates", "Random Gates", RANDOM_TAG); diff --git a/src/Rotator.cpp b/src/Rotator.cpp index 22a3800..069171a 100644 --- a/src/Rotator.cpp +++ b/src/Rotator.cpp @@ -1,14 +1,14 @@ #include "HetrickCV.hpp" -struct Rotator : Module +struct Rotator : Module { - enum ParamIds + enum ParamIds { ROTATE_PARAM, STAGES_PARAM, NUM_PARAMS }; - enum InputIds + enum InputIds { IN1_INPUT, IN2_INPUT, @@ -23,7 +23,7 @@ struct Rotator : Module STAGES_INPUT, NUM_INPUTS }; - enum OutputIds + enum OutputIds { OUT1_OUTPUT, OUT2_OUTPUT, @@ -35,7 +35,7 @@ struct Rotator : Module OUT8_OUTPUT, NUM_OUTPUTS }; - enum LightIds + enum LightIds { IN1_POS_LIGHT, IN1_NEG_LIGHT, IN2_POS_LIGHT, IN2_NEG_LIGHT, @@ -45,7 +45,7 @@ struct Rotator : Module IN6_POS_LIGHT, IN6_NEG_LIGHT, IN7_POS_LIGHT, IN7_NEG_LIGHT, IN8_POS_LIGHT, IN8_NEG_LIGHT, - + OUT1_POS_LIGHT, OUT1_NEG_LIGHT, OUT2_POS_LIGHT, OUT2_NEG_LIGHT, OUT3_POS_LIGHT, OUT3_NEG_LIGHT, @@ -61,13 +61,13 @@ struct Rotator : Module float ins[8] = {}; float outs[8] = {}; - Rotator() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) + Rotator() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { - + } void step() override; - + int clampInt(const int _in, const int min = 0, const int max = 7) { if (_in > max) return max; @@ -82,7 +82,7 @@ struct Rotator : Module }; -void Rotator::step() +void Rotator::step() { int rotation = round(params[ROTATE_PARAM].value + inputs[ROTATE_INPUT].value); int stages = round(params[STAGES_PARAM].value + inputs[STAGES_INPUT].value); @@ -104,10 +104,10 @@ void Rotator::step() } -RotatorWidget::RotatorWidget() +struct RotatorWidget : ModuleWidget { RotatorWidget(Rotator *module); }; + +RotatorWidget::RotatorWidget(Rotator *module) : ModuleWidget(module) { - auto *module = new Rotator(); - setModule(module); box.size = Vec(12 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -117,17 +117,17 @@ RotatorWidget::RotatorWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //////PARAMS////// - addParam(createParam(Vec(70, 85), module, Rotator::ROTATE_PARAM, 0, 7.0, 0.0)); - addParam(createParam(Vec(70, 245), module, Rotator::STAGES_PARAM, 0, 7.0, 7.0)); - - addInput(createInput(Vec(75, 150), module, Rotator::ROTATE_INPUT)); - addInput(createInput(Vec(75, 310), module, Rotator::STAGES_INPUT)); + addParam(ParamWidget::create(Vec(70, 85), module, Rotator::ROTATE_PARAM, 0, 7.0, 0.0)); + addParam(ParamWidget::create(Vec(70, 245), module, Rotator::STAGES_PARAM, 0, 7.0, 7.0)); + + addInput(Port::create(Vec(75, 150), Port::INPUT, module, Rotator::ROTATE_INPUT)); + addInput(Port::create(Vec(75, 310), Port::INPUT, module, Rotator::STAGES_INPUT)); const int inXPos = 10; const int outXPos = 145; @@ -139,13 +139,15 @@ RotatorWidget::RotatorWidget() const int lightY = 59 + (40 * i); //////INPUTS////// - addInput(createInput(Vec(inXPos, yPos), module, i)); + addInput(Port::create(Vec(inXPos, yPos), Port::INPUT, module, i)); //////OUTPUTS////// - addOutput(createOutput(Vec(outXPos, yPos), module, i)); + addOutput(Port::create(Vec(outXPos, yPos), Port::OUTPUT, module, i)); //////BLINKENLIGHTS////// - addChild(createLight>(Vec(inLightX, lightY), module, Rotator::IN1_POS_LIGHT + 2*i)); - addChild(createLight>(Vec(outLightX, lightY), module, Rotator::OUT1_POS_LIGHT + 2*i)); + addChild(ModuleLightWidget::create>(Vec(inLightX, lightY), module, Rotator::IN1_POS_LIGHT + 2*i)); + addChild(ModuleLightWidget::create>(Vec(outLightX, lightY), module, Rotator::OUT1_POS_LIGHT + 2*i)); } } + +Model *modelRotator = Model::create("HetrickCV", "Rotator", "Rotator", SWITCH_TAG); diff --git a/src/Scanner.cpp b/src/Scanner.cpp index aefdd41..3eaa5ce 100644 --- a/src/Scanner.cpp +++ b/src/Scanner.cpp @@ -1,8 +1,8 @@ #include "HetrickCV.hpp" -struct Scanner : Module +struct Scanner : Module { - enum ParamIds + enum ParamIds { SCAN_PARAM, STAGES_PARAM, @@ -12,7 +12,7 @@ struct Scanner : Module MIXSCALE_PARAM, NUM_PARAMS }; - enum InputIds + enum InputIds { IN1_INPUT, IN2_INPUT, @@ -30,7 +30,7 @@ struct Scanner : Module ALLIN_INPUT, NUM_INPUTS }; - enum OutputIds + enum OutputIds { OUT1_OUTPUT, OUT2_OUTPUT, @@ -43,7 +43,7 @@ struct Scanner : Module MIX_OUTPUT, NUM_OUTPUTS }; - enum LightIds + enum LightIds { IN1_LIGHT, IN2_LIGHT, @@ -53,7 +53,7 @@ struct Scanner : Module IN6_LIGHT, IN7_LIGHT, IN8_LIGHT, - + OUT1_POS_LIGHT, OUT1_NEG_LIGHT, OUT2_POS_LIGHT, OUT2_NEG_LIGHT, OUT3_POS_LIGHT, OUT3_NEG_LIGHT, @@ -71,13 +71,13 @@ struct Scanner : Module float inMults[8] = {}; float widthTable[9] = {0, 0, 0, 0.285, 0.285, 0.2608, 0.23523, 0.2125, 0.193}; - Scanner() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) + Scanner() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { - + } void step() override; - + int clampInt(const int _in, const int min = 0, const int max = 7) { if (_in > max) return max; @@ -98,7 +98,7 @@ struct Scanner : Module }; -void Scanner::step() +void Scanner::step() { float allInValue = 0.0f; if(inputs[ALLIN_INPUT].active) allInValue = inputs[ALLIN_INPUT].value; @@ -166,10 +166,10 @@ void Scanner::step() } -ScannerWidget::ScannerWidget() +struct ScannerWidget : ModuleWidget { ScannerWidget(Scanner *module); }; + +ScannerWidget::ScannerWidget(Scanner *module) : ModuleWidget(module) { - auto *module = new Scanner(); - setModule(module); box.size = Vec(18 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -179,32 +179,32 @@ ScannerWidget::ScannerWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); const int knobX = 75; const int jackX = 123; //////PARAMS////// - addParam(createParam(Vec(knobX, 65), module, Scanner::SCAN_PARAM, 0, 5.0, 0.0)); - addInput(createInput(Vec(jackX, 70), module, Scanner::SCAN_INPUT)); + addParam(ParamWidget::create(Vec(knobX, 65), module, Scanner::SCAN_PARAM, 0, 5.0, 0.0)); + addInput(Port::create(Vec(jackX, 70), Port::INPUT, module, Scanner::SCAN_INPUT)); - addParam(createParam(Vec(knobX, 125), module, Scanner::STAGES_PARAM, 0, 6.0, 6.0)); - addInput(createInput(Vec(jackX, 130), module, Scanner::STAGES_INPUT)); + addParam(ParamWidget::create(Vec(knobX, 125), module, Scanner::STAGES_PARAM, 0, 6.0, 6.0)); + addInput(Port::create(Vec(jackX, 130), Port::INPUT, module, Scanner::STAGES_INPUT)); - addParam(createParam(Vec(knobX, 185), module, Scanner::WIDTH_PARAM, 0, 5.0, 0.0)); - addInput(createInput(Vec(jackX, 190), module, Scanner::WIDTH_INPUT)); + addParam(ParamWidget::create(Vec(knobX, 185), module, Scanner::WIDTH_PARAM, 0, 5.0, 0.0)); + addInput(Port::create(Vec(jackX, 190), Port::INPUT, module, Scanner::WIDTH_INPUT)); - addParam(createParam(Vec(knobX, 245), module, Scanner::SLOPE_PARAM, 0, 5.0, 0.0)); - addInput(createInput(Vec(jackX, 250), module, Scanner::SLOPE_INPUT)); + addParam(ParamWidget::create(Vec(knobX, 245), module, Scanner::SLOPE_PARAM, 0, 5.0, 0.0)); + addInput(Port::create(Vec(jackX, 250), Port::INPUT, module, Scanner::SLOPE_INPUT)); - addInput(createInput(Vec(96, 310), module, Scanner::ALLIN_INPUT)); - addOutput(createOutput(Vec(141, 310), module, Scanner::MIX_OUTPUT)); + addInput(Port::create(Vec(96, 310), Port::INPUT, module, Scanner::ALLIN_INPUT)); + addOutput(Port::create(Vec(141, 310), Port::OUTPUT, module, Scanner::MIX_OUTPUT)); - addParam(createParam(Vec(75, 312), module, Scanner::OFFSET_PARAM, 0.0, 1.0, 0.0)); - addParam(createParam(Vec(180, 313), module, Scanner::MIXSCALE_PARAM, 0.0, 1.0, 0.125)); + addParam(ParamWidget::create(Vec(75, 312), module, Scanner::OFFSET_PARAM, 0.0, 1.0, 0.0)); + addParam(ParamWidget::create(Vec(180, 313), module, Scanner::MIXSCALE_PARAM, 0.0, 1.0, 0.125)); const int inXPos = 10; const int inLightX = 50; @@ -218,13 +218,15 @@ ScannerWidget::ScannerWidget() const int lightY = 59 + (40 * i); //////INPUTS////// - addInput(createInput(Vec(inXPos, yPos), module, i)); + addInput(Port::create(Vec(inXPos, yPos), Port::INPUT, module, i)); //////OUTPUTS////// - addOutput(createOutput(Vec(outXPos, yPos), module, i)); + addOutput(Port::create(Vec(outXPos, yPos), Port::OUTPUT, module, i)); //////BLINKENLIGHTS////// - addChild(createLight>(Vec(inLightX, lightY), module, Scanner::IN1_LIGHT + i)); - addChild(createLight>(Vec(outLightX, lightY), module, Scanner::OUT1_POS_LIGHT + 2*i)); + addChild(ModuleLightWidget::create>(Vec(inLightX, lightY), module, Scanner::IN1_LIGHT + i)); + addChild(ModuleLightWidget::create>(Vec(outLightX, lightY), module, Scanner::OUT1_POS_LIGHT + 2*i)); } } + +Model *modelScanner = Model::create("HetrickCV", "Scanner", "Scanner", MIXER_TAG); diff --git a/src/TwoToFour.cpp b/src/TwoToFour.cpp index a8c2472..a26b69e 100644 --- a/src/TwoToFour.cpp +++ b/src/TwoToFour.cpp @@ -1,19 +1,19 @@ #include "HetrickCV.hpp" #include "dsp/digital.hpp" -struct TwoToFour : Module +struct TwoToFour : Module { - enum ParamIds + enum ParamIds { NUM_PARAMS }; - enum InputIds + enum InputIds { INA_INPUT, INB_INPUT, NUM_INPUTS }; - enum OutputIds + enum OutputIds { OUT1_OUTPUT, OUT2_OUTPUT, @@ -22,7 +22,7 @@ struct TwoToFour : Module NUM_OUTPUTS }; - enum LightIds + enum LightIds { OUT1_POS_LIGHT, OUT1_NEG_LIGHT, OUT2_POS_LIGHT, OUT2_NEG_LIGHT, @@ -33,9 +33,9 @@ struct TwoToFour : Module float outs[4] = {}; - TwoToFour() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) + TwoToFour() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) { - + } void step() override; @@ -47,7 +47,7 @@ struct TwoToFour : Module }; -void TwoToFour::step() +void TwoToFour::step() { const float inA = inputs[INA_INPUT].value; const float inB = inputs[INB_INPUT].value; @@ -61,7 +61,7 @@ void TwoToFour::step() outputs[OUT2_OUTPUT].value = outs[1]; outputs[OUT3_OUTPUT].value = outs[2]; outputs[OUT4_OUTPUT].value = outs[3]; - + lights[OUT1_POS_LIGHT].setBrightnessSmooth(fmaxf(0.0, outs[0] / 5.0)); lights[OUT1_NEG_LIGHT].setBrightnessSmooth(fmaxf(0.0, -outs[0] / 5.0)); @@ -75,11 +75,10 @@ void TwoToFour::step() lights[OUT4_NEG_LIGHT].setBrightnessSmooth(fmaxf(0.0, -outs[3] / 5.0)); } +struct TwoToFourWidget : ModuleWidget { TwoToFourWidget(TwoToFour *module); }; -TwoToFourWidget::TwoToFourWidget() +TwoToFourWidget::TwoToFourWidget(TwoToFour *module) : ModuleWidget(module) { - auto *module = new TwoToFour(); - setModule(module); box.size = Vec(6 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -89,21 +88,24 @@ TwoToFourWidget::TwoToFourWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //////PARAMS////// //////INPUTS////// - addInput(createInput(Vec(10, 100), module, TwoToFour::INA_INPUT)); - addInput(createInput(Vec(55, 100), module, TwoToFour::INB_INPUT)); + addInput(Port::create(Vec(10, 100), Port::INPUT, module, TwoToFour::INA_INPUT)); + addInput(Port::create(Vec(55, 100), Port::INPUT, module, TwoToFour::INB_INPUT)); for(int i = 0; i < 4; i++) { const int yPos = i*45; - addOutput(createOutput(Vec(33, 150 + yPos), module, TwoToFour::OUT1_OUTPUT + i)); - addChild(createLight>(Vec(70, 158 + yPos), module, TwoToFour::OUT1_POS_LIGHT + i*2)); + addOutput(Port::create(Vec(33, 150 + yPos), Port::OUTPUT, module, TwoToFour::OUT1_OUTPUT + i)); + addChild(ModuleLightWidget::create>(Vec(70, 158 + yPos), module, TwoToFour::OUT1_POS_LIGHT + i*2)); } } + +Model *modelTwoToFour = Model::create("HetrickCV", "2To4", "2 To 4 Mix Matrix", MIXER_TAG); + diff --git a/src/Waveshape.cpp b/src/Waveshape.cpp index 7b4dae6..4cd0316 100644 --- a/src/Waveshape.cpp +++ b/src/Waveshape.cpp @@ -1,29 +1,29 @@ #include "HetrickCV.hpp" -struct Waveshape : Module +struct Waveshape : Module { - enum ParamIds + enum ParamIds { AMOUNT_PARAM, SCALE_PARAM, RANGE_PARAM, NUM_PARAMS }; - enum InputIds + enum InputIds { MAIN_INPUT, AMOUNT_INPUT, NUM_INPUTS }; - enum OutputIds + enum OutputIds { MAIN_OUTPUT, NUM_OUTPUTS }; - Waveshape() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) + Waveshape() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) { - + } void step() override; @@ -35,7 +35,7 @@ struct Waveshape : Module }; -void Waveshape::step() +void Waveshape::step() { float input = inputs[MAIN_INPUT].value; @@ -55,7 +55,7 @@ void Waveshape::step() if(mode5V) output *= 5.0f; else output *= 10.0f; - + outputs[MAIN_OUTPUT].value = output; } @@ -68,10 +68,11 @@ struct CKSSRot : SVGSwitch, ToggleSwitch { } }; -WaveshapeWidget::WaveshapeWidget() + +struct WaveshapeWidget : ModuleWidget { WaveshapeWidget(Waveshape *module); }; + +WaveshapeWidget::WaveshapeWidget(Waveshape *module) : ModuleWidget(module) { - auto *module = new Waveshape(); - setModule(module); box.size = Vec(6 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); { @@ -81,20 +82,22 @@ WaveshapeWidget::WaveshapeWidget() addChild(panel); } - addChild(createScrew(Vec(15, 0))); - addChild(createScrew(Vec(box.size.x - 30, 0))); - addChild(createScrew(Vec(15, 365))); - addChild(createScrew(Vec(box.size.x - 30, 365))); + addChild(Widget::create(Vec(15, 0))); + addChild(Widget::create(Vec(box.size.x - 30, 0))); + addChild(Widget::create(Vec(15, 365))); + addChild(Widget::create(Vec(box.size.x - 30, 365))); //////PARAMS////// - addParam(createParam(Vec(27, 62), module, Waveshape::AMOUNT_PARAM, -5.0, 5.0, 0.0)); - addParam(createParam(Vec(36, 112), module, Waveshape::SCALE_PARAM, -1.0, 1.0, 1.0)); - addParam(createParam(Vec(35, 200), module, Waveshape::RANGE_PARAM, 0.0, 1.0, 0.0)); + addParam(ParamWidget::create(Vec(27, 62), module, Waveshape::AMOUNT_PARAM, -5.0, 5.0, 0.0)); + addParam(ParamWidget::create(Vec(36, 112), module, Waveshape::SCALE_PARAM, -1.0, 1.0, 1.0)); + addParam(ParamWidget::create(Vec(35, 200), module, Waveshape::RANGE_PARAM, 0.0, 1.0, 0.0)); //////INPUTS////// - addInput(createInput(Vec(33, 235), module, Waveshape::MAIN_INPUT)); - addInput(createInput(Vec(33, 145), module, Waveshape::AMOUNT_INPUT)); + addInput(Port::create(Vec(33, 235), Port::INPUT, module, Waveshape::MAIN_INPUT)); + addInput(Port::create(Vec(33, 145), Port::INPUT, module, Waveshape::AMOUNT_INPUT)); //////OUTPUTS////// - addOutput(createOutput(Vec(33, 285), module, Waveshape::MAIN_OUTPUT)); + addOutput(Port::create(Vec(33, 285), Port::OUTPUT, module, Waveshape::MAIN_OUTPUT)); } + +Model *modelWaveshape = Model::create("HetrickCV", "Waveshaper", "Waveshaper", WAVESHAPER_TAG, DISTORTION_TAG, EFFECT_TAG);