Skip to content

Commit 072ca62

Browse files
committed
Fix
1 parent 67f8616 commit 072ca62

File tree

2 files changed

+42
-13
lines changed

2 files changed

+42
-13
lines changed

src/engraving/dom/instrchange.cpp

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "score.h"
3535
#include "segment.h"
3636
#include "staff.h"
37-
3837
#include "log.h"
3938

4039
using namespace mu;
@@ -82,8 +81,15 @@ InstrumentChange::~InstrumentChange()
8281
void InstrumentChange::setInstrument(const Instrument& i)
8382
{
8483
*m_instrument = i;
85-
//delete _instrument;
86-
//_instrument = new Instrument(i);
84+
// Number of staves for this instrument
85+
size_t n = i.cleffTypeCount();
86+
_concertClefs.resize(n);
87+
_transposingClefs.resize(n);
88+
for (size_t s = 0; s < n; ++s) {
89+
ClefTypeList ct = i.clefType(s);
90+
_concertClefs[s] = ct.concertClef;
91+
_transposingClefs[s] = ct.transposingClef;
92+
}
8793
}
8894

8995
void InstrumentChange::setupInstrument(const Instrument* instrument)
@@ -101,17 +107,26 @@ void InstrumentChange::setupInstrument(const Instrument* instrument)
101107

102108
// change the clef for each staff
103109
for (size_t i = 0; i < part->nstaves(); i++) {
104-
ClefType oldClefType = concPitch ? part->instrument(tickStart)->clefType(i).concertClef
105-
: part->instrument(tickStart)->clefType(i).transposingClef;
106-
ClefType newClefType = concPitch ? instrument->clefType(i).concertClef
107-
: instrument->clefType(i).transposingClef;
108-
// Introduce cleff change only if the new clef *symbol* is different from the old one
109-
if (ClefInfo::symId(oldClefType) != ClefInfo::symId(newClefType)) {
110-
// 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.
111-
EngravingItem* element = rtick().isZero() ? toEngravingItem(findMeasure()) : toEngravingItem(this);
112-
score()->undoChangeClef(part->staff(i), element, newClefType, true);
113-
}
110+
ClefType oldClefType = concPitch ? part->instrument(tickStart)->clefType(i).concertClef
111+
: part->instrument(tickStart)->clefType(i).transposingClef;
112+
ClefTypeList ct = instrument->clefType(i);
113+
ClefType newClefType = concPitch ? ct.concertClef : ct.transposingClef;
114+
if (ClefInfo::symId(oldClefType) != ClefInfo::symId(newClefType)) {
115+
EngravingItem* element = rtick().isZero() ? toEngravingItem(findMeasure()) : toEngravingItem(this);
116+
score()->undoChangeClef(part->staff(i), element, newClefType, true);
114117
}
118+
}
119+
120+
for (size_t i = 0; i < part->nstaves(); i++) {
121+
Staff* staff = part->staff(i);
122+
123+
ClefType oldClef = staff->clef(tickStart);
124+
ClefType newClef = clefTypeForCurrentLayout(i);
125+
126+
if (ClefInfo::symId(oldClef) != ClefInfo::symId(newClef)) {
127+
score()->undoChangeClef(staff, this, newClef, true);
128+
}
129+
}
115130

116131
// Change key signature if necessary. CAUTION: not necessary in case of octave-transposing!
117132
if ((v.chromatic - oldV.chromatic) % 12) {
@@ -213,4 +228,13 @@ engraving::PropertyValue InstrumentChange::propertyDefault(Pid propertyId) const
213228
return TextBase::propertyDefault(propertyId);
214229
}
215230
}
231+
232+
ClefType InstrumentChange::clefTypeForCurrentLayout(size_t staffIndex) const
233+
{
234+
bool isConcert = score()->style().styleB(Sid::concertPitch);
235+
return isConcert
236+
? _concertClefs[staffIndex]
237+
: _transposingClefs[staffIndex];
238+
}
239+
216240
}

src/engraving/dom/instrchange.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ class InstrumentChange final : public TextBase
6767

6868
bool placeMultiple() const override { return false; }
6969

70+
ClefType clefTypeForCurrentLayout(size_t staffIndex) const;
71+
72+
std::vector<ClefType> _concertClefs;
73+
std::vector<ClefType> _transposingClefs;
74+
7075
private:
7176

7277
Instrument* m_instrument = nullptr; // Staff holds ownership if part of score

0 commit comments

Comments
 (0)