diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index 22367e9..5020786 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -134,6 +134,11 @@ actions! { /// two adjacent clips picked on one lane, or a single pick faded into the /// clip right after it. Crossfade, + /// Dissolves the selected video clip into its neighbour + /// ([`Project::set_transition_out`]): two adjacent clips picked on one + /// lane, or a single pick dissolved into the clip right after it. A + /// second press on a clip that already dissolves removes it instead. + Dissolve, Mix, ToggleSnap, ToggleSubtitles, @@ -225,6 +230,7 @@ impl ActionId { ActionId::Speed => "Speed (tape)…", ActionId::Silence => "Silences: cut or speed up…", ActionId::Crossfade => "Crossfade into the next clip", + ActionId::Dissolve => "Dissolve into the next clip", ActionId::Mix => "Mix: track volumes and the limiter…", ActionId::ToggleSnap => "Snap on / off (edges, the playhead, the start)", ActionId::ToggleSubtitles => "Subtitles on / off over the picture", @@ -292,6 +298,7 @@ impl ActionId { ActionId::Speed => "speed", ActionId::Silence => "silence", ActionId::Crossfade => "crossfade", + ActionId::Dissolve => "dissolve", ActionId::Mix => "mix", ActionId::ToggleSnap => "toggle-snap", ActionId::ToggleSubtitles => "toggle-subtitles", @@ -346,7 +353,8 @@ impl ActionId { // timeline the clip is on -- it is a clip card like the three // above it, opened on whichever half was picked. | ActionId::Silence - | ActionId::Crossfade => Category::Clips, + | ActionId::Crossfade + | ActionId::Dissolve => Category::Clips, // The project's own picture size is not a clip's business, and not // a file operation either: it is what the viewer is looking at. // Neither is how much of the timeline the panel shows: a zoom edits @@ -964,6 +972,12 @@ impl Keymap { // ctrl its own room now that plain "f" is the mix card's own // (below) -- the same letter, the modifier telling them apart. b(ActionId::Crossfade, "f", true), + // Dissolve takes ctrl+x: the join it draws on the timeline is + // an X (widgets.rs, dissolve_glyph) -- "d" itself is taken + // both plain (Detach) and, in the keymap's own rebind test, + // as the free chord it rebinds Delete onto, so this reaches + // for the shape instead of the word. + b(ActionId::Dissolve, "x", true), // The mix card takes "f", for the faders on it: "m" would be // the word but it is the monitoring mute, which is this // machine's volume and not the project's -- two things one key @@ -1276,7 +1290,7 @@ mod tests { #[test] fn every_default_stroke_reaches_its_action() { let k = Keymap::defaults(); - assert_eq!(k.entries().len(), 62); + assert_eq!(k.entries().len(), 63); assert_eq!(k.lookup("f11", false), Some(ActionId::Fullscreen)); assert_eq!(k.lookup("w", false), Some(ActionId::Screenshot)); assert_eq!(k.lookup("y", false), Some(ActionId::SubtitleStyle)); diff --git a/crates/app/src/menus.rs b/crates/app/src/menus.rs index 7845172..35dcb3e 100644 --- a/crates/app/src/menus.rs +++ b/crates/app/src/menus.rs @@ -142,7 +142,7 @@ impl RowItem { /// action a stroke already reaches -- the menu is a second way *to* the actions /// and never a second version of them -- so both the label and the hint come /// out of the keymap registry and the two can never disagree. -pub(crate) const MENU_ITEMS: [ActionId; 14] = [ +pub(crate) const MENU_ITEMS: [ActionId; 15] = [ ActionId::Cut, // The clipboard pair, which had no door but a chord: copy takes the clip the // menu names, and paste is the timeline's rather than this clip's -- the @@ -160,6 +160,10 @@ pub(crate) const MENU_ITEMS: [ActionId; 14] = [ // was clicked -- and a card only a stroke could open is one a pointer never // finds. ActionId::Silence, + // The dissolve is a video clip's own join, same door as the crossfade + // above it would be for sound -- a stroke-only pair, opened here on + // whichever half was clicked. + ActionId::Dissolve, ActionId::Color, ActionId::Fit, ActionId::ToggleMute, diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index ca77480..59d0753 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -54,6 +54,7 @@ impl Player { | ActionId::RemoveSubtitleLane | ActionId::ImportSubtitles | ActionId::Crossfade + | ActionId::Dissolve ) { self.mark_dirty(); } @@ -90,6 +91,7 @@ impl Player { ActionId::Cut => self.cut(cx), ActionId::Regroup => self.regroup(cx), ActionId::Crossfade => self.crossfade_selected(cx), + ActionId::Dissolve => self.dissolve_selected(cx), ActionId::Detach => self.detach(cx), ActionId::Group => self.group(cx), ActionId::Select => self.select_under_playhead(cx), diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index e856c25..6191576 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -1295,6 +1295,41 @@ impl Player { cx.notify(); } + /// Dissolves the join the selection names, into or back out of it: two + /// picks on one video lane take the pair, one pick takes it and its + /// right-hand neighbour. If the leading clip already carries a dissolve + /// this removes it (`0` frames) instead of widening it -- a toggle, same + /// key either way. The engine owns adjacency ([`Project::set_transition_out`]); + /// a refusal is worded here, in [`Player::crossfade_selected`]'s voice. + pub(crate) fn dissolve_selected(&mut self, cx: &mut Context) { + if self.exporting().is_some() { + return; + } + let Some((lane, idx)) = (match self.selected.picks() { + [a, b] if a.0 == b.0 && a.1.abs_diff(b.1) == 1 => Some((a.0, a.1.min(b.1))), + _ => self.selected.anchor(), + }) else { + self.notify_user("NOTHING TO DISSOLVE — select a video clip that has a neighbour".into()); + cx.notify(); + return; + }; + let Some(session) = &mut self.session else { + cx.notify(); + return; + }; + let removing = session.transition_out_of(lane, idx) > 0; + let frames = if removing { 0 } else { self.fps.round().max(1.) as u32 }; + if !session.set_transition_out(lane, idx, frames) { + self.notify_user( + "NOTHING TO DISSOLVE — it takes two video clips sitting end to end on one lane" + .into(), + ); + } else if removing { + self.notify_user("DISSOLVE REMOVED — the clips cut again".into()); + } + cx.notify(); + } + /// The clip as the drag is showing it: an edge under the pointer moves its /// own box, and the boxes of everything linked to it, before anything is /// committed. Display only -- the project is not touched until the release. diff --git a/crates/app/src/ui/timeline.rs b/crates/app/src/ui/timeline.rs index 6ea34fb..717e90f 100644 --- a/crates/app/src/ui/timeline.rs +++ b/crates/app/src/ui/timeline.rs @@ -1545,6 +1545,33 @@ impl Player { .flatten(), ) }) + // The dissolve: a small X astride the join, drawn + // over the last `transition_out` frames of this + // clip's own box, whenever the next clip on the + // lane actually abuts it -- the engine already + // refuses `transition_out` on anything else + // ([`Project::set_transition_out`]), but a moved + // neighbour can leave a stale value behind, so + // this checks the join itself rather than trust + // the field alone. + .when( + lane.kind == LaneKind::Video + && clip.transition_out > 0 + && clips.get(i + 1).is_some_and(|n| n.start == clip.end()), + |d| { + d.child( + div() + .absolute() + .right_0() + .top_0() + .h_full() + .w(px(scale + .width_px(f64::from(clip.transition_out) / self.fps) + .min(width))) + .child(dissolve_glyph()), + ) + }, + ) // The fade handles: a small grab corner at each // *top* of an audio clip's box, sitting just // inside the [`EDGE_W`] trim strip rather than on diff --git a/crates/app/src/ui/widgets.rs b/crates/app/src/ui/widgets.rs index 4223c48..dd4e0b8 100644 --- a/crates/app/src/ui/widgets.rs +++ b/crates/app/src/ui/widgets.rs @@ -76,6 +76,34 @@ pub(crate) fn fade_wedge(is_in: bool) -> impl IntoElement { .size_full() } +/// A video clip's dissolve into its neighbour, drawn as a small X astride the +/// join -- the box it is given is the last [`Clip::transition_out`] frames of +/// the clip's own width, so the mark sits right at the edge it dissolves +/// through. Two strokes rather than [`fade_wedge`]'s fill: a dissolve is not +/// a ramp to or from silence, it is two clips overlapping, and an X reads as +/// a splice the way a wedge reads as a fade. +pub(crate) fn dissolve_glyph() -> impl IntoElement { + canvas( + |_, _, _| (), + move |bounds, _, window, _| { + let (o, s) = (bounds.origin, bounds.size); + let (w, h) = (f32::from(s.width), f32::from(s.height)); + if w <= 0. || h <= 0. { + return; + } + let mut path = PathBuilder::stroke(px(1.5)); + path.move_to(point(o.x, o.y)); + path.line_to(point(o.x + px(w), o.y + px(h))); + path.move_to(point(o.x + px(w), o.y)); + path.line_to(point(o.x, o.y + px(h))); + if let Ok(path) = path.build() { + window.paint_path(path, rgba(ACCENT_WASH())); + } + }, + ) + .size_full() +} + /// A toolbar button: its glyph, its name, and its key on hover. `id` only buys /// `on_click` and the tooltip -- it is still not focusable, so the root's own /// key listener keeps working after a press, and the click lands on mouse-up diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index f73a194..491c2fb 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -2587,6 +2587,18 @@ impl PlaybackSession { self.edit(Dirty::Sound, |p| p.crossfade(lane, idx, frames)) } + /// Timeline frames of dissolve at the end of the clip at `idx` of `lane`, + /// into its neighbour. `0` for an index that is not there. + pub fn transition_out_of(&self, lane: Lane, idx: usize) -> u32 { + self.project.transition_out_of(lane, idx) + } + + /// Sets that clip's dissolve into its neighbour, clamped to its own + /// length. A picture edit -- same as a grade or fit policy. + pub fn set_transition_out(&mut self, lane: Lane, idx: usize, frames: u32) -> bool { + self.edit(Dirty::Picture, |p| p.set_transition_out(lane, idx, frames)) + } + /// The clip at `idx` -- what a caller copies. It is a pair of source frame /// numbers and nothing else, so a copy stays valid after the clip it came /// from is deleted. `None` past the end.