Skip to content

Commit

Permalink
Fix GH#23041: Prevent setting measure rest with ticks value of 0
Browse files Browse the repository at this point in the history
Backport of musescore#23670
  • Loading branch information
miiizen authored and Jojo-Schmitz committed Dec 29, 2024
1 parent ff38f52 commit cdcfed5
Show file tree
Hide file tree
Showing 7 changed files with 494 additions and 24 deletions.
13 changes: 6 additions & 7 deletions libmscore/check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
// the file LICENCE.GPL
//=============================================================================

#include "score.h"
#include "slur.h"
#include "measure.h"
#include "tuplet.h"
#include "chordrest.h"
#include "clef.h"
#include "keysig.h"
#include "measure.h"
#include "rest.h"
#include "score.h"
#include "segment.h"
#include "staff.h"
#include "keysig.h"
#include "clef.h"
#include "tuplet.h"
#include "utils.h"

namespace Ms {
Expand Down Expand Up @@ -331,7 +330,7 @@ void Measure::fillGap(const Fraction& pos, const Fraction& len, int track, const
d.setVal(len.ticks());
if (d.isValid()) {
Rest* rest = new Rest(score());
rest->setTicks(len);
rest->setTicks(d.isMeasure() ? ticks() : len);
rest->setDurationType(d);
rest->setTrack(track);
rest->setGap(useGapRests);
Expand Down
2 changes: 1 addition & 1 deletion libmscore/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ Segment* Score::setNoteRest(Segment* segment, int track, NoteVal nval, Fraction
nr = ncr = new Rest(this);
nr->setTrack(track);
ncr->setDurationType(d);
ncr->setTicks(d == TDuration::DurationType::V_MEASURE ? measure->ticks() : d.fraction());
ncr->setTicks(d.isMeasure() ? measure->ticks() : d.fraction());
}
else {
nr = note = new Note(this);
Expand Down
2 changes: 1 addition & 1 deletion libmscore/edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ ChordRest* Score::addClone(ChordRest* cr, const Fraction& tick, const TDuration&
newcr = toChordRest(cr->clone());
newcr->rxpos() = 0.0;
newcr->setDurationType(d);
newcr->setTicks(d.fraction());
newcr->setTicks(d.isMeasure() ? cr->measure()->ticks() : d.fraction());
newcr->setTuplet(cr->tuplet());
newcr->setSelected(false);

Expand Down
9 changes: 6 additions & 3 deletions libmscore/measure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1860,15 +1860,18 @@ void Measure::adjustToLen(Fraction nf, bool appendRestsIfNecessary)
// convert the measure duration in a list of values (no dots for rests)
std::vector<TDuration> durList = toDurationList(nf * stretch, false, 0);

rest->undoChangeProperty(Pid::DURATION, QVariant::fromValue<Fraction>(durList[0].fraction()));
// set the existing rest to the first value of the duration list
TDuration firstDur = durList[0];
rest->undoChangeProperty(Pid::DURATION, firstDur.isMeasure() ? ticks() : firstDur.fraction());
rest->undoChangeProperty(Pid::DURATION_TYPE, QVariant::fromValue<TDuration>(durList[0]));

// add rests for any other duration list value
Fraction tickOffset = tick() + rest->actualTicks();
for (unsigned i = 1; i < durList.size(); i++) {
Rest* newRest = new Rest(s);
newRest->setDurationType(durList.at(i));
newRest->setTicks(durList.at(i).fraction());
TDuration dur = durList.at(i);
newRest->setDurationType(dur);
newRest->setTicks(dur.isMeasure() ? ticks() : dur.fraction());
newRest->setTrack(rest->track());
score()->undoAddCR(newRest, this, tickOffset);
tickOffset += newRest->actualTicks();
Expand Down
222 changes: 222 additions & 0 deletions mtest/libmscore/measure/changeMeasureLen-ref.mscx
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
<?xml version="1.0" encoding="UTF-8"?>
<museScore version="3.02">
<Score>
<LayerTag id="0" tag="default"></LayerTag>
<currentLayer>0</currentLayer>
<Division>480</Division>
<Style>
<Spatium>1.74978</Spatium>
</Style>
<showInvisible>1</showInvisible>
<showUnprintable>1</showUnprintable>
<showFrames>1</showFrames>
<showMargins>0</showMargins>
<metaTag name="arranger"></metaTag>
<metaTag name="composer">Composer / arranger</metaTag>
<metaTag name="copyright"></metaTag>
<metaTag name="lyricist"></metaTag>
<metaTag name="movementNumber"></metaTag>
<metaTag name="movementTitle"></metaTag>
<metaTag name="poet"></metaTag>
<metaTag name="source"></metaTag>
<metaTag name="subtitle">Subtitle</metaTag>
<metaTag name="translator"></metaTag>
<metaTag name="workNumber"></metaTag>
<metaTag name="workTitle">Untitled score</metaTag>
<Order id="orchestra" customized="1">
<name>Orchestra</name>
<instrument id="flute">
<family id="flutes">Flutes</family>
</instrument>
<section id="woodwind" brackets="true" showSystemMarkings="false" barLineSpan="true" thinBrackets="true">
<family>flutes</family>
<family>oboes</family>
<family>clarinets</family>
<family>saxophones</family>
<family>bassoons</family>
<unsorted group="woodwinds"/>
</section>
<section id="brass" brackets="true" showSystemMarkings="false" barLineSpan="true" thinBrackets="true">
<family>horns</family>
<family>trumpets</family>
<family>cornets</family>
<family>flugelhorns</family>
<family>trombones</family>
<family>tubas</family>
<unsorted group="brass"/>
</section>
<section id="timpani" brackets="true" showSystemMarkings="false" barLineSpan="true" thinBrackets="true">
<family>timpani</family>
</section>
<section id="percussion" brackets="true" showSystemMarkings="false" barLineSpan="true" thinBrackets="true">
<family>keyboard-percussion</family>
<unsorted group="pitched-percussion"/>
<family>drums</family>
<family>unpitched-metal-percussion</family>
<family>unpitched-wooden-percussion</family>
<family>other-percussion</family>
<unsorted group="unpitched-percussion"/>
</section>
<family>keyboards</family>
<family>harps</family>
<family>organs</family>
<family>synths</family>
<unsorted/>
<soloists/>
<section id="voices" brackets="true" showSystemMarkings="false" barLineSpan="false" thinBrackets="true">
<family>voices</family>
<family>voice-groups</family>
</section>
<section id="strings" brackets="true" showSystemMarkings="false" barLineSpan="true" thinBrackets="true">
<family>orchestral-strings</family>
</section>
</Order>
<Part>
<Staff id="1">
<StaffType group="pitched">
<name>stdNormal</name>
</StaffType>
</Staff>
<trackName>Flute</trackName>
<Instrument id="flute">
<longName>Flute</longName>
<shortName>Fl.</shortName>
<trackName>Flute</trackName>
<minPitchP>59</minPitchP>
<maxPitchP>98</maxPitchP>
<minPitchA>60</minPitchA>
<maxPitchA>93</maxPitchA>
<instrumentId>wind.flutes.flute</instrumentId>
<Channel>
<program value="73"/>
</Channel>
</Instrument>
</Part>
<Staff id="1">
<Measure>
<voice>
<TimeSig>
<sigN>4</sigN>
<sigD>4</sigD>
</TimeSig>
<Chord>
<durationType>quarter</durationType>
<Note>
<pitch>74</pitch>
<tpc>16</tpc>
</Note>
</Chord>
<Chord>
<durationType>quarter</durationType>
<Note>
<pitch>74</pitch>
<tpc>16</tpc>
</Note>
</Chord>
<Chord>
<durationType>quarter</durationType>
<Note>
<pitch>74</pitch>
<tpc>16</tpc>
</Note>
</Chord>
<Chord>
<durationType>quarter</durationType>
<Note>
<pitch>74</pitch>
<tpc>16</tpc>
</Note>
</Chord>
</voice>
</Measure>
<Measure len="6/4">
<voice>
<Chord>
<durationType>quarter</durationType>
<Note>
<pitch>74</pitch>
<tpc>16</tpc>
</Note>
</Chord>
<Chord>
<durationType>quarter</durationType>
<Note>
<pitch>74</pitch>
<tpc>16</tpc>
</Note>
</Chord>
<Rest>
<durationType>half</durationType>
</Rest>
<Rest>
<durationType>half</durationType>
</Rest>
</voice>
</Measure>
<Measure>
<voice>
<Chord>
<durationType>quarter</durationType>
<Note>
<pitch>74</pitch>
<tpc>16</tpc>
</Note>
</Chord>
<Chord>
<durationType>quarter</durationType>
<Note>
<pitch>74</pitch>
<tpc>16</tpc>
</Note>
</Chord>
<Chord>
<durationType>quarter</durationType>
<Note>
<pitch>74</pitch>
<tpc>16</tpc>
</Note>
</Chord>
<Chord>
<durationType>quarter</durationType>
<Note>
<pitch>74</pitch>
<tpc>16</tpc>
</Note>
</Chord>
</voice>
</Measure>
<Measure>
<voice>
<Chord>
<durationType>quarter</durationType>
<Note>
<pitch>74</pitch>
<tpc>16</tpc>
</Note>
</Chord>
<Chord>
<durationType>quarter</durationType>
<Note>
<pitch>74</pitch>
<tpc>16</tpc>
</Note>
</Chord>
<Chord>
<durationType>quarter</durationType>
<Note>
<pitch>74</pitch>
<tpc>16</tpc>
</Note>
</Chord>
<Chord>
<durationType>quarter</durationType>
<Note>
<pitch>74</pitch>
<tpc>16</tpc>
</Note>
</Chord>
</voice>
</Measure>
</Staff>
</Score>
</museScore>
Loading

0 comments on commit cdcfed5

Please sign in to comment.