@@ -6625,6 +6625,104 @@ void Score::removeLayoutBreaksOnAddSystemLock(const SystemLock* lock)
66256625 }
66266626}
66276627
6628+ void Score::removeSystemLocksOnRemoveMeasures (const MeasureBase* m1, const MeasureBase* m2)
6629+ {
6630+ std::vector<const SystemLock*> allSysLocks = systemLocks ()->allLocks ();
6631+ for (const SystemLock* lock : allSysLocks) {
6632+ MeasureBase* lockStart = lock->startMB ();
6633+ MeasureBase* lockEnd = lock->endMB ();
6634+ bool lockStartIsInRange = lockStart->isAfterOrEqual (m1) && lockStart->isBeforeOrEqual (m2);
6635+ bool lockEndIsInRange = lockEnd->isAfterOrEqual (m1) && lockEnd->isBeforeOrEqual (m2);
6636+ if (lockStartIsInRange || lockEndIsInRange) {
6637+ undoRemoveSystemLock (lock);
6638+ }
6639+ if (lockStartIsInRange && !lockEndIsInRange) {
6640+ MeasureBase* newLockStart = m2->nextMeasure ();
6641+ if (newLockStart) {
6642+ undoAddSystemLock (new SystemLock (newLockStart, lockEnd));
6643+ }
6644+ } else if (!lockStartIsInRange && lockEndIsInRange) {
6645+ MeasureBase* newLockEnd = m1->prevMeasure ();
6646+ if (newLockEnd) {
6647+ undoAddSystemLock (new SystemLock (lockStart, newLockEnd));
6648+ }
6649+ }
6650+ }
6651+ }
6652+
6653+ void Score::updateSystemLocksOnDisableMMRests ()
6654+ {
6655+ // NOTE: this can be done before layout for the full score
6656+ // because we already know where the mmRests are.
6657+
6658+ assert (!style ().styleB (Sid::createMultiMeasureRests));
6659+
6660+ std::vector<const SystemLock*> allLocks = m_systemLocks.allLocks ();
6661+ for (const SystemLock* lock : allLocks) {
6662+ MeasureBase* startMB = lock->startMB ();
6663+ MeasureBase* endMB = lock->endMB ();
6664+ bool startIsMMRest = startMB->isMeasure () && toMeasure (startMB)->isMMRest ();
6665+ bool endIsMMRest = endMB->isMeasure () && toMeasure (endMB)->isMMRest ();
6666+ if (startIsMMRest || endIsMMRest) {
6667+ undoRemoveSystemLock (lock);
6668+ MeasureBase* newStartMeas = startMB;
6669+ MeasureBase* newEndMeas = endMB;
6670+ if (startIsMMRest) {
6671+ newStartMeas = toMeasure (startMB)->mmRestFirst ();
6672+ }
6673+ if (endIsMMRest) {
6674+ newEndMeas = toMeasure (endMB)->mmRestLast ();
6675+ }
6676+ undoAddSystemLock (new SystemLock (newStartMeas, newEndMeas));
6677+ }
6678+ }
6679+ }
6680+
6681+ void Score::updateSystemLocksOnCreateMMRests (Measure* first, Measure* last)
6682+ {
6683+ // NOTE: this must be done during layout as the mmRests get created.
6684+
6685+ for (const SystemLock* lock : systemLocks ()->locksContainedInRange (first, last)) {
6686+ // These locks are inside the range of the mmRest so remove them
6687+ undoRemoveSystemLock (lock);
6688+ }
6689+
6690+ const SystemLock* lockOnFirst = systemLocks ()->lockContaining (first);
6691+ const SystemLock* lockOnLast = systemLocks ()->lockContaining (last);
6692+
6693+ if (lockOnFirst) {
6694+ MeasureBase* startMB = lockOnFirst->startMB ();
6695+ MeasureBase* endMB = lockOnFirst->endMB ();
6696+
6697+ if (startMB->isBefore (first)) {
6698+ if (endMB->isBeforeOrEqual (last)) {
6699+ endMB = first->mmRest ();
6700+ } else {
6701+ return ;
6702+ }
6703+ } else {
6704+ startMB = first->mmRest ();
6705+ }
6706+
6707+ if (startMB != lockOnFirst->startMB () || endMB != lockOnFirst->endMB ()) {
6708+ undoRemoveSystemLock (lockOnFirst);
6709+ undoAddSystemLock (new SystemLock (startMB, endMB));
6710+ }
6711+ }
6712+
6713+ if (!lockOnLast || lockOnLast == lockOnFirst) {
6714+ return ;
6715+ }
6716+
6717+ MeasureBase* startMB = lockOnLast->startMB ();
6718+ MeasureBase* endMB = lockOnLast->endMB ();
6719+ assert (startMB->isAfter (first) && endMB->isAfter (last));
6720+
6721+ undoRemoveSystemLock (lockOnLast);
6722+ startMB = last->nextMM ();
6723+ undoAddSystemLock (new SystemLock (startMB, endMB));
6724+ }
6725+
66286726// ---------------------------------------------------------
66296727// undoAddCR
66306728// ---------------------------------------------------------
@@ -7118,6 +7216,8 @@ void Score::undoRemoveMeasures(Measure* m1, Measure* m2, bool preserveTies, bool
71187216 }
71197217 }
71207218
7219+ removeSystemLocksOnRemoveMeasures (m1, m2);
7220+
71217221 undo (new RemoveMeasures (m1, m2, moveStaffTypeChanges));
71227222}
71237223
0 commit comments