diff --git a/src/engraving/libmscore/instrument.cpp b/src/engraving/libmscore/instrument.cpp index e8cacf7f57ef1..540802c764ec7 100644 --- a/src/engraving/libmscore/instrument.cpp +++ b/src/engraving/libmscore/instrument.cpp @@ -166,6 +166,18 @@ StaffName::StaffName(const String& xmlText, int pos) TextBase::validateText(_name); // enforce HTML encoding } +void StaffName::xmlReplaceAccidentals() +{ + // instrument names in some musicXML use 'b' instead of '♭' for flat, so we need to convert them. + // i don't know if there is a valid reason for # to be in a staff name, but we convert it too just in case. + + _name.replace(std::regex(R"(((?:^|\s)([A-Ga-g]|[Uu][Tt]|[Dd][Oo]|[Rr][EeÉé]|[MmSsTt][Ii]|[FfLl][Aa]|[Ss][Oo][Ll]))b(?=\s|$))"), + String::fromStdString(R"($1♭)")); + + _name.replace(std::regex(R"(((?:^|\s)([A-Ga-g]|[Uu][Tt]|[Dd][Oo]|[Rr][EeÉé]|[MmSsTt][Ii]|[FfLl][Aa]|[Ss][Oo][Ll]))#(?=\s|$))"), + String::fromStdString(R"($1♯)")); +} + String Instrument::recognizeMusicXmlId() const { static const String defaultMusicXmlId(u"keyboard.piano"); @@ -1219,6 +1231,17 @@ void Instrument::updateInstrumentId() } } +void Instrument::updateNamesForAccidentals() +{ + // change staff names from simple text (eg 'Eb') to text using accidental symbols (eg 'E♭') + for (StaffName& sn : _longNames) { + sn.xmlReplaceAccidentals(); + } + for (StaffName& sn : _shortNames) { + sn.xmlReplaceAccidentals(); + } +} + //--------------------------------------------------------- // Instrument::playbackChannel //--------------------------------------------------------- diff --git a/src/engraving/libmscore/instrument.h b/src/engraving/libmscore/instrument.h index 6c9e63774a8c9..0f2fcee33fe75 100644 --- a/src/engraving/libmscore/instrument.h +++ b/src/engraving/libmscore/instrument.h @@ -66,6 +66,8 @@ class StaffName void setPos(int p) { _pos = p; } String name() const { return _name; } void setName(const String& n) { _name = n; } + + void xmlReplaceAccidentals(); }; //--------------------------------------------------------- @@ -425,6 +427,7 @@ class Instrument void setIsPrimary(bool isPrimary); void updateInstrumentId(); + void updateNamesForAccidentals(); bool singleNoteDynamics() const { return _singleNoteDynamics; } void setSingleNoteDynamics(bool val) { _singleNoteDynamics = val; } diff --git a/src/importexport/musicxml/internal/musicxml/importmxml.cpp b/src/importexport/musicxml/internal/musicxml/importmxml.cpp index 1cb5ef4695014..91e82d7b65309 100644 --- a/src/importexport/musicxml/internal/musicxml/importmxml.cpp +++ b/src/importexport/musicxml/internal/musicxml/importmxml.cpp @@ -83,6 +83,7 @@ Err importMusicXMLfromBuffer(Score* score, const QString& /*name*/, QIODevice* d for (const Part* part : score->parts()) { for (const auto& pair : part->instruments()) { pair.second->updateInstrumentId(); + pair.second->updateNamesForAccidentals(); } }