Skip to content

Commit

Permalink
Merge pull request #23632 from mike-spa/takeIntoAccountInvisibleStave…
Browse files Browse the repository at this point in the history
…sForCentering

When centering elements between staves, take invisible staves into account
  • Loading branch information
RomanPudashkin authored Jul 17, 2024
2 parents f457467 + 84d77d6 commit df46037
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
18 changes: 18 additions & 0 deletions src/engraving/dom/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,24 @@ staff_idx_t System::nextVisibleStaff(staff_idx_t staffIdx) const
return firstVisibleStaffFrom(staffIdx + 1);
}

staff_idx_t System::prevVisibleStaff(staff_idx_t startStaffIdx) const
{
for (staff_idx_t i = startStaffIdx;; --i) {
Staff* s = score()->staff(i);
SysStaff* ss = m_staves[i];

if (s->show() && ss->show()) {
return i;
}

if (i == 0) {
break;
}
}

return muse::nidx;
}

//---------------------------------------------------------
// firstVisibleStaff
//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/engraving/dom/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class System final : public EngravingItem

staff_idx_t firstVisibleStaff() const;
staff_idx_t nextVisibleStaff(staff_idx_t) const;
staff_idx_t prevVisibleStaff(staff_idx_t) const;
double distance() const { return m_distance; }
void setDistance(double d) { m_distance = d; }

Expand Down
11 changes: 6 additions & 5 deletions src/engraving/rendering/dev/systemlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2833,11 +2833,9 @@ bool SystemLayout::elementShouldBeCenteredBetweenStaves(const EngravingItem* ite
return false;
}
}
staff_idx_t nextIdx = item->placeAbove() ? thisIdx - 1 : thisIdx + 1;

const SysStaff* thisSystemStaff = system->staff(thisIdx);
const SysStaff* nextSystemStaff = system->staff(nextIdx);
if (!thisSystemStaff->show() || !nextSystemStaff->show()) {
staff_idx_t nextIdx = item->placeAbove() ? system->prevVisibleStaff(thisIdx) : system->nextVisibleStaff(thisIdx);
if (nextIdx == muse::nidx || !muse::contains(partStaves, item->score()->staff(nextIdx))) {
return false;
}

Expand All @@ -2853,7 +2851,10 @@ void SystemLayout::centerElementBetweenStaves(EngravingItem* element, const Syst
return;
}
}
staff_idx_t nextIdx = isAbove ? thisIdx - 1 : thisIdx + 1;
staff_idx_t nextIdx = isAbove ? system->prevVisibleStaff(thisIdx) : system->nextVisibleStaff(thisIdx);
IF_ASSERT_FAILED(nextIdx != muse::nidx) {
return;
}

SysStaff* thisStaff = system->staff(thisIdx);
SysStaff* nextStaff = system->staff(nextIdx);
Expand Down

0 comments on commit df46037

Please sign in to comment.