forge
Explore
Log in

Don't you dare go Hollow

A dissolve key and menu item join two video clips (ctrl+x)

Browse files at this commit

86ef2d549813f2e44313724c2d4c07d8fb149a82Ahmet Kaan GümüşParent: 82061a9270631a
  • feat
    • a dissolve key and menu item join two video clips (ctrl+x)
Show full message
✨ feat(app): a dissolve key and menu item join two video clips (ctrl+x)
crates/app/src/keymap.rsmodified+16 -2
@@ -134,6 +134,11 @@ actions! {
134134 /// two adjacent clips picked on one lane, or a single pick faded into the
135135 /// clip right after it.
136136 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,
137142 Mix,
138143 ToggleSnap,
139144 ToggleSubtitles,
@@ -225,6 +230,7 @@ impl ActionId {
225230 ActionId::Speed => "Speed (tape)…",
226231 ActionId::Silence => "Silences: cut or speed up…",
227232 ActionId::Crossfade => "Crossfade into the next clip",
233+ ActionId::Dissolve => "Dissolve into the next clip",
228234 ActionId::Mix => "Mix: track volumes and the limiter…",
229235 ActionId::ToggleSnap => "Snap on / off (edges, the playhead, the start)",
230236 ActionId::ToggleSubtitles => "Subtitles on / off over the picture",
@@ -292,6 +298,7 @@ impl ActionId {
292298 ActionId::Speed => "speed",
293299 ActionId::Silence => "silence",
294300 ActionId::Crossfade => "crossfade",
301+ ActionId::Dissolve => "dissolve",
295302 ActionId::Mix => "mix",
296303 ActionId::ToggleSnap => "toggle-snap",
297304 ActionId::ToggleSubtitles => "toggle-subtitles",
@@ -346,7 +353,8 @@ impl ActionId {
346353 // timeline the clip is on -- it is a clip card like the three
347354 // above it, opened on whichever half was picked.
348355 | ActionId::Silence
349- | ActionId::Crossfade => Category::Clips,
356+ | ActionId::Crossfade
357+ | ActionId::Dissolve => Category::Clips,
350358 // The project's own picture size is not a clip's business, and not
351359 // a file operation either: it is what the viewer is looking at.
352360 // Neither is how much of the timeline the panel shows: a zoom edits
@@ -964,6 +972,12 @@ impl Keymap {
964972 // ctrl its own room now that plain "f" is the mix card's own
965973 // (below) -- the same letter, the modifier telling them apart.
966974 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),
967981 // The mix card takes "f", for the faders on it: "m" would be
968982 // the word but it is the monitoring mute, which is this
969983 // machine's volume and not the project's -- two things one key
@@ -1276,7 +1290,7 @@ mod tests {
12761290 #[test]
12771291 fn every_default_stroke_reaches_its_action() {
12781292 let k = Keymap::defaults();
1279- assert_eq!(k.entries().len(), 62);
1293+ assert_eq!(k.entries().len(), 63);
12801294 assert_eq!(k.lookup("f11", false), Some(ActionId::Fullscreen));
12811295 assert_eq!(k.lookup("w", false), Some(ActionId::Screenshot));
12821296 assert_eq!(k.lookup("y", false), Some(ActionId::SubtitleStyle));
crates/app/src/menus.rsmodified+5 -1
@@ -142,7 +142,7 @@ impl RowItem {
142142 /// action a stroke already reaches -- the menu is a second way *to* the actions
143143 /// and never a second version of them -- so both the label and the hint come
144144 /// 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] = [
146146 ActionId::Cut,
147147 // The clipboard pair, which had no door but a chord: copy takes the clip the
148148 // 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] = [
160160 // was clicked -- and a card only a stroke could open is one a pointer never
161161 // finds.
162162 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,
163167 ActionId::Color,
164168 ActionId::Fit,
165169 ActionId::ToggleMute,
crates/app/src/player/actions.rsmodified+2 -0
@@ -54,6 +54,7 @@ impl Player {
5454 | ActionId::RemoveSubtitleLane
5555 | ActionId::ImportSubtitles
5656 | ActionId::Crossfade
57+ | ActionId::Dissolve
5758 ) {
5859 self.mark_dirty();
5960 }
@@ -90,6 +91,7 @@ impl Player {
9091 ActionId::Cut => self.cut(cx),
9192 ActionId::Regroup => self.regroup(cx),
9293 ActionId::Crossfade => self.crossfade_selected(cx),
94+ ActionId::Dissolve => self.dissolve_selected(cx),
9395 ActionId::Detach => self.detach(cx),
9496 ActionId::Group => self.group(cx),
9597 ActionId::Select => self.select_under_playhead(cx),
crates/app/src/player/timeline_edit.rsmodified+35 -0
@@ -1295,6 +1295,41 @@ impl Player {
12951295 cx.notify();
12961296 }
12971297
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+
12981333 /// The clip as the drag is showing it: an edge under the pointer moves its
12991334 /// own box, and the boxes of everything linked to it, before anything is
13001335 /// 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 {
15451545 .flatten(),
15461546 )
15471547 })
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+ )
15481575 // The fade handles: a small grab corner at each
15491576 // *top* of an audio clip's box, sitting just
15501577 // 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 {
7676 .size_full()
7777 }
7878
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+
79107 /// A toolbar button: its glyph, its name, and its key on hover. `id` only buys
80108 /// `on_click` and the tooltip -- it is still not focusable, so the root's own
81109 /// 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 {
25872587 self.edit(Dirty::Sound, |p| p.crossfade(lane, idx, frames))
25882588 }
25892589
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+
25902602 /// The clip at `idx` -- what a caller copies. It is a pair of source frame
25912603 /// numbers and nothing else, so a copy stays valid after the clip it came
25922604 /// from is deleted. `None` past the end.