Skip to content

Commit

Permalink
Handle instrument changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sammik committed Mar 7, 2025
1 parent 7a22ac6 commit 1bc91e8
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/engraving/dom/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2899,7 +2899,22 @@ void Score::deleteItem(EngravingItem* el)
if (!ks->forSectionBreak()) {
continue;
}
if (isFirst) {
Staff* staff = ks->staff();
Fraction tick = ks->tick();
KeySigEvent actualKey = ks->keySigEvent();
KeySigEvent prevKey = staff->prevKey(tick);

// do not remove keysig on first measure, or if signatures differ

// if previous signature is "forInstrumentChange",
// comparation returns false, even if they are otherwise identical
// (because one is forInstrumentChange and second not)
// so we need to remove "forInstrumentChange" flag first
if (prevKey.forInstrumentChange()) {
prevKey.setForInstrumentChange(false);
}

if (isFirst || actualKey != prevKey) {
ks->setForSectionBreak(false);
} else {
deleteItem(ks);
Expand Down Expand Up @@ -6167,13 +6182,13 @@ void Score::undoAddElement(EngravingItem* element, bool addToLinkedStaves, bool
MeasureBase* m = lb->measure();

// add Key Signature on Section Break
// TODO: special case for instrument change
Fraction tick = m->endTick();
int ticks = tick.ticks();
for (Staff* staff : score()->staves()) {
KeyList* kl = staff->keyList();
if (kl->currentKeyTick(ticks) != ticks) {
KeySigEvent ks = kl->key(ticks);
KeySigEvent ks = kl->key(ticks);
if (kl->currentKeyTick(ticks) != ticks || ks.forInstrumentChange()) {
ks.setForInstrumentChange(false);
ks.setForSectionBreak(true);
undoChangeKeySig(staff, tick, ks);
}
Expand Down

0 comments on commit 1bc91e8

Please sign in to comment.