missionpinball / mpf-gmc

Godot-based Media Controller for the MPF pinball framework
MIT License
11 stars 4 forks source link

MPF.Media.Sounds supporting looping of audiostreamrandomiser? #15

Closed DorusvdLinden closed 1 month ago

DorusvdLinden commented 1 month ago

Dear all,

I love the new setup, but i have one issue: In my previous iteration I was looping multiple sounds in attract mode randomly, to create a dynamic background.

Now in Godot, the individual wav files can loop, but the audiostreamrandomiser stops after 1 sound played.

Using loops: -1, 3 or true gives an error in the MPF.Media.Sounds code (GMCChannel.gd) in mpf-gmc/scripts/) Screenshot 2024-09-14 153948

Screenshot 2024-09-14 153751

code:

sound_player:
  mode_attract_started:
    SlowMusic:
      bus: music
      loops: 3

without the loops it runs fine. Could be my mistake. Kind regards Dorus

avanwinkle commented 1 month ago

Thanks for opening this issue! There were some challenges with getting loops to behave "MPF style" in GMC, and I set that work aside to finish out other features. I've been thinking on it and your notes here have given me an idea on how to implement loops in a better way, so I'll keep you updated with how it goes!

DorusvdLinden commented 1 month ago

Thank you @avanwinkle, for the update. Loops: 3 works now on AudioStreamRandomizer. Loops: -1 gives an error:

image

Not sure if AudioStreamRandomizer supports "self.stream.loop=true"

would it be an option to use the same approach as in _on_loop until overwritten by a state change?

PS: my machine configuration is on: https://github.com/DorusvdLinden/PortalPinball-V4.0

avanwinkle commented 1 month ago

That's a curious error, because AudioStreamRandomizer inherits from AudioStream, as do AudioStreamOggVorbis and AudioStreamMP3, but the randomizer does not inherit from either of those so it shouldn't be entering this code block if self.stream is a randomizer.

There's an argument to be made for always doing the manual looping instead of relying on the Ogg/MP3/Wav built-in method, but I'll investigate a little more first.

avanwinkle commented 1 month ago

Okay, my bad. I had a shorthand in the condition that was always returning true and trying to treat the resource as an Ogg/Wav. Fixed that and verified that AudioStreamRandomizer now can loop indefinitely.

DorusvdLinden commented 1 month ago

Great to hear. I will test it in the weekend. Thank you for the fast response. Ps: I really like the new setup.

DorusvdLinden commented 1 month ago

Thank you so much, the loop: -1 now also works. Great to see how fast this evolves.