diff --git a/src/notation/internal/masternotationparts.cpp b/src/notation/internal/masternotationparts.cpp index 77fce7794066f..457a0c7c0add2 100644 --- a/src/notation/internal/masternotationparts.cpp +++ b/src/notation/internal/masternotationparts.cpp @@ -191,7 +191,7 @@ void MasterNotationParts::replaceInstrument(const InstrumentKey& instrumentKey, startGlobalEdit(TranslatableString("undoableAction", "Replace instrument")); Part* part = partModifiable(instrumentKey.partId); - bool isMainInstrument = part && isMainInstrumentForPart(instrumentKey, part); + bool isMainInstrument = part && isMainInstrumentForPart(instrumentKey); mu::engraving::Interval oldTranspose = part ? part->instrument()->transpose() : mu::engraving::Interval(0, 0); diff --git a/src/notation/internal/notationparts.cpp b/src/notation/internal/notationparts.cpp index b2233a86c3a45..854890c769fa9 100644 --- a/src/notation/internal/notationparts.cpp +++ b/src/notation/internal/notationparts.cpp @@ -726,7 +726,7 @@ void NotationParts::replaceInstrument(const InstrumentKey& instrumentKey, const startEdit(TranslatableString("undoableAction", "Replace instrument")); - if (isMainInstrumentForPart(instrumentKey, part)) { + if (isMainInstrumentForPart(instrumentKey)) { mu::engraving::EditPart::replacePartInstrument(score(), part, newInstrument, newStaffType); } else { if (!mu::engraving::EditPart::replaceInstrumentAtTick(score(), part, instrumentKey.tick, newInstrument)) { diff --git a/src/notation/notationtypes.h b/src/notation/notationtypes.h index ff7de63fcdfff..6f907547701e2 100644 --- a/src/notation/notationtypes.h +++ b/src/notation/notationtypes.h @@ -293,9 +293,9 @@ struct InstrumentKey Fraction tick = mu::engraving::Fraction(0, 1); }; -inline bool isMainInstrumentForPart(const InstrumentKey& instrumentKey, const Part* part) +inline bool isMainInstrumentForPart(const InstrumentKey& instrumentKey) { - return instrumentKey.instrumentId == part->instrumentId() && instrumentKey.tick == Part::MAIN_INSTRUMENT_TICK; + return instrumentKey.tick == Part::MAIN_INSTRUMENT_TICK; } inline QString formatInstrumentTitle(const QString& instrumentName, const InstrumentTrait& trait) diff --git a/src/notationscene/widgets/editstaff.cpp b/src/notationscene/widgets/editstaff.cpp index 7e0d5fbb74884..abf5ea7861162 100644 --- a/src/notationscene/widgets/editstaff.cpp +++ b/src/notationscene/widgets/editstaff.cpp @@ -152,7 +152,6 @@ void EditStaff::setStaff(Staff* s, const Fraction& tick) } m_instrument = *it->second; - m_orgInstrument = m_instrument; m_instrumentKey.instrumentId = m_instrument.id(); m_instrumentKey.partId = part->id(); @@ -662,8 +661,7 @@ void EditStaff::applyPartProperties() interval.flip(); } - Instrument prevInstrument = m_instrument; - + Instrument prevInstrument = instrument(); m_instrument.setTranspose(interval); m_instrument.setMinPitchA(m_minPitchA); m_instrument.setMaxPitchA(m_maxPitchA); @@ -700,8 +698,11 @@ void EditStaff::applyPartProperties() size_t staffIdxInPart = muse::indexOf(part->staves(), m_orgStaff); DO_ASSERT(staffIdxInPart != muse::nidx); + bool instrumentChanged = false; + if (m_instrument.id() != prevInstrument.id()) { masterNotationParts()->replaceInstrument(m_instrumentKey, m_instrument); + instrumentChanged = true; } else if (m_instrument != prevInstrument) { bool groupNameChanged = name.useCustomGroupName() != prevInstrument.instrumentLabel().useCustomGroupName() || name.customNameLongGroup() != prevInstrument.instrumentLabel().customNameLongGroup() @@ -712,6 +713,7 @@ void EditStaff::applyPartProperties() name.customNameShortGroup()); } notationParts()->replaceInstrument(m_instrumentKey, m_instrument); + instrumentChanged = true; } SharpFlat newSharpFlat = SharpFlat(preferSharpFlat->currentIndex()); @@ -723,6 +725,10 @@ void EditStaff::applyPartProperties() if (part->preferSharpFlat() != newSharpFlat) { notationParts()->setPartSharpFlat(m_instrumentKey.partId, newSharpFlat); } + + if (instrumentChanged) { + m_instrumentKey.instrumentId = m_instrument.id(); + } } void EditStaff::showReplaceInstrumentDialog() diff --git a/src/notationscene/widgets/editstaff.h b/src/notationscene/widgets/editstaff.h index 32b1fe552fc1e..28b2da467a9ad 100644 --- a/src/notationscene/widgets/editstaff.h +++ b/src/notationscene/widgets/editstaff.h @@ -110,7 +110,6 @@ private slots: mu::engraving::Staff* m_staff = nullptr; mu::engraving::Staff* m_orgStaff = nullptr; Instrument m_instrument; - Instrument m_orgInstrument; InstrumentKey m_instrumentKey; int m_minPitchA, m_maxPitchA, m_minPitchP, m_maxPitchP; mu::engraving::Fraction m_tick;