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.

117 lines
3.3KB

  1. #include "HetrickCV.hpp"
  2. namespace rack_plugin_HetrickCV {
  3. #ifdef USE_VST2
  4. #define plugin "HetrickCV"
  5. #endif // USE_VST2
  6. struct Waveshape : Module
  7. {
  8. enum ParamIds
  9. {
  10. AMOUNT_PARAM,
  11. SCALE_PARAM,
  12. RANGE_PARAM,
  13. NUM_PARAMS
  14. };
  15. enum InputIds
  16. {
  17. MAIN_INPUT,
  18. AMOUNT_INPUT,
  19. NUM_INPUTS
  20. };
  21. enum OutputIds
  22. {
  23. MAIN_OUTPUT,
  24. NUM_OUTPUTS
  25. };
  26. Waveshape() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS)
  27. {
  28. }
  29. void step() override;
  30. // For more advanced Module features, read Rack's engine.hpp header file
  31. // - toJson, fromJson: serialization of internal data
  32. // - onSampleRateChange: event triggered by a change of sample rate
  33. // - reset, randomize: implements special behavior when user clicks these from the context menu
  34. };
  35. void Waveshape::step()
  36. {
  37. float input = inputs[MAIN_INPUT].value;
  38. bool mode5V = (params[RANGE_PARAM].value == 0.0f);
  39. if(mode5V) input = clampf(input, -5.0f, 5.0f) * 0.2f;
  40. else input = clampf(input, -10.0f, 10.0f) * 0.1f;
  41. float shape = params[AMOUNT_PARAM].value + (inputs[AMOUNT_INPUT].value * params[SCALE_PARAM].value);
  42. shape = clampf(shape, -5.0f, 5.0f) * 0.2f;
  43. shape *= 0.99f;
  44. const float shapeB = (1.0 - shape) / (1.0 + shape);
  45. const float shapeA = (4.0 * shape) / ((1.0 - shape) * (1.0 + shape));
  46. float output = input * (shapeA + shapeB);
  47. output = output / ((std::abs(input) * shapeA) + shapeB);
  48. if(mode5V) output *= 5.0f;
  49. else output *= 10.0f;
  50. outputs[MAIN_OUTPUT].value = output;
  51. }
  52. struct CKSSRot : SVGSwitch, ToggleSwitch {
  53. CKSSRot() {
  54. addFrame(SVG::load(assetPlugin(plugin, "res/CKSS_rot_0.svg")));
  55. addFrame(SVG::load(assetPlugin(plugin, "res/CKSS_rot_1.svg")));
  56. sw->wrap();
  57. box.size = sw->box.size;
  58. }
  59. };
  60. struct WaveshapeWidget : ModuleWidget { WaveshapeWidget(Waveshape *module); };
  61. WaveshapeWidget::WaveshapeWidget(Waveshape *module) : ModuleWidget(module)
  62. {
  63. box.size = Vec(6 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT);
  64. {
  65. auto *panel = new SVGPanel();
  66. panel->box.size = box.size;
  67. panel->setBackground(SVG::load(assetPlugin(plugin, "res/Waveshape.svg")));
  68. addChild(panel);
  69. }
  70. addChild(Widget::create<ScrewSilver>(Vec(15, 0)));
  71. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 30, 0)));
  72. addChild(Widget::create<ScrewSilver>(Vec(15, 365)));
  73. addChild(Widget::create<ScrewSilver>(Vec(box.size.x - 30, 365)));
  74. //////PARAMS//////
  75. addParam(ParamWidget::create<Davies1900hBlackKnob>(Vec(27, 62), module, Waveshape::AMOUNT_PARAM, -5.0, 5.0, 0.0));
  76. addParam(ParamWidget::create<Trimpot>(Vec(36, 112), module, Waveshape::SCALE_PARAM, -1.0, 1.0, 1.0));
  77. addParam(ParamWidget::create<CKSSRot>(Vec(35, 200), module, Waveshape::RANGE_PARAM, 0.0, 1.0, 0.0));
  78. //////INPUTS//////
  79. addInput(Port::create<PJ301MPort>(Vec(33, 235), Port::INPUT, module, Waveshape::MAIN_INPUT));
  80. addInput(Port::create<PJ301MPort>(Vec(33, 145), Port::INPUT, module, Waveshape::AMOUNT_INPUT));
  81. //////OUTPUTS//////
  82. addOutput(Port::create<PJ301MPort>(Vec(33, 285), Port::OUTPUT, module, Waveshape::MAIN_OUTPUT));
  83. }
  84. } // namespace rack_plugin_HetrickCV
  85. using namespace rack_plugin_HetrickCV;
  86. RACK_PLUGIN_MODEL_INIT(HetrickCV, Waveshape) {
  87. Model *modelWaveshape = Model::create<Waveshape, WaveshapeWidget>("HetrickCV", "Waveshaper", "Waveshaper", WAVESHAPER_TAG, DISTORTION_TAG, EFFECT_TAG);
  88. return modelWaveshape;
  89. }