Home » MODDING HQ 1.13 » v1.13 Feature Requests » Externalizing/freeing music
Externalizing/freeing music[message #346545]
|
Mon, 08 August 2016 11:36
|
|
Taro_M |
|
Messages:292
Registered:November 2008 |
|
|
I'm trying to figure out how to change the music system, so all of the events (tension, battle, nothing etc.) have their own folders and the music system uses any .ogg or .wav files you place in those folders.
Right now I'm manually editing the "Music Control.cpp" and "Music Control.h" in order to add my own music, but I need to recompile the exe every time I do so.
Yeah, yeah you can just play the music using winamp, but I like when music fits the situation and game changes the music for me.
Currently in the "Music Control.cpp" there is a list "szMusicList" with contains the list of all of the music in the game. Later in the code for playing the music this list is called.
This is the battle music bit:
else if ( MusicMode == MUSIC_TACTICAL_BATTLE )
{
sprintf( zFileName, "%s\\BATTLE_%d.ogg", szMusicList[15], uiNum);
if ( !FileExists( zFileName ) )
sprintf( zFileName, "%s\\BATTLE_%d.wav", szMusicList[15], uiNum );
}
From this the bit:
sprintf( zFileName, "%s\\BATTLE_%d.ogg", szMusicList[15], uiNum);
is what I'm interested in (the other one is for .wav files).
At lines 594, 708 and 769 there is also this bit:
bBattleModeSong = (INT8) (BATTLE_A_MUSIC + Random(2));
With is basically a randomization of the battle music if I understand this correctly. Notice the hardcoded "2" with means there are only 3 battle themes allowed.
So, I think that if we would have something like this:
sprintf( zFileName, "%s\\Battle_music\\*.ogg", uiNum);
and:
bBattleModeSong = (INT8) (BATTLE_A_MUSIC + Random(battle_music_count - 1));
battle_music_count = function counting of .ogg files in the new Battle_music folder.
I just want a simple to use system, similar to TES Oblivion and Fallout 3, where you could just place music files in the correct folders and game played them all as it should.
Report message to a moderator
|
Master Sergeant
|
|
|
Re: Externalizing/freeing music[message #346550 is a reply to message #346545]
|
Mon, 08 August 2016 13:08
|
|
Flugente |
|
Messages:3509
Registered:April 2009 Location: Germany |
|
|
Assuming you'd number all your music files - so BATTLE_1.ogg, BATTLE_2.ogg, BATTLE_234.ogg etc. - you could use this very simple (but also very dumb) solution:
...
BOOLEAN wefoundmusictoplay = FALSE;
while ( !wefoundmusictoplay )
{
UINT32 randomnumber = Random( 1000 );
sprintf( zFileName, "%s\\BATTLE_%d.ogg", szMusicList[15], randomnumber );
if ( !FileExists( zFileName ) )
sprintf( zFileName, "%s\\BATTLE_%d.wav", szMusicList[15], randomnumber );
if ( FileExists( zFileName ) )
{
wefoundmusictoplay = TRUE;
// do music stuff here..
}
}
...
It's not smart and won't work on different names, but is a first step. Keep in mind that a few of the music numbers are likely stored in INT8, so you might need to change that.
[Updated on: Mon, 08 August 2016 13:11]
I know now that it could never work between us, as much as we wanted to, it could never be! Not because you're a rabbit, but because you're black.
If you want, you can donate to me. This will not affect how and what I code, and I will not code specific features in return. I will be thankful though.Report message to a moderator
|
|
|
|
|
|
|
|
Re: Externalizing/freeing music[message #346613 is a reply to message #346552]
|
Fri, 12 August 2016 16:50
|
|
Julix |
|
Messages:105
Registered:June 2010 Location: Canada |
|
|
DepressivesBrot wrote on Mon, 08 August 2016 14:42What you'll want to do for a fully drop'n'play system is to generate file lists from your folders in some way (SO has some ideas as usual) and then pick a random element to play.
If you randomized which file the game is looking for (like Taro suggested) why would you still need to have it look for the files in the folder? -- Although it would have the advantage of perhaps allowing for any kind of name, as long as it's in the appropriate folder... that would make it really easy to change... If you want extra music, throw those files into this folder. Done. Very neat.
Taro_M wrote on Mon, 08 August 2016 18:49
Also, this may require an INI setting with would have something like new_music_system with could be set to true or false. On false music is played as it was, on new the folder system would be used.
If it works well, not throwing additional music files in that folder would mean nothing changes, right? Why the support for the old system? Is it for use with Mods that changed the music? - Or would it be a precaution to keep ini setting in case it doesn't work well?
[Updated on: Fri, 12 August 2016 16:57] Report message to a moderator
|
Sergeant
|
|
|
|
|
Re: Externalizing/freeing music[message #346617 is a reply to message #346612]
|
Fri, 12 August 2016 19:50
|
|
Flugente |
|
Messages:3509
Registered:April 2009 Location: Germany |
|
|
Taro_M wrote on Fri, 12 August 2016 12:31It seems that after patch with allows ogg files I cannot add my music the way I did before.
What patch? What I posted was a code bit, in no way finished code.
Taro_M wrote on Fri, 12 August 2016 12:31
I also tried this:
sprintf( zFileName, "%s\\BATTLE\\BATTLE_%d.wav" );
but music was playing as in vanilla, with was weird as I was sure this would at least break the music system for combat.
That line needs more arguments. Of course it won't work this way. http://www.tutorialspoint.com/c_standard_library/c_function_sprintf.htm
I know now that it could never work between us, as much as we wanted to, it could never be! Not because you're a rabbit, but because you're black.
If you want, you can donate to me. This will not affect how and what I code, and I will not code specific features in return. I will be thankful though.Report message to a moderator
|
|
|
|
Re: Externalizing/freeing music[message #346630 is a reply to message #346617]
|
Sat, 13 August 2016 11:06
|
|
Taro_M |
|
Messages:292
Registered:November 2008 |
|
|
At some point the musiccontrol.hpp has been changed.
I had older version saved (it had my changes), now when I compared it with the newest version it is very much different.
The old version: http://pastebin.com/Wy4C2YLN
The old version did not have lines calling for the list with is why my cludge code was working then.
[Updated on: Sat, 13 August 2016 11:08] Report message to a moderator
|
Master Sergeant
|
|
|
|
Re: Externalizing/freeing music[message #346635 is a reply to message #346631]
|
Sat, 13 August 2016 14:58
|
|
Taro_M |
|
Messages:292
Registered:November 2008 |
|
|
I understand, I just wanted to say that the changes caused the music system to behave differently.
Could you guys help me break this down for me?
sprintf( zFileName, "%s\\BATTLE\\BATTLE_%d.wav", szMusicList[15], uiNum );
sprintf is the command that is used to get the name of the music file to be played
zFileName is the formatted file name of the music that will be played, it is formatted by the string
"%s\\BATTLE\\BATTLE_%d.wav" is the formatting string, the % symbols are places where specifiers/arguments are inserted
szMusicList[15] is an argument referencing the music list and what appears be total number of entries in the list
uiNum not sure, the number of the song?
So what should be printed if, lets say, game is supposed to play "Tensor B.wav"? Maybe I could wrap my head around this, if I knew what is the end result.
Report message to a moderator
|
Master Sergeant
|
|
|
Goto Forum:
Current Time: Wed Apr 17 22:35:39 GMT+3 2024
Total time taken to generate the page: 0.01334 seconds
|