diff --git a/src/engraving/dom/instrchange.cpp b/src/engraving/dom/instrchange.cpp index 9bc9a30c0ee8c..ba67fcd852450 100644 --- a/src/engraving/dom/instrchange.cpp +++ b/src/engraving/dom/instrchange.cpp @@ -99,20 +99,18 @@ void InstrumentChange::setupInstrument(const Instrument* instrument) Interval v = instrument->transpose(); bool concPitch = style().styleB(Sid::concertPitch); - // change the clef for each staff for (size_t i = 0; i < part->nstaves(); i++) { - ClefType oldClefType = concPitch ? part->instrument(tickStart)->clefType(i).concertClef - : part->instrument(tickStart)->clefType(i).transposingClef; - ClefType newClefType = concPitch ? instrument->clefType(i).concertClef - : instrument->clefType(i).transposingClef; - // Introduce cleff change only if the new clef *symbol* is different from the old one - if (ClefInfo::symId(oldClefType) != ClefInfo::symId(newClefType)) { - // If instrument change is at the start of a measure, use the measure as the element, as this will place the instrument change before the barline. + ClefTypeList oldClefTypeList = part->instrument(tickStart)->clefType(i); + ClefTypeList newClefTypeList = instrument->clefType(i); + if (ClefInfo::symId(oldClefTypeList.concertClef) != ClefInfo::symId(newClefTypeList.concertClef) + || ClefInfo::symId(oldClefTypeList.transposingClef) != ClefInfo::symId(newClefTypeList.transposingClef)) { + int cp = static_cast(newClefTypeList.concertClef); + int tp = static_cast(newClefTypeList.transposingClef); + int packedData = 1000 + (cp & 0xFF) + ((tp & 0xFF) << 8); EngravingItem* element = rtick().isZero() ? toEngravingItem(findMeasure()) : toEngravingItem(this); - score()->undoChangeClef(part->staff(i), element, newClefType, true); + score()->undoChangeClef(part->staff(i), element, newClefTypeList.concertClef, packedData); } } - // Change key signature if necessary. CAUTION: not necessary in case of octave-transposing! if ((v.chromatic - oldV.chromatic) % 12) { for (size_t i = 0; i < part->nstaves(); i++) { diff --git a/src/engraving/dom/score.h b/src/engraving/dom/score.h index 83b1b7ca444a1..77bd8aeb57b58 100644 --- a/src/engraving/dom/score.h +++ b/src/engraving/dom/score.h @@ -498,7 +498,7 @@ class Score : public EngravingObject, public muse::Contextable void undoChangeTuning(Note*, double); void undoChangeUserMirror(Note*, DirectionH); void undoChangeKeySig(Staff* ostaff, const Fraction& tick, KeySigEvent); - void undoChangeClef(Staff* ostaff, EngravingItem*, ClefType st, bool forInstrumentChange = false, Clef* clefToRelink = nullptr); + void undoChangeClef(Staff* ostaff, EngravingItem*, ClefType st, int forInstrumentChange = false, Clef* clefToRelink = nullptr); bool undoPropertyChanged(EngravingItem* item, Pid propId, const PropertyValue& propValue, PropertyFlags propFlags = PropertyFlags::NOSTYLE); void undoPropertyChanged(EngravingObject*, Pid, const PropertyValue& v, PropertyFlags ps = PropertyFlags::NOSTYLE); diff --git a/src/engraving/editing/edit.cpp b/src/engraving/editing/edit.cpp index 3cb9d0c687676..f0148cf03ed3a 100644 --- a/src/engraving/editing/edit.cpp +++ b/src/engraving/editing/edit.cpp @@ -6172,7 +6172,7 @@ void Score::updateInstrumentChangeTranspositions(KeySigEvent& key, Staff* staff, // create a clef before element e //--------------------------------------------------------- -void Score::undoChangeClef(Staff* ostaff, EngravingItem* e, ClefType ct, bool forInstrumentChange, Clef* clefToRelink) +void Score::undoChangeClef(Staff* ostaff, EngravingItem* e, ClefType ct, int forInstrumentChange, Clef* clefToRelink) { IF_ASSERT_FAILED(ostaff && e) { return; @@ -6210,6 +6210,14 @@ void Score::undoChangeClef(Staff* ostaff, EngravingItem* e, ClefType ct, bool fo Fraction tick = e->tick(); Fraction rtick = e->rtick(); bool isSmall = (st == SegmentType::Clef); + bool isIC = (forInstrumentChange >= 1000); + ClefType cp = ct; + ClefType tp = ct; + if (isIC) { + int val = forInstrumentChange - 1000; + cp = static_cast(static_cast(val & 0xFF)); + tp = static_cast(static_cast((val >> 8) & 0xFF)); + } for (Staff* staff : ostaff->staffList()) { if (clefToRelink && ostaff == staff) { continue; @@ -6239,7 +6247,7 @@ void Score::undoChangeClef(Staff* ostaff, EngravingItem* e, ClefType ct, bool fo StaffType* staffType = staff->staffType(e->tick()); StaffGroup staffGroup = staffType->group(); - if (ClefInfo::staffGroup(ct) != staffGroup && !forInstrumentChange) { + if (ClefInfo::staffGroup(ct) != staffGroup && !isIC) { continue; } @@ -6249,17 +6257,18 @@ void Score::undoChangeClef(Staff* ostaff, EngravingItem* e, ClefType ct, bool fo // clef type for concertPitch // Instrument* i = staff->part()->instrument(tick); - ClefType cp, tp; - if (i->transpose().isZero()) { - cp = ct; - tp = ct; - } else { - if (concertPitch) { + if (!isIC) { + if (i->transpose().isZero()) { cp = ct; - tp = clef->transposingClef(); - } else { - cp = clef->concertClef(); tp = ct; + } else { + if (concertPitch) { + cp = ct; + tp = clef->transposingClef(); + } else { + cp = clef->concertClef(); + tp = ct; + } } } clef->setGenerated(false); @@ -6285,7 +6294,12 @@ void Score::undoChangeClef(Staff* ostaff, EngravingItem* e, ClefType ct, bool fo clef->setScore(score); } else { clef = Factory::createClef(score->dummy()->segment()); - clef->setClefType(ct); + if (isIC) { + clef->setTransposingClef(tp); + clef->setConcertClef(cp); + } else { + clef->setClefType(ct); + } gclef = clef; } clef->setTrack(track); @@ -6293,7 +6307,7 @@ void Score::undoChangeClef(Staff* ostaff, EngravingItem* e, ClefType ct, bool fo clef->setIsHeader(st == SegmentType::HeaderClef); score->doUndoAddElement(clef); } - if (forInstrumentChange) { + if (isIC) { clef->setForInstrumentChange(true); } clef->setSmall(isSmall);