@zsherman/sound 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/LICENSE +373 -0
- package/README.md +16 -2
- package/dist/dom/engine/cues.js +69 -0
- package/dist/dom/engine/engine.js +104 -0
- package/dist/dom/engine/index.js +4 -0
- package/dist/dom/engine/synth.js +172 -0
- package/dist/dom/engine/types.js +0 -0
- package/dist/dom/index.js +9 -0
- package/dist/dom/sound-provider/index.js +1 -0
- package/dist/dom/sound-provider/sound-provider.js +75 -0
- package/dist/dom/themes/glass.js +47 -0
- package/dist/dom/themes/index.js +5 -0
- package/dist/dom/themes/mechanical.js +46 -0
- package/dist/dom/themes/score.js +210 -0
- package/dist/dom/themes/soft.js +28 -0
- package/dist/solid/engine/cues.jsx +69 -0
- package/dist/solid/engine/engine.jsx +104 -0
- package/dist/solid/engine/index.jsx +4 -0
- package/dist/solid/engine/synth.jsx +172 -0
- package/dist/solid/engine/types.jsx +0 -0
- package/dist/solid/index.jsx +9 -0
- package/dist/solid/sound-provider/index.jsx +1 -0
- package/dist/solid/sound-provider/sound-provider.jsx +66 -0
- package/dist/solid/themes/glass.jsx +47 -0
- package/dist/solid/themes/index.jsx +5 -0
- package/dist/solid/themes/mechanical.jsx +46 -0
- package/dist/solid/themes/score.jsx +210 -0
- package/dist/solid/themes/soft.jsx +28 -0
- package/dist/types/engine/cues.d.ts +21 -0
- package/dist/types/engine/engine.d.ts +42 -0
- package/dist/types/engine/index.d.ts +6 -0
- package/dist/types/engine/synth.d.ts +28 -0
- package/dist/types/engine/types.d.ts +65 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/sound-provider/index.d.ts +2 -0
- package/dist/types/sound-provider/sound-provider.d.ts +55 -0
- package/dist/types/themes/glass.d.ts +7 -0
- package/dist/types/themes/index.d.ts +5 -0
- package/dist/types/themes/mechanical.d.ts +7 -0
- package/dist/types/themes/score.d.ts +14 -0
- package/dist/types/themes/soft.d.ts +6 -0
- package/docs/api.json +55 -0
- package/docs/llms.txt +39 -0
- package/docs/search-index.json +25 -0
- package/docs/sound-provider.md +152 -0
- package/docs/sounds.md +203 -0
- package/package.json +56 -4
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { defineTheme } from "./score.jsx";
|
|
2
|
+
// src/themes/soft.ts
|
|
3
|
+
/**
|
|
4
|
+
* Soft: warm mallets in a small room. Each tone gets a quiet second harmonic that dies first, so it reads as
|
|
5
|
+
* struck; noise is darker and lower. The default, for most products.
|
|
6
|
+
*/
|
|
7
|
+
const soft = /* @__PURE__ */ defineTheme("soft", .16, 1, (layer) => {
|
|
8
|
+
if (layer.kind === "noise") return [{
|
|
9
|
+
...layer,
|
|
10
|
+
f: layer.f * .8,
|
|
11
|
+
to: layer.to && layer.to * .8,
|
|
12
|
+
peak: layer.peak * .7
|
|
13
|
+
}];
|
|
14
|
+
const body = {
|
|
15
|
+
...layer,
|
|
16
|
+
a: Math.max(layer.a ?? 0, .003),
|
|
17
|
+
d: layer.d * 1.1
|
|
18
|
+
};
|
|
19
|
+
const overtone = layer.f * 2;
|
|
20
|
+
return overtone > 12e3 ? [body] : [body, {
|
|
21
|
+
...body,
|
|
22
|
+
f: overtone,
|
|
23
|
+
to: layer.to && layer.to * 2,
|
|
24
|
+
peak: layer.peak * .15,
|
|
25
|
+
d: layer.d * .45
|
|
26
|
+
}];
|
|
27
|
+
});
|
|
28
|
+
export { soft };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Cue } from "./types.js";
|
|
2
|
+
/** Every cue, by family, in the order the docs list them. */
|
|
3
|
+
export declare const cueFamilies: {
|
|
4
|
+
readonly input: readonly ["tap", "type", "tick", "drag", "drop"];
|
|
5
|
+
readonly selection: readonly ["toggle-on", "toggle-off", "check", "uncheck", "select"];
|
|
6
|
+
readonly navigation: readonly ["open", "close", "expand", "collapse", "navigate"];
|
|
7
|
+
readonly feedback: readonly ["success", "warning", "error", "denied"];
|
|
8
|
+
readonly communication: readonly ["notify", "send", "receive"];
|
|
9
|
+
readonly editing: readonly ["copy", "delete", "complete"];
|
|
10
|
+
readonly call: readonly ["mute", "unmute", "muted-speaking", "participant-join", "participant-leave", "call-join", "call-leave", "knock", "hand-raise", "recording-start", "recording-stop", "share-start", "share-stop", "reconnecting", "reconnected"];
|
|
11
|
+
};
|
|
12
|
+
/** Every cue's name. */
|
|
13
|
+
export declare const cueNames: readonly Cue[];
|
|
14
|
+
/**
|
|
15
|
+
* The shortest gap between two plays of one cue, in ms; a play inside it is dropped. Keys repeat and sliders
|
|
16
|
+
* step faster than the rest, and their cues are shorter. People join and leave in bursts (a meeting's start,
|
|
17
|
+
* a breakout room closing): one cue for the burst, not one per person.
|
|
18
|
+
*/
|
|
19
|
+
export declare const cooldown: (cue: Cue) => 40 | 60 | 1500;
|
|
20
|
+
/** Keys and slider steps repeat fast: they reach the room at a quarter, so their tails don't pile up. */
|
|
21
|
+
export declare const roomShare: (cue: Cue) => 0.25 | 1;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Cue, PlayOptions, PlayedCue, SoundTheme } from "./types.js";
|
|
2
|
+
export interface SoundEngineOptions {
|
|
3
|
+
/** The recipes cues play (default `soft`). */
|
|
4
|
+
theme?: SoundTheme;
|
|
5
|
+
/** 0 to 1 (default 0.7). Perceptual: half is about a quarter of the level. */
|
|
6
|
+
volume?: number;
|
|
7
|
+
/** Plays nothing while true. */
|
|
8
|
+
muted?: boolean;
|
|
9
|
+
/** Varies each play by up to ±15 cents and ±5 % level, so repeats don't sound stamped (default true). */
|
|
10
|
+
humanize?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface SoundEngine {
|
|
13
|
+
/**
|
|
14
|
+
* Plays a cue now. Returns false when it was muted, inside its cooldown (60 ms; 40 ms for `type` and
|
|
15
|
+
* `tick`), on the server, or dropped because the browser hasn't allowed audio yet.
|
|
16
|
+
*/
|
|
17
|
+
play(cue: Cue, options?: PlayOptions): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Starts audio from a tap, click or key press (a "Turn sound on" button's handler). Resolves true once
|
|
20
|
+
* audio runs, false when the browser doesn't allow it yet (outside a gesture, within 300 ms); never
|
|
21
|
+
* rejects. Plays from other handlers start audio themselves, so this is rarely needed.
|
|
22
|
+
*/
|
|
23
|
+
unlock(): Promise<boolean>;
|
|
24
|
+
/** Changes the theme, volume, mute or humanizing. */
|
|
25
|
+
set(options: SoundEngineOptions): void;
|
|
26
|
+
/** The current settings. */
|
|
27
|
+
get(): Readonly<Required<SoundEngineOptions>>;
|
|
28
|
+
/** Calls `listener` with every cue the engine accepts. Returns the unsubscribe. */
|
|
29
|
+
subscribe(listener: (played: PlayedCue) => void): () => void;
|
|
30
|
+
/** Closes the audio context and drops the listeners. */
|
|
31
|
+
dispose(): void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The sound engine: plays cues by building them from oscillators and filtered noise at play time. Safe to
|
|
35
|
+
* create on the server and before any gesture: the audio context starts at the first play the browser
|
|
36
|
+
* allows (after the page's first tap, click or key press), and cues before that are dropped, not queued.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* const sound = createSoundEngine({ volume: 0.6 });
|
|
40
|
+
* button.addEventListener("click", () => sound.play("success"));
|
|
41
|
+
*/
|
|
42
|
+
export declare function createSoundEngine(options?: SoundEngineOptions): SoundEngine;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createSoundEngine } from "./engine.js";
|
|
2
|
+
export type { SoundEngine, SoundEngineOptions } from "./engine.js";
|
|
3
|
+
export { renderCue, cueDuration } from "./synth.js";
|
|
4
|
+
export type { RenderOptions } from "./synth.js";
|
|
5
|
+
export { cueFamilies, cueNames } from "./cues.js";
|
|
6
|
+
export type { Cue, CueEmphasis, CueOptions, Layer, NoiseLayer, PlayOptions, PlayedCue, SoundTheme, ToneLayer, } from "./types.js";
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Cue, PlayOptions, SoundTheme } from "./types.js";
|
|
2
|
+
/** The most layers one cue plays; a theme's extra layers are ignored. */
|
|
3
|
+
export declare const MAX_LAYERS = 12;
|
|
4
|
+
/** The output every cue feeds: a master gain into a limiter, and the room's send. */
|
|
5
|
+
export interface Bus {
|
|
6
|
+
/** Dry input: the master gain. */
|
|
7
|
+
input: GainNode;
|
|
8
|
+
/** Room input: into the convolver, which feeds `input`. */
|
|
9
|
+
room: GainNode;
|
|
10
|
+
}
|
|
11
|
+
/** Builds the master chain on a context: master gain → limiter → speakers, and the room into the master. */
|
|
12
|
+
export declare function createBus(ctx: BaseAudioContext, limiter?: boolean): Bus;
|
|
13
|
+
/** How long a cue's layers ring, in seconds, before the room's tail. */
|
|
14
|
+
export declare function cueDuration(theme: SoundTheme, cue: Cue, options?: PlayOptions): number;
|
|
15
|
+
/** Plays a cue on `bus` at `when` (the context's clock). Returns when its layers end. */
|
|
16
|
+
export declare function scheduleCue(ctx: BaseAudioContext, bus: Bus, theme: SoundTheme, cue: Cue, options: PlayOptions, when: number, volume: number, humanize: boolean): number;
|
|
17
|
+
/** Options for an offline render. */
|
|
18
|
+
export interface RenderOptions extends PlayOptions {
|
|
19
|
+
/** Sample rate (default 48000). */
|
|
20
|
+
sampleRate?: number;
|
|
21
|
+
/** Run it through the limiter, as the engine plays it (default true). */
|
|
22
|
+
limiter?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Renders a cue to an `AudioBuffer` without a speaker (an `OfflineAudioContext`): for tests, waveforms, or a
|
|
26
|
+
* WAV file. No humanizing, so a render is the same every time. Browser only.
|
|
27
|
+
*/
|
|
28
|
+
export declare function renderCue(theme: SoundTheme, cue: Cue, options?: RenderOptions): Promise<AudioBuffer>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Cue, CueOptions } from "@zsherman/kit/cues";
|
|
2
|
+
export type { Cue, CueEmphasis, CueOptions } from "@zsherman/kit/cues";
|
|
3
|
+
interface LayerBase {
|
|
4
|
+
/** Where the layer starts, in seconds after the cue does (default 0). */
|
|
5
|
+
at?: number;
|
|
6
|
+
/** Rise to the peak, in seconds (default 0.002: struck, not swelled). */
|
|
7
|
+
a?: number;
|
|
8
|
+
/** Fall from the peak to silence, in seconds. */
|
|
9
|
+
d: number;
|
|
10
|
+
/** Peak level, 0 to 0.5 (linear; 0.25 is about −12 dBFS before the theme's gain). */
|
|
11
|
+
peak: number;
|
|
12
|
+
/** Start frequency, in Hz: the tone's pitch or the noise filter's centre. */
|
|
13
|
+
f: number;
|
|
14
|
+
/** Frequency it sweeps to, in Hz (exponentially). */
|
|
15
|
+
to?: number;
|
|
16
|
+
/** How long the sweep takes, in seconds (default: the attack plus the decay). */
|
|
17
|
+
glide?: number;
|
|
18
|
+
/** An ornament: left out at `emphasis="subtle"`, louder at `strong`. */
|
|
19
|
+
accent?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** An oscillator under an envelope. */
|
|
22
|
+
export interface ToneLayer extends LayerBase {
|
|
23
|
+
kind: "tone";
|
|
24
|
+
wave: "sine" | "triangle" | "square" | "sawtooth";
|
|
25
|
+
}
|
|
26
|
+
/** Filtered white noise under an envelope: contact, air, a swish. */
|
|
27
|
+
export interface NoiseLayer extends LayerBase {
|
|
28
|
+
kind: "noise";
|
|
29
|
+
filter: "bandpass" | "lowpass" | "highpass";
|
|
30
|
+
/** The filter's resonance (default 1). */
|
|
31
|
+
q?: number;
|
|
32
|
+
}
|
|
33
|
+
export type Layer = ToneLayer | NoiseLayer;
|
|
34
|
+
/** A set of recipes, one per cue, and how it sits in the room. */
|
|
35
|
+
export interface SoundTheme {
|
|
36
|
+
/** Shown in pickers and reported in the trace. */
|
|
37
|
+
name: string;
|
|
38
|
+
/** How much reaches the shared room, 0 (dry) to 1. */
|
|
39
|
+
room: number;
|
|
40
|
+
/** A level trim so themes play equally loud (1 = as written). */
|
|
41
|
+
gain: number;
|
|
42
|
+
/** The layers each cue plays, at most 12 (`MAX_LAYERS`). */
|
|
43
|
+
cues: Record<Cue, readonly Layer[]>;
|
|
44
|
+
}
|
|
45
|
+
/** Options for one cue. */
|
|
46
|
+
export interface PlayOptions extends CueOptions {
|
|
47
|
+
/** 0 to 1, times the engine's volume (default 1). */
|
|
48
|
+
volume?: number;
|
|
49
|
+
/** Semitones up (or down, negative). */
|
|
50
|
+
pitch?: number;
|
|
51
|
+
/** Plays this cue from another theme. */
|
|
52
|
+
theme?: SoundTheme;
|
|
53
|
+
}
|
|
54
|
+
/** A cue the engine accepted (not muted, not inside its cooldown), as `subscribe` reports it. */
|
|
55
|
+
export interface PlayedCue {
|
|
56
|
+
cue: Cue;
|
|
57
|
+
/** The theme it played in. */
|
|
58
|
+
theme: string;
|
|
59
|
+
options: PlayOptions;
|
|
60
|
+
/**
|
|
61
|
+
* False when the browser hadn't allowed audio yet (no tap, click or key press on the page so far) or the
|
|
62
|
+
* page was hidden: the cue was dropped, not queued.
|
|
63
|
+
*/
|
|
64
|
+
sounded: boolean;
|
|
65
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { JSX } from "@solidjs/web";
|
|
2
|
+
import { type Cue } from "@zsherman/kit/cues";
|
|
3
|
+
import { type SoundEngine } from "../engine/engine.js";
|
|
4
|
+
import type { PlayOptions, SoundTheme } from "../engine/types.js";
|
|
5
|
+
export interface SoundProviderProps {
|
|
6
|
+
/**
|
|
7
|
+
* The theme cues play in: `soft` (the default), `mechanical` or `glass` from `@zsherman/sound/themes`, or
|
|
8
|
+
* your own. Nested, it changes the theme for that part of the page.
|
|
9
|
+
*/
|
|
10
|
+
theme?: SoundTheme;
|
|
11
|
+
/** 0 to 1, times the engine's volume (and an outer provider's). */
|
|
12
|
+
volume?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Silences everything inside. Keep the person's choice (a Sound switch in settings, saved in
|
|
15
|
+
* `localStorage`) and pass it here; nested, it silences one region.
|
|
16
|
+
*/
|
|
17
|
+
muted?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Plays another cue in place of one, or none (`false`): `{ navigate: false, "toggle-on": "check" }`.
|
|
20
|
+
* Applies to the kit's components and to `useSound().play`.
|
|
21
|
+
*/
|
|
22
|
+
cues?: Partial<Record<Cue, Cue | false>>;
|
|
23
|
+
/**
|
|
24
|
+
* The engine to play through. By default the outermost provider makes one (soft theme, volume 0.7), and
|
|
25
|
+
* nested providers share it. Pass your own (`createSoundEngine`) to share it with code outside Solid.
|
|
26
|
+
*/
|
|
27
|
+
engine?: SoundEngine;
|
|
28
|
+
children?: JSX.Element;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Turns on the kit's sounds: inside it, components play their cues (a Switch `toggle-on`, a Dialog `open`, a
|
|
32
|
+
* toast `success`). Without it the kit is silent and none of the engine is in the bundle. No sound plays
|
|
33
|
+
* before the person's first tap, click or key press on the page.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* <SoundProvider muted={!soundOn()}>
|
|
37
|
+
* <App />
|
|
38
|
+
* </SoundProvider>
|
|
39
|
+
*/
|
|
40
|
+
export declare function SoundProvider(props: SoundProviderProps): JSX.Element;
|
|
41
|
+
export interface SoundControls {
|
|
42
|
+
/** Plays a cue through the nearest provider (its mute, map, theme and volume); outside one, nothing. */
|
|
43
|
+
play: (cue: Cue, options?: PlayOptions) => void;
|
|
44
|
+
/** The provider's engine (made on first use), for `subscribe` or `unlock`; undefined outside a provider. */
|
|
45
|
+
engine: () => SoundEngine | undefined;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Plays cues from your own code: a sent message, a finished upload, a game. Call `play` from the handler, after
|
|
49
|
+
* the visible change.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* const sound = useSound();
|
|
53
|
+
* <Button onClick={() => { save(); sound.play("success"); }}>Save</Button>
|
|
54
|
+
*/
|
|
55
|
+
export declare function useSound(): SoundControls;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SoundTheme } from "../engine/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Glass: bright struck bars that ring. Tones go up a fifth and last longer, with the inharmonic partials of a
|
|
4
|
+
* free bar (2.76× and 5.4×) dying away first; noise rings through narrow filters; a larger room. For calm,
|
|
5
|
+
* airy products and moments that should feel light.
|
|
6
|
+
*/
|
|
7
|
+
export declare const glass: SoundTheme;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SoundTheme } from "../engine/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Mechanical: dry keycaps and switches. Each tone becomes a contact click (narrow noise) over a short
|
|
4
|
+
* triangle body and a low thock; transients halve, and there's almost no room. For tools, terminals and
|
|
5
|
+
* dense, fast UI.
|
|
6
|
+
*/
|
|
7
|
+
export declare const mechanical: SoundTheme;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Cue, Layer, SoundTheme } from "../engine/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Every theme plays the same gestures: the same notes, rhythm and sweeps per cue, so a cue means one thing
|
|
4
|
+
* whichever theme plays it (on rises and off falls; success resolves upward, error falls and darkens). A
|
|
5
|
+
* theme's voice decides the timbre. Outcome cues (warning, error, denied) are triangles, a little buzzier
|
|
6
|
+
* than the rest, so they don't read as confirmations.
|
|
7
|
+
*/
|
|
8
|
+
export declare const score: Record<Cue, readonly Layer[]>;
|
|
9
|
+
/** Turns one layer of the score into a theme's layers. */
|
|
10
|
+
export type Voice = (layer: Layer) => Layer[];
|
|
11
|
+
/** A theme from the shared score and a voice. */
|
|
12
|
+
export declare function defineTheme(name: string, room: number, gain: number, voice: Voice): SoundTheme;
|
|
13
|
+
/** Partials above this are dropped: small speakers don't play them, and they only sting. */
|
|
14
|
+
export declare const CEILING = 12000;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SoundTheme } from "../engine/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Soft: warm mallets in a small room. Each tone gets a quiet second harmonic that dies first, so it reads as
|
|
4
|
+
* struck; noise is darker and lower. The default, for most products.
|
|
5
|
+
*/
|
|
6
|
+
export declare const soft: SoundTheme;
|
package/docs/api.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"sound-provider": {
|
|
3
|
+
"components": {
|
|
4
|
+
"SoundProvider": {
|
|
5
|
+
"props": [
|
|
6
|
+
{
|
|
7
|
+
"name": "children",
|
|
8
|
+
"type": "Element",
|
|
9
|
+
"description": "",
|
|
10
|
+
"required": false,
|
|
11
|
+
"from": "kit"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"name": "cues",
|
|
15
|
+
"type": "Partial<Record<Cue, false | Cue>>",
|
|
16
|
+
"description": "Plays another cue in place of one, or none (`false`): `{ navigate: false, \"toggle-on\": \"check\" }`. Applies to the kit's components and to `useSound().play`.",
|
|
17
|
+
"required": false,
|
|
18
|
+
"from": "kit"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "engine",
|
|
22
|
+
"type": "SoundEngine",
|
|
23
|
+
"description": "The engine to play through. By default the outermost provider makes one (soft theme, volume 0.7), and nested providers share it. Pass your own (`createSoundEngine`) to share it with code outside Solid.",
|
|
24
|
+
"required": false,
|
|
25
|
+
"from": "kit"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"name": "muted",
|
|
29
|
+
"type": "boolean",
|
|
30
|
+
"description": "Silences everything inside. Keep the person's choice (a Sound switch in settings, saved in `localStorage`) and pass it here; nested, it silences one region.",
|
|
31
|
+
"required": false,
|
|
32
|
+
"from": "kit"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "theme",
|
|
36
|
+
"type": "SoundTheme",
|
|
37
|
+
"description": "The theme cues play in: `soft` (the default), `mechanical` or `glass` from `@zsherman/sound/themes`, or your own. Nested, it changes the theme for that part of the page.",
|
|
38
|
+
"required": false,
|
|
39
|
+
"from": "kit"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"name": "volume",
|
|
43
|
+
"type": "number",
|
|
44
|
+
"description": "0 to 1, times the engine's volume (and an outer provider's).",
|
|
45
|
+
"required": false,
|
|
46
|
+
"from": "kit"
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"dataAttributes": [],
|
|
50
|
+
"cssVariables": [],
|
|
51
|
+
"state": []
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
package/docs/llms.txt
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @zsherman/sound
|
|
2
|
+
|
|
3
|
+
> Interface sounds for @zsherman/kit: 40 cues (tap, toggle, open, success, notify, …, and video-call cues: mute, someone joining, recording, a knock) built from Web Audio oscillators and filtered noise when they play, so there are no audio files to load or license, in three loudness-matched themes (soft, mechanical, glass). A `SoundProvider` turns on the kit's own cues (a Switch plays `toggle-on`, a Dialog `open`, a toast `success`); without one the kit stays silent and none of this package is in the bundle. Framework-free engine for code outside Solid.
|
|
4
|
+
|
|
5
|
+
Read this file first, then the pages for what you use. These docs ship in the package, so they match the installed version.
|
|
6
|
+
|
|
7
|
+
## Setup
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @zsherman/sound @zsherman/kit solid-js@^2 @solidjs/web@^2
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
No stylesheet. Put the provider at the root, with a mute the person controls:
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { SoundProvider } from "@zsherman/sound/sound-provider";
|
|
17
|
+
|
|
18
|
+
<SoundProvider muted={!soundOn()}>
|
|
19
|
+
<App />
|
|
20
|
+
</SoundProvider>;
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Common tasks:
|
|
24
|
+
|
|
25
|
+
- Turn on the kit's sounds, with a mute that remembers: [sound-provider.md](./sound-provider.md)
|
|
26
|
+
- Which kit component plays which cue: [sound-provider.md#kit-components](./sound-provider.md#kit-components)
|
|
27
|
+
- Play a cue from your own code (a sent message, a finished upload): [sound-provider.md#your-own-cues](./sound-provider.md#your-own-cues)
|
|
28
|
+
- Silence one region, or change a cue: [sound-provider.md#nesting-and-remapping](./sound-provider.md#nesting-and-remapping)
|
|
29
|
+
- Every cue, and when to use it: [sounds.md#cues](./sounds.md#cues)
|
|
30
|
+
- Video-call sounds (mute, joining, recording, knocks, the connection): [sounds.md#cues](./sounds.md#cues), then `@zsherman/meeting`'s call-controls.md and tile-layout.md
|
|
31
|
+
- When not to play a sound: [sounds.md#when-not-to-play](./sounds.md#when-not-to-play)
|
|
32
|
+
- Themes, and writing your own: [sounds.md#themes](./sounds.md#themes)
|
|
33
|
+
- The engine without Solid, and rendering a cue to a buffer: [sounds.md#engine](./sounds.md#engine)
|
|
34
|
+
|
|
35
|
+
## Components
|
|
36
|
+
|
|
37
|
+
- `@zsherman/sound/sound-provider` — `SoundProvider` (`theme`, `volume`, `muted`, `cues` remap, `engine`; nests), `useSound()` (`play`, `engine`) — [sound-provider.md](./sound-provider.md)
|
|
38
|
+
- `@zsherman/sound/engine` — `createSoundEngine` (`play`, `unlock`, `set`, `get`, `subscribe`, `dispose`), `renderCue` (offline `AudioBuffer`), `cueDuration`, `cueFamilies`, `cueNames`; types `Cue`, `Layer`, `SoundTheme`, `PlayOptions`, `PlayedCue` — [sounds.md](./sounds.md)
|
|
39
|
+
- `@zsherman/sound/themes` — `soft` (default), `mechanical`, `glass`, `defineTheme`, `score` — [sounds.md](./sounds.md)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{"records":[
|
|
2
|
+
{"id":"sound-provider.md","kind":"page","title":"Sound provider","page":"Sound provider","doc":"sound-provider.md","entry":"@zsherman/sound/sound-provider","keywords":"sound provider, enable sounds, turn on sound, mute, sound toggle, sound setting, volume, ui sounds, play sound, useSound","text":"Turns on the kit's sounds. Inside a SoundProvider, components play their cues when the person uses them: a Switch toggle-on, a Dialog open, a toast success. Outside one the kit is silent, and none of @zsherman/sound is in your bundle (the kit carries only the names of its cues)."},
|
|
3
|
+
{"id":"sound-provider.md#usage-guidelines","kind":"section","title":"Usage guidelines","page":"Sound provider","doc":"sound-provider.md","anchor":"usage-guidelines","text":"Put one at the root, around everything that should be heard. Give the person a mute and remember it. Keep the choice in your own state (a Sound switch in settings, saved in localStorage or their profile) and pass it as muted. Default to on or off as suits your product; off is the safe default for a work tool used in shared spaces. Nothing plays before the person's first tap, click or key press on the page (browsers block it); cues before that are dropped, not saved for later. Let the kit's components play their own cues, and add yours only for outcomes the kit can't see: a sent message, a finished upload."},
|
|
4
|
+
{"id":"sound-provider.md#anatomy","kind":"section","title":"Anatomy","page":"Sound provider","doc":"sound-provider.md","anchor":"anatomy","text":"","code":"SoundProvider App muted useSound play cue options engine"},
|
|
5
|
+
{"id":"sound-provider.md#a-mute-that-remembers","kind":"section","title":"A mute that remembers","page":"Sound provider","doc":"sound-provider.md","anchor":"a-mute-that-remembers","text":"","code":"Label zsherman kit label Switch switch SoundProvider sound sound-provider createSignal onSettled Root setOn saved localStorage getItem toggle next setItem off checked onCheckedChange Sound muted App"},
|
|
6
|
+
{"id":"sound-provider.md#kit-components","kind":"section","title":"Kit components","page":"Sound provider","doc":"sound-provider.md","anchor":"kit-components","text":"Each plays its cue for what the person does (a press, a key, a drag, a swipe), not for a change your code makes. Switch · toggle-on / toggle-off Checkbox · check / uncheck RadioGroup, SegmentedControl, Select, Combobox · select Rating · select, pitched by the score Slider · tick, pitched by the value (dropped within 40 ms of the last, so a drag doesn't chatter) Tabs · navigate; back when the new tab comes before the old one Dialog, Sheet, AlertDialog · open / close Accordion, Collapsible · expand / collapse Toasts (ToastRegion) · success, warning, error by type; notify for info and plain toasts; a loading toast plays its outcome when it settles CopyButton · copy; error when copying fails Button, IconButton · nothing, unless you give one a sound: <Button sound=\"send\"> Menus, popovers, tooltips and the command palette stay silent: they open too often to be heard each time."},
|
|
7
|
+
{"id":"sound-provider.md#your-own-cues","kind":"section","title":"Your own cues","page":"Sound provider","doc":"sound-provider.md","anchor":"your-own-cues","text":"useSound().play plays through the nearest provider, with its mute, its remapping, its theme and its volume (outside a provider it does nothing). Call it from the handler, once the change is visible. useSound().engine() is the provider's engine, for subscribe (a trace of what played) or unlock (a \"Turn sound on\" button). See sounds.md#engine.","code":"useSound zsherman sound sound-provider Composer submit send draft play Button onClick Send"},
|
|
8
|
+
{"id":"sound-provider.md#nesting-and-remapping","kind":"section","title":"Nesting and remapping","page":"Sound provider","doc":"sound-provider.md","anchor":"nesting-and-remapping","text":"A provider inside another shares its engine and adds its own settings on top: an outer mute silences everything, and an inner one silences its region. cues plays another cue in place of one, or none (false), for the kit's components and useSound().play alike:","code":"SoundProvider muted App ActivityFeed theme mechanical volume Editor cues navigate toggle-on check toggle-off uncheck"},
|
|
9
|
+
{"id":"sound-provider.md#routing-cues-elsewhere","kind":"section","title":"Routing cues elsewhere","page":"Sound provider","doc":"sound-provider.md","anchor":"routing-cues-elsewhere","text":"The kit asks for cues through CueContext (@zsherman/kit/cues), and the provider is what answers. To send the kit's cues somewhere else, such as haptics on a phone or an analytics event, provide your own player: cues.md in the kit's docs."},
|
|
10
|
+
{"id":"sound-provider.md#api-reference","kind":"section","title":"API reference","page":"Sound provider","doc":"sound-provider.md","anchor":"api-reference","text":""},
|
|
11
|
+
{"id":"sounds.md","kind":"page","title":"Sounds","page":"Sounds","doc":"sounds.md","keywords":"sound, sounds, audio, sfx, sound effects, ui sounds, interface sounds, click sound, feedback sound, chime, beep, haptic, earcon, web audio, notification sound, success sound, error sound","text":"40 short interface sounds, called cues, in seven families (six for any interface, one for video calls). Each is built from Web Audio oscillators and filtered noise at the moment it plays: there are no audio files to load, cache or license, and a cue can follow the moment (a slider's tick rises with its value; back turns a sweep around). Three themes play the same gestures in different materials, matched in loudness so switching one never makes the interface louder. Sound reinforces what the person sees; it never replaces it. Every cue the kit plays accompanies a visible change, and the interface must work the same with sound off."},
|
|
12
|
+
{"id":"sounds.md#usage-guidelines","kind":"section","title":"Usage guidelines","page":"Sounds","doc":"sounds.md","anchor":"usage-guidelines","text":"Turn sounds on with a SoundProvider at the root, and give the person a mute they control (sound-provider.md). The kit's components then play their own cues. Play a cue yourself only for an outcome the kit can't see (a message sent, an upload finished), from the handler, once the change is on screen. Play the outcome, not every step: one cue per action, and none for what your code changes on its own (see When not to play). Pick the cue by what happened, not by how it sounds: the families below are meanings, and a theme changes how all of them sound at once."},
|
|
13
|
+
{"id":"sounds.md#anatomy","kind":"section","title":"Anatomy","page":"Sounds","doc":"sounds.md","anchor":"anatomy","text":"","code":"SoundProvider muted theme volume cues App sound useSound play cue emphasis value direction pitch"},
|
|
14
|
+
{"id":"sounds.md#cues","kind":"section","title":"Cues","page":"Sounds","doc":"sounds.md","anchor":"cues","text":"Input · tap · A press that should be heard: a primary action, a key on a pad · Button sound=\"tap\" type · A keystroke in a field that wants a typing sound (a terminal, a game) · — tick · A step of a value: a slider, a stepper, a dial. Pass value (0 to 1) to re-pitch it · Slider drag · A drag starts (an item lifts) · — drop · It lands · — Selection · toggle-on / toggle-off · A switch turns on or off: siblings, a rising and a falling fifth · Switch check / uncheck · A checkbox · Checkbox select · One choice among several · RadioGroup, SegmentedControl, Select, Combobox, Rating (pitched by the score) Navigation · open / close · A modal surface opens or closes · Dialog, Sheet, AlertDialog expand / collapse · Content shows or hides in place · Accordion, Collapsible navigate · A tab or a step; direction: \"back\" for a previous one · Tabs (direction from the tabs' order) Feedback · success · An action finished well, after the fact (not on the press) · success toasts warning · Something needs attention but nothing failed · warning toasts error · An action failed · error toasts, CopyButton when copying fails denied · An action that can't happen now (a shortcut with nothing to act on) · — Communication · notify · Something arrived for the person: a mention, a reminder · info and plain toasts send · The person sent something · Button sound=\"send\" receive · A message arrived in an open conversation · — Editing · copy · Copied to the clipboard · CopyButton delete · Something was deleted (after it is, not on the confirm dialog's open) · Button sound=\"delete\" complete · A long task or a whole flow finished: an upload, an onboarding · — Call · mute / unmute · Your own microphone turns off or on · CallControlsDevice kind=\"microphone\" muted-speaking · You're talking while muted. Your app detects the voice; play it at most every 30 s or so · — participant-join / participant-leave · Someone else comes or goes. One per burst (1.5 s apart at most), and silent in calls over eight people · TileLayout (presenceSounds) call-join / call-leave · You're in the call, or out of it · CallControlButton sound=\"call-leave\" knock · Someone is waiting in the lobby (play it for the hosts) · — hand-raise · A hand goes up (play it for the hosts or the presenter) · — recording-start / recording-stop · A recording or transcript has started or stopped, for everyone in the call, and on joining a call that's being captured · CallControlsRecordingIndicator share-start / share-stop · A screen share appears or ends · TileLayout (a tile with isScreenShare) reconnecting / reconnected · The connection dropped, or it's back · — Call cues play over people talking, so they sit lower (about 400 to 1,200 Hz), stay short and are quieter than the outcome cues. Recording has its own rhythm (two even pulses, then a held note) so it can't be mistaken for anything else. The call parts that play them are in @zsherman/meeting's docs (call-controls.md and tile-layout.md, under \"Sounds\"). Every cue also takes emphasis: subtle drops its ornaments and most of its room (for something that happens often), strong adds them (for a moment worth marking). Emphasis is not a volume knob: use volume for that.","code":"sound play success emphasis strong tick value navigate direction back"},
|
|
15
|
+
{"id":"sounds.md#when-not-to-play","kind":"section","title":"When not to play","page":"Sounds","doc":"sounds.md","anchor":"when-not-to-play","text":"Silence is the default. A sound earns its place when it tells the person something they'd otherwise miss or wait for. One cue per action. Don't stack tap, select and success on one press: play the outcome. No hover sounds, no sounds on scroll, focus, or a layout change the person didn't cause. Nothing for changes made in code: the kit plays cues only for what the person did (a press, a key, a drag, a swipe), never when your code sets a value. An outcome (success, a toast) is the exception, because it reports something the person started. Not per item in a list that updates (a feed, streamed tokens, every row of an import): one cue when it settles. Not in password fields, and not for every keystroke unless typing sound is the point. success only after it succeeded, delete only after the deletion happened. Menus, popovers and tooltips are silent in the kit: they open too often to be heard each time."},
|
|
16
|
+
{"id":"sounds.md#accessibility","kind":"section","title":"Accessibility","page":"Sounds","doc":"sounds.md","anchor":"accessibility","text":"Never the only channel: every cue pairs with a visible change, and nothing depends on hearing it. Offer a mute the person controls, and remember it (see sound-provider.md). A mute in settings is the minimum; a Sound switch near where sounds happen is better. No sound before the person interacts: browsers block audio until the first tap, click or key press, and the engine drops (not queues) cues until then, so a toast on page load is silent. Cues sit well below speech: they're short (most under a quarter of a second, keys and ticks 50 ms or less), peak below −5 dBFS before your volume, and frequent cues are the quietest, so they don't bury a screen reader. Sound is a separate preference from motion: prefers-reduced-motion doesn't mute it."},
|
|
17
|
+
{"id":"sounds.md#themes","kind":"section","title":"Themes","page":"Sounds","doc":"sounds.md","anchor":"themes","text":"soft (default) · Warm mallets in a small room · Most products mechanical · Dry keycaps and switches: a contact click over a short body, almost no room · Tools, terminals, dense and fast UI glass · Bright struck bars that ring, a larger room · Calm, airy products; moments that should feel light A theme is data: per cue, a list of layers (at most 12), each an oscillator or filtered noise under an envelope. Change a few cues of a built-in theme by spreading it: Or give the shared score (score: every cue's notes, rhythm and sweeps) a new voice with defineTheme(name, room, gain, voice), where voice turns each layer of the score into your layers. The built-in themes are made this way, so a cue keeps its meaning (on rises, error falls) in every theme: Keep a custom theme's peaks under about −3 dBFS and its loudness near the built-in themes': render cues with renderCue and measure them.","code":"glass zsherman sound themes SoundProvider theme SoundTheme name room gain cues Record Cue readonly Layer ToneLayer NoiseLayer kind tone wave sine triangle square sawtooth glide peak accent noise filter bandpass lowpass highpass engine soft branded notify defineTheme muted layer"},
|
|
18
|
+
{"id":"sounds.md#engine","kind":"section","title":"Engine","page":"Sounds","doc":"sounds.md","anchor":"engine","text":"The provider runs on a framework-free engine. Use it directly outside Solid, or pass one to SoundProvider engine={…} to share it. play(cue, options?) plays now and returns whether it was accepted. A repeat of one cue within 60 ms (40 ms for type and tick) is dropped, so a held key or a fast drag doesn't machine-gun. Each play varies by up to ±15 cents and ±5 % level, so repeats don't sound stamped (humanize: false turns it off). unlock() starts audio from a gesture's handler (\"Turn sound on\") and resolves true once it runs, false if the browser doesn't allow it yet; it never rejects. Plays from a handler start audio themselves. set({ theme, volume, muted, humanize }), get(). subscribe(listener) reports every accepted cue (sounded: false when it was dropped because audio wasn't allowed yet or the page was hidden). Returns the unsubscribe. dispose() closes the audio context. The engine is safe to create on the server: nothing touches the browser until the first play. Its audio context starts at the first play the browser allows and is suspended a few seconds after the last cue ends. Everything goes through a limiter, so cues that overlap don't clip. renderCue(theme, cue, options?) renders a cue to an AudioBuffer with an OfflineAudioContext (no speaker, no humanizing, the same every time): for tests, a waveform, or exporting a file. cueDuration(theme, cue) is how long its layers ring, in seconds. cueNames lists every cue; cueFamilies groups them as the table above does.","code":"createSoundEngine zsherman sound engine volume play success set muted stop subscribe cue theme sounded console log"},
|
|
19
|
+
{"id":"api:sound-provider/SoundProvider","kind":"part","title":"SoundProvider","page":"Sound provider","doc":"sound-provider.md","anchor":"soundprovider","entry":"@zsherman/sound/sound-provider","text":"SoundProvider from @zsherman/sound/sound-provider.","code":"cues engine muted theme volume"},
|
|
20
|
+
{"id":"api:sound-provider/SoundProvider.cues","kind":"prop","title":"cues","page":"Sound provider","parent":"SoundProvider","doc":"sound-provider.md","anchor":"soundprovider","entry":"@zsherman/sound/sound-provider","text":"Plays another cue in place of one, or none (false): { navigate: false, \"toggle-on\": \"check\" }. Applies to the kit's components and to useSound().play. Type: Partial<Record<Cue, false | Cue>>."},
|
|
21
|
+
{"id":"api:sound-provider/SoundProvider.engine","kind":"prop","title":"engine","page":"Sound provider","parent":"SoundProvider","doc":"sound-provider.md","anchor":"soundprovider","entry":"@zsherman/sound/sound-provider","text":"The engine to play through. By default the outermost provider makes one (soft theme, volume 0.7), and nested providers share it. Pass your own (createSoundEngine) to share it with code outside Solid. Type: SoundEngine."},
|
|
22
|
+
{"id":"api:sound-provider/SoundProvider.muted","kind":"prop","title":"muted","page":"Sound provider","parent":"SoundProvider","doc":"sound-provider.md","anchor":"soundprovider","entry":"@zsherman/sound/sound-provider","text":"Silences everything inside. Keep the person's choice (a Sound switch in settings, saved in localStorage) and pass it here; nested, it silences one region. Type: boolean."},
|
|
23
|
+
{"id":"api:sound-provider/SoundProvider.theme","kind":"prop","title":"theme","page":"Sound provider","parent":"SoundProvider","doc":"sound-provider.md","anchor":"soundprovider","entry":"@zsherman/sound/sound-provider","text":"The theme cues play in: soft (the default), mechanical or glass from @zsherman/sound/themes, or your own. Nested, it changes the theme for that part of the page. Type: SoundTheme."},
|
|
24
|
+
{"id":"api:sound-provider/SoundProvider.volume","kind":"prop","title":"volume","page":"Sound provider","parent":"SoundProvider","doc":"sound-provider.md","anchor":"soundprovider","entry":"@zsherman/sound/sound-provider","text":"0 to 1, times the engine's volume (and an outer provider's). Type: number."}
|
|
25
|
+
]}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Sound provider
|
|
2
|
+
|
|
3
|
+
<!-- search: sound provider, enable sounds, turn on sound, mute, sound toggle, sound setting, volume, ui sounds, play sound, useSound -->
|
|
4
|
+
|
|
5
|
+
Turns on the kit's sounds. Inside a `SoundProvider`, components play their cues when the person uses them: a Switch `toggle-on`, a Dialog `open`, a toast `success`. Outside one the kit is silent, and none of `@zsherman/sound` is in your bundle (the kit carries only the names of its cues).
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { SoundProvider } from "@zsherman/sound/sound-provider";
|
|
9
|
+
|
|
10
|
+
<SoundProvider muted={!soundOn()}>
|
|
11
|
+
<App />
|
|
12
|
+
</SoundProvider>;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage guidelines
|
|
16
|
+
|
|
17
|
+
- Put one at the root, around everything that should be heard.
|
|
18
|
+
- Give the person a mute and remember it. Keep the choice in your own state (a Sound switch in settings, saved in `localStorage` or their profile) and pass it as `muted`. Default to on or off as suits your product; off is the safe default for a work tool used in shared spaces.
|
|
19
|
+
- Nothing plays before the person's first tap, click or key press on the page (browsers block it); cues before that are dropped, not saved for later.
|
|
20
|
+
- Let the kit's components play their own cues, and add yours only for outcomes the kit can't see: a sent message, a finished upload.
|
|
21
|
+
|
|
22
|
+
## Anatomy
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
<SoundProvider // muted, volume, theme, cues, engine
|
|
26
|
+
<App /> // kit components inside play their cues
|
|
27
|
+
<SoundProvider muted /> // nested: settings for one region, same engine
|
|
28
|
+
</SoundProvider>
|
|
29
|
+
|
|
30
|
+
useSound().play(cue, options?) // your own cues, through the nearest provider
|
|
31
|
+
useSound().engine() // subscribe, unlock
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## A mute that remembers
|
|
35
|
+
|
|
36
|
+
```tsx
|
|
37
|
+
import { Label } from "@zsherman/kit/label";
|
|
38
|
+
import { Switch } from "@zsherman/kit/switch";
|
|
39
|
+
import { SoundProvider } from "@zsherman/sound/sound-provider";
|
|
40
|
+
import { createSignal, onSettled } from "solid-js";
|
|
41
|
+
|
|
42
|
+
function Root() {
|
|
43
|
+
const [on, setOn] = createSignal(true);
|
|
44
|
+
// Read after hydration, so the server's markup and the first client render agree.
|
|
45
|
+
onSettled(() => {
|
|
46
|
+
const saved = localStorage.getItem("sound");
|
|
47
|
+
if (saved) setOn(saved === "on");
|
|
48
|
+
});
|
|
49
|
+
const toggle = (next: boolean) => {
|
|
50
|
+
setOn(next);
|
|
51
|
+
localStorage.setItem("sound", next ? "on" : "off");
|
|
52
|
+
};
|
|
53
|
+
return (
|
|
54
|
+
<>
|
|
55
|
+
{/* Outside the provider: the switch that mutes everything doesn't play a cue itself. */}
|
|
56
|
+
<Label>
|
|
57
|
+
<Switch checked={on()} onCheckedChange={toggle} /> Sound
|
|
58
|
+
</Label>
|
|
59
|
+
<SoundProvider muted={!on()}>
|
|
60
|
+
<App />
|
|
61
|
+
</SoundProvider>
|
|
62
|
+
</>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Kit components
|
|
68
|
+
|
|
69
|
+
Each plays its cue for what the person does (a press, a key, a drag, a swipe), not for a change your code makes.
|
|
70
|
+
|
|
71
|
+
| Component | Cue |
|
|
72
|
+
| --- | --- |
|
|
73
|
+
| `Switch` | `toggle-on` / `toggle-off` |
|
|
74
|
+
| `Checkbox` | `check` / `uncheck` |
|
|
75
|
+
| `RadioGroup`, `SegmentedControl`, `Select`, `Combobox` | `select` |
|
|
76
|
+
| `Rating` | `select`, pitched by the score |
|
|
77
|
+
| `Slider` | `tick`, pitched by the value (dropped within 40 ms of the last, so a drag doesn't chatter) |
|
|
78
|
+
| `Tabs` | `navigate`; `back` when the new tab comes before the old one |
|
|
79
|
+
| `Dialog`, `Sheet`, `AlertDialog` | `open` / `close` |
|
|
80
|
+
| `Accordion`, `Collapsible` | `expand` / `collapse` |
|
|
81
|
+
| Toasts (`ToastRegion`) | `success`, `warning`, `error` by type; `notify` for `info` and plain toasts; a loading toast plays its outcome when it settles |
|
|
82
|
+
| `CopyButton` | `copy`; `error` when copying fails |
|
|
83
|
+
| `Button`, `IconButton` | nothing, unless you give one a `sound`: `<Button sound="send">` |
|
|
84
|
+
|
|
85
|
+
Menus, popovers, tooltips and the command palette stay silent: they open too often to be heard each time.
|
|
86
|
+
|
|
87
|
+
## Your own cues
|
|
88
|
+
|
|
89
|
+
`useSound().play` plays through the nearest provider, with its mute, its remapping, its theme and its volume (outside a provider it does nothing). Call it from the handler, once the change is visible.
|
|
90
|
+
|
|
91
|
+
```tsx
|
|
92
|
+
import { useSound } from "@zsherman/sound/sound-provider";
|
|
93
|
+
|
|
94
|
+
function Composer() {
|
|
95
|
+
const sound = useSound();
|
|
96
|
+
const submit = async () => {
|
|
97
|
+
await send(draft());
|
|
98
|
+
sound.play("send");
|
|
99
|
+
};
|
|
100
|
+
return <Button onClick={submit}>Send</Button>;
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`useSound().engine()` is the provider's engine, for `subscribe` (a trace of what played) or `unlock` (a "Turn sound on" button). See [sounds.md#engine](./sounds.md#engine).
|
|
105
|
+
|
|
106
|
+
## Nesting and remapping
|
|
107
|
+
|
|
108
|
+
A provider inside another shares its engine and adds its own settings on top: an outer mute silences everything, and an inner one silences its region.
|
|
109
|
+
|
|
110
|
+
```tsx
|
|
111
|
+
<SoundProvider muted={!on()}>
|
|
112
|
+
<App>
|
|
113
|
+
{/* The activity feed updates often: no cues from it. */}
|
|
114
|
+
<SoundProvider muted>
|
|
115
|
+
<ActivityFeed />
|
|
116
|
+
</SoundProvider>
|
|
117
|
+
{/* The editor clicks like a keyboard, at half the volume. */}
|
|
118
|
+
<SoundProvider theme={mechanical} volume={0.5}>
|
|
119
|
+
<Editor />
|
|
120
|
+
</SoundProvider>
|
|
121
|
+
</App>
|
|
122
|
+
</SoundProvider>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
`cues` plays another cue in place of one, or none (`false`), for the kit's components and `useSound().play` alike:
|
|
126
|
+
|
|
127
|
+
```tsx
|
|
128
|
+
<SoundProvider cues={{ navigate: false, "toggle-on": "check", "toggle-off": "uncheck" }}>
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Routing cues elsewhere
|
|
132
|
+
|
|
133
|
+
The kit asks for cues through `CueContext` (`@zsherman/kit/cues`), and the provider is what answers. To send the kit's cues somewhere else, such as haptics on a phone or an analytics event, provide your own player: [cues.md](../../kit/docs/cues.md) in the kit's docs.
|
|
134
|
+
|
|
135
|
+
## API reference
|
|
136
|
+
|
|
137
|
+
<!-- generated:props:sound-provider (node tooling/props-doc.ts; edit the JSDoc in the source, not this table) -->
|
|
138
|
+
|
|
139
|
+
Generated from the types of `@zsherman/sound/sound-provider`. Each part also takes its element's native and ARIA attributes.
|
|
140
|
+
|
|
141
|
+
#### `SoundProvider`
|
|
142
|
+
|
|
143
|
+
| Prop | Type | Default | Description |
|
|
144
|
+
| --- | --- | --- | --- |
|
|
145
|
+
| `children` | `Element` | | |
|
|
146
|
+
| `cues` | `Partial<Record<Cue, false \| Cue>>` | | Plays another cue in place of one, or none (`false`): `{ navigate: false, "toggle-on": "check" }`. Applies to the kit's components and to `useSound().play`. |
|
|
147
|
+
| `engine` | `SoundEngine` | | The engine to play through. By default the outermost provider makes one (soft theme, volume 0.7), and nested providers share it. Pass your own (`createSoundEngine`) to share it with code outside Solid. |
|
|
148
|
+
| `muted` | `boolean` | | Silences everything inside. Keep the person's choice (a Sound switch in settings, saved in `localStorage`) and pass it here; nested, it silences one region. |
|
|
149
|
+
| `theme` | `SoundTheme` | | The theme cues play in: `soft` (the default), `mechanical` or `glass` from `@zsherman/sound/themes`, or your own. Nested, it changes the theme for that part of the page. |
|
|
150
|
+
| `volume` | `number` | | 0 to 1, times the engine's volume (and an outer provider's). |
|
|
151
|
+
|
|
152
|
+
<!-- /generated:props:sound-provider -->
|