diff --git a/src/engraving/dom/spanner.cpp b/src/engraving/dom/spanner.cpp index 53068f4dcc05e..24991fdbe5ca8 100644 --- a/src/engraving/dom/spanner.cpp +++ b/src/engraving/dom/spanner.cpp @@ -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 //--------------------------------------------------------- diff --git a/src/engraving/dom/spanner.h b/src/engraving/dom/spanner.h index 3d3ab48b0b3f4..355f151ee1b4f 100644 --- a/src/engraving/dom/spanner.h +++ b/src/engraving/dom/spanner.h @@ -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); diff --git a/src/engraving/rendering/score/measurelayout.cpp b/src/engraving/rendering/score/measurelayout.cpp index 2c114e9b9c06e..6d169c0f13546 100644 --- a/src/engraving/rendering/score/measurelayout.cpp +++ b/src/engraving/rendering/score/measurelayout.cpp @@ -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 @@ -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())) { @@ -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(); @@ -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(); diff --git a/src/engraving/rendering/score/systemlayout.cpp b/src/engraving/rendering/score/systemlayout.cpp index 6d8272205a0a9..54f56cb29b970 100644 --- a/src/engraving/rendering/score/systemlayout.cpp +++ b/src/engraving/rendering/score/systemlayout.cpp @@ -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); } diff --git a/vtest/scores/mmrest-invisible-elements.mscz b/vtest/scores/mmrest-invisible-elements.mscz new file mode 100644 index 0000000000000..201942029dd09 Binary files /dev/null and b/vtest/scores/mmrest-invisible-elements.mscz differ