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.

134 lines
3.4KB

  1. //***********************************************************************************************
  2. //Impromptu Modular: Modules for VCV Rack by Marc Boulé
  3. //***********************************************************************************************
  4. #include "PhraseSeqUtil.hpp"
  5. namespace rack_plugin_ImpromptuModular {
  6. int moveIndex(int index, int indexNext, int numSteps) {
  7. if (indexNext < 0)
  8. index = numSteps - 1;
  9. else
  10. {
  11. if (indexNext - index >= 0) { // if moving right or same place
  12. if (indexNext >= numSteps)
  13. index = 0;
  14. else
  15. index = indexNext;
  16. }
  17. else { // moving left
  18. if (indexNext >= numSteps)
  19. index = numSteps - 1;
  20. else
  21. index = indexNext;
  22. }
  23. }
  24. return index;
  25. }
  26. bool moveIndexRunMode(int* index, int numSteps, int runMode, int* history) {
  27. bool crossBoundary = false;
  28. int numRuns;// for FWx
  29. switch (runMode) {
  30. case MODE_REV :// reverse; history base is 1000 (not needed)
  31. (*history) = 1000;
  32. (*index)--;
  33. if ((*index) < 0) {
  34. (*index) = numSteps - 1;
  35. crossBoundary = true;
  36. }
  37. break;
  38. case MODE_PPG :// forward-reverse; history base is 2000
  39. if ((*history) != 2000 && (*history) != 2001) // 2000 means going forward, 2001 means going reverse
  40. (*history) = 2000;
  41. if ((*history) == 2000) {// forward phase
  42. (*index)++;
  43. if ((*index) >= numSteps) {
  44. (*index) = numSteps - 1;
  45. (*history) = 2001;
  46. }
  47. }
  48. else {// it is 2001; reverse phase
  49. (*index)--;
  50. if ((*index) < 0) {
  51. (*index) = 0;
  52. (*history) = 2000;
  53. crossBoundary = true;
  54. }
  55. }
  56. break;
  57. case MODE_BRN :// brownian random; history base is 3000
  58. if ( (*history) < 3000 || ((*history) > (3000 + numSteps)) )
  59. (*history) = 3000 + numSteps;
  60. (*index) += (randomu32() % 3) - 1;
  61. if ((*index) >= numSteps) {
  62. (*index) = 0;
  63. }
  64. if ((*index) < 0) {
  65. (*index) = numSteps - 1;
  66. }
  67. (*history)--;
  68. if ((*history) <= 3000) {
  69. (*history) = 3000 + numSteps;
  70. crossBoundary = true;
  71. }
  72. break;
  73. case MODE_RND :// random; history base is 4000
  74. if ( (*history) < 4000 || ((*history) > (4000 + numSteps)) )
  75. (*history) = 4000 + numSteps;
  76. (*index) = (randomu32() % numSteps) ;
  77. (*history)--;
  78. if ((*history) <= 4000) {
  79. (*history) = 4000 + numSteps;
  80. crossBoundary = true;
  81. }
  82. break;
  83. case MODE_FW2 :// forward twice
  84. case MODE_FW3 :// forward three times
  85. case MODE_FW4 :// forward four times
  86. numRuns = 5002 + runMode - MODE_FW2;
  87. if ( (*history) < 5000 || (*history) >= numRuns ) // 5000 means first pass, 5001 means 2nd pass, etc...
  88. (*history) = 5000;
  89. (*index)++;
  90. if ((*index) >= numSteps) {
  91. (*index) = 0;
  92. (*history)++;
  93. if ((*history) >= numRuns) {
  94. (*history) = 5000;
  95. crossBoundary = true;
  96. }
  97. }
  98. break;
  99. default :// MODE_FWD forward; history base is 0 (not needed)
  100. (*history) = 0;
  101. (*index)++;
  102. if ((*index) >= numSteps) {
  103. (*index) = 0;
  104. crossBoundary = true;
  105. }
  106. }
  107. return crossBoundary;
  108. }
  109. int keyIndexToGateMode(int keyIndex, int pulsesPerStep) {
  110. if (pulsesPerStep == 4 && (keyIndex == 1 || keyIndex == 3 || keyIndex == 6 || keyIndex == 8 || keyIndex == 10))
  111. return -1;
  112. if (pulsesPerStep == 6 && (keyIndex == 0 || keyIndex == 4 || keyIndex == 7 || keyIndex == 9))
  113. return -1;
  114. return keyIndex;// keyLight index now matches gate modes, so no mapping table needed anymore
  115. }
  116. } // namespace rack_plugin_ImpromptuModular