UPDATE 11/28 - Version 0.71 released, and should fix many of the problems reported here. Alas, aside from this simple fix release, I likely won't be investing more time in it in the short term. Maybe if I'm egged on. Lol!
UPDATE 9/30 - Version 0.7 is out. This version adds the playlist control commands and fixes some bugs. I hope the "no title music" bug is squashed in this version. Let me have your feed back! Download link at the end of the post is still the one to go to.
Enhanced Music Control
--------
Enhanced Music Control is an OBSE plugin that enhances Oblivion's music playback and provides script commands to further extend manipulation functionality to scripters. Its still a work in progress, but the progress has come far enough along that I'm now ready to get input on it.
This release adds commands for manipulating playlists, allowing you to build your own and replace the default music. Create new music for your mod's world, and swap out the Explore music with your's. Got a maddening boss? Swap the battle music with your boss's theme. Well, you can do that now in this release. Take a look at the Commands List in the download for the list of available commands and their usage.
This release requires Oblivion 1.2.0416 and OBSE version 15, simply because its the version I was working with. I've not tested it with other OBSE versions, but give it a try if you desire.
--------
What It Does
--------
What it does passively:
EMC effectivly removes control of Oblivion's music from the game's own code and places it solely in the hands of the plugin. None of the game's functions are used to play the music. A DirectShow powered player within the plugin renders the music in it's place. This gives the plugin absolute control of how the music is rendered and gives the capability of enhanced effects such as fading between tracks and resuming a previous track from earlier.
From a gameplay stand point, some of the first things you'll notice is that the previous track will resume after a battle is concluded. This prevents short Mud Crab beatdowns from interupting the regular exploration music. This is great if you have enjoyable custom music and get aggrevated that it gets cut off by battles before it gets to the good part. You'll be able to listen to the entire track all the way through to the end even if you continue to run into minotaurs and timber wolves over and over. This was the main reason I wrote the plugin. Kept stopping my lovely Eternal Sonata music...
Further, short music changes will result in a resume as well. So, if you pop into an Inn (and the music changes as a result) then decide you don't need to do anything there and immediately exit, if it was within 10 seconds, the previous track will resume instead of a new one being selected. It also does it with battle music too, so if you kill one guard and exit battle, then get spotted by some more, the battle music will start back up where it left. Its really cool!
I'm unsure if this was an issue in vanilla Oblivion, but each song in each music type's playlist will play once before you'll hear a song again, and the playlist is automatically reshuffled after each full playthough. You're guaranteed not to hear the same song twice in a row or too quickly in succession (unless, of course, your playlist only has one or two song in it). The more music you have, the better it all works.
Also, tracks will appropriately fade gently in and out instead of a sudden hard change. I find this more pleasing to the ears and disturbs the atmosphere less.
The music control system was designed to try and mimic Oblivion's as closely as possible. You'll still find some things are a little different. Like the title music plays through until you're in game. Not by design, of course, and I'll try and find a way to fix it soon as I can figure out where to place a sensor for the load screen.
What it does for modders:
For modders, it will allow you to control whats being played. Let the player explore your mod's world with it's own custom soundtrack thats completely seperate from Oblivion's by creating your own playlist and substituting your's for Oblivion's where appropriate.
Reliable GetMusicType commands. OBSE's GetCellMusicType command does not allways return the music that SHOULD be playing for a particular location or situation. I found that in IC's Marketplace district, this command incorrectly reports the musictype as Default (Explore) when it clearly should be Public. While now I realize that it is doing exactly what its supposed to do, it didn't help me any. Now, I'll provide commands that accurately let you know exactly the type of music that is being played, where ever the player is or what ever the player's state.
What it will do for modders:
In later releases, there will be an override mode that will allow a plugin to take ultimate control over the music. Tell it to play Battle music even though the game wants to play Dungeon music. Stuff like that. I will attempt to create a compatibility framework so that more than one plugin can perform the override if they are aware of one another.
Cool things I might do with it in the future:
I was thinking a heartbeat effect would be cool. When the player's health gets low, a heartbeat will fade in and the music will fade out as the player gets closer to death. Would definately add some amount of urgency to the game.
A script command that would affect playback speed would also be pretty cool to mess with, seeing as DShow has the ability. Slow down and speed up the music to screw with the player's mind. Perhaps a plugin to make the Shivering Isles' dungeons a little more insane? Or how about an inebriation mod where the music starts speeding up and slowing down irradically? Combine this with The J's OblivionEAX plugin and you can add a powerful echo to the sounds all around you. Ha! That would be awesome!
I was thinking of providing the ability to support multiple Special music tracks. For instance, you could have more than one MP3 for the title music allowing it to play from one randomly. Add more musical variety to the sight of your lifeless body flying backwards after taking that final hit from a Clannfear! Play any one of the many, many different Final Fantasy victory themes (not to mention OverClocked Remixes therein) when you level up! Imagine the possibilities!
Support for more than just MP3s. I don't know how this will work as I don't have any experience in DirectShow graph building. If DirectShow's RenderFile() function builds a poor graph, who knows what will end up happening. Technically, this is supported allready, but not officially. You can change the playlists to select non-MP3 files and it'll add them, but I have no idea what will happen when it tries to play them. Until I get a chance to play around with other music types and make sure they work, I'm not saying its offically supported.
--------
Known Issues
--------
One of Oblivion's volume variables keeps changing, fading out, then back to full blast. It is not stable for use. Anything that relies on this variable (like other OBSE plugins) will likely have a fit.
The music player does not pause when a movie, such as the Opening Movie after starting a new game, plays. This should be no sweat to fix. Just need to find the point in code where BINKs are started and stopped. Okay, maybe it is a little harder than I say. Anyone have any ideas that will get me along faster?
The Success music does not stop playing until its played through totally once. I would like it to stop playing as soon as the levelup menu is closed, instead, but I haven't figured out how to do it yet.
One time as I was playing, I got killed and the Death music played, then went back to the Combat music when it finished (it was supposed to stay silent until it reloads). I don't know the particular circumstances that caused it to go back to battle music, but I'll hopefully find out sooner or later. Its a rare problem, as far as I can tell and haven't been able to reproduce it yet.
Any mod that relies on the StreamMusic command won't function correctly yet. I haven't put in the hooks to handle this command yet, so it won't play the music. Any mods that rely on this command will fail to play their custom music.
--------
Known Non-Issues
--------
When you save a game, the current music type is saved with it. If you die, no music will play unless you're loading a save game that has that music data saved into the save game, or your save requires a loadscreen to complete. So, when you first use this plugin, you might notice that after you die, no music will play even after loading a save game. In order to fix this, just make a save and load from it when you die instead. Similarly, when you load a new game from the title screen that hasn't been saved while this plugin was active, the Title Music will continue playing until the loadscreen is dismissed. (Actually, this might be resolved now. I haven't gone and confirmed it yet though.)
--------
Version History
--------
0.5 - Initial Release0.70 - Commands for Playlist Control were implimented. Setting bMusicEnabled to 0 now mutes music (but it is still doing it's work) Master volume now properly affects the music volume. Fixed some assembly errors. Luckily, they didn't cause problems. Added a timer to the battle music. This should reduce (but may not elliminate) issues where low confidence animals, like deer, engage in combat mode, then flee immediately afterwards. Second, if the battle music plays more than 45 seconds, the previous track will not resume. A new one will be selected instead. Added useful debug text for the log file. Title music filename should now be lifted from the INI file. Fixed problems regarding my poor handling of COM objects. This will probably fix the 'no title music' problems people have been reporting.0.71 - Fixes the problem where the Explore playlist was not randomizing. Fixes the problem where one file is always missing from the playlists. Fixes a problem where directories and non-files could be added to a playlist. This would not actually cause a noticable problem, but it could result in the creation of an empty playlist, which would be a problem.0.72 - Fixes a problem where non-files could be added to a playlist if not using wildcards. Should now be next to impossible to create empty playlists. Added ability to specify more than one path to build a playlist. Added ability to modify existing playlists. This new ability does not apply to the default Oblivion playlists. Modifications can only be done to inactive playlists (IE: ones not associated with a music type). New Command: emcRecreatePlaylist; Similar to emcCreatePlaylist, except it operates on existing playlists. New Command: emcAddPathToPlaylist; Adds a new path to a playlist and then rebuilds that playlist. New Command: emcIsPlaylistActive; Determines if a playlist is currently active. If it is active, it can not be modified. Added ability to disable/enable the battle music. This does not cause a silence during battles. It just does not allow the player to switch to the battle playlist. Care should be given when using these commands; If your mod did not enable the override, you should NOT disable it. Doing so may interupt the program flow of another mod. New Command: emcEnableBattleOverride; Enables the override, preventing the music type Battle from occuring. New Command: emcDisableBattleOverride; Disables the override, allowing the battle music to be played once more. New Command: emcIsBattleOverridden; Indicates if the Battle Override is active. Gave the command emcChangePlaylist a new optional Queue Mode. If you use this command to swap a playlist that currently has a track playing, instead of interupting the current track, you can tell it to wait until its played through fully or stopped due to a music state change before making the swap. For more details, check out the commands list. Command emcRestoreDefaultPlaylist no longer forces a music change when restoring a specific playlist to default, unless the playlists are actually changed. The music will allways be restarted when passing -1 as a parameter, however. Added command (emcPrintAvailablePlaylists) to print all available playlists to the console. This should assist in debugging mods based off of EMC. Added command (emcPrintActivePlaylists) to print which playlists are associated with which MusicTypes. This should assist in debugging mods based off of EMC.
--------
Credits
--------
Credits to the following:
Scanti - His SoundCommands plugin was used as a base for this one. While only a small amount of code from his plugin is used in mine, it provided me with the orientation I needed to get started. He also provided me with some help when I asked. Thanks alot!
Kumar Prabhu - The DS Player sample application from CodeProject gave me my orientation into DirectShow. Hope my implimentation is allright.
Peter Chen - For providing CPath for general non-profit use. I've allways hated paths. Resolving absolute paths from relative ones. Using this class, I felt like I was cheating.
--------
Final
--------
This OBSE plugin is not only a modder's resource, but also a general enhancment to the music. That means anyone can download and install it and reap benefits from it without having to get a mod to go with it. If you've allways been a bit dissatisfied with the way vanilla Oblivion handles music, you now have a choice. Do you dislike sudden music changes and your relaxing music getting interupted everytime you walk past a rat? If so, give this OBSE plugin a shot!
--------
Now then! You no doubt want some links!
http://www.tesnexus.com/downloads/file.php?id=19772
http://planetelderscrolls.gamespy.com/View.php?view=OblivionMods.Detail&id=5141
If you try it out, please let me know of any issues you have, especially those not covered in the Known Issues section above. Also, have any suggestions or comments, well, thats what the thread is for. Lay them on me! There could allways have been something I missed, some really cool thing that I just didn't think of that it should do.