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.

125 lines
3.4KB

  1. #include "HetrickCV.hpp"
  2. #include "dsp/digital.hpp"
  3. namespace rack_plugin_HetrickCV {
  4. #ifdef USE_VST2
  5. #define plugin "HetrickCV"
  6. #endif // USE_VST2
  7. struct TwoToFour : Module
  8. {
  9. enum ParamIds
  10. {
  11. NUM_PARAMS
  12. };
  13. enum InputIds
  14. {
  15. INA_INPUT,
  16. INB_INPUT,
  17. NUM_INPUTS
  18. };
  19. enum OutputIds
  20. {
  21. OUT1_OUTPUT,
  22. OUT2_OUTPUT,
  23. OUT3_OUTPUT,
  24. OUT4_OUTPUT,
  25. NUM_OUTPUTS
  26. };
  27. enum LightIds
  28. {
  29. OUT1_POS_LIGHT, OUT1_NEG_LIGHT,
  30. OUT2_POS_LIGHT, OUT2_NEG_LIGHT,
  31. OUT3_POS_LIGHT, OUT3_NEG_LIGHT,
  32. OUT4_POS_LIGHT, OUT4_NEG_LIGHT,
  33. NUM_LIGHTS
  34. };
  35. float outs[4] = {};
  36. TwoToFour() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS)
  37. {
  38. }
  39. void step() override;
  40. // For more advanced Module features, read Rack's engine.hpp header file
  41. // - toJson, fromJson: serialization of internal data
  42. // - onSampleRateChange: event triggered by a change of sample rate
  43. // - reset, randomize: implements special behavior when user clicks these from the context menu
  44. };
  45. void TwoToFour::step()
  46. {
  47. const float inA = inputs[INA_INPUT].value;
  48. const float inB = inputs[INB_INPUT].value;
  49. outs[0] = inA + inB;
  50. outs[1] = outs[0] * -1.0f;
  51. outs[3] = inA - inB;
  52. outs[2] = outs[3] * -1.0f;
  53. outputs[OUT1_OUTPUT].value = outs[0];
  54. outputs[OUT2_OUTPUT].value = outs[1];
  55. outputs[OUT3_OUTPUT].value = outs[2];
  56. outputs[OUT4_OUTPUT].value = outs[3];
  57. lights[OUT1_POS_LIGHT].setBrightnessSmooth(fmaxf(0.0, outs[0] / 5.0));
  58. lights[OUT1_NEG_LIGHT].setBrightnessSmooth(fmaxf(0.0, -outs[0] / 5.0));
  59. lights[OUT2_POS_LIGHT].setBrightnessSmooth(fmaxf(0.0, outs[1] / 5.0));
  60. lights[OUT2_NEG_LIGHT].setBrightnessSmooth(fmaxf(0.0, -outs[1] / 5.0));
  61. lights[OUT3_POS_LIGHT].setBrightnessSmooth(fmaxf(0.0, outs[2] / 5.0));
  62. lights[OUT3_NEG_LIGHT].setBrightnessSmooth(fmaxf(0.0, -outs[2] / 5.0));
  63. lights[OUT4_POS_LIGHT].setBrightnessSmooth(fmaxf(0.0, outs[3] / 5.0));
  64. lights[OUT4_NEG_LIGHT].setBrightnessSmooth(fmaxf(0.0, -outs[3] / 5.0));
  65. }
  66. struct TwoToFourWidget : ModuleWidget { TwoToFourWidget(TwoToFour *module); };
  67. TwoToFourWidget::TwoToFourWidget(TwoToFour *module) : ModuleWidget(module)
  68. {
  69. box.size = Vec(6 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT);
  70. {
  71. auto *panel = new SVGPanel();
  72. panel->box.size = box.size;
  73. panel->setBackground(SVG::load(assetPlugin(plugin, "res/2To4.svg")));
  74. addChild(panel);
  75. }
  76. addChild(Widget::create<ScrewSilver>(Vec(15, 0)));
  77. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 30, 0)));
  78. addChild(Widget::create<ScrewSilver>(Vec(15, 365)));
  79. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 30, 365)));
  80. //////PARAMS//////
  81. //////INPUTS//////
  82. addInput(Port::create<PJ301MPort>(Vec(10, 100), Port::INPUT, module, TwoToFour::INA_INPUT));
  83. addInput(Port::create<PJ301MPort>(Vec(55, 100), Port::INPUT, module, TwoToFour::INB_INPUT));
  84. for(int i = 0; i < 4; i++)
  85. {
  86. const int yPos = i*45;
  87. addOutput(Port::create<PJ301MPort>(Vec(33, 150 + yPos), Port::OUTPUT, module, TwoToFour::OUT1_OUTPUT + i));
  88. addChild(ModuleLightWidget::create<SmallLight<GreenRedLight>>(Vec(70, 158 + yPos), module, TwoToFour::OUT1_POS_LIGHT + i*2));
  89. }
  90. }
  91. } // namespace rack_plugin_HetrickCV
  92. using namespace rack_plugin_HetrickCV;
  93. RACK_PLUGIN_MODEL_INIT(HetrickCV, TwoToFour) {
  94. Model *modelTwoToFour = Model::create<TwoToFour, TwoToFourWidget>("HetrickCV", "2To4", "2 To 4 Mix Matrix", MIXER_TAG);
  95. return modelTwoToFour;
  96. }