From 660df4b462844003a15159b46bb09833cc50b5fb Mon Sep 17 00:00:00 2001 From: sammik Date: Thu, 6 Jul 2023 23:47:11 +0200 Subject: [PATCH] fix #18425 - part containing key with more than 6 accidentals has to be PreferSharpFlat::NONE --- src/engraving/rw/read400/tread.cpp | 5 +++++ src/engraving/rw/read410/tread.cpp | 5 +++++ src/importexport/bb/internal/bb.cpp | 4 ++++ src/importexport/capella/internal/capella.cpp | 7 ++++++- src/importexport/midi/internal/midiimport/importmidi.cpp | 4 ++++ .../musicxml/internal/musicxml/importmxmlpass2.cpp | 5 +++++ src/importexport/ove/internal/importove.cpp | 4 ++++ 7 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/engraving/rw/read400/tread.cpp b/src/engraving/rw/read400/tread.cpp index c5650deab2f89..a27c25e6a90c6 100644 --- a/src/engraving/rw/read400/tread.cpp +++ b/src/engraving/rw/read400/tread.cpp @@ -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); } diff --git a/src/engraving/rw/read410/tread.cpp b/src/engraving/rw/read410/tread.cpp index 290e3a574340a..6a8ebb1ed7b26 100644 --- a/src/engraving/rw/read410/tread.cpp +++ b/src/engraving/rw/read410/tread.cpp @@ -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); } diff --git a/src/importexport/bb/internal/bb.cpp b/src/importexport/bb/internal/bb.cpp index e767604285bad..a2ebae62ea298 100644 --- a/src/importexport/bb/internal/bb.cpp +++ b/src/importexport/bb/internal/bb.cpp @@ -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); diff --git a/src/importexport/capella/internal/capella.cpp b/src/importexport/capella/internal/capella.cpp index b16a3c70076fa..f2f9a3f3077b8 100644 --- a/src/importexport/capella/internal/capella.cpp +++ b/src/importexport/capella/internal/capella.cpp @@ -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); diff --git a/src/importexport/midi/internal/midiimport/importmidi.cpp b/src/importexport/midi/internal/midiimport/importmidi.cpp index 02ba76f3ab441..7f4cf8ec64a4a 100644 --- a/src/importexport/midi/internal/midiimport/importmidi.cpp +++ b/src/importexport/midi/internal/midiimport/importmidi.cpp @@ -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); diff --git a/src/importexport/musicxml/internal/musicxml/importmxmlpass2.cpp b/src/importexport/musicxml/internal/musicxml/importmxmlpass2.cpp index bd03ec0f64e49..7972a73d5711e 100644 --- a/src/importexport/musicxml/internal/musicxml/importmxmlpass2.cpp +++ b/src/importexport/musicxml/internal/musicxml/importmxmlpass2.cpp @@ -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); diff --git a/src/importexport/ove/internal/importove.cpp b/src/importexport/ove/internal/importove.cpp index 7506c78b1015b..5563979ef08ae 100644 --- a/src/importexport/ove/internal/importove.cpp +++ b/src/importexport/ove/internal/importove.cpp @@ -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);