forge
Explore
Log in

Don't you dare go Hollow

Clips select from the keyboard

Browse files at this commit

cc90921f0aa4194ce5e539fc791a6b5bc48bea7aAhmet Kaan GümüşParent: cd9f0df
  • feat
    • clips select from the keyboard
Show full message
✨ feat(timeline): clips select from the keyboard

tab selects the clip under the playhead -- again for the next lane's --
and [ / ] walk the selection along its own lane, wrapping at both ends.
shift+tab stays unspellable (a chord carries only ctrl and parse refuses
an uppercase key), so the brackets are the pair.

One selection and not a second: every door -- click, right-click, all
three keys -- goes through Player::select, so the group-scoped tint a
click draws is the tint a key draws. Project::lane_clip_at is what the
walk asks, per lane, rather than the UI re-deriving where a clip ends.

This is what makes delete, lift, the equalizer and the grade reachable
with no pointer at all: the equalizer card had never been rendered live,
because nothing but a click could select the audio clip it needs.
crates/app/src/keymap.rsmodified+30 -3
@@ -45,6 +45,9 @@ pub enum ActionId {
45 Paste,45 Paste,
46 Cut,46 Cut,
47 Regroup,47 Regroup,
48+ Select,
49+ SelectNext,
50+ SelectPrev,
48 Delete,51 Delete,
49 Lift,52 Lift,
50 Color,53 Color,
@@ -63,7 +66,7 @@ pub enum ActionId {
63 impl ActionId {66 impl ActionId {
64 /// Display order everywhere -- the editor lists them in it and67 /// Display order everywhere -- the editor lists them in it and
65 /// [`Keymap::defaults`] binds them in it.68 /// [`Keymap::defaults`] binds them in it.
66- pub const ALL: [ActionId; 20] = [69+ pub const ALL: [ActionId; 23] = [
67 ActionId::Play,70 ActionId::Play,
68 ActionId::Export,71 ActionId::Export,
69 ActionId::Save,72 ActionId::Save,
@@ -71,6 +74,9 @@ impl ActionId {
71 ActionId::Paste,74 ActionId::Paste,
72 ActionId::Cut,75 ActionId::Cut,
73 ActionId::Regroup,76 ActionId::Regroup,
77+ ActionId::Select,
78+ ActionId::SelectNext,
79+ ActionId::SelectPrev,
74 ActionId::Delete,80 ActionId::Delete,
75 ActionId::Lift,81 ActionId::Lift,
76 ActionId::Color,82 ActionId::Color,
@@ -96,6 +102,9 @@ impl ActionId {
96 ActionId::Paste => "Paste",102 ActionId::Paste => "Paste",
97 ActionId::Cut => "Cut",103 ActionId::Cut => "Cut",
98 ActionId::Regroup => "Regroup",104 ActionId::Regroup => "Regroup",
105+ ActionId::Select => "Select the clip under the playhead (again for the next lane)",
106+ ActionId::SelectNext => "Select the next clip in the lane",
107+ ActionId::SelectPrev => "Select the previous clip in the lane",
99 ActionId::Delete => "Delete",108 ActionId::Delete => "Delete",
100 ActionId::Lift => "Lift (leave a gap)",109 ActionId::Lift => "Lift (leave a gap)",
101 ActionId::Color => "Colour…",110 ActionId::Color => "Colour…",
@@ -123,6 +132,9 @@ impl ActionId {
123 ActionId::Paste => "paste",132 ActionId::Paste => "paste",
124 ActionId::Cut => "cut",133 ActionId::Cut => "cut",
125 ActionId::Regroup => "regroup",134 ActionId::Regroup => "regroup",
135+ ActionId::Select => "select",
136+ ActionId::SelectNext => "select-next",
137+ ActionId::SelectPrev => "select-prev",
126 ActionId::Delete => "delete",138 ActionId::Delete => "delete",
127 ActionId::Lift => "lift",139 ActionId::Lift => "lift",
128 ActionId::Color => "color",140 ActionId::Color => "color",
@@ -151,6 +163,9 @@ impl ActionId {
151 ActionId::Play => Category::Playback,163 ActionId::Play => Category::Playback,
152 ActionId::Copy164 ActionId::Copy
153 | ActionId::Paste165 | ActionId::Paste
166+ | ActionId::Select
167+ | ActionId::SelectNext
168+ | ActionId::SelectPrev
154 | ActionId::Delete169 | ActionId::Delete
155 | ActionId::Lift170 | ActionId::Lift
156 | ActionId::Color171 | ActionId::Color
@@ -384,6 +399,14 @@ impl Keymap {
384 // The two lane keys, on the letters they are named after: both399 // The two lane keys, on the letters they are named after: both
385 // were free, and neither is next to a key that edits.400 // were free, and neither is next to a key that edits.
386 b(ActionId::Regroup, "g", false),401 b(ActionId::Regroup, "g", false),
402+ // Selection without a pointer. Tab is what a keyboard already
403+ // means by "move on to the next thing", and the two brackets
404+ // are the pair either side of it in the lane -- shift+tab is
405+ // the obvious partner and is unspellable here, since a chord
406+ // carries only ctrl and `parse` refuses an uppercase key.
407+ b(ActionId::Select, "tab", false),
408+ b(ActionId::SelectNext, "]", false),
409+ b(ActionId::SelectPrev, "[", false),
387 b(ActionId::Delete, "x", false),410 b(ActionId::Delete, "x", false),
388 b(ActionId::Delete, "delete", false),411 b(ActionId::Delete, "delete", false),
389 b(ActionId::Lift, "l", false),412 b(ActionId::Lift, "l", false),
@@ -640,7 +663,7 @@ mod tests {
640 #[test]663 #[test]
641 fn every_default_stroke_reaches_its_action() {664 fn every_default_stroke_reaches_its_action() {
642 let k = Keymap::defaults();665 let k = Keymap::defaults();
643- assert_eq!(k.entries().len(), 22);666+ assert_eq!(k.entries().len(), 25);
644 assert_eq!(k.lookup("space", false), Some(ActionId::Play));667 assert_eq!(k.lookup("space", false), Some(ActionId::Play));
645 assert_eq!(k.lookup("e", false), Some(ActionId::Export));668 assert_eq!(k.lookup("e", false), Some(ActionId::Export));
646 assert_eq!(k.lookup("s", true), Some(ActionId::Save));669 assert_eq!(k.lookup("s", true), Some(ActionId::Save));
@@ -648,6 +671,10 @@ mod tests {
648 assert_eq!(k.lookup("v", true), Some(ActionId::Paste));671 assert_eq!(k.lookup("v", true), Some(ActionId::Paste));
649 assert_eq!(k.lookup("c", false), Some(ActionId::Cut));672 assert_eq!(k.lookup("c", false), Some(ActionId::Cut));
650 assert_eq!(k.lookup("g", false), Some(ActionId::Regroup));673 assert_eq!(k.lookup("g", false), Some(ActionId::Regroup));
674+ // The keyboard's way onto a clip, and the pair that walks the lane.
675+ assert_eq!(k.lookup("tab", false), Some(ActionId::Select));
676+ assert_eq!(k.lookup("]", false), Some(ActionId::SelectNext));
677+ assert_eq!(k.lookup("[", false), Some(ActionId::SelectPrev));
651 assert_eq!(k.lookup("x", false), Some(ActionId::Delete));678 assert_eq!(k.lookup("x", false), Some(ActionId::Delete));
652 assert_eq!(k.lookup("delete", false), Some(ActionId::Delete));679 assert_eq!(k.lookup("delete", false), Some(ActionId::Delete));
653 assert_eq!(k.lookup("l", false), Some(ActionId::Lift));680 assert_eq!(k.lookup("l", false), Some(ActionId::Lift));
@@ -794,7 +821,7 @@ mod tests {
794 );821 );
795 // The label is the editor's column, and never the file's word for it.822 // The label is the editor's column, and never the file's word for it.
796 assert_eq!(ActionId::CancelExport.label(), "Cancel export");823 assert_eq!(ActionId::CancelExport.label(), "Cancel export");
797- assert_eq!(ActionId::ALL.len(), 20);824+ assert_eq!(ActionId::ALL.len(), 23);
798 }825 }
799 826
800 #[test]827 #[test]
crates/app/src/main.rsmodified+85 -10
@@ -501,6 +501,9 @@ impl Player {
501 ActionId::Paste => self.paste(cx),501 ActionId::Paste => self.paste(cx),
502 ActionId::Cut => self.cut(cx),502 ActionId::Cut => self.cut(cx),
503 ActionId::Regroup => self.regroup(cx),503 ActionId::Regroup => self.regroup(cx),
504+ ActionId::Select => self.select_under_playhead(cx),
505+ ActionId::SelectNext => self.select_step(true, cx),
506+ ActionId::SelectPrev => self.select_step(false, cx),
504 ActionId::Delete => self.delete_selected(cx),507 ActionId::Delete => self.delete_selected(cx),
505 ActionId::Lift => self.lift_selected(cx),508 ActionId::Lift => self.lift_selected(cx),
506 ActionId::Color => self.open_color(cx),509 ActionId::Color => self.open_color(cx),
@@ -519,6 +522,73 @@ impl Player {
519 }522 }
520 }523 }
521 524
525+ /// The one place a clip becomes *the* selected one: a click, a right-click
526+ /// that opens the menu, and every selection key go through here, so what a
527+ /// keyboard marks and what a pointer marks are the same state marked the
528+ /// same way (group and all -- see [`marked`]).
529+ fn select(&mut self, target: (Lane, usize), cx: &mut Context<Self>) {
530+ self.selected = Some(target);
531+ cx.notify();
532+ }
533+
534+ /// Every clip the playhead is over, one per lane, in the order the lanes are
535+ /// drawn -- video first, which is the order [`PlaybackSession::lanes`] comes
536+ /// in. What the select key walks.
537+ fn under_playhead(&self) -> Vec<(Lane, usize)> {
538+ let Some(session) = &self.session else {
539+ return Vec::new();
540+ };
541+ let now = session.now();
542+ session
543+ .lanes()
544+ .into_iter()
545+ .filter_map(|lane| Some((lane, session.lane_clip_at(lane, now)?)))
546+ .collect()
547+ }
548+
549+ /// Selects the clip under the playhead, and on a repeat press the next
550+ /// lane's -- so one key reaches every clip the playhead is over, which is
551+ /// what makes selection (and everything that acts on a selection: delete,
552+ /// lift, the equalizer, the grade) reachable with no pointer at all.
553+ fn select_under_playhead(&mut self, cx: &mut Context<Self>) {
554+ let under = self.under_playhead();
555+ let Some(&first) = under.first() else {
556+ self.notice = Some("NOTHING UNDER THE PLAYHEAD — move it onto a clip first".into());
557+ cx.notify();
558+ return;
559+ };
560+ // Where the current selection sits in that walk decides what "again"
561+ // means; a selection off the playhead starts the walk over.
562+ let next = self
563+ .selected
564+ .and_then(|sel| under.iter().position(|&clip| clip == sel))
565+ .map_or(first, |at| under[(at + 1) % under.len()]);
566+ self.select(next, cx);
567+ }
568+
569+ /// Walks the selection along its own lane, wrapping at either end. Nothing
570+ /// selected means nothing to walk from, so it selects under the playhead
571+ /// exactly as the select key does: either key can start as well as continue.
572+ fn select_step(&mut self, forward: bool, cx: &mut Context<Self>) {
573+ let clips = self
574+ .selected
575+ .zip(self.session.as_ref())
576+ .map_or(0, |((lane, _), session)| session.lane_clips(lane).len());
577+ match (self.selected, clips) {
578+ // An empty lane is a selection nothing can be stepped from -- as is
579+ // no selection at all, and the playhead answers both.
580+ (Some((lane, idx)), len) if len > 0 => {
581+ let next = if forward {
582+ (idx + 1) % len
583+ } else {
584+ (idx + len - 1) % len
585+ };
586+ self.select((lane, next), cx);
587+ }
588+ _ => self.select_under_playhead(cx),
589+ }
590+ }
591+
522 /// Cycles the fit policy of the clip the picture is coming from -- the592 /// Cycles the fit policy of the clip the picture is coming from -- the
523 /// clicked one when it is a video clip, else the composite's own, exactly as593 /// clicked one when it is a video clip, else the composite's own, exactly as
524 /// the colour card picks its target. A whole card for one four-valued594 /// the colour card picks its target. A whole card for one four-valued
@@ -580,9 +650,9 @@ impl Player {
580 /// Opens the colour card on the clip a grade would go on: the clip that was650 /// Opens the colour card on the clip a grade would go on: the clip that was
581 /// clicked when it is a video one, and otherwise the clip the picture is651 /// clicked when it is a video one, and otherwise the clip the picture is
582 /// coming from -- the one the engine's own compositing rule picks, which is652 /// coming from -- the one the engine's own compositing rule picks, which is
583- /// what a person means by "this shot". That fallback is also what makes the653+ /// what a person means by "this shot". The fallback stands even now that a
584- /// card reachable with no pointer at all: clip selection is a click and654+ /// selection key exists: a grade asked for with nothing selected still means
585- /// nothing else (ledger:182).655+ /// the shot on screen.
586 fn open_color(&mut self, cx: &mut Context<Self>) {656 fn open_color(&mut self, cx: &mut Context<Self>) {
587 if self.exporting().is_some() {657 if self.exporting().is_some() {
588 return;658 return;
@@ -669,10 +739,13 @@ impl Player {
669 return;739 return;
670 }740 }
671 let refusal = match (self.selected, &self.session) {741 let refusal = match (self.selected, &self.session) {
672- (_, None) => Some("NO TIMELINE — open a file first"),742+ (_, None) => Some("NO TIMELINE — open a file first".to_string()),
673- (None, _) => Some("NOTHING SELECTED — click an audio clip, then ask again"),743+ (None, _) => Some(format!(
744+ "NOTHING SELECTED — click an audio clip or press {}, then ask again",
745+ self.keymap.display(ActionId::Select)
746+ )),
674 (Some((lane, _)), _) if lane.kind != LaneKind::Audio => Some(747 (Some((lane, _)), _) if lane.kind != LaneKind::Audio => Some(
675- "NOT AN AUDIO CLIP — the equalizer works on the sound, so pick a clip in an audio lane",748+ "NOT AN AUDIO CLIP — the equalizer works on the sound, so pick a clip in an audio lane".to_string(),
676 ),749 ),
677 _ => None,750 _ => None,
678 };751 };
@@ -3169,7 +3242,10 @@ impl Player {
3169 let (sel, sel_link) = (self.selected, self.selected_link());3242 let (sel, sel_link) = (self.selected, self.selected_link());
3170 let audio = lane.kind == LaneKind::Audio;3243 let audio = lane.kind == LaneKind::Audio;
3171 let tip: SharedString = format!(3244 let tip: SharedString = format!(
3172- "Select — {} removes the take, {} leaves a gap, {} rejoins a cut",3245+ "Select (or {} under the playhead, {}/{} along the lane) — {} removes the take, {} leaves a gap, {} rejoins a cut",
3246+ self.keymap.display(ActionId::Select),
3247+ self.keymap.display(ActionId::SelectPrev),
3248+ self.keymap.display(ActionId::SelectNext),
3173 self.keymap.display(ActionId::Delete),3249 self.keymap.display(ActionId::Delete),
3174 self.keymap.display(ActionId::Lift),3250 self.keymap.display(ActionId::Lift),
3175 self.keymap.display(ActionId::Regroup)3251 self.keymap.display(ActionId::Regroup)
@@ -3272,8 +3348,7 @@ impl Player {
3272 .on_mouse_down(3348 .on_mouse_down(
3273 MouseButton::Left,3349 MouseButton::Left,
3274 cx.listener(move |this, _: &MouseDownEvent, _, cx| {3350 cx.listener(move |this, _: &MouseDownEvent, _, cx| {
3275- this.selected = Some((lane, i));3351+ this.select((lane, i), cx);
3276- cx.notify();
3277 }),3352 }),
3278 )3353 )
3279 // The right button selects exactly as the left one3354 // The right button selects exactly as the left one
@@ -3286,7 +3361,7 @@ impl Player {
3286 if this.modal() {3361 if this.modal() {
3287 return;3362 return;
3288 }3363 }
3289- this.selected = Some((lane, i));3364+ this.select((lane, i), cx);
3290 this.context_menu = Some(ContextMenu {3365 this.context_menu = Some(ContextMenu {
3291 lane,3366 lane,
3292 idx: i,3367 idx: i,
crates/engine/src/playback.rsmodified+9 -0
@@ -590,6 +590,15 @@ impl PlaybackSession {
590 .composite_clip_at(secs_to_frame(timeline_secs, self.meta.frame_rate))590 .composite_clip_at(secs_to_frame(timeline_secs, self.meta.frame_rate))
591 }591 }
592 592
593+ /// Which clip of `lane` sits at `timeline_secs`, by the same rule
594+ /// [`video_clip_at`](Self::video_clip_at) picks the picture's with -- per
595+ /// lane, so a keyboard walking the lanes for something to select asks the
596+ /// engine rather than re-deriving where a clip ends.
597+ pub fn lane_clip_at(&self, lane: Lane, timeline_secs: f64) -> Option<usize> {
598+ self.project
599+ .lane_clip_at(lane, secs_to_frame(timeline_secs, self.meta.frame_rate))
600+ }
601+
593 /// How the clip at `idx` of `lane` is graded, or `None` for one that plays602 /// How the clip at `idx` of `lane` is graded, or `None` for one that plays
594 /// as it was shot -- what a colour card reads when it opens.603 /// as it was shot -- what a colour card reads when it opens.
595 pub fn color_of(&self, lane: Lane, idx: usize) -> Option<&ColorParams> {604 pub fn color_of(&self, lane: Lane, idx: usize) -> Option<&ColorParams> {
crates/engine/src/project.rsmodified+28 -0
@@ -842,6 +842,14 @@ impl Project {
842 Some((video[winner], at(self.lane(video[winner]), timeline_frame)?))842 Some((video[winner], at(self.lane(video[winner]), timeline_frame)?))
843 }843 }
844 844
845+ /// Which clip of *one* lane `timeline_frame` falls on, or `None` over a gap
846+ /// and past that lane's end. [`composite_clip_at`](Project::composite_clip_at)
847+ /// answers "the clip on screen"; this answers it per lane, which is what
848+ /// walking the lanes for something to select needs.
849+ pub fn lane_clip_at(&self, lane: Lane, timeline_frame: u32) -> Option<usize> {
850+ at(self.lane(lane), timeline_frame)
851+ }
852+
845 /// How the composite is graded at `timeline_frame`, so the picture playback853 /// How the composite is graded at `timeline_frame`, so the picture playback
846 /// converts and the one an export encodes are graded from one answer.854 /// converts and the one an export encodes are graded from one answer.
847 /// `None` over a gap (black is black) and for a clip nobody has graded,855 /// `None` over a gap (black is black) and for a clip nobody has graded,
@@ -1847,6 +1855,26 @@ mod tests {
1847 assert_eq!(p.timeline_frames(), 9);1855 assert_eq!(p.timeline_frames(), 9);
1848 }1856 }
1849 1857
1858+ /// What a keyboard selection walks: one answer per lane, gaps included --
1859+ /// the composite's own answer is one lane's and cannot say what the audio
1860+ /// lane holds under the same playhead.
1861+ #[test]
1862+ fn lane_clip_at_answers_for_each_lane_separately() {
1863+ let mut p = Project::single(FILE, 9);
1864+ assert!(p.split(3), "both lanes split");
1865+ assert_eq!(p.lane_clip_at(Lane::V1, 0), Some(0));
1866+ assert_eq!(p.lane_clip_at(Lane::V1, 3), Some(1));
1867+ assert_eq!(p.lane_clip_at(Lane::A1, 3), Some(1));
1868+ assert_eq!(p.lane_clip_at(Lane::V1, 9), None, "past the end");
1869+ // A gap on one lane leaves the other's clip selectable there.
1870+ assert!(p.lift(Lane::A1, 0));
1871+ assert_eq!(p.lane_clip_at(Lane::A1, 0), None, "the gap holds nothing");
1872+ assert_eq!(p.lane_clip_at(Lane::A1, 3), Some(0), "indices moved with it");
1873+ assert_eq!(p.lane_clip_at(Lane::V1, 0), Some(0));
1874+ // A lane that is not there is not a panic.
1875+ assert_eq!(p.lane_clip_at(Lane::new(LaneKind::Video, 1), 0), None);
1876+ }
1877+
1850 #[test]1878 #[test]
1851 fn place_overwrites_only_its_own_lane() {1879 fn place_overwrites_only_its_own_lane() {
1852 let mut p = three();1880 let mut p = three();