|
Post by thechrisalan on Jun 28, 2022 22:07:43 GMT
Hello!
I am working on a turn based game and have a different music loop play for each turn, each music clip and turn it builds in intensity. The way it is setup up is each turn simply steps through using "play next song" in the playlist I created. My question is - how do I now add some random variety into this? I would like to have a few variations of music loops for it to select from each turn that are different but same intensity, so that it continues the path of building intensity, however, each turn it picks from a small pool of random variations. I know there is "play random song", however that will not work considering it may play the wrong turns music, resulting in the wrong intensity playing.
Thanks in advance for the help!
|
|
|
Post by DarkTonic Dev on Jun 29, 2022 0:20:36 GMT
I think you'll need to use "Song Metadata" feature. www.dtdevtools.com/docs/masteraudio/PlaylistSettings.htm#PlaylistControllerSetupFind "Metadata" on the page and read about it. You'll need to write some code to select the random pool of songs matching your criteria of metadata, then play one. A couple example queries to grab matching songs. var playlist = PlaylistController.Instances[0].CurrentPlaylist; var favoriteSongs = playlist.MusicSettings.Select(f => f.metadataBoolValues.Any(x => x.PropertyName == "IsFavorite" && x.Value == true)); var songsByBrianOrChris = playlist.MusicSettings.Select(f => f.metadataStringValues.Any(x => x.PropertyName == "Author" && (x.Value == "Brian" || x.Value == "Chris")));
-Brian
|
|
|
Post by thechrisalan on Jun 29, 2022 21:38:35 GMT
This is excellent, thank you Brian!
I'm curious if you wouldn't mind sharing some sample code of how I would also play a specific item in the playlist with it's specific metadata criteria too? I might be needing to do both in different situations. Or in that case, would it be best to just use the song ID field and call it specifically? Or could this also be handled by the metadata?
|
|
|
Post by DarkTonic Dev on Jun 29, 2022 22:18:09 GMT
Sure, and it's confusing because I got part of the code wrong above. Let me fix:
var playlist = PlaylistController.Instances[0].CurrentPlaylist; var songsByBrianOrChris = playlist.MusicSettings.Where(f => f.metadataStringValues.Any(x => x.PropertyName == "Author" && (x.Value == "Brian" || x.Value == "Chris"))).ToList(); var chosenSong = songsByBrianOrChris.FirstOrDefault(); // do a random selection if you like. PlaylistController.Instances[0].TriggerPlaylistClip(chosenSong.songName);
|
|
|
Post by thechrisalan on Aug 10, 2022 22:28:38 GMT
So, I am using a single playlist with the synchronize clips function so that I can move through my clips in time/sync, would using this metadata code maintain that sync or is this more like a playlist change and it just crossfades between clips to the beginning of the next clip?
|
|
|
Post by DarkTonic Dev on Aug 11, 2022 5:44:50 GMT
It should crossfade to the same time in the new song with that transition mode.
|
|