Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: division by zero in compatmidirenderer #24839
fix: division by zero in compatmidirenderer #24839
Changes from all commits
bcee79a
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took another look and this check appears to be unnecessary: just at the top of
CompatMidiRender::renderTremolo
, we already haveThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the
double
casts don't make a difference here: when(static_cast<double>(t) * tpoch) > chord->ticks().ticks()
, then the result of the division would be between 0.0 and 1.0, so casting that back toint
will still result in 0.But you are changing the meaning of the code. Essentially, this is what's happening:
I think that's incorrect: if the whole chord were a tremolo, then
(chord->ticks().ticks() / t)
would be the correct number of events; and if only part of the chord is a tremolo (i.e.tremoloPartOfChord < 1
) then(chord->ticks().ticks() / t) * tremoloPartOfChord
would be the correct number.It looks like the calculation of
tremoloEventsSize
can stay as it is (even extra casts to double would not have any effect); all that's needed would be to check thattremoloEventsSize
is not zero. If it is zero, then just do an early return, since thefor
loop below would not be run anyway in that case.Apart from that, the precision of the calculations could of course be improved, by utilising
Fraction
and/ordouble
everywhere, i.e. int
,tremoloEventsSize
,tremoloTime
,tremoloEventStep
; and cast toint
only at the very end. (Note that that ensures so thatt != 0
, since that would only happen as a result of rounding errors.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
Initially I had a problem in another branch and this branch just doesn't have this check which you've mentioned.
And this more than enough.
Thank you for your help and time, @cbjeukendrup
Closing this PR.