Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GH#17397: Fully export instrument changes to MusicXML #658

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 45 additions & 5 deletions importexport/musicxml/exportxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -3967,7 +3968,7 @@ void ExportMusicXml::chord(Chord* chord, int staff, const std::vector<Lyrics*>*
_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())
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
//---------------------------------------------------------
Expand Down
15 changes: 15 additions & 0 deletions mtest/musicxml/io/testChangeTranspose-no-diatonic_ref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,27 @@
<fifths>2</fifths>
</key>
</attributes>
<print>
<part-name-display>
<display-text>A Clarinet</display-text>
</part-name-display>
<part-abbreviation-display>
<display-text>A Cl.</display-text>
</part-abbreviation-display>
</print>
<attributes>
<transpose>
<diatonic>-1</diatonic>
<chromatic>-2</chromatic>
</transpose>
</attributes>
<sound>
<instrument-change>
<score-instrument id="P1-I2">
<instrument-name>B♭ Clarinet</instrument-name>
</score-instrument>
</instrument-change>
</sound>
<direction placement="above">
<direction-type>
<words font-weight="bold" font-size="12">To B♭ Clarinet</words>
Expand Down
15 changes: 15 additions & 0 deletions mtest/musicxml/io/testChangeTranspose.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,27 @@
<fifths>2</fifths>
</key>
</attributes>
<print>
<part-name-display>
<display-text>A Clarinet</display-text>
</part-name-display>
<part-abbreviation-display>
<display-text>A Cl.</display-text>
</part-abbreviation-display>
</print>
<attributes>
<transpose>
<diatonic>-1</diatonic>
<chromatic>-2</chromatic>
</transpose>
</attributes>
<sound>
<instrument-change>
<score-instrument id="P1-I2">
<instrument-name>B♭ Clarinet</instrument-name>
</score-instrument>
</instrument-change>
</sound>
<direction placement="above">
<direction-type>
<words font-weight="bold" font-size="12">To B♭ Clarinet</words>
Expand Down
15 changes: 15 additions & 0 deletions mtest/musicxml/io/testInstrumentChangeMIDIportExport_ref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,21 @@
</note>
</measure>
<measure number="2">
<print>
<part-name-display>
<display-text>Voice</display-text>
</part-name-display>
<part-abbreviation-display>
<display-text>Vo.</display-text>
</part-abbreviation-display>
</print>
<sound>
<instrument-change>
<score-instrument id="P15-I2">
<instrument-name>Voice</instrument-name>
</score-instrument>
</instrument-change>
</sound>
<direction placement="above">
<direction-type>
<words font-weight="bold">Voice</words>
Expand Down
15 changes: 15 additions & 0 deletions mtest/musicxml/io/testMultiInstrumentPart1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@
</note>
</measure>
<measure number="3">
<print>
<part-name-display>
<display-text>Piano</display-text>
</part-name-display>
<part-abbreviation-display>
<display-text>Pno.</display-text>
</part-abbreviation-display>
</print>
<sound>
<instrument-change>
<score-instrument id="P1-I2">
<instrument-name>Flute</instrument-name>
</score-instrument>
</instrument-change>
</sound>
<direction placement="above">
<direction-type>
<words font-weight="bold" font-size="12">Flute</words>
Expand Down
30 changes: 30 additions & 0 deletions mtest/musicxml/io/testMultiInstrumentPart2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@
</note>
</measure>
<measure number="3">
<print>
<part-name-display>
<display-text>Piano</display-text>
</part-name-display>
<part-abbreviation-display>
<display-text>Pno.</display-text>
</part-abbreviation-display>
</print>
<sound>
<instrument-change>
<score-instrument id="P1-I2">
<instrument-name>Flute</instrument-name>
</score-instrument>
</instrument-change>
</sound>
<direction placement="above">
<direction-type>
<words font-weight="bold" font-size="12">Flute</words>
Expand Down Expand Up @@ -246,6 +261,21 @@
</note>
</measure>
<measure number="7">
<print>
<part-name-display>
<display-text>Voice</display-text>
</part-name-display>
<part-abbreviation-display>
<display-text>Vo.</display-text>
</part-abbreviation-display>
</print>
<sound>
<instrument-change>
<score-instrument id="P2-I2">
<instrument-name>C Trumpet</instrument-name>
</score-instrument>
</instrument-change>
</sound>
<direction placement="above">
<direction-type>
<words font-weight="bold" font-size="12">Trumpet</words>
Expand Down
29 changes: 24 additions & 5 deletions mtest/musicxml/io/testMultiInstrumentPart3_ref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,34 @@
<fifths>-3</fifths>
</key>
</attributes>
<print>
<part-name-display>
<display-text>B</display-text>
<accidental-text>flat</accidental-text>
<display-text> Clarinet</display-text>
</part-name-display>
<part-abbreviation-display>
<display-text>B</display-text>
<accidental-text>flat</accidental-text>
<display-text> Cl.</display-text>
</part-abbreviation-display>
</print>
<attributes>
<transpose>
<diatonic>-1</diatonic>
<chromatic>-2</chromatic>
</transpose>
</attributes>
<sound>
<instrument-change>
<score-instrument id="P1-I2">
<instrument-name>B♭ Clarinet</instrument-name>
</score-instrument>
</instrument-change>
</sound>
<direction placement="above">
<direction-type>
<words font-weight="bold" font-size="12">B♭ Clarinet</words>
<words font-weight="bold">B♭ Clarinet</words>
</direction-type>
</direction>
<note>
Expand Down Expand Up @@ -276,28 +295,28 @@
</measure>
<measure number="5">
<note>
<rest/>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
</measure>
<measure number="6">
<note>
<rest/>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
</measure>
<measure number="7">
<note>
<rest/>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
</measure>
<measure number="8">
<note>
<rest/>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
</note>
Expand Down
1 change: 1 addition & 0 deletions mtest/musicxml/io/tst_mxml_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"); }
Expand Down
Loading