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.

138 lines
3.9KB

  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 Ringo : Module
  20. {
  21. enum ParamIds
  22. {
  23. SOURCE,
  24. FREQUENCY,
  25. SHAPE,
  26. NUM_PARAMS
  27. };
  28. enum InputIds
  29. {
  30. CARRIER,
  31. MODULATOR,
  32. CV_FREQ,
  33. NUM_INPUTS
  34. };
  35. enum OutputIds
  36. {
  37. OUTPUT,
  38. NUM_OUTPUTS
  39. };
  40. enum LightIds
  41. {
  42. NUM_LIGHTS
  43. };
  44. Ringo() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  45. void step() override;
  46. float phase = 0.0;
  47. bool audio_modulated = false;
  48. };
  49. void Ringo::step()
  50. {
  51. float freq = 0.0;
  52. float sine_out = 0.0;
  53. float saw_out = 0.0;
  54. float shape = params[SHAPE].value;
  55. float carrier = inputs[CARRIER].value / 5.0;
  56. float modulator = inputs[MODULATOR].value / 5.0;
  57. if (params[SOURCE].value == 0.0)
  58. {
  59. audio_modulated = false;
  60. }
  61. else
  62. {
  63. audio_modulated = true;
  64. }
  65. float pitch = params[FREQUENCY].value;
  66. pitch += inputs[CV_FREQ].value;
  67. pitch = clamp(pitch, -4.0, 4.0);
  68. freq = 440.0 * powf(2.0, pitch);
  69. phase += freq / engineGetSampleRate();
  70. if (phase >= 1.0)
  71. {
  72. phase -= 1.0;
  73. }
  74. sine_out = sinf(2.0 * M_PI * phase);
  75. saw_out = 2.0 * (phase - 0.5);
  76. if (audio_modulated)
  77. {
  78. outputs[OUTPUT].value = carrier * modulator * 5.0;
  79. }
  80. else
  81. {
  82. outputs[OUTPUT].value = carrier * (((1.0 - shape) * sine_out) + (shape * saw_out)) * 5.0;
  83. }
  84. }
  85. struct RingoWidget : ModuleWidget
  86. {
  87. RingoWidget(Ringo *module);
  88. };
  89. RingoWidget::RingoWidget(Ringo *module) : ModuleWidget(module)
  90. {
  91. box.size = Vec(15 * 6, 380);
  92. {
  93. SVGPanel *panel = new SVGPanel();
  94. panel->box.size = box.size;
  95. panel->setBackground(SVG::load(assetPlugin(plugin, "res/ringo.svg")));
  96. addChild(panel);
  97. }
  98. addChild(Widget::create<SonusScrew>(Vec(0, 0)));
  99. addChild(Widget::create<SonusScrew>(Vec(box.size.x - 15, 0)));
  100. addChild(Widget::create<SonusScrew>(Vec(0, 365)));
  101. addChild(Widget::create<SonusScrew>(Vec(box.size.x - 15, 365)));
  102. addInput(Port::create<PJ301MPort>(Vec(14, 67), Port::INPUT, module, Ringo::MODULATOR));
  103. addInput(Port::create<PJ301MPort>(Vec(52, 67), Port::INPUT, module, Ringo::CARRIER));
  104. addOutput(Port::create<PJ301MPort>(Vec(33, 132), Port::OUTPUT, module, Ringo::OUTPUT));
  105. addParam(ParamWidget::create<CKSS>(Vec(28, 197), module, Ringo::SOURCE, 0.0, 1.0, 0.0));
  106. addParam(ParamWidget::create<SonusKnob>(Vec(27, 243), module, Ringo::SHAPE, 0.0, 1.0, 0.0));
  107. addParam(ParamWidget::create<SonusKnob>(Vec(48, 293), module, Ringo::FREQUENCY, -2.0, 2.0, 0.0));
  108. addInput(Port::create<PJ301MPort>(Vec(14, 300), Port::INPUT, module, Ringo::CV_FREQ));
  109. }
  110. } // namespace rack_plugin_SonusModular
  111. using namespace rack_plugin_SonusModular;
  112. RACK_PLUGIN_MODEL_INIT(SonusModular, Ringo) {
  113. Model *modelRingo = Model::create<Ringo, RingoWidget>("Sonus Modular", "Ringo", "Ringo | Ring Modulator", RING_MODULATOR_TAG, EFFECT_TAG);
  114. return modelRingo;
  115. }