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.

104 lines
1.7KB

  1. #include "common.hpp"
  2. ////////////////////
  3. // module widgets
  4. ////////////////////
  5. using namespace rack;
  6. #define plugin "TheXOR"
  7. namespace rack_plugin_TheXOR {
  8. struct Burst;
  9. struct BurstWidget : SequencerWidget
  10. {
  11. BurstWidget(Burst * module);
  12. };
  13. #define NUM_BURST_PORTS (6)
  14. struct Burst : Module
  15. {
  16. enum ParamIds
  17. {
  18. OUT_SPAN,
  19. EVENT_COUNT,
  20. MODE,
  21. MODE_INVERT,
  22. TRIGGER,
  23. TRIG_THRESH,
  24. NUM_PARAMS
  25. };
  26. enum InputIds
  27. {
  28. CLOCK_IN,
  29. OUT_SPAN_IN,
  30. EVENT_COUNT_IN,
  31. TRIGGER_THRESH_IN,
  32. RESET,
  33. NUM_INPUTS
  34. };
  35. enum OutputIds
  36. {
  37. OUT_1,
  38. NUM_OUTPUTS = OUT_1 + NUM_BURST_PORTS
  39. };
  40. enum LightIds
  41. {
  42. LEDOUT_1,
  43. NUM_LIGHTS = LEDOUT_1 + NUM_BURST_PORTS
  44. };
  45. Burst() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS)
  46. {
  47. }
  48. void step() override;
  49. void reset() override { load(); }
  50. void fromJson(json_t *root) override { Module::fromJson(root); on_loaded(); }
  51. json_t *toJson() override
  52. {
  53. json_t *rootJ = json_object();
  54. return rootJ;
  55. };
  56. private:
  57. void on_loaded();
  58. void load();
  59. void all_off();
  60. int getInt(ParamIds p_id, InputIds i_id, float minValue, float maxValue);
  61. void prepare_step();
  62. void next_step();
  63. void end_step();
  64. void port(int n, bool on) { lights[LEDOUT_1 + n].value = outputs[OUT_1 + n].value = on ? LVL_ON : LVL_OFF; }
  65. void invert_port(int n) { port(n, outputs[OUT_1 + n].value < LVL_ON); }
  66. private:
  67. SchmittTrigger2 clock;
  68. SchmittTrigger trigger;
  69. SchmittTrigger resetTrigger;
  70. bool active;
  71. bool trigger_pending;
  72. enum MODE
  73. {
  74. FWD = 0,
  75. PEND = 1,
  76. RAND = 2
  77. };
  78. struct
  79. {
  80. int cycle_counter;
  81. int max_cycle;
  82. int out_span;
  83. int max_span;
  84. enum MODE mode;
  85. bool invert_mode;
  86. bool retrogade;
  87. bool first_cycle;
  88. } activating_params;
  89. };
  90. } // namespace rack_plugin_TheXOR