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.

74 lines
2.4KB

  1. #include "qwelk.hpp"
  2. #include "qwelk_common.h"
  3. #define CHANNELS 2
  4. namespace rack_plugin_Qwelk {
  5. struct ModuleGate : Module {
  6. enum ParamIds {
  7. PARAM_GATEMODE,
  8. PARAM_THRESHOLD = PARAM_GATEMODE + CHANNELS,
  9. PARAM_OUTGAIN = PARAM_THRESHOLD + CHANNELS,
  10. NUM_PARAMS = PARAM_OUTGAIN + CHANNELS
  11. };
  12. enum InputIds {
  13. IN_SIG,
  14. NUM_INPUTS = IN_SIG + CHANNELS
  15. };
  16. enum OutputIds {
  17. OUT_GATE,
  18. NUM_OUTPUTS = OUT_GATE + CHANNELS
  19. };
  20. enum LightIds {
  21. NUM_LIGHTS
  22. };
  23. ModuleGate() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  24. void step() override;
  25. };
  26. void ModuleGate::step() {
  27. for (int i = 0; i < CHANNELS; ++i) {
  28. bool gatemode = params[PARAM_GATEMODE + i].value > 0.0;
  29. float in = inputs[IN_SIG + i].value;
  30. float threshold = params[PARAM_THRESHOLD + i].value;
  31. float out_gain = params[PARAM_OUTGAIN + i].value;
  32. float out = ((threshold >= 0) ? (in > threshold) : (in < threshold))
  33. ? (gatemode ? 10.0 : in) : 0.0;
  34. outputs[OUT_GATE + i].value = out * out_gain;
  35. }
  36. }
  37. struct WidgetGate : ModuleWidget {
  38. WidgetGate(ModuleGate *module);
  39. };
  40. WidgetGate::WidgetGate(ModuleGate *module) : ModuleWidget(module) {
  41. setPanel(SVG::load(assetPlugin(plugin, "res/Gate.svg")));
  42. addChild(Widget::create<ScrewSilver>(Vec(15, 0)));
  43. addChild(Widget::create<ScrewSilver>(Vec(15, 365)));
  44. for (int i = 0; i < CHANNELS; ++i) {
  45. float x = 2.5, top = 45 + i * 158;
  46. addParam(ParamWidget::create<CKSS>( Vec(x + 5.7, top + 8), module, ModuleGate::PARAM_GATEMODE + i, 0.0, 1.0, 1.0));
  47. addParam(ParamWidget::create<TinyKnob>(Vec(x + 2.5, top + 40), module, ModuleGate::PARAM_THRESHOLD + i, -10.0, 10.0, 0));
  48. addInput(Port::create<PJ301MPort>( Vec(x , top + 63), Port::INPUT, module, ModuleGate::IN_SIG + i));
  49. addParam(ParamWidget::create<TinyKnob>(Vec(x + 2.5, top + 102), module, ModuleGate::PARAM_OUTGAIN + i, -1.0, 1.0, 1.0));
  50. addOutput(Port::create<PJ301MPort>( Vec(x , top + 125), Port::OUTPUT, module, ModuleGate::OUT_GATE + i));
  51. }
  52. }
  53. } // namespace rack_plugin_Qwelk
  54. using namespace rack_plugin_Qwelk;
  55. RACK_PLUGIN_MODEL_INIT(Qwelk, Gate) {
  56. Model *modelGate = Model::create<ModuleGate, WidgetGate>(
  57. TOSTRING(SLUG), "Gate", "Gate", UTILITY_TAG, ATTENUATOR_TAG);
  58. return modelGate;
  59. }