Skip to content

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

Merge origin/main into fix-503 (keep both sides: Volume line + transitions)

Brandon Thomas8e0a824dcfbe
diff --cc crates/engine/src/tests.rs
index 380519cf8,15af29270..89bfea2ae
--- a/crates/engine/src/tests.rs
+++ b/crates/engine/src/tests.rs
@@@ -642,110 -731,36 +731,144 @@@ fn dragging_an_effect_parameter_is_one_
assert_eq!(opacity(&s), start, "and then the whole first one");
}
+/// The demo's first video transition between two clips: (id, start, duration, cut).
+fn demo_crossing(s: &Session) -> (u64, Tick, Tick, Tick) {
+ let q = s.active_sequence().unwrap();
+ q.video_tracks
+ .iter()
+ .find_map(|t| {
+ t.transitions.iter().find(|x| x.from.is_some() && x.to.is_some()).map(|x| (x.id.0, x.start, x.duration, t.item(x.to.unwrap()).unwrap().start))
+ })
+ .expect("the demo has a transition between two clips")
+}
+
+fn transition_ids(s: &Session) -> Vec<u64> {
+ s.active_sequence().unwrap().all_tracks().flat_map(|t| t.transitions.iter().map(|x| x.id.0)).collect()
+}
+
+/// #430: a transition can be selected (it replaces the clip selection and back), Delete removes
+/// it and leaves its clips, undo brings it back; Ripple Delete is not for a transition alone.
+#[test]
+fn transitions_select_and_delete() {
+ let mut s = demo();
+ let (tid, ..) = demo_crossing(&s);
+ let clips = s.active_sequence().unwrap().all_tracks().map(|t| t.items.len()).sum::<usize>();
+ let some_clip = s.active_sequence().unwrap().video_tracks[0].items[0].id.0;
+ s.execute("timeline.select", json!({"clips": [some_clip]})).unwrap();
+ let r = s.execute("timeline.select", json!({"transitions": [tid]})).unwrap();
+ assert_eq!(r["transitionSelection"], json!([tid]));
+ assert!(s.state.selection.is_empty(), "selecting a transition replaces the clip selection");
+ assert!(s.execute("timeline.select", json!({"transitions": [987_654]})).is_err(), "unknown ids are refused");
+ assert!(s.execute("edit.rippleDelete", json!({})).is_err(), "Ripple Delete needs clips");
+ let before = (*s.project).clone();
+ s.execute("edit.clear", json!({})).unwrap();
+ assert!(!transition_ids(&s).contains(&tid), "Delete removes the selected transition");
+ assert_eq!(s.active_sequence().unwrap().all_tracks().map(|t| t.items.len()).sum::<usize>(), clips, "and leaves the clips");
+ assert!(s.state.transition_selection.is_empty());
+ s.execute("edit.undo", json!({})).unwrap();
+ assert_eq!(*s.project, before, "one undo step");
+ // selecting clips clears a transition selection
+ s.execute("timeline.select", json!({"transitions": [tid]})).unwrap();
+ s.execute("timeline.select", json!({"clips": [some_clip]})).unwrap();
+ assert!(s.state.transition_selection.is_empty());
+ // by id, without a selection
+ s.execute("sequence.removeTransition", json!({"transitions": [tid]})).unwrap();
+ assert!(!transition_ids(&s).contains(&tid));
+ assert!(s.execute("sequence.removeTransition", json!({"transitions": [tid]})).is_err(), "nothing left to remove");
+ assert!(s.execute("sequence.removeTransition", json!({})).is_err(), "nothing given or selected");
+}
+
+/// #224 / Effect Controls: Duration follows the alignment, Alignment re-aligns on the cut, Start
+/// moves it (Custom Start), all within the clips it joins; a drag is one undo step.
+#[test]
+fn transition_duration_alignment_and_position() {
+ let mut s = demo();
+ let rate = s.sequence_rate();
+ let f = |n: i64| rate.tick_of(n);
+ let (tid, _, _, cut) = demo_crossing(&s);
+ let set = |s: &mut Session, p: Value| {
+ let mut p = p;
+ p["transition"] = json!(tid);
+ s.execute("sequence.setTransition", p)
+ };
+ let r = set(&mut s, json!({"align": "start"})).unwrap();
+ assert_eq!((r["start"].as_i64(), r["align"].as_str()), (Some(cut.0), Some("start")));
+ // Start at Cut: only the end moves
+ let r = set(&mut s, json!({"frames": 10})).unwrap();
+ assert_eq!((r["start"].as_i64(), r["duration"].as_i64()), (Some(cut.0), Some(f(10).0)));
+ // End at Cut: only the beginning moves
+ let r = set(&mut s, json!({"align": "end", "frames": 8})).unwrap();
+ assert_eq!((r["start"].as_i64(), r["duration"].as_i64(), r["align"].as_str()), (Some((cut - f(8)).0), Some(f(8).0), Some("end")));
+ // Center at Cut: both ends
+ let r = set(&mut s, json!({"align": "center", "frames": 12})).unwrap();
+ assert_eq!((r["start"].as_i64(), r["align"].as_str()), (Some((cut - f(6)).0), Some("center")));
+ // dragging it over the cut: Custom Start; then a new duration keeps its middle
+ let r = set(&mut s, json!({"start": (cut - f(3)).0})).unwrap();
+ assert_eq!(r["align"], json!("custom"));
+ let r = set(&mut s, json!({"frames": 6})).unwrap();
+ assert_eq!((r["start"].as_i64(), r["duration"].as_i64()), (Some(cut.0), Some(f(6).0)), "centre at cut + 3 frames, 6 frames long");
+ // dragging one edge: start and duration together
+ let r = set(&mut s, json!({"start": (cut - f(4)).0, "duration": f(10).0})).unwrap();
+ assert_eq!((r["start"].as_i64(), r["duration"].as_i64()), (Some((cut - f(4)).0), Some(f(10).0)));
+ // refused, and nothing changes
+ let before = (*s.project).clone();
+ let history = s.history.undo.len();
+ for p in [
+ json!({"frames": 0}),
+ json!({"frames": 100_000_000}),
+ json!({"duration": -5}),
+ json!({"duration": i64::MAX}),
+ json!({"frames": 10, "duration": f(10).0}),
+ json!({"align": "middle"}),
+ json!({"align": "start", "start": cut.0}),
+ json!({"start": i64::MIN}),
+ json!({"start": (cut + f(1)).0, "duration": f(1).0}),
+ ] {
+ assert!(set(&mut s, p.clone()).is_err(), "{p}");
+ assert_eq!(*s.project, before, "{p}");
+ assert_eq!(s.history.undo.len(), history, "{p}");
+ }
+ assert!(s.execute("sequence.setTransition", json!({"transition": 987_654, "frames": 5})).is_err());
+ // a drag (merge) is one undo step
+ let history = s.history.undo.len();
+ for (i, n) in [11, 12, 13, 14].into_iter().enumerate() {
+ set(&mut s, json!({"frames": n, "merge": true, "begin": i == 0})).unwrap();
+ }
+ assert_eq!(s.history.undo.len(), history + 1);
+ s.execute("edit.undo", json!({})).unwrap();
+ assert_eq!(*s.project, before);
+}
++
+ /// #484: Enable flips each selected clip on its own, as in Premiere. With one enabled and one
+ /// disabled clip selected it swaps them, instead of first making both the same.
+ #[test]
+ fn enable_flips_each_selected_clip() {
+ let mut s = demo();
+ let enabled = |s: &Session, c: u64| s.active_sequence().unwrap().find_item(ClipId(c)).unwrap().1.enabled;
+ let partner = |s: &Session, c: u64| {
+ let q = s.active_sequence().unwrap();
+ let link = q.find_item(ClipId(c)).unwrap().1.link?;
+ q.all_tracks().flat_map(|t| t.items.iter()).find(|i| i.link == Some(link) && i.id != ClipId(c)).map(|i| i.id.0)
+ };
+ let (a, b) = (v1(&s)[0].0, v1(&s)[1].0);
+ s.execute("clip.enable", json!({"clips": [a]})).unwrap();
+ assert_eq!((enabled(&s, a), enabled(&s, b)), (false, true));
+ // mixed selection: each flips
+ s.execute("clip.enable", json!({"clips": [a, b]})).unwrap();
+ assert_eq!((enabled(&s, a), enabled(&s, b)), (true, false));
+ s.execute("clip.enable", json!({"clips": [a, b]})).unwrap();
+ assert_eq!((enabled(&s, a), enabled(&s, b)), (false, true));
+ // a clip named twice still flips once, and one press is one undo step
+ s.execute("clip.enable", json!({"clips": [a, a]})).unwrap();
+ assert!(enabled(&s, a));
+ s.undo();
+ assert_eq!((enabled(&s, a), enabled(&s, b)), (false, true));
+ // with linked selection on, a clip's linked audio flips with it
+ if let Some(au) = partner(&s, a) {
+ assert_eq!(enabled(&s, au), enabled(&s, a));
+ }
+ // a uniform selection still toggles as before
+ s.execute("clip.enable", json!({"clips": [b]})).unwrap();
+ s.execute("clip.enable", json!({"clips": [a, b]})).unwrap();
+ assert_eq!((enabled(&s, a), enabled(&s, b)), (true, true));
+ }
diff --cc crates/ui-egui/src/i18n/es.tsv
index a5c296e6b,77b0faae1..e3fd2e87a
--- a/crates/ui-egui/src/i18n/es.tsv
+++ b/crates/ui-egui/src/i18n/es.tsv
@@@ -3480,5 -3487,10 +3487,12 @@@
New Sequence Nueva secuencia
Tracks Pistas
tracks pistas
+ Clear Transition Borrar transición
+ Set Transition Duration Establecer duración de la transición
+ In Entrada
+ Out Salida
+ Export Markers as CSV… Exportar marcadores como CSV…
+ Fill Type Tipo de relleno
+ Gradient Angle Ángulo del degradado
+ Linear Gradient Degradado lineal
+ Solid Sólido
diff --cc crates/ui-egui/src/panels/effect_controls.rs
index 905089f18,b4142ca45..9bfca4180
--- a/crates/ui-egui/src/panels/effect_controls.rs
+++ b/crates/ui-egui/src/panels/effect_controls.rs
@@@ -45,12 -57,8 +57,13 @@@ fn selected_clips(app: &FilmcraftApp) -
pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
let t = app.tokens;
- let Some((clip, it, kind)) = selected_clip(app) else {
+ let clips = selected_clips(app);
+ let Some((clip, it, _)) = clips.first().cloned() else {
+ // a transition clicked in the Timeline (#430)
+ if let Some(id) = crate::panels::transition_controls::selected(app) {
+ crate::panels::transition_controls::effect_controls(app, ui, rect, id);
+ return;
+ }
crate::dock::placeholder(ui, rect, &t, tl!("(no clip selected)"));
return;
};
diff --cc crates/ui-egui/src/panels/mod.rs
index 5591f357e,91613447a..871d59327
--- a/crates/ui-egui/src/panels/mod.rs
+++ b/crates/ui-egui/src/panels/mod.rs
@@@ -46,8 -46,8 +46,9 @@@ pub mod timeline
pub mod timeline_automation;
pub mod timeline_captions;
pub mod timeline_hit;
+ pub mod timeline_volume;
pub mod tools;
+pub mod transition_controls;
pub mod trim_monitor;
pub mod voiceover;
pub mod workspaces;
diff --cc crates/ui-egui/src/panels/timeline.rs
index a1b1d9268,cfc58e2bb..125aa94f9
--- a/crates/ui-egui/src/panels/timeline.rs
+++ b/crates/ui-egui/src/panels/timeline.rs
@@@ -1752,8 -1826,8 +1848,10 @@@ fn interact(app: &mut FilmcraftApp, ui
let g = grab_at(seq, layout, p, tool, mods, roll_ripple);
let cur = match (tool, g) {
(_, Grab::Edge { .. }) => CursorIcon::ResizeColumn,
+ (Tool::Selection, Grab::Other(Hit::Transition { edge: Some(_), .. })) => CursorIcon::ResizeColumn,
+ (Tool::Selection, Grab::Other(Hit::Transition { edge: None, .. })) => CursorIcon::Grab,
+ (_, Grab::Volume { .. }) if tool == Tool::Pen || mods.command => CursorIcon::Crosshair,
+ (_, Grab::Volume { .. }) => CursorIcon::ResizeVertical,
(Tool::Razor, Grab::Other(Hit::Clip { .. })) => CursorIcon::Crosshair,
(Tool::Slip | Tool::Slide, Grab::Other(Hit::Clip { .. })) => CursorIcon::ResizeHorizontal,
(Tool::Hand, _) => CursorIcon::Grab,
@@@ -1870,21 -1954,6 +1979,22 @@@
None
}
}
+ // click a transition to select it (Shift adds / removes); drag an end to change its
+ // duration or its middle to slide it over the cut (#430, #224)
+ (Tool::Selection, Grab::Other(Hit::Transition { id, edge, .. })) => {
- if !(app.session.state.transition_selection.contains(&id) && !mods.shift && resp.drag_started()) {
++ // a drag of a selected transition (Shift too) moves it rather than toggling it out first
++ if !(app.session.state.transition_selection.contains(&id) && resp.drag_started()) {
+ let r = app.session.execute("timeline.select", json!({"transitions": [id.0], "toggle": mods.shift}));
+ if let Err(e) = r {
+ app.ui.status = e.to_string();
+ }
+ }
+ let span = seq.all_tracks().find_map(|tr| tr.transitions.iter().find(|x| x.id == id)).map(|x| (x.start, x.duration));
+ match span {
+ Some((start, duration)) if resp.drag_started() => Some(Drag::Transition { id, edge, from: t, start, duration }),
+ _ => None,
+ }
+ }
(_, Grab::Other(Hit::Transition { .. })) => None,
(_, Grab::Other(Hit::Empty { .. })) => {
if resp.drag_started() {
@@@ -1980,14 -2048,7 +2090,15 @@@
let origin = ctx.input(|i| i.pointer.press_origin()).map(|o| layout.tick_at(o.x)).unwrap_or(t_here);
Some(Drag::Slide { clip, delta: rate.snap_nearest(t_here - origin) })
}
+ Drag::Transition { id, edge, from, start, duration } => {
+ let delta = rate.snap_nearest(t_here - from);
+ let span = seq.all_tracks().find_map(|tr| {
+ tr.transitions.iter().find(|x| x.id == id).and_then(|x| filmcraft_edit::transitions::drag_span(tr, x, edge, delta, rate.frame_duration()))
+ });
+ let (start, duration) = span.unwrap_or((start, duration));
+ Some(Drag::Transition { id, edge, from, start, duration })
+ }
+ Drag::Volume(v) => Some(Drag::Volume(super::timeline_volume::drag(app, ui, seq, layout, v, p.y))),
Drag::Marquee { start } => {
let r = Rect::from_two_pos(start, p);
ui.painter().rect_filled(r, 0.0, Color32::from_white_alpha(18));