[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] Moving the music module?



> I kind of like this. Actually, I think the whole sound system is a
> little weird. Consider - I want to play a sound, so I go:
> 
>        sound = pygame.mixer.get_channel()
>        sound.play()
> 
> I want to play music, so I go:
> 
>        pygame.music.play()
> 
> To my way of thinking, the two actions should be congruent. Maybe:
> 
>        music = pygame.mixer.get_music()
>        music.play()

when i first started on pygame this was how the music worked.
music = pygame.mixer.load_music('song.mp3')
music.play()

there's a few differences between the the mixer's music and sounds.
Many sounds can be played at the same time, each sound may even
be played multiple times simulataneously. Meanwhile there can only
be one music playing at a time.
Also, sound files are physically loaded into ram and played from ram.
music files are never really "loaded", they are streamed (or rendered)
as the music file plays along.

at one point i did have a separate music object type. it wouldn't be
hard to add one again. but it felt like it added a layer of management
to the music module that didn't offer any benefits. think of treating
the music module as the object you would get from some sort of get_music()
function. (import music is the get_music() function, heh)

with music objects
    music1 = pygame.music.load('song1.mp3')
    music1.play()
    pygame.time.delay(5000)
    music2 = pygame.music.load('song2.mp3')
    music2.play()
without music objects
    pygame.music.load('song1.mp3')
    pygame.music.play()
    pygame.time.delay(5000)
    pygame.music.load('song2.mp3')
    pygame.music.play()


i think moving music into the mixer module would make this method
even more obvious. music would work and act just like an object
(but it would really be a module in the music namespace). just think
of music as a special channel of mixer that streams music instead of
just playback.

anytime there is a new type of object that pygame offers, it comes
with a bit of 'management' that is needed. although it's not a big
deal to handle, things always seem cleaner when you don't even have
to worry about it.

hmm? i'm still thinking about it...


____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org