Skip to content

Commit

Permalink
fix #20855: [MusicXML] Export of chordnames not over a ChordRest does…
Browse files Browse the repository at this point in the history
…n't work
  • Loading branch information
lasconic committed Aug 9, 2013
1 parent 40b43f3 commit 3aebe10
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 34 deletions.
8 changes: 5 additions & 3 deletions libmscore/harmony.cpp
Expand Up @@ -959,9 +959,11 @@ void TextSegment::set(const QString& s, const QFont& f, qreal _x, qreal _y)
void Harmony::render(const QString& s, qreal& x, qreal& y)
{
int fontIdx = 0;
TextSegment* ts = new TextSegment(s, fontList[fontIdx], x, y);
textList.append(ts);
x += ts->width();
if(!s.isEmpty()) {
TextSegment* ts = new TextSegment(s, fontList[fontIdx], x, y);
textList.append(ts);
x += ts->width();
}
}

//---------------------------------------------------------
Expand Down
45 changes: 18 additions & 27 deletions mscore/exportxml.cpp
Expand Up @@ -301,7 +301,7 @@ class ExportMusicXml {
void dynamic(Dynamic const* const dyn, int staff);
void symbol(Symbol const* const sym, int staff);
void tempoText(TempoText const* const text, int staff);
void harmony(Harmony const* const, FretDiagram const* const fd);
void harmony(Harmony const* const, FretDiagram const* const fd, int offset = 0);
Score* score() { return _score; }
};

Expand Down Expand Up @@ -4268,37 +4268,15 @@ void ExportMusicXml::write(QIODevice* dev)

int sstaff = (staves > 1) ? st - strack + VOICES : 0;
sstaff /= VOICES;

