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.

79 lines
1.2KB

  1. #include "common.hpp"
  2. ////////////////////
  3. // module widgets
  4. ////////////////////
  5. using namespace rack;
  6. #define plugin "TheXOR"
  7. namespace rack_plugin_TheXOR {
  8. #define NUM_MPLEX_INPUTS (8)
  9. struct Mplex;
  10. struct MplexWidget : ModuleWidget
  11. {
  12. MplexWidget(Mplex * module);
  13. private:
  14. float yncscape(float y, float height)
  15. {
  16. return RACK_GRID_HEIGHT - mm2px(y + height);
  17. }
  18. };
  19. struct Mplex : Module
  20. {
  21. enum ParamIds
  22. {
  23. BTUP, BTDN,
  24. NUM_PARAMS
  25. };
  26. enum InputIds
  27. {
  28. INUP,
  29. INDN,
  30. IN_1,
  31. NUM_INPUTS = IN_1 + NUM_MPLEX_INPUTS
  32. };
  33. enum OutputIds
  34. {
  35. OUT_1,
  36. NUM_OUTPUTS
  37. };
  38. enum LightIds
  39. {
  40. LED_1,
  41. NUM_LIGHTS = LED_1 + NUM_MPLEX_INPUTS
  42. };
  43. Mplex() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS)
  44. {
  45. load();
  46. }
  47. void fromJson(json_t *root) override { Module::fromJson(root); on_loaded(); }
  48. json_t *toJson() override
  49. {
  50. json_t *rootJ = json_object();
  51. return rootJ;
  52. }
  53. void step() override;
  54. void reset() override { load(); }
  55. void randomize() override
  56. {
  57. set_output((int)roundf(rescale(randomUniform(), 0.0, 1.0, 0, NUM_MPLEX_INPUTS)));
  58. }
  59. private:
  60. void load();
  61. void on_loaded();
  62. void set_output(int n);
  63. int cur_sel;
  64. SchmittTrigger upTrigger;
  65. SchmittTrigger dnTrigger;
  66. };
  67. } // namespace rack_plugin_TheXOR