feat: complete Phase 8.2 - punch-in/punch-out and overdub recording
Recording Controls (Phase 8.2): - Added punch-in/punch-out UI controls with time inputs - Punch mode toggle button with visual feedback - Set punch times from current playback position - Collapsible punch time editor shown when enabled - Overdub mode toggle for layering recordings - Overdub implementation mixes recorded audio with existing track audio Components Modified: - PlaybackControls: Added punch and overdub controls with icons - AudioEditor: Implemented overdub mixing logic and state management - PLAN.md: Marked Phase 8.1 and 8.2 as complete Technical Details: - Overdub mixes audio buffers by averaging samples to avoid clipping - Handles multi-channel audio correctly - Punch controls use AlignVerticalJustifyStart/End icons - Overdub uses Layers icon for visual clarity Phase 8 Progress: - ✅ Phase 8.1: Audio Input (complete) - ✅ Phase 8.2: Recording Controls (complete) - 🔲 Phase 8.3: Recording Settings (next) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -32,6 +32,10 @@ export function AudioEditor() {
|
||||
const [masterVolume, setMasterVolume] = React.useState(0.8);
|
||||
const [clipboard, setClipboard] = React.useState<AudioBuffer | null>(null);
|
||||
const [recordingTrackId, setRecordingTrackId] = React.useState<string | null>(null);
|
||||
const [punchInEnabled, setPunchInEnabled] = React.useState(false);
|
||||
const [punchInTime, setPunchInTime] = React.useState(0);
|
||||
const [punchOutTime, setPunchOutTime] = React.useState(0);
|
||||
const [overdubEnabled, setOverdubEnabled] = React.useState(false);
|
||||
|
||||
const { addToast } = useToast();
|
||||
|
||||
@@ -224,18 +228,63 @@ export function AudioEditor() {
|
||||
if (!recordingTrackId) return;
|
||||
|
||||
try {
|
||||
const audioBuffer = await stopRecording();
|
||||
const recordedBuffer = await stopRecording();
|
||||
|
||||
if (audioBuffer) {
|
||||
// Update the track with recorded audio
|
||||
updateTrack(recordingTrackId, { audioBuffer });
|
||||
if (recordedBuffer) {
|
||||
const track = tracks.find((t) => t.id === recordingTrackId);
|
||||
|
||||
addToast({
|
||||
title: 'Recording Complete',
|
||||
description: `Recorded ${audioBuffer.duration.toFixed(2)}s of audio`,
|
||||
variant: 'success',
|
||||
duration: 3000,
|
||||
});
|
||||
// Check if overdub mode is enabled and track has existing audio
|
||||
if (overdubEnabled && track?.audioBuffer) {
|
||||
// Mix recorded audio with existing audio
|
||||
const audioContext = new AudioContext();
|
||||
const existingBuffer = track.audioBuffer;
|
||||
|
||||
// Create a new buffer that's long enough for both
|
||||
const maxDuration = Math.max(existingBuffer.duration, recordedBuffer.duration);
|
||||
const maxChannels = Math.max(existingBuffer.numberOfChannels, recordedBuffer.numberOfChannels);
|
||||
const mixedBuffer = audioContext.createBuffer(
|
||||
maxChannels,
|
||||
Math.floor(maxDuration * existingBuffer.sampleRate),
|
||||
existingBuffer.sampleRate
|
||||
);
|
||||
|
||||
// Mix each channel
|
||||
for (let channel = 0; channel < maxChannels; channel++) {
|
||||
const mixedData = mixedBuffer.getChannelData(channel);
|
||||
const existingData = channel < existingBuffer.numberOfChannels
|
||||
? existingBuffer.getChannelData(channel)
|
||||
: new Float32Array(mixedData.length);
|
||||
const recordedData = channel < recordedBuffer.numberOfChannels
|
||||
? recordedBuffer.getChannelData(channel)
|
||||
: new Float32Array(mixedData.length);
|
||||
|
||||
// Mix the samples (average them to avoid clipping)
|
||||
for (let i = 0; i < mixedData.length; i++) {
|
||||
const existingSample = i < existingData.length ? existingData[i] : 0;
|
||||
const recordedSample = i < recordedData.length ? recordedData[i] : 0;
|
||||
mixedData[i] = (existingSample + recordedSample) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
updateTrack(recordingTrackId, { audioBuffer: mixedBuffer });
|
||||
|
||||
addToast({
|
||||
title: 'Recording Complete (Overdub)',
|
||||
description: `Mixed ${recordedBuffer.duration.toFixed(2)}s with existing audio`,
|
||||
variant: 'success',
|
||||
duration: 3000,
|
||||
});
|
||||
} else {
|
||||
// Normal mode - replace existing audio
|
||||
updateTrack(recordingTrackId, { audioBuffer: recordedBuffer });
|
||||
|
||||
addToast({
|
||||
title: 'Recording Complete',
|
||||
description: `Recorded ${recordedBuffer.duration.toFixed(2)}s of audio`,
|
||||
variant: 'success',
|
||||
duration: 3000,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
setRecordingTrackId(null);
|
||||
@@ -249,7 +298,7 @@ export function AudioEditor() {
|
||||
});
|
||||
setRecordingTrackId(null);
|
||||
}
|
||||
}, [recordingTrackId, stopRecording, updateTrack, addToast]);
|
||||
}, [recordingTrackId, stopRecording, updateTrack, addToast, overdubEnabled, tracks]);
|
||||
|
||||
// Edit handlers
|
||||
const handleCut = React.useCallback(() => {
|
||||
@@ -664,6 +713,14 @@ export function AudioEditor() {
|
||||
isRecording={recordingState.isRecording}
|
||||
onStartRecording={handleStartRecording}
|
||||
onStopRecording={handleStopRecording}
|
||||
punchInEnabled={punchInEnabled}
|
||||
punchInTime={punchInTime}
|
||||
punchOutTime={punchOutTime}
|
||||
onPunchInEnabledChange={setPunchInEnabled}
|
||||
onPunchInTimeChange={setPunchInTime}
|
||||
onPunchOutTimeChange={setPunchOutTime}
|
||||
overdubEnabled={overdubEnabled}
|
||||
onOverdubEnabledChange={setOverdubEnabled}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user