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.

67 lines
2.0KB

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