Skip to content

Commit

Permalink
move layouts to data from bss to fix initialization order bug
Browse files Browse the repository at this point in the history
  • Loading branch information
m-m-adams committed Feb 10, 2025
1 parent f990759 commit e5025f5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 41 deletions.
80 changes: 40 additions & 40 deletions src/deluge/gui/ui/keyboard/keyboard_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<KeyboardLayout*, KeyboardLayoutType::KeyboardLayoutTypeMaxElement> 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};
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
Expand All @@ -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);

Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
Expand All @@ -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();
}

Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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],
Expand All @@ -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;

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/deluge/gui/ui/keyboard/layout/velocity_drums.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e5025f5

Please sign in to comment.