#16057: basic MusicXML export of chord diagrams

This commit is contained in:
Leon Vinken 2013-01-03 19:55:45 +01:00
parent a33d0a4647
commit fb3f18bcd5
6 changed files with 363 additions and 7 deletions

View file

@ -564,6 +564,34 @@ void FretDiagram::readMusicXML(XmlReader& e)
// Write MusicXML
//---------------------------------------------------------
void FretDiagram::writeMusicXML(Xml& /*xml*/) const
void FretDiagram::writeMusicXML(Xml& xml) const
{
qDebug("FretDiagram::writeMusicXML() this %p harmony %p", this, _harmony);
xml.stag("frame");
xml.tag("frame-strings", strings());
xml.tag("frame-frets", frets());
QString strDots = "'";
QString strMarker = "'";
QString strFingering = "'";
for (int i = 0; i < strings(); ++i) {
// TODO print frame note
if (_dots) strDots += QString("%1'").arg(static_cast<int>(_dots[i]));
if (_marker) strMarker += QString("%1'").arg(static_cast<int>(_marker[i]));
if (_fingering) strFingering += QString("%1'").arg(static_cast<int>(_fingering[i]));
if (_marker[i] != 88) {
xml.stag("frame-note");
xml.tag("string", strings() - i);
xml.tag("fret", _dots[i]);
xml.etag();
}
}
qDebug("FretDiagram::writeMusicXML() this %p dots %s marker %s fingering %s",
this, qPrintable(strDots), qPrintable(strMarker), qPrintable(strFingering));
/*
xml.tag("root-step", tpc2stepName(rootTpc));
int alter = tpc2alter(rootTpc);
if (alter)
xml.tag("root-alter", alter);
*/
xml.etag();
}

View file

