Skip to content

Commit

Permalink
Fix GH#17037: allow replacement of 'b' and '#' with unicode equivalen…
Browse files Browse the repository at this point in the history
…t in insrt names

Backport of musescore#18556, part 4, resp. musescore#17118

Disabled for now, needs more work
  • Loading branch information
asattely authored and Jojo-Schmitz committed Nov 7, 2023
1 parent 561dddf commit 5a75119
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions importexport/musicxml/importmxml.cpp
Expand Up @@ -93,6 +93,34 @@ static int musicXMLImportErrorDialog(QString text, QString detailedText)
return errorDialog.exec();
}

#if 0
static void updateNamesForAccidentals(Instrument* inst)
{
auto replace = [](QString 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|$))"),
QString::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|$))"),
QString::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
QList<StaffName> longNamesCopy = inst->longNames();
for (StaffName& sn : longNamesCopy)
sn.setName(replace(sn.name()));
QList<StaffName> shortNamesCopy = inst->shortNames();
for (StaffName& sn : shortNamesCopy)
sn.setName(replace(sn.name()));
inst->setLongNames(longNamesCopy);
inst->setShortNames(shortNamesCopy);
}
#endif

//---------------------------------------------------------
// importMusicXMLfromBuffer
//---------------------------------------------------------
Expand Down Expand Up @@ -125,6 +153,15 @@ Score::FileError importMusicXMLfromBuffer(Score* score, const QString& /*name*/,
res = pass2.parse(dev);
}

#if 0
for (const Part* part : score->parts()) {
for (const auto& pair : *part->instruments()) {
pair.second->updateInstrumentId();
updateNamesForAccidentals(pair.second);
}
}
#endif

// report result
const auto pass2_errors = pass2.errors();
if (!(pass1_errors.isEmpty() && pass2_errors.isEmpty())) {
Expand Down

0 comments on commit 5a75119

Please sign in to comment.