From 0ff2406144739f72ec7cfec568070a9200c7f4b8 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 26 Nov 2024 16:05:38 -0800 Subject: [PATCH] Fixed pattern select in core --- .../src/Menus/MenuList/PatternSelect.cpp | 57 ++++++++++++++----- .../src/Menus/MenuList/PatternSelect.h | 6 ++ 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/VortexEngine/src/Menus/MenuList/PatternSelect.cpp b/VortexEngine/src/Menus/MenuList/PatternSelect.cpp index d4531be1b3..79720ebf56 100644 --- a/VortexEngine/src/Menus/MenuList/PatternSelect.cpp +++ b/VortexEngine/src/Menus/MenuList/PatternSelect.cpp @@ -94,34 +94,56 @@ void PatternSelect::onShortClick() } return; } - PatternID newID = (PatternID)(m_previewMode.getPatternID(m_srcLed) + 1); - PatternID maxID = PATTERN_SINGLE_LAST; + nextPattern(); +} + +void PatternSelect::nextPatternID() +{ + // increment to next pattern + PatternID endList = PATTERN_SINGLE_LAST; + PatternID beginList = PATTERN_SINGLE_FIRST; #if VORTEX_SLIM == 0 - if (m_targetLeds == MAP_LED_ALL || m_targetLeds == MAP_LED(LED_MULTI)) { - maxID = PATTERN_MULTI_LAST; + // if targeted multi led or all singles, iterate through multis + if ((m_targetLeds == MAP_LED_ALL) || (m_targetLeds == MAP_LED(LED_MULTI))) { + endList = PATTERN_MULTI_LAST; + } + // if targeted multi then start at multis and only iterate multis + if ((m_targetLeds == MAP_LED(LED_MULTI))) { + beginList = PATTERN_MULTI_FIRST; } #endif - if (newID > maxID) { - newID = maxID; + m_newPatternID = (PatternID)((m_newPatternID + 1) % endList); + if (m_newPatternID > endList || m_newPatternID < beginList) { + m_newPatternID = beginList; } - if (!m_started) { +} + +void PatternSelect::nextPattern() +{ + if (m_started) { + nextPatternID(); + } else { m_started = true; - newID = PATTERN_FIRST; + // Do not modify m_newPatternID Here! It has been set in the long click handler + // to be the start of the list we want to iterate } // set the new pattern id - if (isMultiLedPatternID(newID)) { - m_previewMode.setPattern(newID); + if (isMultiLedPatternID(m_newPatternID)) { + m_previewMode.setPattern(m_newPatternID); } else { + // if the user selected multi then just put singles on all leds + LedMap setLeds = (m_targetLeds == MAP_LED(LED_MULTI)) ? LED_ALL : m_targetLeds; + m_previewMode.setPatternMap(setLeds, m_newPatternID); // TODO: clear multi a better way - m_previewMode.setPatternMap(m_targetLeds, newID); m_previewMode.clearPattern(LED_MULTI); } m_previewMode.init(); - DEBUG_LOGF("Iterated to pattern id %d", newID); + DEBUG_LOGF("Iterated to pattern id %d", m_newPatternID); } void PatternSelect::onLongClick() { + bool needsSave = false; if (m_advanced) { m_argIndex++; if (m_argIndex < m_previewMode.getPattern(m_srcLed)->getNumArgs()) { @@ -130,7 +152,12 @@ void PatternSelect::onLongClick() } Leds::holdAll(m_menuColor); } - // store the mode as current mode - Modes::updateCurMode(&m_previewMode); - leaveMenu(true); + needsSave = !Modes::curMode()->equals(&m_previewMode); + if (needsSave) { + // update the current mode with the new pattern + Modes::updateCurMode(&m_previewMode); + } + DEBUG_LOGF("Saving pattern %u", m_newPatternID); + // done in the pattern select menu + leaveMenu(needsSave); } diff --git a/VortexEngine/src/Menus/MenuList/PatternSelect.h b/VortexEngine/src/Menus/MenuList/PatternSelect.h index 317611a7fa..2b1b0616af 100644 --- a/VortexEngine/src/Menus/MenuList/PatternSelect.h +++ b/VortexEngine/src/Menus/MenuList/PatternSelect.h @@ -23,6 +23,12 @@ class PatternSelect : public Menu void onLongClick() override; private: + void nextPatternID(); + void nextPattern(); + + // the patternid of the current demo + PatternID m_newPatternID; + // helpful member LedPos m_srcLed;