You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm working on creating a new feature which i'm calling "Sound Groups".
The idea being that you can "group" individual sound items together into a group. You can then play that group in order, or have it randomly pick an item from the group to play.
The random setting will play though all sounds in the group before resetting.
If random is set to false, it will play the sounds in the order they were added to the group.
A use-case for this is bonus items in a platform-style game. You have a set of sounds for when a play collects a bonus item, and you randomly play one each time an item is collected, rather then a single sound.
Any case where you'd like a bit of variation for an event sound, this could be useful.
What do you think? Comments, suggestions?
Thanks
jos
ps. i've used this idea already in a previous version of the SM library, but the code is, well, not great. I'd fix it up and include it if there is interest here. I'll probably do it anyway, but would be great to get some feedback, so it could be useful for a wider audience.
i like the idea, but seems like a playlist for me.
.addToPlaylist( $playlistName:String, $soundName:String ); //check if the playlist already exists, if not, create a new one
.removeFromPlaylist( $playlistName:String, $soundName:String );
.removePlaylist( $playlistName:String);
.clearPlaylist( $playlistName:String);
.startPlaylist( $playlistName:String, $volume:Number, $random:Boolean = true );
That seems good to me - better naming again! This covers the use-cases i have, and adds some useful methods i hadn't though off (remove the playlist itself, implicit playlist creation, clear playlist). I'm so-so on implicit stuff ie. the addToPlaylist creating a new playlist if it doesn't already exist - mostly because the programmer could get the spelling of the name of the playlist wrong, and not understand why her playlist doesn't have a specific bit of audio in it. So, i'd keep a .createPlaylist( $playlistName:String ) method. Possibly with an "$soundsArray:Array" param, too. The .addToPlaylist() method would throw an error if the $playlistName param does not already exist. All of them would throw a RTE in that case, actually. I know its an extra step, but i'm big on explicit rather then implicit ;) Comes from writing Python i think, and also hard lessons learned around hard to track bugs.
Hurm. In doing the implementation, i'm not sure of how .startPlaylist might work. I can see that having a playlist which would just play one song after the next, auto-magically (listening to Sound.ON_COMPLETE or whatever) would be a useful method, this isn't what i was thinking of.
I usually just manually call a .playNext( $random:Boolean ) method on the playlist.
I can implement a startPlaylist, which would work as a "real" playlist might, but i'm not going to tackle that one right away.
Maybe i even need to simplify the playlist even more. It is simply a way of holding a list of sounds. The playing of the sound is what the SoundManager does.
So, the API would then change to something like (NOTE these are not static methods, i'm just writing them that way so you know what Class they are attached to):
PlaylistItem is a new class for managing a Playlist.
PlaylistItem( $name:String ); // Constructor.
PlaylistItem.addSound( $name:String, $multiple:Boolean ); // $multiple allows for more then 1 instance of the same sound in a playlist
PlaylistItem.removeSound( $name:String, $all:Boolean ); // $all removes all instances of a sound from a playlist.
PlaylistItem.clear();
PlaylistItem.getNext( $random:Boolean = false ):String;
We could then also create a SoundManager.startPlaylist( $playlistName:String ) method, giving you the ability to play a playlist right through. But i'm not going to do that for this first cut. I
ok, i understand what you're saying. i think you're right.
i saw that you are shifting and splicing the playlist items i don't know if that is the best way of doing it...
what if i want to play that playlist again??? and in this API, how do you actually play the sound of a playlist???.
I only shift (and splice) item's out of the _availableSoundsList array. This array is just used to track which tracks have been played so far. Once the _availableSoundsList is empty, the _soundsList is cloned back into it.
You play a sound using the SoundManager.playSound( SoundManager.getSoundFromPlaylist( $playlistName) );
I agree that having something like SoundManager.playPlaylist( $playlistName ), but i'm not ready to set that up now. It would require listening for the SoundComplete event, and getting the next sound from the playlist automatically.
My use-case for the Playlist is more in having a number of sounds representing one "event" (like in my original post). I see the advantage of having it work like a "real" playlist, i just don't have the time right now to code that part up.
Also having "nextSound()" and "previousSound()" methods would make sense when using it in a more traditional manner.
So, yes, these are probably good methods to have, but i can't implement them right now. But i hope that the code as is will allow for this kind of eventual use.
Looking at the SoundManager class, i'm wondering if adding all these "helper" methods to SM is too much. Should we just pass the PlaylistItem back to the user/programmer, then they use the methods on the PI directly?
ahhh sorry about that i didn't notice that _availableSoundsList was a copy of _soundsList XD
why not create a method that play the next sound of a playlist????, forget (about the real playlist functionality)
SoundManager.playNextSound( $playlistName:String, $random:Boolean ) {
//by now this method only hides SoundManager.playSound( SoundManager.getSoundFromPlaylist( $playlistName) );
SoundManager.playSound( SoundManager.getSoundFromPlaylist( $playlistName, $random) );
}
Activity
rauluranga commentedon May 13, 2011
i like the idea, but seems like a playlist for me.
.addToPlaylist( $playlistName:String, $soundName:String ); //check if the playlist already exists, if not, create a new one
.removeFromPlaylist( $playlistName:String, $soundName:String );
.removePlaylist( $playlistName:String);
.clearPlaylist( $playlistName:String);
.startPlaylist( $playlistName:String, $volume:Number, $random:Boolean = true );
what do you think??
hyakugei commentedon May 13, 2011
That seems good to me - better naming again! This covers the use-cases i have, and adds some useful methods i hadn't though off (remove the playlist itself, implicit playlist creation, clear playlist). I'm so-so on implicit stuff ie. the addToPlaylist creating a new playlist if it doesn't already exist - mostly because the programmer could get the spelling of the name of the playlist wrong, and not understand why her playlist doesn't have a specific bit of audio in it. So, i'd keep a .createPlaylist( $playlistName:String ) method. Possibly with an "$soundsArray:Array" param, too. The .addToPlaylist() method would throw an error if the $playlistName param does not already exist. All of them would throw a RTE in that case, actually. I know its an extra step, but i'm big on explicit rather then implicit ;) Comes from writing Python i think, and also hard lessons learned around hard to track bugs.
hyakugei commentedon May 14, 2011
Hurm. In doing the implementation, i'm not sure of how .startPlaylist might work. I can see that having a playlist which would just play one song after the next, auto-magically (listening to Sound.ON_COMPLETE or whatever) would be a useful method, this isn't what i was thinking of.
I usually just manually call a .playNext( $random:Boolean ) method on the playlist.
I can implement a startPlaylist, which would work as a "real" playlist might, but i'm not going to tackle that one right away.
Maybe i even need to simplify the playlist even more. It is simply a way of holding a list of sounds. The playing of the sound is what the SoundManager does.
So, the API would then change to something like (NOTE these are not static methods, i'm just writing them that way so you know what Class they are attached to):
SoundManager.createPlaylist( $playlistName:String);
SoundManager.removePlaylist( $playlistName:String );
SoundManager.addSoundToPlaylist( $playlistName:String, $soundName:String );
SoundManager.removeSoundFromPlaylist( $playlistName:String, $soundName:String );
SoundManager.clearPlaylist( $playlistName:String );
SoundManager.getNextSoundInPlaylist( $playlistName:String, $random:Boolean ):String
PlaylistItem is a new class for managing a Playlist.
PlaylistItem( $name:String ); // Constructor.
PlaylistItem.addSound( $name:String, $multiple:Boolean ); // $multiple allows for more then 1 instance of the same sound in a playlist
PlaylistItem.removeSound( $name:String, $all:Boolean ); // $all removes all instances of a sound from a playlist.
PlaylistItem.clear();
PlaylistItem.getNext( $random:Boolean = false ):String;
We could then also create a SoundManager.startPlaylist( $playlistName:String ) method, giving you the ability to play a playlist right through. But i'm not going to do that for this first cut. I
rauluranga commentedon May 16, 2011
ok, i understand what you're saying. i think you're right.
i saw that you are shifting and splicing the playlist items i don't know if that is the best way of doing it...
what if i want to play that playlist again??? and in this API, how do you actually play the sound of a playlist???.
cheers.
hyakugei commentedon May 16, 2011
I only shift (and splice) item's out of the _availableSoundsList array. This array is just used to track which tracks have been played so far. Once the _availableSoundsList is empty, the _soundsList is cloned back into it.
You play a sound using the SoundManager.playSound( SoundManager.getSoundFromPlaylist( $playlistName) );
I agree that having something like SoundManager.playPlaylist( $playlistName ), but i'm not ready to set that up now. It would require listening for the SoundComplete event, and getting the next sound from the playlist automatically.
My use-case for the Playlist is more in having a number of sounds representing one "event" (like in my original post). I see the advantage of having it work like a "real" playlist, i just don't have the time right now to code that part up.
Also having "nextSound()" and "previousSound()" methods would make sense when using it in a more traditional manner.
So, perhaps the API should be something like:
PlaylistItem.nextSound():String
PlaylistItem.prevSound():String
PlaylistItem.randomSound():String
(all these passed though to the SoundManager in some way)
However, there are more questions regarding how those methods interact with each other. Also might have to deal with the movement of Sound order:
PlaylistItem.moveSound( $soundName:String, $position:int )
So, yes, these are probably good methods to have, but i can't implement them right now. But i hope that the code as is will allow for this kind of eventual use.
hyakugei commentedon May 16, 2011
Looking at the SoundManager class, i'm wondering if adding all these "helper" methods to SM is too much. Should we just pass the PlaylistItem back to the user/programmer, then they use the methods on the PI directly?
ie:
SoundManager.createPlaylist( $name ):PlaylistItem (??)
SoundManager.getPlaylist( $name ):PlaylistItem
SoundManager.removePlaylist( $name ):void
SoundManager.addPlaylist( $playlist:PlaylistItem )
Something like that?
rauluranga commentedon May 16, 2011
ahhh sorry about that i didn't notice that _availableSoundsList was a copy of _soundsList XD
why not create a method that play the next sound of a playlist????, forget (about the real playlist functionality)
SoundManager.playNextSound( $playlistName:String, $random:Boolean ) {
//by now this method only hides SoundManager.playSound( SoundManager.getSoundFromPlaylist( $playlistName) );
SoundManager.playSound( SoundManager.getSoundFromPlaylist( $playlistName, $random) );
}
i think PlaylistItem should be hidden by now. =)