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.

75 lines
1.9KB

  1. #include "dsp/digital.hpp"
  2. #include "qwelk.hpp"
  3. #define CHANNELS 8
  4. namespace rack_plugin_Qwelk {
  5. struct ModuleWrap : Module {
  6. enum ParamIds {
  7. NUM_PARAMS
  8. };
  9. enum InputIds {
  10. IN_WRAP,
  11. IN_SIG,
  12. NUM_INPUTS = IN_SIG + CHANNELS
  13. };
  14. enum OutputIds {
  15. OUT_WRAPPED,
  16. NUM_OUTPUTS = OUT_WRAPPED + CHANNELS
  17. };
  18. enum LightIds {
  19. NUM_LIGHTS
  20. };
  21. int _wrap = -10;
  22. ModuleWrap() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  23. void step() override;
  24. };
  25. void ModuleWrap::step() {
  26. int wrap = (/*clampf(*/inputs[IN_WRAP].value/*, -5.0, 5.0)*/ / 5.0) * (CHANNELS - 1);
  27. for (int i = 0; i < CHANNELS; ++i) {
  28. int w = i;
  29. if (wrap > 0)
  30. w = (i + wrap) % CHANNELS;
  31. else if (wrap < 0)
  32. w = (i + CHANNELS - wrap) % CHANNELS;
  33. outputs[OUT_WRAPPED + i].value = inputs[IN_SIG + w].value;
  34. }
  35. }
  36. struct WidgetWrap : ModuleWidget {
  37. WidgetWrap(ModuleWrap *module);
  38. };
  39. WidgetWrap::WidgetWrap(ModuleWrap *module) : ModuleWidget(module) {
  40. setPanel(SVG::load(assetPlugin(plugin, "res/Wrap.svg")));
  41. addChild(Widget::create<ScrewSilver>(Vec(15, 0)));
  42. addChild(Widget::create<ScrewSilver>(Vec(15, 365)));
  43. float x = box.size.x / 2.0 - 25, ytop = 60, ystep = 39;
  44. addInput(Port::create<PJ301MPort>(Vec(17.5, 30), Port::INPUT, module, ModuleWrap::IN_WRAP));
  45. for (int i = 0; i < CHANNELS; ++i) {
  46. addInput(Port::create<PJ301MPort>( Vec(x , ytop + ystep * i), Port::INPUT, module, ModuleWrap::IN_SIG + i));
  47. addOutput(Port::create<PJ301MPort>( Vec(x + 26 , ytop + ystep * i), Port::OUTPUT, module, ModuleWrap::OUT_WRAPPED + i));
  48. }
  49. }
  50. } // namespace rack_plugin_Qwelk
  51. using namespace rack_plugin_Qwelk;
  52. RACK_PLUGIN_MODEL_INIT(Qwelk, Wrap) {
  53. Model *modelWrap = Model::create<ModuleWrap, WidgetWrap>(
  54. TOSTRING(SLUG), "Wrap", "Wrap", UTILITY_TAG);
  55. return modelWrap;
  56. }