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.

104 lines
3.2KB

  1. /******************************************************************************
  2. * Copyright 2017-2018 Valerio Orlandini / Sonus Dept. <sonusdept@gmail.com>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *****************************************************************************/
  17. #include "sonusmodular.hpp"
  18. namespace rack_plugin_SonusModular {
  19. struct Bymidside : Module
  20. {
  21. enum ParamIds
  22. {
  23. M_GAIN,
  24. S_GAIN,
  25. NUM_PARAMS
  26. };
  27. enum InputIds
  28. {
  29. L_INPUT,
  30. R_INPUT,
  31. NUM_INPUTS
  32. };
  33. enum OutputIds
  34. {
  35. M_OUTPUT,
  36. S_OUTPUT,
  37. NUM_OUTPUTS
  38. };
  39. enum LightIds
  40. {
  41. NUM_LIGHTS
  42. };
  43. Bymidside() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  44. void step() override;
  45. };
  46. void Bymidside::step()
  47. {
  48. float mid = inputs[L_INPUT].value + inputs[R_INPUT].value;
  49. float side = inputs[L_INPUT].value - inputs[R_INPUT].value;
  50. float mid_gain = params[M_GAIN].value;
  51. float side_gain = params[S_GAIN].value;
  52. outputs[M_OUTPUT].value = mid * mid_gain;
  53. outputs[S_OUTPUT].value = side * side_gain;
  54. }
  55. struct BymidsideWidget : ModuleWidget
  56. {
  57. BymidsideWidget(Bymidside *module);
  58. };
  59. BymidsideWidget::BymidsideWidget(Bymidside *module) : ModuleWidget(module)
  60. {
  61. box.size = Vec(15 * 6, 380);
  62. {
  63. SVGPanel *panel = new SVGPanel();
  64. panel->box.size = box.size;
  65. panel->setBackground(SVG::load(assetPlugin(plugin, "res/bymidside.svg")));
  66. addChild(panel);
  67. }
  68. addChild(Widget::create<SonusScrew>(Vec(0, 0)));
  69. addChild(Widget::create<SonusScrew>(Vec(box.size.x - 15, 0)));
  70. addChild(Widget::create<SonusScrew>(Vec(0, 365)));
  71. addChild(Widget::create<SonusScrew>(Vec(box.size.x - 15, 365)));
  72. addInput(Port::create<PJ301MPort>(Vec(14, 67), Port::INPUT, module, Bymidside::L_INPUT));
  73. addInput(Port::create<PJ301MPort>(Vec(52, 67), Port::INPUT, module, Bymidside::R_INPUT));
  74. addOutput(Port::create<PJ301MPort>(Vec(14, 132), Port::OUTPUT, module, Bymidside::M_OUTPUT));
  75. addOutput(Port::create<PJ301MPort>(Vec(52, 132), Port::OUTPUT, module, Bymidside::S_OUTPUT));
  76. addParam(ParamWidget::create<SonusBigKnob>(Vec(18, 195), module, Bymidside::M_GAIN, 0.0, 2.0, 1.0));
  77. addParam(ParamWidget::create<SonusBigKnob>(Vec(18, 275), module, Bymidside::S_GAIN, 0.0, 2.0, 1.0));
  78. }
  79. } // namespace rack_plugin_SonusModular
  80. using namespace rack_plugin_SonusModular;
  81. RACK_PLUGIN_MODEL_INIT(SonusModular, Bymidside) {
  82. Model *modelBymidside = Model::create<Bymidside, BymidsideWidget>("Sonus Modular", "Bymidside", "Bymidside | MS Encoder", DYNAMICS_TAG, UTILITY_TAG);
  83. return modelBymidside;
  84. }