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.

83 lines
1.3KB

  1. #pragma once
  2. namespace rack_plugin_TheXOR {
  3. struct Renato;
  4. extern bool Access(Renato *pr, bool is_x, int p);
  5. struct rntSequencer
  6. {
  7. public:
  8. void Reset()
  9. {
  10. curPos = 0;
  11. pp_rev = false;
  12. }
  13. int Position() { return curPos; }
  14. int Step(float clock, float count_mode, bool seek_mode, Renato *pr, bool is_x)
  15. {
  16. int clk = clockTrig.process(clock); // 1=rise, -1=fall
  17. if(clk == 1)
  18. {
  19. int attempts = 0;
  20. do
  21. {
  22. switch((int)std::roundf(count_mode))
  23. {
  24. case 0: // fwd:
  25. if(++curPos > 3)
  26. curPos = 0;
  27. break;
  28. case 1: // bwd
  29. if(--curPos < 0)
  30. curPos = 3;
  31. break;
  32. case 2: //pend
  33. if(pp_rev)
  34. {
  35. if(--curPos < 0)
  36. {
  37. curPos = 1;
  38. pp_rev = !pp_rev;
  39. }
  40. } else
  41. {
  42. if(++curPos > 3)
  43. {
  44. curPos = 2;
  45. pp_rev = !pp_rev;
  46. }
  47. }
  48. break;
  49. }
  50. attempts++;
  51. } while(!Access(pr, is_x, curPos) && seek_mode && attempts < 4);
  52. }
  53. return clk;
  54. }
  55. bool Gate(int clk, Output *output, Light *led)
  56. {
  57. if(clk == 1) // rise
  58. {
  59. led->value = output->value = LVL_ON;
  60. } else if(clk == -1) // fall
  61. {
  62. led->value = output->value = LVL_OFF;
  63. }
  64. return clk == 1;
  65. }
  66. private:
  67. SchmittTrigger2 clockTrig;
  68. int curPos;
  69. bool pp_rev;
  70. };
  71. } // namespace rack_plugin_TheXOR