diff --git a/VortexEngine/src/Menus/MenuList/Randomizer.cpp b/VortexEngine/src/Menus/MenuList/Randomizer.cpp index ad10d25ddb..2004a0f175 100644 --- a/VortexEngine/src/Menus/MenuList/Randomizer.cpp +++ b/VortexEngine/src/Menus/MenuList/Randomizer.cpp @@ -132,6 +132,40 @@ void Randomizer::onLongClick() leaveMenu(true); } +bool Randomizer::reRoll() +{ + MAP_FOREACH_LED(m_targetLeds) { + // grab local reference to the target random context + Random &ctx = m_singlesRandCtx[pos]; + if (m_flags & RANDOMIZE_PATTERN) { + // roll a new pattern + if (m_advanced) { + if (!rollCustomPattern(ctx, &m_previewMode, pos)) { + ERROR_LOG("Failed to roll new pattern"); + return false; + } + } else { + if (!m_previewMode.setPattern(rollSingleLedPatternID(ctx), pos)) { + ERROR_LOG("Failed to roll new pattern"); + return false; + } + } + } + if (m_flags & RANDOMIZE_COLORSET) { + // roll a new colorset + if (!m_previewMode.setColorset(rollColorset(ctx), pos)) { + ERROR_LOG("Failed to roll new colorset"); + return false; + } + } + } + // initialize the mode with the new pattern and colorset + m_previewMode.init(); + DEBUG_LOGF("Randomized Led %u set with randomization technique %u, %u colors, and Pattern number %u", + pos, randType, randomSet.numColors(), newPat); + return true; +} + void Randomizer::showRandomizationSelect() { // show iterating rainbow if they are randomizing color, otherwise 0 sat if they @@ -145,6 +179,17 @@ void Randomizer::showRandomizationSelect() Menus::showSelection(); } +PatternID Randomizer::rollSingleLedPatternID(Random &ctx) +{ + PatternID newPat; + // the random range begin/end + do { + // continuously re-randomize the pattern so we don't get undesirable patterns + newPat = (PatternID)ctx.next8(PATTERN_SINGLE_FIRST, PATTERN_SINGLE_LAST); + } while (newPat == PATTERN_SOLID || newPat == PATTERN_RIBBON || newPat == PATTERN_MINIRIBBON); + return newPat; +} + Colorset Randomizer::rollColorset(Random &ctx) { Colorset randomSet; @@ -194,7 +239,7 @@ Colorset Randomizer::rollColorset(Random &ctx) return randomSet; } -bool Randomizer::rollPattern(Random &ctx, Mode *pMode, LedPos pos) +bool Randomizer::rollCustomPattern(Random &ctx, Mode *pMode, LedPos pos) { PatternArgs args; // pick a random type of randomizer to use then use @@ -281,48 +326,3 @@ void Randomizer::crushPattern(Random &ctx, PatternArgs &outArgs) uint8_t on = ctx.next8(1, 10); // on duration 1 -> 10 outArgs.init(on, off, gap, dash, group); } - -PatternID Randomizer::rollPatternID(Random &ctx) -{ - PatternID newPat; - // the random range begin/end - do { - // continuously re-randomize the pattern so we don't get undesirable patterns - newPat = (PatternID)ctx.next8(PATTERN_SINGLE_FIRST, PATTERN_SINGLE_LAST); - } while (newPat == PATTERN_SOLID || newPat == PATTERN_RIBBON || newPat == PATTERN_MINIRIBBON); - return newPat; -} - -bool Randomizer::reRoll() -{ - MAP_FOREACH_LED(m_targetLeds) { - // grab local reference to the target random context - Random &ctx = m_singlesRandCtx[pos]; - if (m_flags & RANDOMIZE_PATTERN) { - // roll a new pattern - if (m_advanced) { - if (!rollPattern(ctx, &m_previewMode, pos)) { - ERROR_LOG("Failed to roll new pattern"); - return false; - } - } else { - if (!m_previewMode.setPattern(rollPatternID(ctx), pos)) { - ERROR_LOG("Failed to roll new pattern"); - return false; - } - } - } - if (m_flags & RANDOMIZE_COLORSET) { - // roll a new colorset - if (!m_previewMode.setColorset(rollColorset(ctx), pos)) { - ERROR_LOG("Failed to roll new colorset"); - return false; - } - } - } - // initialize the mode with the new pattern and colorset - m_previewMode.init(); - DEBUG_LOGF("Randomized Led %u set with randomization technique %u, %u colors, and Pattern number %u", - pos, randType, randomSet.numColors(), newPat); - return true; -} diff --git a/VortexEngine/src/Menus/MenuList/Randomizer.h b/VortexEngine/src/Menus/MenuList/Randomizer.h index 01af38c5c6..134162a5ae 100644 --- a/VortexEngine/src/Menus/MenuList/Randomizer.h +++ b/VortexEngine/src/Menus/MenuList/Randomizer.h @@ -59,12 +59,15 @@ class Randomizer : public Menu // show the randomization type selection void showRandomizationSelect(); + PatternID rollSingleLedPatternID(Random &ctx); + // generate a random colorset with a random context - bool rollPattern(Random &ctx, Mode *pMode, LedPos pos); - PatternID rollPatternID(Random &ctx); Colorset rollColorset(Random &ctx); - // random pattern generators + // roll a custom pattern by generating random arguments + bool rollCustomPattern(Random &ctx, Mode *pMode, LedPos pos); + + // more specific random pattern generators that just generate patternargs void traditionalPattern(Random &ctx, PatternArgs &outArgs); void gapPattern(Random &ctx, PatternArgs &outArgs); void dashPattern(Random &ctx, PatternArgs &outArgs);