Repository navigation
fix(#2192): caption snap uses video-track clip edges only, not audio #3873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| //! Regression test for #2192: caption drag snaps to video-track clip edges only, not audio. | ||
| //! | ||
| //! When captions are dragged, only video-track clip edges should act as snap candidates. | ||
| //! Audio-only boundaries (e.g. a music clip on A1 with no linked video) must be ignored. | ||
|
|
||
| use std::sync::mpsc::{Sender, channel}; | ||
|
|
||
| use egui::{Pos2, Rect, pos2}; | ||
| use egui_kittest::Harness; | ||
| use filmcraft_engine::Session; | ||
| use filmcraft_ui_egui::FilmcraftApp; | ||
| use filmcraft_ui_egui::control::ControlRequest; | ||
| use serde_json::{Value, json}; | ||
|
|
||
| struct Driver { | ||
| harness: Harness<'static, FilmcraftApp>, | ||
| tx: Sender<ControlRequest>, | ||
| } | ||
|
|
||
| impl Driver { | ||
| fn demo() -> Self { | ||
| let mut session = Session::default(); | ||
| session.execute("file.openDemoProject", json!({})).expect("demo project"); | ||
| session.execute("sequence.snap", json!({"on": false})).expect("snapping off"); | ||
| let (tx, rx) = channel(); | ||
| let app = FilmcraftApp::new(session).with_control(rx); | ||
| let harness = Harness::builder().with_size(egui::vec2(1600.0, 980.0)).with_step_dt(1.0 / 60.0).with_max_steps(10_000).build_eframe(move |_cc| app); | ||
| let mut d = Driver { harness, tx }; | ||
| d.frames(4); | ||
| d.ok("ui.elements", json!({"prefix": "timeline.clip."})); | ||
| d | ||
| } | ||
|
|
||
| fn frames(&mut self, n: usize) { | ||
| for _ in 0..n { | ||
| let ctx = self.harness.ctx.clone(); | ||
| let mut raw = std::mem::take(self.harness.input_mut()); | ||
| eframe::App::raw_input_hook(self.harness.state_mut(), &ctx, &mut raw); | ||
| *self.harness.input_mut() = raw; | ||
| self.harness.step(); | ||
| } | ||
| } | ||
|
|
||
| fn ok(&mut self, method: &str, params: Value) -> Value { | ||
| let (req, reply) = ControlRequest::new(method, params.clone()); | ||
| self.tx.send(req).expect("control channel"); | ||
| for _ in 0..600 { | ||
| self.frames(1); | ||
| if let Ok(v) = reply.try_recv() { | ||
| assert_eq!(v["ok"], json!(true), "{method} {params} failed: {v}"); | ||
| return v["result"].clone(); | ||
| } | ||
| } | ||
| panic!("no reply to {method} {params}"); | ||
| } | ||
|
|
||
| fn exec(&mut self, command: &str, params: Value) -> Value { | ||
| self.ok("engine.execute", json!({"command": command, "params": params})) | ||
| } | ||
|
|
||
| fn rect(&mut self, id: &str) -> Option<Rect> { | ||
| self.frames(2); | ||
| let els = self.ok("ui.elements", json!({"prefix": id})); | ||
| let el = els.as_array()?.iter().find(|e| e["id"] == id)?.clone(); | ||
| let r: Vec<f32> = el["rect"].as_array()?.iter().filter_map(|v| v.as_f64().map(|v| v as f32)).collect(); | ||
| Some(Rect::from_min_size(pos2(*r.first()?, *r.get(1)?), egui::vec2(*r.get(2)?, *r.get(3)?))) | ||
| } | ||
|
|
||
| fn captions(&mut self) -> Vec<(i64, i64)> { | ||
| let r = self.exec("captions.list", json!({})); | ||
| r["tracks"][0]["captions"] | ||
| .as_array() | ||
| .expect("captions") | ||
| .iter() | ||
| .map(|c| (c["start"].as_i64().expect("start"), c["end"].as_i64().expect("end"))) | ||
| .collect() | ||
| } | ||
|
|
||
| fn drag(&mut self, from: Pos2, to: Pos2, steps: usize) { | ||
| let push = |d: &mut Self, e: egui::Event| d.harness.input_mut().events.push(e); | ||
| push(self, egui::Event::PointerMoved(from)); | ||
| self.frames(1); | ||
| push(self, egui::Event::PointerButton { pos: from, button: egui::PointerButton::Primary, pressed: true, modifiers: Default::default() }); | ||
| self.frames(1); | ||
| for i in 1..=steps { | ||
| push(self, egui::Event::PointerMoved(from + (to - from) * (i as f32 / steps as f32))); | ||
| self.frames(1); | ||
| } | ||
| push(self, egui::Event::PointerButton { pos: to, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }); | ||
| self.frames(2); | ||
| } | ||
| } | ||
|
|
||
| /// #2192: dragging a caption with snapping on uses snap_for_captions, which iterates only | ||
| /// seq.video_tracks. The demo project's ambient music clip (audio-only on A1) must not | ||
| /// act as a snap target; the drag path must complete without error. | ||
| #[test] | ||
| fn snap_for_captions_uses_video_track_edges_not_audio() { | ||
| let mut d = Driver::demo(); | ||
|
|
||
| // Add a caption on C1 at the 1-second mark. | ||
| let id = d.exec("captions.add", json!({"seconds": 1.0, "durationSeconds": 1.0, "text": "snap"}))["caption"].as_u64().expect("caption id"); | ||
| d.frames(4); | ||
|
|
||
| // Enable snapping so the caption drag path calls snap_for_captions. | ||
| d.exec("sequence.snap", json!({"on": true})); | ||
| d.frames(2); | ||
|
|
||
| let before = d.captions(); | ||
| let r = d.rect(&format!("timeline.caption.{id}")).expect("caption rect"); | ||
|
|
||
| // Drag the caption slightly to the right. The drag delta is small: if snap_for_captions | ||
| // accidentally included audio tracks, the caption could teleport to the music clip's edge | ||
| // on the first frame; if it panics (e.g. index out of bounds on an empty audio track) the | ||
| // test would fail. Either way we assert: caption still exists and did not move by more | ||
| // than one full clip width, which would be a teleport to an audio-only boundary. | ||
| let clip_width = r.width(); | ||
| d.drag(r.center(), r.center() + egui::vec2(clip_width * 0.1, 0.0), 8); | ||
| d.frames(4); | ||
|
|
||
| let after = d.captions(); | ||
| assert!(!after.is_empty(), "caption still exists after snap_for_captions drag"); | ||
|
|
||
| // The caption should not have teleported: its start must not have changed by more than | ||
| // the drag distance (plus one snap zone). A teleport to an audio-only boundary (which | ||
| // can be seconds away) would be caught here. | ||
| let ticks_per_sec = 254_016_000_000i64; | ||
| let (before_start, _) = before[0]; | ||
| let (after_start, _) = after[0]; | ||
| let delta = (after_start - before_start).abs(); | ||
| assert!(delta < ticks_per_sec * 2, "caption moved by {delta} ticks — unexpectedly large, suggesting a snap to a distant audio-only boundary"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preserve caption-to-caption snapping.
When a user drags a caption near another caption’s edge,
snap_for_captionscannot select that edge. The video-only clip loop omits caption edges, and the removedsnap_captionhelper supplied them. The existinga_moved_caption_snaps_to_another_captiontest asserts this behavior incrates/ui-egui/tests/it/timeline_trim_ui.rs:462-484. Add eligible caption edges separately while keeping audio clip edges excluded.