From 5a75119ee0d95b38a59f96c6b79531ce0f130f3b Mon Sep 17 00:00:00 2001 From: asattely Date: Tue, 7 Nov 2023 18:34:31 +0100 Subject: [PATCH] Fix GH#17037: allow replacement of 'b' and '#' with unicode equivalent in insrt names Backport of #18556, part 4, resp. #17118 Disabled for now, needs more work --- importexport/musicxml/importmxml.cpp | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/importexport/musicxml/importmxml.cpp b/importexport/musicxml/importmxml.cpp index 0275a5637c57f..30ca8ded74ea3 100644 --- a/importexport/musicxml/importmxml.cpp +++ b/importexport/musicxml/importmxml.cpp @@ -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 longNamesCopy = inst->longNames(); + for (StaffName& sn : longNamesCopy) + sn.setName(replace(sn.name())); + QList shortNamesCopy = inst->shortNames(); + for (StaffName& sn : shortNamesCopy) + sn.setName(replace(sn.name())); + inst->setLongNames(longNamesCopy); + inst->setShortNames(shortNamesCopy); + } +#endif + //--------------------------------------------------------- // importMusicXMLfromBuffer //--------------------------------------------------------- @@ -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())) {