A better Torque music player...
by Eric Forhan · in Torque Game Engine · 11/03/2002 (12:27 pm) · 7 replies
I've recently submitted a resource for porting the Tribes2 music player over to torque. This allows for a simple system where the audio profile is defined once, then in the mission file set musicTrack to the audioprofile name.
While I'm waiting for it to be approved, I thought I'd run it by someone else to make sure it's all correct. It works fine on Trajectory Zone, but I want to be thorough.
To show the implementation (after the music player has been installed):
In ~/server/scripts/audioprofile.cs you would add:
and in the mission file, under new SimGroup(MissionGroup) {, either change or add the following line:
For one song, that may seem like not much help. However, now every time you have a dark dungeon, you only need to add the musicTrack = "dungeon"; to the mission file. It also allows for a random or demo mode, which I haven't tested but should work with little effort.
So, anyone out there want to give it a pre-release try? You must have ogg vorbis installed, though changing it to MP3 should be fairly easy. It's totally in scripts, so no engine compiling necessary. Just cut-n-paste and go. :-)
I don't know how much interest, if any, there will be in this--I'd rather only open it up to a manageable one or two developers. lol. :-) Hopefully it will be approved in the next week, and any changes I must make I can.
Eric
While I'm waiting for it to be approved, I thought I'd run it by someone else to make sure it's all correct. It works fine on Trajectory Zone, but I want to be thorough.
To show the implementation (after the music player has been installed):
In ~/server/scripts/audioprofile.cs you would add:
new AudioProfile( dungeon )
{
filename = "~/data/sound/music/dim_hope.ogg";
description = "MusicLooping";
preload = false;
isStreaming = true;
is3D = false;
type = $MusicAudioType;
};and in the mission file, under new SimGroup(MissionGroup) {, either change or add the following line:
musicTrack = "dungeon";
For one song, that may seem like not much help. However, now every time you have a dark dungeon, you only need to add the musicTrack = "dungeon"; to the mission file. It also allows for a random or demo mode, which I haven't tested but should work with little effort.
So, anyone out there want to give it a pre-release try? You must have ogg vorbis installed, though changing it to MP3 should be fairly easy. It's totally in scripts, so no engine compiling necessary. Just cut-n-paste and go. :-)
I don't know how much interest, if any, there will be in this--I'd rather only open it up to a manageable one or two developers. lol. :-) Hopefully it will be approved in the next week, and any changes I must make I can.
Eric
About the author
#2
I can email you a .doc copy of what I submitted.
Eric
www.trajectoryzone.com
11/03/2002 (3:24 pm)
lol. I meant to mention that. :-)I can email you a .doc copy of what I submitted.
Eric
www.trajectoryzone.com
#3
You can probably implement it a little cleaner, but hey... there you go.
11/03/2002 (3:27 pm)
The basic interface I've been using for a while has been:$MusicAudioType = 4;
new AudioDescription(MusicAudio)
{
volume = 2.0;
isLooping = true;
isStreaming = true;
is3D = false;
type = $MusicAudioType;
};
new AudioProfile(GameMusic)
{
filename = "default_music_filename_here.ogg";
description = "MusicAudio";
preload = false;
};
function startMusic()
{
$GameMusic = true;
$GameMusicHandle = alxPlay(GameMusic);
}
function stopMusic()
{
$GameMusic = false;
alxStop($GameMusicHandle);
}
function setMusic(%fileName)
{
%temp = false;
if ($GameMusic)
{
%temp = true;
stopMusic();
}
// Small check to see if the file exists.
// Don't want it crashing trying to stream a file
// that just isn't on your harddrive...
if(isfile(%fileName))
{
GameMusic.filename = %fileName;
if (%temp)
{
startMusic();
}
}
else
{
echo("setMusic -- FILE DOES NOT EXIST");
}
}
function getMusic()
{
return GameMusic.filename;
}You can probably implement it a little cleaner, but hey... there you go.
#4
I always recommend backups, too. ;-)
Here it is, as I had sent to GG:
This is the T2 port of the music player for Ogg Vorbis. It also allows the map creator to easily choose what the default music for the level is, as well as a random or demo mode.
This was done for Trajectory Zone, and so refers to a song file called "DimHope.ogg"
First, you MUST have Ogg Vorbis installed! There's a tutorial for it on GG, so I won't go into that. Note, an MP3 version should be simple.
Next, put DimHope.ogg (or, preferably your music file. ;-) ) in ~/data/sounds/music
The next step uses ~client/scripts/audioprofiles.cs. Add the following code under the commented line "// assign some human readable variable to channel numbers" and then delete the similar lines. Only $MusicAudioType really is necessary, but by defining them all we may curb a few audio channel conflicts. We also define a new AudioDescription, which is used in the next step.
In ~/server/scripts/audioprofiles.cs (note, this is not the same file as above), add:
To define the profile, I chose to put it in
~/server/scripts/audioprofiles.cs, though you may wish to have a seperate file strictly for music. Create the audio profile:
That's it!
Once you've got the audioprofile defined, then any number of maps can use that same music simply by putting the name (Dim_Hope, here) in the mission file.
Possible uses? Could be for moods--Preset the profiles for gloomy, happy, adrenalyn then just type the name in the missions and go.
Taking it a step further, this might be used to dynamically alter the music in-game. Profiles might be: solo (quiet/by self), company(a few players), crowd(lots) The more the action(or players), the faster profile of music plays. I do not know if there would be server/client issues, though I'm sure they could be worked out.
A note: If you've already got music working, but want to implement this you will need to make sure you take out the old.
Hope it helps!
Eric Forhan
www.midnightryder.com
11/03/2002 (3:42 pm)
I originally posted with the idea of limited release (until the resource is approved), so I could be totally positive it was rock-solid for general consumption. :-) But, I can post it here just the same. I always recommend backups, too. ;-)
Here it is, as I had sent to GG:
This is the T2 port of the music player for Ogg Vorbis. It also allows the map creator to easily choose what the default music for the level is, as well as a random or demo mode.
This was done for Trajectory Zone, and so refers to a song file called "DimHope.ogg"
First, you MUST have Ogg Vorbis installed! There's a tutorial for it on GG, so I won't go into that. Note, an MP3 version should be simple.
Next, put DimHope.ogg (or, preferably your music file. ;-) ) in ~/data/sounds/music
The next step uses ~client/scripts/audioprofiles.cs. Add the following code under the commented line "// assign some human readable variable to channel numbers" and then delete the similar lines. Only $MusicAudioType really is necessary, but by defining them all we may curb a few audio channel conflicts. We also define a new AudioDescription, which is used in the next step.
$DefaultAudioType = 0;
$GuiAudioType = 1;
$SimAudioType = 2;
$MusicAudioType = 3;
$EffectAudioType = 4;
new AudioDescription(MusicLooping)
{
volume = 2.0;
isLooping= true;
is3D = false;
type = $MusicAudioType;
};In ~/server/scripts/audioprofiles.cs (note, this is not the same file as above), add:
//--------------------------------------------------------------------------
// ogg-Music player
//--------------------------------------------------------------------------
new ScriptObject(MusicPlayer)
{
class = oggAudio;
currentTrack = "";
repeat = true;
};
function oggAudio::stop(%this)
{
alxStopAll();
}
function getRandomTrack()
{
if ( isDemo() )
return( "desert" );
%val = mFloor(getRandom(0, 4));
switch(%val)
{
case 0:
return "Dim_Hope"; //change to your names
case 1:
return "Azteca";
case 2:
return "Gloomy";
case 3:
return "Cheery";
case 4:
return "Gaelic";
}
}
function oggAudio::play(%this)
{
if(%this.currentTrack $= "")
%this.currentTrack = getRandomTrack();
%this.playTrack(%this.currentTrack);
}
function oggAudio::playTrack(%this, %trackName)
{
%this.currentTrack = %trackName;
if($pref::Audio::musicEnabled)
{
//if ( isDemo() )
// alxPlay("~/data/sound/music/" @ %trackName @ ".ogg");
//else
$musicHandle = alxPlay ( %trackName );
}
}
function finishedMusicStream(%stopped)
{
if(%stopped $= "true")
return;
if(MusicPlayer.repeat)
MusicPlayer.playTrack(MusicPlayer.currentTrack);
}
function clientCmdPlayMusic(%trackname)
{
if(%trackname !$= "")
MusicPlayer.playTrack(%trackName);
}
function clientCmdStopMusic()
{
MusicPlayer.stop();
}The next step is in /common/client/missiondownload.cs. In function clientCmdMissionStartPhase1 put as the last entry: clientCmdPlayMusic(%musicTrack);The Music Player should now be installed. To use it, you only need to define an audioProfile for the song and a small change the mission file.
To define the profile, I chose to put it in
~/server/scripts/audioprofiles.cs, though you may wish to have a seperate file strictly for music. Create the audio profile:
//
// Music Profiles
//
new AudioProfile(Dim_Hope)
{
filename = "~/data/sound/music/dim_hope.ogg";
description = "MusicLooping";
preload = false;
isStreaming = true;
is3D = false;
type = $MusicAudioType;
};Open the mission file. Under new SimGroup(MissionGroup) {, either change or add the following line:musicTrack = "Dim_Hope";musicTrack must use the same name as your audio profile.
That's it!
Once you've got the audioprofile defined, then any number of maps can use that same music simply by putting the name (Dim_Hope, here) in the mission file.
Possible uses? Could be for moods--Preset the profiles for gloomy, happy, adrenalyn then just type the name in the missions and go.
Taking it a step further, this might be used to dynamically alter the music in-game. Profiles might be: solo (quiet/by self), company(a few players), crowd(lots) The more the action(or players), the faster profile of music plays. I do not know if there would be server/client issues, though I'm sure they could be worked out.
A note: If you've already got music working, but want to implement this you will need to make sure you take out the old.
Hope it helps!
Eric Forhan
www.midnightryder.com
#5
Loading compiled script fps/server/scripts/audioProfiles.cs.
AudioProfile: data dataBlock not networkable (use datablock to create).
fps/server/scripts/audioProfiles.cs (0): Register object failed for object track_1.
11/23/2002 (6:07 am)
Im getting the following error:Loading compiled script fps/server/scripts/audioProfiles.cs.
AudioProfile: data dataBlock not networkable (use datablock to create).
fps/server/scripts/audioProfiles.cs (0): Register object failed for object track_1.
#6
Has anyone else run into this?
Eric
12/02/2002 (3:37 am)
Christian, did you get this figured out? I'm not sure where to begin.Has anyone else run into this?
Eric
#7
So, in missiondownload.cs find function clientCmdMissionStartPhase1 and add this:
[code]
12/04/2002 (9:23 am)
Just found out the code above is never called upon. :) So, in missiondownload.cs find function clientCmdMissionStartPhase1 and add this:
[code]
Associate Stefan Beffy Moises