[SOLVED] Synchronized + Progressive Music

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.
Post Reply
Message
Author
User avatar
Vogue
Regular
Posts: 65
Joined: Wed Sep 18, 2013 9:51 pm
Completed: SC2VN
Projects: Don't Forget Our eSports Dream
Contact:

[SOLVED] Synchronized + Progressive Music

#1 Post by Vogue »

Hey guys. I'm working on a scene where the music progressively builds as it goes on. We intend to have five different tracks and want the songs to transition in a way that doesn't start them over/makes sure that, when the switch happens, the next song is in time with the one prior. Poking around the documentation wiki leads me to believe I need to do two things: I need to create some extra sound channels, and I need to use the synchro_start function to make sure all five tracks get started at the right time. What I want to do is mute four of the channels and the unmute the right one/mute the previous one when the shift needs to be made. I haven't been able to get this working, so I'm looking for some advice from someone that might be able to put this together/explain if this is possible.

Thanks.
Last edited by Vogue on Mon May 25, 2015 5:11 pm, edited 1 time in total.

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Synchronized + Progressive Music

#2 Post by Onishion »

Hmm. Would it be possible to define volume controls for each music channel and then turn the volume on the unwanted ones down to zero? Ideally you'd probably also want to take the default music volume adjuster and change it to impact all five channels while they are active. I don't know enough about the system to tell you exactly how to do that though.

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Synchronized + Progressive Music

#3 Post by trooper6 »

I was planning on doing something similar for my game. Though, I'm not that far along yet so I haven't tested anything. What I was planning was what Onishion suggested. Creating multiple music channels, starting all of them at once but having all of the other channels' volumes down to 0 using renpy.music.set_volume(volume, delay=0, channel='music') and then playing with volumes to bring in the elements I want when I want them.

But really, I just plan on experimenting while reading the documentation...use trial and error and figure it out.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Synchronized + Progressive Music

#4 Post by Onishion »

Ok, yeah. The trick, I think, would be to design it in a way that it respects the player's volume settings as well, so that as you raise the volume of a channel from 0 to 100, that 100 is only 100% of whatever master volume level the player has defined in the settings. I guess it would just involve adding a function to dupe the volume controls to all channels, using the get and set volumes here?

User avatar
Vogue
Regular
Posts: 65
Joined: Wed Sep 18, 2013 9:51 pm
Completed: SC2VN
Projects: Don't Forget Our eSports Dream
Contact:

Re: Synchronized + Progressive Music

#5 Post by Vogue »

Heh, as I expected this seems kinda complicated. I'll give it a few tries but I'm really not much of a programmer. Just defining my new channels is something that's giving me trouble.

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Synchronized + Progressive Music

#6 Post by Onishion »

It doesn't seem that complicated, and actually looking at it, that step I was talking about might not even be necessary. I haven't messed with music stuff much so someone double check this for me, but I think this would work:

Code: Select all

$ renpy.music.register_channel("Track1", "music", True)
$ renpy.music.register_channel("Track2", "music", True)
$ renpy.music.register_channel("Track3", "music", True)
$ renpy.music.register_channel("Track4", "music", True)
$ renpy.music.register_channel("Track5", "music", True) #this defines all five audio tracks, and ties them to the "music" volume slider

$ renpy.music.set_volume(1, 0, channel="Track1") 
$ renpy.music.set_volume(0, 0, channel="Track2") 
$ renpy.music.set_volume(0, 0, channel="Track3") 
$ renpy.music.set_volume(0, 0, channel="Track4") 
$ renpy.music.set_volume(0, 0, channel="Track5") # This sets the Track 1 volume to full, but all the others to zero

play Track1 "yourfirstsong.ogg"
play Track2 "yoursecondsong.ogg"
play Track3 "yourthirdsong.ogg"
play Track4 "yourforthsong.ogg"
play Track5 "yourfifthsong.ogg" #This starts all the tracks playing, but since only Track 1 has volume, only it can be heard

. . .  #a bunch of game happens, later . . .

$  renpy.music.set_volume(1, 1, channel="Track2") # This causes Track two to fade in. The second "1" means that it will fade in over 1 second, you can adjust this if you like. 

$ renpy.music.set_volume(1, 1, channel="Track3") # This causes Track three to fade in.

