srctools.sndscape
The sndscape module reads and writes soundscape files. Basic usage involves first parsing the
file into a Keyvalues tree, then parsing into soundscapes:
with open('soundscape.txt', 'r') as f:
kv = Keyvalues.parse(f)
soundscapes = Soundscape.parse(kv)
The opposite is done by simply calling Soundscape.export() on each soundscape to append to a file.
Enumerations
Classes
- class srctools.sndscape.Soundscape(
- *,
- name: str,
- rand_sounds: list[RandSound] = ...,
- loop_sounds: list[LoopSound] = ...,
- children: list[SubScape] = ...,
- dsp: int | None = None,
- dsp_spatial: int | None = None,
- dsp_volume: float = 1.0,
- fadetime: float = 0.0,
- soundmixer: str | None = None,
A single soundscape definition.
- fadetime: float
If non-zero, overrides the duration of the crossfade between this and the previous soundscape.
- classmethod parse(
- file: Keyvalues,
Parse all soundscape definitions in a file.
This returns a dict mapping casefolded names to Soundscapes.
- classmethod parse_one(kv: Keyvalues) Soundscape
Parse a single soundscape definition.
- class srctools.sndscape.SubScape(
- *,
- name: str,
- volume: tuple[float | Volume, float | Volume] = (srctools.sndscript.VOL_NORM, srctools.sndscript.VOL_NORM),
- pos_offset: int = 0,
- pos_override: int | None = None,
- ambient_pos_override: int | None = None,
A sub-soundscape entry, which triggers another soundscape to play also.
- volume: tuple[float | Volume, float | Volume]
Modulates the volume of the child soundscape, and anything it plays.
- abstract class srctools.sndscape.SoundRule
These attributes are common to
RandSoundandLoopSound.- position: PosType | int | Vec
The position to play the sound from. This can take a few forms:
PosType.AMBIENT(default)Plays at full volume regardless of location.
PosType.RANDOMPlays from a random position near the player.
- An integer
This is the index of an entity referenced by the
env_soundscape.- A vector
This is a fixed position in world, only useful for map-specific soundscapes.
- class srctools.sndscape.RandSound(
- *,
- position: PosType | int | Vec = PosType.AMBIENT,
- volume: tuple[float | Volume, float | Volume] = (srctools.sndscript.VOL_NORM, srctools.sndscript.VOL_NORM),
- pitch: tuple[float | Pitch, float | Pitch] = (Pitch.PITCH_NORM, Pitch.PITCH_NORM),
- level: tuple[int | Level, int | Level] = (Level.SNDLVL_NORM, Level.SNDLVL_NORM),
- no_restore: bool = False,
- time: tuple[float, float],
- sounds: list[str],
Bases:
SoundRuleA playrandom entry in a soundscape. These are played at random intervals.
- class srctools.sndscape.LoopSound(
- *,
- position: PosType | int | Vec = PosType.AMBIENT,
- volume: tuple[float | Volume, float | Volume] = (srctools.sndscript.VOL_NORM, srctools.sndscript.VOL_NORM),
- pitch: tuple[float | Pitch, float | Pitch] = (Pitch.PITCH_NORM, Pitch.PITCH_NORM),
- level: tuple[int | Level, int | Level] = (Level.SNDLVL_NORM, Level.SNDLVL_NORM),
- no_restore: bool = False,
- radius: float = 1.0,
- sound: str,
Bases:
SoundRuleA playlooping entry in a soundscape.