Skip to content

Commit

Permalink
allow replacement of 'b' and '#' with unicode equivalent in insrt names
Browse files Browse the repository at this point in the history
  • Loading branch information
asattely committed May 3, 2023
1 parent 133e5bf commit c876eda
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/engraving/libmscore/instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
//---------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions src/engraving/libmscore/instrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

//---------------------------------------------------------
Expand Down Expand Up @@ -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; }
Expand Down
1 change: 1 addition & 0 deletions src/importexport/musicxml/internal/musicxml/importmxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down

0 comments on commit c876eda

Please sign in to comment.