Skip to content

Commit 7efbe85

Browse files
authored
Merge pull request #5589 from lvinken/294815-musicxml-export-transpose-multi-instrument
fix MusicXML export part of #294815 - [Musicxml im-export] - New Tran…
2 parents c29b06b + 93a9443 commit 7efbe85

File tree

9 files changed

+711
-25
lines changed

9 files changed

+711
-25
lines changed

mscore/exportxml.cpp

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
#include "libmscore/fermata.h"
101101
#include "musicxmlfonthandler.h"
102102
#include "libmscore/textframe.h"
103+
#include "libmscore/instrchange.h"
103104

104105
namespace Ms {
105106

@@ -336,6 +337,7 @@ class ExportMusicXml {
336337
double getTenthsFromInches(double) const;
337338
double getTenthsFromDots(double) const;
338339
Fraction tick() const { return _tick; }
340+
void writeInstrumentDetails(const Instrument* instrument);
339341
};
340342

341343
//---------------------------------------------------------
@@ -1303,10 +1305,10 @@ static void tabpitch2xml(const int pitch, const int tpc, QString& s, int& alter,
13031305

13041306
static void pitch2xml(const Note* note, QString& s, int& alter, int& octave)
13051307
{
1306-
1307-
const Staff* st = note->staff();
1308-
const Instrument* instr = st->part()->instrument(); // TODO: tick
1309-
const Interval intval = instr->transpose();
1308+
const auto st = note->staff();
1309+
const auto tick = note->tick();
1310+
const auto instr = st->part()->instrument(tick);
1311+
const auto intval = instr->transpose();
13101312

13111313
s = tpc2stepName(note->tpc());
13121314
alter = tpc2alterByKey(note->tpc(), Key::C);
@@ -1320,7 +1322,6 @@ static void pitch2xml(const Note* note, QString& s, int& alter, int& octave)
13201322
// note->pitch() and note->line()
13211323
// note->line() is determined by drumMap
13221324
//
1323-
Fraction tick = note->chord()->tick();
13241325
ClefType ct = st->clef(tick);
13251326
if (ct == ClefType::PERC || ct == ClefType::PERC2) {
13261327
alter = 0;
@@ -4401,6 +4402,16 @@ static const FretDiagram* findFretDiagram(int strack, int etrack, int track, Seg
44014402

44024403
static bool commonAnnotations(ExportMusicXml* exp, const Element* e, int sstaff)
44034404
{
4405+
bool instrChangeHandled = false;
4406+
4407+
// note: write the changed instrument details (transposition) here,
4408+
// optionally writing the associated staff text is done below
4409+
if (e->isInstrumentChange()) {
4410+
const auto instrChange = toInstrumentChange(e);
4411+
exp->writeInstrumentDetails(instrChange->instrument());
4412+
instrChangeHandled = true;
4413+
}
4414+
44044415
if (e->isSymbol())
44054416
exp->symbol(toSymbol(e), sstaff);
44064417
else if (e->isTempoText())
@@ -4412,7 +4423,7 @@ static bool commonAnnotations(ExportMusicXml* exp, const Element* e, int sstaff)
44124423
else if (e->isRehearsalMark())
44134424
exp->rehearsal(toRehearsalMark(e), sstaff);
44144425
else
4415-
return false;
4426+
return instrChangeHandled;
44164427

44174428
return true;
44184429
}
@@ -4454,13 +4465,13 @@ static void annotations(ExportMusicXml* exp, int strack, int etrack, int track,
44544465
else if (e->isFermata() || e->isFiguredBass() || e->isFretDiagram() || e->isJump())
44554466
; // handled separately by chordAttributes(), figuredBass(), findFretDiagram() or ignored
44564467
else
4457-
qDebug("annotations: direction type %s at tick %d not implemented",
4468+
qDebug("direction type %s at tick %d not implemented",
44584469
Element::name(e->type()), seg->tick().ticks());
44594470
}
44604471
}
44614472
if (fd)
44624473
// found fd but no harmony, cannot write (MusicXML would be invalid)
4463-
qDebug("annotations seg %p found fretboard diagram %p w/o harmony: cannot write",
4474+
qDebug("seg %p found fretboard diagram %p w/o harmony: cannot write",
44644475
seg, fd);
44654476
}
44664477
}
@@ -5431,22 +5442,21 @@ static void writeStaffDetails(XmlWriter& xml, const Part* part)
54315442
//---------------------------------------------------------
54325443

54335444
/**
5434-
Write the instrument details for \a part to \a xml.
5445+
Write the instrument details for \a instrument.
54355446
*/
54365447

5437-
static void writeInstrumentDetails(XmlWriter& xml, const Part* part)
5448+
void ExportMusicXml::writeInstrumentDetails(const Instrument* instrument)
54385449
{
5439-
const Instrument* instrument = part->instrument();
5440-
5441-
// instrument details
5442-
if (instrument->transpose().chromatic) { // TODO: tick
5443-
xml.stag("transpose");
5444-
xml.tag("diatonic", instrument->transpose().diatonic % 7);
5445-
xml.tag("chromatic", instrument->transpose().chromatic % 12);
5450+
if (instrument->transpose().chromatic) {
5451+
_attr.doAttr(_xml, true);
5452+
_xml.stag("transpose");
5453+
_xml.tag("diatonic", instrument->transpose().diatonic % 7);
5454+
_xml.tag("chromatic", instrument->transpose().chromatic % 12);
54465455
int octaveChange = instrument->transpose().chromatic / 12;
54475456
if (octaveChange != 0)
5448-
xml.tag("octave-change", octaveChange);
5449-
xml.etag();
5457+
_xml.tag("octave-change", octaveChange);
5458+
_xml.etag();
5459+
_attr.doAttr(_xml, false);
54505460
}
54515461
}
54525462

@@ -5662,7 +5672,7 @@ void ExportMusicXml::write(QIODevice* dev)
56625672
// output attributes with the first actual measure (pickup or regular) only
56635673
if (isFirstActualMeasure) {
56645674
writeStaffDetails(_xml, part);
5665-
writeInstrumentDetails(_xml, part);
5675+
writeInstrumentDetails(part->instrument());
56665676
}
56675677

56685678
// output attribute at start of measure: measure-style

mtest/musicxml/io/iotest

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
# OS X terminal build
99
#MSCORE=../../../applebuild/mscore.app/Contents/MacOS/mscore
1010
# OS X Xcode build
11-
MSCORE=../../../build.xcode/mscore/Debug/mscore.app/Contents/MacOS/mscore
11+
#MSCORE=../../../build.xcode/mscore/Debug/mscore.app/Contents/MacOS/mscore
12+
# OS X Xcode build (since early 2020)
13+
MSCORE=../../../build.xcode/main/Debug/mscore.app/Contents/MacOS/mscore
1214

1315
echo "----------------------------------------------"
1416
echo "Regression Tests for MuseScore MusicXML import"

mtest/musicxml/io/iotest.mscxformat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#MSCORE=../../../applebuild/mscore.app/Contents/MacOS/mscore
1111
# OS X Xcode build
1212
OLD_MSCORE=../../../oldbuilds/mscore-20150301.app/Contents/MacOS/mscore
13-
NEW_MSCORE=../../../build.xcode/mscore/Debug/mscore.app/Contents/MacOS/mscore
13+
#NEW_MSCORE=../../../build.xcode/mscore/Debug/mscore.app/Contents/MacOS/mscore
14+
# OS X Xcode build (since early 2020)
15+
NEW_MSCORE=../../../build.xcode/main/Debug/mscore.app/Contents/MacOS/mscore
1416

1517
echo "----------------------------------------------"
1618
echo "Regression Tests for MuseScore MusicXML import"

mtest/musicxml/io/iotest.mxmlformat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#MSCORE=../../../applebuild/mscore.app/Contents/MacOS/mscore
1111
# OS X Xcode build
1212
OLD_MSCORE=../../../oldbuilds/mscore-20150301.app/Contents/MacOS/mscore
13-
NEW_MSCORE=../../../build.xcode/mscore/Debug/mscore.app/Contents/MacOS/mscore
13+
#NEW_MSCORE=../../../build.xcode/mscore/Debug/mscore.app/Contents/MacOS/mscore
14+
# OS X Xcode build (since early 2020)
15+
NEW_MSCORE=../../../build.xcode/main/Debug/mscore.app/Contents/MacOS/mscore
1416

1517
echo "----------------------------------------------"
1618
echo "Regression Tests for MuseScore MusicXML import"

mtest/musicxml/io/iotest.short

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
# OS X terminal build
99
#MSCORE=../../../applebuild/mscore.app/Contents/MacOS/mscore
1010
# OS X Xcode build
11-
MSCORE=../../../build.xcode/mscore/Debug/mscore.app/Contents/MacOS/mscore
11+
#MSCORE=../../../build.xcode/mscore/Debug/mscore.app/Contents/MacOS/mscore
12+
# OS X Xcode build (since early 2020)
13+
MSCORE=../../../build.xcode/main/Debug/mscore.app/Contents/MacOS/mscore
1214

1315
echo "----------------------------------------------"
1416
echo "Regression Tests for MuseScore MusicXML import"

mtest/musicxml/io/iotest.single

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
# OS X terminal build
99
#MSCORE=../../../applebuild/mscore.app/Contents/MacOS/mscore
1010
# OS X Xcode build
11-
MSCORE=../../../build.xcode/mscore/Debug/mscore.app/Contents/MacOS/mscore
11+
#MSCORE=../../../build.xcode/mscore/Debug/mscore.app/Contents/MacOS/mscore
12+
# OS X Xcode build (since early 2020)
13+
MSCORE=../../../build.xcode/main/Debug/mscore.app/Contents/MacOS/mscore
1214

1315
echo "----------------------------------------------"
1416
echo "Regression Tests for MuseScore MusicXML import"

0 commit comments

Comments
 (0)