Merge branch 'worktree-agent-a75da909f275c6cda'
Browse files at this commit4 changed files +152 -13
- crates/app/src/keymap.rs +30 -3
- crates/app/src/main.rs +85 -10
- crates/engine/src/playback.rs +9 -0
- crates/engine/src/project.rs +28 -0
crates/app/src/keymap.rsmodified+30 -3
| @@ -45,6 +45,9 @@ pub enum ActionId { | ||
| 45 | 45 | Paste, |
| 46 | 46 | Cut, |
| 47 | 47 | Regroup, |
| 48 | + Select, | |
| 49 | + SelectNext, | |
| 50 | + SelectPrev, | |
| 48 | 51 | Delete, |
| 49 | 52 | Lift, |
| 50 | 53 | Color, |
| @@ -63,7 +66,7 @@ pub enum ActionId { | ||
| 63 | 66 | impl ActionId { |
| 64 | 67 | /// Display order everywhere -- the editor lists them in it and |
| 65 | 68 | /// [`Keymap::defaults`] binds them in it. |
| 66 | - pub const ALL: [ActionId; 20] = [ | |
| 69 | + pub const ALL: [ActionId; 23] = [ | |
| 67 | 70 | ActionId::Play, |
| 68 | 71 | ActionId::Export, |
| 69 | 72 | ActionId::Save, |
| @@ -71,6 +74,9 @@ impl ActionId { | ||
| 71 | 74 | ActionId::Paste, |
| 72 | 75 | ActionId::Cut, |
| 73 | 76 | ActionId::Regroup, |
| 77 | + ActionId::Select, | |
| 78 | + ActionId::SelectNext, | |
| 79 | + ActionId::SelectPrev, | |
| 74 | 80 | ActionId::Delete, |
| 75 | 81 | ActionId::Lift, |
| 76 | 82 | ActionId::Color, |
| @@ -96,6 +102,9 @@ impl ActionId { | ||
| 96 | 102 | ActionId::Paste => "Paste", |
| 97 | 103 | ActionId::Cut => "Cut", |
| 98 | 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 | 108 | ActionId::Delete => "Delete", |
| 100 | 109 | ActionId::Lift => "Lift (leave a gap)", |
| 101 | 110 | ActionId::Color => "Colour…", |
| @@ -123,6 +132,9 @@ impl ActionId { | ||
| 123 | 132 | ActionId::Paste => "paste", |
| 124 | 133 | ActionId::Cut => "cut", |
| 125 | 134 | ActionId::Regroup => "regroup", |
| 135 | + ActionId::Select => "select", | |
| 136 | + ActionId::SelectNext => "select-next", | |
| 137 | + ActionId::SelectPrev => "select-prev", | |
| 126 | 138 | ActionId::Delete => "delete", |
| 127 | 139 | ActionId::Lift => "lift", |
| 128 | 140 | ActionId::Color => "color", |
| @@ -151,6 +163,9 @@ impl ActionId { | ||
| 151 | 163 | ActionId::Play => Category::Playback, |
| 152 | 164 | ActionId::Copy |
| 153 | 165 | | ActionId::Paste |
| 166 | + | ActionId::Select | |
| 167 | + | ActionId::SelectNext | |
| 168 | + | ActionId::SelectPrev | |
| 154 | 169 | | ActionId::Delete |
| 155 | 170 | | ActionId::Lift |
| 156 | 171 | | ActionId::Color |
| @@ -384,6 +399,14 @@ impl Keymap { | ||
| 384 | 399 | // The two lane keys, on the letters they are named after: both |
| 385 | 400 | // were free, and neither is next to a key that edits. |
| 386 | 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 | 410 | b(ActionId::Delete, "x", false), |
| 388 | 411 | b(ActionId::Delete, "delete", false), |
| 389 | 412 | b(ActionId::Lift, "l", false), |
| @@ -640,7 +663,7 @@ mod tests { | ||
| 640 | 663 | #[test] |
| 641 | 664 | fn every_default_stroke_reaches_its_action() { |
| 642 | 665 | let k = Keymap::defaults(); |
| 643 | - assert_eq!(k.entries().len(), 22); | |
| 666 | + assert_eq!(k.entries().len(), 25); | |
| 644 | 667 | assert_eq!(k.lookup("space", false), Some(ActionId::Play)); |
| 645 | 668 | assert_eq!(k.lookup("e", false), Some(ActionId::Export)); |
| 646 | 669 | assert_eq!(k.lookup("s", true), Some(ActionId::Save)); |
| @@ -648,6 +671,10 @@ mod tests { | ||
| 648 | 671 | assert_eq!(k.lookup("v", true), Some(ActionId::Paste)); |
| 649 | 672 | assert_eq!(k.lookup("c", false), Some(ActionId::Cut)); |
| 650 | 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 | 678 | assert_eq!(k.lookup("x", false), Some(ActionId::Delete)); |
| 652 | 679 | assert_eq!(k.lookup("delete", false), Some(ActionId::Delete)); |
| 653 | 680 | assert_eq!(k.lookup("l", false), Some(ActionId::Lift)); |
| @@ -794,7 +821,7 @@ mod tests { | ||
| 794 | 821 | ); |
| 795 | 822 | // The label is the editor's column, and never the file's word for it. |
| 796 | 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 | 827 | #[test] |
crates/app/src/main.rsmodified+85 -10
| @@ -501,6 +501,9 @@ impl Player { | ||
| 501 | 501 | ActionId::Paste => self.paste(cx), |
| 502 | 502 | ActionId::Cut => self.cut(cx), |
| 503 | 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 | 507 | ActionId::Delete => self.delete_selected(cx), |
| 505 | 508 | ActionId::Lift => self.lift_selected(cx), |
| 506 | 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 | 592 | /// Cycles the fit policy of the clip the picture is coming from -- the |
| 523 | 593 | /// clicked one when it is a video clip, else the composite's own, exactly as |
| 524 | 594 | /// the colour card picks its target. A whole card for one four-valued |
| @@ -580,9 +650,9 @@ impl Player { | ||
| 580 | 650 | /// Opens the colour card on the clip a grade would go on: the clip that was |
| 581 | 651 | /// clicked when it is a video one, and otherwise the clip the picture is |
| 582 | 652 | /// 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 the | |
| 584 | - /// card reachable with no pointer at all: clip selection is a click and | |
| 585 | - /// nothing else (ledger:182). | |
| 653 | + /// what a person means by "this shot". The fallback stands even now that a | |
| 654 | + /// selection key exists: a grade asked for with nothing selected still means | |
| 655 | + /// the shot on screen. | |
| 586 | 656 | fn open_color(&mut self, cx: &mut Context<Self>) { |
| 587 | 657 | if self.exporting().is_some() { |
| 588 | 658 | return; |
| @@ -669,10 +739,13 @@ impl Player { | ||
| 669 | 739 | return; |
| 670 | 740 | } |
| 671 | 741 | let refusal = match (self.selected, &self.session) { |
| 672 | - (_, None) => Some("NO TIMELINE — open a file first"), | |
| 673 | - (None, _) => Some("NOTHING SELECTED — click an audio clip, then ask again"), | |
| 742 | + (_, None) => Some("NO TIMELINE — open a file first".to_string()), | |
| 743 | + (None, _) => Some(format!( | |
| 744 | + "NOTHING SELECTED — click an audio clip or press {}, then ask again", | |
| 745 | + self.keymap.display(ActionId::Select) | |
| 746 | + )), | |
| 674 | 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 | 750 | _ => None, |
| 678 | 751 | }; |
| @@ -3169,7 +3242,10 @@ impl Player { | ||
| 3169 | 3242 | let (sel, sel_link) = (self.selected, self.selected_link()); |
| 3170 | 3243 | let audio = lane.kind == LaneKind::Audio; |
| 3171 | 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 | 3249 | self.keymap.display(ActionId::Delete), |
| 3174 | 3250 | self.keymap.display(ActionId::Lift), |
| 3175 | 3251 | self.keymap.display(ActionId::Regroup) |
| @@ -3272,8 +3348,7 @@ impl Player { | ||
| 3272 | 3348 | .on_mouse_down( |
| 3273 | 3349 | MouseButton::Left, |
| 3274 | 3350 | cx.listener(move |this, _: &MouseDownEvent, _, cx| { |
| 3275 | - this.selected = Some((lane, i)); | |
| 3276 | - cx.notify(); | |
| 3351 | + this.select((lane, i), cx); | |
| 3277 | 3352 | }), |
| 3278 | 3353 | ) |
| 3279 | 3354 | // The right button selects exactly as the left one |
| @@ -3286,7 +3361,7 @@ impl Player { | ||
| 3286 | 3361 | if this.modal() { |
| 3287 | 3362 | return; |
| 3288 | 3363 | } |
| 3289 | - this.selected = Some((lane, i)); | |
| 3364 | + this.select((lane, i), cx); | |
| 3290 | 3365 | this.context_menu = Some(ContextMenu { |
| 3291 | 3366 | lane, |
| 3292 | 3367 | idx: i, |
crates/engine/src/playback.rsmodified+9 -0
| @@ -590,6 +590,15 @@ impl PlaybackSession { | ||
| 590 | 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 | 602 | /// How the clip at `idx` of `lane` is graded, or `None` for one that plays |
| 594 | 603 | /// as it was shot -- what a colour card reads when it opens. |
| 595 | 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 | 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 | 853 | /// How the composite is graded at `timeline_frame`, so the picture playback |
| 846 | 854 | /// converts and the one an export encodes are graded from one answer. |
| 847 | 855 | /// `None` over a gap (black is black) and for a clip nobody has graded, |
| @@ -1847,6 +1855,26 @@ mod tests { | ||
| 1847 | 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 | 1878 | #[test] |
| 1851 | 1879 | fn place_overwrites_only_its_own_lane() { |
| 1852 | 1880 | let mut p = three(); |