Page 1 of 1

6.12.2: Music Room

Posted: Sat Jul 02, 2011 10:13 pm
by PyTom
I managed to get some work done on Ren'Py today, for the first time in over a week. Since I'm in no condition to code newtext, I put some work into a Music Room system. Since the result is immediately useful, I thought I'd post it here.

The idea is that Ren'Py will supply a series of actions that manipulate a playlist. It's then up to the creator to make a screen that takes advantage of those actions to become an actual music room. Here's the example code from the documentation.

Code: Select all

init python:
    
    # Step 1. Create a MusicRoom instance.
    mr = MusicRoom(fadeout=1.0)
    
    # Step 2. Add music files.
    mr.add("track1.ogg", always_unlocked=True)
    mr.add("track2.ogg")
    mr.add("track3.ogg")
    
    
# Step 3. Create the music room screen.
screen music_room:

    tag menu

    frame:
        has vbox
            
        # The buttons that play each track.
        textbutton "Track 1" action mr.Play("track1.ogg")
        textbutton "Track 2" action mr.Play("track2.ogg")
        textbutton "Track 3" action mr.Play("track3.ogg")
        
        null height 20
    
        # Buttons that let us advance tracks.
        textbutton "Next" action mr.Next()
        textbutton "Previous" action mr.Previous()
        
        null height 20
        
        # The button that lets the user exit the music room.
        textbutton "Main Menu" action ShowMenu("main_menu")
        
    # Start the music playing on entry to the music room.
    on "replace" action mr.Play()
    
    # Restore the main menu music upon leaving.
    on "replaced" action Play("music", "track1.ogg")
Of course, this being screens-based, this could just as easily be an imagemap or something like that.

Rather than try to write thus up further, I've posted the documentation online:

http://www.renpy.org/dev-doc/html/rooms.html#music-room

If someone could proofread that, I'd appreciate it - it's hard to focus on proofreading.

You can take advantage of this today by grabbing the code from:

http://bazaar.launchpad.net/~renpytom/r ... icroom.rpy

and dropping it into your game. (You should also change the init -1135 in that file to something smaller, like init -100.)

Re: 6.12.2: Music Room

Posted: Sun Jul 03, 2011 1:30 am
by SleepKirby
I read over the documentation and didn't find any mistakes, myself.

Also took a look at the .rpy - ooh, I didn't know about renpy.seen_audio. The way I implemented music unlocking was to make a custom play() function which unlocks the song upon playing, and then make the entire game script use this play() function instead of "play music"... though, I had other uses for this function, too. (Such as being able to refer to Python objects instead of raw filenames, and being able to play an Intro section followed by a Loop section of the song.)

Anyway, good to see a music room framework!

Re: 6.12.2: Music Room

Posted: Sun Jul 03, 2011 5:21 pm
by HigurashiKira
Only problem I noticed:

Code: Select all

textbutton "Music Room" action ShowMenu("music_room")
Should be

Code: Select all

textbutton _("Music Room") action ShowMenu("music_room")

Re: 6.12.2: Music Room

Posted: Sun Jul 03, 2011 5:54 pm
by PyTom
While you're right, that won't be necessary once I finish the translation system. I was just looking ahead when writing the documentation.

Good catch.

Re: 6.12.2: Music Room

Posted: Wed Jul 06, 2011 2:33 pm
by yummy
I assume it's possible to customize and create themed music rooms?

Like assigning a themed BG with one song, or create custom playlists, animations, videos...
Not that I would make use of them by now, but it would be interesting to know if it's possible.

Re: 6.12.2: Music Room

Posted: Tue Sep 20, 2011 12:03 am
by inahochama
Thank you very much for this code! Now I just need to combine this with the other music room code and voila, ipod theme here we go!

Re: 6.12.2: Music Room

Posted: Wed May 08, 2013 8:06 am
by rdokoye
After putting it under some scrutiny, it appears that it works. Thanks for that.




_________________
Rdokoye's Blog