#include "Befaco.hpp" #include "dsp/functions.hpp" struct ABC : Module { enum ParamIds { B1_LEVEL_PARAM, C1_LEVEL_PARAM, B2_LEVEL_PARAM, C2_LEVEL_PARAM, NUM_PARAMS }; enum InputIds { A1_INPUT, B1_INPUT, C1_INPUT, A2_INPUT, B2_INPUT, C2_INPUT, NUM_INPUTS }; enum OutputIds { OUT1_OUTPUT, OUT2_OUTPUT, NUM_OUTPUTS }; enum LightIds { OUT1_POS_LIGHT, OUT1_NEG_LIGHT, OUT2_POS_LIGHT, OUT2_NEG_LIGHT, NUM_LIGHTS }; ABC() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {} void step() override; }; static float clip(float x) { x = clamp(x, -2.0f, 2.0f); return x / powf(1.0 + powf(x, 24.0), 1/24.0); } void ABC::step() { float a1 = inputs[A1_INPUT].value; float b1 = inputs[B1_INPUT].normalize(5.0) * 2.0*exponentialBipolar(80.0, params[B1_LEVEL_PARAM].value); float c1 = inputs[C1_INPUT].normalize(10.0) * exponentialBipolar(80.0, params[C1_LEVEL_PARAM].value); float out1 = a1 * b1 / 5.0 + c1; float a2 = inputs[A2_INPUT].value; float b2 = inputs[B2_INPUT].normalize(5.0) * 2.0*exponentialBipolar(80.0, params[B2_LEVEL_PARAM].value); float c2 = inputs[C2_INPUT].normalize(10.0) * exponentialBipolar(80.0, params[C2_LEVEL_PARAM].value); float out2 = a2 * b2 / 5.0 + c2; // Set outputs if (outputs[OUT1_OUTPUT].active) { outputs[OUT1_OUTPUT].value = clip(out1 / 10.0) * 10.0; } else { out2 += out1; } if (outputs[OUT2_OUTPUT].active) { outputs[OUT2_OUTPUT].value = clip(out2 / 10.0) * 10.0; } // Lights lights[OUT1_POS_LIGHT].value = fmaxf(0.0, out1 / 5.0); lights[OUT1_NEG_LIGHT].value = fmaxf(0.0, -out1 / 5.0); lights[OUT2_POS_LIGHT].value = fmaxf(0.0, out2 / 5.0); lights[OUT2_NEG_LIGHT].value = fmaxf(0.0, -out2 / 5.0); } struct ABCWidget : ModuleWidget { ABCWidget(ABC *module) : ModuleWidget(module) { setPanel(SVG::load(assetPlugin(plugin, "res/ABC.svg"))); addChild(createWidget(Vec(15, 0))); addChild(createWidget(Vec(15, 365))); addParam(createParam(Vec(45, 37), module, ABC::B1_LEVEL_PARAM, -1.0, 1.0, 0.0)); addParam(createParam(Vec(45, 107), module, ABC::C1_LEVEL_PARAM, -1.0, 1.0, 0.0)); addParam(createParam(Vec(45, 204), module, ABC::B2_LEVEL_PARAM, -1.0, 1.0, 0.0)); addParam(createParam(Vec(45, 274), module, ABC::C2_LEVEL_PARAM, -1.0, 1.0, 0.0)); addInput(createPort(Vec(7, 28), PortWidget::INPUT, module, ABC::A1_INPUT)); addInput(createPort(Vec(7, 70), PortWidget::INPUT, module, ABC::B1_INPUT)); addInput(createPort(Vec(7, 112), PortWidget::INPUT, module, ABC::C1_INPUT)); addOutput(createPort(Vec(7, 154), PortWidget::OUTPUT, module, ABC::OUT1_OUTPUT)); addInput(createPort(Vec(7, 195), PortWidget::INPUT, module, ABC::A2_INPUT)); addInput(createPort(Vec(7, 237), PortWidget::INPUT, module, ABC::B2_INPUT)); addInput(createPort(Vec(7, 279), PortWidget::INPUT, module, ABC::C2_INPUT)); addOutput(createPort(Vec(7, 321), PortWidget::OUTPUT, module, ABC::OUT2_OUTPUT)); addChild(createLight>(Vec(37, 162), module, ABC::OUT1_POS_LIGHT)); addChild(createLight>(Vec(37, 329), module, ABC::OUT2_POS_LIGHT)); } }; Model *modelABC = createModel("ABC");