From c4801ac7feca2a9006143e397ee1c60ba1f1d9e7 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Fri, 14 Oct 2022 11:23:43 -0400 Subject: [PATCH] The basics of a plugin! --- .gitignore | 6 +++ Makefile | 23 ++++++++++++ plugin.json | 25 +++++++++++++ res/module.svg | 100 +++++++++++++++++++++++++++++++++++++++++++++++++ src/module.cpp | 55 +++++++++++++++++++++++++++ src/plugin.cpp | 15 ++++++++ src/plugin.hpp | 11 ++++++ 7 files changed, 235 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 plugin.json create mode 100644 res/module.svg create mode 100644 src/module.cpp create mode 100644 src/plugin.cpp create mode 100644 src/plugin.hpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..abde234 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/build +/dist +/plugin.so +/plugin.dylib +/plugin.dll +.DS_Store diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..07b5733 --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +# If RACK_DIR is not defined when calling the Makefile, default to two directories above +RACK_DIR ?= ../.. + +# FLAGS will be passed to both the C and C++ compiler +FLAGS += +CFLAGS += +CXXFLAGS += + +# Careful about linking to shared libraries, since you can't assume much about the user's environment and library search path. +# Static libraries are fine, but they should be added to this plugin's build system. +LDFLAGS += + +# Add .cpp files to the build +SOURCES += $(wildcard src/*.cpp) + +# Add files to the ZIP package when running `make dist` +# The compiled plugin and "plugin.json" are automatically added. +DISTRIBUTABLES += res +DISTRIBUTABLES += $(wildcard LICENSE*) +DISTRIBUTABLES += $(wildcard presets) + +# Include the Rack plugin Makefile framework +include $(RACK_DIR)/plugin.mk diff --git a/plugin.json b/plugin.json new file mode 100644 index 0000000..bda9d65 --- /dev/null +++ b/plugin.json @@ -0,0 +1,25 @@ +{ + "slug": "a10u8r_plugin", + "name": "A10U8R", + "version": "2.0.0", + "license": "GPL-2.0-or-later", + "brand": "ewpratten", + "author": "Evan Pratten", + "authorEmail": "contact@ewpratten.com", + "authorUrl": "https://ewpratten.com", + "pluginUrl": "https://ewpratten.com/products/vcvrack/a10u8r", + "manualUrl": "", + "sourceUrl": "https://github.com/ewpratten/A10U8R", + "donateUrl": "https://ewpratten.com/donate", + "changelogUrl": "", + "modules": [ + { + "slug": "a10u8r_module", + "name": "a10u8r_module", + "description": "A simple, hacky, attenuator", + "tags": [ + "Attenuator" + ] + } + ] +} \ No newline at end of file diff --git a/res/module.svg b/res/module.svg new file mode 100644 index 0000000..68121cd --- /dev/null +++ b/res/module.svg @@ -0,0 +1,100 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/src/module.cpp b/src/module.cpp new file mode 100644 index 0000000..65942b7 --- /dev/null +++ b/src/module.cpp @@ -0,0 +1,55 @@ +#include "plugin.hpp" + + +struct A10u8r_module : Module { + enum ParamId { + VALUE_PARAM, + PARAMS_LEN + }; + enum InputId { + INPUT_INPUT, + INPUTS_LEN + }; + enum OutputId { + OUTPUT_OUTPUT, + OUTPUTS_LEN + }; + enum LightId { + LIGHTS_LEN + }; + + A10u8r_module() { + config(PARAMS_LEN, INPUTS_LEN, OUTPUTS_LEN, LIGHTS_LEN); + configParam(VALUE_PARAM, 0.f, 1.f, 0.f, ""); + configInput(INPUT_INPUT, ""); + configOutput(OUTPUT_OUTPUT, ""); + } + + void process(const ProcessArgs& args) override { + float value = params[VALUE_PARAM].getValue(); + float input = inputs[INPUT_INPUT].getVoltage(); + outputs[OUTPUT_OUTPUT].setVoltage(value * input); + } +}; + + +struct A10u8r_moduleWidget : ModuleWidget { + A10u8r_moduleWidget(A10u8r_module* module) { + setModule(module); + setPanel(createPanel(asset::plugin(pluginInstance, "res/a10u8r_module.svg"))); + + addChild(createWidget(Vec(RACK_GRID_WIDTH, 0))); + addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0))); + addChild(createWidget(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); + addChild(createWidget(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); + + addParam(createParamCentered(mm2px(Vec(15.24, 64.25)), module, A10u8r_module::VALUE_PARAM)); + + addInput(createInputCentered(mm2px(Vec(15.24, 25.81)), module, A10u8r_module::INPUT_INPUT)); + + addOutput(createOutputCentered(mm2px(Vec(15.24, 110.491)), module, A10u8r_module::OUTPUT_OUTPUT)); + } +}; + + +Model* modelA10u8r_module = createModel("a10u8r_module"); \ No newline at end of file diff --git a/src/plugin.cpp b/src/plugin.cpp new file mode 100644 index 0000000..dc08710 --- /dev/null +++ b/src/plugin.cpp @@ -0,0 +1,15 @@ +#include "plugin.hpp" + + +Plugin* pluginInstance; + + +void init(Plugin* p) { + pluginInstance = p; + + // Add modules here + p->addModel(modelA10u8r_module); + + // Any other plugin initialization may go here. + // As an alternative, consider lazy-loading assets and lookup tables when your module is created to reduce startup times of Rack. +} diff --git a/src/plugin.hpp b/src/plugin.hpp new file mode 100644 index 0000000..178736f --- /dev/null +++ b/src/plugin.hpp @@ -0,0 +1,11 @@ +#pragma once +#include + + +using namespace rack; + +// Declare the Plugin, defined in plugin.cpp +extern Plugin* pluginInstance; + +// Declare each Model, defined in each module source file +extern Model* modelA10u8r_module;