import type { ReplayChange, ReplayEvent } from "./replay.types.ts"; import type { CueKind, SoundBed, SoundLayer, SoundLevel, SoundSet, SoundVoice } from "./sound.sets.ts"; /** The venue a surface is in, as far as the sound cares: its roof and its seats. Both are optional; without them the bed's own are used. */ export interface SoundVenue { /** * The kind of roof, as the venues and the stadiums give it: `open` and `canopy` leave the crowd under the sky; `cable` and `panels` (a retractable roof) mostly close it in; `fixed`, `dome`, * `saddle` and `barrel` close it in. An unknown word is taken as the bed's own. */ roof?: string; /** The seats. */ seats?: number; } /** Where and how a surface is heard. */ export interface SoundContext { /** The surface: a sport of the package (`nhl`, `soccer`, `judo`, ...). */ sport: string; venue?: SoundVenue; /** The share of the seats that are taken, 0 to 1 (1 by default): 0 is an empty building, as when a page's Crowd is off. */ crowd?: number; /** The view: `3d` is in the building, `2d` the drawing from above, heard as a broadcast is, the crowd further off and the room drier. */ view?: "2d" | "3d"; } /** The room a surface is heard in. */ export interface SoundRoom { bed: SoundBed; /** How closed in it is, 0 (open sky) to 1 (a roof all over). */ enclosure: number; /** How long the room rings, in seconds. */ decay: number; /** How much of the sound is the room's echo, 0 to 1. */ wet: number; /** The people in it. */ people: number; /** How loud the crowd is for the people in it, 0 (nobody) to a little over 1 (more than the bed was made for). */ crowd: number; /** All of it, for the view: 1 in 3D, less from above. */ gain: number; } /** A mix: each layer's gain, and the room. */ export interface SoundMix extends SoundRoom { level: SoundLevel; layers: Readonly>; } /** The set of a surface's sport, or `undefined` when it has none (a surface with no sound shows no sound controls). */ export declare function soundSetOf(sport: string): SoundSet | undefined; /** The crowd levels a surface offers, quietest first: none for a surface with no sound. */ export declare function soundLevelsOf(sport: string): readonly SoundLevel[]; /** The voices a surface's cues use, each once, in the order of `CUE_KINDS`: what a page loads when it has files for them. */ export declare function soundVoicesOf(sport: string): readonly SoundVoice[]; /** * The room of a surface in its context: how closed in the venue is (its roof, else its bed's), how long it rings (longer closed in and larger), how much echo, and how loud the crowd is for the * people in it (the seats times the share taken, on a scale that grows as a crowd's sound does, slower than its number). `undefined` for a surface with no sound. * @example * ```ts * import { soundRoom } from "@johnmorrisdotca/kyogijo-stadiums/sound"; * const arena = soundRoom({ sport: "nhl", venue: { roof: "fixed", seats: 18000 } })!; * const field = soundRoom({ sport: "soccer", venue: { roof: "open", seats: 50000 } })!; * console.log(arena.bed.id, arena.decay > field.decay, arena.wet > field.wet); * console.log(soundRoom({ sport: "nhl", crowd: 0 })!.crowd); * // arena true true * // 0 * ``` */ export declare function soundRoom(context: SoundContext): SoundRoom | undefined; /** Each layer's gain at each level, before the crowd's size: the room and the water stay, the voices come up. */ export declare const LEVEL_MIX: Readonly>>>; /** The nearest level a surface offers to the one asked for: a dojo asked to roar is loud. */ export declare function levelFor(sport: string, level: SoundLevel): SoundLevel; /** * The mix of a surface in its context at a crowd level: each of its bed's layers' gain (the crowd's voices scaled by the people in the room; a layer the bed does not have is 0) and the room. * `undefined` for a surface with no sound. * @example * ```ts * import { soundMix } from "@johnmorrisdotca/kyogijo-stadiums/sound"; * const quiet = soundMix({ sport: "nhl" }, "quiet")!; * const roar = soundMix({ sport: "nhl" }, "roar")!; * console.log(quiet.layers.roar, roar.layers.roar > roar.layers.murmur, soundMix({ sport: "kyudo" }, "roar")!.level); * // 0 true murmur * ``` */ export declare function soundMix(context: SoundContext, level: SoundLevel): SoundMix | undefined; /** A period of a game on the timeline's clock, as the example games give them. */ export interface SoundPeriod { number?: number; start: number; end: number; } /** A game at a moment: what moves the crowd. */ export interface GameMoment { /** The time on the timeline's clock. */ t: number; /** The game's periods; without them the whole timeline is one. */ periods?: readonly SoundPeriod[]; /** The timeline's first and last moments. */ start: number; end: number; /** The score now. */ score?: { home: number; away: number; }; /** Seconds since the last goal, when there was one. */ sinceGoal?: number; } /** * How excited the crowd is at a moment of a game: a murmur before the start, between periods and after the end; engaged while it plays; loud late in a close game; a roar for a few seconds * after a goal; and back to a murmur when one side is far ahead late on. * @example * ```ts * import { excitementAt } from "@johnmorrisdotca/kyogijo-stadiums/sound"; * const periods = [{ start: 0, end: 100 }, { start: 120, end: 220 }]; * console.log(excitementAt({ t: 50, start: 0, end: 220, periods, score: { home: 0, away: 0 } })); * console.log(excitementAt({ t: 110, start: 0, end: 220, periods })); * console.log(excitementAt({ t: 200, start: 0, end: 220, periods, score: { home: 2, away: 1 } })); * console.log(excitementAt({ t: 60, start: 0, end: 220, periods, sinceGoal: 2 })); * // engaged * // murmur * // loud * // roar * ``` */ export declare function excitementAt(moment: GameMoment): SoundLevel; /** The kind of moment a timeline's event is, or `undefined` for one with no cue (a pass). */ export declare function cueKindOf(event: Pick): CueKind | undefined; /** * The voices an event calls on a surface: its kind's cue in the sport's set, or none. * @example * ```ts * import { cuesOf } from "@johnmorrisdotca/kyogijo-stadiums/sound"; * console.log(cuesOf({ kind: "goal" }, "nhl").join(), cuesOf({ kind: "goal" }, "soccer").join(), cuesOf({ kind: "whistle" }, "nba").join()); * console.log(cuesOf({ kind: "pass" }, "nhl").length, cuesOf({ kind: "goal" }, "a-surface-with-no-sound").length); * // horn,swell swell whistle * // 0 0 * ``` */ export declare function cuesOf(event: Pick, sport: string): readonly SoundVoice[]; /** A cue to play: its voice, the event that called it, and the time on the timeline's clock it belongs to. */ export interface SoundCue { voice: SoundVoice; kind: CueKind; t: number; team?: "home" | "away"; } /** * The cues of a move of a replay: the events it went by and the periods it began or ended, each with its voices. Only a move made by the clock playing (`tick`) or by a step forward calls * cues; a seek, a jump back, a pause or a change of speed calls none, as scrubbing announces nothing. The end of the last period is the game's end. * @example * ```ts * import { cuesOfChange } from "@johnmorrisdotca/kyogijo-stadiums/sound"; * const state = { t: 10, start: 0, end: 60, playing: true, ended: false, speed: 1, loop: false, motion: "smooth" as const, follow: "off" as const, followHeld: false }; * const change = { state, reason: "tick" as const, crossed: [{ t: 9.5, kind: "goal", team: "home" as const }] }; * console.log(cuesOfChange(change, 9, "nhl").map((c) => c.voice).join()); * console.log(cuesOfChange({ ...change, reason: "seek" as const }, 9, "nhl").length); * // horn,swell * // 0 * ``` */ export declare function cuesOfChange(change: ReplayChange, from: number, sport: string, periods?: readonly SoundPeriod[]): SoundCue[];