Implement AudioStreamSynchronized::get_bar_beats()
, fix division by zero
#99327
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.
Fixes #92453, and tested using its MRP.
get_bar_beats()
was unimplemented onAudioStreamSynchronized
, so this implements it similarly to other methods likeget_bpm()
. It could also be implemented more similarly toget_beat_count()
, which gets the maximum beat count (not just the first), although it's a bit unclear what the intended behavior would be if there are different bar beats for each sub-stream.The underlying issue is that
get_bar_beats()
is used to calculate the end time of the current bar (inAudioStreamInteractive
), and without an implementation, it returns zero. This leads to a division by zero, resulting in NaN, which completely breaks timings. Thus, this PR also adds a guard which will check if bar beats is > 0 (if not, the transition will instead occur immediately), since this can probably occur with other stream types that still do not implementget_bar_beats()
.(As a side note, this division by zero guard may also need to be implemented in the new code introduced in #99188.)