# AudioDirector

> Talos next · Since 0.6

## Signature

```ts
export class AudioDirector {
  defaultBus: AudioBus
  masterVolume: number
  constructor(ctx: Ctx, opts: AudioDirectorOptions = {})
  play(cue: Cue | string, extra: Partial<Cue> = {}): number
  loop(cue: Cue | string, extra: Partial<Cue> = {}): number
  stop(handleOrTag: number | string): void
  stopAll(): void
  handleOf(tag: string): number | null
  get playing(): number[]
  bus(name: AudioBus, volume: number, seconds = 0): boolean
  snapshot(name: string): boolean
  music(layer: string, crossfade = 0): number
  fire(cue: AudioCue | string): number
  on(event: string, cue: AudioCue | string): this
  off(event: string): this
  handle(ev: GameEvent): number[]
  applyComponent(component: AudioComponent, at?: Target, tag = "component"): number | null
  applyEntityComponent(tag = "component"): number | null
}
```

Import: `import { AudioDirector } from "@argus/gameplay"`

## Members

| Member | Signature | Description |
|---|---|---|
| `defaultBus` | `defaultBus: AudioBus` |  |
| `masterVolume` | `masterVolume: number` |  |
| `constructor` | `constructor(ctx: Ctx, opts: AudioDirectorOptions = {})` |  |
| `play` | `play(cue: Cue \| string, extra: Partial<Cue> = {}): number` | Start a cue. Returns the engine handle. A tagged cue replaces whatever that tag was playing. |
| `loop` | `loop(cue: Cue \| string, extra: Partial<Cue> = {}): number` | Start a cue looping. |
| `stop` | `stop(handleOrTag: number \| string): void` | Stop a handle or a tag. Unknown tags and already-stopped handles are ignored. |
| `stopAll` | `stopAll(): void` | Stop everything this director started. |
| `handleOf` | `handleOf(tag: string): number \| null` | The handle a tag is playing on, or null. |
| `playing` | `get playing(): number[]` | Handles started by this director and not yet stopped. |
| `bus` | `bus(name: AudioBus, volume: number, seconds = 0): boolean` | Ramp a bus of the scene's mixer graph. False when the scene declares no such bus. The director does not keep bus state: the mixer owns it, one graph for the whole scene, and two behaviors both ducking `music` would otherwise each believe they had set it back. |
| `snapshot` | `snapshot(name: string): boolean` | Cross-fade to a named snapshot. False when the scene declares no such snapshot. |
| `music` | `music(layer: string, crossfade = 0): number` | Change music layer at the next bar line. Returns the handle of whatever is sounding now, which is 0 before the first layer starts. |
| `fire` | `fire(cue: AudioCue \| string): number` | Run one cue now, whichever kind it is. Returns a handle for the two that make one. |
| `on` | `on(event: string, cue: AudioCue \| string): this` | Bind a cue to an event name. Several cues may share an event, and they run in order. |
| `off` | `off(event: string): this` | Unbind every cue for an event. |
| `handle` | `handle(ev: GameEvent): number[]` | Fire the cues bound to a delivered event. Returns the handles started; a bus or snapshot cue contributes nothing to play, so it contributes no handle either. |
| `applyComponent` | `applyComponent(component: AudioComponent, at?: Target, tag = "component"): number \| null` | Apply an `audio` component: spatial cues follow `at` (the owning entity by default), and the component plays now when it autoplays. Returns the handle, or null when it is waiting to be triggered. |
| `applyEntityComponent` | `applyEntityComponent(tag = "component"): number \| null` | Apply the `audio` component on the behavior's own entity, if it has one. |
