SoundPlayer beta
Class of @v12-engine/client/common
export declare class SoundPlayerPlays sounds of the game for a listener: the mix, the buses, the music and where each sound is on the map
Members
constructor
constructor(listener: () => Listener, hearing?: Hearing,
assets?: Assets,
limits?: Limits,
storage?: KeptStorage,
mixer?: AppMixer);Constructs a new instance of the SoundPlayer class
audition
audition(name: string, def?: SoundDef): boolean;Plays a sound as it is defined (define), or as def says, at once and from nowhere on the map: what a click on a Play button asks (the editor's Sounds panel), so it wakes the player as that click would. Heard through the player's mix as any other; not kept from playing again so soon. Whether there was a file of it to play
define
define(defs?: Readonly<Record<string, SoundDef>>): void;How each sound is played from now on, by its name (GameView.sounds.defs, with the game's sounds.json laid over them): its volume, how much higher or lower each time, how far it carries and where it is cut off, its bus. Those before go; none for every sound as what plays it asks. A sound standing on the map takes it as it is put there again
defOf
defOf(name: string): SoundDef;How a sound is played, as it is defined (define): nothing said for one it does not say
dispose
dispose(): void;It goes: what it plays ends. Attached to the app's sound, faded, and what it set on the mix put back, the music going on where a scene after it took it over; on a mixer of its own, all of it at once
frame
frame(): void;Every frame: how loud each sound of the map is, and to which side, from where the player listens
hold
hold(held: boolean): void;Holds every sound, music too, where it is, or lets them go on: the map editor's own while a game is played over it, whose keys and clicks would otherwise wake them
isMuted
get isMuted(): boolean;Whether all sound is off, as the mixer has it
late
late: number;Seconds a sound may start late where its file is not there yet (fetched as it is first heard): one later than that is skipped, as a blow heard after the fight is worse than none (SoundSet.late)
level
level(bus: Bus | 'master'): number;The volume of a bus, or of everything, 0..1
levels
levels(): SoundLevels;The volumes the player set, of everything and of each bus
load
load(names: Iterable<string>, progress?: (done: number, total: number) => void): Promise<void>;Loads sounds ahead, every take of each, and settles once they are there: before a game starts. Tells progress how many of how many files are. Those that do not load are said in the console, and counted all the same
loadLater
loadLater(names: Iterable<string>, atOnce?: number): Promise<void>;Loads sounds behind the game, a few files at a time (LATER_AT_ONCE), every take of each: what was not loaded before it started (SoundSet.preload). One heard before its turn is fetched then, and not again
log
log: Logger;Where it says what went wrong: the log of the game it is part of, once that has taken it (GameClient.log)
loop
loop(name: string, bus?: Bus): SoundLoop;A sound that loops until it is stopped, as loud as it is told (0 to 1, eased): the rain's, a fire's. One file, made to loop, or one made in code (make). On the ambience bus unless told
make
make(name: string, build: (context: BaseAudioContext) => AudioBuffer): void;A sound made in code, by its name, in place of a file of that name: played as any other (play, loop). The client's own are rustle, of moving through tall grass (FoliageLook.sound), and foliage-fire and foliage-catch, of grass burning and catching (FoliageFireLook)
mixer
readonly mixer: AppMixer;The app's sound, or its own (attached says): the context, the volumes, the buses and the music
mode
readonly mode: HearingMode;How a sound's direction is heard (Hearing.mode)
musicTracks
get musicTracks(): string[];The music playing now: its tracks, none for none
musicVolume
musicVolume(level: number, seconds?: number): void;The music's own volume (0 to 1), eased over seconds
onMix
onMix?: (muted: boolean, levels: SoundLevels) => void;Told of the player's mix each time it is set (setMuted, setLevel): what the HUD shows of it (ui.muted, ui.levels)
paused
paused(on: boolean): void;Whether this game is paused, for what the mix does then (AppMixer.onPause): over as it goes
play
play(name: string | undefined, at?: Vec2, volume?: number, delay?: number, bus?: Bus): void;Plays one of the files of a sound. at is where it comes from on the map, left out for what is not in the world, like a click. delay is in seconds from now. Effects unless another bus is said
playAmbience
playAmbience(names: string[]): void;Plays sounds over and over in the background, all together: wind, birds, a river. Each is one file, made to loop. On the ambience bus
playingMusic
playingMusic(): CutMusic | undefined;The music playing now, as code reaches it (CutMusic): its element, its volume's node. None for none
preload
preload(names: Iterable<string>): void;Loads sounds ahead, so the first time they are heard is not late
quiet
quiet(on: boolean): void;Quiets this scene's sounds alone, or lets them be heard again, while the app's go on (GameClient.rest): the game behind a menu, asleep under what plays over it. All of them, where it has a mixer of its own
routeMedia
routeMedia(element: HTMLMediaElement, bus?: Bus): CutMediaSound | undefined;A <video> or <audio> of the page heard through the sound (CN52): on bus, so that the player's volumes and mute are its, at full volume (the element's own left at 1 by who plays it), nothing of code's in it. The same each time for an element; none where the page will not (the element heard through another context already)
say
say(name: string | undefined, speaker: number, options?: {
at?: Vec2;
volume?: number;
rest?: number;
always?: boolean;
}): void;Lets someone say one of the lines of a sound, the way it was recorded. A speaker says one line at a time, and keeps quiet for rest seconds after it: what it is asked to say in the meantime is left unsaid, unless it has to be (always)
scale
scale(bus: Bus, level: number, seconds?: number): void;A bus at level of the player's volume for it (1 as they set it), eased over seconds: a cinematic's say over the mix (D1), never kept with the player's settings, and as it was once this is gone
schedule
schedule(name: string | undefined, at?: Vec2, volume?: number, delay?: number, bus?: Bus): (() => void) | undefined;play, giving back a function that calls the sound off, before it starts or while it plays (a blow's sound whose swing was cut short), or nothing when there was nothing to play
secondsOf
secondsOf(name: string): number | undefined;How long a sound is, in seconds, as far as it is loaded: the longest of its takes there. Nothing for one not loaded yet (load, preload), or one the game has not
setEmitters
setEmitters(emitters?: readonly MapEmitter[], group?: string): void;Sounds that keep playing at places of the map (MapEnvironment.sounds), in place of those there were: each heard as loud as where the player listens is near it (frame), by its own reach and volume. Each is one file, made to loop, at a pitch its definition says (one rate between its lowest and highest, for as long as it plays) on its definition's bus (effects where it says none). group: whose they are, those of other groups left playing (the map's own, 'map', when left out; the waterfalls', 'waterfalls')
setLevel
setLevel(bus: Bus | 'master', level: number): void;Sets the volume of a bus, or of everything. Remembered for the next game
setMusic
setMusic(tracks: string[], options?: {
crossfade?: number;
volume?: number;
}): void;Plays other music, or none: the tracks one after the other, over and over. Nothing changes when they are the ones playing, whoever began them (a menu's that carries into a game). Its own from then: faded out as this goes, unless a scene after it took it over
setMuted
setMuted(muted: boolean): void;Turns all sound off or on again. Remembered for the next game
sound
sound(name: string, play?: SoundPlay): PlayedSound | undefined;Plays one of the files of a sound, held (CN50): what a cinematic plays, reached by code while it plays (CutSound: stopped, faded, filtered, paused, its nodes). Shaped as play says (SoundPlay): its volume, rate, side, where in the file, looped, faded in, filtered, with a reverb or an echo. Heard while the player muted the game (as nothing: the mix is silent), so that it lasts as long as its file all the same; nothing before the first click or key, of a sound there is no file of, or too far to hear