diff --git a/Makefile b/Makefile index b96662e..eb53375 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,3 @@ -SLUG = mtsch-plugins -VERSION = 0.6.0 - RACK_DIR ?= ../.. # FLAGS will be passed to both the C and C++ compiler FLAGS += diff --git a/src/Rationals.cpp b/src/Rationals.cpp index d2bf3ee..0d02b0d 100644 --- a/src/Rationals.cpp +++ b/src/Rationals.cpp @@ -44,20 +44,24 @@ struct Rationals : Module { }; Rationals() { - config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); + config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); + for (int i = 0; i < NUM_CHANNELS; i++) { + configParam(Rationals::PARAMS + 2*i, 1, MAX_VALUE, 1); + configParam(Rationals::PARAMS + 1 + 2*i, 1, MAX_VALUE, 1); + } } - void step() override; + void process(const ProcessArgs& args) override; char display[4*NUM_CHANNELS]; }; -void Rationals::step() { +void Rationals::process(const ProcessArgs& args) { for (int i = 0; i < NUM_CHANNELS; i++) { - float num_cv = std::round(inputs[INPUTS + 1 + 3*i].value); - float num_par = std::round(params[PARAMS + 2*i].value); - float den_cv = std::round(inputs[INPUTS + 2 + 3*i].value); - float den_par = std::round(params[PARAMS + 1 + 2*i].value); + float num_cv = std::round(inputs[INPUTS + 1 + 3*i].getVoltage()); + float num_par = std::round(params[PARAMS + 2*i].getValue()); + float den_cv = std::round(inputs[INPUTS + 2 + 3*i].getVoltage()); + float den_par = std::round(params[PARAMS + 1 + 2*i].getValue()); float num = num_cv + num_par; float den = den_cv + den_par; @@ -84,7 +88,7 @@ void Rationals::step() { } display[3 + digit_offset] = dig2 + '0'; - outputs[OUTPUTS + i].value = inputs[INPUTS + 3*i].value + log2f(num/den); + outputs[OUTPUTS + i].setVoltage(inputs[INPUTS + 3*i].getVoltage() + log2f(num/den)); } } @@ -98,12 +102,7 @@ RationalsWidget::RationalsWidget(Rationals *module) { box.size = Vec(10 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); - { - SVGPanel *panel = new SVGPanel(); - panel->box.size = box.size; - panel->setBackground(SVG::load(assetPlugin(pluginInstance, "res/Rationals.svg"))); - addChild(panel); - } + setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/Rationals.svg"))); addChild(createWidget(Vec(0, 0))); addChild(createWidget(Vec(0, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); @@ -116,37 +115,27 @@ RationalsWidget::RationalsWidget(Rationals *module) { if (module) { // Numerator digits. - addChild(new DigitDisplay(Vec(digit_x, y_pos + DIGIT_Y_OFFSET), - 5.f, &module->display[0+offset])); - addChild(new DigitDisplay(Vec(digit_x + DIGIT_SPACING, y_pos + DIGIT_Y_OFFSET), - 5.f, &module->display[1+offset])); + addChild(new DigitDisplay(Vec(digit_x, y_pos + DIGIT_Y_OFFSET), 5.f, &module->display[0+offset])); + addChild(new DigitDisplay(Vec(digit_x + DIGIT_SPACING, y_pos + DIGIT_Y_OFFSET), 5.f, &module->display[1+offset])); // Denominator digits. - addChild(new DigitDisplay(Vec(digit_x, y_pos + DIGIT_Y_OFFSET + NUMDEN_SPACING), - 5.f, &module->display[2+offset])); - addChild(new DigitDisplay(Vec(digit_x + DIGIT_SPACING, y_pos + DIGIT_Y_OFFSET + NUMDEN_SPACING), - 5.f, &module->display[3+offset])); + addChild(new DigitDisplay(Vec(digit_x, y_pos + DIGIT_Y_OFFSET + NUMDEN_SPACING), 5.f, &module->display[2+offset])); + addChild(new DigitDisplay(Vec(digit_x + DIGIT_SPACING, y_pos + DIGIT_Y_OFFSET + NUMDEN_SPACING), 5.f, &module->display[3+offset])); } // Numerator knob. - addParam(createParam(Vec(X_POS + KNOB_X_OFFSET, y_pos), - module, Rationals::PARAMS + 2*i, 1, MAX_VALUE, 1)); + addParam(createParam(Vec(X_POS + KNOB_X_OFFSET, y_pos), module, Rationals::PARAMS + 2*i)); // Denominator knob. - addParam(createParam(Vec(X_POS + KNOB_X_OFFSET, y_pos + NUMDEN_SPACING), - module, Rationals::PARAMS + 1 + 2*i, 1, MAX_VALUE, 1)); + addParam(createParam(Vec(X_POS + KNOB_X_OFFSET, y_pos + NUMDEN_SPACING), module, Rationals::PARAMS + 1 + 2*i)); // IO. - addInput(createPort(Vec(X_POS, y_pos + IO_Y_OFFSET), - PortWidget::INPUT, module, Rationals::INPUTS + i*3)); - addOutput(createPort(Vec(X_POS + OUT_X_OFFSET, y_pos + IO_Y_OFFSET), - PortWidget::OUTPUT, module, Rationals::OUTPUTS + i)); + addInput(createInput(Vec(X_POS, y_pos + IO_Y_OFFSET), module, Rationals::INPUTS + i*3)); + addOutput(createOutput(Vec(X_POS + OUT_X_OFFSET, y_pos + IO_Y_OFFSET), module, Rationals::OUTPUTS + i)); } // CV mod grid. for (int i = 0; i < NUM_CHANNELS; i++) { - addInput(createPort(Vec(GRID_X_POS + i*GRID_SPACING, GRID_Y_POS), - PortWidget::INPUT, module, Rationals::INPUTS + 1 + i*3)); - addInput(createPort(Vec(GRID_X_POS + i*GRID_SPACING, GRID_Y_POS + GRID_SPACING), - PortWidget::INPUT, module, Rationals::INPUTS + 2 + i*3)); + addInput(createInput(Vec(GRID_X_POS + i*GRID_SPACING, GRID_Y_POS), module, Rationals::INPUTS + 1 + i*3)); + addInput(createInput(Vec(GRID_X_POS + i*GRID_SPACING, GRID_Y_POS + GRID_SPACING), module, Rationals::INPUTS + 2 + i*3)); } } diff --git a/src/Sum.cpp b/src/Sum.cpp index 28a9807..d27461b 100644 --- a/src/Sum.cpp +++ b/src/Sum.cpp @@ -27,19 +27,22 @@ struct Sum : Module { }; Sum() { - config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); + config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); + for (int i = 0; i < NUM_CHANNELS; i++) { + configParam(Sum::PARAMS + i, -1, 1, 1); + } } - void step() override; + void process(const ProcessArgs& args) override; }; -void Sum::step() { +void Sum::process(const ProcessArgs& args) { float acc = 0; for (int i = 0; i < NUM_CHANNELS; i++) { - acc += inputs[INPUTS + i].value * params[PARAMS + i].value; + acc += inputs[INPUTS + i].getVoltage() * params[PARAMS + i].getValue(); } - outputs[OUTPUT].value = acc; + outputs[OUTPUT].setVoltage(acc); } struct SumWidget : ModuleWidget { @@ -50,24 +53,17 @@ SumWidget::SumWidget(Sum *module) { setModule(module); box.size = Vec(4 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); - { - SVGPanel *panel = new SVGPanel(); - panel->box.size = box.size; - panel->setBackground(SVG::load(assetPlugin(pluginInstance, "res/Sum.svg"))); - addChild(panel); - } + setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/Sum.svg"))); addChild(createWidget(Vec(0, 0))); addChild(createWidget(Vec(0, RACK_GRID_HEIGHT - RACK_GRID_WIDTH))); for (int i = 0; i < NUM_CHANNELS; i++) { - addInput(createPort(Vec(X_POSITION, Y_INPUT_POSITION + i * SPACING), - PortWidget::INPUT, module, Sum::INPUTS + i)); - addParam(createParam(Vec(X_POSITION + 30, Y_INPUT_POSITION + i * SPACING), - module, Sum::PARAMS + i, -1, 1, 1)); + addInput(createInput(Vec(X_POSITION, Y_INPUT_POSITION + i * SPACING), module, Sum::INPUTS + i)); + addParam(createParam(Vec(X_POSITION + 30, Y_INPUT_POSITION + i * SPACING), module, Sum::PARAMS + i)); } - addOutput(createPort(Vec(X_POSITION, Y_OUTPUT_POSITION), PortWidget::OUTPUT, module, Sum::OUTPUT)); + addOutput(createOutput(Vec(X_POSITION, Y_OUTPUT_POSITION), module, Sum::OUTPUT)); } diff --git a/src/TriggerPanic.cpp b/src/TriggerPanic.cpp index ef40153..72b079e 100644 --- a/src/TriggerPanic.cpp +++ b/src/TriggerPanic.cpp @@ -82,43 +82,48 @@ struct TriggerPanic : Module { NUM_LIGHTS }; - SchmittTrigger trigger; - SchmittTrigger panic; - SchmittTrigger clear; + dsp::SchmittTrigger trigger; + dsp::SchmittTrigger panic; + dsp::SchmittTrigger clear; float *buff; int current_i; int buff_len; TriggerPanic() { - config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); - buff_len = BUFFER_LENGTH * engineGetSampleRate(); - buff = new float[buff_len]; + config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS); + configParam(TriggerPanic::PANIC_BUTTON, 0, 1, 0); + configParam(TriggerPanic::MIX_KNOB, 0, 1, 0.5); + configParam(TriggerPanic::MIX_CV_AMT, -1, 1, 0); + configParam(TriggerPanic::FEEDBACK_KNOB, 0, 1, 0.5); + configParam(TriggerPanic::FEEDBACK_CV_AMT, -1, 1, 0); + buff_len = BUFFER_LENGTH * APP->engine->getSampleRate(); + buff = new float[buff_len]; } - void onReset() { // override + void onReset() override { for (int i = 0; i < buff_len; i++) { buff[i] = 0; } current_i = 0; } - void step() override; + void process(const ProcessArgs& args) override; }; -void TriggerPanic::step() { +void TriggerPanic::process(const ProcessArgs& args) { // TODO: cv control // panic button // gui // Reset on trigger. - if (trigger.process(inputs[TRIGGER_IN].value)) { + if (trigger.process(inputs[TRIGGER_IN].getVoltage())) { current_i = 0; } // Panic button. - if (panic.process(params[PANIC_BUTTON].value)) { + if (panic.process(params[PANIC_BUTTON].getValue())) { onReset(); - outputs[AUDIO_OUT].value = 0; - outputs[AUX_OUT].value = 0; + outputs[AUDIO_OUT].setVoltage(0); + outputs[AUX_OUT].setVoltage(0); return; } @@ -127,33 +132,33 @@ void TriggerPanic::step() { // Get feedback amount value. float feedback_amt = - clamp(params[FEEDBACK_KNOB].value + - inputs[FEEDBACK_CV].value/5 * params[FEEDBACK_CV_AMT].value, + clamp(params[FEEDBACK_KNOB].getValue() + + inputs[FEEDBACK_CV].getVoltage()/5 * params[FEEDBACK_CV_AMT].getValue(), 0.0f, 1.0f); // Direct feedback when AUX_IN or AUX_OUT are disconnected. float feedback; - if (inputs[AUX_IN].active && outputs[AUX_OUT].active) { + if (inputs[AUX_IN].isConnected() && outputs[AUX_OUT].isConnected()) { lights[AUX_ACTIVE_LIGHT].value = 0; - outputs[AUX_OUT].value = buff[current_i]; - feedback = inputs[AUX_IN].value * feedback_amt; + outputs[AUX_OUT].setVoltage(buff[current_i]); + feedback = inputs[AUX_IN].getVoltage() * feedback_amt; } else { lights[AUX_ACTIVE_LIGHT].value = 1; - outputs[AUX_OUT].value = buff[current_i]; - feedback = (inputs[AUX_IN].value + buff[current_i]) * feedback_amt; + outputs[AUX_OUT].setVoltage(buff[current_i]); + feedback = (inputs[AUX_IN].getVoltage() + buff[current_i]) * feedback_amt; } float mix = - clamp(params[MIX_KNOB].value + - (params[MIX_CV_AMT].value * inputs[MIX_CV].value/5), + clamp(params[MIX_KNOB].getValue() + + (params[MIX_CV_AMT].getValue() * inputs[MIX_CV].getVoltage()/5), 0.0f, 1.0f); - outputs[AUDIO_OUT].value = (1-mix)*inputs[AUDIO_IN].value + mix*buff[current_i]; + outputs[AUDIO_OUT].setVoltage((1-mix)*inputs[AUDIO_IN].getVoltage() + mix*buff[current_i]); - buff[current_i] = clamp(inputs[AUDIO_IN].value + feedback, -5.0f, 5.0f); + buff[current_i] = clamp(inputs[AUDIO_IN].getVoltage() + feedback, -5.0f, 5.0f); current_i++; } else { lights[BUFF_FULL_LIGHT].value = 1; - outputs[AUDIO_OUT].value = 0; + outputs[AUDIO_OUT].setVoltage(0); } } @@ -165,57 +170,38 @@ TriggerPanicWidget::TriggerPanicWidget(TriggerPanic *module) { setModule(module); box.size = Vec(10 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT); - { - SVGPanel *panel = new SVGPanel(); - panel->box.size = box.size; - panel->setBackground(SVG::load(assetPlugin(pluginInstance, "res/TriggerPanic.svg"))); - addChild(panel); - } + setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/TriggerPanic.svg"))); addChild(createWidget(Vec(15, 0))); - addChild(createWidget(Vec(box.size.x-30, 0))); - addChild(createWidget(Vec(15, 365))); - addChild(createWidget(Vec(box.size.x-30, 365))); + addChild(createWidget(Vec(box.size.x-30, 0))); + addChild(createWidget(Vec(15, 365))); + addChild(createWidget(Vec(box.size.x-30, 365))); // Trigger in. - addInput(createPort(Vec(TRIGGER_X, TRIGGER_Y), - PortWidget::INPUT, module, TriggerPanic::TRIGGER_IN)); + addInput(createInput(Vec(TRIGGER_X, TRIGGER_Y), module, TriggerPanic::TRIGGER_IN)); // Panic. - addParam(createParam(Vec(PANIC_X, PANIC_Y), - module, TriggerPanic::PANIC_BUTTON, 0, 1, 0)); - addChild(createLight>(Vec(BUFF_X, BUFF_Y), - module, TriggerPanic::BUFF_FULL_LIGHT)); + addParam(createParam(Vec(PANIC_X, PANIC_Y), module, TriggerPanic::PANIC_BUTTON)); + addChild(createLight>(Vec(BUFF_X, BUFF_Y), module, TriggerPanic::BUFF_FULL_LIGHT)); // Mix. - addParam(createParam(Vec(MIX_GROUP_X, MIX_GROUP_Y), - module, TriggerPanic::MIX_KNOB, 0, 1, 0.5)); - addParam(createParam(Vec(MIX_GROUP_X + MF_GROUP_CV_AMT_X, MIX_GROUP_Y + MF_GROUP_CV_AMT_Y), - module, TriggerPanic::MIX_CV_AMT, -1, 1, 0)); - addInput(createPort(Vec(MIX_GROUP_X + MF_GROUP_CV_IN_X, MIX_GROUP_Y + MF_GROUP_CV_IN_Y), - PortWidget::INPUT, module, TriggerPanic::MIX_CV)); + addParam(createParam(Vec(MIX_GROUP_X, MIX_GROUP_Y), module, TriggerPanic::MIX_KNOB)); + addParam(createParam(Vec(MIX_GROUP_X + MF_GROUP_CV_AMT_X, MIX_GROUP_Y + MF_GROUP_CV_AMT_Y), module, TriggerPanic::MIX_CV_AMT)); + addInput(createInput(Vec(MIX_GROUP_X + MF_GROUP_CV_IN_X, MIX_GROUP_Y + MF_GROUP_CV_IN_Y), module, TriggerPanic::MIX_CV)); // Feedback. - addParam(createParam(Vec(FB_GROUP_X, FB_GROUP_Y), - module, TriggerPanic::FEEDBACK_KNOB, 0, 1, 0.5)); - addParam(createParam(Vec(FB_GROUP_X + MF_GROUP_CV_AMT_X, FB_GROUP_Y + MF_GROUP_CV_AMT_Y), - module, TriggerPanic::FEEDBACK_CV_AMT, -1, 1, 0)); - addInput(createPort(Vec(FB_GROUP_X + MF_GROUP_CV_IN_X, FB_GROUP_Y + MF_GROUP_CV_IN_Y), - PortWidget::INPUT, module, TriggerPanic::FEEDBACK_CV)); + addParam(createParam(Vec(FB_GROUP_X, FB_GROUP_Y), module, TriggerPanic::FEEDBACK_KNOB)); + addParam(createParam(Vec(FB_GROUP_X + MF_GROUP_CV_AMT_X, FB_GROUP_Y + MF_GROUP_CV_AMT_Y), module, TriggerPanic::FEEDBACK_CV_AMT)); + addInput(createInput(Vec(FB_GROUP_X + MF_GROUP_CV_IN_X, FB_GROUP_Y + MF_GROUP_CV_IN_Y), module, TriggerPanic::FEEDBACK_CV)); // Aux IO. - addInput(createPort(Vec(AUX_X, AUX_Y), - PortWidget::INPUT, module, TriggerPanic::AUX_IN)); - addChild(createLight>(Vec(AUX_LIGHT_X, AUX_LIGHT_Y), - module, TriggerPanic::AUX_ACTIVE_LIGHT)); - addOutput(createPort(Vec(AUX_OUT_X, AUX_Y), - PortWidget::OUTPUT, module, TriggerPanic::AUX_OUT)); + addInput(createInput(Vec(AUX_X, AUX_Y), module, TriggerPanic::AUX_IN)); + addChild(createLight>(Vec(AUX_LIGHT_X, AUX_LIGHT_Y), module, TriggerPanic::AUX_ACTIVE_LIGHT)); + addOutput(createOutput(Vec(AUX_OUT_X, AUX_Y), module, TriggerPanic::AUX_OUT)); // Audio IO. - addInput(createPort(Vec(AUDIO_IN_X, AUDIO_IO_Y), - PortWidget::INPUT, module, TriggerPanic::AUDIO_IN)); - addOutput(createPort(Vec(AUDIO_OUT_X, AUDIO_IO_Y), - PortWidget::OUTPUT, module, TriggerPanic::AUDIO_OUT)); + addInput(createInput(Vec(AUDIO_IN_X, AUDIO_IO_Y), module, TriggerPanic::AUDIO_IN)); + addOutput(createOutput(Vec(AUDIO_OUT_X, AUDIO_IO_Y), module, TriggerPanic::AUDIO_OUT)); } diff --git a/src/mtsch.hpp b/src/mtsch.hpp index 1218748..3e0733d 100644 --- a/src/mtsch.hpp +++ b/src/mtsch.hpp @@ -1,4 +1,4 @@ -#include "rack0.hpp" +#include "rack.hpp" using namespace rack;