Skip to content

Commit

Permalink
fix #104731 - Text lost when musicXML file imported
Browse files Browse the repository at this point in the history
  • Loading branch information
lvinken committed Feb 2, 2020
1 parent fceeba5 commit 6587b8a
Show file tree
Hide file tree
Showing 12 changed files with 803 additions and 314 deletions.
538 changes: 275 additions & 263 deletions mscore/importmxmlpass1.cpp

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions mscore/importmxmlpass1.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,16 @@ class MusicXMLParserPass1 {
void scorePartwise();
void identification();
void credit(CreditWordsList& credits);
void defaults(int& pageWidth, int& pageHeight);
void pageLayout(PageFormat& pf, const qreal conversion, int& pageWidth, int& pageHeight);
void defaults();
void pageLayout(PageFormat& pf, const qreal conversion);
void partList(MusicXmlPartGroupList& partGroupList);
void partGroup(const int scoreParts, MusicXmlPartGroupList& partGroupList, MusicXmlPartGroupMap& partGroups);
void scorePart();
void scoreInstrument(const QString& partId);
void midiInstrument(const QString& partId);
void part();
void measure(const QString& partId, const Fraction cTime, Fraction& mdur, VoiceOverlapDetector& vod);
void measure(const QString& partId, const Fraction cTime, Fraction& mdur, VoiceOverlapDetector& vod, const int measureNr);
void print(const int measureNr);
void attributes(const QString& partId, const Fraction cTime);
void clef(const QString& partId);
void time(const Fraction cTime);
Expand Down Expand Up @@ -161,6 +162,7 @@ class MusicXMLParserPass1 {
MusicXmlInstrList getInstrList(const QString id) const;
Fraction getMeasureStart(const int i) const;
int octaveShift(const QString& id, const int staff, const Fraction f) const;
const CreditWordsList& credits() const { return _credits; }

private:
// functions
Expand All @@ -170,8 +172,11 @@ class MusicXMLParserPass1 {
QXmlStreamReader _e;
int _divs; ///< Current MusicXML divisions value
QMap<QString, MusicXmlPart> _parts; ///< Parts data, mapped on part id
std::set<int> _systemStartMeasureNrs; ///< Measure numbers of measures starting a page
std::set<int> _pageStartMeasureNrs; ///< Measure numbers of measures starting a page
QVector<Fraction> _measureLength; ///< Length of each measure
QVector<Fraction> _measureStart; ///< Start time of each measure
CreditWordsList _credits; ///< All credits collected
PartMap _partMap; ///< TODO merge into MusicXmlPart ??
QMap<QString, MusicXMLDrumset> _drumsets; ///< Drumset for each part, mapped on part id
Score* _score; ///< MuseScore score
Expand All @@ -182,6 +187,7 @@ class MusicXMLParserPass1 {
QMap<int, MxmlOctaveShiftDesc> _octaveShifts; ///< Pending octave-shifts
Fraction _firstInstrSTime; ///< First instrument start time
QString _firstInstrId; ///< First instrument id
QSize _pageSize; ///< Page width read from defaults
};

} // namespace Ms
Expand Down
47 changes: 1 addition & 46 deletions mscore/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2002,7 +2002,7 @@ void MusicXMLParserPass2::measure(const QString& partId,
else if (_e.name() == "barline")
barline(partId, measure, time + mTime);
else if (_e.name() == "print")
print(measure);
_e.skipCurrentElement();
else
skipLogCurrElem();

Expand Down Expand Up @@ -2255,51 +2255,6 @@ void MusicXMLParserPass2::measureStyle(Measure* measure)
}
}


//---------------------------------------------------------
// print
//---------------------------------------------------------

/**
Parse the /score-partwise/part/measure/print node.
*/

void MusicXMLParserPass2::print(Measure* measure)
{
Q_ASSERT(_e.isStartElement() && _e.name() == "print");

bool newSystem = _e.attributes().value("new-system") == "yes";
bool newPage = _e.attributes().value("new-page") == "yes";
int blankPage = _e.attributes().value("blank-page").toInt();
//
// in MScore the break happens _after_ the marked measure:
//
MeasureBase* pm = measure->prevMeasure(); // We insert VBox only for title, no HBox for the moment
if (pm == 0) {
_logger->logDebugInfo("break on first measure", &_e);
if (blankPage == 1) { // blank title page, insert a VBOX if needed
pm = measure->prev();
if (pm == 0) {
_score->insertMeasure(ElementType::VBOX, measure);
pm = measure->prev();
}
}
}
if (pm) {
if (preferences.getBool(PREF_IMPORT_MUSICXML_IMPORTBREAKS) && (newSystem || newPage)) {
if (!pm->lineBreak() && !pm->pageBreak()) {
LayoutBreak* lb = new LayoutBreak(_score);
lb->setLayoutBreakType(newSystem ? LayoutBreak::Type::LINE : LayoutBreak::Type::PAGE);
pm->add(lb);
}
}
}

while (_e.readNextStartElement()) {
skipLogCurrElem();
}
}

//---------------------------------------------------------
// calcTicks
//---------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion mscore/importmxmlpass2.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ class MusicXMLParserPass2 {
void measure(const QString& partId, const Fraction time);
void attributes(const QString& partId, Measure* measure, const Fraction& tick);
void measureStyle(Measure* measure);
void print(Measure* measure);
void barline(const QString& partId, Measure* measure, const Fraction& tick);
void key(const QString& partId, Measure* measure, const Fraction& tick);
void clef(const QString& partId, Measure* measure, const Fraction& tick);
Expand Down
4 changes: 3 additions & 1 deletion mscore/musicxml.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ const int MAX_NUMBER_LEVEL = 6; // maximum number of overlapping MusicXML object
//---------------------------------------------------------

struct CreditWords {
int page;
double defaultX;
double defaultY;
QString justify;
QString hAlign;
QString vAlign;
QString words;
CreditWords(double a, double b, QString c, QString d, QString e, QString f)
CreditWords(int p, double a, double b, QString c, QString d, QString e, QString f)
{
page = p;
defaultX = a;
defaultY = b;
justify = c;
Expand Down
141 changes: 141 additions & 0 deletions mtest/musicxml/io/Page_break_in_vbox.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.1 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="3.1">
<work>
<work-title>Title</work-title>
</work>
<identification>
<creator type="composer">Composer</creator>
<creator type="lyricist">Lyricist</creator>
<rights>Copyright</rights>
<encoding>
<software>MuseScore 3.4.0</software>
<encoding-date>2020-01-24</encoding-date>
<supports element="accidental" type="yes"/>
<supports element="beam" type="yes"/>
<supports element="print" attribute="new-page" type="no"/>
<supports element="print" attribute="new-system" type="no"/>
<supports element="stem" type="yes"/>
</encoding>
</identification>
<defaults>
<scaling>
<millimeters>7.05556</millimeters>
<tenths>40</tenths>
</scaling>
<page-layout>
<page-height>1683.36</page-height>
<page-width>1190.88</page-width>
<page-margins type="even">
<left-margin>56.6929</left-margin>
<right-margin>56.6929</right-margin>
<top-margin>56.6929</top-margin>
<bottom-margin>113.386</bottom-margin>
</page-margins>
<page-margins type="odd">
<left-margin>56.6929</left-margin>
<right-margin>56.6929</right-margin>
<top-margin>56.6929</top-margin>
<bottom-margin>113.386</bottom-margin>
</page-margins>
</page-layout>
<word-font font-family="FreeSerif" font-size="10"/>
<lyric-font font-family="FreeSerif" font-size="11"/>
</defaults>
<credit page="1">
<credit-words default-x="595.44" default-y="1626.67" justify="center" valign="top" font-size="24">Title</credit-words>
</credit>
<credit page="1">
<credit-words default-x="595.44" default-y="1569.97" justify="center" valign="top" font-size="14">Subtitle</credit-words>
</credit>
<credit page="1">
<credit-words default-x="1134.19" default-y="1526.67" justify="right" valign="bottom" font-size="12">Composer</credit-words>
</credit>
<credit page="1">
<credit-words default-x="56.6929" default-y="1526.67" justify="left" valign="bottom" font-size="12">Lyricist</credit-words>
</credit>
<credit page="1">
<credit-words default-x="59" default-y="67" valign="top" font-size="12">Bottom vbox page 1</credit-words>
</credit>
<credit page="2">
<credit-words default-x="59" default-y="1626" valign="top" font-size="12">Top vbox page 2</credit-words>
</credit>
<credit page="2">
<credit-words default-x="59" default-y="67" valign="top" font-size="12">Bottom vbox page 2</credit-words>
</credit>
<part-list>
<score-part id="P1">
<part-name>Voice</part-name>
<part-abbreviation>Vo.</part-abbreviation>
<score-instrument id="P1-I1">
<instrument-name>Voice</instrument-name>
</score-instrument>
<midi-device id="P1-I1" port="1"></midi-device>
<midi-instrument id="P1-I1">
<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" width="1077.49">
<print>
<system-layout>
<system-margins>
<left-margin>0.00</left-margin>
<right-margin>0.00</right-margin>
</system-margins>
<top-system-distance>170.00</top-system-distance>
</system-layout>
</print>
<attributes>
<divisions>1</divisions>
<key>
<fifths>0</fifths>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<note>
<rest/>
<duration>4</duration>
<voice>1</voice>
</note>
</measure>
<measure number="2" width="1077.49">
<print new-system="yes"/>
<note>
<rest/>
<duration>4</duration>
<voice>1</voice>
</note>
</measure>
<measure number="3" width="1077.49">
<print new-page="yes"/>
<note>
<rest/>
<duration>4</duration>
<voice>1</voice>
</note>
</measure>
<measure number="4" width="1077.49">
<print new-system="yes"/>
<note>
<rest/>
<duration>4</duration>
<voice>1</voice>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>
3 changes: 3 additions & 0 deletions mtest/musicxml/io/TODO
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
2.2.2020 lv
Convert files Page*.xml and Title*.xml into regular testfiles.
Note: depends on fixing MusicXML export for the fetaures tested.
6.2.2015 ws
Test Wedge2 needs checking.
A Hairpin() changes its tick length in checkSpanners().
Expand Down
99 changes: 99 additions & 0 deletions mtest/musicxml/io/Title_page_double_at_start.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE score-partwise PUBLIC "-//Recordare//DTD MusicXML 3.1 Partwise//EN" "http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="3.1">
<work>
<work-title>Title page</work-title>
</work>
<identification>
<encoding>
<software>MuseScore 3.4.0</software>
<encoding-date>2020-02-02</encoding-date>
<supports element="accidental" type="yes"/>
<supports element="beam" type="yes"/>
<supports element="print" attribute="new-page" type="no"/>
<supports element="print" attribute="new-system" type="no"/>
<supports element="stem" type="yes"/>
</encoding>
</identification>
<defaults>
<scaling>
<millimeters>7.05556</millimeters>
<tenths>40</tenths>
</scaling>
<page-layout>
<page-height>1683.36</page-height>
<page-width>1190.88</page-width>
<page-margins type="even">
<left-margin>56.6929</left-margin>
<right-margin>56.6929</right-margin>
<top-margin>56.6929</top-margin>
<bottom-margin>113.386</bottom-margin>
</page-margins>
<page-margins type="odd">
<left-margin>56.6929</left-margin>
<right-margin>56.6929</right-margin>
<top-margin>56.6929</top-margin>
<bottom-margin>113.386</bottom-margin>
</page-margins>
</page-layout>
<word-font font-family="FreeSerif" font-size="10"/>
<lyric-font font-family="FreeSerif" font-size="11"/>
</defaults>
<credit page="1">
<credit-words default-x="595.44" default-y="1626.67" justify="center" valign="top" font-size="24">Title (double at start) page 1</credit-words>
</credit>
<credit page="2">
<credit-words default-x="595.44" default-y="1626.67" justify="center" valign="top" font-size="24">Title (double at start) page 2</credit-words>
</credit>
<part-list>
<score-part id="P1">
<part-name>Voice</part-name>
<part-abbreviation>Vo.</part-abbreviation>
<score-instrument id="P1-I1">
<instrument-name>Voice</instrument-name>
</score-instrument>
<midi-device id="P1-I1" port="1"></midi-device>
<midi-instrument id="P1-I1">
<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" width="239.74">
<print blank-page="2" new-page="yes">
<system-layout>
<system-margins>
<left-margin>0.00</left-margin>
<right-margin>837.76</right-margin>
</system-margins>
<top-system-distance>70.00</top-system-distance>
</system-layout>
</print>
<attributes>
<divisions>1</divisions>
<key>
<fifths>0</fifths>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<note>
<rest/>
<duration>4</duration>
<voice>1</voice>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
</barline>
</measure>
</part>
</score-partwise>
Loading

0 comments on commit 6587b8a

Please sign in to comment.