diff --git a/importexport/musicxml/exportxml.cpp b/importexport/musicxml/exportxml.cpp index cf3a88c30535b..c31b8e70ff134 100644 --- a/importexport/musicxml/exportxml.cpp +++ b/importexport/musicxml/exportxml.cpp @@ -393,6 +393,7 @@ class ExportMusicXml { double getTenthsFromInches(double) const; double getTenthsFromDots(double) const; Fraction tick() const { return _tick; } + void writeInstrumentChange(const InstrumentChange* instrChange); void writeInstrumentDetails(const Instrument* instrument, const bool concertPitch); static bool canWrite(const Element* e); }; @@ -1481,9 +1482,9 @@ static void textAsCreditWords(const ExportMusicXml* const expMxml, XmlWriter& xm void ExportMusicXml::credits(XmlWriter& xml) { // find the vboxes in every page and write their elements as credit-words - for (Page* const page : _score->pages()) { + for (Page* const page : qAsConst(_score->pages())) { const int pageIdx = _score->pageIdx(page); - for (const System* system : page->systems()) { + for (const System* system : qAsConst(page->systems())) { for (const MeasureBase* mb : system->measures()) { if (mb->isVBox()) { for (const Element* element : mb->el()) { @@ -1689,7 +1690,7 @@ static void ending(XmlWriter& xml, Volta* v, bool left) { QString number; QString type; - for (int i : v->endings()) { + for (int& i : v->endings()) { if (!number.isEmpty()) number += ", "; number += QString("%1").arg(i); @@ -3967,7 +3968,7 @@ void ExportMusicXml::chord(Chord* chord, int staff, const std::vector* _xml.tag("voice", voice); writeType(_xml, note); - for (NoteDot* dot : note->dots()) { + for (const NoteDot* dot : qAsConst(note->dots())) { QString dotTag = "dot"; if (note->userDotPosition() != Direction::AUTO) { if (note->dotIsUp()) @@ -5818,7 +5819,7 @@ static bool commonAnnotations(ExportMusicXml* exp, const Element* e, int sstaff) // 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; } @@ -7015,6 +7016,45 @@ static void writeStaffDetails(XmlWriter& xml, const Part* part) } } +//--------------------------------------------------------- +// writeInstrumentChange +//--------------------------------------------------------- + +/** + Write the instrument change. + */ + +void ExportMusicXml::writeInstrumentChange(const InstrumentChange* instrChange) + { + const Instrument* instr = instrChange->instrument(); + Part* const part = instrChange->part(); + const int partNr = _score->parts().indexOf(part); + const int instNr = instrMap.value(instr, -1); + QString longName = instr->longNames()[0].name(); + QString shortName = instr->shortNames()[0].name(); + + _xml.stag("print"); + if (!longName.isEmpty()) { + _xml.stag("part-name-display"); + writeDisplayName(_xml, longName); + _xml.etag(); + } + if (!shortName.isEmpty()) { + _xml.stag("part-abbreviation-display"); + writeDisplayName(_xml, shortName); + _xml.etag(); + } + _xml.etag(); + + writeInstrumentDetails(instr, _score->styleB(Sid::concertPitch)); + + _xml.stag("sound"); + _xml.stag("instrument-change"); + scoreInstrument(_xml, partNr + 1, instNr + 1, instr->trackName(), instr); + _xml.etag(); + _xml.etag(); + } + //--------------------------------------------------------- // writeInstrumentDetails //--------------------------------------------------------- diff --git a/mtest/musicxml/io/testChangeTranspose-no-diatonic_ref.xml b/mtest/musicxml/io/testChangeTranspose-no-diatonic_ref.xml index 1258193551636..3a1951910a203 100644 --- a/mtest/musicxml/io/testChangeTranspose-no-diatonic_ref.xml +++ b/mtest/musicxml/io/testChangeTranspose-no-diatonic_ref.xml @@ -100,12 +100,27 @@ 2 + + + A Clarinet + + + A Cl. + + -1 -2 + + + + B♭ Clarinet + + + To B♭ Clarinet diff --git a/mtest/musicxml/io/testChangeTranspose.xml b/mtest/musicxml/io/testChangeTranspose.xml index b690658f66625..d4c72d1a3e1c9 100644 --- a/mtest/musicxml/io/testChangeTranspose.xml +++ b/mtest/musicxml/io/testChangeTranspose.xml @@ -100,12 +100,27 @@ 2 + + + A Clarinet + + + A Cl. + + -1 -2 + + + + B♭ Clarinet + + + To B♭ Clarinet diff --git a/mtest/musicxml/io/testInstrumentChangeMIDIportExport_ref.xml b/mtest/musicxml/io/testInstrumentChangeMIDIportExport_ref.xml index 8dc1ca54af764..12cf35189e903 100644 --- a/mtest/musicxml/io/testInstrumentChangeMIDIportExport_ref.xml +++ b/mtest/musicxml/io/testInstrumentChangeMIDIportExport_ref.xml @@ -1060,6 +1060,21 @@ + + + Voice + + + Vo. + + + + + + Voice + + + Voice diff --git a/mtest/musicxml/io/testMultiInstrumentPart1.xml b/mtest/musicxml/io/testMultiInstrumentPart1.xml index fddb90c401dae..78bd5afd99eb8 100644 --- a/mtest/musicxml/io/testMultiInstrumentPart1.xml +++ b/mtest/musicxml/io/testMultiInstrumentPart1.xml @@ -83,6 +83,21 @@ + + + Piano + + + Pno. + + + + + + Flute + + + Flute diff --git a/mtest/musicxml/io/testMultiInstrumentPart2.xml b/mtest/musicxml/io/testMultiInstrumentPart2.xml index 3118a5e2d7076..3138a4b4e4c97 100644 --- a/mtest/musicxml/io/testMultiInstrumentPart2.xml +++ b/mtest/musicxml/io/testMultiInstrumentPart2.xml @@ -107,6 +107,21 @@ + + + Piano + + + Pno. + + + + + + Flute + + + Flute @@ -246,6 +261,21 @@ + + + Voice + + + Vo. + + + + + + C Trumpet + + + Trumpet diff --git a/mtest/musicxml/io/testMultiInstrumentPart3_ref.xml b/mtest/musicxml/io/testMultiInstrumentPart3_ref.xml index 5b3a02ce54ba2..466b46cb8edef 100644 --- a/mtest/musicxml/io/testMultiInstrumentPart3_ref.xml +++ b/mtest/musicxml/io/testMultiInstrumentPart3_ref.xml @@ -168,15 +168,34 @@ -3 + + + B + flat + Clarinet + + + B + flat + Cl. + + -1 -2 + + + + B♭ Clarinet + + + - B♭ Clarinet + B♭ Clarinet @@ -276,28 +295,28 @@ - + 4 1 - + 4 1 - + 4 1 - + 4 1 diff --git a/mtest/musicxml/io/tst_mxml_io.cpp b/mtest/musicxml/io/tst_mxml_io.cpp index 714e6d5229a5f..3768e594d3e20 100644 --- a/mtest/musicxml/io/tst_mxml_io.cpp +++ b/mtest/musicxml/io/tst_mxml_io.cpp @@ -224,6 +224,7 @@ private slots: void midiPortExport() { mxmlMscxExportTestRef("testMidiPortExport"); } void multiInstrumentPart1() { mxmlIoTest("testMultiInstrumentPart1"); } void multiInstrumentPart2() { mxmlIoTest("testMultiInstrumentPart2"); } + void multiInstrumentPart3() { mxmlMscxExportTestRef("testMultiInstrumentPart3"); } void multiMeasureRest1() { mxmlIoTestRef("testMultiMeasureRest1"); } void multiMeasureRest2() { mxmlIoTestRef("testMultiMeasureRest2"); } void multiMeasureRest3() { mxmlIoTestRef("testMultiMeasureRest3"); }