Keyboard trim-to-playhead (debt #42)
Browse files at this commitba764f902e0e2434faf7bdc196a7639fa42d3017Parent: b05a649- feat
- keyboard trim-to-playhead (debt #42)
6 changed files +193 -1
- DESIGN.md +4 -0
- crates/app/src/keymap.rs +29 -1
- crates/app/src/oracle.rs +12 -0
- crates/app/src/player/actions.rs +37 -0
- crates/app/src/tests/editing.rs +88 -0
- crates/app/src/ui/spine_stance.rs +23 -0
DESIGN.mdmodified+4 -0
| @@ -142,6 +142,10 @@ The cut is the subject. Grammar (implement before any cosmetics): | |||
| 142 | 142 | ||
| 143 | - `,` `.` — walk cuts (shift = stride 10). The cut readout is the odometer. | 143 | - `,` `.` — walk cuts (shift = stride 10). The cut readout is the odometer. |
| 144 | - `[` `]` — no-aim trim of the subject cut, frame detents, works at any zoom (even 4px clips). | 144 | - `[` `]` — no-aim trim of the subject cut, frame detents, works at any zoom (even 4px clips). |
| 145 | +- `ctrl+{` `ctrl+}` — trim-to-playhead (debt #42): snaps the subject cut's in/out edge straight to | ||
| 146 | + the playhead, one press, one undo step -- the keyboard's own version of dragging the edge to a | ||
| 147 | + spot instead of nudging it a detent at a time. Needs a subject cut with the playhead resting on | ||
| 148 | + it, same as the pair above. | ||
| 145 | - `/` — loop-trim: loop around the subject cut while trimming (the modernized Avid trim mode). | 149 | - `/` — loop-trim: loop around the subject cut while trimming (the modernized Avid trim mode). |
| 146 | - Two-up OUT|IN on the screen when resting on a cut. | 150 | - Two-up OUT|IN on the screen when resting on a cut. |
| 147 | - `j k l` — shuttle; `s` — split; `↵` context-dependent commit; `esc` always retreats. | 151 | - `j k l` — shuttle; `s` — split; `↵` context-dependent commit; `esc` always retreats. |
crates/app/src/keymap.rsmodified+29 -1
| @@ -175,6 +175,16 @@ actions! { | |||
| 175 | /// Loop-trim: loops around the subject cut while trimming it (DESIGN.md | 175 | /// Loop-trim: loops around the subject cut while trimming it (DESIGN.md |
| 176 | /// §6, "the modernized Avid trim mode"). | 176 | /// §6, "the modernized Avid trim mode"). |
| 177 | LoopTrim, | 177 | LoopTrim, |
| 178 | + /// The keyboard's own version of the pointer's drag-the-edge-to-a-spot | ||
| 179 | + /// trim (debt #42: trim used to be pointer-only): snaps the subject | ||
| 180 | + /// cut's in point straight to the playhead, one press, one undo step -- | ||
| 181 | + /// [`ActionId::TrimIn`]'s frame-detent nudge covers the other case. Bare | ||
| 182 | + /// `[`/`{`/ctrl+`[` are all spoken for (nudge, select-prev, sync point), | ||
| 183 | + /// so this takes the next rung of the same bracket family: ctrl held on | ||
| 184 | + /// the shifted bracket, `ctrl+{` (what ctrl+shift+[ actually types). | ||
| 185 | + TrimInToPlayhead, | ||
| 186 | + /// The pair's other half, the subject cut's out point, on `ctrl+}`. | ||
| 187 | + TrimOutToPlayhead, | ||
| 178 | /// Dissolves the selected video clip into its neighbour | 188 | /// Dissolves the selected video clip into its neighbour |
| 179 | /// ([`Project::set_transition_out`]): two adjacent clips picked on one | 189 | /// ([`Project::set_transition_out`]): two adjacent clips picked on one |
| 180 | /// lane, or a single pick dissolved into the clip right after it. A | 190 | /// lane, or a single pick dissolved into the clip right after it. A |
| @@ -296,6 +306,8 @@ impl ActionId { | |||
| 296 | ActionId::TrimIn => "Trim the subject cut's in point", | 306 | ActionId::TrimIn => "Trim the subject cut's in point", |
| 297 | ActionId::TrimOut => "Trim the subject cut's out point", | 307 | ActionId::TrimOut => "Trim the subject cut's out point", |
| 298 | ActionId::LoopTrim => "Loop-trim the subject cut", | 308 | ActionId::LoopTrim => "Loop-trim the subject cut", |
| 309 | + ActionId::TrimInToPlayhead => "Trim the subject cut's in point to the playhead", | ||
| 310 | + ActionId::TrimOutToPlayhead => "Trim the subject cut's out point to the playhead", | ||
| 299 | ActionId::Dissolve => "Dissolve into the next clip", | 311 | ActionId::Dissolve => "Dissolve into the next clip", |
| 300 | ActionId::Mix => "Mix: track volumes and the limiter…", | 312 | ActionId::Mix => "Mix: track volumes and the limiter…", |
| 301 | ActionId::ToggleSnap => "Snap on / off (edges, the playhead, the start)", | 313 | ActionId::ToggleSnap => "Snap on / off (edges, the playhead, the start)", |
| @@ -377,6 +389,8 @@ impl ActionId { | |||
| 377 | ActionId::TrimIn => "trim-in", | 389 | ActionId::TrimIn => "trim-in", |
| 378 | ActionId::TrimOut => "trim-out", | 390 | ActionId::TrimOut => "trim-out", |
| 379 | ActionId::LoopTrim => "loop-trim", | 391 | ActionId::LoopTrim => "loop-trim", |
| 392 | + ActionId::TrimInToPlayhead => "trim-in-to-playhead", | ||
| 393 | + ActionId::TrimOutToPlayhead => "trim-out-to-playhead", | ||
| 380 | ActionId::Dissolve => "dissolve", | 394 | ActionId::Dissolve => "dissolve", |
| 381 | ActionId::Mix => "mix", | 395 | ActionId::Mix => "mix", |
| 382 | ActionId::ToggleSnap => "toggle-snap", | 396 | ActionId::ToggleSnap => "toggle-snap", |
| @@ -444,6 +458,8 @@ impl ActionId { | |||
| 444 | | ActionId::TrimIn | 458 | | ActionId::TrimIn |
| 445 | | ActionId::TrimOut | 459 | | ActionId::TrimOut |
| 446 | | ActionId::LoopTrim | 460 | | ActionId::LoopTrim |
| 461 | + | ActionId::TrimInToPlayhead | ||
| 462 | + | ActionId::TrimOutToPlayhead | ||
| 447 | | ActionId::Dissolve => Category::Clips, | 463 | | ActionId::Dissolve => Category::Clips, |
| 448 | // The project's own picture size is not a clip's business, and not | 464 | // The project's own picture size is not a clip's business, and not |
| 449 | // a file operation either: it is what the viewer is looking at. | 465 | // a file operation either: it is what the viewer is looking at. |
| @@ -1182,6 +1198,15 @@ impl Keymap { | |||
| 1182 | // Loop-trim (DESIGN.md §6, "the modernized Avid trim mode"): | 1198 | // Loop-trim (DESIGN.md §6, "the modernized Avid trim mode"): |
| 1183 | // bare "/" was free. | 1199 | // bare "/" was free. |
| 1184 | b(ActionId::LoopTrim, "/", false), | 1200 | b(ActionId::LoopTrim, "/", false), |
| 1201 | + // Trim-to-playhead (debt #42): the whole bracket family is | ||
| 1202 | + // already spoken for -- bare `[`/`]` nudge, `{`/`}` walk the | ||
| 1203 | + // selection, ctrl+`[`/ctrl+`]` jump sync points -- so this | ||
| 1204 | + // takes the one rung left in the same family, ctrl held on | ||
| 1205 | + // the shifted bracket (`ctrl+{`/`ctrl+}`, what | ||
| 1206 | + // ctrl+shift+[/ctrl+shift+] actually type per this table's | ||
| 1207 | + // own shift note above). | ||
| 1208 | + b(ActionId::TrimInToPlayhead, "{", true), | ||
| 1209 | + b(ActionId::TrimOutToPlayhead, "}", true), | ||
| 1185 | // Dissolve takes ctrl+x: the join it draws on the timeline is | 1210 | // Dissolve takes ctrl+x: the join it draws on the timeline is |
| 1186 | // an X (widgets.rs, dissolve_glyph) -- "d" itself is taken | 1211 | // an X (widgets.rs, dissolve_glyph) -- "d" itself is taken |
| 1187 | // both plain (Detach) and, in the keymap's own rebind test, | 1212 | // both plain (Detach) and, in the keymap's own rebind test, |
| @@ -1491,7 +1516,7 @@ mod tests { | |||
| 1491 | #[test] | 1516 | #[test] |
| 1492 | fn every_default_stroke_reaches_its_action() { | 1517 | fn every_default_stroke_reaches_its_action() { |
| 1493 | let k = Keymap::defaults(); | 1518 | let k = Keymap::defaults(); |
| 1494 | - assert_eq!(k.entries().len(), 76); | 1519 | + assert_eq!(k.entries().len(), 78); |
| 1495 | // The cut odometer: bare walks one, `<`/`>` (what shift+,/shift+. | 1520 | // The cut odometer: bare walks one, `<`/`>` (what shift+,/shift+. |
| 1496 | // actually type) strides ten. | 1521 | // actually type) strides ten. |
| 1497 | assert_eq!(k.lookup(".", false), Some(ActionId::WalkCutNext)); | 1522 | assert_eq!(k.lookup(".", false), Some(ActionId::WalkCutNext)); |
| @@ -1502,6 +1527,9 @@ mod tests { | |||
| 1502 | // The trim pair, on its designed bare brackets (DESIGN.md §6). | 1527 | // The trim pair, on its designed bare brackets (DESIGN.md §6). |
| 1503 | assert_eq!(k.lookup("[", false), Some(ActionId::TrimIn)); | 1528 | assert_eq!(k.lookup("[", false), Some(ActionId::TrimIn)); |
| 1504 | assert_eq!(k.lookup("]", false), Some(ActionId::TrimOut)); | 1529 | assert_eq!(k.lookup("]", false), Some(ActionId::TrimOut)); |
| 1530 | + // Trim-to-playhead (debt #42): the same family, one rung further. | ||
| 1531 | + assert_eq!(k.lookup("{", true), Some(ActionId::TrimInToPlayhead)); | ||
| 1532 | + assert_eq!(k.lookup("}", true), Some(ActionId::TrimOutToPlayhead)); | ||
| 1505 | assert_eq!(k.lookup("f11", false), Some(ActionId::Fullscreen)); | 1533 | assert_eq!(k.lookup("f11", false), Some(ActionId::Fullscreen)); |
| 1506 | assert_eq!(k.lookup("w", false), Some(ActionId::Screenshot)); | 1534 | assert_eq!(k.lookup("w", false), Some(ActionId::Screenshot)); |
| 1507 | assert_eq!(k.lookup("y", false), Some(ActionId::SubtitleStyle)); | 1535 | assert_eq!(k.lookup("y", false), Some(ActionId::SubtitleStyle)); |
crates/app/src/oracle.rsmodified+12 -0
| @@ -302,6 +302,18 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { | |||
| 302 | { | 302 | { |
| 303 | Enable::No("no subject cut") | 303 | Enable::No("no subject cut") |
| 304 | } | 304 | } |
| 305 | + // Trim-to-playhead (debt #42): the keyboard's own version of the | ||
| 306 | + // pointer's drag-the-edge-to-a-spot trim, so it needs the two things | ||
| 307 | + // that gesture needs -- a subject cut, and the playhead actually | ||
| 308 | + // resting somewhere on it, or the "spot" the edge would snap to is | ||
| 309 | + // not on the clip at all. | ||
| 310 | + ActionId::TrimInToPlayhead | ActionId::TrimOutToPlayhead => match ctx.clip { | ||
| 311 | + None => Enable::No("no subject cut"), | ||
| 312 | + Some((clip, _)) if ctx.playhead < clip.start || ctx.playhead > clip.end() => { | ||
| 313 | + Enable::No("playhead is outside the subject cut") | ||
| 314 | + } | ||
| 315 | + _ => Enable::Yes, | ||
| 316 | + }, | ||
| 305 | ActionId::Paste if !ctx.clipboard => Enable::No("nothing copied yet"), | 317 | ActionId::Paste if !ctx.clipboard => Enable::No("nothing copied yet"), |
| 306 | // Nothing to draw over the picture, so nothing to switch off: the | 318 | // Nothing to draw over the picture, so nothing to switch off: the |
| 307 | // library says how subtitles arrive, and this row would flip a state | 319 | // library says how subtitles arrive, and this row would flip a state |
crates/app/src/player/actions.rsmodified+37 -0
| @@ -201,6 +201,11 @@ impl Player { | |||
| 201 | ActionId::TrimIn => self.nudge_cut(Edge::Start, 1, cx), | 201 | ActionId::TrimIn => self.nudge_cut(Edge::Start, 1, cx), |
| 202 | ActionId::TrimOut => self.nudge_cut(Edge::End, -1, cx), | 202 | ActionId::TrimOut => self.nudge_cut(Edge::End, -1, cx), |
| 203 | ActionId::LoopTrim => self.toggle_loop_trim(cx), | 203 | ActionId::LoopTrim => self.toggle_loop_trim(cx), |
| 204 | + // Trim-to-playhead (debt #42): the same `Edge::Start`/`Edge::End` | ||
| 205 | + // split as the nudge pair above, at the playhead's frame instead | ||
| 206 | + // of a one-frame detent. | ||
| 207 | + ActionId::TrimInToPlayhead => self.trim_cut_to_playhead(Edge::Start, cx), | ||
| 208 | + ActionId::TrimOutToPlayhead => self.trim_cut_to_playhead(Edge::End, cx), | ||
| 204 | } | 209 | } |
| 205 | } | 210 | } |
| 206 | 211 | ||
| @@ -599,6 +604,38 @@ impl Player { | |||
| 599 | cx.notify(); | 604 | cx.notify(); |
| 600 | } | 605 | } |
| 601 | 606 | ||
| 607 | + /// Trim-to-playhead (debt #42): the keyboard's own version of the | ||
| 608 | + /// pointer's drag-the-edge-to-a-spot trim ([`Player::trim_to`] / | ||
| 609 | + /// [`Player::commit_trim`]) -- same [`PlaybackSession::trim_clip`] | ||
| 610 | + /// primitive either path ends at, so a hand on the keyboard gets the | ||
| 611 | + /// same undo step and the same room clamp a drag gets, just aimed at | ||
| 612 | + /// the playhead instead of wherever the pointer stopped. The oracle | ||
| 613 | + /// already refused this with no subject cut or a playhead off it, so an | ||
| 614 | + /// anchor and a frame are here to read. | ||
| 615 | + pub(crate) fn trim_cut_to_playhead(&mut self, edge: Edge, cx: &mut Context<Self>) { | ||
| 616 | + let Some((lane, idx)) = self.selected.anchor() else { | ||
| 617 | + return; | ||
| 618 | + }; | ||
| 619 | + let Some(session) = &self.session else { | ||
| 620 | + return; | ||
| 621 | + }; | ||
| 622 | + let to = frame_at(session.now(), self.fps); | ||
| 623 | + self.mark_dirty(); | ||
| 624 | + let trimmed = self | ||
| 625 | + .session | ||
| 626 | + .as_mut() | ||
| 627 | + .is_some_and(|s| s.trim_clip(lane, idx, edge, to)); | ||
| 628 | + if trimmed { | ||
| 629 | + self.reset_after_reseek(); | ||
| 630 | + // Loop-trim follows the edge it is trimming, same as the nudge | ||
| 631 | + // pair above. | ||
| 632 | + if self.loop_trim.is_some() { | ||
| 633 | + self.loop_trim = self.cut_span(lane, idx); | ||
| 634 | + } | ||
| 635 | + } | ||
| 636 | + cx.notify(); | ||
| 637 | + } | ||
| 638 | + | ||
| 602 | /// Loop-trim (DESIGN.md §6, `/`): loops the transport around the subject | 639 | /// Loop-trim (DESIGN.md §6, `/`): loops the transport around the subject |
| 603 | /// cut's own span while `[`/`]` move its edges -- the modernized Avid | 640 | /// cut's own span while `[`/`]` move its edges -- the modernized Avid |
| 604 | /// trim mode. Neither direction touches play/pause: off drops the window | 641 | /// trim mode. Neither direction touches play/pause: off drops the window |
crates/app/src/tests/editing.rsmodified+88 -0
| @@ -1797,6 +1797,94 @@ fn a_clip_trimmed_by_its_edge_plays_less_of_its_file() { | |||
| 1797 | assert_eq!(session.lane_clips(Lane::V1)[0], whole); | 1797 | assert_eq!(session.lane_clips(Lane::V1)[0], whole); |
| 1798 | } | 1798 | } |
| 1799 | 1799 | ||
| 1800 | +/// Trim-to-playhead (debt #42): [`Player::trim_cut_to_playhead`] reads | ||
| 1801 | +/// `frame_at(session.now(), fps)` and calls exactly the [`PlaybackSession:: | ||
| 1802 | +/// trim_clip`] primitive [`Player::commit_trim`]'s pointer path does, so | ||
| 1803 | +/// this exercises that same door at the playhead's own frame -- the clip's | ||
| 1804 | +/// start moves to where the playhead rests, one undo step takes it back. | ||
| 1805 | +#[test] | ||
| 1806 | +fn trim_to_playhead_moves_the_selected_clips_edge_and_undoes_in_one_step() { | ||
| 1807 | + use engine::project::Edge; | ||
| 1808 | + | ||
| 1809 | + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | ||
| 1810 | + session.set_gain(0.0); | ||
| 1811 | + let whole = session.lane_clips(Lane::V1)[0]; | ||
| 1812 | + let fps = session.meta().frame_rate; | ||
| 1813 | + | ||
| 1814 | + // Playhead mid-clip, a second in on a five-second timeline. | ||
| 1815 | + session.seek(1.0); | ||
| 1816 | + let playhead = frame_at(session.now(), fps); | ||
| 1817 | + assert!(playhead > whole.start && playhead < whole.end(), "mid-clip"); | ||
| 1818 | + | ||
| 1819 | + // Trim-in: the head follows the playhead, same as a pointer drag would | ||
| 1820 | + // stop there. | ||
| 1821 | + assert!(session.trim_clip(Lane::V1, 0, Edge::Start, playhead)); | ||
| 1822 | + assert_eq!(session.lane_clips(Lane::V1)[0].start, playhead); | ||
| 1823 | + assert!(session.undo(), "one step for the whole press"); | ||
| 1824 | + assert_eq!(session.lane_clips(Lane::V1)[0], whole, "the head is back"); | ||
| 1825 | + | ||
| 1826 | + // Trim-out: the same door, the tail this time. | ||
| 1827 | + session.seek(4.0); | ||
| 1828 | + let playhead = frame_at(session.now(), fps); | ||
| 1829 | + assert!(playhead > whole.start && playhead < whole.end(), "mid-clip"); | ||
| 1830 | + assert!(session.trim_clip(Lane::V1, 0, Edge::End, playhead)); | ||
| 1831 | + assert_eq!(session.lane_clips(Lane::V1)[0].end(), playhead); | ||
| 1832 | + assert!(session.undo(), "one step for the whole press"); | ||
| 1833 | + assert_eq!(session.lane_clips(Lane::V1)[0], whole, "the tail is back"); | ||
| 1834 | +} | ||
| 1835 | + | ||
| 1836 | +/// The oracle side of trim-to-playhead (debt #42): needs a subject cut *and* | ||
| 1837 | +/// the playhead actually resting on it, unlike the nudge pair above it which | ||
| 1838 | +/// only needs a cut -- the "spot" a keyless drag would snap to has to be on | ||
| 1839 | +/// the clip at all. | ||
| 1840 | +#[test] | ||
| 1841 | +fn trim_to_playhead_needs_a_subject_cut_with_the_playhead_on_it() { | ||
| 1842 | + let clip = Clip { | ||
| 1843 | + fade_in: 0, | ||
| 1844 | + fade_out: 0, | ||
| 1845 | + transition_out: 0, | ||
| 1846 | + start: 100, | ||
| 1847 | + in_frame: 0, | ||
| 1848 | + out_frame: 60, | ||
| 1849 | + source: 0, | ||
| 1850 | + link: None, | ||
| 1851 | + eq: None, | ||
| 1852 | + color: None, | ||
| 1853 | + transform: None, | ||
| 1854 | + fit: FitPolicy::default(), | ||
| 1855 | + speed: Speed::NORMAL, | ||
| 1856 | + }; | ||
| 1857 | + assert_eq!( | ||
| 1858 | + enable( | ||
| 1859 | + ActionId::TrimInToPlayhead, | ||
| 1860 | + Ctx { | ||
| 1861 | + timeline: true, | ||
| 1862 | + ..Ctx::default() | ||
| 1863 | + } | ||
| 1864 | + ), | ||
| 1865 | + Enable::No("no subject cut"), | ||
| 1866 | + "nothing marked" | ||
| 1867 | + ); | ||
| 1868 | + let off = Ctx { | ||
| 1869 | + clip: Some((clip, Lane::V1)), | ||
| 1870 | + playhead: 5, | ||
| 1871 | + timeline: true, | ||
| 1872 | + ..Ctx::default() | ||
| 1873 | + }; | ||
| 1874 | + assert_eq!( | ||
| 1875 | + enable(ActionId::TrimOutToPlayhead, off), | ||
| 1876 | + Enable::No("playhead is outside the subject cut") | ||
| 1877 | + ); | ||
| 1878 | + let on = Ctx { | ||
| 1879 | + clip: Some((clip, Lane::V1)), | ||
| 1880 | + playhead: clip.start, | ||
| 1881 | + timeline: true, | ||
| 1882 | + ..Ctx::default() | ||
| 1883 | + }; | ||
| 1884 | + assert_eq!(enable(ActionId::TrimInToPlayhead, on), Enable::Yes); | ||
| 1885 | + assert_eq!(enable(ActionId::TrimOutToPlayhead, on), Enable::Yes); | ||
| 1886 | +} | ||
| 1887 | + | ||
| 1800 | /// The move-a-clip-between-tracks path through the door the drop uses | 1888 | /// The move-a-clip-between-tracks path through the door the drop uses |
| 1801 | /// ([`Player::move_clip`] calls exactly this): the clip changes row, the | 1889 | /// ([`Player::move_clip`] calls exactly this): the clip changes row, the |
| 1802 | /// *picture* comes from the new row afterwards -- which is what "it plays | 1890 | /// *picture* comes from the new row afterwards -- which is what "it plays |
crates/app/src/ui/spine_stance.rsmodified+23 -0
| @@ -302,6 +302,29 @@ pub(crate) fn render(player: &Player, cx: &mut Context<Player>) -> impl IntoElem | |||
| 302 | ), | 302 | ), |
| 303 | )) | 303 | )) |
| 304 | .child(trim_control(player.loop_trim.is_some(), player, cx)) | 304 | .child(trim_control(player.loop_trim.is_some(), player, cx)) |
| 305 | + .child(pair( | ||
| 306 | + // Trim-to-playhead (debt #42): the keyboard's own version of the | ||
| 307 | + // pointer's drag-to-a-spot trim, beside the nudge pair it shares | ||
| 308 | + // its primitive with. | ||
| 309 | + glyph( | ||
| 310 | + "spine-trim-in-playhead", | ||
| 311 | + "[▮", | ||
| 312 | + ActionId::TrimInToPlayhead, | ||
| 313 | + false, | ||
| 314 | + false, | ||
| 315 | + player, | ||
| 316 | + cx, | ||
| 317 | + ), | ||
| 318 | + glyph( | ||
| 319 | + "spine-trim-out-playhead", | ||
| 320 | + "▮]", | ||
| 321 | + ActionId::TrimOutToPlayhead, | ||
| 322 | + false, | ||
| 323 | + false, | ||
| 324 | + player, | ||
| 325 | + cx, | ||
| 326 | + ), | ||
| 327 | + )) | ||
| 305 | .child(glyph( | 328 | .child(glyph( |
| 306 | "spine-loop-trim", | 329 | "spine-loop-trim", |
| 307 | "↻", | 330 | "↻", |