Skip to content

Commit

Permalink
Prevent crash on splitting the shortest possible measure
Browse files Browse the repository at this point in the history
Backport of musescore#8894, part 2
  • Loading branch information
Jojo-Schmitz committed Aug 20, 2021
1 parent ed94573 commit 840de23
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions libmscore/mscore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ std::vector<MScoreError> MScore::errorList {
{ CANNOT_SPLIT_TUPLET, "t2", QT_TRANSLATE_NOOP("error", "Cannot split tuplet") },
{ CANNOT_SPLIT_MEASURE_FIRST_BEAT, "m1", QT_TRANSLATE_NOOP("error", "Cannot split measure here:\n" "First beat of measure") },
{ CANNOT_SPLIT_MEASURE_TUPLET, "m2", QT_TRANSLATE_NOOP("error", "Cannot split measure here:\n" "Cannot split tuplet") },
{ CANNOT_SPLIT_MEASURE_TOO_SHORT, "m3", QT_TRANSLATE_NOOP("error", "Cannot split measure here:\n" "Measure would be too short") },

{ NO_DEST, "p1", QT_TRANSLATE_NOOP("error", "No destination to paste") },
{ DEST_TUPLET, "p2", QT_TRANSLATE_NOOP("error", "Cannot paste into tuplet") },
Expand Down
1 change: 1 addition & 0 deletions libmscore/mscore.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ enum MsError {
CANNOT_SPLIT_TUPLET,
CANNOT_SPLIT_MEASURE_FIRST_BEAT,
CANNOT_SPLIT_MEASURE_TUPLET,
CANNOT_SPLIT_MEASURE_TOO_SHORT,
NO_DEST,
DEST_TUPLET,
TUPLET_CROSSES_BAR,
Expand Down
7 changes: 5 additions & 2 deletions libmscore/splitMeasure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ void Score::cmdSplitMeasure(ChordRest* cr)

//---------------------------------------------------------
// splitMeasure
// return true on success
//---------------------------------------------------------

void Score::splitMeasure(Segment* segment)
Expand Down Expand Up @@ -111,7 +110,7 @@ void Score::splitMeasure(Segment* segment)
if (ticks1.denominator() < measure->ticks().denominator()) {
if (measure->ticks().denominator() % m1->timesig().denominator() == 0) {
int mult = measure->ticks().denominator() / ticks1.denominator();
// *= operator audomatically reduces via GCD, so rather do literal multiplication:
// *= operator automatically reduces via GCD, so rather do literal multiplication:
ticks1.setDenominator(ticks1.denominator() * mult);
ticks1.setNumerator(ticks1.numerator() * mult);
}
Expand All @@ -123,6 +122,10 @@ void Score::splitMeasure(Segment* segment)
ticks2.setNumerator(ticks2.numerator() * mult);
}
}
if (ticks1.denominator() > 128 || ticks2.denominator() > 128) {
MScore::setError(CANNOT_SPLIT_MEASURE_TOO_SHORT);
return;
}
m1->adjustToLen(ticks1, false);
m2->adjustToLen(ticks2, false);
range.write(this, m1->tick());
Expand Down

0 comments on commit 840de23

Please sign in to comment.