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.

127 lines
3.7KB

  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 Paramath : Module
  20. {
  21. enum ParamIds
  22. {
  23. NUM_PARAMS
  24. };
  25. enum InputIds
  26. {
  27. IN_A,
  28. IN_B,
  29. NUM_INPUTS
  30. };
  31. enum OutputIds
  32. {
  33. A_GEQ_B,
  34. A_EQ_B,
  35. MIN,
  36. MAX,
  37. A_MUL_B,
  38. PYTHAGORAS,
  39. NUM_OUTPUTS
  40. };
  41. enum LightIds
  42. {
  43. NUM_LIGHTS
  44. };
  45. Paramath() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  46. void step() override;
  47. };
  48. void Paramath::step()
  49. {
  50. float in_a = inputs[IN_A].value;
  51. float in_b = inputs[IN_B].value;
  52. if (in_a >= in_b)
  53. {
  54. outputs[A_GEQ_B].value = 5.0;
  55. outputs[MIN].value = in_b;
  56. outputs[MAX].value = in_a;
  57. }
  58. else
  59. {
  60. outputs[A_GEQ_B].value = 0.0;
  61. outputs[MIN].value = in_a;
  62. outputs[MAX].value = in_b;
  63. }
  64. if (in_a == in_b)
  65. {
  66. outputs[A_EQ_B].value = 5.0;
  67. }
  68. else
  69. {
  70. outputs[A_EQ_B].value = 0.0;
  71. }
  72. // These two value are computed on normalized [-1.0; 1.0]
  73. outputs[A_MUL_B].value = (in_a * in_b) * 5.0;
  74. outputs[PYTHAGORAS].value = sqrt(powf(in_a / 5.0, 2.0) + powf(in_b / 5.0, 2.0)) * 5.0;
  75. }
  76. struct ParamathWidget : ModuleWidget
  77. {
  78. ParamathWidget(Paramath *module);
  79. };
  80. ParamathWidget::ParamathWidget(Paramath *module) : ModuleWidget(module)
  81. {
  82. box.size = Vec(15 * 6, 380);
  83. {
  84. SVGPanel *panel = new SVGPanel();
  85. panel->box.size = box.size;
  86. panel->setBackground(SVG::load(assetPlugin(plugin, "res/paramath.svg")));
  87. addChild(panel);
  88. }
  89. addChild(Widget::create<SonusScrew>(Vec(0, 0)));
  90. addChild(Widget::create<SonusScrew>(Vec(box.size.x - 15, 0)));
  91. addChild(Widget::create<SonusScrew>(Vec(0, 365)));
  92. addChild(Widget::create<SonusScrew>(Vec(box.size.x - 15, 365)));
  93. addInput(Port::create<PJ301MPort>(Vec(14, 67), Port::INPUT, module, Paramath::IN_A));
  94. addInput(Port::create<PJ301MPort>(Vec(52, 67), Port::INPUT, module, Paramath::IN_B));
  95. addOutput(Port::create<PJ301MPort>(Vec(14, 132), Port::OUTPUT, module, Paramath::A_GEQ_B));
  96. addOutput(Port::create<PJ301MPort>(Vec(52, 132), Port::OUTPUT, module, Paramath::A_EQ_B));
  97. addOutput(Port::create<PJ301MPort>(Vec(14, 197), Port::OUTPUT, module, Paramath::MIN));
  98. addOutput(Port::create<PJ301MPort>(Vec(52, 197), Port::OUTPUT, module, Paramath::MAX));
  99. addOutput(Port::create<PJ301MPort>(Vec(14, 262), Port::OUTPUT, module, Paramath::A_MUL_B));
  100. addOutput(Port::create<PJ301MPort>(Vec(52, 262), Port::OUTPUT, module, Paramath::PYTHAGORAS));
  101. }
  102. } // namespace rack_plugin_SonusModular
  103. using namespace rack_plugin_SonusModular;
  104. RACK_PLUGIN_MODEL_INIT(SonusModular, Paramath) {
  105. Model *modelParamath = Model::create<Paramath, ParamathWidget>("Sonus Modular", "Paramath", "Paramath | Comparing and Maths", LOGIC_TAG, UTILITY_TAG);
  106. return modelParamath;
  107. }