A dissolve key and menu item join two video clips (ctrl+x)
Browse files at this commit- feat
- a dissolve key and menu item join two video clips (ctrl+x)
7 changed files +125 -3
- crates/app/src/keymap.rs +16 -2
- crates/app/src/menus.rs +5 -1
- crates/app/src/player/actions.rs +2 -0
- crates/app/src/player/timeline_edit.rs +35 -0
- crates/app/src/ui/timeline.rs +27 -0
- crates/app/src/ui/widgets.rs +28 -0
- crates/engine/src/playback.rs +12 -0
crates/app/src/keymap.rsmodified+16 -2
| @@ -134,6 +134,11 @@ actions! { | |||
| 134 | /// two adjacent clips picked on one lane, or a single pick faded into the | 134 | /// two adjacent clips picked on one lane, or a single pick faded into the |
| 135 | /// clip right after it. | 135 | /// clip right after it. |
| 136 | Crossfade, | 136 | Crossfade, |
| 137 | + /// Dissolves the selected video clip into its neighbour | ||
| 138 | + /// ([`Project::set_transition_out`]): two adjacent clips picked on one | ||
| 139 | + /// lane, or a single pick dissolved into the clip right after it. A | ||
| 140 | + /// second press on a clip that already dissolves removes it instead. | ||
| 141 | + Dissolve, | ||
| 137 | Mix, | 142 | Mix, |
| 138 | ToggleSnap, | 143 | ToggleSnap, |
| 139 | ToggleSubtitles, | 144 | ToggleSubtitles, |
| @@ -225,6 +230,7 @@ impl ActionId { | |||
| 225 | ActionId::Speed => "Speed (tape)…", | 230 | ActionId::Speed => "Speed (tape)…", |
| 226 | ActionId::Silence => "Silences: cut or speed up…", | 231 | ActionId::Silence => "Silences: cut or speed up…", |
| 227 | ActionId::Crossfade => "Crossfade into the next clip", | 232 | ActionId::Crossfade => "Crossfade into the next clip", |
| 233 | + ActionId::Dissolve => "Dissolve into the next clip", | ||
| 228 | ActionId::Mix => "Mix: track volumes and the limiter…", | 234 | ActionId::Mix => "Mix: track volumes and the limiter…", |
| 229 | ActionId::ToggleSnap => "Snap on / off (edges, the playhead, the start)", | 235 | ActionId::ToggleSnap => "Snap on / off (edges, the playhead, the start)", |
| 230 | ActionId::ToggleSubtitles => "Subtitles on / off over the picture", | 236 | ActionId::ToggleSubtitles => "Subtitles on / off over the picture", |
| @@ -292,6 +298,7 @@ impl ActionId { | |||
| 292 | ActionId::Speed => "speed", | 298 | ActionId::Speed => "speed", |
| 293 | ActionId::Silence => "silence", | 299 | ActionId::Silence => "silence", |
| 294 | ActionId::Crossfade => "crossfade", | 300 | ActionId::Crossfade => "crossfade", |
| 301 | + ActionId::Dissolve => "dissolve", | ||
| 295 | ActionId::Mix => "mix", | 302 | ActionId::Mix => "mix", |
| 296 | ActionId::ToggleSnap => "toggle-snap", | 303 | ActionId::ToggleSnap => "toggle-snap", |
| 297 | ActionId::ToggleSubtitles => "toggle-subtitles", | 304 | ActionId::ToggleSubtitles => "toggle-subtitles", |
| @@ -346,7 +353,8 @@ impl ActionId { | |||
| 346 | // timeline the clip is on -- it is a clip card like the three | 353 | // timeline the clip is on -- it is a clip card like the three |
| 347 | // above it, opened on whichever half was picked. | 354 | // above it, opened on whichever half was picked. |
| 348 | | ActionId::Silence | 355 | | ActionId::Silence |
| 349 | - | ActionId::Crossfade => Category::Clips, | 356 | + | ActionId::Crossfade |
| 357 | + | ActionId::Dissolve => Category::Clips, | ||
| 350 | // The project's own picture size is not a clip's business, and not | 358 | // The project's own picture size is not a clip's business, and not |
| 351 | // a file operation either: it is what the viewer is looking at. | 359 | // a file operation either: it is what the viewer is looking at. |
| 352 | // Neither is how much of the timeline the panel shows: a zoom edits | 360 | // Neither is how much of the timeline the panel shows: a zoom edits |
| @@ -964,6 +972,12 @@ impl Keymap { | |||
| 964 | // ctrl its own room now that plain "f" is the mix card's own | 972 | // ctrl its own room now that plain "f" is the mix card's own |
| 965 | // (below) -- the same letter, the modifier telling them apart. | 973 | // (below) -- the same letter, the modifier telling them apart. |
| 966 | b(ActionId::Crossfade, "f", true), | 974 | b(ActionId::Crossfade, "f", true), |
| 975 | + // Dissolve takes ctrl+x: the join it draws on the timeline is | ||
| 976 | + // an X (widgets.rs, dissolve_glyph) -- "d" itself is taken | ||
| 977 | + // both plain (Detach) and, in the keymap's own rebind test, | ||
| 978 | + // as the free chord it rebinds Delete onto, so this reaches | ||
| 979 | + // for the shape instead of the word. | ||
| 980 | + b(ActionId::Dissolve, "x", true), | ||
| 967 | // The mix card takes "f", for the faders on it: "m" would be | 981 | // The mix card takes "f", for the faders on it: "m" would be |
| 968 | // the word but it is the monitoring mute, which is this | 982 | // the word but it is the monitoring mute, which is this |
| 969 | // machine's volume and not the project's -- two things one key | 983 | // machine's volume and not the project's -- two things one key |
| @@ -1276,7 +1290,7 @@ mod tests { | |||
| 1276 | #[test] | 1290 | #[test] |
| 1277 | fn every_default_stroke_reaches_its_action() { | 1291 | fn every_default_stroke_reaches_its_action() { |
| 1278 | let k = Keymap::defaults(); | 1292 | let k = Keymap::defaults(); |
| 1279 | - assert_eq!(k.entries().len(), 62); | 1293 | + assert_eq!(k.entries().len(), 63); |
| 1280 | assert_eq!(k.lookup("f11", false), Some(ActionId::Fullscreen)); | 1294 | assert_eq!(k.lookup("f11", false), Some(ActionId::Fullscreen)); |
| 1281 | assert_eq!(k.lookup("w", false), Some(ActionId::Screenshot)); | 1295 | assert_eq!(k.lookup("w", false), Some(ActionId::Screenshot)); |
| 1282 | assert_eq!(k.lookup("y", false), Some(ActionId::SubtitleStyle)); | 1296 | assert_eq!(k.lookup("y", false), Some(ActionId::SubtitleStyle)); |
crates/app/src/menus.rsmodified+5 -1
| @@ -142,7 +142,7 @@ impl RowItem { | |||
| 142 | /// action a stroke already reaches -- the menu is a second way *to* the actions | 142 | /// action a stroke already reaches -- the menu is a second way *to* the actions |
| 143 | /// and never a second version of them -- so both the label and the hint come | 143 | /// and never a second version of them -- so both the label and the hint come |
| 144 | /// out of the keymap registry and the two can never disagree. | 144 | /// out of the keymap registry and the two can never disagree. |
| 145 | -pub(crate) const MENU_ITEMS: [ActionId; 14] = [ | 145 | +pub(crate) const MENU_ITEMS: [ActionId; 15] = [ |
| 146 | ActionId::Cut, | 146 | ActionId::Cut, |
| 147 | // The clipboard pair, which had no door but a chord: copy takes the clip the | 147 | // The clipboard pair, which had no door but a chord: copy takes the clip the |
| 148 | // menu names, and paste is the timeline's rather than this clip's -- the | 148 | // 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] = [ | |||
| 160 | // was clicked -- and a card only a stroke could open is one a pointer never | 160 | // was clicked -- and a card only a stroke could open is one a pointer never |
| 161 | // finds. | 161 | // finds. |
| 162 | ActionId::Silence, | 162 | ActionId::Silence, |
| 163 | + // The dissolve is a video clip's own join, same door as the crossfade | ||
| 164 | + // above it would be for sound -- a stroke-only pair, opened here on | ||
| 165 | + // whichever half was clicked. | ||
| 166 | + ActionId::Dissolve, | ||
| 163 | ActionId::Color, | 167 | ActionId::Color, |
| 164 | ActionId::Fit, | 168 | ActionId::Fit, |
| 165 | ActionId::ToggleMute, | 169 | ActionId::ToggleMute, |
crates/app/src/player/actions.rsmodified+2 -0
| @@ -54,6 +54,7 @@ impl Player { | |||
| 54 | | ActionId::RemoveSubtitleLane | 54 | | ActionId::RemoveSubtitleLane |
| 55 | | ActionId::ImportSubtitles | 55 | | ActionId::ImportSubtitles |
| 56 | | ActionId::Crossfade | 56 | | ActionId::Crossfade |
| 57 | + | ActionId::Dissolve | ||
| 57 | ) { | 58 | ) { |
| 58 | self.mark_dirty(); | 59 | self.mark_dirty(); |
| 59 | } | 60 | } |
| @@ -90,6 +91,7 @@ impl Player { | |||
| 90 | ActionId::Cut => self.cut(cx), | 91 | ActionId::Cut => self.cut(cx), |
| 91 | ActionId::Regroup => self.regroup(cx), | 92 | ActionId::Regroup => self.regroup(cx), |
| 92 | ActionId::Crossfade => self.crossfade_selected(cx), | 93 | ActionId::Crossfade => self.crossfade_selected(cx), |
| 94 | + ActionId::Dissolve => self.dissolve_selected(cx), | ||
| 93 | ActionId::Detach => self.detach(cx), | 95 | ActionId::Detach => self.detach(cx), |
| 94 | ActionId::Group => self.group(cx), | 96 | ActionId::Group => self.group(cx), |
| 95 | ActionId::Select => self.select_under_playhead(cx), | 97 | ActionId::Select => self.select_under_playhead(cx), |
crates/app/src/player/timeline_edit.rsmodified+35 -0
| @@ -1295,6 +1295,41 @@ impl Player { | |||
| 1295 | cx.notify(); | 1295 | cx.notify(); |
| 1296 | } | 1296 | } |
| 1297 | 1297 | ||
| 1298 | + /// Dissolves the join the selection names, into or back out of it: two | ||
| 1299 | + /// picks on one video lane take the pair, one pick takes it and its | ||
| 1300 | + /// right-hand neighbour. If the leading clip already carries a dissolve | ||
| 1301 | + /// this removes it (`0` frames) instead of widening it -- a toggle, same | ||
| 1302 | + /// key either way. The engine owns adjacency ([`Project::set_transition_out`]); | ||
| 1303 | + /// a refusal is worded here, in [`Player::crossfade_selected`]'s voice. | ||
| 1304 | + pub(crate) fn dissolve_selected(&mut self, cx: &mut Context<Self>) { | ||
| 1305 | + if self.exporting().is_some() { | ||
| 1306 | + return; | ||
| 1307 | + } | ||
| 1308 | + let Some((lane, idx)) = (match self.selected.picks() { | ||
| 1309 | + [a, b] if a.0 == b.0 && a.1.abs_diff(b.1) == 1 => Some((a.0, a.1.min(b.1))), | ||
| 1310 | + _ => self.selected.anchor(), | ||
| 1311 | + }) else { | ||
| 1312 | + self.notify_user("NOTHING TO DISSOLVE — select a video clip that has a neighbour".into()); | ||
| 1313 | + cx.notify(); | ||
| 1314 | + return; | ||
| 1315 | + }; | ||
| 1316 | + let Some(session) = &mut self.session else { | ||
| 1317 | + cx.notify(); | ||
| 1318 | + return; | ||
| 1319 | + }; | ||
| 1320 | + let removing = session.transition_out_of(lane, idx) > 0; | ||
| 1321 | + let frames = if removing { 0 } else { self.fps.round().max(1.) as u32 }; | ||
| 1322 | + if !session.set_transition_out(lane, idx, frames) { | ||
| 1323 | + self.notify_user( | ||
| 1324 | + "NOTHING TO DISSOLVE — it takes two video clips sitting end to end on one lane" | ||
| 1325 | + .into(), | ||
| 1326 | + ); | ||
| 1327 | + } else if removing { | ||
| 1328 | + self.notify_user("DISSOLVE REMOVED — the clips cut again".into()); | ||
| 1329 | + } | ||
| 1330 | + cx.notify(); | ||
| 1331 | + } | ||
| 1332 | + | ||
| 1298 | /// The clip as the drag is showing it: an edge under the pointer moves its | 1333 | /// The clip as the drag is showing it: an edge under the pointer moves its |
| 1299 | /// own box, and the boxes of everything linked to it, before anything is | 1334 | /// own box, and the boxes of everything linked to it, before anything is |
| 1300 | /// committed. Display only -- the project is not touched until the release. | 1335 | /// committed. Display only -- the project is not touched until the release. |
crates/app/src/ui/timeline.rsmodified+27 -0
| @@ -1545,6 +1545,33 @@ impl Player { | |||
| 1545 | .flatten(), | 1545 | .flatten(), |
| 1546 | ) | 1546 | ) |
| 1547 | }) | 1547 | }) |
| 1548 | + // The dissolve: a small X astride the join, drawn | ||
| 1549 | + // over the last `transition_out` frames of this | ||
| 1550 | + // clip's own box, whenever the next clip on the | ||
| 1551 | + // lane actually abuts it -- the engine already | ||
| 1552 | + // refuses `transition_out` on anything else | ||
| 1553 | + // ([`Project::set_transition_out`]), but a moved | ||
| 1554 | + // neighbour can leave a stale value behind, so | ||
| 1555 | + // this checks the join itself rather than trust | ||
| 1556 | + // the field alone. | ||
| 1557 | + .when( | ||
| 1558 | + lane.kind == LaneKind::Video | ||
| 1559 | + && clip.transition_out > 0 | ||
| 1560 | + && clips.get(i + 1).is_some_and(|n| n.start == clip.end()), | ||
| 1561 | + |d| { | ||
| 1562 | + d.child( | ||
| 1563 | + div() | ||
| 1564 | + .absolute() | ||
| 1565 | + .right_0() | ||
| 1566 | + .top_0() | ||
| 1567 | + .h_full() | ||
| 1568 | + .w(px(scale | ||
| 1569 | + .width_px(f64::from(clip.transition_out) / self.fps) | ||
| 1570 | + .min(width))) | ||
| 1571 | + .child(dissolve_glyph()), | ||
| 1572 | + ) | ||
| 1573 | + }, | ||
| 1574 | + ) | ||
| 1548 | // The fade handles: a small grab corner at each | 1575 | // The fade handles: a small grab corner at each |
| 1549 | // *top* of an audio clip's box, sitting just | 1576 | // *top* of an audio clip's box, sitting just |
| 1550 | // inside the [`EDGE_W`] trim strip rather than on | 1577 | // inside the [`EDGE_W`] trim strip rather than on |
crates/app/src/ui/widgets.rsmodified+28 -0
| @@ -76,6 +76,34 @@ pub(crate) fn fade_wedge(is_in: bool) -> impl IntoElement { | |||
| 76 | .size_full() | 76 | .size_full() |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | +/// A video clip's dissolve into its neighbour, drawn as a small X astride the | ||
| 80 | +/// join -- the box it is given is the last [`Clip::transition_out`] frames of | ||
| 81 | +/// the clip's own width, so the mark sits right at the edge it dissolves | ||
| 82 | +/// through. Two strokes rather than [`fade_wedge`]'s fill: a dissolve is not | ||
| 83 | +/// a ramp to or from silence, it is two clips overlapping, and an X reads as | ||
| 84 | +/// a splice the way a wedge reads as a fade. | ||
| 85 | +pub(crate) fn dissolve_glyph() -> impl IntoElement { | ||
| 86 | + canvas( | ||
| 87 | + |_, _, _| (), | ||
| 88 | + move |bounds, _, window, _| { | ||
| 89 | + let (o, s) = (bounds.origin, bounds.size); | ||
| 90 | + let (w, h) = (f32::from(s.width), f32::from(s.height)); | ||
| 91 | + if w <= 0. || h <= 0. { | ||
| 92 | + return; | ||
| 93 | + } | ||
| 94 | + let mut path = PathBuilder::stroke(px(1.5)); | ||
| 95 | + path.move_to(point(o.x, o.y)); | ||
| 96 | + path.line_to(point(o.x + px(w), o.y + px(h))); | ||
| 97 | + path.move_to(point(o.x + px(w), o.y)); | ||
| 98 | + path.line_to(point(o.x, o.y + px(h))); | ||
| 99 | + if let Ok(path) = path.build() { | ||
| 100 | + window.paint_path(path, rgba(ACCENT_WASH())); | ||
| 101 | + } | ||
| 102 | + }, | ||
| 103 | + ) | ||
| 104 | + .size_full() | ||
| 105 | +} | ||
| 106 | + | ||
| 79 | /// A toolbar button: its glyph, its name, and its key on hover. `id` only buys | 107 | /// A toolbar button: its glyph, its name, and its key on hover. `id` only buys |
| 80 | /// `on_click` and the tooltip -- it is still not focusable, so the root's own | 108 | /// `on_click` and the tooltip -- it is still not focusable, so the root's own |
| 81 | /// key listener keeps working after a press, and the click lands on mouse-up | 109 | /// key listener keeps working after a press, and the click lands on mouse-up |
crates/engine/src/playback.rsmodified+12 -0
| @@ -2587,6 +2587,18 @@ impl PlaybackSession { | |||
| 2587 | self.edit(Dirty::Sound, |p| p.crossfade(lane, idx, frames)) | 2587 | self.edit(Dirty::Sound, |p| p.crossfade(lane, idx, frames)) |
| 2588 | } | 2588 | } |
| 2589 | 2589 | ||
| 2590 | + /// Timeline frames of dissolve at the end of the clip at `idx` of `lane`, | ||
| 2591 | + /// into its neighbour. `0` for an index that is not there. | ||
| 2592 | + pub fn transition_out_of(&self, lane: Lane, idx: usize) -> u32 { | ||
| 2593 | + self.project.transition_out_of(lane, idx) | ||
| 2594 | + } | ||
| 2595 | + | ||
| 2596 | + /// Sets that clip's dissolve into its neighbour, clamped to its own | ||
| 2597 | + /// length. A picture edit -- same as a grade or fit policy. | ||
| 2598 | + pub fn set_transition_out(&mut self, lane: Lane, idx: usize, frames: u32) -> bool { | ||
| 2599 | + self.edit(Dirty::Picture, |p| p.set_transition_out(lane, idx, frames)) | ||
| 2600 | + } | ||
| 2601 | + | ||
| 2590 | /// The clip at `idx` -- what a caller copies. It is a pair of source frame | 2602 | /// The clip at `idx` -- what a caller copies. It is a pair of source frame |
| 2591 | /// numbers and nothing else, so a copy stays valid after the clip it came | 2603 | /// numbers and nothing else, so a copy stays valid after the clip it came |
| 2592 | /// from is deleted. `None` past the end. | 2604 | /// from is deleted. `None` past the end. |