audio/ui
Toggle Mode D
Copy to Clipboardpnpm dlx shadcn@latest add @audio-ui/use-demo-source
Copy to Clipboardimport { useDemoSource, useDemoSound } from "@/hooks/use-demo-source";
| Files | hooks/use-demo-source.ts |
|---|---|
| Depends on | demo-sound, use-audio-session, use-device-loop, use-play-switch, web-audio |
| npm | Nothing |
| Used by | block-auto-pan, block-bass-enhancer, block-binaural-panner, block-channel-eq, block-chorus, block-compander, block-compressor, block-deesser, block-delay, block-device-chain, block-distortion, block-ducker, block-equalizer, block-exciter, block-expander, block-filter, block-frequency-shifter, block-gate, block-graphic-eq, block-limiter, block-lofi, block-mid-side, block-multiband, block-overdrive, block-phaser, block-redux, block-reverb, block-rotary, block-saturator, block-stutter, block-tilt-eq, block-transient, block-unlimiter, block-utility, block-vibe, block-wah |
| Export | Kind | What it is |
|---|---|---|
useDemoSource | function | The sound a device plays: the one chosen in its session, such as from a preview's bar, else fallback, the one that shows best what the device does. |
useDemoSound | function | The demo sound a device plays (useDemoSource), rendered for the page's context, with the kick that goes with it as a sidechain key when key is set: the sound of useDeviceLoop. |
Usage
The sound a device plays: the one chosen in its session, such as from a preview's bar, else fallback, the one that shows best what the device does. It tells the session its fallback, so a bar offers the choice only where there is one.
Copy to Clipboardimport { useDemoSource } from "@/hooks/use-demo-source"; const name = useDemoSource("groove"); // one of DEMO_SOURCES
The sounds are demo-sound's, made in code. Outside a session it is always fallback.
useDemoSound(fallback, { key }) renders that sound for the page's context, with the kick that goes with it when key is set: the sound of useDeviceLoop. It renders once the session's play switch is on, so no audio context is made before a press, and is null until then.
Copy to Clipboardimport { useDemoSound } from "@/hooks/use-demo-source"; const sound = useDemoSound("groove");