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.

62 lines
1.6KB

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