audio/ui
Toggle Mode D
Copy to Clipboardpnpm dlx shadcn@latest add @audio-ui/use-bake
Copy to Clipboardimport { renderEdited, useBake } from "@/hooks/use-bake";
| Files | hooks/use-bake.ts |
|---|---|
| Depends on | arrangement, arrangement-engine, clip-player, sound-operations |
| npm | Nothing |
| Used by | block-audio-editor, use-sound-report |
| Export | Kind | What it is |
|---|---|---|
renderEdited | function | What the track's clips play over the whole arrangement, as plain channels: the cuts, fades and gains made, not the track's devices. |
useBake | function | Changes the samples of the sound as edited. |
Usage
An edit of the arrangement (a cut, a fade, a gain) leaves the recording as it was. An operation on samples (a reverse, a filter, a resample) needs the sound as it plays. useBake renders what the track's clips play over the whole arrangement, gives its channels to your operation, and hands the result to onBaked, which puts it on the track as a sound of its own: one step of undo.
Copy to Clipboardimport { useBake } from "@/hooks/use-bake"; const { bake, process } = useBake({ doc, // the arrangement's document onBaked, // (sound, label) => void: puts the sound on the track as a step of the history recordings, sampleRate: 48_000, // the rate the edited sound is rendered at setStatus, // what the editor says while it works stop, // stops what plays track: "track-1", }); // An operation of the Process menu, named after it: "Repeat ×4". <ProcessMenuItems onProcess={process} />; <MenuItem onClick={() => process({ times: 4, type: "repeat" })}>Repeat 4 times</MenuItem>; // Any operation: channels in, channels out. bake("Resample", ({ channels, sampleRate }) => ({ channels: resampleChannels(channels, sampleRate, 44_100), sampleRate: 44_100, }));
process(operation) bakes one of the operations of sound-operations, which the Process menu lists: Reverse, Repeat, Add silence, Normalize, Pan, Dither, Filter, Stretch, Pitch, Speed and Repair, each over @/lib/engine/files or @/lib/engine/repair. A browser that cannot render offline says so through setStatus.