pnpm dlx shadcn@latest add @audio-ui/use-clip-edits
import { useClipEdits } from "@/hooks/use-clip-edits";| Files | hooks/use-clip-edits.ts |
|---|---|
| Depends on | arrangement, clip-edits, use-arrangement |
| npm | @audio-ui/react |
| Used by | block-audio-editor |
| Export | Kind | What it is |
|---|---|---|
useClipEdits | function | The edits of the sound, as an audio editor makes them, each one step of undo: on the time selected, Cut and Copy; Paste makes room for what it lays down, over the selection if there is one; Delete and Crop close the gap they leave; Mark puts a locator at the selection's start, or at the cursor; Louder and Quieter move the selection's level by 3 dB. |
Usage
useClipEdits is what an audio editor does with a sound laid on one track of an arrangement: the selection, the clipboard, and each edit as a step of the history. The arrangement's length and loop follow the sound's after every one.
import { useClipEdits } from "@/hooks/use-clip-edits";
const edits = useClipEdits({
act, // (label, command) => void: sends a command as a named step of undo
arrangement,
notify: setStatus, // what an edit says when it had nothing to do
pauses, // [from, to][] of the silences of the sound as it lies
position, // the playhead's source
track: "track-1",
});
<ContextMenuItem disabled={!edits.time} onClick={edits.cut}>Cut</ContextMenuItem>;
<div onKeyDown={edits.handleKey} />;time is the selection, setTime sets it. cut, copy, paste, remove and crop work on it; louder and quieter move its level by 3 dB and shape sets its fades and level; mark puts a locator at its start. trimSilence takes off the silence at the start and the end, and shrinkPauses(gap) cuts every pause between sounds down to gap seconds, 0 removing them. The pure parts are in clip-edits; useSilenceHover shows a pause as a zone.