Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
init python:
renpy.music.register_channel("music1", mixer="music", loop=False, stop_on_mute=True, tight=True, file_prefix='', file_suffix='', buffer_queue=True)
sounds = ["audio/audio{}.wav".format(i) for i in range(1, 3)]
def m1_callback():
renpy.music.play(renpy.random.choice(sounds), channel="music1", fadein=10)
renpy.music.set_queue_empty_callback(m1_callback)
label start:
"Just sit here and listen to the sounds"
return
However the code below works correctly, that is, the random tracks fadeout for 10 seconds in succession (starting at full volume). The only change is "fadeout=10".
init python:
renpy.music.register_channel("music1", mixer="music", loop=False, stop_on_mute=True, tight=True, file_prefix='', file_suffix='', buffer_queue=True)
sounds = ["audio/audio{}.wav".format(i) for i in range(1, 3)]
def m1_callback():
renpy.music.play(renpy.random.choice(sounds), channel="music1", fadeout=10)
renpy.music.set_queue_empty_callback(m1_callback)
label start:
"Just sit here and listen to the sounds"
return
This sets a callback that is called when the queue is empty. This callback is called when the queue first becomes empty, and at least once per interaction while the queue is empty.
The callback is called with no parameters. It can queue sounds by calling renpy.music.queue with the appropriate arguments. Please note that the callback may be called while a sound is playing, as long as a queue slot is empty.
In your first example you immideately start playing a single track (with fadein) so queue becomes empty instantly and empty queue callback is called again.
In your second example currently playing track is set to stop (with fadeout) and a new track is placed in queue. When fadeout finishes, new track starts playing, queue becomes empty and callback is called, causing fadeout etc.
Ocelot wrote: ↑Mon Apr 15, 2024 2:01 pm
In your first example you immideately start playing a single track (with fadein) so queue becomes empty instantly and empty queue callback is called again.
In your second example currently playing track is set to stop (with fadeout) and a new track is placed in queue. When fadeout finishes, new track starts playing, queue becomes empty and callback is called, causing fadeout etc.
Thanks for your invaluable insight!
How do I manage to smoothly handle fading in a track, playing it for several seconds, fading it out, and then repeating this process again and again? I'm at a loss.
Ocelot wrote: ↑Tue Apr 16, 2024 2:04 pm
YOu almost got it, but instead of playing sound in callback, queue it to play right after current sound instead.
Thanks for your answer. Accordingly, my new approach is pasted below. Now music fades in, new music is queued, but the music never fades out (it plays for the configured time and then the music is quickly interrupted instead of fading out, just before playing the next file in the queue).
Ocelot wrote: ↑Sun Apr 21, 2024 7:10 am
YOu don't set any fadeout on any tracks aside from the first one.
Initially, I anticipated finding a 'fadeout' parameter within renpy.music.queue. However, upon reviewing the documentation, I discovered that such a parameter was not present. https://www.renpy.org/doc/html/audio.ht ... usic.queue
There is only 'fadein' there. Did I understand your point accurately?