-
-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Queuing multiple musics with pygame.mixer.music.Queue
#3058
Comments
for the record, a full pythonic implementation would require the update method but the implementation i added in #3057 uses a bit of C to remove the need for it. |
Ok, so it's got all these features, cool, but what does this actually do for a game? What's the use case? Maybe it shouldn't be called a Queue, because this is not a generic data structure, this is a very specific object. And it seems weird to have remove() and indexing on a queue. But I don't understand the use case, so names are hard to come up with. Also this would need to support file like objects, so things shouldn't be called |
I ended up writing something very similar for my game. Specifically because I wanted the functionality of Sound objects but for music. I wanted the ability to preload each track and set per track volume levels or make "groups" of tracks for certain playback properties. There were a couple of other reasons I ended up writing it but I do agree that the current mixer.Music is very basic and could use some gussying up. I simply called mine a music manager but a 'playlist' or 'tracklist' would work for names too. |
It allows to handle and manage multiple musics at once, and most precisely the possibility to play musics like a queue. It can be used in a game to play a list of music.
I do agree with this name, this feature requires discussion about the actual features it comes up with. This is why every feedback is appreciated. Thanks for the feedback ❤️ @Starbuck5 . |
I had several potential use cases for my games, and ended up programming something similar myself on several occasions:
As for naming, I always looped the music functionality in the same object as the one that handled sound effects and called the whole thing a No matter what features you add or don't add, I would highly recommend making it subclassable and extensible like At least that's my two cents. I've been making games with pygame for about 5 years now and as a user that's what I would like to see, but all you pygame developers have other things like maintainability to worry about and I have little experience there. EDIT: Wait mixer.music streams audio from the file. That invalidates a significant portion of point 2. It would still be nice to have an API for loading my music filenames when I load my other assets. |
@pmp-p This is something you might want to answer. |
This is possible already with
The difference between music and sounds in pygame-ce is that music is streamed, so I don't see any performance gains from preloading here. And regardless, the current implementation doesn't stage the musics as Mix_Music anyways. EDIT: I now see your edit about music being streamed,
What do you mean? |
Volume and other playback properties aren't supported by this proposed API though. The only playback property supported seems to be loops. And the proposed API doesn't preload in any meaningful sense besides storing the filenames. |
Talked to bilhox on discord about this, here's what I think would be an interesting use case for a feature like this: "My game has multiple worlds / stages / levels whatever, and I want to compile some music for each to be ambient music for the player. I want an object that I can say "go" and it plays my music in a random order continuously, with configurable fade-in/fade-out and silent periods in between as not to jar players with sudden changes. Each time I switch levels I will transition to a new one of these objects." I think finding use cases here is a meaningful exercise, because the proposed API does not work for my given use case. |
🤦 I have been up and down the docs so many times and I never saw that. Thanks!
This is just a code architecture thing. Generally surfaces, sounds, text files, and any other assets are all preloaded at the beginning of game, with a nice splash screen and stuff. In my head music is an asset too, and it would make sense to process them at the beginning. For streamed music currently I can't do any of that because I generally have to load stuff right before I play it, so I generally just ignore them in my asset loading code. My OCD would really like an object to make and play with upon game load, instead of messing around with filenames later in the code, so I generally make one, just to store the filenames, so that all path processing is in one place. I've refactored my assets handling enough times (pyinstaller and pygbag, I'm looking at you!) where I'm a bit paranoid about this. Also I still tout cutscenes and boss fights where the music needs to change seamlessly and sometimes in rapid succession. Just having a function that makes the music one level more of scary, or adds another level of atmosphere, when the next stage starts would make developing that sort of stuff that much nicer. I could also see alternate soundtracks for stuff being an interesting use case. What if I have two variants on a level sountrack, just to keep things interesting? Picking a random index out of a Queue would be very useful here. |
@bilhox pygame.mixer.music is not decently useable on WASM(browser) because that part of SDL2 is hard realtime. Wasi runtimes don't have audio yet. As a result in pyodide there's poor support for audio or none at all (worker). In Pygbag pygame.mixer.music works fine but under the hood is re-implemented in javascript : it is already multichannel/multitracks because using browser audio threads and a track cache. So i'm +1 for handling multitrack music since feature is already available. Preloading is always better since it make smooth transitions and avoid I/O error at runtime. sidenote : i would discourage people from using .mp3 explicitely for that new feature and promote .ogg usage. pygame-ce on pyodide is not assisted to convert mp3 at pack/preload. |
Personally, I'm 50/50 on whether pygame should have this. Any game with multiple tracks will probably need to implement a music manager or system. But implementing it is a bit annoying with the basic However, it may be best to leave it to the user so they can write it to their needs, similar to implementing animations or the event loop. (Though, using a built-in class would be optional.) Pygame is like this for a lot of things, providing basics and not abstractions, which helps to avoid bloat. I advocate for the class name I'm going to propose another design/API for this class to address problems in extensibility and ease of use. Class outline:Goals: easy to use (intuitive, simple), extendable and customizable, can cover many use cases, fits with I omitted most of the reasons for this design, for conciseness.
Now, some features for automatically running through the playlist. Implemented by invoking a user-defined callback when the playing song ends. These features are optional to use.
Looks intuitive to me. Let me know if there are any issues or possible improvements with this design. |
Hello, Following what we said on discord, I analysed more precisely the situation and I think personally it's not the thing we're actually in need. This is why I came across a better idea, what's actually stopping us from having a That said, |
Hello,
I want to introduce a new feature called
pygame.mixer_music.Queue
, which is, as its name says about it, an object for handling several queued music at once compared to his friendpygame.mixer_music.queue
.What features it can propose for a pygame user ? :
Queue.play_next()
andQueue.play_previous()
, or even play a music at certain index.Below a code example of how it can work :
stubs preview by @damusss :
While this can be just a python implementation,
pygame.Channel
has already a similar system withpygame.Sound
, so I highly believe this can be pygame feature. @damusss tried to test and try to make an implementation in python, but keeping track of the music playing would involve having an update method, which doesn't follow how pygame.mixer works.I would like to hear the opinion of the steering council about this.
The text was updated successfully, but these errors were encountered: