Right-click empty space to close the gap
Browse files at this commit- feat
- right-click empty space to close the gap
9 changed files +477 -16
- crates/app/src/menus.rs +19 -5
- crates/app/src/notices.rs +35 -0
- crates/app/src/player/timeline_edit.rs +63 -1
- crates/app/src/tests/layout.rs +25 -0
- crates/app/src/ui/bench_stance.rs +18 -0
- crates/app/src/ui/overlays.rs +24 -3
- crates/app/src/ui/stance.rs +26 -7
- crates/engine/src/playback.rs +15 -0
- crates/engine/src/project.rs +252 -0
crates/app/src/menus.rsmodified+19 -5
| @@ -2,14 +2,28 @@ | ||
| 2 | 2 | |
| 3 | 3 | use crate::*; |
| 4 | 4 | |
| 5 | -/// An open clip menu: which clip it was opened on, where it hangs, and whether | |
| 6 | -/// it has been turned over to show what that clip *is* instead of what can be | |
| 7 | -/// done to it. The lane and index are the ones the same click selected, so | |
| 8 | -/// every item acts on exactly the box under the pointer. | |
| 5 | +/// What a right-click on the bench named: a clip at an index, or the empty | |
| 6 | +/// stretch of the lane it landed in ([`engine::PlaybackSession::gap_at`]) -- | |
| 7 | +/// two different things the one menu can be about, so it stays one struct and | |
| 8 | +/// one field to clear rather than a second `Option` beside `context_menu` | |
| 9 | +/// that every closer would have to learn about too. | |
| 10 | +#[derive(Clone, Copy)] | |
| 11 | +pub(crate) enum MenuOn { | |
| 12 | + Clip(usize), | |
| 13 | + /// `(start, frames)` of the gap, in timeline frames -- what | |
| 14 | + /// [`Player::close_gap`] ripples shut. | |
| 15 | + Gap(u32, u32), | |
| 16 | +} | |
| 17 | + | |
| 18 | +/// An open clip menu: what it was opened on, where it hangs, and whether it | |
| 19 | +/// has been turned over to show what a clip *is* instead of what can be done | |
| 20 | +/// to it (`details` means nothing for a gap, which has no properties side). | |
| 21 | +/// The lane is the one the same click selected, so every item acts on | |
| 22 | +/// exactly the box -- or the hole -- under the pointer. | |
| 9 | 23 | #[derive(Clone, Copy)] |
| 10 | 24 | pub(crate) struct ContextMenu { |
| 11 | 25 | pub(crate) lane: Lane, |
| 12 | - pub(crate) idx: usize, | |
| 26 | + pub(crate) on: MenuOn, | |
| 13 | 27 | pub(crate) at: Point<Pixels>, |
| 14 | 28 | pub(crate) details: bool, |
| 15 | 29 | } |
crates/app/src/notices.rsmodified+35 -0
| @@ -58,3 +58,38 @@ pub(crate) fn audio_notice(session: &PlaybackSession) -> Option<String> { | ||
| 58 | 58 | .audio_disabled_reason() |
| 59 | 59 | .map(|reason| format!(" — NO AUDIO: {reason}")) |
| 60 | 60 | } |
| 61 | + | |
| 62 | +#[cfg(test)] | |
| 63 | +mod tests { | |
| 64 | + use super::*; | |
| 65 | + | |
| 66 | + /// The class this guards: a notice queued behind an earlier, undismissed | |
| 67 | + /// one is never *lost* -- `push_notice` still appends it to the back -- | |
| 68 | + /// but a reader of `front()` alone (what `stance::notice_plate` read | |
| 69 | + /// before this fix) would never see it, because nothing but a keystroke | |
| 70 | + /// ever calls `dismiss_notice`, and most of what fills this queue (a | |
| 71 | + /// click on a gap, a menu row, a drag) is not one. `back()` is the read | |
| 72 | + /// that survives that: it always names the newest message, which is why | |
| 73 | + /// the plate and the ledger's "last action" both read it now. | |
| 74 | + /// | |
| 75 | + /// This is a value-level check on the queue only -- this binary has no | |
| 76 | + /// `TestAppContext`, so it cannot measure what actually painted, and this | |
| 77 | + /// test does not claim to. | |
| 78 | + #[test] | |
| 79 | + fn a_notice_queued_behind_an_unread_one_is_still_reachable_at_the_back() { | |
| 80 | + let mut notices = std::collections::VecDeque::new(); | |
| 81 | + push_notice(&mut notices, "SAVED test_h264.edith".into()); | |
| 82 | + let refusal = "the V1 clip at frame 0 is one take with the A1 clip at frame 0: \ | |
| 83 | + closing this gap alone would pull the take out of sync — close A1's \ | |
| 84 | + gap there too, or detach them first"; | |
| 85 | + push_notice(&mut notices, refusal.into()); | |
| 86 | + // Nobody dismissed the SAVED notice (no keystroke happened) -- it is | |
| 87 | + // still sitting at the front, exactly the scenario that froze the | |
| 88 | + // plate on stale text. | |
| 89 | + assert_eq!(notices.front().unwrap().as_ref(), "SAVED test_h264.edith"); | |
| 90 | + // The refusal, remedy clause and all, is reachable at the back -- | |
| 91 | + // whole, not truncated, because `push_notice` never touches a | |
| 92 | + // message's text. | |
| 93 | + assert_eq!(notices.back().unwrap().as_ref(), refusal); | |
| 94 | + } | |
| 95 | +} |
crates/app/src/player/timeline_edit.rsmodified+63 -1
| @@ -1031,13 +1031,75 @@ impl Player { | ||
| 1031 | 1031 | } |
| 1032 | 1032 | self.context_menu = Some(ContextMenu { |
| 1033 | 1033 | lane, |
| 1034 | - idx, | |
| 1034 | + on: MenuOn::Clip(idx), | |
| 1035 | + at, | |
| 1036 | + details: false, | |
| 1037 | + }); | |
| 1038 | + cx.notify(); | |
| 1039 | + } | |
| 1040 | + | |
| 1041 | + /// Opens the same menu on the gap under the pointer instead of a clip -- | |
| 1042 | + /// the empty-bench-space door to [`Player::close_gap`]. Nothing is | |
| 1043 | + /// selected: a gap owns no clip to select, unlike [`Player::open_menu`]. | |
| 1044 | + pub(crate) fn open_gap_menu(&mut self, lane: Lane, start: u32, frames: u32, at: Point<Pixels>, cx: &mut Context<Self>) { | |
| 1045 | + if self.modal() { | |
| 1046 | + return; | |
| 1047 | + } | |
| 1048 | + self.context_menu = Some(ContextMenu { | |
| 1049 | + lane, | |
| 1050 | + on: MenuOn::Gap(start, frames), | |
| 1035 | 1051 | at, |
| 1036 | 1052 | details: false, |
| 1037 | 1053 | }); |
| 1038 | 1054 | cx.notify(); |
| 1039 | 1055 | } |
| 1040 | 1056 | |
| 1057 | + /// Closes the gap `(start, frames)` -- Premiere's "Close Gap", scoped to | |
| 1058 | + /// `lane` and, when the gap borders a take, to the take's other lane too | |
| 1059 | + /// ([`engine::PlaybackSession::gap_take_scope`]): a lane not sharing the | |
| 1060 | + /// take never moves, so a neighbour that meant to keep its own silence is | |
| 1061 | + /// untouched, but the two halves of a linked A/V take close together -- | |
| 1062 | + /// the alternative is a ripple that pulls a take's picture and sound out | |
| 1063 | + /// of step with each other, which no lane's own gap is worth. A take | |
| 1064 | + /// whose gap does not match on its other lane is refused in words, not | |
| 1065 | + /// silence ([`engine::Project::gap_take_scope`]). | |
| 1066 | + pub(crate) fn close_gap(&mut self, lane: Lane, start: u32, frames: u32, cx: &mut Context<Self>) { | |
| 1067 | + let Some(session) = self.session.as_mut() else { | |
| 1068 | + return; | |
| 1069 | + }; | |
| 1070 | + let scope = match session.gap_take_scope(lane, start, frames) { | |
| 1071 | + Ok(scope) => scope, | |
| 1072 | + Err(e) => { | |
| 1073 | + self.notify_user(e.to_string().into()); | |
| 1074 | + cx.notify(); | |
| 1075 | + return; | |
| 1076 | + } | |
| 1077 | + }; | |
| 1078 | + match session.cut_regions(&[(start, frames)], &scope) { | |
| 1079 | + Ok(()) => { | |
| 1080 | + self.mark_dirty(); | |
| 1081 | + // The ripple moves every index after the gap on the scoped | |
| 1082 | + // lanes, the same reason a delete drops the selection. | |
| 1083 | + self.selected.clear(); | |
| 1084 | + self.reset_after_reseek(); | |
| 1085 | + let where_ = if scope.len() > 1 { | |
| 1086 | + "its take".to_string() | |
| 1087 | + } else { | |
| 1088 | + lane.label().to_string() | |
| 1089 | + }; | |
| 1090 | + self.notify_user( | |
| 1091 | + format!( | |
| 1092 | + "GAP CLOSED on {where_} — {} takes it back", | |
| 1093 | + self.keymap.display(ActionId::Undo) | |
| 1094 | + ) | |
| 1095 | + .into(), | |
| 1096 | + ); | |
| 1097 | + } | |
| 1098 | + Err(e) => self.notify_user(e.to_string().into()), | |
| 1099 | + } | |
| 1100 | + cx.notify(); | |
| 1101 | + } | |
| 1102 | + | |
| 1041 | 1103 | /// A press on an edge: the start of the drag that changes how much of a |
| 1042 | 1104 | /// source it plays. It picks the placement as a press anywhere else on the |
| 1043 | 1105 | /// box does -- the edge strip covers the box's own listener (`occlude`), so |
crates/app/src/tests/layout.rsmodified+25 -0
| @@ -1930,6 +1930,31 @@ fn the_notice_plate_cannot_reach_the_bench_at_any_height() { | ||
| 1930 | 1930 | ); |
| 1931 | 1931 | } |
| 1932 | 1932 | } |
| 1933 | +/// The renderer only wraps text when the text measurement receives a definite | |
| 1934 | +/// width and normal whitespace. This source-level guard keeps both declarations | |
| 1935 | +/// on the notice plate: `max_w` alone limits max-content after that measurement | |
| 1936 | +/// and silently permits one-line overflow. It cannot inspect GPUI's painted | |
| 1937 | +/// lines; only live driving can confirm the full notice actually wrapped. | |
| 1938 | +#[test] | |
| 1939 | +fn the_notice_plate_declares_a_bounded_wrapping_text_layout() { | |
| 1940 | + let stance = src_text("ui/stance.rs"); | |
| 1941 | + let notice_start = stance.find("fn notice_plate(").expect("notice plate moved or renamed"); | |
| 1942 | + let notice_end = stance[notice_start..] | |
| 1943 | + .find("\n/// Thin strip") | |
| 1944 | + .map(|end| notice_start + end) | |
| 1945 | + .expect("notice plate no longer precedes the ledger"); | |
| 1946 | + let plate = &stance[notice_start..notice_end]; | |
| 1947 | + | |
| 1948 | + assert!( | |
| 1949 | + plate.contains(".w_full()") && plate.contains(".max_w(px(480.))"), | |
| 1950 | + "notice plate lacks a definite width bounded to 480 px; max_w alone does not wrap text" | |
| 1951 | + ); | |
| 1952 | + assert!( | |
| 1953 | + plate.contains(".whitespace_normal()"), | |
| 1954 | + "notice plate no longer explicitly requests GPUI's wrapping whitespace mode" | |
| 1955 | + ); | |
| 1956 | +} | |
| 1957 | + | |
| 1933 | 1958 | |
| 1934 | 1959 | /// A round trip through the file: what is saved is what the next load reads |
| 1935 | 1960 | /// back, one seam touched and the other left at its default -- a scratch |
crates/app/src/ui/bench_stance.rsmodified+18 -0
| @@ -658,6 +658,24 @@ fn lane_row( | ||
| 658 | 658 | let at = this.place_frame(window.mouse_position().x).0; |
| 659 | 659 | this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx) |
| 660 | 660 | })) |
| 661 | + // Right-click on empty bed space: the "Close Gap" door. A | |
| 662 | + // clip's own right-click handler (`clip_box`/`sub_box`) never | |
| 663 | + // stops propagation, so this fires on that press too -- | |
| 664 | + // harmlessly, since `gap_at` answers `None` for a frame a | |
| 665 | + // clip already covers and this listener does nothing then, | |
| 666 | + // leaving the clip's own menu exactly as it set it. | |
| 667 | + .on_mouse_down( | |
| 668 | + MouseButton::Right, | |
| 669 | + cx.listener(move |this, event: &MouseDownEvent, _, cx| { | |
| 670 | + let Some(session) = this.session.as_ref() else { | |
| 671 | + return; | |
| 672 | + }; | |
| 673 | + let frame = this.frame_under(event.position.x); | |
| 674 | + if let Some((start, frames)) = session.gap_at(lane, frame) { | |
| 675 | + this.open_gap_menu(lane, start, frames, event.position, cx); | |
| 676 | + } | |
| 677 | + }), | |
| 678 | + ) | |
| 661 | 679 | // The landing shadow (`Player::preview_ghost_asset`, the same |
| 662 | 680 | // setter `ui/timeline.rs`'s own bed calls) -- guarded on the |
| 663 | 681 | // pointer actually being inside this bed's own bounds, since |
crates/app/src/ui/overlays.rsmodified+24 -3
| @@ -477,7 +477,11 @@ impl Player { | ||
| 477 | 477 | // oracle's either way ([`Ctx::caption`]), so what the card *has* is |
| 478 | 478 | // asked for where it is used rather than at the door -- refusing here |
| 479 | 479 | // would be a right-click that opens nothing. |
| 480 | - let clip = session.lane_clips(menu.lane).get(menu.idx).copied(); | |
| 480 | + let idx = match menu.on { | |
| 481 | + MenuOn::Clip(idx) => Some(idx), | |
| 482 | + MenuOn::Gap(..) => None, | |
| 483 | + }; | |
| 484 | + let clip = idx.and_then(|idx| session.lane_clips(menu.lane).get(idx).copied()); | |
| 481 | 485 | let source = clip.and_then(|clip| session.sources().get(clip.source).cloned()); |
| 482 | 486 | let secs = |frames: u32| timecode(f64::from(frames) / self.fps, self.fps); |
| 483 | 487 | // DESIGN §9/§3: a menu row is a plate row, Archivo at the room's |
| @@ -562,6 +566,22 @@ impl Player { | ||
| 562 | 566 | .into_any_element(), |
| 563 | 567 | ); |
| 564 | 568 | } |
| 569 | + } else if let MenuOn::Gap(start, frames) = menu.on { | |
| 570 | + // The one item a gap offers: no properties, no clip actions, just | |
| 571 | + // the ripple that closes it -- Premiere's Close Gap, Resolve's | |
| 572 | + // Delete Gap, per-lane the way `Player::close_gap` documents. | |
| 573 | + rows.push( | |
| 574 | + row(rows.len()) | |
| 575 | + .cursor_pointer() | |
| 576 | + .hover(|s| s.bg(rgb(BG_HOVER()))) | |
| 577 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | |
| 578 | + this.context_menu = None; | |
| 579 | + this.close_gap(menu.lane, start, frames, cx); | |
| 580 | + })) | |
| 581 | + .child("Close gap") | |
| 582 | + .child(chord_style(div().text_color(rgb(FG_SECONDARY()))).child("ripples left")) | |
| 583 | + .into_any_element(), | |
| 584 | + ); | |
| 565 | 585 | } else { |
| 566 | 586 | // A grade on a waveform, an equalizer on a picture, a silence scan |
| 567 | 587 | // on a still: things that do not exist for what was right-clicked, |
| @@ -570,7 +590,8 @@ impl Player { | ||
| 570 | 590 | // `menu_items`, so there is no second answer to keep in step. The |
| 571 | 591 | // state refusals below stay, dimmed and saying why -- the next |
| 572 | 592 | // click of the playhead lights them. |
| 573 | - let ctx = self.ctx(Some((menu.lane, menu.idx))); | |
| 593 | + let idx = idx.expect("MenuOn::Gap handled above"); | |
| 594 | + let ctx = self.ctx(Some((menu.lane, idx))); | |
| 574 | 595 | for action in menu_items(ctx) { |
| 575 | 596 | // The registry's own answer, the same one the actions card |
| 576 | 597 | // dims a row with -- and a row that takes no click says *why* |
| @@ -627,7 +648,7 @@ impl Player { | ||
| 627 | 648 | // The stroke still steps -- same door. |
| 628 | 649 | if action == ActionId::Fit { |
| 629 | 650 | this.open_picker( |
| 630 | - Pick::Fit(menu.lane, menu.idx), | |
| 651 | + Pick::Fit(menu.lane, idx), | |
| 631 | 652 | event.position(), |
| 632 | 653 | cx, |
| 633 | 654 | ); |
crates/app/src/ui/stance.rsmodified+26 -7
| @@ -562,9 +562,18 @@ pub(crate) fn notice_bottom_offset(bench_h: f32) -> f32 { | ||
| 562 | 562 | /// A notice plate (DESIGN §8): one at a time, rising above the *bench*, its |
| 563 | 563 | /// severity a 3px left spine rather than a colour flood. Fed by the same |
| 564 | 564 | /// [`Player::notify_user`]/`notices` queue the legacy bar reads |
| 565 | -/// ([`Player::notice_bar`]) -- no second notice channel. Dismissal is | |
| 566 | -/// already wired: [`render`]'s `on_key_down` calls `dismiss_notice()` on | |
| 567 | -/// every stroke, the same door the legacy handler uses. | |
| 565 | +/// ([`Player::notice_bar`]) -- no second notice channel. | |
| 566 | +/// | |
| 567 | +/// Reads the *back* of the queue, not the front: dismissal only ever fires | |
| 568 | +/// on a keystroke ([`render`]'s `on_key_down` calling `dismiss_notice()`), | |
| 569 | +/// and most of what fills this queue -- a click on a gap, a menu row, a | |
| 570 | +/// drag -- is not one. A `front()` plate left showing a `ctrl+s` "SAVED" | |
| 571 | +/// notice sat frozen through an unrelated mouse-driven refusal that queued | |
| 572 | +/// in behind it: the ledger strip's own "last action" already reads | |
| 573 | +/// `back()` for exactly this reason, and the plate disagreeing with it is | |
| 574 | +/// what made the refusal look like it never reached the notice surface at | |
| 575 | +/// all. `back()` keeps the two in step and guarantees the newest, most | |
| 576 | +/// actionable message is always the one on screen. | |
| 568 | 577 | /// |
| 569 | 578 | /// Anchored off `bench_h` rather than a fixed offset off the ledger: at the |
| 570 | 579 | /// bench's floor a fixed `LEDGER_H + 6.` bottom offset put the plate right |
| @@ -585,9 +594,19 @@ fn notice_plate(message: SharedString, bench_h: f32) -> impl IntoElement { | ||
| 585 | 594 | .absolute() |
| 586 | 595 | .bottom(px(notice_bottom_offset(bench_h))) |
| 587 | 596 | .left(px(12.)) |
| 588 | - .max_w(px(360.)) | |
| 589 | - .flex() | |
| 590 | - .items_center() | |
| 597 | + // `max_w` only caps a box after GPUI has measured its text at | |
| 598 | + // max-content width. `w_full` supplies a definite width to that | |
| 599 | + // measurement (then `max_w` bounds it at 480 px), and normal | |
| 600 | + // whitespace gives the text system permission to shape every word | |
| 601 | + // into the resulting lines. Keep this a block: as a flex child the | |
| 602 | + // text's automatic min-content width can overflow its own plate. | |
| 603 | + // | |
| 604 | + // No fixed height: GPUI's shaped lines contribute their actual | |
| 605 | + // default `phi()` line boxes, so two or three lines grow upward from | |
| 606 | + // this bottom anchor without reaching down over the bench lanes. | |
| 607 | + .w_full() | |
| 608 | + .max_w(px(480.)) | |
| 609 | + .whitespace_normal() | |
| 591 | 610 | .px(px(10.)) |
| 592 | 611 | .py(px(6.)) |
| 593 | 612 | .rounded(px(2.)) |
| @@ -922,7 +941,7 @@ pub(crate) fn render( | ||
| 922 | 941 | .child(divider(Split::Bench, cx)) |
| 923 | 942 | .child(bench(player, bench_h, cx)) |
| 924 | 943 | .child(ledger(player, position)) |
| 925 | - .when_some(player.notices.front().cloned(), |el, n| { | |
| 944 | + .when_some(player.notices.back().cloned(), |el, n| { | |
| 926 | 945 | el.child(notice_plate(n, bench_h)) |
| 927 | 946 | }) |
| 928 | 947 | .when(player.keys_open, |el| el.child(keys_overlay(player))) |
crates/engine/src/playback.rsmodified+15 -0
| @@ -2028,6 +2028,13 @@ impl PlaybackSession { | ||
| 2028 | 2028 | self.project.lane(lane) |
| 2029 | 2029 | } |
| 2030 | 2030 | |
| 2031 | + /// The empty stretch of `lane` covering `frame`, or `None` when `frame` | |
| 2032 | + /// is inside a clip or past the last one ([`Project::gap_at`]). What a | |
| 2033 | + /// right-click on empty bench space asks before offering to close it. | |
| 2034 | + pub fn gap_at(&self, lane: Lane, frame: u32) -> Option<(u32, u32)> { | |
| 2035 | + self.project.gap_at(lane, frame) | |
| 2036 | + } | |
| 2037 | + | |
| 2031 | 2038 | /// Every lane's handle, in display order -- what a front-end lays out top to |
| 2032 | 2039 | /// bottom, and the list [`add_lane`](Self::add_lane) grows. |
| 2033 | 2040 | pub fn lanes(&self) -> Vec<Lane> { |
| @@ -2443,6 +2450,14 @@ impl PlaybackSession { | ||
| 2443 | 2450 | .and_then(|s| s.from) |
| 2444 | 2451 | } |
| 2445 | 2452 | |
| 2453 | + /// The lanes closing the gap `(start, frames)` on `lane` must ripple | |
| 2454 | + /// together to keep every take crossing it in sync | |
| 2455 | + /// ([`Project::gap_take_scope`]) -- what a right-click on empty bench | |
| 2456 | + /// space asks before offering to close it. | |
| 2457 | + pub fn gap_take_scope(&self, lane: Lane, start: u32, frames: u32) -> crate::Result<Vec<Lane>> { | |
| 2458 | + self.project.gap_take_scope(lane, start, frames) | |
| 2459 | + } | |
| 2460 | + | |
| 2446 | 2461 | /// Cuts every one of `regions` -- `(start, len)` in timeline frames -- out |
| 2447 | 2462 | /// of the lanes in `scope` and closes each hole, as **one** edit |
| 2448 | 2463 | /// ([`Project::cut_regions`]): the jumpcut a silence scan |
crates/engine/src/project.rsmodified+252 -0
| @@ -4180,6 +4180,83 @@ impl Project { | ||
| 4180 | 4180 | true |
| 4181 | 4181 | } |
| 4182 | 4182 | |
| 4183 | + /// The empty stretch of `lane` covering `frame`, as `(start, len)` -- what | |
| 4184 | + /// a right-click on empty bench space names before offering to close it. | |
| 4185 | + /// `None` when `frame` sits inside a clip, or past the last one: the open | |
| 4186 | + /// end of a lane is not a gap, since there is nothing after it to slide | |
| 4187 | + /// back ([`gap`]). | |
| 4188 | + pub fn gap_at(&self, lane: Lane, frame: u32) -> Option<(u32, u32)> { | |
| 4189 | + gap(self.lane(lane), frame) | |
| 4190 | + } | |
| 4191 | + | |
| 4192 | + /// The lanes closing the gap `(start, frames)` on `lane` must ripple | |
| 4193 | + /// together to keep sync -- what a right-click on empty bench space asks | |
| 4194 | + /// before the menu offers to close it, and what widens | |
| 4195 | + /// [`cut_regions`](Project::cut_regions)'s scope from the one lane a hand | |
| 4196 | + /// named to the whole take the gap might be half of. | |
| 4197 | + /// | |
| 4198 | + /// A clip bordering the gap on `lane` -- the one ending where it starts, | |
| 4199 | + /// the one starting where it ends -- carries a link when it is one take | |
| 4200 | + /// with a clip on another lane. That lane joins the scope only when the | |
| 4201 | + /// *exact same* stretch is empty there too (same start, same length): the | |
| 4202 | + /// ripple then removes nothing but silence, on every lane it touches, and | |
| 4203 | + /// both halves stay the length they always were. A link whose partner | |
| 4204 | + /// lane is not empty there -- a gap of a different length, or none at all | |
| 4205 | + /// -- is named back to the caller rather than silently widened past | |
| 4206 | + /// (which would cut real media out of a lane nothing asked to touch) or | |
| 4207 | + /// silently left out (which is the defect this closes: a per-lane ripple | |
| 4208 | + /// would leave [`scope_holds_takes_whole`](Project::scope_holds_takes_whole) | |
| 4209 | + /// to refuse it after the fact, on the very half this could have carried | |
| 4210 | + /// along). | |
| 4211 | + /// | |
| 4212 | + /// `Ok(vec![lane])` alone for a gap that borders no take, or none whose | |
| 4213 | + /// partner clip sits on another lane -- the unlinked case, untouched. | |
| 4214 | + pub fn gap_take_scope(&self, lane: Lane, start: u32, frames: u32) -> crate::Result<Vec<Lane>> { | |
| 4215 | + let Some(li) = self.index(lane) else { | |
| 4216 | + return Err("no track to work on".into()); | |
| 4217 | + }; | |
| 4218 | + let labels = handles(&self.lanes); | |
| 4219 | + let end = start + frames; | |
| 4220 | + let mut scope = vec![lane]; | |
| 4221 | + for c in self.lanes[li] | |
| 4222 | + .clips | |
| 4223 | + .iter() | |
| 4224 | + .filter(|c| c.end() == start || c.start == end) | |
| 4225 | + { | |
| 4226 | + let Some(id) = c.link else { continue }; | |
| 4227 | + for (j, data) in self.lanes.iter().enumerate() { | |
| 4228 | + if j == li { | |
| 4229 | + continue; | |
| 4230 | + } | |
| 4231 | + let Some(half) = data.clips.iter().find(|o| o.link == Some(id)) else { | |
| 4232 | + continue; | |
| 4233 | + }; | |
| 4234 | + match gap(&data.clips, start) { | |
| 4235 | + Some((s, f)) if s == start && f == frames => { | |
| 4236 | + let other = labels[j]; | |
| 4237 | + if !scope.contains(&other) { | |
| 4238 | + scope.push(other); | |
| 4239 | + } | |
| 4240 | + } | |
| 4241 | + _ => { | |
| 4242 | + return Err(format!( | |
| 4243 | + "the {} clip at frame {} is one take with the {} clip at frame {}: \ | |
| 4244 | + closing this gap alone would pull the take out of sync -- close {}'s \ | |
| 4245 | + gap there too, or detach them first", | |
| 4246 | + labels[li].label(), | |
| 4247 | + c.start, | |
| 4248 | + labels[j].label(), | |
| 4249 | + half.start, | |
| 4250 | + labels[j].label() | |
| 4251 | + ) | |
| 4252 | + .into()); | |
| 4253 | + } | |
| 4254 | + } | |
| 4255 | + } | |
| 4256 | + } | |
| 4257 | + Ok(scope) | |
| 4258 | + } | |
| 4259 | + | |
| 4183 | 4260 | /// Cut **every** one of `regions` -- `(start, len)` in timeline frames -- |
| 4184 | 4261 | /// out of the lanes in `scope` and close each hole, as one edit: the |
| 4185 | 4262 | /// jumpcut a silence scan asks for ([`crate::silence`]). |
| @@ -4899,6 +4976,21 @@ fn at(clips: &[Clip], frame: u32) -> Option<usize> { | ||
| 4899 | 4976 | (frame < clips[idx].end()).then_some(idx) |
| 4900 | 4977 | } |
| 4901 | 4978 | |
| 4979 | +/// The empty stretch of `clips` covering `frame`, as `(start, len)` -- `None` | |
| 4980 | +/// when `frame` is inside a clip, or past the last one. Sorted-disjoint | |
| 4981 | +/// invariant like [`at`]: the first clip whose start is past `frame` is the | |
| 4982 | +/// far wall, and the last one that ends at or before `frame` (or the | |
| 4983 | +/// timeline's own head, `0`, when there is none) is the near one. | |
| 4984 | +fn gap(clips: &[Clip], frame: u32) -> Option<(u32, u32)> { | |
| 4985 | + if at(clips, frame).is_some() { | |
| 4986 | + return None; | |
| 4987 | + } | |
| 4988 | + let idx = clips.partition_point(|c| c.start <= frame); | |
| 4989 | + let next = clips.get(idx)?; | |
| 4990 | + let start = idx.checked_sub(1).map_or(0, |i| clips[i].end()); | |
| 4991 | + Some((start, next.start - start)) | |
| 4992 | +} | |
| 4993 | + | |
| 4902 | 4994 | /// Index of the clip `frame` falls *strictly inside*, i.e. the one a split |
| 4903 | 4995 | /// there would cut in two. A placement's own first frame is not inside it. |
| 4904 | 4996 | fn splittable(clips: &[Clip], frame: u32) -> Option<usize> { |
| @@ -7521,6 +7613,166 @@ mod tests { | ||
| 7521 | 7613 | ); |
| 7522 | 7614 | } |
| 7523 | 7615 | |
| 7616 | + /// The gap-close menu's hit test: what `gap_at` says about a frame at the | |
| 7617 | + /// head of a lane, between two clips, inside a clip, past the last one, | |
| 7618 | + /// and on a lane holding nothing at all. | |
| 7619 | + #[test] | |
| 7620 | + fn gap_at_finds_the_hole_a_frame_sits_in() { | |
| 7621 | + let mut p = Project::single(FILE, 1); | |
| 7622 | + let v = p.add_lane(LaneKind::Video); | |
| 7623 | + // Empty lane: nothing before and nothing after -- not a gap, since | |
| 7624 | + // there is nothing to ripple toward. | |
| 7625 | + assert_eq!(p.gap_at(v, 0), None, "an empty lane has nothing to close"); | |
| 7626 | + | |
| 7627 | + assert!(p.place(v, 5, clip(5, 0, 3, 0)), "single clip at [5,8)"); | |
| 7628 | + // Before the only clip: the gap runs from the timeline's own head. | |
| 7629 | + assert_eq!(p.gap_at(v, 0), Some((0, 5))); | |
| 7630 | + assert_eq!(p.gap_at(v, 4), Some((0, 5))); | |
| 7631 | + // Inside the clip: not a gap. | |
| 7632 | + assert_eq!(p.gap_at(v, 5), None); | |
| 7633 | + assert_eq!(p.gap_at(v, 7), None); | |
| 7634 | + // Past the only clip: the open end of the lane, not a gap -- there is | |
| 7635 | + // nothing after it to slide back. | |
| 7636 | + assert_eq!(p.gap_at(v, 8), None); | |
| 7637 | + assert_eq!(p.gap_at(v, 100), None); | |
| 7638 | + | |
| 7639 | + assert!(p.place(v, 12, clip(12, 0, 2, 0)), "a second clip at [12,14)"); | |
| 7640 | + // Between the two: the gap [8,12). | |
| 7641 | + assert_eq!(p.gap_at(v, 8), Some((8, 4))); | |
| 7642 | + assert_eq!(p.gap_at(v, 11), Some((8, 4))); | |
| 7643 | + assert_eq!(p.gap_at(v, 14), None, "still the open end"); | |
| 7644 | + | |
| 7645 | + assert!( | |
| 7646 | + p.place(v, 8, clip(8, 0, 4, 0)), | |
| 7647 | + "fills [8,12) exactly, meeting both neighbours" | |
| 7648 | + ); | |
| 7649 | + assert_eq!(p.gap_at(v, 8), None, "adjacent clips leave no frame to name a gap"); | |
| 7650 | + assert_eq!(p.gap_at(v, 11), None); | |
| 7651 | + } | |
| 7652 | + | |
| 7653 | + /// Closing a gap is [`Project::cut_regions`] scoped to the one lane the | |
| 7654 | + /// menu named: the clip after the gap slides back on that lane, a clip on | |
| 7655 | + /// another lane at the very same frame range does not move, and the whole | |
| 7656 | + /// close is one press of undo. | |
| 7657 | + #[test] | |
| 7658 | + fn closing_a_gap_ripples_only_its_own_lane_and_undoes_in_one_step() { | |
| 7659 | + let mut p = Project::single(FILE, 1); | |
| 7660 | + let v = p.add_lane(LaneKind::Video); | |
| 7661 | + let a = p.add_lane(LaneKind::Audio); | |
| 7662 | + assert!(p.place(v, 5, clip(5, 0, 3, 0)), "V clip at [5,8)"); | |
| 7663 | + assert!( | |
| 7664 | + p.place(a, 0, clip(0, 0, 3, 0)), | |
| 7665 | + "A clip at [0,3) -- outside the video lane's gap and this scope" | |
| 7666 | + ); | |
| 7667 | + let before = shape(&p); | |
| 7668 | + let (start, len) = p.gap_at(v, 0).expect("a gap before the only clip"); | |
| 7669 | + assert_eq!((start, len), (0, 5)); | |
| 7670 | + assert!(p.cut_regions(&[(start, len)], &[v]).is_ok()); | |
| 7671 | + assert_eq!(p.lane(v)[0].start, 0, "the clip slid back to close the gap"); | |
| 7672 | + assert_eq!(p.lane(a)[0].start, 0, "the untouched lane's clip did not move"); | |
| 7673 | + assert!(p.undo(), "one press undoes the whole close"); | |
| 7674 | + assert_eq!(shape(&p), before, "back to exactly where it was"); | |
| 7675 | + } | |
| 7676 | + | |
| 7677 | + /// A clip carrying an explicit link id -- what a | |
| 7678 | + /// [`from_parts`](Project::from_parts) fixture below needs to build a take | |
| 7679 | + /// by hand, the same shape `a_link_id_is_never_two_clips_of_one_lane` | |
| 7680 | + /// already builds inline. | |
| 7681 | + fn linked(start: u32, in_frame: u32, out_frame: u32, link: u32) -> Clip { | |
| 7682 | + Clip { | |
| 7683 | + fade_in: 0, | |
| 7684 | + fade_out: 0, | |
| 7685 | + transition_out: 0, | |
| 7686 | + start, | |
| 7687 | + in_frame, | |
| 7688 | + out_frame, | |
| 7689 | + source: 0, | |
| 7690 | + link: Some(link), | |
| 7691 | + eq: None, | |
| 7692 | + color: None, | |
| 7693 | + transform: None, | |
| 7694 | + fit: FitPolicy::default(), | |
| 7695 | + speed: Speed::NORMAL, | |
| 7696 | + } | |
| 7697 | + } | |
| 7698 | + | |
| 7699 | + /// The ordinary case the defect made a permanent no-op: a gap on `V1` | |
| 7700 | + /// bordered by a linked take whose `A1` half is empty across the very | |
| 7701 | + /// same stretch widens the scope to both lanes, so the ripple carries the | |
| 7702 | + /// take rather than tearing it -- and one undo puts both halves back. | |
| 7703 | + #[test] | |
| 7704 | + fn closing_a_gap_carries_a_linked_take_when_the_gap_matches_on_both_lanes() { | |
| 7705 | + let sources = vec![Source::new(FILE, 0)]; | |
| 7706 | + let video = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)]; | |
| 7707 | + let audio = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)]; | |
| 7708 | + let mut p = Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new()) | |
| 7709 | + .expect("valid parts"); | |
| 7710 | + let before = shape(&p); | |
| 7711 | + assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2))); | |
| 7712 | + assert_eq!(p.gap_at(Lane::A1, 3), Some((3, 2)), "the same stretch is empty on A1 too"); | |
| 7713 | + | |
| 7714 | + let scope = p | |
| 7715 | + .gap_take_scope(Lane::V1, 3, 2) | |
| 7716 | + .expect("a matching gap on both halves widens the scope"); | |
| 7717 | + assert_eq!(scope.len(), 2, "the take's other lane joins"); | |
| 7718 | + assert!(scope.contains(&Lane::V1) && scope.contains(&Lane::A1)); | |
| 7719 | + | |
| 7720 | + assert!(p.cut_regions(&[(3, 2)], &scope).is_ok()); | |
| 7721 | + assert_eq!(p.lane(Lane::V1)[1].start, 3, "V1's far half slid back"); | |
| 7722 | + assert_eq!(p.lane(Lane::A1)[1].start, 3, "A1's far half rode along, in sync"); | |
| 7723 | + assert!(p.undo(), "one press undoes the whole close"); | |
| 7724 | + assert_eq!(shape(&p), before, "back to exactly where it was"); | |
| 7725 | + } | |
| 7726 | + | |
| 7727 | + /// The real design question: a take whose gap is not the *same size* on | |
| 7728 | + /// both lanes cannot ripple by one number without pulling a lane's clip | |
| 7729 | + /// out from under the other's sync -- refused by name, with the frame | |
| 7730 | + /// naming which lane is out of step, rather than silently taking real | |
| 7731 | + /// media off the shorter side. | |
| 7732 | + #[test] | |
| 7733 | + fn closing_a_gap_refuses_a_take_whose_gap_lengths_differ() { | |
| 7734 | + let sources = vec![Source::new(FILE, 0)]; | |
| 7735 | + let video = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)]; | |
| 7736 | + // A1's second half starts at 4, not 5: its gap is [3,4), one frame | |
| 7737 | + // shorter than V1's [3,5) -- a legal offset-preserving group, and | |
| 7738 | + // still one take. | |
| 7739 | + let audio = vec![linked(0, 0, 3, 1), linked(4, 5, 9, 3)]; | |
| 7740 | + let p = Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new()) | |
| 7741 | + .expect("valid parts"); | |
| 7742 | + assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2))); | |
| 7743 | + assert_eq!(p.gap_at(Lane::A1, 3), Some((3, 1)), "a shorter gap on A1"); | |
| 7744 | + | |
| 7745 | + let err = p | |
| 7746 | + .gap_take_scope(Lane::V1, 3, 2) | |
| 7747 | + .expect_err("a mismatched gap cannot ripple by one number") | |
| 7748 | + .to_string(); | |
| 7749 | + assert!(err.contains("A1"), "{err}"); | |
| 7750 | + assert!(err.contains("out of sync"), "{err}"); | |
| 7751 | + } | |
| 7752 | + | |
| 7753 | + /// A gap on `V1` whose `A1` half is not a gap at all -- real audio plays | |
| 7754 | + /// there -- cannot close without cutting that audio out from under | |
| 7755 | + /// nothing asked to touch it: refused, not widened silently past. | |
| 7756 | + #[test] | |
| 7757 | + fn closing_a_gap_refuses_a_take_whose_other_half_is_solid() { | |
| 7758 | + let sources = vec![Source::new(FILE, 0)]; | |
| 7759 | + let video = vec![linked(0, 0, 3, 1), linked(5, 5, 9, 3)]; | |
| 7760 | + // A1 plays through the whole span as one continuous clip, sharing | |
| 7761 | + // V1's first-half link: nothing empty at frame 3 there at all. | |
| 7762 | + let audio = vec![linked(0, 0, 9, 1)]; | |
| 7763 | + let p = Project::from_parts(sources, two(video, audio), Vec::new(), Vec::new(), Vec::new()) | |
| 7764 | + .expect("valid parts"); | |
| 7765 | + assert_eq!(p.gap_at(Lane::V1, 3), Some((3, 2))); | |
| 7766 | + assert_eq!(p.gap_at(Lane::A1, 3), None, "A1 plays through, no gap there"); | |
| 7767 | + | |
| 7768 | + let err = p | |
| 7769 | + .gap_take_scope(Lane::V1, 3, 2) | |
| 7770 | + .expect_err("a solid partner cannot ripple with the gap") | |
| 7771 | + .to_string(); | |
| 7772 | + assert!(err.contains("A1"), "{err}"); | |
| 7773 | + assert!(err.contains("detach"), "{err}"); | |
| 7774 | + } | |
| 7775 | + | |
| 7524 | 7776 | #[test] |
| 7525 | 7777 | fn ripple_delete_spans_partial_clips() { |
| 7526 | 7778 | let mut p = three(); |