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.

94 lines
3.0KB

  1. #include "AudibleInstruments.hpp"
  2. #include <string.h>
  3. struct Shades : Module {
  4. enum ParamIds {
  5. GAIN1_PARAM,
  6. GAIN2_PARAM,
  7. GAIN3_PARAM,
  8. MODE1_PARAM,
  9. MODE2_PARAM,
  10. MODE3_PARAM,
  11. NUM_PARAMS
  12. };
  13. enum InputIds {
  14. IN1_INPUT,
  15. IN2_INPUT,
  16. IN3_INPUT,
  17. NUM_INPUTS
  18. };
  19. enum OutputIds {
  20. OUT1_OUTPUT,
  21. OUT2_OUTPUT,
  22. OUT3_OUTPUT,
  23. NUM_OUTPUTS
  24. };
  25. enum LightIds {
  26. OUT1_POS_LIGHT, OUT1_NEG_LIGHT,
  27. OUT2_POS_LIGHT, OUT2_NEG_LIGHT,
  28. OUT3_POS_LIGHT, OUT3_NEG_LIGHT,
  29. NUM_LIGHTS
  30. };
  31. Shades() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  32. void step() override;
  33. };
  34. void Shades::step() {
  35. float out = 0.0;
  36. for (int i = 0; i < 3; i++) {
  37. float in = inputs[IN1_INPUT + i].normalize(5.0);
  38. if ((int)params[MODE1_PARAM + i].value == 1) {
  39. // attenuverter
  40. in *= 2.0 * params[GAIN1_PARAM + i].value - 1.0;
  41. }
  42. else {
  43. // attenuator
  44. in *= params[GAIN1_PARAM + i].value;
  45. }
  46. out += in;
  47. lights[OUT1_POS_LIGHT + 2*i].setBrightnessSmooth(fmaxf(0.0, out / 5.0));
  48. lights[OUT1_NEG_LIGHT + 2*i].setBrightnessSmooth(fmaxf(0.0, -out / 5.0));
  49. if (outputs[OUT1_OUTPUT + i].active) {
  50. outputs[OUT1_OUTPUT + i].value = out;
  51. out = 0.0;
  52. }
  53. }
  54. }
  55. struct ShadesWidget : ModuleWidget {
  56. ShadesWidget(Shades *module) : ModuleWidget(module) {
  57. setPanel(SVG::load(assetPlugin(plugin, "res/Shades.svg")));
  58. addChild(Widget::create<ScrewSilver>(Vec(15, 0)));
  59. addChild(Widget::create<ScrewSilver>(Vec(15, 365)));
  60. addParam(ParamWidget::create<Rogan1PSRed>(Vec(40, 40), module, Shades::GAIN1_PARAM, 0.0, 1.0, 0.5));
  61. addParam(ParamWidget::create<Rogan1PSWhite>(Vec(40, 106), module, Shades::GAIN2_PARAM, 0.0, 1.0, 0.5));
  62. addParam(ParamWidget::create<Rogan1PSGreen>(Vec(40, 172), module, Shades::GAIN3_PARAM, 0.0, 1.0, 0.5));
  63. addParam(ParamWidget::create<CKSS>(Vec(10, 51), module, Shades::MODE1_PARAM, 0.0, 1.0, 1.0));
  64. addParam(ParamWidget::create<CKSS>(Vec(10, 117), module, Shades::MODE2_PARAM, 0.0, 1.0, 1.0));
  65. addParam(ParamWidget::create<CKSS>(Vec(10, 183), module, Shades::MODE3_PARAM, 0.0, 1.0, 1.0));
  66. addInput(Port::create<PJ301MPort>(Vec(9, 245), Port::INPUT, module, Shades::IN1_INPUT));
  67. addInput(Port::create<PJ301MPort>(Vec(9, 281), Port::INPUT, module, Shades::IN2_INPUT));
  68. addInput(Port::create<PJ301MPort>(Vec(9, 317), Port::INPUT, module, Shades::IN3_INPUT));
  69. addOutput(Port::create<PJ301MPort>(Vec(56, 245), Port::OUTPUT, module, Shades::OUT1_OUTPUT));
  70. addOutput(Port::create<PJ301MPort>(Vec(56, 281), Port::OUTPUT, module, Shades::OUT2_OUTPUT));
  71. addOutput(Port::create<PJ301MPort>(Vec(56, 317), Port::OUTPUT, module, Shades::OUT3_OUTPUT));
  72. addChild(ModuleLightWidget::create<SmallLight<GreenRedLight>>(Vec(41, 254), module, Shades::OUT1_POS_LIGHT));
  73. addChild(ModuleLightWidget::create<SmallLight<GreenRedLight>>(Vec(41, 290), module, Shades::OUT2_POS_LIGHT));
  74. addChild(ModuleLightWidget::create<SmallLight<GreenRedLight>>(Vec(41, 326), module, Shades::OUT3_POS_LIGHT));
  75. }
  76. };
  77. Model *modelShades = Model::create<Shades, ShadesWidget>("Audible Instruments", "Shades", "Mixer", MIXER_TAG);