From e069097efff1bf46e66aef2f62d58fa76f30e639 Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Thu, 11 Sep 2025 16:43:37 +0800 Subject: [PATCH 1/4] working camera offsetting --- .../src/routes/editor/ConfigSidebar.tsx | 233 +++++++++++++++++- .../src/routes/editor/Timeline/ClipTrack.tsx | 31 +-- apps/desktop/src/utils/tauri.ts | 4 +- crates/editor/src/editor_instance.rs | 4 +- crates/editor/src/playback.rs | 4 +- crates/project/src/configuration.rs | 25 +- crates/rendering/src/lib.rs | 15 +- 7 files changed, 280 insertions(+), 36 deletions(-) diff --git a/apps/desktop/src/routes/editor/ConfigSidebar.tsx b/apps/desktop/src/routes/editor/ConfigSidebar.tsx index 2d3693cd238..6023fcac7c1 100644 --- a/apps/desktop/src/routes/editor/ConfigSidebar.tsx +++ b/apps/desktop/src/routes/editor/ConfigSidebar.tsx @@ -31,7 +31,7 @@ import { Suspense, type ValidComponent, } from "solid-js"; -import { createStore } from "solid-js/store"; +import { createStore, produce } from "solid-js/store"; import { Dynamic } from "solid-js/web"; import toast from "solid-toast"; import colorBg from "~/assets/illustrations/color.webp"; @@ -43,6 +43,7 @@ import { generalSettingsStore } from "~/store"; import { type BackgroundSource, type CameraShape, + ClipOffsets, commands, type SceneSegment, type StereoMode, @@ -71,6 +72,7 @@ import { Subfield, topSlideAnimateClasses, } from "./ui"; +import { NumberField } from "@kobalte/core"; const BACKGROUND_SOURCES = { wallpaper: "Wallpaper", @@ -2317,9 +2319,32 @@ function ClipSegmentConfig(props: { segmentIndex: number; segment: TimelineSegment; }) { - const { setProject, setEditorState, project, projectActions } = + const { setProject, setEditorState, project, projectActions, meta } = useEditorContext(); + // Get current clip configuration + const clipConfig = () => project.clips?.[props.segmentIndex]; + const offsets = () => clipConfig()?.offsets || {}; + + function setOffset(type: keyof ClipOffsets, offset: number) { + if (Number.isNaN(offset)) return; + + setProject( + produce((proj) => { + const clips = (proj.clips ??= []); + let clip = clips.find( + (clip) => clip.index === (props.segment.recordingSegment ?? 0), + ); + if (!clip) { + clip = { index: 0, offsets: {} }; + clips.push(clip); + } + + clip.offsets[type] = offset / 1000; + }), + ); + } + return ( <>
@@ -2348,20 +2373,206 @@ function ClipSegmentConfig(props: { Delete
- - } /> - - - } + +
+

Clip Settings

+

+ These settings apply to all segments for the current clip +

+
+ + {meta().hasSystemAudio && ( + { + setOffset("system_audio", offset); + }} /> -
+ )} + {meta().hasMicrophone && ( + { + setOffset("mic", offset); + }} + /> + )} + {meta().hasCamera && ( + { + setOffset("camera", offset); + }} + /> + )} + + {/*
+

Audio/Video Offsets

+ +
+
+ +
+ { + const value = parseFloat(e.currentTarget.value) || 0; + const clips = [...(project.clips || [])]; + if (!clips[props.segmentIndex]) { + clips[props.segmentIndex] = { + index: props.segmentIndex, + offsets: {}, + }; + } + clips[props.segmentIndex].offsets.camera = value; + setProject("clips", clips); + }} + step="0.01" + min="-10" + max="10" + class="w-24 px-2 py-1 text-sm bg-gray-800 border border-gray-700 rounded text-gray-200 focus:outline-none focus:border-blue-500" + /> + seconds +
+

Adjust camera video timing

+
+ +
+ +
+ { + const value = parseFloat(e.currentTarget.value) || 0; + const clips = [...(project.clips || [])]; + if (!clips[props.segmentIndex]) { + clips[props.segmentIndex] = { + index: props.segmentIndex, + offsets: {}, + }; + } + clips[props.segmentIndex].offsets.mic = value; + setProject("clips", clips); + }} + step="0.01" + min="-10" + max="10" + class="w-24 px-2 py-1 text-sm bg-gray-800 border border-gray-700 rounded text-gray-200 focus:outline-none focus:border-blue-500" + /> + seconds +
+

Adjust microphone audio timing

+
+ +
+ +
+ { + const value = parseFloat(e.currentTarget.value) || 0; + const clips = [...(project.clips || [])]; + if (!clips[props.segmentIndex]) { + clips[props.segmentIndex] = { + index: props.segmentIndex, + offsets: {}, + }; + } + clips[props.segmentIndex].offsets.system_audio = value; + setProject("clips", clips); + }} + step="0.01" + min="-10" + max="10" + class="w-24 px-2 py-1 text-sm bg-gray-800 border border-gray-700 rounded text-gray-200 focus:outline-none focus:border-blue-500" + /> + seconds +
+

Adjust system audio timing

+
+
+
*/} + + {/* + } /> + + + } + /> + */} ); } +function SourceOffsetField(props: { + name: string; + // seconds + value?: number; + onChange: (value: number) => void; +}) { + const rawValue = () => Math.round((props.value ?? 0) * 1000); + + const [value, setValue] = createSignal(rawValue().toString()); + + return ( + +
+
+ { + props.onChange(v); + }} + > + { + if (!rawValue() || value() === "" || Number.isNaN(rawValue())) { + setValue("0"); + props.onChange(0); + } + }} + class="w-[5rem] p-[0.375rem] border rounded-[0.5rem] bg-gray-1 focus-visible:outline-none" + /> + + ms +
+
+ {[-100, -10, 10, 100].map((v) => ( + + ))} +
+
+
+ ); +} + function SceneSegmentConfig(props: { segmentIndex: number; segment: SceneSegment; diff --git a/apps/desktop/src/routes/editor/Timeline/ClipTrack.tsx b/apps/desktop/src/routes/editor/Timeline/ClipTrack.tsx index ee132163d0c..c30e2eecbc5 100644 --- a/apps/desktop/src/routes/editor/Timeline/ClipTrack.tsx +++ b/apps/desktop/src/routes/editor/Timeline/ClipTrack.tsx @@ -355,21 +355,22 @@ export function ClipTrack( createEventListener(e.currentTarget, "mouseup", (e) => { dispose(); - // If there's only one segment, don't open the clip config panel - // since there's nothing to configure - just let the normal click behavior happen - const hasOnlyOneSegment = segments().length === 1; - - if (hasOnlyOneSegment) { - // Clear any existing selection (zoom, layout, etc.) when clicking on a clip - // This ensures the sidebar updates properly - setEditorState("timeline", "selection", null); - } else { - // When there are multiple segments, show the clip configuration - setEditorState("timeline", "selection", { - type: "clip", - index: i(), - }); - } + // // If there's only one segment, don't open the clip config panel + // // since there's nothing to configure - just let the normal click behavior happen + // const hasOnlyOneSegment = segments().length === 1; + + // if (hasOnlyOneSegment) { + // // Clear any existing selection (zoom, layout, etc.) when clicking on a clip + // // This ensures the sidebar updates properly + // setEditorState("timeline", "selection", null); + // } else { + // When there are multiple segments, show the clip configuration + setEditorState("timeline", "selection", { + type: "clip", + index: i(), + }); + + // } props.handleUpdatePlayhead(e); }); }); diff --git a/apps/desktop/src/utils/tauri.ts b/apps/desktop/src/utils/tauri.ts index b7719566dcb..a6d2405a006 100644 --- a/apps/desktop/src/utils/tauri.ts +++ b/apps/desktop/src/utils/tauri.ts @@ -349,6 +349,8 @@ export type CaptionSettings = { enabled: boolean; font: string; size: number; co export type CaptionsData = { segments: CaptionSegment[]; settings: CaptionSettings } export type CaptureDisplay = { id: DisplayId; name: string; refresh_rate: number } export type CaptureWindow = { id: WindowId; owner_name: string; name: string; bounds: LogicalBounds; refresh_rate: number } +export type ClipConfiguration = { index: number; offsets: ClipOffsets } +export type ClipOffsets = { camera?: number; mic?: number; system_audio?: number } export type CommercialLicense = { licenseKey: string; expiryDate: number | null; refresh: number; activatedOn: number } export type Crop = { position: XY; size: XY } export type CurrentRecording = { target: CurrentRecordingTarget; mode: RecordingMode } @@ -411,7 +413,7 @@ export type PostDeletionBehaviour = "doNothing" | "reopenRecordingWindow" export type PostStudioRecordingBehaviour = "openEditor" | "showOverlay" export type Preset = { name: string; config: ProjectConfiguration } export type PresetsStore = { presets: Preset[]; default: number | null } -export type ProjectConfiguration = { aspectRatio: AspectRatio | null; background: BackgroundConfiguration; camera: Camera; audio: AudioConfiguration; cursor: CursorConfiguration; hotkeys: HotkeysConfiguration; timeline?: TimelineConfiguration | null; captions?: CaptionsData | null } +export type ProjectConfiguration = { aspectRatio: AspectRatio | null; background: BackgroundConfiguration; camera: Camera; audio: AudioConfiguration; cursor: CursorConfiguration; hotkeys: HotkeysConfiguration; timeline?: TimelineConfiguration | null; captions?: CaptionsData | null; clips?: ClipConfiguration[] } export type ProjectRecordingsMeta = { segments: SegmentRecordings[] } export type RecordingDeleted = { path: string } export type RecordingEvent = { variant: "Countdown"; value: number } | { variant: "Started" } | { variant: "Stopped" } | { variant: "Failed"; error: string } diff --git a/crates/editor/src/editor_instance.rs b/crates/editor/src/editor_instance.rs index c39a1f10a99..6dd25c6f04c 100644 --- a/crates/editor/src/editor_instance.rs +++ b/crates/editor/src/editor_instance.rs @@ -211,10 +211,12 @@ impl EditorInstance { }; let segment = &self.segments[segment_i as usize]; + let clip_config = project.clips.iter().find(|v| v.index == segment_i); + let clip_offsets = clip_config.map(|v| v.offsets).unwrap_or_default(); if let Some(segment_frames) = segment .decoders - .get_frames(segment_time as f32, !project.camera.hide) + .get_frames(segment_time as f32, !project.camera.hide, clip_offsets) .await { let uniforms = ProjectUniforms::new( diff --git a/crates/editor/src/playback.rs b/crates/editor/src/playback.rs index 4a762ca28c8..8dd5aeae431 100644 --- a/crates/editor/src/playback.rs +++ b/crates/editor/src/playback.rs @@ -83,10 +83,12 @@ impl Playback { if let Some((segment_time, segment_i)) = project.get_segment_time(time) { let segment = &self.segments[segment_i as usize]; + let clip_config = project.clips.iter().find(|v| v.index == segment_i); + let clip_offsets = clip_config.map(|v| v.offsets).unwrap_or_default(); let data = tokio::select! { _ = stop_rx.changed() => { break; }, - data = segment.decoders.get_frames(segment_time as f32, !project.camera.hide) => { data } + data = segment.decoders.get_frames(segment_time as f32, !project.camera.hide, clip_offsets) => { data } }; if let Some(segment_frames) = data { diff --git a/crates/project/src/configuration.rs b/crates/project/src/configuration.rs index 735b9a66edb..289824234a9 100644 --- a/crates/project/src/configuration.rs +++ b/crates/project/src/configuration.rs @@ -580,17 +580,32 @@ impl Default for CaptionSettings { } } -#[derive(Type, Serialize, Deserialize, Clone, Debug)] +#[derive(Type, Serialize, Deserialize, Clone, Debug, Default)] #[serde(rename_all = "camelCase")] -#[derive(Default)] pub struct CaptionsData { pub segments: Vec, pub settings: CaptionSettings, } -#[derive(Type, Serialize, Deserialize, Clone, Debug)] +#[derive(Type, Serialize, Deserialize, Clone, Copy, Debug, Default)] +pub struct ClipOffsets { + #[serde(default)] + pub camera: f32, + #[serde(default)] + pub mic: f32, + #[serde(default)] + pub system_audio: f32, +} + +#[derive(Type, Serialize, Deserialize, Clone, Debug, Default)] +#[serde(rename_all = "camelCase")] +pub struct ClipConfiguration { + pub index: u32, + pub offsets: ClipOffsets, +} + +#[derive(Type, Serialize, Deserialize, Clone, Debug, Default)] #[serde(rename_all = "camelCase")] -#[derive(Default)] pub struct ProjectConfiguration { pub aspect_ratio: Option, pub background: BackgroundConfiguration, @@ -602,6 +617,8 @@ pub struct ProjectConfiguration { pub timeline: Option, #[serde(default)] pub captions: Option, + #[serde(default)] + pub clips: Vec, } impl ProjectConfiguration { diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rs index 1e32e894288..c7447d125e9 100644 --- a/crates/rendering/src/lib.rs +++ b/crates/rendering/src/lib.rs @@ -1,6 +1,6 @@ use anyhow::Result; use cap_project::{ - AspectRatio, CameraShape, CameraXPosition, CameraYPosition, Crop, CursorEvents, + AspectRatio, CameraShape, CameraXPosition, CameraYPosition, ClipOffsets, Crop, CursorEvents, ProjectConfiguration, RecordingMeta, StudioRecordingMeta, XY, }; use composite_frame::CompositeVideoFrameUniforms; @@ -136,12 +136,16 @@ impl RecordingSegmentDecoders { &self, segment_time: f32, needs_camera: bool, + offsets: ClipOffsets, ) -> Option { let (screen, camera) = tokio::join!( self.screen.get_frame(segment_time), OptionFuture::from( needs_camera - .then(|| self.camera.as_ref().map(|d| d.get_frame(segment_time))) + .then(|| self + .camera + .as_ref() + .map(|d| d.get_frame(segment_time + offsets.camera))) .flatten() ) ); @@ -216,6 +220,7 @@ pub async fn render_video_to_channel( }; let segment = &segments[segment_i as usize]; + let clip_config = project.clips.iter().find(|v| v.index == segment_i); let frame_number = { let prev = frame_number; @@ -224,7 +229,11 @@ pub async fn render_video_to_channel( if let Some(segment_frames) = segment .decoders - .get_frames(segment_time as f32, !project.camera.hide) + .get_frames( + segment_time as f32, + !project.camera.hide, + clip_config.map(|v| v.offsets).unwrap_or_default(), + ) .await { let uniforms = ProjectUniforms::new( From 516d0f1094f51542f37c0a3bfb6ea97cc7837e49 Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Thu, 11 Sep 2025 23:38:43 +0800 Subject: [PATCH 2/4] audio offsett works too --- .../src/routes/editor/ConfigSidebar.tsx | 97 +------------------ apps/desktop/src/utils/createPresets.ts | 1 + crates/audio/src/renderer.rs | 30 ++++-- crates/editor/src/audio.rs | 22 +++-- crates/editor/src/playback.rs | 12 +-- crates/scap-direct3d/src/lib.rs | 1 - 6 files changed, 44 insertions(+), 119 deletions(-) diff --git a/apps/desktop/src/routes/editor/ConfigSidebar.tsx b/apps/desktop/src/routes/editor/ConfigSidebar.tsx index 6023fcac7c1..0765f720b89 100644 --- a/apps/desktop/src/routes/editor/ConfigSidebar.tsx +++ b/apps/desktop/src/routes/editor/ConfigSidebar.tsx @@ -2375,7 +2375,7 @@ function ClipSegmentConfig(props: {
-

Clip Settings

+

Clip Settings

These settings apply to all segments for the current clip

@@ -2409,101 +2409,6 @@ function ClipSegmentConfig(props: { /> )} - {/*
-

Audio/Video Offsets

- -
-
- -
- { - const value = parseFloat(e.currentTarget.value) || 0; - const clips = [...(project.clips || [])]; - if (!clips[props.segmentIndex]) { - clips[props.segmentIndex] = { - index: props.segmentIndex, - offsets: {}, - }; - } - clips[props.segmentIndex].offsets.camera = value; - setProject("clips", clips); - }} - step="0.01" - min="-10" - max="10" - class="w-24 px-2 py-1 text-sm bg-gray-800 border border-gray-700 rounded text-gray-200 focus:outline-none focus:border-blue-500" - /> - seconds -
-

Adjust camera video timing

-
- -
- -
- { - const value = parseFloat(e.currentTarget.value) || 0; - const clips = [...(project.clips || [])]; - if (!clips[props.segmentIndex]) { - clips[props.segmentIndex] = { - index: props.segmentIndex, - offsets: {}, - }; - } - clips[props.segmentIndex].offsets.mic = value; - setProject("clips", clips); - }} - step="0.01" - min="-10" - max="10" - class="w-24 px-2 py-1 text-sm bg-gray-800 border border-gray-700 rounded text-gray-200 focus:outline-none focus:border-blue-500" - /> - seconds -
-

Adjust microphone audio timing

-
- -
- -
- { - const value = parseFloat(e.currentTarget.value) || 0; - const clips = [...(project.clips || [])]; - if (!clips[props.segmentIndex]) { - clips[props.segmentIndex] = { - index: props.segmentIndex, - offsets: {}, - }; - } - clips[props.segmentIndex].offsets.system_audio = value; - setProject("clips", clips); - }} - step="0.01" - min="-10" - max="10" - class="w-24 px-2 py-1 text-sm bg-gray-800 border border-gray-700 rounded text-gray-200 focus:outline-none focus:border-blue-500" - /> - seconds -
-

Adjust system audio timing

-
-
-
*/} - {/* } /> diff --git a/apps/desktop/src/utils/createPresets.ts b/apps/desktop/src/utils/createPresets.ts index 2217a752621..9ba9943d335 100644 --- a/apps/desktop/src/utils/createPresets.ts +++ b/apps/desktop/src/utils/createPresets.ts @@ -28,6 +28,7 @@ export function createPresets() { const config = { ...preset.config }; // @ts-expect-error we reeeally don't want the timeline in the preset config.timeline = undefined; + config.clips = undefined; await updatePresets((store) => { store.presets.push({ name: preset.name, config }); diff --git a/crates/audio/src/renderer.rs b/crates/audio/src/renderer.rs index 9033dff130f..bc9f1124cfd 100644 --- a/crates/audio/src/renderer.rs +++ b/crates/audio/src/renderer.rs @@ -6,9 +6,16 @@ pub enum StereoMode { MonoR, } +pub struct AudioRendererTrack<'a> { + pub data: &'a AudioData, + pub gain: f32, + pub stereo_mode: StereoMode, + pub offset: isize, +} + // Renders a combination of audio tracks into a single stereo buffer pub fn render_audio( - tracks: &[(&AudioData, f32, StereoMode)], + tracks: &[AudioRendererTrack], offset: usize, samples: usize, out_offset: usize, @@ -17,7 +24,7 @@ pub fn render_audio( let samples = samples.min( tracks .iter() - .flat_map(|t| (t.0.samples().len() / t.0.channels() as usize).checked_sub(offset)) + .flat_map(|t| (t.data.samples().len() / t.data.channels() as usize).checked_sub(offset)) .max() .unwrap_or(0), ); @@ -27,27 +34,32 @@ pub fn render_audio( let mut right = 0.0; for track in tracks { - let gain = gain_for_db(track.1); + // dbg!(i); + let i = i.wrapping_add_signed(dbg!(track.offset)); + // dbg!(i); + + let data = track.data; + let gain = gain_for_db(track.gain); if gain == f32::NEG_INFINITY { continue; } - if track.0.channels() == 1 { - if let Some(sample) = track.0.samples().get(offset + i) { + if data.channels() == 1 { + if let Some(sample) = data.samples().get(offset + i) { left += sample * 0.707 * gain; right += sample * 0.707 * gain; } - } else if track.0.channels() == 2 { + } else if data.channels() == 2 { let base_idx = offset * 2 + i * 2; - let Some(l_sample) = track.0.samples().get(base_idx) else { + let Some(l_sample) = data.samples().get(base_idx) else { continue; }; - let Some(r_sample) = track.0.samples().get(base_idx + 1) else { + let Some(r_sample) = data.samples().get(base_idx + 1) else { continue; }; - match track.2 { + match track.stereo_mode { StereoMode::Stereo => { left += l_sample * gain; right += r_sample * gain; diff --git a/crates/editor/src/audio.rs b/crates/editor/src/audio.rs index 3edfec45679..68a5ccd346b 100644 --- a/crates/editor/src/audio.rs +++ b/crates/editor/src/audio.rs @@ -1,4 +1,6 @@ -use cap_audio::{AudioData, FromSampleBytes, StereoMode, cast_f32_slice_to_bytes}; +use cap_audio::{ + AudioData, AudioRendererTrack, FromSampleBytes, StereoMode, cast_f32_slice_to_bytes, +}; use cap_media::MediaError; use cap_media_info::AudioInfo; use cap_project::{AudioConfiguration, ProjectConfiguration, TimelineConfiguration}; @@ -184,16 +186,24 @@ impl AudioRenderer { let track_datas = tracks .iter() .map(|t| { - ( - t.data().as_ref(), - if project.audio.mute { + let offsets = project + .clips + .iter() + .find(|c| c.index == start.segment_index) + .map(|c| c.offsets) + .unwrap_or_default(); + + AudioRendererTrack { + data: t.data().as_ref(), + gain: if project.audio.mute { f32::NEG_INFINITY } else { let g = t.gain(&project.audio); if g < -30.0 { f32::NEG_INFINITY } else { g } }, - t.stereo_mode(&project.audio), - ) + stereo_mode: t.stereo_mode(&project.audio), + offset: (offsets.system_audio * Self::SAMPLE_RATE as f32) as isize, + } }) .collect::>(); diff --git a/crates/editor/src/playback.rs b/crates/editor/src/playback.rs index 8dd5aeae431..42c7a302d9f 100644 --- a/crates/editor/src/playback.rs +++ b/crates/editor/src/playback.rs @@ -250,13 +250,11 @@ impl AudioPlayback { move |buffer: &mut [T], _info| { let project = project.borrow(); - if prev_audio_config != project.audio { - audio_renderer.set_playhead( - playhead + elapsed as f64 / output_info.sample_rate as f64, - &project, - ); - prev_audio_config = project.audio.clone(); - } + audio_renderer.set_playhead( + playhead + elapsed as f64 / output_info.sample_rate as f64, + &project, + ); + prev_audio_config = project.audio.clone(); audio_renderer.render(&project); audio_renderer.fill(buffer); diff --git a/crates/scap-direct3d/src/lib.rs b/crates/scap-direct3d/src/lib.rs index 73edb47a6c8..0302358c6a9 100644 --- a/crates/scap-direct3d/src/lib.rs +++ b/crates/scap-direct3d/src/lib.rs @@ -12,7 +12,6 @@ use std::{ thread::JoinHandle, time::Duration, }; - use windows::{ Foundation::{Metadata::ApiInformation, TypedEventHandler}, Graphics::{ From 7cc6c179fadf8dd3c91bc4e2285f623e4c67918a Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Thu, 11 Sep 2025 23:54:06 +0800 Subject: [PATCH 3/4] fix properly --- apps/desktop/src/routes/editor/ConfigSidebar.tsx | 4 ++-- crates/audio/src/renderer.rs | 4 +--- crates/editor/src/audio.rs | 12 ++++++++++-- crates/editor/src/segments.rs | 2 ++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/desktop/src/routes/editor/ConfigSidebar.tsx b/apps/desktop/src/routes/editor/ConfigSidebar.tsx index 0765f720b89..b9b4aada94d 100644 --- a/apps/desktop/src/routes/editor/ConfigSidebar.tsx +++ b/apps/desktop/src/routes/editor/ConfigSidebar.tsx @@ -1,3 +1,4 @@ +import { NumberField } from "@kobalte/core"; import { Collapsible, Collapsible as KCollapsible, @@ -43,7 +44,7 @@ import { generalSettingsStore } from "~/store"; import { type BackgroundSource, type CameraShape, - ClipOffsets, + type ClipOffsets, commands, type SceneSegment, type StereoMode, @@ -72,7 +73,6 @@ import { Subfield, topSlideAnimateClasses, } from "./ui"; -import { NumberField } from "@kobalte/core"; const BACKGROUND_SOURCES = { wallpaper: "Wallpaper", diff --git a/crates/audio/src/renderer.rs b/crates/audio/src/renderer.rs index bc9f1124cfd..bb22ae7ea3e 100644 --- a/crates/audio/src/renderer.rs +++ b/crates/audio/src/renderer.rs @@ -34,9 +34,7 @@ pub fn render_audio( let mut right = 0.0; for track in tracks { - // dbg!(i); - let i = i.wrapping_add_signed(dbg!(track.offset)); - // dbg!(i); + let i = i.wrapping_add_signed(track.offset); let data = track.data; let gain = gain_for_db(track.gain); diff --git a/crates/editor/src/audio.rs b/crates/editor/src/audio.rs index 68a5ccd346b..99e195444b5 100644 --- a/crates/editor/src/audio.rs +++ b/crates/editor/src/audio.rs @@ -3,7 +3,7 @@ use cap_audio::{ }; use cap_media::MediaError; use cap_media_info::AudioInfo; -use cap_project::{AudioConfiguration, ProjectConfiguration, TimelineConfiguration}; +use cap_project::{AudioConfiguration, ClipOffsets, ProjectConfiguration, TimelineConfiguration}; use ffmpeg::{ChannelLayout, format as avformat, frame::Audio as FFAudio, software::resampling}; use ringbuf::{ HeapRb, @@ -31,11 +31,13 @@ pub struct AudioSegment { pub tracks: Vec, } +// yeah this is cursed oh well #[derive(Clone)] pub struct AudioSegmentTrack { data: Arc, get_gain: fn(&AudioConfiguration) -> f32, get_stereo_mode: fn(&AudioConfiguration) -> StereoMode, + get_offset: fn(&ClipOffsets) -> f32, } impl AudioSegmentTrack { @@ -43,11 +45,13 @@ impl AudioSegmentTrack { data: Arc, get_gain: fn(&AudioConfiguration) -> f32, get_stereo_mode: fn(&AudioConfiguration) -> StereoMode, + get_offset: fn(&ClipOffsets) -> f32, ) -> Self { Self { data, get_gain, get_stereo_mode, + get_offset, } } @@ -62,6 +66,10 @@ impl AudioSegmentTrack { pub fn stereo_mode(&self, config: &AudioConfiguration) -> StereoMode { (self.get_stereo_mode)(config) } + + pub fn offset(&self, offsets: &ClipOffsets) -> f32 { + (self.get_offset)(offsets) + } } impl AudioRenderer { @@ -202,7 +210,7 @@ impl AudioRenderer { if g < -30.0 { f32::NEG_INFINITY } else { g } }, stereo_mode: t.stereo_mode(&project.audio), - offset: (offsets.system_audio * Self::SAMPLE_RATE as f32) as isize, + offset: (t.offset(&offsets) * Self::SAMPLE_RATE as f32) as isize, } }) .collect::>(); diff --git a/crates/editor/src/segments.rs b/crates/editor/src/segments.rs index a9422a3d982..1d13ed4fc41 100644 --- a/crates/editor/src/segments.rs +++ b/crates/editor/src/segments.rs @@ -17,6 +17,7 @@ pub fn get_audio_segments(segments: &[Segment]) -> Vec { cap_project::StereoMode::MonoL => cap_audio::StereoMode::MonoL, cap_project::StereoMode::MonoR => cap_audio::StereoMode::MonoR, }, + |o| o.mic, ) }), s.system_audio.clone().map(|a| -> AudioSegmentTrack { @@ -24,6 +25,7 @@ pub fn get_audio_segments(segments: &[Segment]) -> Vec { a, |c| c.system_volume_db, |_| cap_audio::StereoMode::Stereo, + |o| o.system_audio, ) }), ] From 288b006267b5d0dd31cad6ce2fcc70b26e5109bf Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Mon, 15 Sep 2025 10:12:28 +0800 Subject: [PATCH 4/4] find by segment index --- apps/desktop/src/routes/editor/ConfigSidebar.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/desktop/src/routes/editor/ConfigSidebar.tsx b/apps/desktop/src/routes/editor/ConfigSidebar.tsx index b9b4aada94d..f744933b178 100644 --- a/apps/desktop/src/routes/editor/ConfigSidebar.tsx +++ b/apps/desktop/src/routes/editor/ConfigSidebar.tsx @@ -2323,7 +2323,8 @@ function ClipSegmentConfig(props: { useEditorContext(); // Get current clip configuration - const clipConfig = () => project.clips?.[props.segmentIndex]; + const clipConfig = () => + project.clips?.find((c) => c.index === props.segmentIndex); const offsets = () => clipConfig()?.offsets || {}; function setOffset(type: keyof ClipOffsets, offset: number) {