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.

57 lines
1.5KB

  1. #include "dsp/digital.hpp"
  2. #include "qwelk.hpp"
  3. #define CHANNELS 8
  4. struct ModuleOr : Module {
  5. enum ParamIds {
  6. NUM_PARAMS
  7. };
  8. enum InputIds {
  9. INPUT_CHANNEL,
  10. NUM_INPUTS = INPUT_CHANNEL + CHANNELS
  11. };
  12. enum OutputIds {
  13. OUTPUT_OR,
  14. NUM_OUTPUTS
  15. };
  16. enum LightIds {
  17. NUM_LIGHTS
  18. };
  19. ModuleOr() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS) {}
  20. void step() override;
  21. };
  22. void ModuleOr::step() {
  23. int gate_on = 0;
  24. for (int i = 0; !gate_on && i < CHANNELS; ++i)
  25. gate_on = inputs[INPUT_CHANNEL + i].value;
  26. outputs[OUTPUT_OR].value = gate_on ? 10 : 0;
  27. }
  28. WidgetOr::WidgetOr() {
  29. ModuleOr *module = new ModuleOr();
  30. setModule(module);
  31. box.size = Vec(2 * RACK_GRID_WIDTH, RACK_GRID_HEIGHT);
  32. {
  33. SVGPanel *panel = new SVGPanel();
  34. panel->box.size = box.size;
  35. panel->setBackground(SVG::load(assetPlugin(plugin, "res/Or.svg")));
  36. addChild(panel);
  37. }
  38. addChild(createScrew<ScrewSilver>(Vec(15, 0)));
  39. addChild(createScrew<ScrewSilver>(Vec(15, 365)));
  40. float x = box.size.x / 2.0 - 12, ytop = 45, ystep = 32.85;
  41. for (int i = 0; i < CHANNELS; ++i)
  42. addInput(createInput<PJ301MPort>(Vec(x, ytop + ystep * i), module, ModuleOr::INPUT_CHANNEL + i));
  43. ytop += 9;
  44. addOutput(createOutput<PJ301MPort>( Vec(x, ytop + ystep * CHANNELS), module, ModuleOr::OUTPUT_OR));
  45. }