diff --git a/VortexEngine/src/Menus/MenuList/Randomizer.cpp b/VortexEngine/src/Menus/MenuList/Randomizer.cpp index 9a80cb9f3a..41050076af 100644 --- a/VortexEngine/src/Menus/MenuList/Randomizer.cpp +++ b/VortexEngine/src/Menus/MenuList/Randomizer.cpp @@ -138,51 +138,95 @@ void Randomizer::onLongClick() bool Randomizer::reRoll() { +#if VORTEX_SLIM == 0 + if (m_targetLeds == MAP_LED(LED_MULTI)) { + if (!reRollMulti()) { + return false; + } + } +#endif + if (!reRollSingles()) { + return false; + } + // initialize the mode with the new pattern and colorset + m_previewMode.init(); + return true; +} + +void Randomizer::showRandomizationSelect() +{ + // show iterating rainbow if they are randomizing color, otherwise 0 sat if they + // are only randomizing the pattern + Leds::setAll(HSVColor(m_displayHue++, (m_flags & RANDOMIZE_COLORSET) * 255, 84)); + if (m_flags & RANDOMIZE_PATTERN) { + // this is blinking the light to off so the params are switched but still effectively correct + Leds::blinkAll(DOPS_ON_DURATION, DOPS_OFF_DURATION); + } + // render the click selection blink + Menus::showSelection(); +} + +#if VORTEX_SLIM == 0 +bool Randomizer::reRollMulti() +{ + if (m_flags & RANDOMIZE_PATTERN) { + // TODO: Roll custom multi pattern? + //if (m_advanced) { + // if (!rollCustomPattern(ctx, &m_previewMode, pos)) { + // ERROR_LOG("Failed to roll custom pattern"); + // return false; + // } + //} + if (!m_previewMode.setPattern(rollMultiLedPatternID(m_multiRandCtx), LED_MULTI)) { + ERROR_LOG("Failed to select pattern"); + return false; + } + } + if (m_flags & RANDOMIZE_COLORSET) { + if (!m_previewMode.setColorset(rollColorset(m_multiRandCtx), LED_MULTI)) { + ERROR_LOG("Failed to roll new colorset"); + return false; + } + } + return true; +} + +PatternID Randomizer::rollMultiLedPatternID(Random &ctx) +{ + return (PatternID)ctx.next8(PATTERN_MULTI_FIRST, PATTERN_MULTI_LAST); +} +#endif + +bool Randomizer::reRollSingles() +{ + // re-roll each led position with it's respective random context 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 + // in advanced mode, when not randomizing the multi position, use a + // special function to randomize totally custom led pattern timings if (m_advanced) { if (!rollCustomPattern(ctx, &m_previewMode, pos)) { - ERROR_LOG("Failed to roll new pattern"); + ERROR_LOG("Failed to roll custom pattern"); return false; } } else { if (!m_previewMode.setPattern(rollSingleLedPatternID(ctx), pos)) { - ERROR_LOG("Failed to roll new pattern"); + ERROR_LOG("Failed to select 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 - // are only randomizing the pattern - Leds::setAll(HSVColor(m_displayHue++, (m_flags & RANDOMIZE_COLORSET) * 255, 84)); - if (m_flags & RANDOMIZE_PATTERN) { - // this is blinking the light to off so the params are switched but still effectively correct - Leds::blinkAll(DOPS_ON_DURATION, DOPS_OFF_DURATION); - } - // render the click selection blink - Menus::showSelection(); -} - PatternID Randomizer::rollSingleLedPatternID(Random &ctx) { PatternID newPat; diff --git a/VortexEngine/src/Menus/MenuList/Randomizer.h b/VortexEngine/src/Menus/MenuList/Randomizer.h index 8fa6cc3413..0575ab132f 100644 --- a/VortexEngine/src/Menus/MenuList/Randomizer.h +++ b/VortexEngine/src/Menus/MenuList/Randomizer.h @@ -25,9 +25,10 @@ class Randomizer : public Menu bool reRoll(); private: - // random context for each led and led multi (LED_COUNT + 1) + // random context for each single led Random m_singlesRandCtx[LED_COUNT]; #if VORTEX_SLIM == 0 + // random context for the multi led position Random m_multiRandCtx; #endif @@ -61,6 +62,12 @@ class Randomizer : public Menu // show the randomization type selection void showRandomizationSelect(); + // main reRoll functions +#if VORTEX_SLIM == 0 + bool reRollMulti(); + PatternID rollMultiLedPatternID(Random &ctx); +#endif + bool reRollSingles(); PatternID rollSingleLedPatternID(Random &ctx); // generate a random colorset with a random context