I'm reposting this as the old topic was lost. Some music playing functions were added to the latest AC to allow tighter integration with external music playing assets, in this case it's Midi Tool Kit I'm trying to integrate:
https://assetstore.unity.com/packages/tools/audio/midi-tool-kit-pro-115331 and the free version:
https://assetstore.unity.com/packages/tools/audio/midi-tool-kit-free-107994There is a list of API functions for this particular tool here:
http://paxstellar.fr/2018/06/05/use-midi-player-tool-kit-in-your-script/I'm not 100% certain how to send messages from an AC actionlist to this to change songs, play songs on scene load (in the scene load actionscript), etc.
I understand this isn't totally an AC issue, but this particular tool could be invaluable to people looking to use tiny midis for mobile adventure games to keep the file size down, as well as people looking to make retro adventure games with classic music. If it's possible to
Send messages to MTK from AC, it would be useful for theme changes, and with midi it would be less noticeable that an audio music file being interrupted midway.
Again, sorry this is slightly specific to this tool (hopefully it'll be the same as sending messages to any external music player script), but I'm not sure how to send messages to other assets with AC using their API. If I can get this working, I'll be able to add a wiki tutorial for midi music in AC games.
Comments
Were any new features added to AC in the last major update that would allow closer integration with external music systems such as MidiToolKit?
I'm working on script and it's going well! I just need to clean it up and I'll be ready to add to the wiki for seamless MTK integration. Is there a way of passing the track name instead of index through via the hook? At the moment, I'm using midiFilePlayer.MPTK_MidiIndex = trackID; which is great if both Midi TookKit and AC's list of music is in the exact same order, but if not, it would require manual reassembly. If i could pass the track name from AC, I could use the same clip name and midi file, and just use midiFilePlayer.MPTK_MidiName = trackName; . The other option would be allowing the reordering of music in AC, but that's necessarily ideal.
You can extract the track name with a given track ID with this function:
Thanks, that's great! I used this as I had an error with GetTrackName otherwise, maybe it could be done better than I have though:
private string GetTrackName(int trackID) { string returnTrack = ""; foreach (MusicStorage musicStorage in KickStarter.settingsManager.musicStorages) { if (musicStorage.ID == trackID) { returnTrack = musicStorage.audioClip.name; } } return returnTrack; }
Question about fadeTime, does this just pass the length of the fade in/fade out time for the track when the hook is accessed? In which case, I'm trying to think of how this could be mirrored in MidiToolKit, as I would imagine midiToolKit (or any other music tool accessing AC's music variables) would also need the volume information from the game, in which case that would need to be updated all the time. If it's passing a linear volume change length with fadeOut, it would need to also pass fadeType to any external music script. Just want to confirm this is how all these are used!
The fadeTime is the duration that the fade would occur normally, yes. How it's used is down to your script.
I think the best way for this would be to pass a relative volume change during the fade. AC isn't capable of crossfading music tracks is it, unless I'm mistake? If it is, it could be trickier to match playing two files simutaneous during a fade, but if it's serial (fade out one song, fade in second) either a volume change could be passed via script all the time, or simply during fade to save on performance. Does AC call anything to determine if it's fading that could be passed on?
It is, but it's your choice.
Crossfading is handled via an interim AudioSource component that's a child of the MusicEngine prefab. This is controlled by the attached MusicCrossfade component.