More MusicXML formatting support for lyrics, rehearsal marks and words

This commit is contained in:
Leon Vinken 2014-11-08 21:39:42 +01:00
parent 00ff6c44e6
commit 3b1ee0012e
4 changed files with 295 additions and 13 deletions

View file

@ -2926,7 +2926,13 @@ static void wordsMetrome(Xml& xml, Score* s, Text const* const text)
}
else {
xml.stag("direction-type");
QString attr; // TODO TBD
QString attr;
if (text->textStyle().hasFrame()) {
if (text->textStyle().circle())
attr = " enclosure=\"circle\"";
else
attr = " enclosure=\"rectangle\"";
}
MScoreTextToMXML mttm("words", attr, text->text(), s->textStyle(TextStyleType::STAFF), s->textStyle(TextStyleType::STAFF));
mttm.write(xml);
xml.etag();

View file

@ -2812,7 +2812,7 @@ void MusicXml::direction(Measure* measure, int staff, QDomElement e)
QString type;
QString niente = "no";
QString txt;
QString wordstext;
QString formattedText;
// int offset = 0; // not supported yet
//int track = 0;
int track = staff * VOICES;
@ -2825,7 +2825,6 @@ void MusicXml::direction(Measure* measure, int staff, QDomElement e)
bool hasYoffset = false;
QString dynaVelocity = "";
QString tempo = "";
QString rehearsal = "";
QString sndCapo = "";
QString sndCoda = "";
QString sndDacapo = "";
@ -2842,6 +2841,7 @@ void MusicXml::direction(Measure* measure, int staff, QDomElement e)
// qreal endLength;
QString lineType;
QDomElement metrEl;
QString enclosure = "none";
for (e = e.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) {
if (e.tagName() == "direction-type") {
@ -2855,11 +2855,13 @@ void MusicXml::direction(Measure* measure, int staff, QDomElement e)
// xoffset = ee.attribute("default-x", "0.0").toDouble() * 0.1;
}
if (dirType == "words") {
enclosure = ee.attribute(QString("enclosure"), "none");
txt = ee.text(); // support legacy code
wordstext += nextPartOfFormattedString(ee);
formattedText += nextPartOfFormattedString(ee);
}
else if (dirType == "rehearsal") {
rehearsal = ee.text();
enclosure = ee.attribute(QString("enclosure"), "square");
formattedText += nextPartOfFormattedString(ee);
}
else if (dirType == "pedal") {
type = ee.attribute(QString("type"));
@ -3012,8 +3014,17 @@ void MusicXml::direction(Measure* measure, int staff, QDomElement e)
t = new StaffText(score);
}
qDebug("formatted words '%s'", qPrintable(wordstext));
t->setText(wordstext);
qDebug("formatted words '%s'", qPrintable(formattedText));
t->setText(formattedText);
if (enclosure == "circle") {
t->textStyle().setHasFrame(true);
t->textStyle().setCircle(true);
}
else if (enclosure == "rectangle") {
t->textStyle().setHasFrame(true);
t->textStyle().setFrameRound(0);
}
if (metrEl.tagName() != "") metronome(metrEl, t);
if (hasYoffset) t->textStyle().setYoff(yoffset);
@ -3021,10 +3032,12 @@ void MusicXml::direction(Measure* measure, int staff, QDomElement e)
}
else if (dirType == "rehearsal") {
Text* t = new RehearsalMark(score);
t->setPlainText(rehearsal);
if (!formattedText.contains("<b>"))
formattedText = "<b></b>" + formattedText; // explicitly turn bold off
t->setText(formattedText);
t->textStyle().setHasFrame(enclosure != "none");
if (hasYoffset) t->textStyle().setYoff(yoffset);
else t->setPlacement(placement == "above" ? Element::Placement::ABOVE : Element::Placement::BELOW);
if (hasYoffset) t->textStyle().setYoff(yoffset);
addElem(t, track, placement, measure, tick);
}
else if (dirType == "pedal") {
@ -3596,6 +3609,7 @@ void MusicXml::xmlLyric(int trk, QDomElement e,
unNumbrdLyrics.append(l);
}
QString formattedText;
for (e = e.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) {
if (e.tagName() == "syllabic") {
if (e.text() == "single")
@ -3610,13 +3624,13 @@ void MusicXml::xmlLyric(int trk, QDomElement e,
qDebug("unknown syllabic %s", qPrintable(e.text()));
}
else if (e.tagName() == "text")
l->setPlainText(l->text()+e.text());
formattedText += nextPartOfFormattedString(e);
else if (e.tagName() == "elision")
if (e.text().isEmpty()) {
l->setPlainText(l->text()+" ");
formattedText += " ";
}
else {
l->setPlainText(l->text()+e.text());
formattedText += nextPartOfFormattedString(e);
}
else if (e.tagName() == "extend")
;
@ -3627,6 +3641,8 @@ void MusicXml::xmlLyric(int trk, QDomElement e,
else
domError(e);
}
qDebug("formatted lyric '%s'", qPrintable(formattedText));
l->setText(formattedText);
}
#if 0

Binary file not shown.

View file

@ -0,0 +1,260 @@
<?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>
<work>
<work-number>MuseScore testfile</work-number>
<work-title>Formatted Things</work-title>
</work>
<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>Voice</part-name>
<part-abbreviation>Vo.</part-abbreviation>
<score-instrument id="P1-I3">
<instrument-name>Voice</instrument-name>
</score-instrument>
<midi-device id="P1-I3" port="1"></midi-device>
<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>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="2">
<print new-system="yes"/>
<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 underline="1" font-size="6">For</text>
<text underline="0" font-size="11">matted</text>
<text font-family="JazzText" font-size="18">Lyric</text>
</lyric>
</note>
</measure>
<measure number="3">
<direction placement="above">
<direction-type>
<rehearsal font-weight="bold" font-size="14">Default rehearsal mark</rehearsal>
</direction-type>
</direction>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="4">
<direction placement="above">
<direction-type>
<rehearsal font-size="24">Big, not bold</rehearsal>
</direction-type>
</direction>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="5">
<print new-system="yes"/>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="6">
<direction placement="above">
<direction-type>
<rehearsal font-style="italic" font-size="14">italic</rehearsal>
</direction-type>
</direction>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="7">
<direction placement="above">
<direction-type>
<rehearsal underline="1" font-size="14">underlined</rehearsal>
</direction-type>
</direction>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="8">
<print new-system="yes"/>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="9">
<direction placement="above">
<direction-type>
<rehearsal font-size="14">not bold</rehearsal>
</direction-type>
</direction>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="10">
<direction placement="above">
<direction-type>
<rehearsal enclosure="none" font-weight="bold" font-size="14">No frame</rehearsal>
</direction-type>
</direction>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="11">
<print new-system="yes"/>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="12">
<direction placement="above">
<direction-type>
<words enclosure="rectangle">Boxed Staff Text</words>
</direction-type>
</direction>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="13">
<direction placement="above">
<direction-type>
<words enclosure="circle">Circled</words>
</direction-type>
</direction>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="14">
<print new-system="yes"/>
<direction placement="above">
<direction-type>
<words>Normal Staff Text</words>
</direction-type>
</direction>
<note>
<pitch>
<step>G</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>