Skip to content

Commit

Permalink
Merge b907fe7 into a6cba54
Browse files Browse the repository at this point in the history
  • Loading branch information
Jojo-Schmitz committed Dec 4, 2023
2 parents a6cba54 + b907fe7 commit 36f2f40
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 80 deletions.
2 changes: 1 addition & 1 deletion importexport/musicxml/importmxmlnoteduration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void mxmlNoteDuration::duration(QXmlStreamReader& e)

_specDura.set(0, 0); // invalid unless set correctly
int intDura = e.readElementText().toInt();
_specDura = _pass1->calcTicks(intDura, &e); // Duration reading (and rounding) code consolidated to pass1
_specDura = _pass1->calcTicks(intDura, _divs, &e); // Duration reading (and rounding) code consolidated to pass1
}

//---------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions importexport/musicxml/importmxmlpass1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3555,12 +3555,12 @@ void MusicXMLParserPass1::notePrintSpacingNo(Fraction& dura)
// calcTicks
//---------------------------------------------------------

Fraction MusicXMLParserPass1::calcTicks(const int& intTicks, const QXmlStreamReader* const xmlReader)
Fraction MusicXMLParserPass1::calcTicks(const int& intTicks, const int& _divisions, const QXmlStreamReader* const xmlReader)
{
Fraction dura(0, 1); // invalid unless set correctly

if (_divs > 0) {
dura.set(intTicks, 4 * _divs);
if (_divisions > 0) {
dura.set(intTicks, 4 * _divisions);
dura.reduce(); // prevent overflow in later Fraction operations

// Correct for previously adjusted durations
Expand Down
4 changes: 2 additions & 2 deletions importexport/musicxml/importmxmlpass1.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ class MusicXMLParserPass1 {
void notations(MxmlStartStop& tupletStartStop);
void note(const QString& partId, const Fraction cTime, Fraction& missingPrev, Fraction& dura, Fraction& missingCurr, VoiceOverlapDetector& vod, MxmlTupletStates& tupletStates);
void notePrintSpacingNo(Fraction& dura);
Fraction calcTicks(const int& intTicks, const QXmlStreamReader* const xmlReader);
Fraction calcTicks(const int& intTicks) { return calcTicks(intTicks, &_e); }
Fraction calcTicks(const int& intTicks, const int& _divisions, const QXmlStreamReader* const xmlReader);
Fraction calcTicks(const int& intTicks) { return calcTicks(intTicks, _divs, &_e); }
void duration(Fraction& dura, QXmlStreamReader& e);
void duration(Fraction& dura) { duration(dura, _e); }
void forward(Fraction& dura);
Expand Down
6 changes: 3 additions & 3 deletions importexport/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3123,7 +3123,7 @@ void MusicXMLParserDirection::direction(const QString& partId,
if (_e.name() == "direction-type")
directionType(starts, stops);
else if (_e.name() == "offset") {
_offset = _pass1.calcTicks(_e.readElementText().toInt(), &_e);
_offset = _pass1.calcTicks(_e.readElementText().toInt(), _pass2.divs(), &_e);
preventNegativeTick(tick, _offset, _logger);
}
else if (_e.name() == "sound")
Expand Down Expand Up @@ -6047,7 +6047,7 @@ void MusicXMLParserPass2::duration(Fraction& dura)
dura.set(0, 0); // invalid unless set correctly
const auto elementText = _e.readElementText();
if (elementText.toInt() > 0)
dura = _pass1.calcTicks(elementText.toInt(), &_e);
dura = _pass1.calcTicks(elementText.toInt(), _divs, &_e);
else
_logger->logError(QString("illegal duration %1").arg(dura.print()), &_e);
//qDebug("duration %s valid %d", qPrintable(dura.print()), dura.isValid());
Expand Down Expand Up @@ -6484,7 +6484,7 @@ void MusicXMLParserPass2::harmony(const QString& partId, Measure* measure, const
else if (_e.name() == "level")
skipLogCurrElem();
else if (_e.name() == "offset") {
offset = _pass1.calcTicks(_e.readElementText().toInt(), &_e);
offset = _pass1.calcTicks(_e.readElementText().toInt(), _divs, &_e);
preventNegativeTick(sTime, offset, _logger);
}
else if (_e.name() == "staff") {
Expand Down
1 change: 1 addition & 0 deletions importexport/musicxml/importmxmlpass2.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ class MusicXMLParserPass2 {
MusicXmlExtendedSpannerDesc& getSpanner(const MusicXmlSpannerDesc& desc);
void clearSpanner(const MusicXmlSpannerDesc& desc);
void deleteHandledSpanner(SLine* const& spanner);
int divs() { return _divs; }

private:
void addError(const QString& error); ///< Add an error to be shown in the GUI
Expand Down
12 changes: 2 additions & 10 deletions mtest/musicxml/io/testDivsDefinedTooLate1_ref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,10 @@
<line>2</line>
</clef>
</attributes>
<note>
<rest/>
<duration>3</duration>
<voice>1</voice>
<type>half</type>
<dot/>
</note>
<note print-object="no">
<rest/>
<duration>1</duration>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
<type>quarter</type>
</note>
</measure>
<measure number="2">
Expand Down
11 changes: 2 additions & 9 deletions mtest/musicxml/io/testDivsDefinedTooLate2_ref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,10 @@
<line>2</line>
</clef>
</attributes>
<note>
<rest/>
<duration>2</duration>
<voice>1</voice>
<type>half</type>
</note>
<note print-object="no">
<rest/>
<duration>2</duration>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
<type>half</type>
</note>
</measure>
<measure number="2">
Expand Down
54 changes: 2 additions & 52 deletions mtest/musicxml/io/testDurationLargeError_ref.mscx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<Note>
<Events>
<Event>
<len>90000</len>
<len>900</len>
</Event>
</Events>
<pitch>67</pitch>
Expand All @@ -128,11 +128,6 @@
<durationType>half</durationType>
<StemDirection>up</StemDirection>
<Note>
<Events>
<Event>
<len>100000</len>
</Event>
</Events>
<pitch>69</pitch>
<tpc>17</tpc>
</Note>
Expand All @@ -147,7 +142,7 @@
<Note>
<Events>
<Event>
<len>110000</len>
<len>1100</len>
</Event>
</Events>
<pitch>71</pitch>
Expand All @@ -158,11 +153,6 @@
<durationType>half</durationType>
<StemDirection>down</StemDirection>
<Note>
<Events>
<Event>
<len>100000</len>
</Event>
</Events>
<pitch>72</pitch>
<tpc>14</tpc>
</Note>
Expand All @@ -175,11 +165,6 @@
<durationType>quarter</durationType>
<StemDirection>up</StemDirection>
<Note>
<Events>
<Event>
<len>484000</len>
</Event>
</Events>
<pitch>60</pitch>
<tpc>14</tpc>
</Note>
Expand All @@ -188,11 +173,6 @@
<durationType>quarter</durationType>
<StemDirection>up</StemDirection>
<Note>
<Events>
<Event>
<len>483000</len>
</Event>
</Events>
<pitch>62</pitch>
<tpc>16</tpc>
</Note>
Expand All @@ -201,11 +181,6 @@
<durationType>quarter</durationType>
<StemDirection>up</StemDirection>
<Note>
<Events>
<Event>
<len>482000</len>
</Event>
</Events>
<pitch>64</pitch>
<tpc>18</tpc>
</Note>
Expand All @@ -214,11 +189,6 @@
<durationType>quarter</durationType>
<StemDirection>up</StemDirection>
<Note>
<Events>
<Event>
<len>481000</len>
</Event>
</Events>
<pitch>65</pitch>
<tpc>13</tpc>
</Note>
Expand All @@ -231,11 +201,6 @@
<durationType>quarter</durationType>
<StemDirection>up</StemDirection>
<Note>
<Events>
<Event>
<len>480000</len>
</Event>
</Events>
<pitch>67</pitch>
<tpc>15</tpc>
</Note>
Expand All @@ -244,11 +209,6 @@
<durationType>quarter</durationType>
<StemDirection>up</StemDirection>
<Note>
<Events>
<Event>
<len>479000</len>
</Event>
</Events>
<pitch>69</pitch>
<tpc>17</tpc>
</Note>
Expand All @@ -257,11 +217,6 @@
<durationType>quarter</durationType>
<StemDirection>up</StemDirection>
<Note>
<Events>
<Event>
<len>478000</len>
</Event>
</Events>
<pitch>71</pitch>
<tpc>19</tpc>
</Note>
Expand All @@ -270,11 +225,6 @@
<durationType>quarter</durationType>
<StemDirection>up</StemDirection>
<Note>
<Events>
<Event>
<len>477000</len>
</Event>
</Events>
<pitch>72</pitch>
<tpc>14</tpc>
</Note>
Expand Down

0 comments on commit 36f2f40

Please sign in to comment.