6.12.2: Music Room

In this forum we discuss the future of Ren'Py, both bug fixes and longer-term development. Pre-releases are announced and discussed here.
Post Reply
Message
Author
User avatar
PyTom
Ren'Py Creator
Posts: 16094
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

6.12.2: Music Room

#1 Post 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.)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
SleepKirby
Veteran
Posts: 255
Joined: Mon Aug 09, 2010 10:02 pm
Projects: Eastern Starlight Romance, Touhou Mecha
Organization: Dai-Sukima Dan
Location: California, USA
Contact:

Re: 6.12.2: Music Room

#2 Post 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!

HigurashiKira
Miko-Class Veteran
Posts: 832
Joined: Mon Nov 01, 2010 9:10 pm
Contact:

Re: 6.12.2: Music Room

#3 Post 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")
I have moved to a new account. Please contact me here from now on. T/Y~

User avatar
PyTom
Ren'Py Creator
Posts: 16094
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: 6.12.2: Music Room

#4 Post 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.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

yummy
Miko-Class Veteran
Posts: 733
Joined: Fri Jul 07, 2006 9:58 pm
Projects: Suna to Majo
Location: France
Contact:

Re: 6.12.2: Music Room

#5 Post 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.

User avatar
inahochama
Regular
Posts: 39
Joined: Tue Dec 15, 2009 12:38 am
Contact:

Re: 6.12.2: Music Room

#6 Post 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!

rdokoye
Newbie
Posts: 1
Joined: Wed May 08, 2013 8:06 am
Contact:

Re: 6.12.2: Music Room

#7 Post by rdokoye »

After putting it under some scrutiny, it appears that it works. Thanks for that.




_________________
Rdokoye's Blog

Post Reply

Who is online

Users browsing this forum: Google [Bot]