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.

130 lines
3.8KB

  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 Osculum : Module
  20. {
  21. enum ParamIds
  22. {
  23. OCTAVE,
  24. NUM_PARAMS
  25. };
  26. enum InputIds
  27. {
  28. PITCH,
  29. NUM_INPUTS
  30. };
  31. enum OutputIds
  32. {
  33. WAVE1_OUT,
  34. WAVE2_OUT,
  35. WAVE3_OUT,
  36. WAVE4_OUT,
  37. NUM_OUTPUTS
  38. };
  39. enum LightIds
  40. {
  41. NUM_LIGHTS
  42. };
  43. Osculum() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS)
  44. {
  45. srand(time(0));
  46. for (int s = 0; s < 8; s++)
  47. {
  48. arand[s] = rand() / (float)RAND_MAX;
  49. }
  50. }
  51. void step() override;
  52. float phase = 0.0;
  53. float arand[8];
  54. };
  55. void Osculum::step()
  56. {
  57. float pitch = params[OCTAVE].value;
  58. pitch += inputs[PITCH].value;
  59. pitch = clamp(pitch, -4.0, 4.0);
  60. float freq = 261.626 * powf(2.0, pitch);
  61. phase += freq / engineGetSampleRate();
  62. if (phase >= 1.0)
  63. {
  64. phase -= 1.0;
  65. }
  66. float wave1 = cosf(powf(M_E, sinf(2.0 * M_PI * phase)));
  67. float wave2 = 0.45 + (2.0 * phase) * sinf(2.0 * M_PI * phase);
  68. if (fabs(wave2) > 1.0)
  69. {
  70. wave2 = 1.0 * copysign(1.0, wave2);
  71. }
  72. float wave3 = cosf(cosh(powf(M_E, sinf(2.0 * M_PI * phase))));
  73. float wave4 = arand[(unsigned int)floorf(phase * 8.0)] * copysign(1.0, phase - 0.5);
  74. outputs[WAVE1_OUT].value = wave1 * 5.0;
  75. outputs[WAVE2_OUT].value = wave2 * 5.0;
  76. outputs[WAVE3_OUT].value = wave3 * 5.0;
  77. outputs[WAVE4_OUT].value = wave4 * 5.0;
  78. }
  79. struct OsculumWidget : ModuleWidget
  80. {
  81. OsculumWidget(Osculum *module);
  82. };
  83. OsculumWidget::OsculumWidget(Osculum *module) : ModuleWidget(module)
  84. {
  85. box.size = Vec(15 * 6, 380);
  86. {
  87. SVGPanel *panel = new SVGPanel();
  88. panel->box.size = box.size;
  89. panel->setBackground(SVG::load(assetPlugin(plugin, "res/osculum.svg")));
  90. addChild(panel);
  91. }
  92. addChild(Widget::create<SonusScrew>(Vec(0, 0)));
  93. addChild(Widget::create<SonusScrew>(Vec(box.size.x - 15, 0)));
  94. addChild(Widget::create<SonusScrew>(Vec(0, 365)));
  95. addChild(Widget::create<SonusScrew>(Vec(box.size.x - 15, 365)));
  96. addInput(Port::create<PJ301MPort>(Vec(33, 67), Port::INPUT, module, Osculum::PITCH));
  97. addOutput(Port::create<PJ301MPort>(Vec(14, 132), Port::OUTPUT, module, Osculum::WAVE1_OUT));
  98. addOutput(Port::create<PJ301MPort>(Vec(52, 132), Port::OUTPUT, module, Osculum::WAVE2_OUT));
  99. addOutput(Port::create<PJ301MPort>(Vec(14, 197), Port::OUTPUT, module, Osculum::WAVE3_OUT));
  100. addOutput(Port::create<PJ301MPort>(Vec(52, 197), Port::OUTPUT, module, Osculum::WAVE4_OUT));
  101. addParam(ParamWidget::create<SonusBigKnob>(Vec(18, 275), module, Osculum::OCTAVE, -3.0, 3.0, 0.0));
  102. }
  103. } // namespace rack_plugin_SonusModular
  104. using namespace rack_plugin_SonusModular;
  105. RACK_PLUGIN_MODEL_INIT(SonusModular, Osculum) {
  106. Model *modelOsculum = Model::create<Osculum, OsculumWidget>("Sonus Modular", "Osculum", "Osculum | Unusual Oscillator", OSCILLATOR_TAG);
  107. return modelOsculum;
  108. }