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.

139 lines
4.6KB

  1. #include "AudibleInstruments.hpp"
  2. #include <string.h>
  3. struct Blinds : Module {
  4. enum ParamIds {
  5. GAIN1_PARAM,
  6. GAIN2_PARAM,
  7. GAIN3_PARAM,
  8. GAIN4_PARAM,
  9. MOD1_PARAM,
  10. MOD2_PARAM,
  11. MOD3_PARAM,
  12. MOD4_PARAM,
  13. NUM_PARAMS
  14. };
  15. enum InputIds {
  16. IN1_INPUT,
  17. IN2_INPUT,
  18. IN3_INPUT,
  19. IN4_INPUT,
  20. CV1_INPUT,
  21. CV2_INPUT,
  22. CV3_INPUT,
  23. CV4_INPUT,
  24. NUM_INPUTS
  25. };
  26. enum OutputIds {
  27. OUT1_OUTPUT,
  28. OUT2_OUTPUT,
  29. OUT3_OUTPUT,
  30. OUT4_OUTPUT,
  31. NUM_OUTPUTS
  32. };
  33. float lights[4] = {};
  34. float gainLights[4] = {};
  35. Blinds();
  36. void step();
  37. };
  38. Blinds::Blinds() {
  39. params.resize(NUM_PARAMS);
  40. inputs.resize(NUM_INPUTS);
  41. outputs.resize(NUM_OUTPUTS);
  42. }
  43. static float getChannelOutput(const float *in, float gain, const float *cv, float mod, float *light) {
  44. gain += mod * fmaxf(getf(cv) / 5.0, 0.0);
  45. *light = gain * 5.0;
  46. return gain * getf(in, 5.0);
  47. }
  48. void Blinds::step() {
  49. float out = 0.0;
  50. out += getChannelOutput(inputs[IN1_INPUT], params[GAIN1_PARAM], inputs[CV1_INPUT], params[MOD1_PARAM], &gainLights[0]);
  51. lights[0] = out;
  52. if (outputs[OUT1_OUTPUT]) {
  53. *outputs[OUT1_OUTPUT] = out;
  54. out = 0.0;
  55. }
  56. out += getChannelOutput(inputs[IN2_INPUT], params[GAIN2_PARAM], inputs[CV2_INPUT], params[MOD2_PARAM], &gainLights[1]);
  57. lights[1] = out;
  58. if (outputs[OUT2_OUTPUT]) {
  59. *outputs[OUT2_OUTPUT] = out;
  60. out = 0.0;
  61. }
  62. out += getChannelOutput(inputs[IN3_INPUT], params[GAIN3_PARAM], inputs[CV3_INPUT], params[MOD3_PARAM], &gainLights[2]);
  63. lights[2] = out;
  64. if (outputs[OUT3_OUTPUT]) {
  65. *outputs[OUT3_OUTPUT] = out;
  66. out = 0.0;
  67. }
  68. out += getChannelOutput(inputs[IN4_INPUT], params[GAIN4_PARAM], inputs[CV4_INPUT], params[MOD4_PARAM], &gainLights[3]);
  69. lights[3] = out;
  70. if (outputs[OUT4_OUTPUT]) {
  71. *outputs[OUT4_OUTPUT] = out;
  72. }
  73. }
  74. BlindsWidget::BlindsWidget() {
  75. Blinds *module = new Blinds();
  76. setModule(module);
  77. box.size = Vec(15*12, 380);
  78. {
  79. Panel *panel = new LightPanel();
  80. panel->backgroundImage = Image::load(assetPlugin(plugin, "res/Blinds.png"));
  81. panel->box.size = box.size;
  82. addChild(panel);
  83. }
  84. addChild(createScrew<ScrewSilver>(Vec(15, 0)));
  85. addChild(createScrew<ScrewSilver>(Vec(150, 0)));
  86. addChild(createScrew<ScrewSilver>(Vec(15, 365)));
  87. addChild(createScrew<ScrewSilver>(Vec(150, 365)));
  88. addParam(createParam<Rogan1PSWhite>(Vec(8, 52), module, Blinds::GAIN1_PARAM, -1.0, 1.0, 0.0));
  89. addParam(createParam<Rogan1PSWhite>(Vec(8, 131), module, Blinds::GAIN2_PARAM, -1.0, 1.0, 0.0));
  90. addParam(createParam<Rogan1PSWhite>(Vec(8, 210), module, Blinds::GAIN3_PARAM, -1.0, 1.0, 0.0));
  91. addParam(createParam<Rogan1PSWhite>(Vec(8, 288), module, Blinds::GAIN4_PARAM, -1.0, 1.0, 0.0));
  92. addParam(createParam<Trimpot>(Vec(72, 63), module, Blinds::MOD1_PARAM, -1.0, 1.0, 0.0));
  93. addParam(createParam<Trimpot>(Vec(72, 142), module, Blinds::MOD2_PARAM, -1.0, 1.0, 0.0));
  94. addParam(createParam<Trimpot>(Vec(72, 221), module, Blinds::MOD3_PARAM, -1.0, 1.0, 0.0));
  95. addParam(createParam<Trimpot>(Vec(72, 300), module, Blinds::MOD4_PARAM, -1.0, 1.0, 0.0));
  96. addInput(createInput<PJ3410Port>(Vec(107, 38), module, Blinds::IN1_INPUT));
  97. addInput(createInput<PJ3410Port>(Vec(107, 117), module, Blinds::IN2_INPUT));
  98. addInput(createInput<PJ3410Port>(Vec(107, 195), module, Blinds::IN3_INPUT));
  99. addInput(createInput<PJ3410Port>(Vec(107, 274), module, Blinds::IN4_INPUT));
  100. addInput(createInput<PJ3410Port>(Vec(107, 77), module, Blinds::CV1_INPUT));
  101. addInput(createInput<PJ3410Port>(Vec(107, 156), module, Blinds::CV2_INPUT));
  102. addInput(createInput<PJ3410Port>(Vec(107, 235), module, Blinds::CV3_INPUT));
  103. addInput(createInput<PJ3410Port>(Vec(107, 313), module, Blinds::CV4_INPUT));
  104. addOutput(createOutput<PJ3410Port>(Vec(141, 38), module, Blinds::OUT1_OUTPUT));
  105. addOutput(createOutput<PJ3410Port>(Vec(141, 117), module, Blinds::OUT2_OUTPUT));
  106. addOutput(createOutput<PJ3410Port>(Vec(141, 195), module, Blinds::OUT3_OUTPUT));
  107. addOutput(createOutput<PJ3410Port>(Vec(141, 274), module, Blinds::OUT4_OUTPUT));
  108. addChild(createValueLight<MediumLight<GreenRedPolarityLight>>(Vec(150, 87), &module->lights[0]));
  109. addChild(createValueLight<MediumLight<GreenRedPolarityLight>>(Vec(150, 166), &module->lights[1]));
  110. addChild(createValueLight<MediumLight<GreenRedPolarityLight>>(Vec(150, 245), &module->lights[2]));
  111. addChild(createValueLight<MediumLight<GreenRedPolarityLight>>(Vec(150, 324), &module->lights[3]));
  112. addChild(createValueLight<SmallLight<GreenRedPolarityLight>>(Vec(77, 96), &module->gainLights[0]));
  113. addChild(createValueLight<SmallLight<GreenRedPolarityLight>>(Vec(77, 175), &module->gainLights[1]));
  114. addChild(createValueLight<SmallLight<GreenRedPolarityLight>>(Vec(77, 254), &module->gainLights[2]));
  115. addChild(createValueLight<SmallLight<GreenRedPolarityLight>>(Vec(77, 333), &module->gainLights[3]));
  116. }