for (Segment* seg = m->first(); seg; seg = seg->next()) {
Element* el = seg->element(st);
if (!el)
if (!el) {
continue;
}
// must ignore start repeat to prevent spurious backup/forward
if (el->type() == Element::BAR_LINE && static_cast<BarLine*>(el)->barLineType() == START_REPEAT)
continue;

// look for harmony element for this tick position
if (el->isChordRest()) {
QList<Element*> list;

#if 0 // TODO-WS
foreach(Element* he, *m->el()) {
if ((he->type() == Element::HARMONY) && (he->staffIdx() == sstaff)
&& (he->tick() == el->tick())) {
list << he;
}
}
#endif

qSort(list.begin(), list.end(), elementRighter);

foreach (Element* hhe, list) {
attr.doAttr(xml, false);
qDebug("writing harmony");
harmony((Harmony*)hhe, 0);
}
}

// generate backup or forward to the start time of the element
// but not for breath, which has the same start time as the
// previous note, while tick is already at the end of that note
Expand All @@ -4312,6 +4290,18 @@ void ExportMusicXml::write(QIODevice* dev)
if (el->isChordRest()) {
attr.doAttr(xml, false);
annotations(this, xml, strack, etrack, st, sstaff, seg);
// look for more harmony
for (Segment* seg1 = seg->next(); seg1; seg1 = seg1->next()) {
if(seg1->isChordRest()) {
Element* el1 = seg1->element(st);
if (el1) // found a ChordRest, next harmony will be attach to this one
break;
foreach (Element* annot, seg1->annotations()) {
if(annot->type() == Element::HARMONY && annot->track() == st)
harmony(static_cast<Harmony*>(annot), 0, (seg1->tick() - seg->tick()) / div);
}
}
}
figuredBass(xml, strack, etrack, st, static_cast<const ChordRest*>(el), fbMap);
spannerStop(this, strack, etrack, st, sstaff, seg);
spannerStart(this, strack, etrack, st, sstaff, seg);
Expand Down Expand Up @@ -4501,7 +4491,7 @@ double ExportMusicXml::getTenthsFromDots(double dots)
// harmony
//---------------------------------------------------------

void ExportMusicXml::harmony(Harmony const* const h, FretDiagram const* const fd)
void ExportMusicXml::harmony(Harmony const* const h, FretDiagram const* const fd, int offset)
{
double rx = h->userOff().x()*10;
QString relative;
Expand Down Expand Up @@ -4573,7 +4563,8 @@ void ExportMusicXml::harmony(Harmony const* const h, FretDiagram const* const fd
}
xml.etag();
}

if(offset > 0)
xml.tag("offset", offset);
if (fd)
fd->writeMusicXML(xml);

Expand Down
7 changes: 3 additions & 4 deletions mscore/importxml.cpp
Expand Up @@ -5039,6 +5039,7 @@ void MusicXml::xmlHarmony(QDomElement e, int tick, Measure* measure, int staff)

Harmony* ha = new Harmony(score);
ha->setUserOff(QPointF(rx, ry + dy - styleYOff));
int offset = 0;
for (e = e.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) {
QString tag(e.tagName());
if (tag == "root") {
Expand Down Expand Up @@ -5151,13 +5152,11 @@ void MusicXml::xmlHarmony(QDomElement e, int tick, Measure* measure, int staff)
else if (tag == "level")
domNotImplemented(e);
else if (tag == "offset")
domNotImplemented(e);
offset = calcTicks(e.text(), divisions);
else
domError(e);
}

//TODO-WS ha->setTick(tick);

const ChordDescription* d = 0;
if (ha->rootTpc() != INVALID_TPC)
d = ha->fromXml(kind, kindText, symbols, parens, degreeList);
Expand All @@ -5176,7 +5175,7 @@ void MusicXml::xmlHarmony(QDomElement e, int tick, Measure* measure, int staff)
// TODO-LV: do this only if ha points to a valid harmony
// harmony = ha;
ha->setTrack(staff * VOICES);
Segment* s = measure->getSegment(Segment::SegChordRest, tick);
Segment* s = measure->getSegment(Segment::SegChordRest, tick + offset);
s->add(ha);
}

Expand Down
64 changes: 64 additions & 0 deletions mtest/musicxml/io/testHarmony5.xml
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise>
<identification>
<encoding>
<software>MuseScore 0.7.0</software>
<encoding-date>2007-09-10</encoding-date>
</encoding>
</identification>
<part-list>
<score-part id="P1">
<part-name></part-name>
<score-instrument id="P1-I3">
<instrument-name></instrument-name>
</score-instrument>
<midi-instrument id="P1-I3">
<midi-channel>1</midi-channel>
<midi-program>74</midi-program>
<volume>78.7402</volume>
<pan>0</pan>
</midi-instrument>
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<fifths>0</fifths>
<mode>major</mode>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<harmony print-frame="no">
<root>
<root-step>C</root-step>
</root>
<kind text="m7">minor-seventh</kind>
</harmony>
<harmony print-frame="no">
<root>
<root-step>C</root-step>
</root>
<kind text="m7">minor-seventh</kind>
<offset>2</offset>
</harmony>
<note>
<rest/>
<duration>4</duration>
<voice>1</voice>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>
2 changes: 2 additions & 0 deletions mtest/musicxml/io/tst_mxml_io.cpp
Expand Up @@ -79,7 +79,9 @@ private slots:
// void grace2() { mxmlIoTest("testGrace2"); }
void harmony1() { mxmlIoTest("testHarmony1"); }
void harmony2() { mxmlIoTest("testHarmony2"); }
// void harmony3() { mxmlIoTest("testHarmony3"); }
void harmony4() { mxmlIoTest("testHarmony4"); }
void harmony5() { mxmlIoTest("testHarmony5"); } // chordnames without chordrest
void hello() { mxmlIoTest("testHello"); }
void helloReadCompr() { mxmlReadTestCompr("testHello"); }
void helloReadWriteCompr() { mxmlReadWriteTestCompr("testHello"); }
Expand Down

0 comments on commit 3aebe10

Please sign in to comment.