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.

161 lines
6.5KB

  1. #ifndef MODULE_VOLTSEQ_HPP
  2. #define MODULE_VOLTSEQ_HPP
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include "dsp/digital.hpp"
  6. #include "trowaSoftComponents.hpp"
  7. #include "trowaSoftUtilities.hpp"
  8. #include "TSSequencerModuleBase.hpp"
  9. #define voltSeq_STEP_KNOB_MIN -10.0 // Minimum value from our knobs
  10. #define voltSeq_STEP_KNOB_MAX 10.0 // Maximum value from our knobs
  11. // voltSeq model.
  12. extern Model *modelVoltSeq;
  13. //===============================================================================
  14. //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  15. // voltSeq Module
  16. // trowaSoft knob / voltage sequencer.
  17. //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  18. //===============================================================================
  19. // [11/28/2017]: Change knobStepMatrix for allowing for > the standard # steps (16).
  20. struct voltSeq : TSSequencerModuleBase
  21. {
  22. // References to our pad knobs.
  23. // We may have > 16 steps in the future, so no more static matrix.
  24. TS_LightedKnob*** knobStepMatrix;
  25. // Array of values of what we last sent over OSC (for comparison).
  26. float* oscLastSentVals = NULL;
  27. ValueSequencerMode* ValueModes[TROWA_SEQ_NUM_MODES] = {
  28. // Voltage Mode
  29. new ValueSequencerMode(/*displayName*/ "VOLT",
  30. /*minDisplayValue*/ -10, /*maxDisplayValue*/ 10,
  31. /*inVoltageMin*/ voltSeq_STEP_KNOB_MIN, /*inVoltageMax*/ voltSeq_STEP_KNOB_MAX,
  32. /*outVoltageMin*/ -10, /*outVoltageMax*/ 10,
  33. /*whole numbers*/ false,
  34. /*zeroPointAngle*/ TROWA_ANGLE_STRAIGHT_UP_RADIANS,
  35. /*display format String */ "%04.2f",
  36. /*roundDisplay*/ 0, /*roundOutput*/ 0,
  37. /*zeroValue*/ (voltSeq_STEP_KNOB_MAX+voltSeq_STEP_KNOB_MIN)/2.0),
  38. // Note mode (1 octave per V; 10 octaves)
  39. new NoteValueSequencerMode(/*displayName*/ "NOTE",
  40. /*inVoltageMin*/ voltSeq_STEP_KNOB_MIN, /*inVoltageMax*/ voltSeq_STEP_KNOB_MAX),
  41. // Sequence Mode (1-64 for the patterns)
  42. new ValueSequencerMode(/*displayName*/ "PATT",
  43. /*minDisplayValue*/ 1, /*maxDisplayValue*/ TROWA_SEQ_NUM_PATTERNS,
  44. /*inVoltageMin*/ voltSeq_STEP_KNOB_MIN, /*inVoltageMax*/ voltSeq_STEP_KNOB_MAX,
  45. /*outVoltageMin*/ TROWA_SEQ_PATTERN_MIN_V, /*outVoltageMax*/ TROWA_SEQ_PATTERN_MAX_V,
  46. /*whole numbers*/ false,
  47. /*zeroPointAngle*/ 0.67*NVG_PI,
  48. /*display format String */ "%02.0f",
  49. /*roundDisplay*/ 0, /*roundOutput*/ 0,
  50. /*zeroValue*/ voltSeq_STEP_KNOB_MIN)
  51. };
  52. voltSeq(int numSteps, int numRows, int numCols) : TSSequencerModuleBase(numSteps, numRows, numCols, /*default val*/ 0.0) // Now default to 0 instead of -10
  53. {
  54. selectedOutputValueMode = VALUE_VOLT;
  55. lastOutputValueMode = selectedOutputValueMode;
  56. modeStrings[0] = "VOLT";
  57. modeStrings[1] = "NOTE";
  58. modeStrings[2] = "PATT";
  59. numStructuredRandomPatterns = TROWA_SEQ_NUM_RANDOM_PATTERNS; // voltSeq can use the full range of random patterns.
  60. knobStepMatrix = new TS_LightedKnob**[numRows];
  61. for (int r = 0; r < numRows; r++)
  62. {
  63. knobStepMatrix[r] = new TS_LightedKnob*[numCols];
  64. }
  65. oscLastSentVals = new float[numSteps];
  66. for (int s = 0; s < numSteps; s++)
  67. {
  68. oscLastSentVals[s] = voltSeq_STEP_KNOB_MIN - 1.0;
  69. }
  70. return;
  71. }
  72. voltSeq() : voltSeq(TROWA_SEQ_NUM_STEPS, TROWA_SEQ_STEP_NUM_ROWS, TROWA_SEQ_STEP_NUM_ROWS)
  73. {
  74. return;
  75. }
  76. ~voltSeq()
  77. {
  78. for (int r = 0; r < numRows; r++)
  79. {
  80. delete[] knobStepMatrix[r];
  81. knobStepMatrix[r] = NULL;
  82. }
  83. delete [] knobStepMatrix;
  84. knobStepMatrix = NULL;
  85. delete [] oscLastSentVals;
  86. }
  87. //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  88. // fromJson(void)
  89. // Read in our junk from json.
  90. //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  91. void fromJson(json_t *rootJ) override {
  92. TSSequencerModuleBase::fromJson(rootJ);
  93. //// Check for old version and try to do graceful conversion from -5 to +5V
  94. //// in Note Mode to -4 to +6V
  95. //if (saveVersion < 7 && selectedOutputValueMode == ValueMode::VALUE_MIDINOTE)
  96. //{
  97. // this->shiftValues(TROWA_INDEX_UNDEFINED, TROWA_INDEX_UNDEFINED, 1.0);
  98. //}
  99. return;
  100. }
  101. //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  102. // Set a single the step value
  103. // (i.e. this command probably comes from an external source).
  104. // >> Should set the control knob value too if applicable. <<
  105. // @step : (IN) The step number to edit (0 to maxSteps).
  106. // @val : (IN) The step value.
  107. // @channel : (IN) The channel to edit (0 to TROWA_SEQ_NUM_CHNLS - 1).
  108. // @pattern: (IN) The pattern to edit (0 to TROWA_SEQ_NUM_PATTERNS - 1).
  109. //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  110. void setStepValue(int step, float val, int channel, int pattern) override;
  111. void step() override;
  112. // Only randomize the current gate/trigger steps.
  113. void randomize() override;
  114. //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  115. // getRandomValue()
  116. // Get a random value for a step in this sequencer.
  117. //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  118. float getRandomValue() override {
  119. return voltSeq_STEP_KNOB_MIN + randomUniform()*(voltSeq_STEP_KNOB_MAX - voltSeq_STEP_KNOB_MIN);
  120. }
  121. //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  122. // onShownStepChange()
  123. // If we changed a step that is shown on the matrix, then do something.
  124. // For voltSeq to adjust the knobs so we dont' read the old knob values again.
  125. //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  126. void onShownStepChange(int step, float val) override {
  127. this->params[CHANNEL_PARAM + step].value = val;
  128. int r = step / numRows;
  129. int c = step % numRows;
  130. knobStepMatrix[r][c]->setKnobValue(val);
  131. return;
  132. }
  133. // Get the toggle step value
  134. float getToggleStepValue(int step, float val, int channel, int pattern) override;
  135. // Calculate a representation of all channels for this step
  136. float getPlayingStepValue(int step, int pattern) override;
  137. //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  138. // Shift all steps (+/-) some number of volts.
  139. // @patternIx : (IN) The index into our pattern matrix (0-15). Or TROWA_INDEX_UNDEFINED for all patterns.
  140. // @channelIx : (IN) The index of the channel (gate/trigger/voice) if any (0-15, or TROWA_SEQ_COPY_CHANNELIX_ALL/TROWA_INDEX_UNDEFINED for all).
  141. // @volts: (IN) The number of volts to add.
  142. //-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
  143. void shiftValues(/*in*/ int patternIx, /*in*/ int channelIx, /*in*/ float volts);
  144. };
  145. #endif // end if not defined