From c9bb9c4d9f9ac17e794af91e5677f5a1df951c85 Mon Sep 17 00:00:00 2001 From: midilab Date: Fri, 22 Sep 2023 10:44:08 -0300 Subject: [PATCH] fix shuffle edge case for +5 tick --- src/uClock.cpp | 59 +++++++++++++++++++++++++------------------------- src/uClock.h | 2 +- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/uClock.cpp b/src/uClock.cpp index 292d8de..e7ec515 100755 --- a/src/uClock.cpp +++ b/src/uClock.cpp @@ -278,6 +278,36 @@ int8_t uClockClass::getShuffleLength() return shuffle_length_ctrl; } +int8_t inline uClockClass::processShuffle() +{ + int8_t mod6_shuffle_counter; + if (!shuffle.active) { + mod6_shuffle_counter = mod6_counter; + } else { + // apply shuffle template to step + int8_t shff = shuffle.step[div16th_counter%shuffle.size]; + // keep track of next note shuffle for current note lenght control + shuffle_length_ctrl = shuffle.step[(div16th_counter+1)%shuffle.size]; + // prepare the next mod6 quantize to be called + if (shff == 0) { + mod6_shuffle_counter = mod6_counter; + } else if (shff > 0) { + if (shuffle_shoot_ctrl == false && mod6_counter > shff || (shff == 5 && mod6_counter == 0)) + shuffle_shoot_ctrl = true; + mod6_shuffle_counter = shuffle_shoot_ctrl ? mod6_counter - shff : 1; + shuffle_length_ctrl -= shff; + } else if (shff < 0) { + if (shuffle_shoot_ctrl == false && mod6_counter == 0) + shuffle_shoot_ctrl = true; + mod6_shuffle_counter = shff - mod6_counter == -6 ? shuffle_shoot_ctrl ? 0 : 1 : 1; + shuffle_length_ctrl += shff; + } + } + if (shuffle_length_ctrl == 0) + shuffle_length_ctrl = 1; + return mod6_shuffle_counter; +} + void uClockClass::handleExternalClock() { @@ -391,35 +421,6 @@ void uClockClass::handleTimerInt() } } -uint8_t inline uClockClass::processShuffle() -{ - uint8_t mod6_shuffle_counter; - if (!shuffle.active) { - mod6_shuffle_counter = mod6_counter; - } else { - // apply shuffle template to step - int8_t shff = shuffle.step[div16th_counter%shuffle.size]; - // keep track of next note shuffle for current note lenght control - shuffle_length_ctrl = shuffle.step[(div16th_counter+1)%shuffle.size]; - // prepare the next mod6 quantize to be called - if (shff == 0) { - mod6_shuffle_counter = mod6_counter; - shuffle_length_ctrl += shff; - } else if (shff > 0) { - if (shuffle_shoot_ctrl == false && mod6_counter > shff) - shuffle_shoot_ctrl = true; - mod6_shuffle_counter = shuffle_shoot_ctrl ? mod6_counter - shff : 1; - shuffle_length_ctrl -= shff; - } else if (shff < 0) { - if (shuffle_shoot_ctrl == false && mod6_counter == 0) - shuffle_shoot_ctrl = true; - mod6_shuffle_counter = shff - mod6_counter == -6 ? shuffle_shoot_ctrl ? 0 : 1 : 1; - shuffle_length_ctrl += shff; - } - } - return mod6_shuffle_counter; -} - // elapsed time support uint8_t uClockClass::getNumberOfSeconds(uint32_t time) { diff --git a/src/uClock.h b/src/uClock.h index 6ea32cf..b6e2e95 100755 --- a/src/uClock.h +++ b/src/uClock.h @@ -66,7 +66,7 @@ private: float inline freqToBpm(uint32_t freq); // shuffle - uint8_t inline processShuffle(); + int8_t inline processShuffle(); void (*onClock96PPQNCallback)(uint32_t tick); void (*onClock32PPQNCallback)(uint32_t tick);