Skip to content

Commit

Permalink
update m_parts & m_systemObjectStaves first and then send notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanPudashkin committed Feb 20, 2025
1 parent 238aa97 commit 241bb6e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
3 changes: 1 addition & 2 deletions src/notation/internal/masternotationparts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ void MasterNotationParts::setParts(const PartInstrumentList& partList, const Sco
impl->setBracketsAndBarlines();
}

updatePartList();
updateSystemObjectStaves();
updatePartsAndSystemObjectStaves();
endGlobalEdit();
}

Expand Down
31 changes: 14 additions & 17 deletions src/notation/internal/notationparts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ void NotationParts::setParts(const PartInstrumentList& parts, const ScoreOrder&
updateSoloist(parts);
sortParts(parts);
setBracketsAndBarlines();
updatePartList();
updateSystemObjectStaves();
updatePartsAndSystemObjectStaves();

apply();
}
Expand Down Expand Up @@ -330,8 +329,7 @@ void NotationParts::listenUndoStackChanges()
return;
}

updatePartList();
updateSystemObjectStaves();
updatePartsAndSystemObjectStaves();

m_undoStack->changesChannel().onReceive(this, [this](const ChangesRange& range) {
if (range.changedTypes.empty()) {
Expand All @@ -346,23 +344,14 @@ void NotationParts::listenUndoStackChanges()

for (ElementType type : TYPES_TO_CHECK) {
if (muse::contains(range.changedTypes, type)) {
updatePartList();
updateSystemObjectStaves();
updatePartsAndSystemObjectStaves();
return;
}
}
});
}

void NotationParts::updatePartList()
{
if (m_parts != score()->parts()) {
m_parts = score()->parts();
m_partChangedNotifier.changed();
}
}

void NotationParts::updateSystemObjectStaves()
void NotationParts::updatePartsAndSystemObjectStaves()
{
const auto systemObjectStavesWithTopStaff = [this]() {
std::vector<Staff*> result;
Expand All @@ -375,10 +364,18 @@ void NotationParts::updateSystemObjectStaves()
return result;
};

const bool partsChanged = m_parts != score()->parts();
m_parts = score()->parts();

std::vector<Staff*> newSystemObjectStaves = systemObjectStavesWithTopStaff();
const bool systemObjectStavesChanged = m_systemObjectStaves != newSystemObjectStaves;
m_systemObjectStaves = std::move(newSystemObjectStaves);

if (partsChanged) {
m_partChangedNotifier.changed();
}

if (m_systemObjectStaves != newSystemObjectStaves) {
m_systemObjectStaves = std::move(newSystemObjectStaves);
if (systemObjectStavesChanged) {
m_systemObjectStavesChanged.notify();
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/notation/internal/notationparts.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ class NotationParts : public INotationParts, public muse::async::Asyncable
friend class MasterNotationParts;

void listenUndoStackChanges();

void updatePartList();
void updateSystemObjectStaves();
void updatePartsAndSystemObjectStaves();

void doSetScoreOrder(const ScoreOrder& order);
void doRemoveParts(const std::vector<Part*>& parts);
Expand Down

0 comments on commit 241bb6e

Please sign in to comment.