Skip to content

Commit

Permalink
Fix #331840: Crash on creating a 4-or-higher tuplet on a 512th
Browse files Browse the repository at this point in the history
 or an 8-or-higher tuplet on a 256th
  • Loading branch information
Jojo-Schmitz committed Jan 28, 2023
1 parent 03b6e76 commit 52c82e8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/notation/inotationinteraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ class INotationInteraction
virtual void addBracketsToSelection(BracketsType type) = 0;
virtual void changeSelectedNotesArticulation(SymbolId articulationSymbolId) = 0;
virtual void addGraceNotesToSelectedNotes(GraceNoteType type) = 0;
virtual bool canAddTupletToSelectedChordRests() const = 0;
virtual bool canAddTupletToSelectedChordRests(int numerator) const = 0;
virtual void addTupletToSelectedChordRests(const TupletOptions& options) = 0;
virtual void addBeamToSelectedChordRests(BeamMode mode) = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/notation/internal/notationactioncontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ void NotationActionController::putTuplet(const TupletOptions& options)
return;
}

if (!interaction->canAddTupletToSelectedChordRests()) {
if (!interaction->canAddTupletToSelectedChordRests(options.ratio.numerator())) {
interactive()->error(trc("notation", "Cannot create tuplet"), trc("notation", "Note value is too short"));
return;
}
Expand Down
9 changes: 6 additions & 3 deletions src/notation/internal/notationinteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3860,15 +3860,18 @@ void NotationInteraction::addGraceNotesToSelectedNotes(GraceNoteType type)
apply();
}

bool NotationInteraction::canAddTupletToSelectedChordRests() const
bool NotationInteraction::canAddTupletToSelectedChordRests(int n) const
{
for (ChordRest* chordRest : score()->getSelectedChordRests()) {
if (chordRest->isGrace()) {
continue;
}

if (chordRest->durationType() < mu::engraving::TDuration(mu::engraving::DurationType::V_512TH)
&& chordRest->durationType() != mu::engraving::TDuration(mu::engraving::DurationType::V_MEASURE)) {
if ((chordRest->durationType() < mu::engraving::TDuration(mu::engraving::DurationType::V_512TH)
&& chordRest->durationType() != mu::engraving::TDuration(mu::engraving::DurationType::V_MEASURE))
|| (chordRest->durationType() < mu::engraving::TDuration(mu::engraving::DurationType::V_256TH) && n > 3)
|| (chordRest->durationType() < mu::engraving::TDuration(mu::engraving::DurationType::V_128TH) && n > 7)
) {
return false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/notation/internal/notationinteraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class NotationInteraction : public INotationInteraction, public async::Asyncable
void addBracketsToSelection(BracketsType type) override;
void changeSelectedNotesArticulation(SymbolId articulationSymbolId) override;
void addGraceNotesToSelectedNotes(GraceNoteType type) override;
bool canAddTupletToSelectedChordRests() const override;
bool canAddTupletToSelectedChordRests(int numerator) const override;
void addTupletToSelectedChordRests(const TupletOptions& options) override;
void addBeamToSelectedChordRests(BeamMode mode) override;

Expand Down

0 comments on commit 52c82e8

Please sign in to comment.