From 0cdde77f8e385cec8e5dcd9da90e522ce3ef8571 Mon Sep 17 00:00:00 2001 From: ws Date: Tue, 9 Jun 2015 17:41:05 +0200 Subject: [PATCH] fix #59301 Deleting measure with clef change corrupts clef map --- libmscore/staff.cpp | 3 ++- libmscore/undo.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/libmscore/staff.cpp b/libmscore/staff.cpp index 1c421a3ec447..3e26554727af 100644 --- a/libmscore/staff.cpp +++ b/libmscore/staff.cpp @@ -1036,7 +1036,8 @@ void Staff::insertTime(int tick, int len) m = m->prevMeasure(); Segment* s = m->findSegment(Segment::Type::Clef, tick); if (s) { - Clef* clef = static_cast(s->element(idx())); + int track = idx() * VOICES; + Clef* clef = static_cast(s->element(track)); if (clef) setClef(clef); } diff --git a/libmscore/undo.cpp b/libmscore/undo.cpp index 6e42a8b640c9..284116a58049 100644 --- a/libmscore/undo.cpp +++ b/libmscore/undo.cpp @@ -3053,6 +3053,22 @@ void InsertRemoveMeasures::removeMeasures() score->fixTicks(); if (fm->type() == Element::Type::MEASURE) { score->setPlaylistDirty(); + + // check if there is a clef at the end of last measure + // remove clef from staff cleflist + + if (lm->type() == Element::Type::MEASURE) { + Measure* m = static_cast(lm); + Segment* s = m->findSegment(Segment::Type::Clef, tick2); + if (s) { + for (int staffIdx = 0; staffIdx <= score->nstaves(); ++staffIdx) { + Clef* clef = static_cast(s->element(staffIdx * VOICES)); + if (clef) + score->staff(staffIdx)->removeClef(clef); + } + } + } + score->insertTime(tick1, -(tick2 - tick1)); score->setLayoutAll(true); for (Spanner* sp : score->unmanagedSpanners())