update instrument list in part when inserting/deleting measures
This commit is contained in:
parent
8282094dd6
commit
c8c1c12208
4 changed files with 42 additions and 0 deletions
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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; }
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
|
|
|
@ -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<Measure*>(fm)->first(); s != static_cast<Measure*>(lm)->last(); s = s->next1()) {
|
||||
for (Element* e : s->annotations()) {
|
||||
if (e->type() == Element::Type::INSTRUMENT_CHANGE) {
|
||||
e->part()->setInstrument(static_cast<InstrumentChange*>(e)->instrument(), s->tick());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Clef* clef : clefs)
|
||||
clef->staff()->setClef(clef);
|
||||
for (KeySig* key : keys)
|
||||
|
|
Loading…
Reference in a new issue