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.

80 lines
1.9KB

  1. #include "dhe-modules.h"
  2. #include "display/controls.h"
  3. #include "display/panel.h"
  4. #include "util/range.h"
  5. #include "util/rotation.h"
  6. #include "util/sigmoid.h"
  7. #include "util/signal.h"
  8. namespace DHE {
  9. class Swave : public rack::Module {
  10. public:
  11. Swave() : Module{PARAMETER_COUNT, INPUT_COUNT, OUTPUT_COUNT} {}
  12. void step() override {
  13. auto phase = Signal::bipolar_range.normalize(signal_in());
  14. auto shaped = Sigmoid::taper(phase, curve(), shape());
  15. auto out_voltage = Signal::bipolar_range.scale(shaped);
  16. send_signal(out_voltage);
  17. }
  18. enum ParameterIds { CURVE_KNOB, SHAPE_SWITCH, PARAMETER_COUNT };
  19. enum InputIds { CURVE_CV, MAIN_IN, INPUT_COUNT };
  20. enum OutputIds { MAIN_OUT, OUTPUT_COUNT };
  21. private:
  22. auto curve() const -> float {
  23. auto rotation = params[CURVE_KNOB].value;
  24. auto cv = inputs[CURVE_CV].value;
  25. return Rotation::modulated(rotation, cv);
  26. }
  27. void send_signal(float voltage) { outputs[MAIN_OUT].value = voltage; }
  28. auto shape() const -> float { return params[SHAPE_SWITCH].value; }
  29. auto signal_in() const -> float { return inputs[MAIN_IN].value; }
  30. };
  31. class SwavePanel : public Panel<SwavePanel> {
  32. public:
  33. explicit SwavePanel(Swave *module) : Panel{module, hp} {
  34. auto widget_right_edge = width();
  35. auto x = widget_right_edge / 2.f;
  36. auto y = 25.f;
  37. auto dy = 18.5f;
  38. install(x, y, toggle<2>(Swave::SHAPE_SWITCH, 1));
  39. y += dy;
  40. install(x, y, knob<LargeKnob>(Swave::CURVE_KNOB));
  41. y += dy;
  42. install(x, y, input(Swave::CURVE_CV));
  43. y = 82.f;
  44. dy = 15.f;
  45. y += dy;
  46. install(x, y, input(Swave::MAIN_IN));
  47. y += dy;
  48. install(x, y, output(Swave::MAIN_OUT));
  49. }
  50. static constexpr auto module_slug = "swave";
  51. public:
  52. static constexpr auto hp = 4;
  53. };
  54. } // namespace DHE
  55. RACK_PLUGIN_MODEL_INIT(DHE_Modules, Swave) {
  56. rack::Model *modelSwave = rack::Model::create<DHE::Swave, DHE::SwavePanel>(
  57. "DHE-Modules", "Swave", "Swave", rack::WAVESHAPER_TAG);
  58. return modelSwave;
  59. }