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.

127 lines
4.8KB

  1. #include "plugin.hpp"
  2. struct Blinds : Module {
  3. enum ParamIds {
  4. GAIN1_PARAM,
  5. GAIN2_PARAM,
  6. GAIN3_PARAM,
  7. GAIN4_PARAM,
  8. MOD1_PARAM,
  9. MOD2_PARAM,
  10. MOD3_PARAM,
  11. MOD4_PARAM,
  12. NUM_PARAMS
  13. };
  14. enum InputIds {
  15. IN1_INPUT,
  16. IN2_INPUT,
  17. IN3_INPUT,
  18. IN4_INPUT,
  19. CV1_INPUT,
  20. CV2_INPUT,
  21. CV3_INPUT,
  22. CV4_INPUT,
  23. NUM_INPUTS
  24. };
  25. enum OutputIds {
  26. OUT1_OUTPUT,
  27. OUT2_OUTPUT,
  28. OUT3_OUTPUT,
  29. OUT4_OUTPUT,
  30. NUM_OUTPUTS
  31. };
  32. enum LightIds {
  33. CV1_POS_LIGHT, CV1_NEG_LIGHT,
  34. CV2_POS_LIGHT, CV2_NEG_LIGHT,
  35. CV3_POS_LIGHT, CV3_NEG_LIGHT,
  36. CV4_POS_LIGHT, CV4_NEG_LIGHT,
  37. OUT1_POS_LIGHT, OUT1_NEG_LIGHT,
  38. OUT2_POS_LIGHT, OUT2_NEG_LIGHT,
  39. OUT3_POS_LIGHT, OUT3_NEG_LIGHT,
  40. OUT4_POS_LIGHT, OUT4_NEG_LIGHT,
  41. NUM_LIGHTS
  42. };
  43. Blinds() {
  44. config(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS);
  45. for (int c = 0; c < 4; c++) {
  46. configParam(GAIN1_PARAM + c, -1.0, 1.0, 0.0, string::f("Channel %d gain", c + 1), "%", 0, 100);
  47. configParam(MOD1_PARAM + c, -1.0, 1.0, 0.0, string::f("Channel %d CV amount", c + 1));
  48. configInput(IN1_INPUT + c, string::f("Channel %d", c + 1));
  49. configInput(CV1_INPUT + c, string::f("Channel %d CV", c + 1));
  50. configOutput(OUT1_OUTPUT + c, string::f("Channel %d", c + 1));
  51. }
  52. }
  53. void process(const ProcessArgs& args) override {
  54. float out = 0.0;
  55. for (int i = 0; i < 4; i++) {
  56. float g = params[GAIN1_PARAM + i].getValue();
  57. g += params[MOD1_PARAM + i].getValue() * inputs[CV1_INPUT + i].getVoltage() / 5.0;
  58. g = clamp(g, -2.0f, 2.0f);
  59. lights[CV1_POS_LIGHT + 2 * i].setSmoothBrightness(fmaxf(0.0, g), args.sampleTime);
  60. lights[CV1_NEG_LIGHT + 2 * i].setSmoothBrightness(fmaxf(0.0, -g), args.sampleTime);
  61. out += g * inputs[IN1_INPUT + i].getNormalVoltage(5.0);
  62. lights[OUT1_POS_LIGHT + 2 * i].setSmoothBrightness(fmaxf(0.0, out / 5.0), args.sampleTime);
  63. lights[OUT1_NEG_LIGHT + 2 * i].setSmoothBrightness(fmaxf(0.0, -out / 5.0), args.sampleTime);
  64. if (outputs[OUT1_OUTPUT + i].isConnected()) {
  65. outputs[OUT1_OUTPUT + i].setVoltage(out);
  66. out = 0.0;
  67. }
  68. }
  69. }
  70. };
  71. struct BlindsWidget : ModuleWidget {
  72. BlindsWidget(Blinds* module) {
  73. setModule(module);
  74. setPanel(Svg::load(asset::plugin(pluginInstance, "res/Blinds.svg")));
  75. addChild(createWidget<ScrewSilver>(Vec(15, 0)));
  76. addChild(createWidget<ScrewSilver>(Vec(150, 0)));
  77. addChild(createWidget<ScrewSilver>(Vec(15, 365)));
  78. addChild(createWidget<ScrewSilver>(Vec(150, 365)));
  79. addParam(createParam<Rogan1PSWhite>(Vec(8, 52), module, Blinds::GAIN1_PARAM));
  80. addParam(createParam<Rogan1PSWhite>(Vec(8, 131), module, Blinds::GAIN2_PARAM));
  81. addParam(createParam<Rogan1PSWhite>(Vec(8, 210), module, Blinds::GAIN3_PARAM));
  82. addParam(createParam<Rogan1PSWhite>(Vec(8, 288), module, Blinds::GAIN4_PARAM));
  83. addParam(createParam<Trimpot>(Vec(72, 63), module, Blinds::MOD1_PARAM));
  84. addParam(createParam<Trimpot>(Vec(72, 142), module, Blinds::MOD2_PARAM));
  85. addParam(createParam<Trimpot>(Vec(72, 221), module, Blinds::MOD3_PARAM));
  86. addParam(createParam<Trimpot>(Vec(72, 300), module, Blinds::MOD4_PARAM));
  87. addInput(createInput<PJ301MPort>(Vec(110, 41), module, Blinds::IN1_INPUT));
  88. addInput(createInput<PJ301MPort>(Vec(110, 120), module, Blinds::IN2_INPUT));
  89. addInput(createInput<PJ301MPort>(Vec(110, 198), module, Blinds::IN3_INPUT));
  90. addInput(createInput<PJ301MPort>(Vec(110, 277), module, Blinds::IN4_INPUT));
  91. addInput(createInput<PJ301MPort>(Vec(110, 80), module, Blinds::CV1_INPUT));
  92. addInput(createInput<PJ301MPort>(Vec(110, 159), module, Blinds::CV2_INPUT));
  93. addInput(createInput<PJ301MPort>(Vec(110, 238), module, Blinds::CV3_INPUT));
  94. addInput(createInput<PJ301MPort>(Vec(110, 316), module, Blinds::CV4_INPUT));
  95. addOutput(createOutput<PJ301MPort>(Vec(144, 41), module, Blinds::OUT1_OUTPUT));
  96. addOutput(createOutput<PJ301MPort>(Vec(144, 120), module, Blinds::OUT2_OUTPUT));
  97. addOutput(createOutput<PJ301MPort>(Vec(144, 198), module, Blinds::OUT3_OUTPUT));
  98. addOutput(createOutput<PJ301MPort>(Vec(144, 277), module, Blinds::OUT4_OUTPUT));
  99. addChild(createLight<SmallLight<GreenRedLight>>(Vec(78, 96), module, Blinds::CV1_POS_LIGHT));
  100. addChild(createLight<SmallLight<GreenRedLight>>(Vec(78, 175), module, Blinds::CV2_POS_LIGHT));
  101. addChild(createLight<SmallLight<GreenRedLight>>(Vec(78, 254), module, Blinds::CV3_POS_LIGHT));
  102. addChild(createLight<SmallLight<GreenRedLight>>(Vec(78, 333), module, Blinds::CV4_POS_LIGHT));
  103. addChild(createLight<MediumLight<GreenRedLight>>(Vec(152, 87), module, Blinds::OUT1_POS_LIGHT));
  104. addChild(createLight<MediumLight<GreenRedLight>>(Vec(152, 166), module, Blinds::OUT2_POS_LIGHT));
  105. addChild(createLight<MediumLight<GreenRedLight>>(Vec(152, 245), module, Blinds::OUT3_POS_LIGHT));
  106. addChild(createLight<MediumLight<GreenRedLight>>(Vec(152, 324), module, Blinds::OUT4_POS_LIGHT));
  107. }
  108. };
  109. Model* modelBlinds = createModel<Blinds, BlindsWidget>("Blinds");