From 69bffc50a1e6f0e952750862ad5599e7fcb26308 Mon Sep 17 00:00:00 2001 From: Klaus Rettinghaus Date: Thu, 26 Sep 2024 10:19:24 +0200 Subject: [PATCH 1/5] fully export instrument change --- .../musicxml/internal/musicxml/exportxml.cpp | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/importexport/musicxml/internal/musicxml/exportxml.cpp b/src/importexport/musicxml/internal/musicxml/exportxml.cpp index 480cb00500f1b..8bcfc069c929c 100644 --- a/src/importexport/musicxml/internal/musicxml/exportxml.cpp +++ b/src/importexport/musicxml/internal/musicxml/exportxml.cpp @@ -391,6 +391,7 @@ class ExportMusicXml : public muse::Injectable double getTenthsFromInches(double) const; double getTenthsFromDots(double) const; Fraction tick() const { return m_tick; } + void writeInstrumentChange(const InstrumentChange* instrChange); void writeInstrumentDetails(const Instrument* instrument, const bool concertPitch); static bool canWrite(const EngravingItem* e); @@ -6365,7 +6366,7 @@ static bool commonAnnotations(ExportMusicXml* exp, const EngravingItem* e, staff // optionally writing the associated staff text is done below if (e->isInstrumentChange()) { const InstrumentChange* instrChange = toInstrumentChange(e); - exp->writeInstrumentDetails(instrChange->instrument(), false); + exp->writeInstrumentChange(instrChange); instrChangeHandled = true; } @@ -7731,6 +7732,48 @@ static void writeStaffDetails(XmlWriter& xml, const Part* part) } } +//--------------------------------------------------------- +// writeInstrumentChange +//--------------------------------------------------------- + +/** + Write the instrument change. + */ + +void ExportMusicXml::writeInstrumentChange(const InstrumentChange* instrChange) +{ + const Instrument* instr = instrChange->instrument(); + const Part* part = instrChange->part(); + const size_t partNr = muse::indexOf(m_score->parts(), part); + const int instNr = muse::value(m_instrMap, instr, -1); + static const std::wregex acc(L"[♭♯]"); + + m_xml.startElement("print"); + m_xml.tag("part-name", instr->nameAsPlainText().replace(u"♭", u"b").replace(u"♯", u"#")); + if (instr->nameAsPlainText().contains(acc)) { + m_xml.startElement("part-name-display"); + writeDisplayName(m_xml, instr->nameAsPlainText()); + m_xml.endElement(); + } + if (!instr->abbreviatureAsPlainText().isEmpty()) { + m_xml.tag("part-abbreviation", instr->abbreviatureAsPlainText().replace(u"♭", u"b").replace(u"♯", u"#")); + if (instr->abbreviatureAsPlainText().contains(acc)) { + m_xml.startElement("part-abbreviation-display"); + writeDisplayName(m_xml, instr->abbreviatureAsPlainText()); + m_xml.endElement(); + } + } + m_xml.endElement(); + + writeInstrumentDetails(instrChange->instrument(), m_score->style().styleB(Sid::concertPitch)); + + m_xml.startElement("sound"); + m_xml.startElement("instrument-change"); + scoreInstrument(m_xml, static_cast(partNr) + 1, instNr + 1, instr->trackName(), instrChange->instrument()); + m_xml.endElement(); + m_xml.endElement(); +} + //--------------------------------------------------------- // writeInstrumentDetails //--------------------------------------------------------- From 7e792a88a1097d69e296c6fdf48975a91a8006c5 Mon Sep 17 00:00:00 2001 From: Klaus Rettinghaus Date: Thu, 26 Sep 2024 10:42:57 +0200 Subject: [PATCH 2/5] simplify --- src/importexport/musicxml/internal/musicxml/exportxml.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/importexport/musicxml/internal/musicxml/exportxml.cpp b/src/importexport/musicxml/internal/musicxml/exportxml.cpp index 8bcfc069c929c..676d85d392eb1 100644 --- a/src/importexport/musicxml/internal/musicxml/exportxml.cpp +++ b/src/importexport/musicxml/internal/musicxml/exportxml.cpp @@ -7769,7 +7769,7 @@ void ExportMusicXml::writeInstrumentChange(const InstrumentChange* instrChange) m_xml.startElement("sound"); m_xml.startElement("instrument-change"); - scoreInstrument(m_xml, static_cast(partNr) + 1, instNr + 1, instr->trackName(), instrChange->instrument()); + scoreInstrument(m_xml, static_cast(partNr) + 1, instNr + 1, instr->trackName(), instr); m_xml.endElement(); m_xml.endElement(); } From 3c2c36fa14c4c5cc943930c8e29b15070efab1e9 Mon Sep 17 00:00:00 2001 From: Klaus Rettinghaus Date: Thu, 26 Sep 2024 10:53:53 +0200 Subject: [PATCH 3/5] update tests --- ...testInstrumentChangeMIDIportExport_ref.xml | 11 ++++++++++ .../data/testMultiInstrumentPart3_ref.xml | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/importexport/musicxml/tests/data/testInstrumentChangeMIDIportExport_ref.xml b/src/importexport/musicxml/tests/data/testInstrumentChangeMIDIportExport_ref.xml index e11f4cda0f3bc..4d98b4a69b8b0 100644 --- a/src/importexport/musicxml/tests/data/testInstrumentChangeMIDIportExport_ref.xml +++ b/src/importexport/musicxml/tests/data/testInstrumentChangeMIDIportExport_ref.xml @@ -1060,6 +1060,17 @@ + + Voice + Vo. + + + + + Voice + + + Voice diff --git a/src/importexport/musicxml/tests/data/testMultiInstrumentPart3_ref.xml b/src/importexport/musicxml/tests/data/testMultiInstrumentPart3_ref.xml index 1d5d86cc1e518..b2801c8cbee34 100644 --- a/src/importexport/musicxml/tests/data/testMultiInstrumentPart3_ref.xml +++ b/src/importexport/musicxml/tests/data/testMultiInstrumentPart3_ref.xml @@ -168,12 +168,33 @@ -3 + + Bb Clarinet + + B + flat + Clarinet + + Bb Cl. + + B + flat + Cl. + + -1 -2 + + + + B♭ Clarinet + + + B♭ Clarinet From ec12b18bec4c7bbdb68e8db09fb22064deb25b5a Mon Sep 17 00:00:00 2001 From: Klaus Rettinghaus Date: Thu, 26 Sep 2024 12:16:00 +0200 Subject: [PATCH 4/5] update tests --- .../testChangeTranspose-no-diatonic_ref.xml | 11 ++++++++++ .../tests/data/testChangeTranspose.xml | 11 ++++++++++ .../tests/data/testMultiInstrumentPart1.xml | 11 ++++++++++ .../tests/data/testMultiInstrumentPart2.xml | 22 +++++++++++++++++++ 4 files changed, 55 insertions(+) diff --git a/src/importexport/musicxml/tests/data/testChangeTranspose-no-diatonic_ref.xml b/src/importexport/musicxml/tests/data/testChangeTranspose-no-diatonic_ref.xml index 1258193551636..1110feba98ade 100644 --- a/src/importexport/musicxml/tests/data/testChangeTranspose-no-diatonic_ref.xml +++ b/src/importexport/musicxml/tests/data/testChangeTranspose-no-diatonic_ref.xml @@ -100,12 +100,23 @@ 2 + + A Clarinet + A Cl. + -1 -2 + + + + B♭ Clarinet + + + To B♭ Clarinet diff --git a/src/importexport/musicxml/tests/data/testChangeTranspose.xml b/src/importexport/musicxml/tests/data/testChangeTranspose.xml index b690658f66625..f4773b45c2750 100644 --- a/src/importexport/musicxml/tests/data/testChangeTranspose.xml +++ b/src/importexport/musicxml/tests/data/testChangeTranspose.xml @@ -100,12 +100,23 @@ 2 + + A Clarinet + A Cl. + -1 -2 + + + + B♭ Clarinet + + + To B♭ Clarinet diff --git a/src/importexport/musicxml/tests/data/testMultiInstrumentPart1.xml b/src/importexport/musicxml/tests/data/testMultiInstrumentPart1.xml index fddb90c401dae..8edd69d7afae9 100644 --- a/src/importexport/musicxml/tests/data/testMultiInstrumentPart1.xml +++ b/src/importexport/musicxml/tests/data/testMultiInstrumentPart1.xml @@ -83,6 +83,17 @@ + + Piano + Pno. + + + + + Flute + + + Flute diff --git a/src/importexport/musicxml/tests/data/testMultiInstrumentPart2.xml b/src/importexport/musicxml/tests/data/testMultiInstrumentPart2.xml index 3118a5e2d7076..df567bbd42634 100644 --- a/src/importexport/musicxml/tests/data/testMultiInstrumentPart2.xml +++ b/src/importexport/musicxml/tests/data/testMultiInstrumentPart2.xml @@ -107,6 +107,17 @@ + + Piano + Pno. + + + + + Flute + + + Flute @@ -246,6 +257,17 @@ + + Voice + Vo. + + + + + C Trumpet + + + Trumpet From 5bad6ac1a1c3bcf8d3af27f4dbc1bb88f1b98e6c Mon Sep 17 00:00:00 2001 From: Klaus Rettinghaus Date: Thu, 26 Sep 2024 19:03:21 +0200 Subject: [PATCH 5/5] fix output --- .../musicxml/internal/musicxml/exportxml.cpp | 21 ++++++++----------- .../testChangeTranspose-no-diatonic_ref.xml | 8 +++++-- .../tests/data/testChangeTranspose.xml | 8 +++++-- ...testInstrumentChangeMIDIportExport_ref.xml | 8 +++++-- .../tests/data/testMultiInstrumentPart1.xml | 8 +++++-- .../tests/data/testMultiInstrumentPart2.xml | 16 ++++++++++---- .../data/testMultiInstrumentPart3_ref.xml | 2 -- 7 files changed, 45 insertions(+), 26 deletions(-) diff --git a/src/importexport/musicxml/internal/musicxml/exportxml.cpp b/src/importexport/musicxml/internal/musicxml/exportxml.cpp index 676d85d392eb1..059ce6722c06d 100644 --- a/src/importexport/musicxml/internal/musicxml/exportxml.cpp +++ b/src/importexport/musicxml/internal/musicxml/exportxml.cpp @@ -7746,26 +7746,23 @@ void ExportMusicXml::writeInstrumentChange(const InstrumentChange* instrChange) const Part* part = instrChange->part(); const size_t partNr = muse::indexOf(m_score->parts(), part); const int instNr = muse::value(m_instrMap, instr, -1); - static const std::wregex acc(L"[♭♯]"); + const String longName = instr->nameAsPlainText(); + const String shortName = instr->abbreviatureAsPlainText(); m_xml.startElement("print"); - m_xml.tag("part-name", instr->nameAsPlainText().replace(u"♭", u"b").replace(u"♯", u"#")); - if (instr->nameAsPlainText().contains(acc)) { + if (!longName.isEmpty()) { m_xml.startElement("part-name-display"); - writeDisplayName(m_xml, instr->nameAsPlainText()); + writeDisplayName(m_xml, longName); m_xml.endElement(); } - if (!instr->abbreviatureAsPlainText().isEmpty()) { - m_xml.tag("part-abbreviation", instr->abbreviatureAsPlainText().replace(u"♭", u"b").replace(u"♯", u"#")); - if (instr->abbreviatureAsPlainText().contains(acc)) { - m_xml.startElement("part-abbreviation-display"); - writeDisplayName(m_xml, instr->abbreviatureAsPlainText()); - m_xml.endElement(); - } + if (!shortName.isEmpty()) { + m_xml.startElement("part-abbreviation-display"); + writeDisplayName(m_xml, shortName); + m_xml.endElement(); } m_xml.endElement(); - writeInstrumentDetails(instrChange->instrument(), m_score->style().styleB(Sid::concertPitch)); + writeInstrumentDetails(instr, m_score->style().styleB(Sid::concertPitch)); m_xml.startElement("sound"); m_xml.startElement("instrument-change"); diff --git a/src/importexport/musicxml/tests/data/testChangeTranspose-no-diatonic_ref.xml b/src/importexport/musicxml/tests/data/testChangeTranspose-no-diatonic_ref.xml index 1110feba98ade..3a1951910a203 100644 --- a/src/importexport/musicxml/tests/data/testChangeTranspose-no-diatonic_ref.xml +++ b/src/importexport/musicxml/tests/data/testChangeTranspose-no-diatonic_ref.xml @@ -101,8 +101,12 @@ - A Clarinet - A Cl. + + A Clarinet + + + A Cl. + diff --git a/src/importexport/musicxml/tests/data/testChangeTranspose.xml b/src/importexport/musicxml/tests/data/testChangeTranspose.xml index f4773b45c2750..d4c72d1a3e1c9 100644 --- a/src/importexport/musicxml/tests/data/testChangeTranspose.xml +++ b/src/importexport/musicxml/tests/data/testChangeTranspose.xml @@ -101,8 +101,12 @@ - A Clarinet - A Cl. + + A Clarinet + + + A Cl. + diff --git a/src/importexport/musicxml/tests/data/testInstrumentChangeMIDIportExport_ref.xml b/src/importexport/musicxml/tests/data/testInstrumentChangeMIDIportExport_ref.xml index 4d98b4a69b8b0..a7938d6c8997b 100644 --- a/src/importexport/musicxml/tests/data/testInstrumentChangeMIDIportExport_ref.xml +++ b/src/importexport/musicxml/tests/data/testInstrumentChangeMIDIportExport_ref.xml @@ -1061,8 +1061,12 @@ - Voice - Vo. + + Voice + + + Vo. + diff --git a/src/importexport/musicxml/tests/data/testMultiInstrumentPart1.xml b/src/importexport/musicxml/tests/data/testMultiInstrumentPart1.xml index 8edd69d7afae9..78bd5afd99eb8 100644 --- a/src/importexport/musicxml/tests/data/testMultiInstrumentPart1.xml +++ b/src/importexport/musicxml/tests/data/testMultiInstrumentPart1.xml @@ -84,8 +84,12 @@ - Piano - Pno. + + Piano + + + Pno. + diff --git a/src/importexport/musicxml/tests/data/testMultiInstrumentPart2.xml b/src/importexport/musicxml/tests/data/testMultiInstrumentPart2.xml index df567bbd42634..3138a4b4e4c97 100644 --- a/src/importexport/musicxml/tests/data/testMultiInstrumentPart2.xml +++ b/src/importexport/musicxml/tests/data/testMultiInstrumentPart2.xml @@ -108,8 +108,12 @@ - Piano - Pno. + + Piano + + + Pno. + @@ -258,8 +262,12 @@ - Voice - Vo. + + Voice + + + Vo. + diff --git a/src/importexport/musicxml/tests/data/testMultiInstrumentPart3_ref.xml b/src/importexport/musicxml/tests/data/testMultiInstrumentPart3_ref.xml index b2801c8cbee34..58a0036dbc75e 100644 --- a/src/importexport/musicxml/tests/data/testMultiInstrumentPart3_ref.xml +++ b/src/importexport/musicxml/tests/data/testMultiInstrumentPart3_ref.xml @@ -169,13 +169,11 @@ - Bb Clarinet B flat Clarinet - Bb Cl. B flat