[MusicXML] Export missing instrument-sound tag

• Aug 3, 2022 - 18:54
Reported version
3.6
Type
Functional
Frequency
Few
Severity
S5 - Suggestion
Reproducibility
Always
Status
PR created
Regression
No
Workaround
No
Project

Comments

the fix is really simple and it involves following changes in exportxml.cpp
1. modifying scoreInstrument
1. add the const Instrument* instr in the signature
2. add the xml.tag instrument-sound with the instr→instrumentId() if this is not empty.
2. modifying the places that call scoreInstrument by adding the pointer to the instrument object
2.1 line 5889 scoreInstrument(xml, idx + 1, i + 1, di.name,di);
2.2 line 5891 scoreInstrument(xml, idx + 1, i + 1, QString("Instrument %1").arg(i + 1),di);
2.3 line 5907 scoreInstrument(xml, idx + 1, instNr + 1, MScoreTextToMXML::toPlainText(rim.value(instNr)->trackName()),rim.value(instNr));

That's it. The new exportxml.cpp is attached .
Unfortunately I am having issues with the compilation (Mac OS...) however at least here the work is saved somehow and perhaps could be useful also to others.

By the way, the same fix needs to be applied also to the master branch (4.x) and there of course the line numbers are different but the content the same.

Attachment Size
exportxml.txt 265.22 KB

How about simply this:

diff --git a/src/importexport/musicxml/internal/musicxml/exportxml.cpp b/src/importexport/musicxml/internal/musicxml/exportxml.cpp
index 2525b8fb69..a236bf278c 100644
--- a/src/importexport/musicxml/internal/musicxml/exportxml.cpp
+++ b/src/importexport/musicxml/internal/musicxml/exportxml.cpp
@@ -6017,10 +6017,13 @@ static int findPartGroupNumber(int* partGroupEnd)
 //  scoreInstrument
 //---------------------------------------------------------
 
-static void scoreInstrument(XmlWriter& xml, const int partNr, const int instrNr, const QString& instrName)
+static void scoreInstrument(XmlWriter& xml, const int partNr, const int instrNr, const QString& instrName, const Instrument* instr = nullptr)
 {
     xml.startElementRaw(QString("score-instrument %1").arg(instrId(partNr, instrNr)));
     xml.tag("instrument-name", instrName);
+    if (instr && !instr->instrumentId().isEmpty()) {
+        xml.tag("instrument-sound", instr->instrumentId());
+    }
     xml.endElement();
 }
 
@@ -6525,7 +6528,7 @@ static void partList(XmlWriter& xml, Score* score, MxmlInstrumentMap& instrMap)
             MxmlReverseInstrumentMap rim;
             initReverseInstrMap(rim, instrMap);
             for (int instNr : rim.keys()) {
-                scoreInstrument(xml, static_cast<int>(idx) + 1, instNr + 1, MScoreTextToMXML::toPlainText(rim.value(instNr)->trackName()));
+                scoreInstrument(xml, static_cast<int>(idx) + 1, instNr + 1, MScoreTextToMXML::toPlainText(rim.value(instNr)->trackName()), rim.value(instNr));
             }
             for (auto ii = rim.constBegin(); ii != rim.constEnd(); ii++) {
                 int instNr = ii.key();

DrumSet actually cannot be mapped to Instrument. It has also no sound-instrument information stored and therefore the most appropriate way to handle that case is to simply pass a nullptr.

scoreInstrument(xml, static_cast(idx) + 1, i + 1, di.name, nullptr );
scoreInstrument(xml, static_cast(idx) + 1, i + 1, QString("Instrument %1").arg(i + 1), nullptr);

ok ?
attached the diff.txt

Attachment Size
diff.txt 2.42 KB

Hmm, now also many (MusicXML) regression tests need to get adjusted. A lot of work, but also a good sign, showing that the change really does what it should do