music_track

From Valve Developer Community
Jump to: navigation, search
Ambient generic.png

music_track is a point entity available in Black Mesa Black Mesa. This entity allows you to play music and control it dynamically, without the need to create lots of scripts. The best example of using this entity is the beginning of chapter Surface Tension. When player triggering the trigger - the first music track starts, which is looped (it loops itself, without help from other entities), when the soldiers leaves the ambush - the next track starts, which is also looped. When the fight with the helicopter ends, the last, final track starts, which is not looped. Before this system implementation, music was launching via ambient_generic, which just playing the full version of the music from beginning to end, which made certain parts of the music inappropriate for situations, or even ended when the helicopter didn't even arrive.

All code for original music tracks from Black Mesa Black Mesa placed in game_sounds_music.txt and game_sounds_xen_music.txt, both placed in scripts folder.

Black Mesa Level Creation

Soundscript

This is example of sound script to make your music properly working with this entity. The comments explain what each line does.

"MusicTrackName" //Sound name.
{
    "channel"       "CHAN_STATIC" //Channels are used to categorize sounds in a way that NPCs, and game logic in general, can understand. In case of music_track, use only CHAN_STATIC.

    "volume"        "1.0" //A number between 0 and 1, where 1 is the sound's original volume.

    "pitch"         "100" //Any number between 0 and 255, where 100 is the sound's original pitch and 255 is very high.

    "soundlevel"    "SNDLVL_NONE" //The sound's attenuation; how fast it drops away. In case of music_track, use only SNDLVL_NONE.

    "bpm"           "31.7756" //BPM is Beats Per Minute. This value is specific to your music.
 
    "signature"     "1" //[Code] your-name-here said the next about it this: "Signature is the time signature: how many Beats Per Measure (BMP). If you know that your song is 100 BPM and that there are 4 beats per measure, 
                        //then you know that each measure covers a 4 beats / 100 bpm slice of time. This is how we can figure out when to fade in the next track". 

    "fadetime"      "2" //How many seconds to fade out the current track over. For example, a value of 5 means "fade this track out over 5 seconds".

    "wave"          "#music/MyCoolMusiс.wav" //Filename and path to it. Usually all music is placed in music folder.
}

Looping

To make your music endless looping, you'll need to add in your .wav file "loop point". Check out this guide.

Keyvalues

Name (targetname) <string>
The name that other entities refer to this entity by, via Inputs/Outputs or other keyvalues (e.g. parentname or target).
Also displayed in Hammer's 2D views and Entity Report.
See also:  Generic Keyvalues, Inputs and Outputs available to all entities

Sound Name (track_script_sound) <sound>
Name of the GameSound entry for the music to play.
Icon-Important.pngImportant:This doesn't work if you specify sound with path (music\bms - st1-part2.wav for example), instead, sound name from the code of the file must be used (music.st.1-part2 in case of the example). It can't use .wav file paths directly because it need the metadata fields (bpm, signature, fade time) above for the system to work properly.
Next Track (next_track_entity) <targetname>
Name of the next music_track entity to play when Next input is called.
Icon-Important.pngImportant:You cannot use any track in next music_track, your music must go sequentially in soundscript file. Otherwise it will not work. Quote from [Code] your-name-here about this: "music_track entities function as a playlist that moves in a single direction (managed by BlackMesaMusicTrackManager). Calling Next on a music_track entity will fade out the currently active music track and queue the next oneto play when the next measure starts".

Inputs

Play <void>
Starts the music track.
Note.pngNote:It cannot be refired while music is playing. Quote from [Code] your-name-here about this: "Doubtful. We ran into a significant number of bugs trying to get this system working. You can only move forward in the playlist (from what I remember)".
Stop <void>
Stops the music track.
Warning.pngWarning:This input only in FGD and doesn't exists in the game.
Fade <void>
Fades the music track out over the given number of seconds in sound script.
Icon-Important.pngImportant:Will not work without bpm, signature and fadetime.
Next <void>
Plays the next track when the BPM lines up.

See Also