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.

151 lines
2.3KB

  1. #pragma once
  2. #include "common.hpp"
  3. #include <algorithm>
  4. namespace rack_plugin_TheXOR {
  5. struct Klee;
  6. struct KleeWidget : SequencerWidget
  7. {
  8. private:
  9. enum MENUACTIONS
  10. {
  11. RANDOMIZE_BUS,
  12. RANDOMIZE_PITCH,
  13. RANDOMIZE_LOAD,
  14. SET_RANGE_1V
  15. };
  16. Menu *addContextMenu(Menu *menu) override;
  17. public:
  18. KleeWidget(Klee *module);
  19. void onMenu(int action);
  20. };
  21. struct Klee : Module
  22. {
  23. enum ParamIds
  24. {
  25. PITCH_KNOB,
  26. GROUPBUS = PITCH_KNOB + 16,
  27. LOAD_BUS = GROUPBUS + 16,
  28. LOAD_PARAM = LOAD_BUS + 16,
  29. STEP_PARAM,
  30. X28_X16,
  31. RND_PAT,
  32. B_INV,
  33. RND_THRESHOLD,
  34. BUS1_LOAD,
  35. BUS_MERGE,
  36. RANGE = BUS_MERGE + 3,
  37. BUS2_MODE,
  38. NUM_PARAMS
  39. };
  40. enum InputIds
  41. {
  42. LOAD_INPUT,
  43. EXT_CLOCK_INPUT,
  44. RND_THRES_IN,
  45. RANGE_IN,
  46. NUM_INPUTS
  47. };
  48. enum OutputIds
  49. {
  50. CV_A,
  51. CV_B,
  52. CV_AB,
  53. CV_A__B,
  54. GATE_OUT,
  55. TRIG_OUT = GATE_OUT + 3,
  56. temp = TRIG_OUT + 3,
  57. NUM_OUTPUTS
  58. };
  59. enum LightIds
  60. {
  61. LED_PITCH,
  62. LED_BUS = LED_PITCH + 16,
  63. temp1 = LED_BUS + 3,
  64. NUM_LIGHTS
  65. };
  66. Klee() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS)
  67. {
  68. #ifdef LAUNCHPAD
  69. drv = new LaunchpadBindingDriver(this, Scene1, 1);
  70. #endif
  71. #ifdef OSCTEST_MODULE
  72. oscDrv = new OSCDriver(this, 1);
  73. #endif
  74. on_loaded();
  75. }
  76. #ifdef DIGITAL_EXT
  77. ~Klee()
  78. {
  79. #if defined(LAUNCHPAD)
  80. delete drv;
  81. #endif
  82. #if defined(OSCTEST_MODULE)
  83. delete oscDrv;
  84. #endif
  85. }
  86. #endif
  87. void fromJson(json_t *root) override { Module::fromJson(root); on_loaded(); }
  88. json_t *toJson() override
  89. {
  90. json_t *rootJ = json_object();
  91. return rootJ;
  92. }
  93. void step() override;
  94. void reset() override { load(); }
  95. void randomize() override { load(); }
  96. #ifdef DIGITAL_EXT
  97. float connected;
  98. #endif
  99. #ifdef LAUNCHPAD
  100. LaunchpadBindingDriver *drv;
  101. #endif
  102. #if defined(OSCTEST_MODULE)
  103. OSCDriver *oscDrv;
  104. #endif
  105. private:
  106. const float pulseTime = 0.002; //2msec trigger
  107. void showValues();
  108. void sr_rotate();
  109. bool chance();
  110. void populate_gate(int clk);
  111. void update_bus();
  112. void load();
  113. void on_loaded();
  114. void populate_outputs();
  115. void check_triggers(float deltaTime);
  116. bool isSwitchOn(int ptr);
  117. int getValue3(int k);
  118. SchmittTrigger loadTrigger;
  119. SchmittTrigger2 clockTrigger;
  120. PulseGenerator triggers[3];
  121. union
  122. {
  123. struct
  124. {
  125. bool A[8];
  126. bool B[8];
  127. };
  128. bool P[16];
  129. } shiftRegister;
  130. bool bus_active[3];
  131. };
  132. } // namespace rack_plugin_TheXOR