Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/notation/internal/masternotationparts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/notation/internal/notationparts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions src/notation/notationtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions src/notationscene/widgets/editstaff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand All @@ -712,6 +713,7 @@ void EditStaff::applyPartProperties()
name.customNameShortGroup());
}
notationParts()->replaceInstrument(m_instrumentKey, m_instrument);
instrumentChanged = true;
}

SharpFlat newSharpFlat = SharpFlat(preferSharpFlat->currentIndex());
Expand All @@ -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()
Expand Down
1 change: 0 additions & 1 deletion src/notationscene/widgets/editstaff.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading