Skip to content
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

GMCChannel support for loops #16

Merged
merged 1 commit into from
Sep 15, 2024
Merged

GMCChannel support for loops #16

merged 1 commit into from
Sep 15, 2024

Conversation

avanwinkle
Copy link
Contributor

This PR introduces support for looping from MPF sound_player triggers and MPFSoundAsset resources. Manually tested with sound files, sound asset resources, and AudioStreamRandomizer resources.

Addresses issue #15

Summary

The Godot classes AudioStreamOGG and AudioStreamWAV support a native loop property which will endlessly loop the sound playback, while AudioStreamMPF supports a loop_mode property which loops playback in a variety of ways. Unfortunately:

  • these properties abstracted from the AudioStreamPlayer (or GMCChannel) which prevents any count of looping
  • AudioStreamRandomizer and other stream types do not have any native looping property

The Fix

This PR adds loop-management logic to GMCChannel to manually loop an audio stream by hooking into the finished signal and calling play() again. For situations where a specific number of loops are requested, metadata is attached to the stream to count the number of loops.

When the stream playback finishes, the channel will check the loop state and either re-play the stream or stop itself.

Note: For situations where the audio stream is a native Godot type that supports looping and the looping is infinite, the native looping property is set and the channel does not manually manage looping.

play it forever

@avanwinkle avanwinkle merged commit eeedb9b into main Sep 15, 2024
@avanwinkle avanwinkle deleted the sound-loops branch September 15, 2024 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant