@waveform-playlist/recording 13.0.6 → 14.0.0-next.0
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 +52 -30
- package/dist/index.d.mts +74 -64
- package/dist/index.d.ts +74 -64
- package/dist/index.js +181 -110
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +192 -110
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -9
package/dist/index.js
CHANGED
|
@@ -23,7 +23,8 @@ __export(src_exports, {
|
|
|
23
23
|
useIntegratedRecording: () => useIntegratedRecording,
|
|
24
24
|
useMicrophoneAccess: () => useMicrophoneAccess,
|
|
25
25
|
useMicrophoneLevel: () => useMicrophoneLevel,
|
|
26
|
-
useRecording: () => useRecording
|
|
26
|
+
useRecording: () => useRecording,
|
|
27
|
+
useRecordingProgress: () => useRecordingProgress
|
|
27
28
|
});
|
|
28
29
|
module.exports = __toCommonJS(src_exports);
|
|
29
30
|
|
|
@@ -39,12 +40,11 @@ function useRecording(stream, options = {}) {
|
|
|
39
40
|
const { channelCount = 1, samplesPerPixel = 1024, bits = 16 } = options;
|
|
40
41
|
const [isRecording, setIsRecording] = (0, import_react.useState)(false);
|
|
41
42
|
const [isPaused, setIsPaused] = (0, import_react.useState)(false);
|
|
42
|
-
const [duration, setDuration] = (0, import_react.useState)(0);
|
|
43
|
-
const [peaks, setPeaks] = (0, import_react.useState)([emptyPeaks(bits)]);
|
|
44
43
|
const [audioBuffer, setAudioBuffer] = (0, import_react.useState)(null);
|
|
45
44
|
const [error, setError] = (0, import_react.useState)(null);
|
|
46
|
-
const [
|
|
47
|
-
|
|
45
|
+
const [{ source: progress, publish: publishProgressValue }] = (0, import_react.useState)(
|
|
46
|
+
() => (0, import_core.createValueSource)({ duration: 0, peaks: [emptyPeaks(bits)] })
|
|
47
|
+
);
|
|
48
48
|
const workletLoadedRef = (0, import_react.useRef)(false);
|
|
49
49
|
const workletNodeRef = (0, import_react.useRef)(null);
|
|
50
50
|
const mediaStreamSourceRef = (0, import_react.useRef)(null);
|
|
@@ -64,17 +64,22 @@ function useRecording(stream, options = {}) {
|
|
|
64
64
|
const isStartingRef = (0, import_react.useRef)(false);
|
|
65
65
|
const isUnmountedRef = (0, import_react.useRef)(false);
|
|
66
66
|
const durationRef = (0, import_react.useRef)(0);
|
|
67
|
+
const peaksRef = (0, import_react.useRef)(progress.getSnapshot().peaks);
|
|
68
|
+
const publishProgress = (0, import_react.useCallback)(() => {
|
|
69
|
+
const current = progress.getSnapshot();
|
|
70
|
+
if (current.duration === durationRef.current && current.peaks === peaksRef.current) return;
|
|
71
|
+
publishProgressValue({ duration: durationRef.current, peaks: peaksRef.current });
|
|
72
|
+
}, [progress, publishProgressValue]);
|
|
67
73
|
const startDurationLoop = (0, import_react.useCallback)(() => {
|
|
68
74
|
const tick = () => {
|
|
69
75
|
if (isRecordingRef.current && !isPausedRef.current && !isStoppingRef.current) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
setDuration(elapsed);
|
|
76
|
+
durationRef.current = (performance.now() - startTimeRef.current) / 1e3;
|
|
77
|
+
publishProgress();
|
|
73
78
|
animationFrameRef.current = requestAnimationFrame(tick);
|
|
74
79
|
}
|
|
75
80
|
};
|
|
76
81
|
tick();
|
|
77
|
-
}, []);
|
|
82
|
+
}, [publishProgress]);
|
|
78
83
|
const loadWorklet = (0, import_react.useCallback)(async () => {
|
|
79
84
|
if (workletLoadedRef.current) {
|
|
80
85
|
return;
|
|
@@ -125,10 +130,10 @@ function useRecording(stream, options = {}) {
|
|
|
125
130
|
};
|
|
126
131
|
recordedChunksRef.current = Array.from({ length: streamChannelCount }, () => []);
|
|
127
132
|
totalSamplesRef.current = 0;
|
|
128
|
-
|
|
133
|
+
durationRef.current = 0;
|
|
134
|
+
peaksRef.current = Array.from({ length: streamChannelCount }, () => emptyPeaks(bits));
|
|
135
|
+
publishProgress();
|
|
129
136
|
setAudioBuffer(null);
|
|
130
|
-
setLevel(0);
|
|
131
|
-
setPeakLevel(0);
|
|
132
137
|
workletNode.port.onmessage = (event) => {
|
|
133
138
|
const { channels, done } = event.data;
|
|
134
139
|
if (channels && channels.length > 0 && channels[0] && channels[0].length > 0) {
|
|
@@ -144,16 +149,17 @@ function useRecording(stream, options = {}) {
|
|
|
144
149
|
const samplesProcessedBefore = totalSamplesRef.current;
|
|
145
150
|
totalSamplesRef.current += channels[0].length;
|
|
146
151
|
if (stopAckResolveRef.current === null) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
152
|
+
const previous = peaksRef.current;
|
|
153
|
+
peaksRef.current = channels.map(
|
|
154
|
+
(channel, ch) => (0, import_core.appendPeaks)(
|
|
155
|
+
previous[ch] ?? emptyPeaks(bits),
|
|
156
|
+
channel,
|
|
157
|
+
samplesPerPixel,
|
|
158
|
+
samplesProcessedBefore,
|
|
159
|
+
bits
|
|
160
|
+
)
|
|
161
|
+
);
|
|
162
|
+
if (isPausedRef.current) publishProgress();
|
|
157
163
|
}
|
|
158
164
|
}
|
|
159
165
|
if (done) {
|
|
@@ -188,7 +194,15 @@ function useRecording(stream, options = {}) {
|
|
|
188
194
|
} finally {
|
|
189
195
|
isStartingRef.current = false;
|
|
190
196
|
}
|
|
191
|
-
}, [
|
|
197
|
+
}, [
|
|
198
|
+
stream,
|
|
199
|
+
channelCount,
|
|
200
|
+
samplesPerPixel,
|
|
201
|
+
bits,
|
|
202
|
+
loadWorklet,
|
|
203
|
+
startDurationLoop,
|
|
204
|
+
publishProgress
|
|
205
|
+
]);
|
|
192
206
|
const stopRecording = (0, import_react.useCallback)(async () => {
|
|
193
207
|
if (!isRecordingRef.current) {
|
|
194
208
|
return null;
|
|
@@ -260,7 +274,7 @@ function useRecording(stream, options = {}) {
|
|
|
260
274
|
const buffer = (0, import_core.createAudioBuffer)(rawContext, channelData, rawContext.sampleRate, numChannels);
|
|
261
275
|
setAudioBuffer(buffer);
|
|
262
276
|
durationRef.current = buffer.duration;
|
|
263
|
-
|
|
277
|
+
publishProgress();
|
|
264
278
|
return buffer;
|
|
265
279
|
} catch (err) {
|
|
266
280
|
console.warn("[waveform-playlist] Failed to stop recording:", String(err));
|
|
@@ -272,9 +286,8 @@ function useRecording(stream, options = {}) {
|
|
|
272
286
|
isStoppingRef.current = false;
|
|
273
287
|
setIsRecording(false);
|
|
274
288
|
setIsPaused(false);
|
|
275
|
-
setLevel(0);
|
|
276
289
|
}
|
|
277
|
-
}, [channelCount]);
|
|
290
|
+
}, [channelCount, publishProgress]);
|
|
278
291
|
stopRecordingRef.current = stopRecording;
|
|
279
292
|
finishStopRecordingRef.current = finishStopRecording;
|
|
280
293
|
const pauseRecording = (0, import_react.useCallback)(() => {
|
|
@@ -285,9 +298,10 @@ function useRecording(stream, options = {}) {
|
|
|
285
298
|
animationFrameRef.current = null;
|
|
286
299
|
}
|
|
287
300
|
isPausedRef.current = true;
|
|
301
|
+
publishProgress();
|
|
288
302
|
setIsPaused(true);
|
|
289
303
|
}
|
|
290
|
-
}, []);
|
|
304
|
+
}, [publishProgress]);
|
|
291
305
|
const resumeRecording = (0, import_react.useCallback)(() => {
|
|
292
306
|
if (isRecordingRef.current && isPausedRef.current && !isStoppingRef.current) {
|
|
293
307
|
workletNodeRef.current?.port.postMessage({ command: "resume" });
|
|
@@ -306,6 +320,7 @@ function useRecording(stream, options = {}) {
|
|
|
306
320
|
}
|
|
307
321
|
if (workletNodeRef.current) {
|
|
308
322
|
workletNodeRef.current.port.postMessage({ command: "stop" });
|
|
323
|
+
workletNodeRef.current.port.onmessage = null;
|
|
309
324
|
if (mediaStreamSourceRef.current) {
|
|
310
325
|
try {
|
|
311
326
|
mediaStreamSourceRef.current.disconnect(workletNodeRef.current);
|
|
@@ -327,11 +342,8 @@ function useRecording(stream, options = {}) {
|
|
|
327
342
|
return {
|
|
328
343
|
isRecording,
|
|
329
344
|
isPaused,
|
|
330
|
-
|
|
331
|
-
peaks,
|
|
345
|
+
progress,
|
|
332
346
|
audioBuffer,
|
|
333
|
-
level,
|
|
334
|
-
peakLevel,
|
|
335
347
|
startRecording,
|
|
336
348
|
stopRecording,
|
|
337
349
|
pauseRecording,
|
|
@@ -449,26 +461,23 @@ var import_react3 = require("react");
|
|
|
449
461
|
var import_playout2 = require("@waveform-playlist/playout");
|
|
450
462
|
var import_core3 = require("@waveform-playlist/core");
|
|
451
463
|
var import_worklets2 = require("@waveform-playlist/worklets");
|
|
452
|
-
var PEAK_DECAY = 0.98;
|
|
453
464
|
function useMicrophoneLevel(stream, options = {}) {
|
|
454
465
|
const { updateRate = 60, channelCount = 1 } = options;
|
|
455
|
-
const [
|
|
456
|
-
|
|
457
|
-
|
|
466
|
+
const [{ source: meter, publish }] = (0, import_react3.useState)(
|
|
467
|
+
() => (0, import_core3.createValueSource)((0, import_core3.silentMeterLevels)(channelCount))
|
|
468
|
+
);
|
|
458
469
|
const [meterError, setMeterError] = (0, import_react3.useState)(null);
|
|
459
470
|
const workletNodeRef = (0, import_react3.useRef)(null);
|
|
460
471
|
const sourceRef = (0, import_react3.useRef)(null);
|
|
461
|
-
const smoothedPeakRef = (0, import_react3.useRef)(
|
|
462
|
-
const resetPeak = (0, import_react3.useCallback)(
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
);
|
|
472
|
+
const smoothedPeakRef = (0, import_react3.useRef)([]);
|
|
473
|
+
const resetPeak = (0, import_react3.useCallback)(() => {
|
|
474
|
+
const current = meter.getSnapshot();
|
|
475
|
+
publish({ ...current, peakLevels: current.peakLevels.map(() => 0) });
|
|
476
|
+
}, [meter, publish]);
|
|
466
477
|
(0, import_react3.useEffect)(() => {
|
|
467
478
|
if (!stream) {
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
setRmsLevels(new Array(channelCount).fill(0));
|
|
471
|
-
smoothedPeakRef.current = new Array(channelCount).fill(0);
|
|
479
|
+
smoothedPeakRef.current = [];
|
|
480
|
+
publish((0, import_core3.silentMeterLevels)(channelCount));
|
|
472
481
|
return;
|
|
473
482
|
}
|
|
474
483
|
let isMounted = true;
|
|
@@ -499,24 +508,18 @@ function useMicrophoneLevel(stream, options = {}) {
|
|
|
499
508
|
const source = context.createMediaStreamSource(stream);
|
|
500
509
|
sourceRef.current = source;
|
|
501
510
|
source.connect(workletNode);
|
|
502
|
-
smoothedPeakRef.current =
|
|
511
|
+
smoothedPeakRef.current = [];
|
|
503
512
|
workletNode.port.onmessage = (event) => {
|
|
504
513
|
if (!isMounted) return;
|
|
505
|
-
const
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
}
|
|
515
|
-
const mirroredPeaks = workletChannels < channelCount ? new Array(channelCount).fill(peakValues[0]) : peakValues;
|
|
516
|
-
const mirroredRms = workletChannels < channelCount ? new Array(channelCount).fill(rmsValues[0]) : rmsValues;
|
|
517
|
-
setLevels(mirroredPeaks);
|
|
518
|
-
setRmsLevels(mirroredRms);
|
|
519
|
-
setPeakLevels((prev) => mirroredPeaks.map((val, i) => Math.max(prev[i] ?? 0, val)));
|
|
514
|
+
const reading = (0, import_core3.readMeterMessage)({
|
|
515
|
+
data: event.data,
|
|
516
|
+
previousSmoothedPeaks: smoothedPeakRef.current,
|
|
517
|
+
heldPeakLevels: meter.getSnapshot().peakLevels,
|
|
518
|
+
// Mirror mono to fill the requested channelCount
|
|
519
|
+
minChannels: channelCount
|
|
520
|
+
});
|
|
521
|
+
smoothedPeakRef.current = reading.smoothedPeaks;
|
|
522
|
+
publish(reading.levels);
|
|
520
523
|
};
|
|
521
524
|
setMeterError(null);
|
|
522
525
|
};
|
|
@@ -546,43 +549,101 @@ function useMicrophoneLevel(stream, options = {}) {
|
|
|
546
549
|
workletNodeRef.current = null;
|
|
547
550
|
}
|
|
548
551
|
};
|
|
549
|
-
}, [stream, updateRate, channelCount]);
|
|
550
|
-
const level = channelCount === 1 ? levels[0] ?? 0 : Math.max(...levels);
|
|
551
|
-
const peakLevel = channelCount === 1 ? peakLevels[0] ?? 0 : Math.max(...peakLevels);
|
|
552
|
+
}, [stream, updateRate, channelCount, meter, publish]);
|
|
552
553
|
return {
|
|
553
|
-
|
|
554
|
-
peakLevel,
|
|
554
|
+
meter,
|
|
555
555
|
resetPeak,
|
|
556
|
-
levels,
|
|
557
|
-
peakLevels,
|
|
558
|
-
rmsLevels,
|
|
559
556
|
error: meterError
|
|
560
557
|
};
|
|
561
558
|
}
|
|
562
559
|
|
|
563
560
|
// src/hooks/useIntegratedRecording.ts
|
|
564
561
|
var import_react4 = require("react");
|
|
562
|
+
|
|
563
|
+
// src/hooks/takeTarget.ts
|
|
565
564
|
var import_core4 = require("@waveform-playlist/core");
|
|
565
|
+
var PREFIX = "Cannot start recording: ";
|
|
566
|
+
function label(track) {
|
|
567
|
+
return '"' + (track.name || track.id) + '"';
|
|
568
|
+
}
|
|
569
|
+
function isUnusableClipFailure(arrangement, clip, state) {
|
|
570
|
+
const message = state.error?.message ?? "";
|
|
571
|
+
return arrangement.getTracks().some(
|
|
572
|
+
(t) => t.clips.some(
|
|
573
|
+
(c) => (0, import_core4.isLoadingClip)(c) && c.src === clip.src && message.startsWith(`clip "${c.id}": `)
|
|
574
|
+
)
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
function loadingClipRefusal(arrangement, track, clip) {
|
|
578
|
+
const state = arrangement.sources.getSnapshot().sources.get(clip.src);
|
|
579
|
+
if (state?.status !== "failed") {
|
|
580
|
+
return new Error(
|
|
581
|
+
`${PREFIX}${label(track)} holds a clip whose audio is still loading ("${clip.id}"). Start the take once it has loaded.`
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
const reason = state.error?.message ?? "unknown error";
|
|
585
|
+
if (isUnusableClipFailure(arrangement, clip, state)) {
|
|
586
|
+
return new Error(
|
|
587
|
+
`${PREFIX}a clip on ${label(track)} cannot be made from its audio (${reason}). Correct or remove the clip.`
|
|
588
|
+
);
|
|
589
|
+
}
|
|
590
|
+
return new Error(
|
|
591
|
+
`${PREFIX}the audio of clip "${clip.id}" on ${label(track)} could not be loaded (${reason}). Retry it with arrangement.retry(), or remove the clip.`
|
|
592
|
+
);
|
|
593
|
+
}
|
|
594
|
+
function takeRefusal(arrangement, trackId) {
|
|
595
|
+
const target = arrangement.getTracks().find((t) => t.id === trackId);
|
|
596
|
+
if (!target) {
|
|
597
|
+
return new Error(
|
|
598
|
+
`${PREFIX}the selected track "${trackId}" is not in the arrangement. Add it with arrangement.addTrack() first.`
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
if ((0, import_core4.trackKind)(target) === "midi") {
|
|
602
|
+
return new Error(
|
|
603
|
+
`${PREFIX}${label(target)} is a MIDI track. Select or create an audio track first.`
|
|
604
|
+
);
|
|
605
|
+
}
|
|
606
|
+
const loading = target.clips.find(import_core4.isLoadingClip);
|
|
607
|
+
return loading ? loadingClipRefusal(arrangement, target, loading) : null;
|
|
608
|
+
}
|
|
609
|
+
function takeNotSaved(trackId, refusal) {
|
|
610
|
+
const cause = refusal instanceof Error ? refusal : new Error(String(refusal));
|
|
611
|
+
return Object.assign(
|
|
612
|
+
new Error(
|
|
613
|
+
`Recording completed but the take could not be saved on track "${trackId}": ` + cause.message
|
|
614
|
+
),
|
|
615
|
+
{ cause }
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
function withTake(track, take) {
|
|
619
|
+
const loaded = track.clips.filter((c) => !(0, import_core4.isLoadingClip)(c));
|
|
620
|
+
const loading = track.clips.filter(import_core4.isLoadingClip);
|
|
621
|
+
const end = take.startSample + take.durationSamples;
|
|
622
|
+
return {
|
|
623
|
+
...track,
|
|
624
|
+
clips: [...(0, import_core4.carveClipRange)(loaded, take.startSample, end), ...loading, take]
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// src/hooks/useIntegratedRecording.ts
|
|
629
|
+
var import_core5 = require("@waveform-playlist/core");
|
|
566
630
|
var import_playout3 = require("@waveform-playlist/playout");
|
|
567
|
-
function useIntegratedRecording(
|
|
631
|
+
function useIntegratedRecording(arrangement, selectedTrackId, options = {}) {
|
|
568
632
|
const { currentTime = 0, audioConstraints, latencyOffset, ...recordingOptions } = options;
|
|
569
633
|
const [isMonitoring, setIsMonitoring] = (0, import_react4.useState)(false);
|
|
570
634
|
const [selectedDevice, setSelectedDevice] = (0, import_react4.useState)(null);
|
|
571
635
|
const [hookError, setHookError] = (0, import_react4.useState)(null);
|
|
572
636
|
const recordingStartTimeRef = (0, import_react4.useRef)(0);
|
|
637
|
+
const recordingTrackIdRef = (0, import_react4.useRef)(null);
|
|
638
|
+
const [recordingTrackId, setRecordingTrackId] = (0, import_react4.useState)(null);
|
|
639
|
+
const isStartingRef = (0, import_react4.useRef)(false);
|
|
573
640
|
const selectedTrackIdRef = (0, import_react4.useRef)(selectedTrackId);
|
|
574
641
|
selectedTrackIdRef.current = selectedTrackId;
|
|
575
642
|
const currentTimeRef = (0, import_react4.useRef)(currentTime);
|
|
576
643
|
currentTimeRef.current = currentTime;
|
|
577
|
-
const tracksRef = (0, import_react4.useRef)(tracks);
|
|
578
|
-
tracksRef.current = tracks;
|
|
579
644
|
const { stream, devices, hasPermission, requestAccess, error: micError } = useMicrophoneAccess();
|
|
580
645
|
const {
|
|
581
|
-
|
|
582
|
-
peakLevel,
|
|
583
|
-
levels,
|
|
584
|
-
peakLevels,
|
|
585
|
-
rmsLevels,
|
|
646
|
+
meter,
|
|
586
647
|
resetPeak,
|
|
587
648
|
error: meterError
|
|
588
649
|
} = useMicrophoneLevel(stream, {
|
|
@@ -591,9 +652,7 @@ function useIntegratedRecording(tracks, setTracks, selectedTrackId, options = {}
|
|
|
591
652
|
const {
|
|
592
653
|
isRecording,
|
|
593
654
|
isPaused,
|
|
594
|
-
|
|
595
|
-
peaks,
|
|
596
|
-
audioBuffer: _recordedAudioBuffer,
|
|
655
|
+
progress,
|
|
597
656
|
startRecording: startRec,
|
|
598
657
|
stopRecording: stopRec,
|
|
599
658
|
pauseRecording,
|
|
@@ -601,12 +660,19 @@ function useIntegratedRecording(tracks, setTracks, selectedTrackId, options = {}
|
|
|
601
660
|
error: recError
|
|
602
661
|
} = useRecording(stream, recordingOptions);
|
|
603
662
|
const startRecording = (0, import_react4.useCallback)(async () => {
|
|
663
|
+
if (isRecordingRef.current || isStartingRef.current) return false;
|
|
604
664
|
if (!selectedTrackIdRef.current) {
|
|
605
665
|
setHookError(
|
|
606
666
|
new Error("Cannot start recording: no track selected. Select or create a track first.")
|
|
607
667
|
);
|
|
608
668
|
return false;
|
|
609
669
|
}
|
|
670
|
+
const refusal = takeRefusal(arrangement, selectedTrackIdRef.current);
|
|
671
|
+
if (refusal) {
|
|
672
|
+
setHookError(refusal);
|
|
673
|
+
return false;
|
|
674
|
+
}
|
|
675
|
+
isStartingRef.current = true;
|
|
610
676
|
try {
|
|
611
677
|
setHookError(null);
|
|
612
678
|
if (!isMonitoring) {
|
|
@@ -614,12 +680,19 @@ function useIntegratedRecording(tracks, setTracks, selectedTrackId, options = {}
|
|
|
614
680
|
setIsMonitoring(true);
|
|
615
681
|
}
|
|
616
682
|
recordingStartTimeRef.current = currentTimeRef.current;
|
|
617
|
-
|
|
683
|
+
recordingTrackIdRef.current = selectedTrackIdRef.current;
|
|
684
|
+
setRecordingTrackId(selectedTrackIdRef.current);
|
|
685
|
+
const started = await startRec();
|
|
686
|
+
if (!started) setRecordingTrackId(null);
|
|
687
|
+
return started;
|
|
618
688
|
} catch (err) {
|
|
689
|
+
setRecordingTrackId(null);
|
|
619
690
|
setHookError(err instanceof Error ? err : new Error(String(err)));
|
|
620
691
|
return false;
|
|
692
|
+
} finally {
|
|
693
|
+
isStartingRef.current = false;
|
|
621
694
|
}
|
|
622
|
-
}, [isMonitoring, startRec]);
|
|
695
|
+
}, [arrangement, isMonitoring, startRec]);
|
|
623
696
|
const stopRecording = (0, import_react4.useCallback)(async () => {
|
|
624
697
|
let buffer;
|
|
625
698
|
try {
|
|
@@ -627,12 +700,12 @@ function useIntegratedRecording(tracks, setTracks, selectedTrackId, options = {}
|
|
|
627
700
|
} catch (err) {
|
|
628
701
|
setHookError(err instanceof Error ? err : new Error(String(err)));
|
|
629
702
|
return;
|
|
703
|
+
} finally {
|
|
704
|
+
setRecordingTrackId(null);
|
|
630
705
|
}
|
|
631
|
-
const trackId =
|
|
632
|
-
const currentTracks = tracksRef.current;
|
|
706
|
+
const trackId = recordingTrackIdRef.current;
|
|
633
707
|
if (buffer && trackId) {
|
|
634
|
-
|
|
635
|
-
if (selectedTrackIndex === -1) {
|
|
708
|
+
if (!arrangement.getTracks().some((t) => t.id === trackId)) {
|
|
636
709
|
const err = new Error(
|
|
637
710
|
`Recording completed but track "${trackId}" no longer exists. The recorded audio could not be saved.`
|
|
638
711
|
);
|
|
@@ -645,7 +718,7 @@ function useIntegratedRecording(tracks, setTracks, selectedTrackId, options = {}
|
|
|
645
718
|
const outputLatency = audioContext.outputLatency ?? 0;
|
|
646
719
|
const toneContext = (0, import_playout3.getGlobalContext)();
|
|
647
720
|
const lookAhead = toneContext.lookAhead ?? 0;
|
|
648
|
-
const latencyOffsetSamples = (0,
|
|
721
|
+
const latencyOffsetSamples = (0, import_core5.resolveRecordingOffsetSamples)({
|
|
649
722
|
overrideSeconds: latencyOffset,
|
|
650
723
|
outputLatency,
|
|
651
724
|
lookAhead,
|
|
@@ -670,21 +743,15 @@ function useIntegratedRecording(tracks, setTracks, selectedTrackId, options = {}
|
|
|
670
743
|
gain: 1,
|
|
671
744
|
name: `Recording ${(/* @__PURE__ */ new Date()).toLocaleTimeString()}`
|
|
672
745
|
};
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
]
|
|
681
|
-
};
|
|
682
|
-
}
|
|
683
|
-
return track;
|
|
684
|
-
});
|
|
685
|
-
setTracks(newTracks);
|
|
746
|
+
try {
|
|
747
|
+
arrangement.updateTrack(trackId, (track) => withTake(track, newClip));
|
|
748
|
+
} catch (err) {
|
|
749
|
+
const notSaved = takeNotSaved(trackId, err);
|
|
750
|
+
console.warn(`[waveform-playlist] ${notSaved.message}`);
|
|
751
|
+
setHookError(notSaved);
|
|
752
|
+
}
|
|
686
753
|
}
|
|
687
|
-
}, [
|
|
754
|
+
}, [arrangement, stopRec, latencyOffset]);
|
|
688
755
|
(0, import_react4.useEffect)(() => {
|
|
689
756
|
if (!hasPermission || devices.length === 0) return;
|
|
690
757
|
if (selectedDevice === null) {
|
|
@@ -735,12 +802,11 @@ function useIntegratedRecording(tracks, setTracks, selectedTrackId, options = {}
|
|
|
735
802
|
// Recording state
|
|
736
803
|
isRecording,
|
|
737
804
|
isPaused,
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
rmsLevels,
|
|
805
|
+
// Only while a take is running: a take can also end without our
|
|
806
|
+
// stopRecording (the microphone is unplugged and useRecording stops itself).
|
|
807
|
+
recordingTrackId: isRecording ? recordingTrackId : null,
|
|
808
|
+
meter,
|
|
809
|
+
progress,
|
|
744
810
|
error: hookError || micError || meterError || recError,
|
|
745
811
|
// Microphone state
|
|
746
812
|
stream,
|
|
@@ -753,16 +819,21 @@ function useIntegratedRecording(tracks, setTracks, selectedTrackId, options = {}
|
|
|
753
819
|
pauseRecording,
|
|
754
820
|
resumeRecording,
|
|
755
821
|
requestMicAccess,
|
|
756
|
-
changeDevice
|
|
757
|
-
// Track state
|
|
758
|
-
recordingPeaks: peaks
|
|
822
|
+
changeDevice
|
|
759
823
|
};
|
|
760
824
|
}
|
|
825
|
+
|
|
826
|
+
// src/hooks/useRecordingProgress.ts
|
|
827
|
+
var import_ui_components = require("@waveform-playlist/ui-components");
|
|
828
|
+
function useRecordingProgress(progress, options = {}) {
|
|
829
|
+
return (0, import_ui_components.useThrottledValue)(progress, options);
|
|
830
|
+
}
|
|
761
831
|
// Annotate the CommonJS export names for ESM import in node:
|
|
762
832
|
0 && (module.exports = {
|
|
763
833
|
useIntegratedRecording,
|
|
764
834
|
useMicrophoneAccess,
|
|
765
835
|
useMicrophoneLevel,
|
|
766
|
-
useRecording
|
|
836
|
+
useRecording,
|
|
837
|
+
useRecordingProgress
|
|
767
838
|
});
|
|
768
839
|
//# sourceMappingURL=index.js.map
|