Skip to content

Commit

Permalink
fix musescore#18425 - part containing key with more than 6 accidental…
Browse files Browse the repository at this point in the history
…s has to be PreferSharpFlat::NONE
  • Loading branch information
sammik committed Jul 6, 2023
1 parent fff51ed commit 660df4b
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/engraving/rw/read400/tread.cpp
Expand Up @@ -1279,6 +1279,11 @@ void TRead::read(KeySig* s, XmlReader& e, ReadContext& ctx)
if (sig.custom() && sig.customKeyDefs().empty()) {
sig.setMode(KeyMode::NONE);
}
// if there are more than 6 accidentals in transposing key, it cannot be PreferSharpFlat::AUTO
if (p && !s->concertPitch() && (sig.key() > 6 || sig.key() < -6)
&& p->preferSharpFlat() == PreferSharpFlat::AUTO && !p->instrument(s->tick())->transpose().isZero()) {
p->setPreferSharpFlat(PreferSharpFlat::NONE);
}

s->setKeySigEvent(sig);
}
Expand Down
5 changes: 5 additions & 0 deletions src/engraving/rw/read410/tread.cpp
Expand Up @@ -1284,6 +1284,11 @@ void TRead::read(KeySig* s, XmlReader& e, ReadContext& ctx)
if (sig.custom() && sig.customKeyDefs().empty()) {
sig.setMode(KeyMode::NONE);
}
// if there are more than 6 accidentals in transposing key, it cannot be PreferSharpFlat::AUTO
if (p && !s->concertPitch() && (sig.key() > 6 || sig.key() < -6)
&& p->preferSharpFlat() == PreferSharpFlat::AUTO && !p->instrument(s->tick())->transpose().isZero()) {
p->setPreferSharpFlat(PreferSharpFlat::NONE);
}

s->setKeySigEvent(sig);
}
Expand Down
4 changes: 4 additions & 0 deletions src/importexport/bb/internal/bb.cpp
Expand Up @@ -561,6 +561,10 @@ Err importBB(MasterScore* score, const QString& name)
Interval v = staff->part()->instrument(tick)->transpose();
if (!v.isZero() && !score->style().styleB(Sid::concertPitch)) {
cKey = transposeKey(key, v);
// if there are more than 6 accidentals in transposing key, it cannot be PreferSharpFlat::AUTO
if ((key > 6 || key < -6) && staff->part()->preferSharpFlat() == PreferSharpFlat::AUTO) {
staff->part()->setPreferSharpFlat(PreferSharpFlat::NONE);
}
}
ke.setConcertKey(cKey);
ke.setKey(key);
Expand Down
7 changes: 6 additions & 1 deletion src/importexport/capella/internal/capella.cpp
Expand Up @@ -870,8 +870,13 @@ static Fraction readCapVoice(Score* score, CapVoice* cvoice, int staffIdx, const
Key tKey = Key(o->signature);
Key cKey = tKey;
Interval v = score->staff(staffIdx)->part()->instrument(tick)->transpose();
if (!v.isZero() && score->style().styleB(mu::engraving::Sid::concertPitch)) {
if (!v.isZero() && !score->style().styleB(mu::engraving::Sid::concertPitch)) {
cKey = transposeKey(tKey, v);
// if there are more than 6 accidentals in transposing key, it cannot be PreferSharpFlat::AUTO
Part* part = score->staff(staffIdx)->part();
if ((tKey > 6 || tKey < -6) && part->preferSharpFlat() == PreferSharpFlat::AUTO) {
part->setPreferSharpFlat(PreferSharpFlat::NONE);
}
}
okey.setConcertKey(cKey);
okey.setKey(tKey);
Expand Down
4 changes: 4 additions & 0 deletions src/importexport/midi/internal/midiimport/importmidi.cpp
Expand Up @@ -334,6 +334,10 @@ void MTrack::processMeta(int tick, const MidiEvent& mm)
Interval v = staff->part()->instrument(t)->transpose();
if (!v.isZero() && !cs->style().styleB(Sid::concertPitch)) {
cKey = transposeKey(tKey, v);
// if there are more than 6 accidentals in transposing key, it cannot be PreferSharpFlat::AUTO
if ((tKey > 6 || tKey < -6) && staff->part()->preferSharpFlat() == PreferSharpFlat::AUTO) {
staff->part()->setPreferSharpFlat(PreferSharpFlat::NONE);
}
}
ke.setConcertKey(cKey);
ke.setKey(tKey);
Expand Down
Expand Up @@ -3826,6 +3826,11 @@ void MusicXMLParserPass2::key(const QString& partId, Measure* measure, const Fra
Interval v = _pass1.getPart(partId)->instrument()->transpose();
if (!v.isZero() && !_score->style().styleB(Sid::concertPitch)) {
cKey = transposeKey(tKey, v);
// if there are more than 6 accidentals in transposing key, it cannot be PreferSharpFlat::AUTO
Part* part = _pass1.getPart(partId);
if ((tKey > 6 || tKey < -6) && part->preferSharpFlat() == PreferSharpFlat::AUTO) {
part->setPreferSharpFlat(PreferSharpFlat::NONE);
}
}
key.setConcertKey(cKey);
key.setKey(tKey);
Expand Down
4 changes: 4 additions & 0 deletions src/importexport/ove/internal/importove.cpp
Expand Up @@ -841,6 +841,10 @@ void OveToMScore::convertSignatures()
Interval v = staff.part()->instrument(tick)->transpose();
if (!v.isZero() && !m_score->style().styleB(Sid::concertPitch)) {
cKey = transposeKey(key, v);
// if there are more than 6 accidentals in transposing key, it cannot be PreferSharpFlat::AUTO
if ((key > 6 || key < -6) && staff.part()->preferSharpFlat() == PreferSharpFlat::AUTO) {
staff.part()->setPreferSharpFlat(PreferSharpFlat::NONE);
}
}
ke.setConcertKey(cKey);
ke.setKey(key);
Expand Down

0 comments on commit 660df4b

Please sign in to comment.