From c8c1c122086f401513ea0403a3bc605d671027f1 Mon Sep 17 00:00:00 2001 From: ws Date: Fri, 13 Mar 2015 12:39:38 +0100 Subject: [PATCH] update instrument list in part when inserting/deleting measures --- libmscore/part.cpp | 30 ++++++++++++++++++++++++++++++ libmscore/part.h | 1 + libmscore/score.cpp | 2 ++ libmscore/undo.cpp | 9 +++++++++ 4 files changed, 42 insertions(+) diff --git a/libmscore/part.cpp b/libmscore/part.cpp index 4c5b1e7b22..0ecb794537 100644 --- a/libmscore/part.cpp +++ b/libmscore/part.cpp @@ -505,5 +505,35 @@ int Part::endTrack() const return _staves.back()->idx() * VOICES + VOICES; } +//--------------------------------------------------------- +// insertTime +//--------------------------------------------------------- + +void Part::insertTime(int tick, int len) + { + if (len == 0) + return; + + // move all instruments + + if (len < 0) { + // remove instruments between tickpos >= tick and tickpos < (tick+len) + // ownership goes back to class InstrumentChange() + + auto si = _instrList.lower_bound(tick); + auto ei = _instrList.lower_bound(tick-len); + _instrList.erase(si, ei); + } + + InstrumentList il; + for (auto i = _instrList.lower_bound(tick); i != _instrList.end();) { + Instrument* instrument = i->second; + int tick = i->first; + _instrList.erase(i++); + _instrList[tick + len] = instrument; + } + _instrList.insert(il.begin(), il.end()); + } + } diff --git a/libmscore/part.h b/libmscore/part.h index d9394e4e9c..0f5524479d 100644 --- a/libmscore/part.h +++ b/libmscore/part.h @@ -120,6 +120,7 @@ class Part : public QObject, public ScoreElement { void setInstrument(const Instrument&&, int tick = -1); void setInstrument(const Instrument&, int tick = -1); void removeInstrument(int tick); + void insertTime(int tick, int len); QString partName() const { return _partName; } void setPartName(const QString& s) { _partName = s; } diff --git a/libmscore/score.cpp b/libmscore/score.cpp index a795193a86..30e6d42170 100644 --- a/libmscore/score.cpp +++ b/libmscore/score.cpp @@ -3430,6 +3430,8 @@ void Score::insertTime(int tick, int len) { for (Staff* staff : staves()) staff->insertTime(tick, len); + for (Part* part : parts()) + part->insertTime(tick, len); } //--------------------------------------------------------- diff --git a/libmscore/undo.cpp b/libmscore/undo.cpp index 302ee8005f..cb1fcd62af 100644 --- a/libmscore/undo.cpp +++ b/libmscore/undo.cpp @@ -2989,6 +2989,15 @@ void InsertRemoveMeasures::insertMeasures() if (fm->type() == Element::Type::MEASURE) { score->fixTicks(); score->insertTime(fm->tick(), lm->endTick() - fm->tick()); + + // move ownership of Instrument back to part + for (Segment* s = static_cast(fm)->first(); s != static_cast(lm)->last(); s = s->next1()) { + for (Element* e : s->annotations()) { + if (e->type() == Element::Type::INSTRUMENT_CHANGE) { + e->part()->setInstrument(static_cast(e)->instrument(), s->tick()); + } + } + } for (Clef* clef : clefs) clef->staff()->setClef(clef); for (KeySig* key : keys)