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.

113 lines
3.4KB

  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 Deathcrush : Module
  20. {
  21. enum ParamIds
  22. {
  23. DRIVE1,
  24. DRIVE2,
  25. BITS,
  26. NUM_PARAMS
  27. };
  28. enum InputIds
  29. {
  30. INPUT,
  31. NUM_INPUTS
  32. };
  33. enum OutputIds
  34. {
  35. OUTPUT,
  36. NUM_OUTPUTS
  37. };
  38. enum LightIds
  39. {
  40. NUM_LIGHTS
  41. };
  42. Deathcrush() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  43. void step() override;
  44. };
  45. void Deathcrush::step()
  46. {
  47. float in = inputs[INPUT].value / 5.0;
  48. float out = 0.0;
  49. float drive1_amount = params[DRIVE1].value;
  50. float drive2_amount = params[DRIVE2].value;
  51. float bits = params[BITS].value;
  52. out = (in * (1.0 - drive1_amount)) + ((copysign(1.0, in) * tan(powf(fabs(in), 0.25)) * drive1_amount * 0.75));
  53. if (fabs(in) > (1.0 - drive2_amount))
  54. {
  55. out = (out * (1.0 - drive2_amount)) + (copysign(1.0, in) * drive2_amount);
  56. }
  57. out = out * powf(2.0, bits - 1.0);
  58. out = round(out);
  59. out = out / powf(2.0, bits - 1.0);
  60. outputs[OUTPUT].value = out * 5.0;
  61. }
  62. struct DeathcrushWidget : ModuleWidget
  63. {
  64. DeathcrushWidget(Deathcrush *module);
  65. };
  66. DeathcrushWidget::DeathcrushWidget(Deathcrush *module) : ModuleWidget(module)
  67. {
  68. box.size = Vec(15 * 6, 380);
  69. {
  70. SVGPanel *panel = new SVGPanel();
  71. panel->box.size = box.size;
  72. panel->setBackground(SVG::load(assetPlugin(plugin, "res/deathcrush.svg")));
  73. addChild(panel);
  74. }
  75. addChild(Widget::create<SonusScrew>(Vec(0, 0)));
  76. addChild(Widget::create<SonusScrew>(Vec(box.size.x - 15, 0)));
  77. addChild(Widget::create<SonusScrew>(Vec(0, 365)));
  78. addChild(Widget::create<SonusScrew>(Vec(box.size.x - 15, 365)));
  79. addInput(Port::create<PJ301MPort>(Vec(14, 67), Port::INPUT, module, Deathcrush::INPUT));
  80. addOutput(Port::create<PJ301MPort>(Vec(52, 67), Port::OUTPUT, module, Deathcrush::OUTPUT));
  81. addParam(ParamWidget::create<SonusKnob>(Vec(27, 150), module, Deathcrush::DRIVE1, 0.0, 1.0, 0.0));
  82. addParam(ParamWidget::create<SonusKnob>(Vec(27, 210), module, Deathcrush::DRIVE2, 0.0, 1.0, 0.0));
  83. addParam(ParamWidget::create<SonusBigKnob>(Vec(18, 275), module, Deathcrush::BITS, 1.0, 12.0, 12.0));
  84. }
  85. } // namespace rack_plugin_SonusModular
  86. using namespace rack_plugin_SonusModular;
  87. RACK_PLUGIN_MODEL_INIT(SonusModular, Deathcrush) {
  88. Model *modelDeathcrush = Model::create<Deathcrush, DeathcrushWidget>("Sonus Modular", "Deathcrush", "Deathcrush | Driver and Crusher", DISTORTION_TAG, EFFECT_TAG);
  89. return modelDeathcrush;
  90. }