Skip to content

Commit

Permalink
Handle instrument changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sammik committed Dec 25, 2024
1 parent 85e8292 commit 02df82c
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 @@ -2789,7 +2789,22 @@ void Score::deleteItem(EngravingItem* el)
// remove section break key signatures
bool isFirst = mb && mb->tick().isZero();
for (KeySig* ks : lb->keySigs()) {
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 @@ -6037,13 +6052,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 02df82c

Please sign in to comment.