Skip to content

Commit

Permalink
fix musescore#17037: allow replacement of 'b' and '#' with unicode eq…
Browse files Browse the repository at this point in the history
…uivalent in insrt names
  • Loading branch information
asattely authored and RomanPudashkin committed Jul 12, 2023
1 parent f0e8873 commit d5f1320
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/importexport/musicxml/internal/musicxml/importmxml.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
Expand Down Expand Up @@ -53,6 +53,34 @@ static int musicXMLImportErrorDialog(QString text, QString detailedText)
return errorDialog.exec();
}

static void updateNamesForAccidentals(Instrument* inst)
{
auto replace = [](String name) {
name = 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 = 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♯)"));

return name;
};
// change staff names from simple text (eg 'Eb') to text using accidental symbols (eg 'E♭')

// Instrument::longNames() is const af so we need to make a deep copy, update it, and then set it again
StaffNameList longNamesCopy = inst->longNames();
for (StaffName& sn : longNamesCopy) {
sn.setName(replace(sn.name()));
}
StaffNameList shortNamesCopy = inst->shortNames();
for (StaffName& sn : shortNamesCopy) {
sn.setName(replace(sn.name()));
}
inst->setLongNames(longNamesCopy);
inst->setShortNames(shortNamesCopy);
}

//---------------------------------------------------------
// importMusicXMLfromBuffer
//---------------------------------------------------------
Expand Down Expand Up @@ -83,6 +111,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();
updateNamesForAccidentals(pair.second);
}
}

Expand Down

0 comments on commit d5f1320

Please sign in to comment.