Here is the code (I deleted all my wrong attempts)
#include "plugin.hpp"
struct Deviat5 : Module {
enum ParamId {
SEL1_PARAM,
SEL2_PARAM,
SEL3_PARAM,
SEL4_PARAM,
SEL5_PARAM,
PARAMS_LEN
};
enum InputId {
IN_INPUT,
INPUTS_LEN
};
enum OutputId {
OUT1_OUTPUT,
OUT2_OUTPUT,
OUT3_OUTPUT,
OUT4_OUTPUT,
OUT5_OUTPUT,
MAIN_OUTPUT,
OUTPUTS_LEN
};
enum LightId {
LIGHTS_LEN
};
//edit channels = 5
int channels = 16;
//edit lastChannels 0
int lastChannels = 0;
Deviat5() {
config(PARAMS_LEN, INPUTS_LEN, OUTPUTS_LEN, LIGHTS_LEN);
configParam(SEL1_PARAM, 0.f, 15.f, 0.f, "Channel Selector 1");
configParam(SEL2_PARAM, 0.f, 15.f, 0.f, "Channel Selector 2");
configParam(SEL3_PARAM, 0.f, 15.f, 0.f, "Channel Selector 3");
configParam(SEL4_PARAM, 0.f, 15.f, 0.f, "Channel Selector 4");
configParam(SEL5_PARAM, 0.f, 15.f, 0.f, "Channel Selector 5");
configInput(IN_INPUT, "Polyphonic");
configOutput(OUT1_OUTPUT, "Output 1");
configOutput(OUT2_OUTPUT, "Output 2");
configOutput(OUT3_OUTPUT, "Output 3");
configOutput(OUT4_OUTPUT, "Output 4");
configOutput(OUT5_OUTPUT, "Output 5");
configOutput(MAIN_OUTPUT, "Main");
}
void process(const ProcessArgs& args) override {
lastChannels = inputs[IN_INPUT].getChannels();
for (int c = 0; c < 5; c++) {
float v = inputs[IN_INPUT].getVoltage(c);
outputs[OUT1_OUTPUT + c].setVoltage(v);
outputs[MAIN_OUTPUT].setVoltage(v, c);
}
int automaticChannels = 5;
automaticChannels = lastChannels;
outputs[MAIN_OUTPUT].channels = (channels >= 0) ? channels : automaticChannels;
}
};
struct Deviat5Widget : ModuleWidget {
Deviat5Widget(Deviat5* module) {
setModule(module);
setPanel(createPanel(asset::plugin(pluginInstance, "res/Deviat5.svg")));
addChild(createWidget<DR4Screw>(Vec(RACK_GRID_WIDTH, 0)));
addChild(createWidget<DR4Screw>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
addChild(createWidget<DR4Screw>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
addChild(createWidget<DR4Screw>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
addParam(createParamCentered<DR4KnobSnap>(mm2px(Vec(9.884, 32.999)), module, Deviat5::SEL1_PARAM));
addParam(createParamCentered<DR4KnobSnap>(mm2px(Vec(9.884, 47.405)), module, Deviat5::SEL2_PARAM));
addParam(createParamCentered<DR4KnobSnap>(mm2px(Vec(9.884, 61.81)), module, Deviat5::SEL3_PARAM));
addParam(createParamCentered<DR4KnobSnap>(mm2px(Vec(9.884, 76.216)), module, Deviat5::SEL4_PARAM));
addParam(createParamCentered<DR4KnobSnap>(mm2px(Vec(9.884, 90.621)), module, Deviat5::SEL5_PARAM));
addInput(createInputCentered<DR4Port>(mm2px(Vec(8.909, 113.653)), module, Deviat5::IN_INPUT));
addOutput(createOutputCentered<DR4Port>(mm2px(Vec(26.652, 32.999)), module, Deviat5::OUT1_OUTPUT));
addOutput(createOutputCentered<DR4Port>(mm2px(Vec(26.652, 47.405)), module, Deviat5::OUT2_OUTPUT));
addOutput(createOutputCentered<DR4Port>(mm2px(Vec(26.652, 61.81)), module, Deviat5::OUT3_OUTPUT));
addOutput(createOutputCentered<DR4Port>(mm2px(Vec(26.652, 76.216)), module, Deviat5::OUT4_OUTPUT));
addOutput(createOutputCentered<DR4Port>(mm2px(Vec(26.652, 90.621)), module, Deviat5::OUT5_OUTPUT));
addOutput(createOutputCentered<DR4Port>(mm2px(Vec(26.652, 113.653)), module, Deviat5::MAIN_OUTPUT));
}
};
Model* modelDeviat5 = createModel<Deviat5, Deviat5Widget>("Deviat5");