From e5025f543c8c730098bc41a28d367c6047c0c9b1 Mon Sep 17 00:00:00 2001 From: m-m-adams Date: Mon, 10 Feb 2025 14:56:49 -0500 Subject: [PATCH] move layouts to data from bss to fix initialization order bug --- .../gui/ui/keyboard/keyboard_screen.cpp | 80 +++++++++---------- .../gui/ui/keyboard/layout/velocity_drums.h | 2 +- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/deluge/gui/ui/keyboard/keyboard_screen.cpp b/src/deluge/gui/ui/keyboard/keyboard_screen.cpp index ae59d9b515..593f19a7f2 100644 --- a/src/deluge/gui/ui/keyboard/keyboard_screen.cpp +++ b/src/deluge/gui/ui/keyboard/keyboard_screen.cpp @@ -57,23 +57,23 @@ PLACE_SDRAM_BSS deluge::gui::ui::keyboard::KeyboardScreen keyboardScreen{}; namespace deluge::gui::ui::keyboard { -PLACE_SDRAM_BSS layout::KeyboardLayoutIsomorphic keyboardLayoutIsomorphic{}; -PLACE_SDRAM_BSS layout::KeyboardLayoutVelocityDrums keyboardLayoutVelocityDrums{}; -PLACE_SDRAM_BSS layout::KeyboardLayoutInKey keyboardLayoutInKey{}; -PLACE_SDRAM_BSS layout::KeyboardLayoutPiano keyboardLayoutPiano{}; -PLACE_SDRAM_BSS layout::KeyboardLayoutChord KeyboardLayoutChord{}; -PLACE_SDRAM_BSS layout::KeyboardLayoutChordLibrary keyboardLayoutChordLibrary{}; -PLACE_SDRAM_BSS layout::KeyboardLayoutNorns keyboardLayoutNorns{}; -PLACE_SDRAM_BSS KeyboardLayout* layoutList[KeyboardLayoutType::KeyboardLayoutTypeMaxElement + 1] = {0}; +PLACE_SDRAM_DATA layout::KeyboardLayoutIsomorphic keyboard_layout_isomorphic{}; +PLACE_SDRAM_DATA layout::KeyboardLayoutVelocityDrums keyboard_layout_velocity_drums{}; +PLACE_SDRAM_DATA layout::KeyboardLayoutInKey keyboard_layout_in_key{}; +PLACE_SDRAM_DATA layout::KeyboardLayoutPiano keyboard_layout_piano{}; +PLACE_SDRAM_DATA layout::KeyboardLayoutChord keyboard_layout_chord{}; +PLACE_SDRAM_DATA layout::KeyboardLayoutChordLibrary keyboard_layout_chord_library{}; +PLACE_SDRAM_DATA layout::KeyboardLayoutNorns keyboard_layout_norns{}; +PLACE_SDRAM_DATA std::array layout_list = {nullptr}; KeyboardScreen::KeyboardScreen() { - layoutList[KeyboardLayoutType::KeyboardLayoutTypeIsomorphic] = (KeyboardLayout*)&keyboardLayoutIsomorphic; - layoutList[KeyboardLayoutType::KeyboardLayoutTypeDrums] = (KeyboardLayout*)&keyboardLayoutVelocityDrums; - layoutList[KeyboardLayoutType::KeyboardLayoutTypeInKey] = (KeyboardLayout*)&keyboardLayoutInKey; - layoutList[KeyboardLayoutType::KeyboardLayoutTypePiano] = (KeyboardLayout*)&keyboardLayoutPiano; - layoutList[KeyboardLayoutType::KeyboardLayoutTypeChord] = (KeyboardLayout*)&KeyboardLayoutChord; - layoutList[KeyboardLayoutType::KeyboardLayoutTypeChordLibrary] = (KeyboardLayout*)&keyboardLayoutChordLibrary; - layoutList[KeyboardLayoutType::KeyboardLayoutTypeNorns] = (KeyboardLayout*)&keyboardLayoutNorns; + layout_list[KeyboardLayoutType::KeyboardLayoutTypeIsomorphic] = &keyboard_layout_isomorphic; + layout_list[KeyboardLayoutType::KeyboardLayoutTypeInKey] = &keyboard_layout_in_key; + layout_list[KeyboardLayoutType::KeyboardLayoutTypePiano] = &keyboard_layout_piano; + layout_list[KeyboardLayoutType::KeyboardLayoutTypeChord] = &keyboard_layout_chord; + layout_list[KeyboardLayoutType::KeyboardLayoutTypeChordLibrary] = &keyboard_layout_chord_library; + layout_list[KeyboardLayoutType::KeyboardLayoutTypeDrums] = &keyboard_layout_velocity_drums; + layout_list[KeyboardLayoutType::KeyboardLayoutTypeNorns] = &keyboard_layout_norns; memset(&pressedPads, 0, sizeof(pressedPads)); currentNotesState = {0}; @@ -193,8 +193,8 @@ ActionResult KeyboardScreen::padAction(int32_t x, int32_t y, int32_t velocity) { void KeyboardScreen::evaluateActiveNotes() { lastNotesState = currentNotesState; - layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->evaluatePads(pressedPads); - currentNotesState = layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->getNotesState(); + layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->evaluatePads(pressedPads); + currentNotesState = layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->getNotesState(); } void KeyboardScreen::updateActiveNotes() { @@ -593,7 +593,7 @@ ActionResult KeyboardScreen::buttonAction(deluge::hid::Button b, bool on, bool i && currentUIMode == UI_MODE_SCALE_MODE_BUTTON_PRESSED) { toggleScaleModeOnButtonRelease = false; cycleThroughScales(); - layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->precalculate(); + layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->precalculate(); requestRendering(); } @@ -654,10 +654,10 @@ ActionResult KeyboardScreen::verticalEncoderAction(int32_t offset, bool inCardRo if (Buttons::isShiftButtonPressed() && currentUIMode == UI_MODE_NONE) { getCurrentInstrumentClip()->colourOffset += offset; - layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->precalculate(); + layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->precalculate(); } else { - layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->handleVerticalEncoder(offset); + layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->handleVerticalEncoder(offset); if (isUIModeWithinRange(padActionUIModes)) { evaluateActiveNotes(); updateActiveNotes(); @@ -670,7 +670,7 @@ ActionResult KeyboardScreen::verticalEncoderAction(int32_t offset, bool inCardRo ActionResult KeyboardScreen::horizontalEncoderAction(int32_t offset) { - layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->handleHorizontalEncoder( + layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->handleHorizontalEncoder( offset, (Buttons::isShiftButtonPressed() && isUIModeWithinRange(padActionUIModes)), pressedPads, xEncoderActive); @@ -709,10 +709,10 @@ void KeyboardScreen::selectLayout(int8_t offset) { ) { // Don't check the next conditions, this one is already lost } - else if (getCurrentOutputType() == OutputType::KIT && layoutList[nextLayout]->supportsKit()) { + else if (getCurrentOutputType() == OutputType::KIT && layout_list[nextLayout]->supportsKit()) { break; } - else if (getCurrentOutputType() != OutputType::KIT && layoutList[nextLayout]->supportsInstrument()) { + else if (getCurrentOutputType() != OutputType::KIT && layout_list[nextLayout]->supportsInstrument()) { break; } @@ -727,13 +727,13 @@ void KeyboardScreen::selectLayout(int8_t offset) { getCurrentInstrumentClip()->keyboardState.currentLayout = (KeyboardLayoutType)nextLayout; if (getCurrentInstrumentClip()->keyboardState.currentLayout != lastLayout) { - display->displayPopup(l10n::get(layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->name())); + display->displayPopup(l10n::get(layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->name())); } // Ensure scale mode is as expected if (getCurrentOutputType() != OutputType::KIT) { auto requiredScaleMode = - layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->requiredScaleMode(); + layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->requiredScaleMode(); if (requiredScaleMode == RequiredScaleMode::Enabled && !getCurrentInstrumentClip()->inScaleMode) { getCurrentInstrumentClip()->yScroll = instrumentClipView.setupForEnteringScaleMode(currentSong->key.rootNote); @@ -747,11 +747,11 @@ void KeyboardScreen::selectLayout(int8_t offset) { } // Ensure scroll values are calculated in bounds - layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->handleHorizontalEncoder(0, false, pressedPads, - xEncoderActive); + layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->handleHorizontalEncoder(0, false, pressedPads, + xEncoderActive); // Precalculate because changing instruments can change pad colours - layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->precalculate(); + layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->precalculate(); requestRendering(); } @@ -774,17 +774,17 @@ void KeyboardScreen::selectEncoderAction(int8_t offset) { } } display->displayPopup(noteName, 3, false, (noteCodeIsSharp[newRootNote] ? 0 : 255)); - layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->handleHorizontalEncoder( + layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->handleHorizontalEncoder( 0, false, pressedPads, xEncoderActive); - layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->precalculate(); + layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->precalculate(); requestRendering(); } else { InstrumentClipMinder::selectEncoderAction(offset); // Ensure scroll values are calculated in bounds - layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->handleHorizontalEncoder( + layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->handleHorizontalEncoder( 0, false, pressedPads, xEncoderActive); - layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->precalculate(); + layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->precalculate(); requestRendering(); } } @@ -822,14 +822,14 @@ void KeyboardScreen::openedInBackground() { getCurrentInstrumentClip()->onKeyboardScreen = true; // Ensure scroll values are calculated in bounds - layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->handleHorizontalEncoder(0, false, pressedPads, - xEncoderActive); - layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->precalculate(); + layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->handleHorizontalEncoder(0, false, pressedPads, + xEncoderActive); + layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->precalculate(); requestRendering(); // This one originally also included sidebar, the other ones didn't } void KeyboardScreen::checkNewInstrument(Instrument* newInstrument) { - layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->checkNewInstrument(newInstrument); + layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->checkNewInstrument(newInstrument); } bool KeyboardScreen::renderMainPads(uint32_t whichRows, RGB image[][kDisplayWidth + kSideBarWidth], @@ -847,7 +847,7 @@ bool KeyboardScreen::renderMainPads(uint32_t whichRows, RGB image[][kDisplayWidt // We assume the whole screen is occupied memset(occupancyMask, 64, sizeof(uint8_t) * kDisplayHeight * (kDisplayWidth + kSideBarWidth)); - layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->renderPads(image); + layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->renderPads(image); PadLEDs::renderingLock = false; @@ -864,7 +864,7 @@ bool KeyboardScreen::renderSidebar(uint32_t whichRows, RGB image[][kDisplayWidth return true; } - layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->renderSidebarPads(image); + layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->renderSidebarPads(image); return true; } @@ -876,7 +876,7 @@ void KeyboardScreen::flashDefaultRootNote() { } void KeyboardScreen::enterScaleMode(int32_t selectedRootNote) { - auto requiredScaleMode = layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->requiredScaleMode(); + auto requiredScaleMode = layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->requiredScaleMode(); if (requiredScaleMode == RequiredScaleMode::Disabled) { return; } @@ -898,7 +898,7 @@ void KeyboardScreen::enterScaleMode(int32_t selectedRootNote) { } void KeyboardScreen::exitScaleMode() { - auto requiredScaleMode = layoutList[getCurrentInstrumentClip()->keyboardState.currentLayout]->requiredScaleMode(); + auto requiredScaleMode = layout_list[getCurrentInstrumentClip()->keyboardState.currentLayout]->requiredScaleMode(); if (requiredScaleMode == RequiredScaleMode::Enabled) { return; } diff --git a/src/deluge/gui/ui/keyboard/layout/velocity_drums.h b/src/deluge/gui/ui/keyboard/layout/velocity_drums.h index 6c9e56ee58..9eff4b6530 100644 --- a/src/deluge/gui/ui/keyboard/layout/velocity_drums.h +++ b/src/deluge/gui/ui/keyboard/layout/velocity_drums.h @@ -28,7 +28,7 @@ constexpr int32_t k_max_zoom_level = 12; const int32_t zoom_arr[13][2] = {{1, 1}, {2, 1}, {3, 1}, {2, 2}, {3, 2}, {4, 2}, {5, 2}, {3, 4}, {4, 4}, {5, 4}, {8, 4}, {8, 8}, {16, 8}}; -class KeyboardLayoutVelocityDrums : KeyboardLayout { +class KeyboardLayoutVelocityDrums : public KeyboardLayout { public: KeyboardLayoutVelocityDrums() = default; ~KeyboardLayoutVelocityDrums() override = default;