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.

62 lines
2.7KB

  1. #include "Distortion.hpp"
  2. #include <cmath>
  3. namespace rack_plugin_MicMusic {
  4. namespace math {
  5. float clamp(float value, float min, float max) {
  6. #define sMIN(a,b) (((a)>(b))?(b):(a))
  7. #define sMAX(a,b) (((a)>(b))?(a):(b))
  8. return sMAX(sMIN(value, max), min);
  9. #undef sMIN
  10. #undef sMAX
  11. }
  12. }
  13. Distortion::Distortion()
  14. : Module((int) Params::COUNT, (int) Inputs::COUNT, (int) Outputs::COUNT, (int) Lights::COUNT)
  15. {}
  16. void Distortion::step() {
  17. float input = inputs[(int) Inputs::SIGNAL].value;
  18. float high_cv = inputs[(int) Inputs::HIGH].value * params[(int) Params::HIGH_CV].value;
  19. float high_value = params[(int) Params::HIGH].value + high_cv;
  20. float low_cv = inputs[(int) Inputs::LOW].value * params[(int) Params::LOW_CV].value;
  21. float low_value = params[(int) Params::LOW].value + low_cv;
  22. //_debugOut << params[(int) Inputs::HIGH].value;
  23. outputs[(int) Outputs::SIGNAL].value = math::clamp(input, low_value, high_value);
  24. }
  25. struct DistortionWidget : ModuleWidget {
  26. DistortionWidget(Distortion *module) : ModuleWidget(module) {
  27. setPanel(SVG::load(assetPlugin(plugin, "res/Distortion.svg")));
  28. addChild(Widget::create<ScrewBlack>(Vec(RACK_GRID_WIDTH, 0)));
  29. addChild(Widget::create<ScrewBlack>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, 0)));
  30. addChild(Widget::create<ScrewBlack>(Vec(RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  31. addChild(Widget::create<ScrewBlack>(Vec(box.size.x - 2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT - RACK_GRID_WIDTH)));
  32. addParam(ParamWidget::create<RoundBlackKnob>(Vec(50, 86), module, (int) Distortion::Params::HIGH, -10.f, 10.f, 10.f));
  33. addParam(ParamWidget::create<RoundBlackKnob>(Vec(50, 188), module, (int) Distortion::Params::HIGH_CV, 0.f, 1.f, 0.f));
  34. addInput(Port::create<PJ301MPort>(Vec(52, 149), Port::INPUT, module, (int) Distortion::Inputs::HIGH));
  35. addParam(ParamWidget::create<RoundBlackKnob>(Vec(10, 86), module, (int) Distortion::Params::LOW, -10.f, 10.f, -10.f));
  36. addParam(ParamWidget::create<RoundBlackKnob>(Vec(10, 188), module, (int) Distortion::Params::LOW_CV, 0.f, 1.f, 0.f));
  37. addInput(Port::create<PJ301MPort>(Vec(12, 149), Port::INPUT, module, (int) Distortion::Inputs::LOW));
  38. addInput(Port::create<PJ301MPort>(Vec(12, 330), Port::INPUT, module, (int) Distortion::Inputs::SIGNAL));
  39. addOutput(Port::create<PJ301MPort>(Vec(52, 330), Port::OUTPUT, module,(int) Distortion::Outputs::SIGNAL));
  40. }
  41. };
  42. } // namespace rack_plugin_MicMusic
  43. using namespace rack_plugin_MicMusic;
  44. RACK_PLUGIN_MODEL_INIT(MicMusic, Distortion) {
  45. Model *distortionModule = Model::create<Distortion, DistortionWidget>("MicMusic", "Distortion", "Distortion - CuTeR", DISTORTION_TAG);
  46. return distortionModule;
  47. }