Sound Tags

by Rockinawsome
An elegant solution to sound managment.
ID:127940
 
By Adam R. Turner aka Rockinawsome

How it works:

The example below demonstrates how to keep a player from hearing the sound of rain if he or she is indoors

if(src.soundtags["rain"])
src.channel_tracker.Play(src.soundtags["rain"])

The idea is that these sound tags indicate what a player should hear in a passive manner, meaning other things in the game world control when
the sound tag is played.

Sound tags are also capable of transmitting to multiple players, and modify BYOND's sound system a little bit.

sound.repeat now repeats a number of times, once if 0, or infinitly if -1
This is different to BYOND's system, which merely uses 1 or 0 to indicate playing once, or playing infinitly.

sound.wait now waits a duration before interupting the current channel, unless specified 0 (wait for clear channel) or -1 (interupt immediately).
This is different to BYOND's system, which merely uses 1 or 0 to indicate interupting the current channel, or waiting for it to clear.

If L4OPEN is TRUE, then the code will attempt to find an open channel before playing.
If L4OPEN is TRUE and the sound tag's channel is specified -1, then L4 will look for any open channel, instead of trying the channel specified first.

Players are given lists of sound tags, which can be easily managed like so:
if(usr.soundtags.Find("piano"))
usr.channel_tracker.Play(usr.soundtags["piano"])


SoundTags has 1024 "channels". The default system has very few. Of course, actually layering that many sounds at once might be a bad idea.

channel_tracker keeps track of a player's available channels.