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.

107 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. float lights[3] = {};
  26. Shades() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS) {}
  27. void step() override;
  28. };
  29. static float getChannelOutput(Input &in, Param &gain, Param &mode) {
  30. float out = in.normalize(5.0);
  31. if ((int)roundf(mode.value) == 1) {
  32. // attenuverter
  33. out *= 2.0*gain.value - 1.0;
  34. }
  35. else {
  36. // attenuator
  37. out *= gain.value;
  38. }
  39. return out;
  40. }
  41. void Shades::step() {
  42. float out = 0.0;
  43. out += getChannelOutput(inputs[IN1_INPUT], params[GAIN1_PARAM], params[MODE1_PARAM]);
  44. lights[0] = out / 5.0;
  45. if (outputs[OUT1_OUTPUT].active) {
  46. outputs[OUT1_OUTPUT].value = out;
  47. out = 0.0;
  48. }
  49. out += getChannelOutput(inputs[IN2_INPUT], params[GAIN2_PARAM], params[MODE2_PARAM]);
  50. lights[1] = out / 5.0;
  51. if (outputs[OUT2_OUTPUT].active) {
  52. outputs[OUT2_OUTPUT].value = out;
  53. out = 0.0;
  54. }
  55. out += getChannelOutput(inputs[IN3_INPUT], params[GAIN3_PARAM], params[MODE3_PARAM]);
  56. lights[2] = out / 5.0;
  57. if (outputs[OUT3_OUTPUT].active) {
  58. outputs[OUT3_OUTPUT].value = out;
  59. }
  60. }
  61. ShadesWidget::ShadesWidget() {
  62. Shades *module = new Shades();
  63. setModule(module);
  64. box.size = Vec(15*6, 380);
  65. {
  66. Panel *panel = new LightPanel();
  67. panel->backgroundImage = Image::load(assetPlugin(plugin, "res/Shades.png"));
  68. panel->box.size = box.size;
  69. addChild(panel);
  70. }
  71. addChild(createScrew<ScrewSilver>(Vec(15, 0)));
  72. addChild(createScrew<ScrewSilver>(Vec(15, 365)));
  73. addParam(createParam<Rogan1PSRed>(Vec(40, 41), module, Shades::GAIN1_PARAM, 0.0, 1.0, 0.0));
  74. addParam(createParam<Rogan1PSWhite>(Vec(40, 107), module, Shades::GAIN2_PARAM, 0.0, 1.0, 0.0));
  75. addParam(createParam<Rogan1PSGreen>(Vec(40, 173), module, Shades::GAIN3_PARAM, 0.0, 1.0, 0.0));
  76. addParam(createParam<CKSS>(Vec(10, 52), module, Shades::MODE1_PARAM, 0.0, 1.0, 0.0));
  77. addParam(createParam<CKSS>(Vec(10, 118), module, Shades::MODE2_PARAM, 0.0, 1.0, 0.0));
  78. addParam(createParam<CKSS>(Vec(10, 184), module, Shades::MODE3_PARAM, 0.0, 1.0, 0.0));
  79. addInput(createInput<PJ3410Port>(Vec(5, 242), module, Shades::IN1_INPUT));
  80. addInput(createInput<PJ3410Port>(Vec(5, 278), module, Shades::IN2_INPUT));
  81. addInput(createInput<PJ3410Port>(Vec(5, 314), module, Shades::IN3_INPUT));
  82. addOutput(createOutput<PJ3410Port>(Vec(52, 242), module, Shades::OUT1_OUTPUT));
  83. addOutput(createOutput<PJ3410Port>(Vec(52, 278), module, Shades::OUT2_OUTPUT));
  84. addOutput(createOutput<PJ3410Port>(Vec(52, 314), module, Shades::OUT3_OUTPUT));
  85. addChild(createValueLight<SmallLight<GreenRedPolarityLight>>(Vec(41, 254), &module->lights[0]));
  86. addChild(createValueLight<SmallLight<GreenRedPolarityLight>>(Vec(41, 290), &module->lights[1]));
  87. addChild(createValueLight<SmallLight<GreenRedPolarityLight>>(Vec(41, 326), &module->lights[2]));
  88. }