LabDAW

useBake

Changes the samples of a sound as edited: renders what a track's clips play, hands the channels to an operation and puts the result back as one step of undo; process(operation) bakes one of the Process menu's operations, named after it.

pnpm dlx shadcn@latest add @audio-ui/use-bake
import { renderEdited, useBake } from "@/hooks/use-bake";
Fileshooks/use-bake.ts
Depends onarrangement, arrangement-engine, clip-player, sound-operations
npmNothing
Used byblock-audio-editor, use-sound-report
ExportKindWhat it is
renderEditedfunctionWhat the track's clips play over the whole arrangement, as plain channels: the cuts, fades and gains made, not the track's devices.
useBakefunctionChanges 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.

import { 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.

Built by Ouest Labs, the source code is available on GitHub.
RSS