Skip to content

Commit

Permalink
fix: division by zero in compatmidirenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekirin committed Sep 20, 2024
1 parent 740034c commit 217d774
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/engraving/compat/midi/compatmidirender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,12 @@ void CompatMidiRender::renderTremolo(Chord* chord, std::vector<NoteEventList>& e
}

// render tremolo with multiple events
int divider = 1 << (tremolo.lines() + chord->durationType().hooks());
int t = 1;
if (divider != 0) {
t = Constants::DIVISION / divider;
}
if (chord->tremoloChordType() == TremoloChordType::TremoloFirstChord) {
int t = Constants::DIVISION / (1 << (tremolo.lines() + chord->durationType().hooks()));
if (t == 0) { // avoid crash on very short tremolo
t = 1;
}
SegmentType st = SegmentType::ChordRest;
Segment* seg2 = seg->next(st);
track_idx_t track = chord->track();
Expand Down Expand Up @@ -404,15 +405,12 @@ void CompatMidiRender::renderTremolo(Chord* chord, std::vector<NoteEventList>& e
events->clear();
}
} else if (chord->tremoloChordType() == TremoloChordType::TremoloSingle) {
int t = Constants::DIVISION / (1 << (tremolo.lines() + chord->durationType().hooks()));
if (t == 0) { // avoid crash on very short tremolo
t = 1;
}
double tpoch = mu::RealIsNull(tremoloPartOfChord) ? 1.0 : tremoloPartOfChord;

int tremoloEventsSize = chord->ticks().ticks() / t * tremoloPartOfChord;
int tremoloEventsSize = chord->ticks().ticks() / t * static_cast<int>(tpoch);

constexpr int fullEventTime = 1000;
int tremoloTime = fullEventTime * tremoloPartOfChord;
int tremoloTime = fullEventTime * static_cast<int>(tremoloPartOfChord);
int tremoloEventStep = tremoloTime / tremoloEventsSize;
ontime += tremoloTime;

Expand Down

0 comments on commit 217d774

Please sign in to comment.