diff --git a/src/engraving/compat/midi/compatmidirender.cpp b/src/engraving/compat/midi/compatmidirender.cpp index 8620acd227893..659169ed722f6 100644 --- a/src/engraving/compat/midi/compatmidirender.cpp +++ b/src/engraving/compat/midi/compatmidirender.cpp @@ -327,11 +327,12 @@ void CompatMidiRender::renderTremolo(Chord* chord, std::vector& 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(); @@ -404,15 +405,12 @@ void CompatMidiRender::renderTremolo(Chord* chord, std::vector& 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 = muse::RealIsNull(tremoloPartOfChord) ? 1.0 : tremoloPartOfChord; - int tremoloEventsSize = chord->ticks().ticks() / t * tremoloPartOfChord; + int tremoloEventsSize = static_cast(static_cast(chord->ticks().ticks()) / t * tpoch); - constexpr int fullEventTime = 1000; - int tremoloTime = fullEventTime * tremoloPartOfChord; + constexpr double fullEventTime = 1000.0; + int tremoloTime = static_cast(fullEventTime * tremoloPartOfChord); int tremoloEventStep = tremoloTime / tremoloEventsSize; ontime += tremoloTime;