FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
Batch: transitions share one clamp to their clips; Effect Controls' cut drag previews with roll_delta
aiongg5ffa3985a4ce
diff --git a/crates/edit/src/lib.rs b/crates/edit/src/lib.rsindex 554b441f2..fd83a6370 100644--- a/crates/edit/src/lib.rs+++ b/crates/edit/src/lib.rs@@ -198,8 +198,7 @@ fn transition_anchor(track: &Track, tr: &Transition) -> Option<Tick> {/// Keep transitions on their edit points after an edit moved cuts (ripple trim, roll, slide, ripple/// speed change): each transition shifts by as much as its anchor clip edge moved. A transition/// between two clips stays within them, whether its cut moved or one of the clips got shorter-/// (shortened when they are now shorter than it), and its stored alignment follows where that-/// leaves it on the cut.+/// ([`keep_within_clips`]).fn transitions_follow_cuts(before: &Sequence, after: &mut Sequence) {let frame = after.settings.frame_rate.frame_duration();for track in after.all_tracks_mut() {@@ -212,31 +211,44 @@ fn transitions_follow_cuts(before: &Sequence, after: &mut Sequence) {(Some(a), Some(b)) => b - a,_ => Tick::ZERO,};- let within = match (tr.from.and_then(|c| track.item(c)), tr.to.and_then(|c| track.item(c))) {- (Some(f), Some(t)) if f.start < t.end() => Some((f.start, t.start, t.end())),- _ => None,- };- (d, within)+ (d, clips_span(track, tr))}).collect();for (tr, (d, within)) in track.transitions.iter_mut().zip(shifts) {tr.start += d;- if let Some((lo, cut, hi)) = within- && (tr.start < lo || tr.end() > hi)- {- tr.duration = tr.duration.min(hi - lo);- tr.start = tr.start.clamp(lo, hi - tr.duration);- // as `transitions::set_span` stores it (interchange): Custom Start has no variant- tr.align = match transitions::alignment(tr, cut, frame) {- transitions::Alignment::Start => TransitionAlign::StartAtCut,- transitions::Alignment::End => TransitionAlign::EndAtCut,- transitions::Alignment::Center | transitions::Alignment::Custom => TransitionAlign::CenterAtCut,- };+ if let Some(span) = within {+ keep_within_clips(tr, span, frame);}}}}+/// The two clips of a transition between clips as (first clip's start, cut, second clip's end),+/// while they still overlap the cut's span.+fn clips_span(track: &Track, tr: &Transition) -> Option<(Tick, Tick, Tick)> {+ match (tr.from.and_then(|c| track.item(c)), tr.to.and_then(|c| track.item(c))) {+ (Some(f), Some(t)) if f.start < t.end() => Some((f.start, t.start, t.end())),+ _ => None,+ }+}++/// Move a transition that reaches past its two clips (`span`, from [`clips_span`]) back inside+/// them, shortened when the clips are now shorter than it. Its stored alignment follows where that+/// leaves it on the cut, as `transitions::set_span` stores it (interchange): Custom Start has no+/// variant.+fn keep_within_clips(tr: &mut Transition, (lo, cut, hi): (Tick, Tick, Tick), frame: Tick) {+ if tr.start >= lo && tr.end() <= hi {+ return;+ }+ tr.duration = tr.duration.min(hi - lo);+ tr.start = tr.start.clamp(lo, hi - tr.duration);+ tr.align = match transitions::alignment(tr, cut, frame) {+ transitions::Alignment::Start => TransitionAlign::StartAtCut,+ transitions::Alignment::End => TransitionAlign::EndAtCut,+ transitions::Alignment::Center | transitions::Alignment::Custom => TransitionAlign::CenterAtCut,+ };+}+/// Keep a clip's one-sided transitions (a fade in from nothing, a fade out to nothing) on its edges/// after a regular trim moved them, no longer than the clip (#374). Transitions between two clips/// are left alone: a regular trim cannot move their cut.@@ -258,30 +270,14 @@ fn fades_follow_edges(track: &mut Track, clip: ClipId) {}/// Keep each transition between `clip` and its neighbor within the two clips after a regular trim-/// or a non-ripple speed change made `clip` shorter: the transition is shortened when the clips are-/// now shorter than it, moved back inside them, and its stored alignment follows where that leaves it-/// on the cut (as `transitions::set_span` stores it: Custom Start has no variant).+/// or a non-ripple speed change made `clip` shorter ([`keep_within_clips`]).fn transitions_stay_within_clips(track: &mut Track, clip: ClipId, frame: Tick) {- let spans: Vec<Option<(Tick, Tick, Tick)>> = track- .transitions- .iter()- .map(|tr| match (tr.from.and_then(|c| track.item(c)), tr.to.and_then(|c| track.item(c))) {- (Some(f), Some(t)) if (f.id == clip || t.id == clip) && f.start < t.end() => Some((f.start, t.start, t.end())),- _ => None,- })- .collect();+ let spans: Vec<Option<(Tick, Tick, Tick)>> =+ track.transitions.iter().map(|tr| clips_span(track, tr).filter(|_| tr.from == Some(clip) || tr.to == Some(clip))).collect();for (tr, span) in track.transitions.iter_mut().zip(spans) {- let Some((lo, cut, hi)) = span else { continue };- if tr.start >= lo && tr.end() <= hi {- continue;+ if let Some(span) = span {+ keep_within_clips(tr, span, frame);}- tr.duration = tr.duration.min(hi - lo);- tr.start = tr.start.clamp(lo, hi - tr.duration);- tr.align = match transitions::alignment(tr, cut, frame) {- transitions::Alignment::Start => filmcraft_project::TransitionAlign::StartAtCut,- transitions::Alignment::End => filmcraft_project::TransitionAlign::EndAtCut,- transitions::Alignment::Center | transitions::Alignment::Custom => filmcraft_project::TransitionAlign::CenterAtCut,- };}}diff --git a/crates/ui-egui/src/panels/transition_controls.rs b/crates/ui-egui/src/panels/transition_controls.rsindex 30dc12cd1..38a439776 100644--- a/crates/ui-egui/src/panels/transition_controls.rs+++ b/crates/ui-egui/src/panels/transition_controls.rs@@ -28,9 +28,9 @@//! the dialog's `transitionDuration.value`, `.ok`, `.cancel`.use egui::{Align2, Pos2, Rect, RichText, Sense, Stroke, pos2, vec2};+use filmcraft_edit::Edge;use filmcraft_edit::transitions::{self as trn, Alignment};-use filmcraft_edit::{Edge, EditCtx};-use filmcraft_project::{ClipId, ParamKind, ParamValue, Transition, TransitionId};+use filmcraft_project::{ParamKind, ParamValue, Transition, TransitionId};use filmcraft_time::{FrameRate, Tick};use serde_json::{Value, json};@@ -365,7 +365,8 @@ fn timeline(app: &mut FilmcraftApp, ui: &mut egui::Ui, lane: Rect, id: Transitio&& d.cut&& let (Some(pos), Some(a), Some(b)) = (sresp.interact_pointer_pos(), x.from, x.to){- d.roll = roll_reach(app, a, b, rate.snap_nearest(ticks_for(lane, d.view, pos.x - d.from_x)));+ // as far as `timeline.roll` will move it on release; 0 when the roll would fail+ d.roll = filmcraft_engine::commands::roll_delta(&app.session, a, b, rate.snap_nearest(ticks_for(lane, d.view, pos.x - d.from_x))).unwrap_or(Tick::ZERO);} else if sresp.dragged()&& let Some(d) = drag.as_mut()&& !d.cut@@ -411,28 +412,6 @@ fn timeline(app: &mut FilmcraftApp, ui: &mut egui::Ui, lane: Rect, id: Transitiochange}-/// How far `timeline.roll` would move the cut between `left` and `right` toward `want`: the same-/// limits on a copy of the sequence (the clips' media, a frame left in each, the transition on the-/// cut, linked clips when Linked Selection is on). 0 when the roll would fail.-fn roll_reach(app: &FilmcraftApp, left: ClipId, right: ClipId, want: Tick) -> Tick {- let Some(seq) = app.session.active_sequence() else { return Tick::ZERO };- let project = &app.session.project;- let durations = |item| filmcraft_engine::media_duration(project, &app.session.media, item);- let starts = |item| filmcraft_engine::media_start(project, item);- let mut next = project.next_id;- let mut ctx = EditCtx { next_id: &mut next, media_duration: &durations, media_start: &starts, min_duration: seq.settings.frame_rate.frame_duration() };- let mut d = want;- for (l, r) in filmcraft_engine::commands::linked_roll_pairs(seq, left, right, app.session.state.linked_selection) {- let mut probe = seq.clone();- match filmcraft_edit::roll(&mut probe, l, r, d, &mut ctx) {- Ok(reach) if reach.abs() < d.abs() => d = reach,- Ok(_) => {}- Err(_) => return Tick::ZERO,- }- }- d-}-/// The timeline's ruler: ticks and sequence timecode across `view` (the clip view's spacing).fn paint_ruler(p: &egui::Painter, ruler: Rect, view: (Tick, Tick), rate: FrameRate, drop_frame: bool, t: &Tokens) {let p = p.with_clip_rect(ruler.intersect(p.clip_rect()));