100
100
#include " libmscore/fermata.h"
101
101
#include " musicxmlfonthandler.h"
102
102
#include " libmscore/textframe.h"
103
+ #include " libmscore/instrchange.h"
103
104
104
105
namespace Ms {
105
106
@@ -336,6 +337,7 @@ class ExportMusicXml {
336
337
double getTenthsFromInches (double ) const ;
337
338
double getTenthsFromDots (double ) const ;
338
339
Fraction tick () const { return _tick; }
340
+ void writeInstrumentDetails (const Instrument* instrument);
339
341
};
340
342
341
343
// ---------------------------------------------------------
@@ -1303,10 +1305,10 @@ static void tabpitch2xml(const int pitch, const int tpc, QString& s, int& alter,
1303
1305
1304
1306
static void pitch2xml (const Note* note, QString& s, int & alter, int & octave)
1305
1307
{
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 ();
1310
1312
1311
1313
s = tpc2stepName (note->tpc ());
1312
1314
alter = tpc2alterByKey (note->tpc (), Key::C);
@@ -1320,7 +1322,6 @@ static void pitch2xml(const Note* note, QString& s, int& alter, int& octave)
1320
1322
// note->pitch() and note->line()
1321
1323
// note->line() is determined by drumMap
1322
1324
//
1323
- Fraction tick = note->chord ()->tick ();
1324
1325
ClefType ct = st->clef (tick);
1325
1326
if (ct == ClefType::PERC || ct == ClefType::PERC2) {
1326
1327
alter = 0 ;
@@ -4401,6 +4402,16 @@ static const FretDiagram* findFretDiagram(int strack, int etrack, int track, Seg
4401
4402
4402
4403
static bool commonAnnotations (ExportMusicXml* exp, const Element* e, int sstaff)
4403
4404
{
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
+
4404
4415
if (e->isSymbol ())
4405
4416
exp->symbol (toSymbol (e), sstaff);
4406
4417
else if (e->isTempoText ())
@@ -4412,7 +4423,7 @@ static bool commonAnnotations(ExportMusicXml* exp, const Element* e, int sstaff)
4412
4423
else if (e->isRehearsalMark ())
4413
4424
exp->rehearsal (toRehearsalMark (e), sstaff);
4414
4425
else
4415
- return false ;
4426
+ return instrChangeHandled ;
4416
4427
4417
4428
return true ;
4418
4429
}
@@ -4454,13 +4465,13 @@ static void annotations(ExportMusicXml* exp, int strack, int etrack, int track,
4454
4465
else if (e->isFermata () || e->isFiguredBass () || e->isFretDiagram () || e->isJump ())
4455
4466
; // handled separately by chordAttributes(), figuredBass(), findFretDiagram() or ignored
4456
4467
else
4457
- qDebug (" annotations: direction type %s at tick %d not implemented" ,
4468
+ qDebug (" direction type %s at tick %d not implemented" ,
4458
4469
Element::name (e->type ()), seg->tick ().ticks ());
4459
4470
}
4460
4471
}
4461
4472
if (fd)
4462
4473
// 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" ,
4464
4475
seg, fd);
4465
4476
}
4466
4477
}
@@ -5431,22 +5442,21 @@ static void writeStaffDetails(XmlWriter& xml, const Part* part)
5431
5442
// ---------------------------------------------------------
5432
5443
5433
5444
/* *
5434
- Write the instrument details for \a part to \a xml .
5445
+ Write the instrument details for \a instrument .
5435
5446
*/
5436
5447
5437
- static void writeInstrumentDetails (XmlWriter& xml, const Part* part )
5448
+ void ExportMusicXml:: writeInstrumentDetails (const Instrument* instrument )
5438
5449
{
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 );
5446
5455
int octaveChange = instrument->transpose ().chromatic / 12 ;
5447
5456
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 );
5450
5460
}
5451
5461
}
5452
5462
@@ -5662,7 +5672,7 @@ void ExportMusicXml::write(QIODevice* dev)
5662
5672
// output attributes with the first actual measure (pickup or regular) only
5663
5673
if (isFirstActualMeasure) {
5664
5674
writeStaffDetails (_xml, part);
5665
- writeInstrumentDetails (_xml, part);
5675
+ writeInstrumentDetails (part-> instrument () );
5666
5676
}
5667
5677
5668
5678
// output attribute at start of measure: measure-style
0 commit comments