Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

Linked slip: clamp to one shared delta so picture and sound stay aligned (#529)

MarekSpodBiedryd1b83b9c9761
diff --git a/crates/engine/src/clip_ops_tests.rs b/crates/engine/src/clip_ops_tests.rs
index 9fc46de97..0f53b8805 100644
--- a/crates/engine/src/clip_ops_tests.rs
+++ b/crates/engine/src/clip_ops_tests.rs
@@ -901,3 +901,26 @@ fn add_edit_cuts_only_the_selected_clips() {
let r = s.execute("sequence.addEdit", json!({"time": t.0})).unwrap();
assert!(r["cuts"].as_u64().unwrap() > 1, "{r}");
}
+
+#[test]
+fn linked_slip_keeps_picture_and_sound_aligned_at_unequal_media_limits() {
+ let mut s = Session::default();
+ s.execute("file.newProject", json!({"name": "Slip"})).unwrap();
+ s.execute("file.newSequence", json!({"name": "Sequence", "fps": 25, "video": 1, "audio": 1, "width": 16, "height": 16})).unwrap();
+ let r = s.execute("file.newOfflineFile", json!({"name": "Media", "seconds": 4, "fps": 25, "video": true, "audio": true})).unwrap();
+ let item = r["item"].as_u64().unwrap();
+ let fr = s.sequence_rate().tick_of(1);
+ let r = s
+ .execute("timeline.place", json!({"item": item, "track": "V1", "audioTrack": "A1", "time": 0, "sourceIn": fr.0 * 20, "duration": fr.0 * 60}))
+ .unwrap();
+ let (v, a) = (r["clips"][0].as_u64().unwrap(), r["clips"][1].as_u64().unwrap());
+ // lengthen only the picture so the pair has unequal tail handles
+ s.execute("sequence.linkedSelection", json!({"on": false})).unwrap();
+ s.execute("timeline.trim", json!({"clip": v, "edge": "out", "deltaFrames": 20})).unwrap();
+ s.execute("sequence.linkedSelection", json!({"on": true})).unwrap();
+ s.execute("timeline.slip", json!({"clip": v, "deltaFrames": 30})).unwrap();
+ assert_eq!(clip(&s, v).source_in, Tick(fr.0 * 20));
+ assert_eq!(clip(&s, a).source_in, Tick(fr.0 * 20), "sound must not slip alone");
+ s.execute("timeline.slip", json!({"clip": v, "deltaFrames": -10})).unwrap();
+ assert_eq!((clip(&s, v).source_in, clip(&s, a).source_in), (Tick(fr.0 * 10), Tick(fr.0 * 10)));
+}
diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rs
index b5e4c847a..93c7cfb09 100644
--- a/crates/engine/src/commands.rs
+++ b/crates/engine/src/commands.rs
@@ -2203,8 +2203,16 @@ fn build() -> Vec<CommandSpec> {
.unwrap_or_default();
let clips = with_links(s, &[c]);
s.edit_sequence("Slip", |q, ctx, _| {
+ // clamp across all linked partners, then slip them by the common delta
+ let mut dd = d;
+ for c in &clips {
+ let x = edit::slip(&mut q.clone(), *c, dd, ctx)?;
+ if x.abs() < dd.abs() {
+ dd = x;
+ }
+ }
for c in &clips {
- edit::slip(q, *c, d, ctx)?;
+ edit::slip(q, *c, dd, ctx)?;
}
Ok(())
})?;