Ok here is the code that replaces the init music, using this can replace the music for pretty much anyone modifying uplink using FMOD. This requires a bit of work on your end, blind copy and paste would likely fail, but this will for sure get you on your way.
Code:
resultUniqueFmod = FMOD::System_Create( & systemF);
if(resultUniqueFmod != FMOD_OK) { exit(-1); }
resultUniqueFmod = systemF - > init(100, FMOD_INIT_NORMAL, 0);
if(resultUniqueFmod != FMOD_OK) { exit(-1); }
resultUniqueFmod = systemF - > createStream(RsArchiveFileOpen(Playlist), FMOD_DEFAULT, 0, & playlistUniqueFmod);
resultUniqueFmod = playlistUniqueFmod - > getFormat( & soundtypeUniqueFmod, 0, 0, 0);
isplaylistUniqueFmod = (soundtypeUniqueFmod == FMOD_SOUND_TYPE_PLAYLIST);
if(isplaylistUniqueFmod) {
resultUniqueFmod = playlistUniqueFmod - > getTag("FILE", countUniqueFmod, & tagUniqueFmod);
ERRCHECK(resultUniqueFmod);
sprintf(fileUniqueFmod, "music/%s", (char * ) tagUniqueFmod.data);
resultUniqueFmod = systemF - > createSound(RsArchiveFileOpen(fileUniqueFmod), FMOD_DEFAULT, 0, & soundUniqueFmod);
ERRCHECK(resultUniqueFmod);
resultUniqueFmod = systemF - > playSound(FMOD_CHANNEL_FREE, soundUniqueFmod, false, & channelUniqueFmod);
ERRCHECK(resultUniqueFmod);
playlistUniqueFmod - > getTag("TITLE", countUniqueFmod, & tagUniqueFmod);
titleUniqueFmod = (char * ) tagUniqueFmod.data;
countUniqueFmod++;
}
In my hud update call i check to see if the track is playing, if it is not playing, than play music by using the count variable already incremented when the initmusic was called, if its the last song, go to the first song. This bit of code being used in the hud update is more ingenious than it seems, this is explained afterwards when using next track and previous track functions.
Code:
bool isplaying = false;
if(channelUniqueFmod && isplaylistUniqueFmod) {
channelUniqueFmod - > isPlaying( & isplaying);
if(!isplaying) {
if(soundUniqueFmod) {
soundUniqueFmod - > release();
soundUniqueFmod = NULL;
}
if(countUniqueFmod < 0) { countUniqueFmod = trackCount - 1; }
resultUniqueFmod = playlistUniqueFmod - > getTag("FILE", countUniqueFmod, & tagUniqueFmod);
if(resultUniqueFmod != FMOD_OK) {
countUniqueFmod = 0;
} else {
sprintf(fileUniqueFmod, "music/%s", (char * ) tagUniqueFmod.data);
resultUniqueFmod = systemF - > createStream(RsArchiveFileOpen(fileUniqueFmod), FMOD_DEFAULT, 0, & soundUniqueFmod);
ERRCHECK(resultUniqueFmod);
resultUniqueFmod = systemF - > playSound(FMOD_CHANNEL_FREE, soundUniqueFmod, false, & channelUniqueFmod);
ERRCHECK(resultUniqueFmod);
playlistUniqueFmod - > getTag("TITLE", countUniqueFmod, & tagUniqueFmod);
titleUniqueFmod = (char * ) tagUniqueFmod.data;
std::ostrstream trackNum;
trackNum << "Track " << countUniqueFmod + 1;
trackNum << '\x0';
EclRegisterCaptionChange("hud_trackname", trackNum.str());
countUniqueFmod++;
}
}
}
The variable "trackCount" is gathered from this function
Code:
FILE * infile = fopen(RsArchiveFileOpen( Playlist ), "r");
int ch;
while(EOF != (ch = getc( infile ))) {
if('\n' == ch) {
++trackCount;
}
}
The variable "Playlist" is just a simple
Code:
char *Playlist="music/playlist.m3u";
Ingeniously using the hud update to check if the song has stopped playing, makes it super easy to make a next track function, the code for the next track function is one line.
Code:
channelUniqueFmod->stop();
Stopping the track causes the hud update to say, "music is stopped so lets play music". Since when a track is played our count variable is increased by one, it will always play the next track.
The code for the previous track button is 2 lines which also is pretty nifty. It subtracts 2 from our count variable (since when the last track started it added 1 already) then calls stop so the hud update can once again say "music is stopped so lets play music", effectively playing the previous track.
Code:
countUniqueFmod=countUniqueFmod-2;
channelUniqueFmod->stop();
This function lets you mute
Code:
float volume;
channelUniqueFmod->getVolume(&volume);
if ( volume <= .01f) {
channelUniqueFmod->setVolume(1.0f);
}else{
channelUniqueFmod->setVolume(0);
}
There it is, I suppose I would be kind of a dick if I didn't expose the format of the global variables eh?
Code:
FMOD::System *systemF;
FMOD_RESULT resultUniqueFmod;
FMOD::Sound *soundUniqueFmod;
FMOD::Channel *channelUniqueFmod;
FMOD::Sound *playlistUniqueFmod = 0;
FMOD_TAG tagUniqueFmod;
bool isplaylistUniqueFmod = false;
FMOD_SOUND_TYPE soundtypeUniqueFmod;
int countUniqueFmod = 0;
char *titleUniqueFmod = NULL;
char fileUniqueFmod[128];