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.

123 lines
4.7KB

  1. /*
  2. Copyright (c) 2017 Leonardo Laguna Ruiz (modlfo@gmail.com), All rights reserved.
  3. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  4. 1.- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  5. 2.- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  6. 3.- Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  7. 4.- Commercial use requires explicit permission of the author.
  8. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  9. */
  10. #include "VultModules.hpp"
  11. #include "util/math.hpp"
  12. #include "VultEngine.h"
  13. struct Rescomb : Module
  14. {
  15. enum ParamIds
  16. {
  17. TUNE_PARAM,
  18. COMB_PARAM,
  19. FEEDBACK_PARAM,
  20. COMB_AMT_PARAM,
  21. FEEDBACK_AMT_PARAM,
  22. NUM_PARAMS
  23. };
  24. enum InputIds
  25. {
  26. PITCH_INPUT,
  27. AUDIO_INPUT,
  28. COMB_INPUT,
  29. FEEDBACK_INPUT,
  30. NUM_INPUTS
  31. };
  32. enum OutputIds
  33. {
  34. AUDIO_OUTPUT,
  35. NUM_OUTPUTS
  36. };
  37. VultEngine_rescomb_type processor;
  38. Rescomb();
  39. void step() override;
  40. };
  41. Rescomb::Rescomb() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS)
  42. {
  43. params.resize(NUM_PARAMS);
  44. inputs.resize(NUM_INPUTS);
  45. outputs.resize(NUM_OUTPUTS);
  46. VultEngine_rescomb_init(processor);
  47. }
  48. void Rescomb::step()
  49. {
  50. float pitch = inputs[PITCH_INPUT].value / 10.0;
  51. float tune = params[TUNE_PARAM].value;
  52. float audio = inputs[AUDIO_INPUT].value / 5.0;
  53. float comb_cv = inputs[COMB_INPUT].value / 5.0;
  54. float comb_p = params[COMB_PARAM].value;
  55. float comb_amt = params[COMB_AMT_PARAM].value;
  56. float feedback_cv = inputs[FEEDBACK_INPUT].value / 5.0;
  57. float feedback_p = params[FEEDBACK_PARAM].value;
  58. float feedback_amt = params[FEEDBACK_AMT_PARAM].value;
  59. float comb = comb_p + comb_cv * comb_amt;
  60. float feedback = feedback_p + feedback_cv * feedback_amt;
  61. float out = VultEngine_rescomb(processor, audio, pitch + tune, comb, feedback);
  62. outputs[AUDIO_OUTPUT].value = out * 5.0;
  63. }
  64. struct RescombWidget : ModuleWidget
  65. {
  66. RescombWidget(Rescomb *module);
  67. };
  68. RescombWidget::RescombWidget(Rescomb *module) : ModuleWidget(module)
  69. {
  70. // Rescomb *module = new Rescomb();
  71. // setModule__deprecated__(module);
  72. box.size = Vec(15 * 10, 380);
  73. {
  74. SVGPanel *panel = new SVGPanel();
  75. panel->box.size = box.size;
  76. panel->setBackground(SVG::load(assetPlugin(plugin, "res/Rescomb.svg")));
  77. addChild(panel);
  78. }
  79. addChild(createScrew<VultScrew>(Vec(15, 0)));
  80. addChild(createScrew<VultScrew>(Vec(box.size.x - 30, 0)));
  81. addChild(createScrew<VultScrew>(Vec(15, 365)));
  82. addChild(createScrew<VultScrew>(Vec(box.size.x - 30, 365)));
  83. addParam(createParam<VultKnob>(Vec(30, 78), module, Rescomb::TUNE_PARAM, -0.4, 0.4, 0.0));
  84. addParam(createParam<VultKnob>(Vec(30, 158), module, Rescomb::COMB_PARAM, -1.0, 1.0, 0.0));
  85. addParam(createParam<VultKnob>(Vec(30, 238), module, Rescomb::FEEDBACK_PARAM, 0.0, 1.1, 0.0));
  86. addParam(createParam<VultKnobSmall>(Vec(103, 158), module, Rescomb::COMB_AMT_PARAM, -1.0, 1.0, 0.0));
  87. addParam(createParam<VultKnobSmall>(Vec(103, 238), module, Rescomb::FEEDBACK_AMT_PARAM, -1.0, 1.0, 0.0));
  88. addInput(createInput<VultJack>(Vec(101, 85), module, Rescomb::PITCH_INPUT));
  89. addInput(createInput<VultJack>(Vec(101, 183), module, Rescomb::COMB_INPUT));
  90. addInput(createInput<VultJack>(Vec(101, 263), module, Rescomb::FEEDBACK_INPUT));
  91. addInput(createInput<VultJack>(Vec(27, 318), module, Rescomb::AUDIO_INPUT));
  92. addOutput(createOutput<VultJack>(Vec(101, 318), module, Rescomb::AUDIO_OUTPUT));
  93. }
  94. RACK_PLUGIN_MODEL_INIT(VultModules, Rescomb) {
  95. Model *model = Model::create<Rescomb, RescombWidget>("VultModules", "Rescomb", "Rescomb", FILTER_TAG);
  96. return model;
  97. }