@ -3460,11 +3460,12 @@ static const FretDiagram* findFretDiagram(int strack, int etrack, int track, Seg
// in MusicXML they are combined in the harmony element. This means they have to be matched.
// TODO: replace/repair current algorithm (which can only handle one FRET_DIAGRAM and one HARMONY)
static void annotations(ExportMusicXml* exp, int strack, int etrack, int track, int sstaff, Segment* seg)
static void annotations(ExportMusicXml* exp, Xml& xml, int strack, int etrack, int track, int sstaff, Segment* seg)
{
if (seg->subtype() == Segment::SegChordRest) {
const FretDiagram* fd = findFretDiagram(strack, etrack, track, seg);
// if (fd) qDebug("annotations seg %p found fret diagram %p", seg, fd);
foreach(const Element* e, seg->annotations()) {
@ -3489,7 +3490,7 @@ static void annotations(ExportMusicXml* exp, int strack, int etrack, int track,
exp->dynamic(static_cast<const Dynamic*>(e), sstaff);
break;
case Element::HARMONY:
qDebug("annotations found harmony");
// qDebug("annotations seg %p found harmony %p", seg, e);
exp->harmony(static_cast<const Harmony*>(e), fd /*, sstaff */);
fd = 0; // make sure to write only once ...
break;
@ -3507,9 +3508,10 @@ static void annotations(ExportMusicXml* exp, int strack, int etrack, int track,
}
}
} // foreach
if (fd) {
// TODO: found fd but no Element::HARMONY -> write separately
}
if (fd)
// found fd but no harmony, cannot write (MusicXML would be invalid)
qDebug("annotations seg %p found fret diagram %p w/o harmony: cannot write",
seg, fd);
}
}
@ -4192,7 +4194,7 @@ void ExportMusicXml::write(QIODevice* dev)
// handle annotations and spanners (directions attached to this note or rest)
if (el->isChordRest()) {
attr.doAttr(xml, false);
annotations(this, strack, etrack, st, sstaff, seg);
annotations(this, xml, strack, etrack, st, sstaff, seg);
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);
@ -4446,6 +4448,10 @@ void ExportMusicXml::harmony(Harmony const* const h, FretDiagram const* const fd
}
xml.etag();
}
if (fd)
fd->writeMusicXML(xml);
xml.etag();
}
else {

View file

@ -0,0 +1,160 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 2.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise>
<work>
<work-number>MuseScore testfile</work-number>
<work-title>Chord diagrams 1</work-title>
</work>
<identification>
<creator type="composer">Leon Vinken</creator>
<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>53</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>G</root-step>
</root>
<kind text="">major</kind>
</harmony>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
<lyric number="1">
<syllabic>single</syllabic>
<text>Chord</text>
</lyric>
</note>
</measure>
<measure number="2">
<harmony print-frame="no">
<root>
<root-step>C</root-step>
</root>
<kind text="">major</kind>
<frame>
<frame-strings>6</frame-strings>
<frame-frets>5</frame-frets>
<frame-note>
<string>5</string>
<fret>3</fret>
</frame-note>
<frame-note>
<string>4</string>
<fret>2</fret>
</frame-note>
<frame-note>
<string>3</string>
<fret>0</fret>
</frame-note>
<frame-note>
<string>2</string>
<fret>1</fret>
</frame-note>
<frame-note>
<string>1</string>
<fret>0</fret>
</frame-note>
</frame>
</harmony>
<note>
<pitch>
<step>C</step>
<octave>5</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
<lyric number="1">
<syllabic>single</syllabic>
<text>Chord plus frame</text>
</lyric>
</note>
</measure>
<measure number="3">
<harmony print-frame="no">
<root>
<root-step>B</root-step>
</root>
<kind text="m">minor</kind>
<frame>
<frame-strings>6</frame-strings>
<frame-frets>5</frame-frets>
<frame-note>
<string>5</string>
<fret>2</fret>
</frame-note>
<frame-note>
<string>4</string>
<fret>4</fret>
</frame-note>
<frame-note>
<string>3</string>
<fret>4</fret>
</frame-note>
<frame-note>
<string>2</string>
<fret>3</fret>
</frame-note>
<frame-note>
<string>1</string>
<fret>2</fret>
</frame-note>
</frame>
</harmony>
<note>
<pitch>
<step>B</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
<lyric number="1">
<syllabic>single</syllabic>
<text>Chord plus frame</text>
</lyric>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>

View file

@ -51,6 +51,7 @@ private slots:
void arpGliss1() { mxmlIoTest("testArpGliss1"); }
void arpGliss2() { mxmlIoTest("testArpGliss2"); }
void barStyles() { mxmlIoTest("testBarStyles"); }
void chordDiagrams1() { mxmlIoTest("testChordDiagrams1"); }
void clefs1() { mxmlIoTest("testClefs1"); }
void completeMeasureRests() { mxmlIoTest("testCompleteMeasureRests"); }
void dalSegno() { mxmlIoTest("testDalSegno"); }

View file

@ -0,0 +1,160 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 2.0 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise>
<work>
<work-number>MuseScore testfile</work-number>
<work-title>Chord diagrams 1</work-title>
</work>
<identification>
<creator type="composer">Leon Vinken</creator>
<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>53</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>G</root-step>
</root>
<kind text="">major</kind>
</harmony>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
<lyric number="1">
<syllabic>single</syllabic>
<text>Chord</text>
</lyric>
</note>
</measure>
<measure number="2">
<harmony print-frame="no">
<root>
<root-step>C</root-step>
</root>
<kind text="">major</kind>
<frame>
<frame-strings>6</frame-strings>
<frame-frets>5</frame-frets>
<frame-note>
<string>5</string>
<fret>3</fret>
</frame-note>
<frame-note>
<string>4</string>
<fret>2</fret>
</frame-note>
<frame-note>
<string>3</string>
<fret>0</fret>
</frame-note>
<frame-note>
<string>2</string>
<fret>1</fret>
</frame-note>
<frame-note>
<string>1</string>
<fret>0</fret>
</frame-note>
</frame>
</harmony>
<note>
<pitch>
<step>C</step>
<octave>5</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
<lyric number="1">
<syllabic>single</syllabic>
<text>Chord plus frame</text>
</lyric>
</note>
</measure>
<measure number="3">
<harmony print-frame="no">
<root>
<root-step>B</root-step>
</root>
<kind text="m">minor</kind>
<frame>
<frame-strings>6</frame-strings>
<frame-frets>5</frame-frets>
<frame-note>
<string>5</string>
<fret>2</fret>
</frame-note>
<frame-note>
<string>4</string>
<fret>4</fret>
</frame-note>
<frame-note>
<string>3</string>
<fret>4</fret>
</frame-note>
<frame-note>
<string>2</string>
<fret>3</fret>
</frame-note>
<frame-note>
<string>1</string>
<fret>2</fret>
</frame-note>
</frame>
</harmony>
<note>
<pitch>
<step>B</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
<lyric number="1">
<syllabic>single</syllabic>
<text>Chord plus frame</text>
</lyric>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>

View file

@ -3,6 +3,7 @@ testAccidentals2.xml
testArpGliss1.xml
testArpGliss2.xml
testBarStyles.xml
testChordDiagrams1.xml
testClefs1.xml
testCompleteMeasureRests.xml
testDalSegno.xml