Skip to content

Commit

Permalink
Fix inferring measure rests & read the measure attribute
Browse files Browse the repository at this point in the history
Backport of  musescore#25040
  • Loading branch information
miiizen authored and Jojo-Schmitz committed Oct 17, 2024
1 parent 089ef5b commit e964a52
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 27 deletions.
17 changes: 8 additions & 9 deletions importexport/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5641,19 +5641,16 @@ void MusicXMLParserPass2::divisions()
// the type for all rests.
// Sibelius calls all whole-measure rests "whole", even if the duration != 4/4

static bool isWholeMeasureRest(const bool rest, const QString& type, const Fraction dura, const Fraction mDura)
static bool isWholeMeasureRest(const QString& type, const Fraction dura, const Fraction mDura)
{
if (!rest)
return false;

if (!dura.isValid())
return false;

if (!mDura.isValid())
return false;

return ((type.isEmpty() && dura == mDura)
|| (type == "whole" && dura == mDura && dura != Fraction(1, 1)));
return (type.isEmpty() && dura == mDura)
|| (type == "whole" && dura == mDura);
}

//---------------------------------------------------------
Expand All @@ -5665,14 +5662,14 @@ static bool isWholeMeasureRest(const bool rest, const QString& type, const Fract
* This includes whole measure rest detection.
*/

static TDuration determineDuration(const bool rest, const QString& type, const int dots, const Fraction dura, const Fraction mDura)
static TDuration determineDuration(const bool rest, const bool measureRest, const QString& type, const int dots, const Fraction dura, const Fraction mDura)
{
//qDebug("determineDuration rest %d type '%s' dots %d dura %s mDura %s",
// rest, qPrintable(type), dots, qPrintable(dura.print()), qPrintable(mDura.print()));

TDuration res;
if (rest) {
if (isWholeMeasureRest(rest, type, dura, mDura))
if (measureRest || isWholeMeasureRest(type, dura, mDura))
res.setType(TDuration::DurationType::V_MEASURE);
else if (type.isEmpty()) {
// If no type, set duration type based on duration.
Expand Down Expand Up @@ -6098,6 +6095,7 @@ Note* MusicXMLParserPass2::note(const QString& partId,
bool isSmall = false;
bool grace = false;
bool rest = false;
bool measureRest = false;
int staff = 0;
QString type;
QString voice;
Expand Down Expand Up @@ -6173,6 +6171,7 @@ Note* MusicXMLParserPass2::note(const QString& partId,
}
else if (_e.name() == "rest") {
rest = true;
measureRest = _e.attributes().value("measure") == "yes";
mnp.displayStepOctave(_e);
}
else if (_e.name() == "staff") {
Expand Down Expand Up @@ -6282,7 +6281,7 @@ Note* MusicXMLParserPass2::note(const QString& partId,
ChordRest* cr { nullptr };
Note* note { nullptr };

TDuration duration = determineDuration(rest, type, mnd.dots(), dura, measure->ticks());
TDuration duration = determineDuration(rest, measureRest, type, mnd.dots(), dura, measure->ticks());

// begin allocation
if (rest) {
Expand Down
9 changes: 3 additions & 6 deletions mtest/musicxml/io/testIncompleteTuplet_ref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,18 @@
</clef>
</attributes>
<note>
<rest/>
<rest measure="yes"/>
<duration>36</duration>
<voice>1</voice>
<type>whole</type>
<staff>1</staff>
</note>
<backup>
<duration>36</duration>
</backup>
<note>
<rest/>
<rest measure="yes"/>
<duration>36</duration>
<voice>5</voice>
<type>whole</type>
<staff>2</staff>
</note>
</measure>
Expand Down Expand Up @@ -243,10 +241,9 @@
<duration>36</duration>
</backup>
<note>
<rest/>
<rest measure="yes"/>
<duration>36</duration>
<voice>5</voice>
<type>whole</type>
<staff>2</staff>
</note>
<barline location="right">
Expand Down
3 changes: 1 addition & 2 deletions mtest/musicxml/io/testNoteAttributes1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,9 @@
</measure>
<measure number="3">
<note>
<rest/>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
<notations>
<fermata type="upright"/>
</notations>
Expand Down
3 changes: 1 addition & 2 deletions mtest/musicxml/io/testNotesRests1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,9 @@
</measure>
<measure number="3">
<note>
<rest/>
<rest measure="yes"/>
<duration>64</duration>
<voice>1</voice>
<type>whole</type>
</note>
<backup>
<duration>64</duration>
Expand Down
12 changes: 4 additions & 8 deletions mtest/musicxml/io/testRestNotations_ref.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,23 @@
</clef>
</attributes>
<note>
<rest/>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="2">
<note>
<rest/>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="3">
<note>
<rest/>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
</measure>
<measure number="4">
Expand All @@ -87,10 +84,9 @@
</measure>
<measure number="5">
<note>
<rest/>
<rest measure="yes"/>
<duration>4</duration>
<voice>1</voice>
<type>whole</type>
</note>
<barline location="right">
<bar-style>light-heavy</bar-style>
Expand Down

0 comments on commit e964a52

Please sign in to comment.