Skip to content

Commit

Permalink
Don't break MMRests on invisible elements
Browse files Browse the repository at this point in the history
  • Loading branch information
miiizen committed Sep 23, 2024
1 parent 967f2e1 commit bd1f5ea
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
39 changes: 39 additions & 0 deletions src/engraving/dom/spanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,45 @@ Measure* Spanner::endMeasure() const
return toMeasure(m_endElement);
}

Measure* Spanner::findStartMeasure() const
{
if (!m_startElement) {
return nullptr;
}

if (m_startElement->isChordRest()) {
return toChordRest(m_startElement)->measure();
} else if (m_startElement->isSegment()) {
return toSegment(m_startElement)->measure();
} else if (m_startElement->isMeasure()) {
toMeasure(m_startElement);
} else if (m_startElement->isNote()) {
const Chord* chord = toNote(m_startElement)->chord();
return chord ? chord->measure() : nullptr;
}

return m_startElement->findMeasure();
}

Measure* Spanner::findEndMeasure() const
{
if (!m_endElement) {
return nullptr;
}
if (m_endElement->isChordRest()) {
return toChordRest(m_endElement)->measure();
} else if (m_endElement->isSegment()) {
return toSegment(m_endElement)->measure();
} else if (m_endElement->isMeasure()) {
toMeasure(m_endElement);
} else if (m_endElement->isNote()) {
const Chord* chord = toNote(m_endElement)->chord();
return chord ? chord->measure() : nullptr;
}

return m_endElement->findMeasure();
}

//---------------------------------------------------------
// setSelected
//---------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions src/engraving/dom/spanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ class Spanner : public EngravingItem
Measure* startMeasure() const;
Measure* endMeasure() const;

Measure* findStartMeasure() const;
Measure* findEndMeasure() const;

void setStartElement(EngravingItem* e);
void setEndElement(EngravingItem* e);

Expand Down
10 changes: 8 additions & 2 deletions src/engraving/rendering/score/measurelayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ void MeasureLayout::createMMRest(LayoutContext& ctx, Measure* firstMeasure, Meas
// clone elements from underlying measure to mmr
for (EngravingItem* e : underlyingSeg->annotations()) {
// look at elements in underlying measure
if (!muse::contains(BREAK_TYPES, e->type())) {
if (!muse::contains(BREAK_TYPES, e->type()) || !e->visible()) {
continue;
}
// try to find a match in mmr
Expand Down Expand Up @@ -534,7 +534,7 @@ static bool validMMRestMeasure(const LayoutContext& ctx, const Measure* m)
int n = 0;
for (const Segment* s = m->first(); s; s = s->next()) {
for (const EngravingItem* e : s->annotations()) {
if (!e->staff()->show()) {
if (!e->staff()->show() || !e->visible()) {
continue;
}
if (!muse::contains(BREAK_TYPES, e->type())) {
Expand Down Expand Up @@ -602,6 +602,9 @@ static bool breakMultiMeasureRest(const LayoutContext& ctx, Measure* m)
auto sl = ctx.dom().spannerMap().findOverlapping(m->tick().ticks(), m->endTick().ticks());
for (auto i : sl) {
Spanner* s = i.value;
if (!s->visible()) {
continue;
}
Fraction spannerStart = s->tick();
Fraction spannerEnd = s->tick2();
Fraction measureStart = m->tick();
Expand All @@ -618,6 +621,9 @@ static bool breakMultiMeasureRest(const LayoutContext& ctx, Measure* m)
auto prevMeasSpanners = ctx.dom().spannerMap().findOverlapping(prevMeas->tick().ticks(), prevMeas->endTick().ticks());
for (auto i : prevMeasSpanners) {
Spanner* s = i.value;
if (!s->visible()) {
continue;
}
Fraction spannerStart = s->tick();
Fraction spannerEnd = s->tick2();
Fraction measureStart = prevMeas->tick();
Expand Down
6 changes: 6 additions & 0 deletions src/engraving/rendering/score/systemlayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,12 @@ void SystemLayout::layoutSystemElements(System* system, LayoutContext& ctx)
continue;
}

const Measure* startMeas = sp->findStartMeasure();
const Measure* endMeas = sp->findEndMeasure();
if (!sp->visible() && ((startMeas && startMeas->isMMRest()) || (endMeas && endMeas->isMMRest()))
&& ctx.conf().styleB(Sid::createMultiMeasureRests)) {
continue;
}
if (sp->tick2() == stick && sp->isPedal() && toPedal(sp)->connect45HookToNext()) {
pedal.push_back(sp);
}
Expand Down
Binary file added vtest/scores/mmrest-invisible-elements.mscz
Binary file not shown.

0 comments on commit bd1f5ea

Please sign in to comment.