# recording

> Recording into an arrangement: an input recorder on an AudioWorklet that keeps each block with its frame on the audio clock, the frames of a take with the latency taken off, and the audio or MIDI clip a take becomes, with record quantization and overdub

```bash
npx shadcn@latest add @audio-ui/recording
```

```ts
import { takeFrames, sliceBlocks, blockPeak, audioTakeClip, RECORD_QUANTIZE, /* … */ } from "@/lib/recording";
```

- Files: `lib/recording.ts`, `lib/input-recorder.ts`
- Depends on: `arrangement`; npm: `@audio-ui/core`, `@audio-ui/engine`
- Used by: `block-audio-editor`

| Export | Kind | What it is |
| --- | --- | --- |
| `RecordedBlock` | interface | What came in from an input, block by block: each block's first frame on the audio clock, and its channels. |
| `takeFrames` | function | Where on the audio clock a take's sound was played: `from` and `to` on the arrangement, in seconds, while playback ran from `playFrom` at clock frame `playAt`. |
| `sliceBlocks` | function | The frames `[from, to)` of the clock out of `blocks`, as one channel array each: silence where no block came in. |
| `blockPeak` | function | The loudest sample of a block, over its channels: what a take drawn live shows of it. |
| `audioTakeClip` | function | The clip an audio take becomes: from where it started, as long as it lasted, over what lies under it. |
| `PlayedNote` | interface | A note played while recording, on the arrangement: where it started and ended, in seconds. |
| `RECORD_QUANTIZE` | const | The record quantizations: none, or a note value as a share of a whole note. |
| `takeNotes` | function | The notes of a MIDI take between `from` and `to`, in seconds from `origin`: each as long as it was held (to `to` when it is still held), its start moved to the nearest `quantize` seconds from `origin` when it is not 0 (REC-009). |
| `midiTakeClip` | function | The MIDI clip a take becomes, from `from` to `to` on the arrangement, over what lies under it. |
| `overdubbed` | function | A MIDI clip with a take's notes added to its own (Overdub on, REC-009): placed in its source's time, so they sound where they were played. |

## Usage

Recording into the arrangement: an input recorder on an `AudioWorklet` (installed with it as `input-recorder`) that keeps blocks of the input with their frame on the audio clock, and the clips a take becomes, audio or MIDI.

```ts
import { createInputRecorder } from "@/lib/input-recorder";
import { audioTakeClip, takeFrames } from "@/lib/recording";

const recorder = await createInputRecorder(ctx); // null where worklets cannot run
input.connect(recorder.input);
recorder.start();
// … the take …
const blocks = await recorder.stop();
const [from, to] = takeFrames({ from, latency, playAt, playFrom, sampleRate: ctx.sampleRate, to });
const clip = audioTakeClip({ id, length, name: "Take 1", recording: id, start, track });
```

`takeFrames` lines the take up with the arrangement, taking the input's latency off; `sliceBlocks` keeps the frames inside it; `midiTakeClip` makes a MIDI clip of the notes played, quantized if asked; `overdubbed` merges a take over a clip. The [Transport](/docs/components/base/transport) shows Record, count-in and Punch; what is recorded and when is the host's.
