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
18 changes: 8 additions & 10 deletions src/engraving/dom/instrchange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,20 @@
Interval oldV = part->instrument(tickStart)->transpose();
Interval oldKv = staff()->transpose(tickStart);
Interval v = instrument->transpose();
bool concPitch = style().styleB(Sid::concertPitch);

Check warning on line 100 in src/engraving/dom/instrchange.cpp

View workflow job for this annotation

GitHub Actions / build (linux_arm64)

unused variable ‘concPitch’ [-Wunused-variable]

Check warning on line 100 in src/engraving/dom/instrchange.cpp

View workflow job for this annotation

GitHub Actions / build (linux_x64)

unused variable ‘concPitch’ [-Wunused-variable]

Check warning on line 100 in src/engraving/dom/instrchange.cpp

View workflow job for this annotation

GitHub Actions / windows_x64

'concPitch': local variable is initialized but not referenced

// 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<int>(newClefTypeList.concertClef);
int tp = static_cast<int>(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++) {
Expand Down
2 changes: 1 addition & 1 deletion src/engraving/dom/score.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
40 changes: 27 additions & 13 deletions src/engraving/editing/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ClefType>(static_cast<signed char>(val & 0xFF));
tp = static_cast<ClefType>(static_cast<signed char>((val >> 8) & 0xFF));
}
for (Staff* staff : ostaff->staffList()) {
if (clefToRelink && ostaff == staff) {
continue;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
Expand All @@ -6285,15 +6294,20 @@ 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);
clef->setParent(destSeg);
clef->setIsHeader(st == SegmentType::HeaderClef);
score->doUndoAddElement(clef);
}
if (forInstrumentChange) {
if (isIC) {
clef->setForInstrumentChange(true);
}
clef->setSmall(isSmall);
Expand Down
Loading