diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index 22367e9..152a54f 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,10 @@ 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+d: the mnemonic letter for "dissolve", + // with ctrl its own room now that plain "d" is Detach's -- + // the same letter, the modifier telling them apart. + b(ActionId::Dissolve, "d", 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 +1288,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/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.