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.

103 lines
1.8KB

  1. #include "common.hpp"
  2. ////////////////////
  3. // module widgets
  4. ////////////////////
  5. using namespace rack;
  6. #define plugin "TheXOR"
  7. namespace rack_plugin_TheXOR {
  8. struct Uncertain;
  9. struct UncertainWidget : SequencerWidget
  10. {
  11. UncertainWidget(Uncertain *module);
  12. };
  13. struct Uncertain : Module
  14. {
  15. static constexpr float SEMITONE = 1.0 / 12.0;// 1/12 V
  16. static constexpr float MIN_VOLTAGE = 1.0 / 96.0;// 1/96 V
  17. static constexpr float MAX_VOLTAGE = 10.0; // 10V
  18. enum ParamIds
  19. {
  20. FLUCT_AMT,
  21. QUANTIZED_AMT,
  22. STORED_AMT,
  23. CURVEAMP_AMT,
  24. NUM_PARAMS
  25. };
  26. enum InputIds
  27. {
  28. CLOCK_FLUCT,
  29. IN_FLUCT,
  30. CLOCK_QUANTIZED,
  31. IN_QUANTIZED,
  32. CLOCK_STORED,
  33. IN_STORED,
  34. IN_CURVEAMP,
  35. NUM_INPUTS
  36. };
  37. enum OutputIds
  38. {
  39. OUT_FLUCT,
  40. OUT_QUANTIZED_N1,
  41. OUT_QUANTIZED_2N,
  42. OUT_STORED_RND,
  43. OUT_STORED_BELL,
  44. NUM_OUTPUTS
  45. };
  46. enum LightIds
  47. {
  48. NUM_LIGHTS
  49. };
  50. Uncertain() : Module(NUM_PARAMS, NUM_INPUTS, NUM_OUTPUTS, NUM_LIGHTS)
  51. {
  52. }
  53. void step() override;
  54. void reset() override { load(); }
  55. void fromJson(json_t *root) override { Module::fromJson(root); on_loaded(); }
  56. json_t *toJson() override
  57. {
  58. json_t *rootJ = json_object();
  59. return rootJ;
  60. };
  61. private:
  62. void on_loaded();
  63. void load();
  64. void out_quantized(int clk);
  65. void out_stored(int clk);
  66. void out_fluct(int clk);
  67. int getInt(ParamIds p_id, InputIds i_id, float minValue, float maxValue) { return (int)getFloat(p_id, i_id, minValue, maxValue); }
  68. float getFloat(ParamIds p_id, InputIds i_id, float minValue, float maxValue);
  69. float rndFluctVoltage();
  70. float rndGaussianVoltage();
  71. private:
  72. SchmittTrigger2 clock_fluct;
  73. SchmittTrigger2 clock_quantized;
  74. SchmittTrigger2 clock_stored;
  75. struct fluct_params
  76. {
  77. float vA;
  78. float vB;
  79. float deltaV;
  80. clock_t tStart;
  81. clock_t duration;
  82. void reset()
  83. {
  84. duration = tStart = 0;
  85. vA = deltaV = 0;
  86. }
  87. } fluctParams;
  88. };
  89. } // namespace rack_plugin_TheXOR