Music track: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
Line 16: Line 16:
     "pitch"        "100" //Any number between 0 and 255, where 100 is the sound's original pitch and 255 is very high.
     "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.
     "soundlevel"    "SNDLVL_NONE" //The sound's attenuation; how fast it drops away. In case of music_track, use only SNDLVL_NONE.
     "bpm"          "31.7756" // fill me in
     "bpm"          "31.7756" //[Code] your-name-here said about it this: "BMP is Beats Per Minute. Use BMP value from yours track (original tracks from Black Mesa use 31.7756)".
     "signature"    "1" //Countdown before playing next track after Next input. Similar happen with Fade input.
     "signature"    "1" //[Code] your-name-here said 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" //Fade out time when starts next music track.
     "fadetime"      "2" //Fade out time when starts next music track.
     "wave"          "#music/MyCoolMusiс.wav" //Filename and path to it. Usually all music is placed in music folder.
     "wave"          "#music/MyCoolMusiс.wav" //Filename and path to it. Usually all music is placed in music folder.

Revision as of 04:21, 23 March 2024

Ambient generic.png

music_track is a point 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.

Todo: Learn how this entity interacts with sound files and their code. Answer the following questions:
    • Why Next input works only if used combination of certain tracks ?
    • Why Fade input works only with certain tracks ?
Black Mesa Level Creation

Soundscript

This is example of sound script to make your music properly working with this entity.

"MusicTrackName"
{
    "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.
    "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" //[Code] your-name-here said about it this: "BMP is Beats Per Minute. Use BMP value from yours track (original tracks from Black Mesa use 31.7756)".
    "signature"     "1" //[Code] your-name-here said 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" //Fade out time when starts next music track.
    "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>[ Edit ]
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.

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> Obsolete
Deprecated.
Stops the music track.
Fade <void>
Fades the music track out over the given number of seconds in sound script.
Next <void>
Plays the next track when the BPM lines up.

Outputs