You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.2KB

  1. #include "plugin.hpp"
  2. struct Shades : Module {
  3. enum ParamIds {
  4. GAIN1_PARAM,
  5. GAIN2_PARAM,
  6. GAIN3_PARAM,
  7. MODE1_PARAM,
  8. MODE2_PARAM,
  9. MODE3_PARAM,
  10. NUM_PARAMS
  11. };
  12. enum InputIds {
  13. IN1_INPUT,
  14. IN2_INPUT,
  15. IN3_INPUT,
  16. NUM_INPUTS
  17. };
  18. enum OutputIds {
  19. OUT1_OUTPUT,
  20. OUT2_OUTPUT,
  21. OUT3_OUTPUT,
  22. NUM_OUTPUTS
  23. };
  24. enum LightIds {
  25. OUT1_POS_LIGHT, OUT1_NEG_LIGHT,
  26. OUT2_POS_LIGHT, OUT2_NEG_LIGHT,
  27. OUT3_POS_LIGHT, OUT3_NEG_LIGHT,
  28. NUM_LIGHTS
  29. };
  30. Shades() {
  31. config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
  32. configParam(GAIN1_PARAM, 0.0, 1.0, 0.5, "Gain 1");
  33. configParam(GAIN2_PARAM, 0.0, 1.0, 0.5, "Gain 2");
  34. configParam(GAIN3_PARAM, 0.0, 1.0, 0.5, "Gain 3");
  35. configParam(MODE1_PARAM, 0.0, 1.0, 1.0, "Attenuverter/Attenuator mode 1");
  36. configParam(MODE2_PARAM, 0.0, 1.0, 1.0, "Attenuverter/Attenuator mode 2");
  37. configParam(MODE3_PARAM, 0.0, 1.0, 1.0, "Attenuverter/Attenuator mode 3");
  38. }
  39. void process(const ProcessArgs& args) override {
  40. float out = 0.0;
  41. for (int i = 0; i < 3; i++) {
  42. float in = inputs[IN1_INPUT + i].getNormalVoltage(5.0);
  43. if ((int)params[MODE1_PARAM + i].getValue() == 1) {
  44. // attenuverter
  45. in *= 2.0 * params[GAIN1_PARAM + i].getValue() - 1.0;
  46. }
  47. else {
  48. // attenuator
  49. in *= params[GAIN1_PARAM + i].getValue();
  50. }
  51. out += in;
  52. lights[OUT1_POS_LIGHT + 2 * i].setSmoothBrightness(fmaxf(0.0, out / 5.0), args.sampleTime);
  53. lights[OUT1_NEG_LIGHT + 2 * i].setSmoothBrightness(fmaxf(0.0, -out / 5.0), args.sampleTime);
  54. if (outputs[OUT1_OUTPUT + i].isConnected()) {
  55. outputs[OUT1_OUTPUT + i].setVoltage(out);
  56. out = 0.0;
  57. }
  58. }
  59. }
  60. };
  61. struct ShadesWidget : ModuleWidget {
  62. ShadesWidget(Shades* module) {
  63. setModule(module);
  64. setPanel(APP->window->loadSvg(asset::plugin(pluginInstance, "res/Shades.svg")));
  65. addChild(createWidget<ScrewSilver>(Vec(15, 0)));
  66. addChild(createWidget<ScrewSilver>(Vec(15, 365)));
  67. addParam(createParam<Rogan1PSRed>(Vec(40, 40), module, Shades::GAIN1_PARAM));
  68. addParam(createParam<Rogan1PSWhite>(Vec(40, 106), module, Shades::GAIN2_PARAM));
  69. addParam(createParam<Rogan1PSGreen>(Vec(40, 172), module, Shades::GAIN3_PARAM));
  70. addParam(createParam<CKSS>(Vec(10, 51), module, Shades::MODE1_PARAM));
  71. addParam(createParam<CKSS>(Vec(10, 117), module, Shades::MODE2_PARAM));
  72. addParam(createParam<CKSS>(Vec(10, 183), module, Shades::MODE3_PARAM));
  73. addInput(createInput<PJ301MPort>(Vec(9, 245), module, Shades::IN1_INPUT));
  74. addInput(createInput<PJ301MPort>(Vec(9, 281), module, Shades::IN2_INPUT));
  75. addInput(createInput<PJ301MPort>(Vec(9, 317), module, Shades::IN3_INPUT));
  76. addOutput(createOutput<PJ301MPort>(Vec(56, 245), module, Shades::OUT1_OUTPUT));
  77. addOutput(createOutput<PJ301MPort>(Vec(56, 281), module, Shades::OUT2_OUTPUT));
  78. addOutput(createOutput<PJ301MPort>(Vec(56, 317), module, Shades::OUT3_OUTPUT));
  79. addChild(createLight<SmallLight<GreenRedLight>>(Vec(41, 254), module, Shades::OUT1_POS_LIGHT));
  80. addChild(createLight<SmallLight<GreenRedLight>>(Vec(41, 290), module, Shades::OUT2_POS_LIGHT));
  81. addChild(createLight<SmallLight<GreenRedLight>>(Vec(41, 326), module, Shades::OUT3_POS_LIGHT));
  82. }
  83. };
  84. Model* modelShades = createModel<Shades, ShadesWidget>("Shades");