Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Auto-generate clip offsets for new projects

Cursor Agent1289365e95d3
diff --git a/crates/editor/src/editor_instance.rs b/crates/editor/src/editor_instance.rs
index da5055931..56211e472 100644
--- a/crates/editor/src/editor_instance.rs
+++ b/crates/editor/src/editor_instance.rs
@@ -139,6 +139,32 @@ impl EditorInstance {
}
}
+ if project.clips.is_empty() {
+ match meta {
+ StudioRecordingMeta::MultipleSegments { inner } => {
+ project.clips = inner
+ .segments
+ .iter()
+ .enumerate()
+ .map(|(i, segment)| cap_project::ClipConfiguration {
+ index: i as u32,
+ offsets: segment.calculate_audio_offsets(),
+ })
+ .collect();
+ }
+ StudioRecordingMeta::SingleSegment { .. } => {
+ project.clips = vec![cap_project::ClipConfiguration {
+ index: 0,
+ offsets: cap_project::ClipOffsets::default(),
+ }];
+ }
+ }
+
+ if let Err(e) = project.write(&recording_meta.project_path) {
+ warn!("Failed to save auto-generated clip offsets: {}", e);
+ }
+ }
+
let recordings = Arc::new(ProjectRecordingsMeta::new(
&recording_meta.project_path,
meta,
diff --git a/crates/project/src/meta.rs b/crates/project/src/meta.rs
index 4dcd11aca..dee73392c 100644
--- a/crates/project/src/meta.rs
+++ b/crates/project/src/meta.rs
@@ -10,8 +10,8 @@ use std::{
use tracing::{debug, info, warn};
use crate::{
- CaptionsData, CursorEvents, CursorImage, ProjectConfiguration, XY,
- cursor::SHORT_CURSOR_SHAPE_DEBOUNCE_MS,
+ cursor::SHORT_CURSOR_SHAPE_DEBOUNCE_MS, CaptionsData, CursorEvents, CursorImage,
+ ProjectConfiguration, XY,
};
#[derive(Debug, Clone, Serialize, Deserialize, Type)]
@@ -408,6 +408,40 @@ impl MultipleSegment {
Some(value)
}
+
+ pub fn calculate_audio_offsets(&self) -> crate::ClipOffsets {
+ let latest = match self.latest_start_time() {
+ Some(t) => t,
+ None => return crate::ClipOffsets::default(),
+ };
+
+ let camera_offset = self
+ .camera
+ .as_ref()
+ .and_then(|c| c.start_time)
+ .map(|t| (latest - t) as f32)
+ .unwrap_or(0.0);
+
+ let mic_offset = self
+ .mic
+ .as_ref()
+ .and_then(|m| m.start_time)
+ .map(|t| (latest - t) as f32)
+ .unwrap_or(0.0);
+
+ let system_audio_offset = self
+ .system_audio
+ .as_ref()
+ .and_then(|s| s.start_time)
+ .map(|t| (latest - t) as f32)
+ .unwrap_or(0.0);
+
+ crate::ClipOffsets {
+ camera: camera_offset,
+ mic: mic_offset,
+ system_audio: system_audio_offset,
+ }
+ }
}
#[cfg(test)]