@waveform-playlist/recording 13.0.6 → 14.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,7 +23,7 @@ npm install @waveform-playlist/recording
23
23
 
24
24
  | Package | Purpose |
25
25
  |---------|---------|
26
- | `react` | ^18.0.0 |
26
+ | `react` | ^19.0.0 |
27
27
  | `styled-components` | ^6.0.0 — required transitively by `@waveform-playlist/ui-components` |
28
28
  | `tone` | ^15.0.0 — recording shares the global AudioContext with `@waveform-playlist/playout` |
29
29
 
@@ -34,11 +34,18 @@ Pairs with `@waveform-playlist/browser` — see the [Recording guide](https://na
34
34
  ### Basic Recording
35
35
 
36
36
  ```tsx
37
- import { useMicrophoneAccess, useRecording } from '@waveform-playlist/recording';
37
+ import {
38
+ useMicrophoneAccess,
39
+ useRecording,
40
+ useRecordingProgress,
41
+ } from '@waveform-playlist/recording';
38
42
 
39
43
  function RecordButton() {
40
44
  const { stream, hasPermission, requestAccess } = useMicrophoneAccess();
41
- const { isRecording, duration, peaks, startRecording, stopRecording } = useRecording(stream);
45
+ const { isRecording, progress, startRecording, stopRecording } = useRecording(stream);
46
+ // `progress` is a source ({ duration, peaks }), not state: useRecording does
47
+ // not re-render as the take grows. This reads it 10 times a second.
48
+ const { duration } = useRecordingProgress(progress);
42
49
 
43
50
  const handleRecord = async () => {
44
51
  if (!hasPermission) {
@@ -72,50 +79,55 @@ import { SegmentedVUMeter } from '@waveform-playlist/ui-components';
72
79
 
73
80
  function MicMonitor() {
74
81
  const { stream, requestAccess } = useMicrophoneAccess();
75
- const { levels, peakLevels } = useMicrophoneLevel(stream, { channelCount: 2 });
82
+ const { meter } = useMicrophoneLevel(stream, { channelCount: 2 });
76
83
 
77
84
  return (
78
85
  <>
79
86
  <button onClick={() => requestAccess()}>Enable Microphone</button>
80
- <SegmentedVUMeter levels={levels} peakLevels={peakLevels} />
87
+ <SegmentedVUMeter meter={meter} />
81
88
  </>
82
89
  );
83
90
  }
84
91
  ```
85
92
 
86
- ### Integrated Recording (with a track list)
93
+ `meter` is a source, not state: levels change about 60 times a second, and the hook does not re-render for them. `SegmentedVUMeter` draws each reading straight to the DOM. For the numbers in render, use `useMeterLevels(meter)` from `@waveform-playlist/ui-components` (10 updates a second by default), or `meter.subscribe(callback)` to draw them yourself.
87
94
 
88
- `useIntegratedRecording` combines microphone access, metering, and recording into one hook that appends the finalized clip directly to a `ClipTrack[]` — the same array shape used by `@waveform-playlist/browser`'s `WaveformPlaylistProvider`.
95
+ ### Integrated Recording (into an arrangement)
96
+
97
+ `useIntegratedRecording` combines microphone access, metering, and recording into one hook that adds the finalized clip to a track of an `Arrangement` — the object `@waveform-playlist/browser`'s `useCreateArrangement` makes and `WaveformPlaylistProvider` plays. This package depends on `@waveform-playlist/engine` and imports only types from it.
89
98
 
90
99
  ```tsx
91
- import { useIntegratedRecording } from '@waveform-playlist/recording';
92
- import type { ClipTrack } from '@waveform-playlist/core';
100
+ import { useIntegratedRecording, useRecordingProgress } from '@waveform-playlist/recording';
101
+ import type { RecordingProgressSource } from '@waveform-playlist/core';
102
+ import type { Arrangement } from '@waveform-playlist/engine';
103
+
104
+ // Only this label re-renders as the take grows.
105
+ function ElapsedTime({ progress }: { progress: RecordingProgressSource }) {
106
+ const { duration } = useRecordingProgress(progress);
107
+ return <>{duration.toFixed(1)}s</>;
108
+ }
93
109
 
94
110
  function Recorder({
95
- tracks,
96
- setTracks,
111
+ arrangement,
97
112
  selectedTrackId,
98
113
  currentTime,
99
114
  }: {
100
- tracks: ClipTrack[];
101
- setTracks: (tracks: ClipTrack[]) => void;
115
+ arrangement: Arrangement;
102
116
  selectedTrackId: string | null;
103
117
  currentTime: number;
104
118
  }) {
105
119
  const {
106
120
  isRecording,
107
- duration,
108
- levels,
109
- peakLevels,
121
+ meter, // live microphone levels — <SegmentedVUMeter meter={meter} />
122
+ progress, // the take's elapsed time and live peaks — <WaveformRecordingPreview recordingState={{ …, progress }} />
110
123
  devices,
111
124
  selectedDevice,
112
125
  requestMicAccess,
113
126
  changeDevice,
114
127
  startRecording,
115
128
  stopRecording,
116
- recordingPeaks, // live per-channel peaks — feed straight into your waveform preview
117
129
  error,
118
- } = useIntegratedRecording(tracks, setTracks, selectedTrackId, {
130
+ } = useIntegratedRecording(arrangement, selectedTrackId, {
119
131
  currentTime,
120
132
  channelCount: 2,
121
133
  });
@@ -124,7 +136,13 @@ function Recorder({
124
136
  <div>
125
137
  <button onClick={() => requestMicAccess()}>Enable Microphone</button>
126
138
  <button onClick={isRecording ? stopRecording : startRecording} disabled={!selectedTrackId}>
127
- {isRecording ? `Stop (${duration.toFixed(1)}s)` : 'Record'}
139
+ {isRecording ? (
140
+ <>
141
+ Stop (<ElapsedTime progress={progress} />)
142
+ </>
143
+ ) : (
144
+ 'Record'
145
+ )}
128
146
  </button>
129
147
  {error && <p>{error.message}</p>}
130
148
  </div>
@@ -132,7 +150,9 @@ function Recorder({
132
150
  }
133
151
  ```
134
152
 
135
- Stopping adds a new `AudioClip` to `selectedTrackId` at the timeline position captured when recording STARTED (punch-in semantics): the take lands exactly at the playhead and REPLACES any existing clip content it overlaps — partial overlaps are trimmed, fully-covered clips removed, and a clip spanning the take is split in two.
153
+ Stopping adds a new `AudioClip` to the track that was selected when the take STARTED (`recordingTrackId`), at the timeline position captured then (punch-in semantics): the take lands exactly at the playhead and REPLACES any existing clip content it overlaps — partial overlaps are trimmed, fully-covered clips removed, and a clip spanning the take is split in two. The take and that carve are one `arrangement.updateTrack()`: one undo step.
154
+
155
+ `startRecording()` resolves `false`, records nothing and sets `error` (a message that starts with `Cannot start recording: ` and names the track) when no track is selected, when the arrangement holds no track of the selected id, for a MIDI track, and for a track holding a clip whose audio is not loaded (still loading, failed to load, or a clip that cannot be made from its audio).
136
156
 
137
157
  ## API Reference
138
158
 
@@ -165,15 +185,18 @@ The core AudioWorklet-based recording hook.
165
185
  - `bits?: 8 | 16` — peak value bit depth (default: `16`)
166
186
 
167
187
  **Returns (`UseRecordingReturn`):**
168
- - `isRecording: boolean`, `isPaused: boolean`, `duration: number` (seconds)
169
- - `peaks: (Int8Array | Int16Array)[]` — one entry per channel, growing live during recording
188
+ - `isRecording: boolean`, `isPaused: boolean`
189
+ - `progress: RecordingProgressSource` — a source of `{ duration: number; peaks: (Int8Array | Int16Array)[] }` (seconds elapsed; one peaks entry per channel, growing live). Published once per animation frame while recording; the hook does not re-render for it. After a stop, `duration` is the recorded buffer's length
170
190
  - `audioBuffer: AudioBuffer | null` — set after `stopRecording()` resolves
171
- - `level: number`, `peakLevel: number` — **deprecated** (always `0`); use `useMicrophoneLevel` for metering. Removed in the next major
172
191
  - `startRecording: () => Promise<boolean>` — resolves `true` when the capture pipeline actually started (`false`: no stream, already recording, worklet failure); check it before starting synchronized playback
173
192
  - `stopRecording: () => Promise<AudioBuffer | null>` — awaits the worklet's final flush before resolving, so the last samples are never dropped
174
193
  - `pauseRecording: () => void`, `resumeRecording: () => void` — pause/resume the worklet itself, not just the UI
175
194
  - `error: Error | null`
176
195
 
196
+ #### `useRecordingProgress(progress, options?)`
197
+
198
+ A recording's `{ duration, peaks }` as React state, at most `options.updateRate` times a second (default: `10`). Use it for slow displays such as an elapsed-time label. Pass the `progress` source itself to `<WaveformRecordingPreview recordingState>` (a child of `<WaveformTracks>` from `@waveform-playlist/browser`) for the live preview.
199
+
177
200
  #### `useMicrophoneLevel(stream, options?)`
178
201
 
179
202
  Sample-accurate VU metering via a separate meter AudioWorklet — independent of `useRecording`, so it works before recording starts.
@@ -185,17 +208,16 @@ Sample-accurate VU metering via a separate meter AudioWorklet — independent of
185
208
  - `channelCount?: number` (default: `1`)
186
209
 
187
210
  **Returns (`UseMicrophoneLevelReturn`):**
188
- - `levels: number[]`, `peakLevels: number[]`, `rmsLevels: number[]` — per channel, normalized 0–1
189
- - `level: number`, `peakLevel: number` — scalar convenience values (max across channels when `channelCount > 1`)
211
+ - `meter: MeterSource` — a source of `{ levels: number[]; peakLevels: number[]; rmsLevels: number[] }`, per channel, normalized 0–1. Stable identity; the hook does not re-render as levels change. Read it with `<SegmentedVUMeter meter={meter} />`, `useMeterLevels(meter)`, or `meter.subscribe(callback)` / `meter.getSnapshot()`
190
212
  - `resetPeak: () => void` — clears held peak indicators, e.g. on device switch
191
213
  - `error: Error | null`
192
214
 
193
- #### `useIntegratedRecording(tracks, setTracks, selectedTrackId, options?)`
215
+ #### `useIntegratedRecording(arrangement, selectedTrackId, options?)`
194
216
 
195
- Batteries-included hook: wires `useMicrophoneAccess` + `useMicrophoneLevel` + `useRecording` together and appends the finalized recording to `tracks` as a new `AudioClip`.
217
+ Batteries-included hook: wires `useMicrophoneAccess` + `useMicrophoneLevel` + `useRecording` together and adds the finalized recording to the arrangement's track as a new `AudioClip`, with one `arrangement.updateTrack()` (one undo step). It keeps no copy of the tracks: it reads the arrangement when a take starts and when it ends.
196
218
 
197
219
  **Parameters:**
198
- - `tracks: ClipTrack[]`, `setTracks: (tracks: ClipTrack[]) => void`, `selectedTrackId: string | null`
220
+ - `arrangement: Arrangement` (from `@waveform-playlist/engine`; `useCreateArrangement` of `@waveform-playlist/browser`), `selectedTrackId: string | null` (the track the next take is recorded onto)
199
221
  - `options?: IntegratedRecordingOptions`
200
222
  - `currentTime?: number` — playback/cursor position; the clip is captured at this position at record *start* (not stop), so overdubbing while transport is running lands the clip correctly
201
223
  - `audioConstraints?: MediaTrackConstraints`
@@ -203,9 +225,9 @@ Batteries-included hook: wires `useMicrophoneAccess` + `useMicrophoneLevel` + `u
203
225
  - `samplesPerPixel?: number` (default: `1024`)
204
226
  - `latencyOffset?: number` — seconds; overrides the auto-computed `outputLatency + lookAhead` compensation applied to the clip's start. `0` disables compensation; omit to auto-compute
205
227
 
206
- **Returns (`UseIntegratedRecordingReturn`):** recording state (`isRecording`, `isPaused`, `duration`, `level`, `peakLevel`, `levels`, `peakLevels`, `rmsLevels`), microphone state (`stream`, `devices`, `hasPermission`, `selectedDevice`), controls (`startRecording` — resolves `true` when capture actually started, `stopRecording`, `pauseRecording`, `resumeRecording`, `requestMicAccess`, `changeDevice`), `recordingPeaks` (live per-channel peaks for preview), and a combined `error`.
228
+ **Returns (`UseIntegratedRecordingReturn`):** recording state (`isRecording`, `isPaused`, `recordingTrackId`: the track the running take was started on, `null` when none is running), the two live sources (`meter`: microphone levels; `progress`: the take's elapsed time and per-channel preview peaks), microphone state (`stream`, `devices`, `hasPermission`, `selectedDevice`), controls (`startRecording` — resolves `true` when capture actually started, `false` with `error` set when the take is refused, `stopRecording`, `pauseRecording`, `resumeRecording`, `requestMicAccess`, `changeDevice`), and a combined `error`.
207
229
 
208
- **Overdub with `@waveform-playlist/browser`:** call `usePlaylistControls().setRecordingActive(true, trackId)` *before* `play()` — while the session is active the end-of-timeline auto-stop is suppressed (the take can run past existing audio) and the recorded-over track's existing content is transiently muted (punch-in replaces it). Both reset automatically when the recording ends; check `startRecording()`'s boolean and release the session on `false`.
230
+ **Recording into a `@waveform-playlist/browser` playlist:** call `useRecordingSession({ isRecording, trackId: recordingTrackId })` (from `@waveform-playlist/browser`) in the component that calls `useIntegratedRecording`; the view's `<WaveformRecordingPreview>` only draws the take. For an overdub, also call `useEditorControls().setRecordingActive(true, trackId)` *before* `play()` — while the session is active the end-of-timeline auto-stop is suppressed (the take can run past existing audio) and the recorded-over track is muted in the arrangement's mix (punch-in replaces what it holds): the mixer and the track's Mute button show it, the built-in `<TrackMuteButton />` is disabled, and `useTrack().isRecordingArmed` is true for it. The mute from before the take is written back when the session ends, whatever was set in between. Both reset automatically when the recording ends; check `startRecording()`'s boolean and release the session on `false`. `play()` does nothing before the playlist's first ready, so a take started during the first load records without playback.
209
231
 
210
232
  ### Types
211
233
 
package/dist/index.d.mts CHANGED
@@ -1,8 +1,11 @@
1
- import { ClipTrack } from '@waveform-playlist/core';
1
+ import { RecordingProgressSource, MeterSource, RecordingProgress } from '@waveform-playlist/core';
2
+ import { Arrangement } from '@waveform-playlist/engine';
3
+ import { UseThrottledValueOptions } from '@waveform-playlist/ui-components';
2
4
 
3
5
  /**
4
6
  * Types for the recording package
5
7
  */
8
+
6
9
  interface RecordingState {
7
10
  isRecording: boolean;
8
11
  isPaused: boolean;
@@ -52,20 +55,17 @@ interface RecordingOptions {
52
55
  interface UseRecordingReturn {
53
56
  isRecording: boolean;
54
57
  isPaused: boolean;
55
- duration: number;
56
- peaks: (Int8Array | Int16Array)[];
57
- audioBuffer: AudioBuffer | null;
58
58
  /**
59
- * @deprecated Always 0 — VU levels come from `useMicrophoneLevel`
60
- * (meter-processor worklet), not this hook. Will be removed in the next
61
- * major version.
59
+ * Elapsed time and live-preview peaks of the take. Its identity is stable
60
+ * for the life of the hook, and the hook does NOT re-render as they change
61
+ * (once per animation frame while recording). Pass it to
62
+ * `<WaveformRecordingPreview recordingState={{ …, progress }} />`, call
63
+ * `progress.subscribe()`, or use `useRecordingProgress(progress)` for
64
+ * throttled React state. After a stop, `duration` is the recorded buffer's
65
+ * length; the next start resets both.
62
66
  */
63
- level: number;
64
- /**
65
- * @deprecated Always 0 — use `useMicrophoneLevel`'s `peakLevel` instead.
66
- * Will be removed in the next major version.
67
- */
68
- peakLevel: number;
67
+ progress: RecordingProgressSource;
68
+ audioBuffer: AudioBuffer | null;
69
69
  /** Start capturing. Resolves `true` when the capture pipeline actually
70
70
  * started, `false` when it could not (no stream, already recording,
71
71
  * worklet/module failure, unmounted). Callers that synchronize playback
@@ -104,6 +104,7 @@ declare function useMicrophoneAccess(): UseMicrophoneAccessReturn;
104
104
  * Uses an AudioWorklet-based meter processor for sample-accurate
105
105
  * peak and RMS metering without requestAnimationFrame overhead.
106
106
  */
107
+
107
108
  interface UseMicrophoneLevelOptions {
108
109
  /**
109
110
  * How often to update the level (in Hz)
@@ -118,38 +119,20 @@ interface UseMicrophoneLevelOptions {
118
119
  }
119
120
  interface UseMicrophoneLevelReturn {
120
121
  /**
121
- * Current peak audio level (0-1)
122
- * For single channel: channel 0 level
123
- * For multi-channel: max across all channels
124
- */
125
- level: number;
126
- /**
127
- * Held peak level since last reset (0-1)
128
- * For single channel: channel 0 peak
129
- * For multi-channel: max across all channels
122
+ * The live levels. Its identity is stable for the life of the hook, and the
123
+ * hook does NOT re-render when levels change: pass it to
124
+ * `<SegmentedVUMeter meter={meter} />`, call `meter.subscribe()`, or use
125
+ * `useMeterLevels(meter)` for throttled React state.
126
+ *
127
+ * Each array has one entry per metered channel: the mic's auto-detected
128
+ * channels, with mono repeated up to the requested `channelCount`. A mic
129
+ * with MORE channels than `channelCount` yields one entry per actual channel.
130
130
  */
131
- peakLevel: number;
131
+ meter: MeterSource;
132
132
  /**
133
- * Reset the held peak level
133
+ * Reset the held peak levels
134
134
  */
135
135
  resetPeak: () => void;
136
- /**
137
- * Per-channel peak levels (0-1). Array length matches the metered channel
138
- * count: the mic's auto-detected channels, with mono mirrored up to the
139
- * requested `channelCount`. A mic with MORE channels than `channelCount`
140
- * yields one entry per actual channel.
141
- * True peak: max absolute sample value per analysis frame.
142
- */
143
- levels: number[];
144
- /**
145
- * Per-channel held peak levels (0-1). Same length contract as `levels`.
146
- */
147
- peakLevels: number[];
148
- /**
149
- * Per-channel RMS levels (0-1). Same length contract as `levels`.
150
- * RMS: root mean square of samples per analysis frame.
151
- */
152
- rmsLevels: number[];
153
136
  /**
154
137
  * Error from meter setup (worklet load failure, context issues, etc.)
155
138
  * Null when metering is working normally.
@@ -161,21 +144,21 @@ interface UseMicrophoneLevelReturn {
161
144
  *
162
145
  * @param stream - MediaStream from getUserMedia
163
146
  * @param options - Configuration options
164
- * @returns Object with current peak level, RMS level, and held peak level
147
+ * @returns A meter source, a peak reset, and any setup error
165
148
  *
166
149
  * @example
167
150
  * ```typescript
168
151
  * const { stream } = useMicrophoneAccess();
169
- * const { levels, rmsLevels, peakLevels } = useMicrophoneLevel(stream, { channelCount: 2 });
152
+ * const { meter } = useMicrophoneLevel(stream, { channelCount: 2 });
170
153
  *
171
- * return <SegmentedVUMeter levels={levels} peakLevels={peakLevels} />;
154
+ * return <SegmentedVUMeter meter={meter} />;
172
155
  * ```
173
156
  */
174
157
  declare function useMicrophoneLevel(stream: MediaStream | null, options?: UseMicrophoneLevelOptions): UseMicrophoneLevelReturn;
175
158
 
176
159
  /**
177
- * Hook for integrated multi-track recording
178
- * Combines recording functionality with track management
160
+ * Hook for integrated multi-track recording: the microphone, the take, and
161
+ * the take added to the arrangement that owns the tracks (#812).
179
162
  */
180
163
 
181
164
  interface IntegratedRecordingOptions {
@@ -206,7 +189,8 @@ interface IntegratedRecordingOptions {
206
189
  * Absolute replacement for the auto-computed `outputLatency + lookAhead` value
207
190
  * — use this to apply an externally-measured round-trip latency. `0` disables
208
191
  * compensation; when omitted, the auto-computed value is used. Pass the same
209
- * value into the provider's `recordingState.latencyOffset` so the live preview
192
+ * value into the preview's `recordingState.latencyOffset`
193
+ * (`<WaveformRecordingPreview recordingState>`) so the live preview
210
194
  * matches the finalized clip. Negative or non-finite values are treated as 0.
211
195
  */
212
196
  latencyOffset?: number;
@@ -214,19 +198,26 @@ interface IntegratedRecordingOptions {
214
198
  interface UseIntegratedRecordingReturn {
215
199
  isRecording: boolean;
216
200
  isPaused: boolean;
217
- duration: number;
218
- level: number;
219
- peakLevel: number;
220
- /**
221
- * Per-channel peak levels (0-1). Array length matches the metered channel
222
- * count (auto-detected mic channels; mono mirrored up to channelCount —
223
- * see UseMicrophoneLevelReturn.levels).
224
- */
225
- levels: number[];
226
- /** Per-channel held peak levels (0-1). Same length contract as `levels`. */
227
- peakLevels: number[];
228
- /** Per-channel RMS levels (0-1). Same length contract as `levels`. */
229
- rmsLevels: number[];
201
+ /**
202
+ * The id of the track the running take will be added to: the track that was
203
+ * selected when `startRecording()` was called, whatever is selected since.
204
+ * `null` whenever `isRecording` is false. Use it, not the selected track,
205
+ * for the live preview (`recordingState.trackId`).
206
+ */
207
+ recordingTrackId: string | null;
208
+ /**
209
+ * Live microphone levels (`useMicrophoneLevel`'s `meter`). The hook does not
210
+ * re-render as they change: pass it to `<SegmentedVUMeter meter={meter} />`
211
+ * or read it with `meter.subscribe()` / `useMeterLevels(meter)`.
212
+ */
213
+ meter: MeterSource;
214
+ /**
215
+ * Elapsed time and live-preview peaks of the take (`useRecording`'s
216
+ * `progress`). The hook does not re-render as they change: pass it to
217
+ * `<WaveformRecordingPreview recordingState={{ …, progress }} />` or read it with
218
+ * `progress.subscribe()` / `useRecordingProgress(progress)`.
219
+ */
220
+ progress: RecordingProgressSource;
230
221
  error: Error | null;
231
222
  stream: MediaStream | null;
232
223
  devices: MicrophoneDevice[];
@@ -234,15 +225,34 @@ interface UseIntegratedRecordingReturn {
234
225
  selectedDevice: string | null;
235
226
  /** Start capturing on the selected track. Resolves `true` when the capture
236
227
  * pipeline actually started — callers that synchronize playback with
237
- * recording (overdub) should check this before starting playback. */
228
+ * recording (overdub) should check this before starting playback.
229
+ * Resolves `false` and sets `error`, recording nothing, when no track is
230
+ * selected, when the arrangement holds no track of the selected id, for a
231
+ * MIDI track, and for a track that holds a clip whose audio is not loaded
232
+ * (still loading, failed to load, or a clip that cannot be made from it). */
238
233
  startRecording: () => Promise<boolean>;
234
+ /** Stop the take and add it to the track it was started on, with one
235
+ * `arrangement.updateTrack()`: one undo step. */
239
236
  stopRecording: () => void;
240
237
  pauseRecording: () => void;
241
238
  resumeRecording: () => void;
242
239
  requestMicAccess: () => Promise<void>;
243
240
  changeDevice: (deviceId: string) => Promise<void>;
244
- recordingPeaks: (Int8Array | Int16Array)[];
245
241
  }
246
- declare function useIntegratedRecording(tracks: ClipTrack[], setTracks: (tracks: ClipTrack[]) => void, selectedTrackId: string | null, options?: IntegratedRecordingOptions): UseIntegratedRecordingReturn;
242
+ /**
243
+ * @param arrangement the owner of the tracks (`useCreateArrangement` from
244
+ * `@waveform-playlist/browser`). The hook reads its tracks when a take starts
245
+ * and ends and keeps no copy of them.
246
+ * @param selectedTrackId the track the next take is recorded onto
247
+ */
248
+ declare function useIntegratedRecording(arrangement: Arrangement, selectedTrackId: string | null, options?: IntegratedRecordingOptions): UseIntegratedRecordingReturn;
249
+
250
+ /**
251
+ * A recording's elapsed time and preview peaks as React state, at most
252
+ * `updateRate` times a second (default 10). Use it for slow displays such as
253
+ * an elapsed-time label; the live waveform takes the source itself
254
+ * (`<WaveformRecordingPreview recordingState={{ …, progress }} />`).
255
+ */
256
+ declare function useRecordingProgress(progress: RecordingProgressSource, options?: UseThrottledValueOptions): RecordingProgress;
247
257
 
248
- export { type IntegratedRecordingOptions, type MicrophoneDevice, type RecordingData, type RecordingOptions, type RecordingState, type UseIntegratedRecordingReturn, type UseMicrophoneAccessReturn, type UseMicrophoneLevelOptions, type UseMicrophoneLevelReturn, type UseRecordingReturn, useIntegratedRecording, useMicrophoneAccess, useMicrophoneLevel, useRecording };
258
+ export { type IntegratedRecordingOptions, type MicrophoneDevice, type RecordingData, type RecordingOptions, type RecordingState, type UseIntegratedRecordingReturn, type UseMicrophoneAccessReturn, type UseMicrophoneLevelOptions, type UseMicrophoneLevelReturn, type UseRecordingReturn, useIntegratedRecording, useMicrophoneAccess, useMicrophoneLevel, useRecording, useRecordingProgress };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,11 @@
1
- import { ClipTrack } from '@waveform-playlist/core';
1
+ import { RecordingProgressSource, MeterSource, RecordingProgress } from '@waveform-playlist/core';
2
+ import { Arrangement } from '@waveform-playlist/engine';
3
+ import { UseThrottledValueOptions } from '@waveform-playlist/ui-components';
2
4
 
3
5
  /**
4
6
  * Types for the recording package
5
7
  */
8
+
6
9
  interface RecordingState {
7
10
  isRecording: boolean;
8
11
  isPaused: boolean;
@@ -52,20 +55,17 @@ interface RecordingOptions {
52
55
  interface UseRecordingReturn {
53
56
  isRecording: boolean;
54
57
  isPaused: boolean;
55
- duration: number;
56
- peaks: (Int8Array | Int16Array)[];
57
- audioBuffer: AudioBuffer | null;
58
58
  /**
59
- * @deprecated Always 0 — VU levels come from `useMicrophoneLevel`
60
- * (meter-processor worklet), not this hook. Will be removed in the next
61
- * major version.
59
+ * Elapsed time and live-preview peaks of the take. Its identity is stable
60
+ * for the life of the hook, and the hook does NOT re-render as they change
61
+ * (once per animation frame while recording). Pass it to
62
+ * `<WaveformRecordingPreview recordingState={{ …, progress }} />`, call
63
+ * `progress.subscribe()`, or use `useRecordingProgress(progress)` for
64
+ * throttled React state. After a stop, `duration` is the recorded buffer's
65
+ * length; the next start resets both.
62
66
  */
63
- level: number;
64
- /**
65
- * @deprecated Always 0 — use `useMicrophoneLevel`'s `peakLevel` instead.
66
- * Will be removed in the next major version.
67
- */
68
- peakLevel: number;
67
+ progress: RecordingProgressSource;
68
+ audioBuffer: AudioBuffer | null;
69
69
  /** Start capturing. Resolves `true` when the capture pipeline actually
70
70
  * started, `false` when it could not (no stream, already recording,
71
71
  * worklet/module failure, unmounted). Callers that synchronize playback
@@ -104,6 +104,7 @@ declare function useMicrophoneAccess(): UseMicrophoneAccessReturn;
104
104
  * Uses an AudioWorklet-based meter processor for sample-accurate
105
105
  * peak and RMS metering without requestAnimationFrame overhead.
106
106
  */
107
+
107
108
  interface UseMicrophoneLevelOptions {
108
109
  /**
109
110
  * How often to update the level (in Hz)
@@ -118,38 +119,20 @@ interface UseMicrophoneLevelOptions {
118
119
  }
119
120
  interface UseMicrophoneLevelReturn {
120
121
  /**
121
- * Current peak audio level (0-1)
122
- * For single channel: channel 0 level
123
- * For multi-channel: max across all channels
124
- */
125
- level: number;
126
- /**
127
- * Held peak level since last reset (0-1)
128
- * For single channel: channel 0 peak
129
- * For multi-channel: max across all channels
122
+ * The live levels. Its identity is stable for the life of the hook, and the
123
+ * hook does NOT re-render when levels change: pass it to
124
+ * `<SegmentedVUMeter meter={meter} />`, call `meter.subscribe()`, or use
125
+ * `useMeterLevels(meter)` for throttled React state.
126
+ *
127
+ * Each array has one entry per metered channel: the mic's auto-detected
128
+ * channels, with mono repeated up to the requested `channelCount`. A mic
129
+ * with MORE channels than `channelCount` yields one entry per actual channel.
130
130
  */
131
- peakLevel: number;
131
+ meter: MeterSource;
132
132
  /**
133
- * Reset the held peak level
133
+ * Reset the held peak levels
134
134
  */
135
135
  resetPeak: () => void;
136
- /**
137
- * Per-channel peak levels (0-1). Array length matches the metered channel
138
- * count: the mic's auto-detected channels, with mono mirrored up to the
139
- * requested `channelCount`. A mic with MORE channels than `channelCount`
140
- * yields one entry per actual channel.
141
- * True peak: max absolute sample value per analysis frame.
142
- */
143
- levels: number[];
144
- /**
145
- * Per-channel held peak levels (0-1). Same length contract as `levels`.
146
- */
147
- peakLevels: number[];
148
- /**
149
- * Per-channel RMS levels (0-1). Same length contract as `levels`.
150
- * RMS: root mean square of samples per analysis frame.
151
- */
152
- rmsLevels: number[];
153
136
  /**
154
137
  * Error from meter setup (worklet load failure, context issues, etc.)
155
138
  * Null when metering is working normally.
@@ -161,21 +144,21 @@ interface UseMicrophoneLevelReturn {
161
144
  *
162
145
  * @param stream - MediaStream from getUserMedia
163
146
  * @param options - Configuration options
164
- * @returns Object with current peak level, RMS level, and held peak level
147
+ * @returns A meter source, a peak reset, and any setup error
165
148
  *
166
149
  * @example
167
150
  * ```typescript
168
151
  * const { stream } = useMicrophoneAccess();
169
- * const { levels, rmsLevels, peakLevels } = useMicrophoneLevel(stream, { channelCount: 2 });
152
+ * const { meter } = useMicrophoneLevel(stream, { channelCount: 2 });
170
153
  *
171
- * return <SegmentedVUMeter levels={levels} peakLevels={peakLevels} />;
154
+ * return <SegmentedVUMeter meter={meter} />;
172
155
  * ```
173
156
  */
174
157
  declare function useMicrophoneLevel(stream: MediaStream | null, options?: UseMicrophoneLevelOptions): UseMicrophoneLevelReturn;
175
158
 
176
159
  /**
177
- * Hook for integrated multi-track recording
178
- * Combines recording functionality with track management
160
+ * Hook for integrated multi-track recording: the microphone, the take, and
161
+ * the take added to the arrangement that owns the tracks (#812).
179
162
  */
180
163
 
181
164
  interface IntegratedRecordingOptions {
@@ -206,7 +189,8 @@ interface IntegratedRecordingOptions {
206
189
  * Absolute replacement for the auto-computed `outputLatency + lookAhead` value
207
190
  * — use this to apply an externally-measured round-trip latency. `0` disables
208
191
  * compensation; when omitted, the auto-computed value is used. Pass the same
209
- * value into the provider's `recordingState.latencyOffset` so the live preview
192
+ * value into the preview's `recordingState.latencyOffset`
193
+ * (`<WaveformRecordingPreview recordingState>`) so the live preview
210
194
  * matches the finalized clip. Negative or non-finite values are treated as 0.
211
195
  */
212
196
  latencyOffset?: number;
@@ -214,19 +198,26 @@ interface IntegratedRecordingOptions {
214
198
  interface UseIntegratedRecordingReturn {
215
199
  isRecording: boolean;
216
200
  isPaused: boolean;
217
- duration: number;
218
- level: number;
219
- peakLevel: number;
220
- /**
221
- * Per-channel peak levels (0-1). Array length matches the metered channel
222
- * count (auto-detected mic channels; mono mirrored up to channelCount —
223
- * see UseMicrophoneLevelReturn.levels).
224
- */
225
- levels: number[];
226
- /** Per-channel held peak levels (0-1). Same length contract as `levels`. */
227
- peakLevels: number[];
228
- /** Per-channel RMS levels (0-1). Same length contract as `levels`. */
229
- rmsLevels: number[];
201
+ /**
202
+ * The id of the track the running take will be added to: the track that was
203
+ * selected when `startRecording()` was called, whatever is selected since.
204
+ * `null` whenever `isRecording` is false. Use it, not the selected track,
205
+ * for the live preview (`recordingState.trackId`).
206
+ */
207
+ recordingTrackId: string | null;
208
+ /**
209
+ * Live microphone levels (`useMicrophoneLevel`'s `meter`). The hook does not
210
+ * re-render as they change: pass it to `<SegmentedVUMeter meter={meter} />`
211
+ * or read it with `meter.subscribe()` / `useMeterLevels(meter)`.
212
+ */
213
+ meter: MeterSource;
214
+ /**
215
+ * Elapsed time and live-preview peaks of the take (`useRecording`'s
216
+ * `progress`). The hook does not re-render as they change: pass it to
217
+ * `<WaveformRecordingPreview recordingState={{ …, progress }} />` or read it with
218
+ * `progress.subscribe()` / `useRecordingProgress(progress)`.
219
+ */
220
+ progress: RecordingProgressSource;
230
221
  error: Error | null;
231
222
  stream: MediaStream | null;
232
223
  devices: MicrophoneDevice[];
@@ -234,15 +225,34 @@ interface UseIntegratedRecordingReturn {
234
225
  selectedDevice: string | null;
235
226
  /** Start capturing on the selected track. Resolves `true` when the capture
236
227
  * pipeline actually started — callers that synchronize playback with
237
- * recording (overdub) should check this before starting playback. */
228
+ * recording (overdub) should check this before starting playback.
229
+ * Resolves `false` and sets `error`, recording nothing, when no track is
230
+ * selected, when the arrangement holds no track of the selected id, for a
231
+ * MIDI track, and for a track that holds a clip whose audio is not loaded
232
+ * (still loading, failed to load, or a clip that cannot be made from it). */
238
233
  startRecording: () => Promise<boolean>;
234
+ /** Stop the take and add it to the track it was started on, with one
235
+ * `arrangement.updateTrack()`: one undo step. */
239
236
  stopRecording: () => void;
240
237
  pauseRecording: () => void;
241
238
  resumeRecording: () => void;
242
239
  requestMicAccess: () => Promise<void>;
243
240
  changeDevice: (deviceId: string) => Promise<void>;
244
- recordingPeaks: (Int8Array | Int16Array)[];
245
241
  }
246
- declare function useIntegratedRecording(tracks: ClipTrack[], setTracks: (tracks: ClipTrack[]) => void, selectedTrackId: string | null, options?: IntegratedRecordingOptions): UseIntegratedRecordingReturn;
242
+ /**
243
+ * @param arrangement the owner of the tracks (`useCreateArrangement` from
244
+ * `@waveform-playlist/browser`). The hook reads its tracks when a take starts
245
+ * and ends and keeps no copy of them.
246
+ * @param selectedTrackId the track the next take is recorded onto
247
+ */
248
+ declare function useIntegratedRecording(arrangement: Arrangement, selectedTrackId: string | null, options?: IntegratedRecordingOptions): UseIntegratedRecordingReturn;
249
+
250
+ /**
251
+ * A recording's elapsed time and preview peaks as React state, at most
252
+ * `updateRate` times a second (default 10). Use it for slow displays such as
253
+ * an elapsed-time label; the live waveform takes the source itself
254
+ * (`<WaveformRecordingPreview recordingState={{ …, progress }} />`).
255
+ */
256
+ declare function useRecordingProgress(progress: RecordingProgressSource, options?: UseThrottledValueOptions): RecordingProgress;
247
257
 
248
- export { type IntegratedRecordingOptions, type MicrophoneDevice, type RecordingData, type RecordingOptions, type RecordingState, type UseIntegratedRecordingReturn, type UseMicrophoneAccessReturn, type UseMicrophoneLevelOptions, type UseMicrophoneLevelReturn, type UseRecordingReturn, useIntegratedRecording, useMicrophoneAccess, useMicrophoneLevel, useRecording };
258
+ export { type IntegratedRecordingOptions, type MicrophoneDevice, type RecordingData, type RecordingOptions, type RecordingState, type UseIntegratedRecordingReturn, type UseMicrophoneAccessReturn, type UseMicrophoneLevelOptions, type UseMicrophoneLevelReturn, type UseRecordingReturn, useIntegratedRecording, useMicrophoneAccess, useMicrophoneLevel, useRecording, useRecordingProgress };