Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix(project): normalize scene segment order on load
Aditya Garud84597350ebbe
diff --git a/crates/project/src/configuration.rs b/crates/project/src/configuration.rsindex 9a2aa35eb..d3094a8da 100644--- a/crates/project/src/configuration.rs+++ b/crates/project/src/configuration.rs@@ -1824,6 +1824,15 @@ whereOk(by_segment.into_values().collect())}+fn deserialize_scene_segments<'de, D>(deserializer: D) -> Result<Vec<SceneSegment>, D::Error>+where+ D: serde::Deserializer<'de>,+{+ let mut segments = Vec::<SceneSegment>::deserialize(deserializer)?;+ segments.sort_by(|left, right| left.start.total_cmp(&right.start));+ Ok(segments)+}+#[derive(Type, Serialize, Deserialize, Clone, Debug)]#[serde(rename_all = "camelCase")]pub struct TimelineConfiguration {@@ -1835,7 +1844,7 @@ pub struct TimelineConfiguration {)]pub transitions: Vec<ClipTransition>,pub zoom_segments: Vec<ZoomSegment>,- #[serde(default)]+ #[serde(default, deserialize_with = "deserialize_scene_segments")]pub scene_segments: Vec<SceneSegment>,#[serde(default)]pub mask_segments: Vec<MaskSegment>,diff --git a/crates/project/tests/configuration_loading.rs b/crates/project/tests/configuration_loading.rsnew file mode 100644index 000000000..940b9ff17--- /dev/null+++ b/crates/project/tests/configuration_loading.rs@@ -0,0 +1,52 @@+use cap_project::ProjectConfiguration;+use serde_json::json;++#[test]+fn loading_sorts_scenes_without_changing_clip_edits() {+ let project = tempfile::tempdir().unwrap();+ let path = project.path().join("project-config.json");+ std::fs::write(+ &path,+ serde_json::to_vec(&json!({+ "timeline": {+ "segments": [+ { "recordingSegment": 1, "start": 20.0, "end": 22.0, "timescale": 0.25, "name": "Opening", "volume": 0.5 },+ { "recordingSegment": 0, "start": 10.0, "end": 10.0, "timescale": 1.0 },+ { "recordingSegment": 0, "start": 0.0, "end": 32.0, "timescale": 8.0 }+ ],+ "zoomSegments": [],+ "sceneSegments": [+ { "start": 8.0, "end": 10.0, "mode": "cameraOnly" },+ { "start": 1.0, "end": 3.0, "mode": "cameraOnly" },+ { "start": 5.0, "end": 7.0, "mode": "hideCamera" }+ ]+ }+ }))+ .unwrap(),+ )+ .unwrap();++ let loaded = ProjectConfiguration::load(project.path()).unwrap();+ loaded.write(project.path()).unwrap();+ let reloaded = ProjectConfiguration::load(project.path()).unwrap();+ for config in [&loaded, &reloaded] {+ let timeline = config.timeline.as_ref().unwrap();+ assert_eq!(+ timeline+ .scene_segments+ .iter()+ .map(|scene| scene.start)+ .collect::<Vec<_>>(),+ [1.0, 5.0, 8.0]+ );+ assert_eq!(timeline.duration(), 12.0);+ let (source_time, clip) = timeline.get_segment_time(0.0).unwrap();+ assert_eq!((source_time, clip.recording_clip), (20.0, 1));+ assert_eq!(clip.name.as_deref(), Some("Opening"));+ assert_eq!(clip.volume(), 0.5);+ let (source_time, clip) = timeline.get_segment_time(9.0).unwrap();+ assert_eq!((source_time, clip.recording_clip), (8.0, 0));+ assert_eq!(timeline.segments.len(), 3);+ assert_eq!(timeline.segments[1].duration(), 0.0);+ }+}diff --git a/crates/rendering/src/scene.rs b/crates/rendering/src/scene.rsindex 6c12e8152..d353ca07f 100644--- a/crates/rendering/src/scene.rs+++ b/crates/rendering/src/scene.rs@@ -382,6 +382,38 @@ mod tests {}}+ #[test]+ fn loaded_unsorted_scenes_fade_into_the_next_scene() {+ let project = tempfile::tempdir().unwrap();+ std::fs::write(+ project.path().join("project-config.json"),+ r#"{+ "timeline": {+ "segments": [{ "recordingSegment": 0, "start": 0.0, "end": 12.0, "timescale": 1.0 }],+ "zoomSegments": [],+ "sceneSegments": [+ { "start": 8.0, "end": 10.0, "mode": "cameraOnly" },+ { "start": 1.0, "end": 3.0, "mode": "cameraOnly" },+ { "start": 5.0, "end": 7.0, "mode": "hideCamera" }+ ]+ }+ }"#,+ )+ .unwrap();+ let config = cap_project::ProjectConfiguration::load(project.path()).unwrap();+ let segments = &config.timeline.as_ref().unwrap().scene_segments;+ let before = scene_at(4.6, segments);+ let during = scene_at(4.85, segments);+ let after = scene_at(5.0, segments);+ assert_eq!(before.camera_opacity, 1.0);+ assert!(+ (during.camera_opacity - 0.5).abs() < 1e-5,+ "expected the camera halfway faded out, got {}",+ during.camera_opacity+ );+ assert_eq!(after.camera_opacity, 0.0);+ }+#[test]fn camera_only_blur_tracks_motion_at_both_boundaries() {let segments = [camera_scene(0.3)];