Initial non-working commit of shuffle behavior. This change exposed a bug that seems to be calling each "processClockTick" method twice per tick.

This commit is contained in:
2025-06-19 09:32:41 -07:00
parent 54999d6525
commit df1a499fa0
6 changed files with 62 additions and 5 deletions

View File

@ -210,6 +210,9 @@ void editChannelParameter(int val) {
case PARAM_CH_OFFSET: case PARAM_CH_OFFSET:
ch.setOffset(ch.getOffset() + val); ch.setOffset(ch.getOffset() + val);
break; break;
case PARAM_CH_SHUFFLE:
ch.setShuffleIndex(ch.getShuffleIndex() + val);
break;
case PARAM_CH_CV_SRC: { case PARAM_CH_CV_SRC: {
int source = static_cast<int>(ch.getCvSource()); int source = static_cast<int>(ch.getCvSource());
updateSelection(source, val, CV_LAST); updateSelection(source, val, CV_LAST);

View File

@ -14,6 +14,7 @@ struct AppState {
int selected_param = 0; int selected_param = 0;
int selected_sub_param = 0; int selected_sub_param = 0;
byte selected_channel = 0; // 0=tempo, 1-6=output channel byte selected_channel = 0; // 0=tempo, 1-6=output channel
byte selected_shuffle = 0; // index into shuffle template
Clock::Source selected_source = Clock::SOURCE_INTERNAL; Clock::Source selected_source = Clock::SOURCE_INTERNAL;
Channel channel[Gravity::OUTPUT_COUNT]; Channel channel[Gravity::OUTPUT_COUNT];
}; };
@ -37,6 +38,7 @@ enum ParamsChannelPage {
PARAM_CH_PROB, PARAM_CH_PROB,
PARAM_CH_DUTY, PARAM_CH_DUTY,
PARAM_CH_OFFSET, PARAM_CH_OFFSET,
PARAM_CH_SHUFFLE,
PARAM_CH_CV_SRC, PARAM_CH_CV_SRC,
PARAM_CH_CV_DEST, PARAM_CH_CV_DEST,
PARAM_CH_LAST, PARAM_CH_LAST,

View File

@ -27,6 +27,30 @@ static const int clock_mod[MOD_CHOICE_SIZE] = {-24, -12, -8, -6, -4, -3, -2, 1,
// This represents the number of clock pulses for a 96 PPQN clock source that match the above div/mult mods. // This represents the number of clock pulses for a 96 PPQN clock source that match the above div/mult mods.
static const int clock_mod_pulses[MOD_CHOICE_SIZE] = {4, 8, 12, 16, 24, 32, 48, 96, 192, 288, 384, 480, 576, 1152, 672, 768, 1536, 2304, 3072, 6144, 12288}; static const int clock_mod_pulses[MOD_CHOICE_SIZE] = {4, 8, 12, 16, 24, 32, 48, 96, 192, 288, 384, 480, 576, 1152, 672, 768, 1536, 2304, 3072, 6144, 12288};
static const int8_t shuffle_size = 2;
// MPC60 groove signatures?
static const int8_t shuffle_54[2] = {0, 2};
static const int8_t shuffle_58[2] = {0, 4};
static const int8_t shuffle_62[2] = {0, 6};
static const int8_t shuffle_66[2] = {0, 8};
static const int8_t shuffle_71[2] = {0, 10};
static const int8_t shuffle_75[2] = {0, 12};
// SWING Groove
static const int8_t swing_54[2] = {0, 1};
static const int8_t swing_58[2] = {-1, 1};
static const int8_t swing_62[2] = {-1, 2};
static const int8_t swing_66[2] = {-2, 2};
static const int8_t swing_71[2] = {-2, 3};
static const int8_t swing_75[2] = {-3, 3};
// static const String shuffle_name[6] = {"OFF", "54%", "58%", "62%", "66%", "71%"};
static const uint8_t SHUFFLE_SIZE = 6;
static const byte shuffle_amount[SHUFFLE_SIZE] = {54, 58, 62, 66, 71, 75};
static const int8_t* shuffle_templates[SHUFFLE_SIZE] = {shuffle_54, shuffle_58, shuffle_62, shuffle_66, shuffle_71, shuffle_75};
// static const int8_t* shuffle_templates[SHUFFLE_SIZE] = {swing_54, swing_58, swing_62, swing_66, swing_71, swing_75};
class Channel { class Channel {
public: public:
Channel() { Channel() {
@ -41,6 +65,8 @@ class Channel {
base_offset = 0; base_offset = 0;
cv_source = CV_NONE; cv_source = CV_NONE;
cv_destination = CV_DEST_NONE; cv_destination = CV_DEST_NONE;
shuffle_index = 0;
step_count = 0;
cvmod_clock_mod_index = base_clock_mod_index; cvmod_clock_mod_index = base_clock_mod_index;
cvmod_probability = base_probability; cvmod_probability = base_probability;
@ -56,6 +82,7 @@ class Channel {
void setProbability(int prob) { base_probability = constrain(prob, 0, 100); } void setProbability(int prob) { base_probability = constrain(prob, 0, 100); }
void setDutyCycle(int duty) { base_duty_cycle = constrain(duty, 1, 99); } void setDutyCycle(int duty) { base_duty_cycle = constrain(duty, 1, 99); }
void setOffset(int off) { base_offset = constrain(off, 0, 100); } void setOffset(int off) { base_offset = constrain(off, 0, 100); }
void setShuffleIndex(int val) { shuffle_index = constrain(val, 0, SHUFFLE_SIZE - 1); }
void setCvSource(CvSource source) { cv_source = source; } void setCvSource(CvSource source) { cv_source = source; }
void setCvDestination(CvDestination dest) { cv_destination = dest; } void setCvDestination(CvDestination dest) { cv_destination = dest; }
@ -64,11 +91,13 @@ class Channel {
int getProbability(bool withCvMod = false) const { return withCvMod ? cvmod_probability : base_probability; } int getProbability(bool withCvMod = false) const { return withCvMod ? cvmod_probability : base_probability; }
int getDutyCycle(bool withCvMod = false) const { return withCvMod ? cvmod_duty_cycle : base_duty_cycle; } int getDutyCycle(bool withCvMod = false) const { return withCvMod ? cvmod_duty_cycle : base_duty_cycle; }
int getOffset(bool withCvMod = false) const { return withCvMod ? cvmod_offset : base_offset; } int getOffset(bool withCvMod = false) const { return withCvMod ? cvmod_offset : base_offset; }
int getShuffleIndex() const { return shuffle_index; }
int getClockMod(bool withCvMod = false) const { return clock_mod[getClockModIndex(withCvMod)]; } int getClockMod(bool withCvMod = false) const { return clock_mod[getClockModIndex(withCvMod)]; }
int getClockModIndex(bool withCvMod = false) const { return withCvMod ? cvmod_clock_mod_index : base_clock_mod_index; } int getClockModIndex(bool withCvMod = false) const { return withCvMod ? cvmod_clock_mod_index : base_clock_mod_index; }
CvSource getCvSource() { return cv_source; } CvSource getCvSource() { return cv_source; }
CvDestination getCvDestination() { return cv_destination; } CvDestination getCvDestination() { return cv_destination; }
bool isCvModActive() const { return cv_source != CV_NONE && cv_destination != CV_DEST_NONE; } bool isCvModActive() const { return cv_source != CV_NONE && cv_destination != CV_DEST_NONE; }
int getStepCount() {return step_count;}
/** /**
* @brief Processes a clock tick and determines if the output should be high or low. * @brief Processes a clock tick and determines if the output should be high or low.
@ -81,17 +110,26 @@ class Channel {
const uint32_t duty_pulses = max((long)((mod_pulses * (100L - cvmod_duty_cycle)) / 100L), 1L); const uint32_t duty_pulses = max((long)((mod_pulses * (100L - cvmod_duty_cycle)) / 100L), 1L);
const uint32_t offset_pulses = (long)((mod_pulses * (100L - cvmod_offset)) / 100L); const uint32_t offset_pulses = (long)((mod_pulses * (100L - cvmod_offset)) / 100L);
const uint32_t current_tick_offset = tick + offset_pulses; uint32_t shuffle_pulses = 0;
if (step_count % 2 == 0) {
// shuffle_pulses = (long)((mod_pulses * (100L - shuffle_amount[shuffle_index])) / 100L);
shuffle_pulses = 4 * shuffle_templates[shuffle_index][1];
}
// Duty cycle high check const uint32_t current_tick_offset = tick + offset_pulses + shuffle_pulses;
// Step check
// TODO: Why is this incrementing twice?
if (current_tick_offset % mod_pulses == 0) { if (current_tick_offset % mod_pulses == 0) {
// Duty cycle high check
if (cvmod_probability >= random(0, 100)) { if (cvmod_probability >= random(0, 100)) {
step_count += 1;
output.High(); output.High();
} }
} }
// Duty cycle low check // Duty cycle low check
const uint32_t duty_cycle_end_tick = tick + duty_pulses + offset_pulses; const uint32_t duty_cycle_end_tick = tick + duty_pulses + offset_pulses + shuffle_pulses;
if (duty_cycle_end_tick % mod_pulses == 0) { if (duty_cycle_end_tick % mod_pulses == 0) {
output.Low(); output.Low();
} }
@ -131,11 +169,14 @@ class Channel {
} }
private: private:
uint32_t step_count;
// User-settable base values. // User-settable base values.
byte base_clock_mod_index; byte base_clock_mod_index;
byte base_probability; byte base_probability;
byte base_duty_cycle; byte base_duty_cycle;
byte base_offset; byte base_offset;
byte shuffle_index;
// Base value with cv mod applied. // Base value with cv mod applied.
byte cvmod_clock_mod_index; byte cvmod_clock_mod_index;

View File

@ -244,6 +244,14 @@ void DisplayChannelPage() {
sprintf(mainText, "%d%%", ch.getOffset(withCvMod)); sprintf(mainText, "%d%%", ch.getOffset(withCvMod));
subText = "SHIFT HIT"; subText = "SHIFT HIT";
break; break;
case PARAM_CH_SHUFFLE:
ch.getShuffleIndex() == 0
// ? sprintf(mainText, "OFF")
// TODO: why is this being incremented by 2?
? sprintf(mainText, "%d", ch.getStepCount())
: sprintf(mainText, "%d%%", shuffle_amount[ch.getShuffleIndex()]);
subText = "SHUFFLE";
break;
case PARAM_CH_CV_SRC: { case PARAM_CH_CV_SRC: {
switch (ch.getCvSource()) { switch (ch.getCvSource()) {
case CV_NONE: case CV_NONE:
@ -293,7 +301,7 @@ void DisplayChannelPage() {
// Draw Channel Page menu items // Draw Channel Page menu items
const char* menu_items[PARAM_CH_LAST] = { const char* menu_items[PARAM_CH_LAST] = {
"MOD", "PROBABILITY", "DUTY", "OFFSET", "CV SOURCE", "CV DEST"}; "MOD", "PROBABILITY", "DUTY", "OFFSET", "SHUFFLE", "CV SOURCE", "CV DEST"};
drawMenuItems(menu_items, PARAM_CH_LAST); drawMenuItems(menu_items, PARAM_CH_LAST);
} }

View File

@ -27,6 +27,7 @@ bool StateManager::initialize(AppState& app) {
ch.setProbability(saved_ch_state.base_probability); ch.setProbability(saved_ch_state.base_probability);
ch.setDutyCycle(saved_ch_state.base_duty_cycle); ch.setDutyCycle(saved_ch_state.base_duty_cycle);
ch.setOffset(saved_ch_state.base_offset); ch.setOffset(saved_ch_state.base_offset);
ch.setShuffleIndex(saved_ch_state.shuffle_index);
ch.setCvSource(static_cast<CvSource>(saved_ch_state.cv_source)); ch.setCvSource(static_cast<CvSource>(saved_ch_state.cv_source));
ch.setCvDestination(static_cast<CvDestination>(saved_ch_state.cv_destination)); ch.setCvDestination(static_cast<CvDestination>(saved_ch_state.cv_destination));
} }
@ -105,6 +106,7 @@ void StateManager::_saveState(const AppState& app) {
save_ch.base_probability = ch.getProbability(false); save_ch.base_probability = ch.getProbability(false);
save_ch.base_duty_cycle = ch.getDutyCycle(false); save_ch.base_duty_cycle = ch.getDutyCycle(false);
save_ch.base_offset = ch.getOffset(false); save_ch.base_offset = ch.getOffset(false);
save_ch.shuffle_index = ch.getShuffleIndex();
save_ch.cv_source = static_cast<byte>(ch.getCvSource()); save_ch.cv_source = static_cast<byte>(ch.getCvSource());
save_ch.cv_destination = static_cast<byte>(ch.getCvDestination()); save_ch.cv_destination = static_cast<byte>(ch.getCvDestination());
} }

View File

@ -9,7 +9,7 @@ struct AppState;
// Define the constants for the current firmware. // Define the constants for the current firmware.
const char SKETCH_NAME[] = "Gravity"; const char SKETCH_NAME[] = "Gravity";
const byte SKETCH_VERSION = 3; const byte SKETCH_VERSION = 4;
// Define the minimum amount of time between EEPROM writes. // Define the minimum amount of time between EEPROM writes.
static const unsigned long SAVE_DELAY_MS = 2000; static const unsigned long SAVE_DELAY_MS = 2000;
@ -41,6 +41,7 @@ class StateManager {
byte base_probability; byte base_probability;
byte base_duty_cycle; byte base_duty_cycle;
byte base_offset; byte base_offset;
byte shuffle_index;
byte cv_source; // Cast the CvSource enum to a byte for storage byte cv_source; // Cast the CvSource enum to a byte for storage
byte cv_destination; // Cast the CvDestination enum as a byte for storage byte cv_destination; // Cast the CvDestination enum as a byte for storage
}; };