$ renpy.music.set_volume(0, 1, channel="Track2") # This causes Track two to fade back out, if you want that. 
Am I right in thinking that would all work? The audio documentation is mostly here.
Last edited by Onishion on Mon May 25, 2015 4:44 pm, edited 2 times in total.

User avatar
Vogue
Regular
Posts: 65
Joined: Wed Sep 18, 2013 9:51 pm
Completed: SC2VN
Projects: Don't Forget Our eSports Dream
Contact:

Re: Synchronized + Progressive Music

#7 Post by Vogue »

After defining those channels with python: preceding it (I think I did that right?) I was able to launch my game, but when I try to start the scenario this is the result.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 40, in script
    play Track1 "sfx/bluepine.ogg"
  File "renpy/common/000statements.rpy", line 99, in execute_play_music
    if_changed=p.get("if_changed", False))
Exception: Audio channel u'Track1' is unknown.

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 40, in script
    play Track1 "sfx/bluepine.ogg"
  File "C:\Users\sean\Desktop\RENPY SDK\renpy\ast.py", line 1635, in execute
    self.call("execute")
  File "C:\Users\sean\Desktop\RENPY SDK\renpy\ast.py", line 1653, in call
    renpy.statements.call(method, parsed, *args, **kwargs)
  File "C:\Users\sean\Desktop\RENPY SDK\renpy\statements.py", line 144, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/000statements.rpy", line 99, in execute_play_music
    if_changed=p.get("if_changed", False))
  File "C:\Users\sean\Desktop\RENPY SDK\renpy\audio\music.py", line 83, in play
    c = get_channel(channel)
  File "C:\Users\sean\Desktop\RENPY SDK\renpy\audio\audio.py", line 758, in get_channel
    raise Exception("Audio channel %r is unknown." % name)
Exception: Audio channel u'Track1' is unknown.
I tried simply to play two songs at once using the Track1 and Track2 channels defined, with one of the channels muted.
Last edited by Vogue on Mon May 25, 2015 4:29 pm, edited 1 time in total.

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Synchronized + Progressive Music

#8 Post by Onishion »

Ah, my bad. As I said I hadn't actually messed with that stuff much. I think you have to put a "$" in front of the lines that start with "renpy," or put them in a python block. I tried that and it at least loaded fine, but since I didn't have actual music to put there I wasn't able to test whether it worked. I corrected the earlier example (I think).

User avatar
Vogue
Regular
Posts: 65
Joined: Wed Sep 18, 2013 9:51 pm
Completed: SC2VN
Projects: Don't Forget Our eSports Dream
Contact:

Re: Synchronized + Progressive Music

#9 Post by Vogue »

Onishion wrote:Ah, my bad. As I said I hadn't actually messed with that stuff much. I think you have to put a "$" in front of the lines that start with "renpy," or put them in a python block. I tried that and it at least loaded fine, but since I didn't have actual music to put there I wasn't able to test whether it worked. I corrected the earlier example (I think).
I think that the channels themselves are defined properly, but it's giving me trouble when I try to play music from them. This might be an issue with my options or something.

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Synchronized + Progressive Music

#10 Post by Onishion »

Hmm. It looks like Track 1 isn't getting defined properly. Maybe you need to put all that stuff into an init block? Like here?

User avatar
Vogue
Regular
Posts: 65
Joined: Wed Sep 18, 2013 9:51 pm
Completed: SC2VN
Projects: Don't Forget Our eSports Dream
Contact:

Re: Synchronized + Progressive Music

#11 Post by Vogue »

Onishion wrote:Hmm. It looks like Track 1 isn't getting defined properly. Maybe you need to put all that stuff into an init block? Like here?
That actually did work, I'm able to play the sound from those channels now. I'm still having an issue setting the volume though. Defining the volume outside of the scene apparently doesn't seem to do anything though, and trying to simple paste that within my script is giving me some errors because I don't think I've told renpy that the script's text that follows isn't a part of that python statement.

Edit: I was able to get this working! Thank you so much, it was actually insanely fun to chip away at a problem like this and solve it in the end. I couldn't have done it without your help. The key was to use the init python: to define the channel before the scenario begins, then use the set_volume function in the middle of the script indented once with a $ preceding it. Trial and error works! Lol.

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: [SOLVED] Synchronized + Progressive Music

#12 Post by Onishion »

Glad to hear it worked out, and learning why it worked should help with later projects. ;)

Post Reply

Who is online

Users browsing this forum: Google [Bot]