merge main into focus lane (keep both Deselect and FocusPanels exemptions, entry count 76)
Browse files at this commit19 changed files +1127 -153
- crates/app/src/keymap.rs +13 -3
- crates/app/src/layout.rs +34 -16
- crates/app/src/library_meta.rs +20 -13
- crates/app/src/main.rs +15 -8
- crates/app/src/player/actions.rs +8 -2
- crates/app/src/player/library.rs +3 -3
- crates/app/src/player/timeline_edit.rs +227 -45
- crates/app/src/player/transport.rs +51 -18
- crates/app/src/render.rs +4 -4
- crates/app/src/tests/cards.rs +70 -2
- crates/app/src/tests/editing.rs +335 -6
- crates/app/src/tests/layout.rs +48 -12
- crates/app/src/timeline_math.rs +30 -8
- crates/app/src/ui/bench_stance.rs +2 -0
- crates/app/src/ui/inspector.rs +100 -0
- crates/app/src/ui/timeline.rs +9 -5
- crates/app/src/ui/toolbar.rs +13 -1
- crates/engine/src/playback.rs +26 -0
- crates/engine/src/project.rs +119 -7
crates/app/src/keymap.rsmodified+13 -3
| @@ -118,6 +118,9 @@ actions! { | |||
| 118 | /// ctrl-click that builds a selection by hand, for the times everything | 118 | /// ctrl-click that builds a selection by hand, for the times everything |
| 119 | /// wants selecting at once. | 119 | /// wants selecting at once. |
| 120 | SelectAll, | 120 | SelectAll, |
| 121 | + /// Bare escape with nothing else claiming it: empties a multi-clip | ||
| 122 | + /// selection without touching picks, cards or fullscreen. | ||
| 123 | + Deselect, | ||
| 121 | Delete, | 124 | Delete, |
| 122 | Lift, | 125 | Lift, |
| 123 | Color, | 126 | Color, |
| @@ -262,6 +265,7 @@ impl ActionId { | |||
| 262 | ActionId::SelectNext => "Select the next clip in the lane", | 265 | ActionId::SelectNext => "Select the next clip in the lane", |
| 263 | ActionId::SelectPrev => "Select the previous clip in the lane", | 266 | ActionId::SelectPrev => "Select the previous clip in the lane", |
| 264 | ActionId::SelectAll => "Select everything (every clip and caption)", | 267 | ActionId::SelectAll => "Select everything (every clip and caption)", |
| 268 | + ActionId::Deselect => "Clear the selection", | ||
| 265 | ActionId::Delete => "Delete", | 269 | ActionId::Delete => "Delete", |
| 266 | ActionId::Lift => "Lift (leave a gap)", | 270 | ActionId::Lift => "Lift (leave a gap)", |
| 267 | ActionId::Color => "Colour…", | 271 | ActionId::Color => "Colour…", |
| @@ -342,6 +346,7 @@ impl ActionId { | |||
| 342 | ActionId::SelectNext => "select-next", | 346 | ActionId::SelectNext => "select-next", |
| 343 | ActionId::SelectPrev => "select-prev", | 347 | ActionId::SelectPrev => "select-prev", |
| 344 | ActionId::SelectAll => "select-all", | 348 | ActionId::SelectAll => "select-all", |
| 349 | + ActionId::Deselect => "deselect", | ||
| 345 | ActionId::Delete => "delete", | 350 | ActionId::Delete => "delete", |
| 346 | ActionId::Lift => "lift", | 351 | ActionId::Lift => "lift", |
| 347 | ActionId::Color => "color", | 352 | ActionId::Color => "color", |
| @@ -421,6 +426,7 @@ impl ActionId { | |||
| 421 | | ActionId::SelectNext | 426 | | ActionId::SelectNext |
| 422 | | ActionId::SelectPrev | 427 | | ActionId::SelectPrev |
| 423 | | ActionId::SelectAll | 428 | | ActionId::SelectAll |
| 429 | + | ActionId::Deselect | ||
| 424 | | ActionId::Delete | 430 | | ActionId::Delete |
| 425 | | ActionId::Lift | 431 | | ActionId::Lift |
| 426 | | ActionId::Color | 432 | | ActionId::Color |
| @@ -1067,6 +1073,10 @@ impl Keymap { | |||
| 1067 | // below had to move off ctrl+a: a stroke that universal was | 1073 | // below had to move off ctrl+a: a stroke that universal was |
| 1068 | // never really the removal's to keep. | 1074 | // never really the removal's to keep. |
| 1069 | b(ActionId::SelectAll, "a", true), | 1075 | b(ActionId::SelectAll, "a", true), |
| 1076 | + // Bare escape, last in the precedence chain behind every card, | ||
| 1077 | + // search and fullscreen close (render.rs) -- just empties the | ||
| 1078 | + // selection when nothing else claims the key. | ||
| 1079 | + b(ActionId::Deselect, "escape", false), | ||
| 1070 | b(ActionId::Delete, "x", false), | 1080 | b(ActionId::Delete, "x", false), |
| 1071 | b(ActionId::Delete, "delete", false), | 1081 | b(ActionId::Delete, "delete", false), |
| 1072 | b(ActionId::Lift, "l", false), | 1082 | b(ActionId::Lift, "l", false), |
| @@ -1519,7 +1529,7 @@ mod tests { | |||
| 1519 | #[test] | 1529 | #[test] |
| 1520 | fn every_default_stroke_reaches_its_action() { | 1530 | fn every_default_stroke_reaches_its_action() { |
| 1521 | let k = Keymap::defaults(); | 1531 | let k = Keymap::defaults(); |
| 1522 | - assert_eq!(k.entries().len(), 75); | 1532 | + assert_eq!(k.entries().len(), 76); |
| 1523 | // The cut odometer: bare walks one, `<`/`>` (what shift+,/shift+. | 1533 | // The cut odometer: bare walks one, `<`/`>` (what shift+,/shift+. |
| 1524 | // actually type) strides ten. | 1534 | // actually type) strides ten. |
| 1525 | assert_eq!(k.lookup(".", false), Some(ActionId::WalkCutNext)); | 1535 | assert_eq!(k.lookup(".", false), Some(ActionId::WalkCutNext)); |
| @@ -1603,9 +1613,9 @@ mod tests { | |||
| 1603 | assert_eq!(k.lookup("=", false), Some(ActionId::VolumeUp)); | 1613 | assert_eq!(k.lookup("=", false), Some(ActionId::VolumeUp)); |
| 1604 | assert_eq!(k.lookup("-", false), Some(ActionId::VolumeDown)); | 1614 | assert_eq!(k.lookup("-", false), Some(ActionId::VolumeDown)); |
| 1605 | assert_eq!(k.lookup("+", false), None); | 1615 | assert_eq!(k.lookup("+", false), None); |
| 1606 | - // The chord, and *only* the chord: bare escape reaches no action at all. | 1616 | + // The chord cancels an export; bare escape falls through to Deselect. |
| 1607 | assert_eq!(k.lookup("escape", true), Some(ActionId::CancelExport)); | 1617 | assert_eq!(k.lookup("escape", true), Some(ActionId::CancelExport)); |
| 1608 | - assert_eq!(k.lookup("escape", false), None); | 1618 | + assert_eq!(k.lookup("escape", false), Some(ActionId::Deselect)); |
| 1609 | // The modifier is half the chord: ctrl+e is not e. | 1619 | // The modifier is half the chord: ctrl+e is not e. |
| 1610 | assert_eq!(k.lookup("e", true), None); | 1620 | assert_eq!(k.lookup("e", true), None); |
| 1611 | assert_eq!(k.lookup("space", true), None); | 1621 | assert_eq!(k.lookup("space", true), None); |
crates/app/src/layout.rsmodified+34 -16
| @@ -398,12 +398,19 @@ pub(crate) enum Split { | |||
| 398 | } | 398 | } |
| 399 | 399 | ||
| 400 | impl Split { | 400 | impl Split { |
| 401 | - /// The two persisted seams -- library/inspector/timeline stay | 401 | + /// Every seam that survives a restart -- all five regions, the file |
| 402 | - /// unpersisted, out of this diff's scope, same as before it. Read by | 402 | + /// itself the only store (view state stays out of `.edith`, the |
| 403 | - /// [`load_stance_splits`] and [`save_stance_splits`] together so the | 403 | + /// settled convention). Read by [`load_stance_splits`] and |
| 404 | - /// two can never learn a different set of keys from each other, the | 404 | + /// [`save_stance_splits`] together so the set can never learn a |
| 405 | - /// gap a sixth region would otherwise fall through silently. | 405 | + /// different set of keys from each other, the gap a sixth region |
| 406 | - const PERSISTED: [Split; 2] = [Split::Dock, Split::Bench]; | 406 | + /// would otherwise fall through silently. |
| 407 | + pub(crate) const PERSISTED: [Split; 5] = [ | ||
| 408 | + Split::Library, | ||
| 409 | + Split::Inspector, | ||
| 410 | + Split::Timeline, | ||
| 411 | + Split::Dock, | ||
| 412 | + Split::Bench, | ||
| 413 | + ]; | ||
| 407 | 414 | ||
| 408 | fn key(self) -> &'static str { | 415 | fn key(self) -> &'static str { |
| 409 | match self { | 416 | match self { |
| @@ -518,23 +525,30 @@ impl Splits { | |||
| 518 | } | 525 | } |
| 519 | } | 526 | } |
| 520 | 527 | ||
| 521 | -/// Where the darkroom's own two dragged sizes live -- dock and bench, the | 528 | +/// Where every seam's dragged size lives. Same small, silent round trip as |
| 522 | -/// only pair with a hand on them so far. Same small, silent round trip as | 529 | +/// [`crate::ui::dock_stance`]'s tab pick: unreadable or absent leaves a seam |
| 523 | -/// [`crate::ui::dock_stance`]'s tab pick: unreadable or absent leaves both | ||
| 524 | /// `None`, which [`split_size`] already reads as "give it the window's own | 530 | /// `None`, which [`split_size`] already reads as "give it the window's own |
| 525 | /// share". | 531 | /// share". |
| 526 | pub(crate) fn stance_splits_config_path() -> std::path::PathBuf { | 532 | pub(crate) fn stance_splits_config_path() -> std::path::PathBuf { |
| 527 | crate::keymap::Keymap::config_path().with_file_name("stance-splits") | 533 | crate::keymap::Keymap::config_path().with_file_name("stance-splits") |
| 528 | } | 534 | } |
| 529 | 535 | ||
| 530 | -pub(crate) fn load_stance_splits() -> Splits { | 536 | +pub(crate) fn load_stance_splits(window: Size<Pixels>) -> Splits { |
| 531 | - load_stance_splits_from(&stance_splits_config_path()) | 537 | + load_stance_splits_from(&stance_splits_config_path(), window) |
| 532 | } | 538 | } |
| 533 | 539 | ||
| 534 | /// One `split=pixels` line per touched seam, read from `path` -- factored out | 540 | /// One `split=pixels` line per touched seam, read from `path` -- factored out |
| 535 | /// of [`load_stance_splits`] so a test can round-trip a scratch file instead | 541 | /// of [`load_stance_splits`] so a test can round-trip a scratch file instead |
| 536 | -/// of the real config. | 542 | +/// of the real config. `window` is the size the layout is about to be drawn |
| 537 | -pub(crate) fn load_stance_splits_from(path: &std::path::Path) -> Splits { | 543 | +/// at -- a file written by a wider or taller window can hold a seam past |
| 544 | +/// this one's own ceiling, so each value is clamped to it here, before it | ||
| 545 | +/// ever reaches [`Splits`]. [`split_size`] still re-clamps every frame on | ||
| 546 | +/// top of this, but that clamp needs a lane count and a scroll state | ||
| 547 | +/// nothing here has yet; this one runs on the three bounds that do not -- | ||
| 548 | +/// [`SIDE_MAX_FRAC`], [`TIMELINE_MAX_SHARE`] and [`BENCH_MIN_H`] -- so a | ||
| 549 | +/// value this open never reaches even the first frame. | ||
| 550 | +pub(crate) fn load_stance_splits_from(path: &std::path::Path, window: Size<Pixels>) -> Splits { | ||
| 551 | + let (w, h) = (f32::from(window.width), f32::from(window.height)); | ||
| 538 | let mut splits = Splits::default(); | 552 | let mut splits = Splits::default(); |
| 539 | if let Ok(text) = std::fs::read_to_string(path) { | 553 | if let Ok(text) = std::fs::read_to_string(path) { |
| 540 | for line in text.lines() { | 554 | for line in text.lines() { |
| @@ -547,15 +561,19 @@ pub(crate) fn load_stance_splits_from(path: &std::path::Path) -> Splits { | |||
| 547 | let Some(split) = Split::PERSISTED.into_iter().find(|s| s.key() == key) else { | 561 | let Some(split) = Split::PERSISTED.into_iter().find(|s| s.key() == key) else { |
| 548 | continue; | 562 | continue; |
| 549 | }; | 563 | }; |
| 564 | + let px = match split { | ||
| 565 | + Split::Library | Split::Inspector | Split::Dock => px.min(w * SIDE_MAX_FRAC), | ||
| 566 | + Split::Timeline => px.min(h * TIMELINE_MAX_SHARE), | ||
| 567 | + Split::Bench => px.max(BENCH_MIN_H), | ||
| 568 | + }; | ||
| 550 | splits.set(split, px); | 569 | splits.set(split, px); |
| 551 | } | 570 | } |
| 552 | } | 571 | } |
| 553 | splits | 572 | splits |
| 554 | } | 573 | } |
| 555 | 574 | ||
| 556 | -/// Writes the sizes a hand has actually dragged -- the legacy three stay | 575 | +/// Writes the sizes a hand has actually dragged, one line per seam a hand |
| 557 | -/// unpersisted, as they already were before this diff (out of its scope). | 576 | +/// has touched. Walks [`Split::PERSISTED`] rather than a hand-written `if let` per field, |
| 558 | -/// Walks [`Split::PERSISTED`] rather than a hand-written `if let` per field, | ||
| 559 | /// so a region added there needs no second, separately-maintained list here. | 577 | /// so a region added there needs no second, separately-maintained list here. |
| 560 | pub(crate) fn save_stance_splits(splits: &Splits) { | 578 | pub(crate) fn save_stance_splits(splits: &Splits) { |
| 561 | save_stance_splits_to(splits, &stance_splits_config_path()); | 579 | save_stance_splits_to(splits, &stance_splits_config_path()); |
crates/app/src/library_meta.rsmodified+20 -13
| @@ -9,19 +9,26 @@ use crate::*; | |||
| 9 | /// **a different file** -- the next one along -- over the range it was copied | 9 | /// **a different file** -- the next one along -- over the range it was copied |
| 10 | /// from. | 10 | /// from. |
| 11 | /// | 11 | /// |
| 12 | -/// The clip's own file gone means there is nothing to paste: `None`, and the | 12 | +/// An entry whose own file is gone drops out of the clipboard rather than |
| 13 | -/// next paste says the clipboard is empty rather than putting some other take | 13 | +/// pasting some other take down in its place; a set with even one such |
| 14 | -/// down. Every index past it moves down by one, exactly as the lanes' clips do. | 14 | +/// member is trimmed, not emptied whole, the way a lane keeps every clip a |
| 15 | -pub(crate) fn clipboard_after_remove(clip: Option<Clip>, removed: usize) -> Option<Clip> { | 15 | +/// removal did not touch. Every index past `removed` moves down by one, |
| 16 | - let mut clip = clip?; | 16 | +/// exactly as the lanes' clips do. |
| 17 | - match clip.source.cmp(&removed) { | 17 | +pub(crate) fn clipboard_after_remove( |
| 18 | - std::cmp::Ordering::Equal => None, | 18 | + clipboard: Vec<(Lane, Clip)>, |
| 19 | - std::cmp::Ordering::Greater => { | 19 | + removed: usize, |
| 20 | - clip.source -= 1; | 20 | +) -> Vec<(Lane, Clip)> { |
| 21 | - Some(clip) | 21 | + clipboard |
| 22 | - } | 22 | + .into_iter() |
| 23 | - std::cmp::Ordering::Less => Some(clip), | 23 | + .filter_map(|(lane, mut clip)| match clip.source.cmp(&removed) { |
| 24 | - } | 24 | + std::cmp::Ordering::Equal => None, |
| 25 | + std::cmp::Ordering::Greater => { | ||
| 26 | + clip.source -= 1; | ||
| 27 | + Some((lane, clip)) | ||
| 28 | + } | ||
| 29 | + std::cmp::Ordering::Less => Some((lane, clip)), | ||
| 30 | + }) | ||
| 31 | + .collect() | ||
| 25 | } | 32 | } |
| 26 | 33 | ||
| 27 | /// One library row: a file and one of its audio streams. Plain data, planned | 34 | /// One library row: a file and one of its audio streams. Plain data, planned |
crates/app/src/main.rsmodified+15 -8
| @@ -298,9 +298,13 @@ struct Player { | |||
| 298 | /// reason (a VA-API init), and kept for the life of the process because the | 298 | /// reason (a VA-API init), and kept for the life of the process because the |
| 299 | /// answer cannot change while we run. `None` is "not asked yet". | 299 | /// answer cannot change while we run. `None` is "not asked yet". |
| 300 | hw_caps: Option<SharedString>, | 300 | hw_caps: Option<SharedString>, |
| 301 | - /// The copied clip. Frame ranges only, so it survives the clip it was taken | 301 | + /// The copied clip, or clips: frame ranges and the lane each was on, in |
| 302 | - /// from being deleted -- and it outlives the selection. | 302 | + /// click order, so it survives the clip (or clips) it was taken from |
| 303 | - clipboard: Option<Clip>, | 303 | + /// being deleted -- and it outlives the selection. One entry for a plain |
| 304 | + /// Copy, the whole ctrl-click set for one made over a selection; either | ||
| 305 | + /// way [`Player::paste`] drops the set at the playhead keeping the gaps | ||
| 306 | + /// and lanes between its members intact. | ||
| 307 | + clipboard: Vec<(Lane, Clip)>, | ||
| 304 | /// A drag that started on the ruler. Moves anywhere in the window scrub | 308 | /// A drag that started on the ruler. Moves anywhere in the window scrub |
| 305 | /// while it is set; the release commits the exact position. | 309 | /// while it is set; the release commits the exact position. |
| 306 | scrubbing: bool, | 310 | scrubbing: bool, |
| @@ -385,8 +389,11 @@ struct Player { | |||
| 385 | /// over no lane: the shadow every proper editor draws under a drag. Set by | 389 | /// over no lane: the shadow every proper editor draws under a drag. Set by |
| 386 | /// the lane the pointer is actually over -- that is the one question the | 390 | /// the lane the pointer is actually over -- that is the one question the |
| 387 | /// line above does not answer -- and drawn only while a drag is live, for | 391 | /// line above does not answer -- and drawn only while a drag is live, for |
| 388 | - /// [`Player::snap_cue`]'s reason. | 392 | + /// [`Player::snap_cue`]'s reason. More than one entry only while a |
| 389 | - ghost: Option<Ghost>, | 393 | + /// set-drag ([`Player::move_clip`]'s `set_move`) is carrying more than |
| 394 | + /// the clip under the hand: every other pick draws its own shadow too, at | ||
| 395 | + /// the same delta the anchor's is landing at ([`Player::preview_ghost`]). | ||
| 396 | + ghost: Vec<Ghost>, | ||
| 390 | /// The slot a track header being dragged is about to drop into, or `None` | 397 | /// The slot a track header being dragged is about to drop into, or `None` |
| 391 | /// while the pointer is over no lane: the line drawn between two headers, | 398 | /// while the pointer is over no lane: the line drawn between two headers, |
| 392 | /// for the reason [`Player::ghost`] draws a shadow -- where a gesture lands | 399 | /// for the reason [`Player::ghost`] draws a shadow -- where a gesture lands |
| @@ -935,9 +942,9 @@ fn main() { | |||
| 935 | decoders: HashMap::new(), | 942 | decoders: HashMap::new(), |
| 936 | export_seat: None, | 943 | export_seat: None, |
| 937 | hw_caps: None, | 944 | hw_caps: None, |
| 938 | - clipboard: None, | 945 | + clipboard: Vec::new(), |
| 939 | scrubbing: false, | 946 | scrubbing: false, |
| 940 | - splits: load_stance_splits(), | 947 | + splits: load_stance_splits(bounds.size), |
| 941 | split_drag: None, | 948 | split_drag: None, |
| 942 | trim: None, | 949 | trim: None, |
| 943 | fade_drag: None, | 950 | fade_drag: None, |
| @@ -948,7 +955,7 @@ fn main() { | |||
| 948 | sub_folded: HashSet::new(), | 955 | sub_folded: HashSet::new(), |
| 949 | sub_lane: None, | 956 | sub_lane: None, |
| 950 | snap_cue: None, | 957 | snap_cue: None, |
| 951 | - ghost: None, | 958 | + ghost: Vec::new(), |
| 952 | lane_drop: None, | 959 | lane_drop: None, |
| 953 | last_scrub: Instant::now(), | 960 | last_scrub: Instant::now(), |
| 954 | last_target: 0, | 961 | last_target: 0, |
crates/app/src/player/actions.rsmodified+8 -2
| @@ -98,6 +98,12 @@ impl Player { | |||
| 98 | ActionId::SelectNext => self.select_step(true, cx), | 98 | ActionId::SelectNext => self.select_step(true, cx), |
| 99 | ActionId::SelectPrev => self.select_step(false, cx), | 99 | ActionId::SelectPrev => self.select_step(false, cx), |
| 100 | ActionId::SelectAll => self.select_all(cx), | 100 | ActionId::SelectAll => self.select_all(cx), |
| 101 | + // Last in escape's precedence chain (render.rs): nothing else | ||
| 102 | + // claimed the key, so it just empties the selection. | ||
| 103 | + ActionId::Deselect => { | ||
| 104 | + self.selected = Selection::new(); | ||
| 105 | + cx.notify(); | ||
| 106 | + } | ||
| 101 | ActionId::Delete => self.delete_selected(cx), | 107 | ActionId::Delete => self.delete_selected(cx), |
| 102 | ActionId::Lift => self.lift_selected(cx), | 108 | ActionId::Lift => self.lift_selected(cx), |
| 103 | ActionId::Color => self.open_color(cx), | 109 | ActionId::Color => self.open_color(cx), |
| @@ -241,7 +247,7 @@ impl Player { | |||
| 241 | pub(crate) fn toggle_snap(&mut self, cx: &mut Context<Self>) { | 247 | pub(crate) fn toggle_snap(&mut self, cx: &mut Context<Self>) { |
| 242 | self.snap = !self.snap; | 248 | self.snap = !self.snap; |
| 243 | self.snap_cue = None; | 249 | self.snap_cue = None; |
| 244 | - self.ghost = None; | 250 | + self.ghost.clear(); |
| 245 | self.notify_user(match self.snap { | 251 | self.notify_user(match self.snap { |
| 246 | true => "SNAP ON — drags land on clip edges, the playhead and the start".into(), | 252 | true => "SNAP ON — drags land on clip edges, the playhead and the start".into(), |
| 247 | false => "SNAP OFF — drags land exactly where the hand leaves them".into(), | 253 | false => "SNAP OFF — drags land exactly where the hand leaves them".into(), |
| @@ -364,7 +370,7 @@ impl Player { | |||
| 364 | }), | 370 | }), |
| 365 | playhead: frame_at(session.now(), self.fps), | 371 | playhead: frame_at(session.now(), self.fps), |
| 366 | timeline: true, | 372 | timeline: true, |
| 367 | - clipboard: self.clipboard.is_some(), | 373 | + clipboard: !self.clipboard.is_empty(), |
| 368 | subtitles: !session.subtitles().is_empty(), | 374 | subtitles: !session.subtitles().is_empty(), |
| 369 | playable: !nothing_to_play(self.active_session()), | 375 | playable: !nothing_to_play(self.active_session()), |
| 370 | exporting: self.exporting().is_some(), | 376 | exporting: self.exporting().is_some(), |
crates/app/src/player/library.rsmodified+3 -3
| @@ -164,7 +164,7 @@ impl Player { | |||
| 164 | // A copied clip names its source by *index*, and every index | 164 | // A copied clip names its source by *index*, and every index |
| 165 | // past the one that went has just moved down: without this the | 165 | // past the one that went has just moved down: without this the |
| 166 | // next paste puts some other file on the timeline. | 166 | // next paste puts some other file on the timeline. |
| 167 | - self.clipboard = clipboard_after_remove(self.clipboard, idx); | 167 | + self.clipboard = clipboard_after_remove(std::mem::take(&mut self.clipboard), idx); |
| 168 | self.reset_after_reseek(); | 168 | self.reset_after_reseek(); |
| 169 | // The last row leaves a session naming no file: nothing to | 169 | // The last row leaves a session naming no file: nothing to |
| 170 | // play, nothing to save and nothing to show, which is the empty | 170 | // play, nothing to save and nothing to show, which is the empty |
| @@ -305,7 +305,7 @@ impl Player { | |||
| 305 | self.image = None; | 305 | self.image = None; |
| 306 | // The drawn cue with it, and its tile for the same reason as above. | 306 | // The drawn cue with it, and its tile for the same reason as above. |
| 307 | self.sub_image = None; | 307 | self.sub_image = None; |
| 308 | - self.clipboard = None; | 308 | + self.clipboard.clear(); |
| 309 | self.selected.clear(); | 309 | self.selected.clear(); |
| 310 | self.selected_asset = None; | 310 | self.selected_asset = None; |
| 311 | // The subtitle rows go with the timeline they were on, and so does the | 311 | // The subtitle rows go with the timeline they were on, and so does the |
| @@ -1486,7 +1486,7 @@ impl Player { | |||
| 1486 | self.name = file_name(path).into(); | 1486 | self.name = file_name(path).into(); |
| 1487 | // A copied clip names its source by index, which means a | 1487 | // A copied clip names its source by index, which means a |
| 1488 | // different file -- or none -- in another project. | 1488 | // different file -- or none -- in another project. |
| 1489 | - self.clipboard = None; | 1489 | + self.clipboard.clear(); |
| 1490 | self.selected.clear(); | 1490 | self.selected.clear(); |
| 1491 | // A menu can be up while a project is dropped on the window -- | 1491 | // A menu can be up while a project is dropped on the window -- |
| 1492 | // the scrim swallows clicks, never a drop -- and its index | 1492 | // the scrim swallows clicks, never a drop -- and its index |
crates/app/src/player/timeline_edit.rsmodified+227 -45
| @@ -12,7 +12,7 @@ use crate::*; | |||
| 12 | /// from a live `MouseExitEvent` still cannot be, and is proven by driving | 12 | /// from a live `MouseExitEvent` still cannot be, and is proven by driving |
| 13 | /// instead. | 13 | /// instead. |
| 14 | pub(crate) fn split_drag_owes_save(split: Option<Split>) -> bool { | 14 | pub(crate) fn split_drag_owes_save(split: Option<Split>) -> bool { |
| 15 | - matches!(split, Some(Split::Dock) | Some(Split::Bench)) | 15 | + split.is_some_and(|split| Split::PERSISTED.contains(&split)) |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | impl Player { | 18 | impl Player { |
| @@ -250,18 +250,26 @@ impl Player { | |||
| 250 | cx.notify(); | 250 | cx.notify(); |
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | - /// Copies the selected clip. Nothing on screen changes, so no notify. | 253 | + /// Copies the selection: one entry for a plain click, the whole |
| 254 | + /// ctrl-click set -- every pick, its own lane and its own frames -- for | ||
| 255 | + /// one made over more than a clip. Out of the lane each was clicked in: | ||
| 256 | + /// the audio half of a group is a different clip from the video one, and | ||
| 257 | + /// copying the wrong lane's frames is a paste of the wrong thing. Nothing | ||
| 258 | + /// on screen changes, so no notify. Empty rather than touched at all for | ||
| 259 | + /// a selection naming nothing any more, so a stale Copy leaves the | ||
| 260 | + /// clipboard exactly as a stale Paste would find it. | ||
| 254 | pub(crate) fn copy_selected(&mut self) { | 261 | pub(crate) fn copy_selected(&mut self) { |
| 255 | - let session = self.session.as_ref(); | 262 | + let Some(session) = self.session.as_ref() else { |
| 256 | - // Out of the lane it was clicked in: the audio half of a group is a | 263 | + return; |
| 257 | - // different clip from the video one, and copying the wrong lane's | 264 | + }; |
| 258 | - // frames is a paste of the wrong thing. | 265 | + let picks: Vec<(Lane, Clip)> = self |
| 259 | - if let Some(clip) = self | ||
| 260 | .selected | 266 | .selected |
| 261 | - .anchor() | 267 | + .picks() |
| 262 | - .and_then(|(lane, idx)| session?.lane_clips(lane).get(idx).copied()) | 268 | + .iter() |
| 263 | - { | 269 | + .filter_map(|&(lane, idx)| Some((lane, session.lane_clips(lane).get(idx).copied()?))) |
| 264 | - self.clipboard = Some(clip); | 270 | + .collect(); |
| 271 | + if !picks.is_empty() { | ||
| 272 | + self.clipboard = picks; | ||
| 265 | } | 273 | } |
| 266 | } | 274 | } |
| 267 | 275 | ||
| @@ -288,17 +296,37 @@ impl Player { | |||
| 288 | (picks, links) | 296 | (picks, links) |
| 289 | } | 297 | } |
| 290 | 298 | ||
| 291 | - /// Drops the copied clip in at the playhead. The engine reseeks itself, so | 299 | + /// Drops the copied clip -- or the whole copied set -- in at the |
| 292 | - /// like a delete this owes the flag reset -- and the selection, whose index | 300 | + /// playhead. A single clipboard entry takes the door it always has |
| 293 | - /// the insert has just moved. | 301 | + /// ([`PlaybackSession::paste_at`]): across `V1`/`A1`, splitting whatever |
| 302 | + /// it lands inside of and rippling the room open, byte-identical to | ||
| 303 | + /// before a set could be copied at all. More than one takes | ||
| 304 | + /// [`PlaybackSession::paste_set_at`] instead: every member lands on the | ||
| 305 | + /// lane it was copied off, at the same distance from the others it had on | ||
| 306 | + /// the bed it was copied from, refused whole rather than opening room -- | ||
| 307 | + /// see [`Project::paste_set`] for why a set-paste cannot ripple. The | ||
| 308 | + /// engine reseeks itself either way, so like a delete this owes the flag | ||
| 309 | + /// reset -- and the selection, whose index the insert has just moved. | ||
| 294 | pub(crate) fn paste(&mut self, cx: &mut Context<Self>) { | 310 | pub(crate) fn paste(&mut self, cx: &mut Context<Self>) { |
| 295 | - let pasted = match (&mut self.session, self.clipboard) { | 311 | + let pasted = match (&mut self.session, self.clipboard.as_slice()) { |
| 296 | - (Some(session), Some(clip)) => session.paste_at(session.now(), clip), | 312 | + (Some(session), [(_, clip)]) => session.paste_at(session.now(), *clip), |
| 313 | + (Some(session), items) if !items.is_empty() => { | ||
| 314 | + session.paste_set_at(session.now(), items) | ||
| 315 | + } | ||
| 297 | _ => false, | 316 | _ => false, |
| 298 | }; | 317 | }; |
| 299 | if pasted { | 318 | if pasted { |
| 300 | self.selected.clear(); | 319 | self.selected.clear(); |
| 301 | self.reset_after_reseek(); | 320 | self.reset_after_reseek(); |
| 321 | + } else if self.clipboard.len() > 1 { | ||
| 322 | + // The set-paste's own refusal, worded like a set-drag's | ||
| 323 | + // ([`Player::move_clip`]) -- a single-clip paste stays silent on | ||
| 324 | + // failure exactly as it always has. | ||
| 325 | + self.notify_user( | ||
| 326 | + "NOT PASTED — another clip already covers where one of the copied clips would \ | ||
| 327 | + land" | ||
| 328 | + .into(), | ||
| 329 | + ); | ||
| 302 | } | 330 | } |
| 303 | cx.notify(); | 331 | cx.notify(); |
| 304 | } | 332 | } |
| @@ -310,6 +338,13 @@ impl Player { | |||
| 310 | /// nothing is said about it. The engine reseeks, so all this owes is the | 338 | /// nothing is said about it. The engine reseeks, so all this owes is the |
| 311 | /// flag reset -- and the selection, whose index was that lane's own and now | 339 | /// flag reset -- and the selection, whose index was that lane's own and now |
| 312 | /// names a different clip there. | 340 | /// names a different clip there. |
| 341 | + /// | ||
| 342 | + /// A dragged clip that is *itself* one of the selection's picks carries the | ||
| 343 | + /// whole selection with it: every other pick moves the same frame delta, | ||
| 344 | + /// all-or-nothing ([`PlaybackSession::move_selection_to`]), and the picks | ||
| 345 | + /// survive the move -- their indices remapped rather than cleared, since a | ||
| 346 | + /// pick that travels still names the clip it named before. A clip dragged | ||
| 347 | + /// from outside the selection moves alone, exactly as it always has. | ||
| 313 | pub(crate) fn move_clip( | 348 | pub(crate) fn move_clip( |
| 314 | &mut self, | 349 | &mut self, |
| 315 | from: Lane, | 350 | from: Lane, |
| @@ -330,10 +365,23 @@ impl Player { | |||
| 330 | ) else { | 365 | ) else { |
| 331 | return; | 366 | return; |
| 332 | }; | 367 | }; |
| 333 | - let moved = self | 368 | + let set_move = self.selected.contains((from, idx)) && self.selected.len() > 1; |
| 334 | - .session | 369 | + let picks: Vec<(Lane, usize)> = self.selected.picks().to_vec(); |
| 335 | - .as_mut() | 370 | + // Every pick's own start, read before the move touches anything -- the |
| 336 | - .is_some_and(|session| session.move_clip_to(from, idx, to, start)); | 371 | + // only way to find a pick again afterwards, since a lane change or an |
| 372 | + // insert can move the index it was named by. | ||
| 373 | + let pre_starts: Vec<Option<u32>> = picks | ||
| 374 | + .iter() | ||
| 375 | + .map(|&(lane, i)| { | ||
| 376 | + self.session | ||
| 377 | + .as_ref() | ||
| 378 | + .and_then(|session| session.lane_clips(lane).get(i).map(|c| c.start)) | ||
| 379 | + }) | ||
| 380 | + .collect(); | ||
| 381 | + let moved = self.session.as_mut().is_some_and(|session| match set_move { | ||
| 382 | + true => session.move_selection_to(&picks, from, idx, to, start), | ||
| 383 | + false => session.move_clip_to(from, idx, to, start), | ||
| 384 | + }); | ||
| 337 | let (kind, lanes) = match from.kind { | 385 | let (kind, lanes) = match from.kind { |
| 338 | LaneKind::Video => ("picture", "video"), | 386 | LaneKind::Video => ("picture", "video"), |
| 339 | LaneKind::Audio => ("sound", "audio"), | 387 | LaneKind::Audio => ("sound", "audio"), |
| @@ -343,7 +391,18 @@ impl Player { | |||
| 343 | }; | 391 | }; |
| 344 | match moved { | 392 | match moved { |
| 345 | true => { | 393 | true => { |
| 346 | - self.selected.clear(); | 394 | + // Every pick named a `(lane, ...)` by index into that lane's |
| 395 | + // clips, sorted by start -- exactly what an insert or a lane | ||
| 396 | + // change reorders. Re-read by the frame each pick's clip now | ||
| 397 | + // starts at (recorded before the move moved anything), so the | ||
| 398 | + // selection survives naming the clips it named, not the slots | ||
| 399 | + // they used to sit in. | ||
| 400 | + if set_move { | ||
| 401 | + self.selected = | ||
| 402 | + self.remap_selection(&picks, &pre_starts, from, idx, to, was, start); | ||
| 403 | + } else { | ||
| 404 | + self.selected.clear(); | ||
| 405 | + } | ||
| 347 | self.reset_after_reseek(); | 406 | self.reset_after_reseek(); |
| 348 | } | 407 | } |
| 349 | // The three ways a drag is refused, told apart by what the | 408 | // The three ways a drag is refused, told apart by what the |
| @@ -360,6 +419,15 @@ impl Player { | |||
| 360 | // Picked up and put back down where it was: a click, and a click | 419 | // Picked up and put back down where it was: a click, and a click |
| 361 | // says nothing. | 420 | // says nothing. |
| 362 | false if from == to && start == was => {} | 421 | false if from == to && start == was => {} |
| 422 | + false if set_move => self.notify_user( | ||
| 423 | + format!( | ||
| 424 | + "NOT MOVED — {} clips selected, and another clip already covers where one of \ | ||
| 425 | + them would land on {}", | ||
| 426 | + picks.len(), | ||
| 427 | + to.label() | ||
| 428 | + ) | ||
| 429 | + .into(), | ||
| 430 | + ), | ||
| 363 | false => self.notify_user( | 431 | false => self.notify_user( |
| 364 | format!( | 432 | format!( |
| 365 | "NOT MOVED — another clip already covers those frames on {}", | 433 | "NOT MOVED — another clip already covers those frames on {}", |
| @@ -371,6 +439,50 @@ impl Player { | |||
| 371 | cx.notify(); | 439 | cx.notify(); |
| 372 | } | 440 | } |
| 373 | 441 | ||
| 442 | + /// What a selection's picks are called after a set-move that shifted every | ||
| 443 | + /// one of them by `landed - was` timeline frames (the delta the dragged | ||
| 444 | + /// clip's own head travelled, which every pick travelled too -- see | ||
| 445 | + /// [`Project::move_selection`]): the clip a pick named is found again by | ||
| 446 | + /// where it now starts, on the lane it stays on (or `to`, for the one | ||
| 447 | + /// that changed lane), rather than by the index it had, which a lane | ||
| 448 | + /// change or an insert can have moved. A pick whose clip cannot be found | ||
| 449 | + /// there any more (a bad index handed in) is dropped rather than guessed | ||
| 450 | + /// at. | ||
| 451 | + fn remap_selection( | ||
| 452 | + &self, | ||
| 453 | + picks: &[(Lane, usize)], | ||
| 454 | + pre_starts: &[Option<u32>], | ||
| 455 | + from: Lane, | ||
| 456 | + dragged: usize, | ||
| 457 | + to: Lane, | ||
| 458 | + was: u32, | ||
| 459 | + landed: u32, | ||
| 460 | + ) -> Selection { | ||
| 461 | + let mut out = Selection::new(); | ||
| 462 | + let Some(session) = self.session.as_ref() else { | ||
| 463 | + return out; | ||
| 464 | + }; | ||
| 465 | + let delta = i64::from(landed) - i64::from(was); | ||
| 466 | + for (&pick, &old_start) in picks.iter().zip(pre_starts) { | ||
| 467 | + let Some(old_start) = old_start else { | ||
| 468 | + continue; | ||
| 469 | + }; | ||
| 470 | + let want = (i64::from(old_start) + delta) as u32; | ||
| 471 | + // Every pick but the dragged clip itself stays on the lane it was | ||
| 472 | + // already on; only the exact clip the hand let go of changed | ||
| 473 | + // lane, so only its own pick is found on `to` rather than `from`. | ||
| 474 | + let now_lane = if pick == (from, dragged) { to } else { pick.0 }; | ||
| 475 | + if let Some(found) = session | ||
| 476 | + .lane_clips(now_lane) | ||
| 477 | + .iter() | ||
| 478 | + .position(|c| c.start == want) | ||
| 479 | + { | ||
| 480 | + out.add((now_lane, found)); | ||
| 481 | + } | ||
| 482 | + } | ||
| 483 | + out | ||
| 484 | + } | ||
| 485 | + | ||
| 374 | /// The whole of a palette track as a placement: from its own first | 486 | /// The whole of a palette track as a placement: from its own first |
| 375 | /// microsecond to its last cue, and as many timeline frames as that is worth | 487 | /// microsecond to its last cue, and as many timeline frames as that is worth |
| 376 | /// at this rate. What a row dragged out of the Subtitles list carries, and | 488 | /// at this rate. What a row dragged out of the Subtitles list carries, and |
| @@ -405,7 +517,7 @@ impl Player { | |||
| 405 | } | 517 | } |
| 406 | self.mark_dirty(); | 518 | self.mark_dirty(); |
| 407 | self.snap_cue = None; | 519 | self.snap_cue = None; |
| 408 | - self.ghost = None; | 520 | + self.ghost.clear(); |
| 409 | let at = self.place_frame(x).0; | 521 | let at = self.place_frame(x).0; |
| 410 | // What the mark is on, before the lane is renumbered: a caption's start | 522 | // What the mark is on, before the lane is renumbered: a caption's start |
| 411 | // frame is its name on its lane ([`sub_mark`]). | 523 | // frame is its name on its lane ([`sub_mark`]). |
| @@ -493,7 +605,7 @@ impl Player { | |||
| 493 | } | 605 | } |
| 494 | self.mark_dirty(); | 606 | self.mark_dirty(); |
| 495 | self.snap_cue = None; | 607 | self.snap_cue = None; |
| 496 | - self.ghost = None; | 608 | + self.ghost.clear(); |
| 497 | let Some(idx) = self.dragged_sub(drag) else { | 609 | let Some(idx) = self.dragged_sub(drag) else { |
| 498 | return; | 610 | return; |
| 499 | }; | 611 | }; |
| @@ -669,7 +781,7 @@ impl Player { | |||
| 669 | tint: CLIP_TEXT(), | 781 | tint: CLIP_TEXT(), |
| 670 | refused: to.kind != LaneKind::Subtitle, | 782 | refused: to.kind != LaneKind::Subtitle, |
| 671 | }; | 783 | }; |
| 672 | - self.set_ghost(Some(ghost), cx); | 784 | + self.set_ghost(vec![ghost], cx); |
| 673 | } | 785 | } |
| 674 | 786 | ||
| 675 | /// The same for a palette row on its way down: it lands at the frame it is | 787 | /// The same for a palette row on its way down: it lands at the frame it is |
| @@ -689,7 +801,7 @@ impl Player { | |||
| 689 | tint: CLIP_TEXT(), | 801 | tint: CLIP_TEXT(), |
| 690 | refused: to.kind != LaneKind::Subtitle, | 802 | refused: to.kind != LaneKind::Subtitle, |
| 691 | }; | 803 | }; |
| 692 | - self.set_ghost(Some(ghost), cx); | 804 | + self.set_ghost(vec![ghost], cx); |
| 693 | } | 805 | } |
| 694 | 806 | ||
| 695 | /// Where a clip let go at window `x` over lane `to` wants its head: the | 807 | /// Where a clip let go at window `x` over lane `to` wants its head: the |
| @@ -779,6 +891,15 @@ impl Player { | |||
| 779 | /// are one answer -- and its own length at this zoom. A lane of the other | 891 | /// are one answer -- and its own length at this zoom. A lane of the other |
| 780 | /// kind refuses the drop ([`Project::move_clip`]), and the shadow says so | 892 | /// kind refuses the drop ([`Project::move_clip`]), and the shadow says so |
| 781 | /// before the release does. | 893 | /// before the release does. |
| 894 | + /// | ||
| 895 | + /// When the dragged clip is itself one of a multi-pick selection (the same | ||
| 896 | + /// `set_move` test [`Player::move_clip`] commits by), every other pick | ||
| 897 | + /// draws its own shadow too, at the delta the anchor above is landing at -- | ||
| 898 | + /// [`Project::move_selection`]'s own clamp is not reread here, so a wall | ||
| 899 | + /// that would narrow the group's travel is seen only at the release, not | ||
| 900 | + /// in the shadow; the anchor's own room is still exact; corner-cut, ceiling | ||
| 901 | + /// a shadow a member or two too wide on a tight bed, upgrade is exposing | ||
| 902 | + /// `move_room` to preview against. | ||
| 782 | pub(crate) fn preview_ghost( | 903 | pub(crate) fn preview_ghost( |
| 783 | &mut self, | 904 | &mut self, |
| 784 | drag: &ClipDrag, | 905 | drag: &ClipDrag, |
| @@ -786,17 +907,46 @@ impl Player { | |||
| 786 | x: Pixels, | 907 | x: Pixels, |
| 787 | cx: &mut Context<Self>, | 908 | cx: &mut Context<Self>, |
| 788 | ) { | 909 | ) { |
| 789 | - let ghost = self | 910 | + let Some(idx) = self.dragged(drag) else { |
| 790 | - .dragged(drag) | 911 | + self.set_ghost(Vec::new(), cx); |
| 791 | - .and_then(|idx| self.drop_frame(drag.lane, idx, x)) | 912 | + return; |
| 792 | - .map(|(start, _)| Ghost { | 913 | + }; |
| 793 | - lane: to, | 914 | + let Some((start, _)) = self.drop_frame(drag.lane, idx, x) else { |
| 794 | - start, | 915 | + self.set_ghost(Vec::new(), cx); |
| 795 | - frames: drag.clip.frames(), | 916 | + return; |
| 796 | - tint: self.clip_tint(drag.clip.source), | 917 | + }; |
| 797 | - refused: drag.lane.kind != to.kind, | 918 | + let anchor = Ghost { |
| 798 | - }); | 919 | + lane: to, |
| 799 | - self.set_ghost(ghost, cx); | 920 | + start, |
| 921 | + frames: drag.clip.frames(), | ||
| 922 | + tint: self.clip_tint(drag.clip.source), | ||
| 923 | + refused: drag.lane.kind != to.kind, | ||
| 924 | + }; | ||
| 925 | + let mut ghosts = vec![anchor]; | ||
| 926 | + if self.selected.contains((drag.lane, idx)) && self.selected.len() > 1 { | ||
| 927 | + let delta = i64::from(start) - i64::from(drag.clip.start); | ||
| 928 | + for &(lane, i) in self.selected.picks() { | ||
| 929 | + if (lane, i) == (drag.lane, idx) { | ||
| 930 | + continue; | ||
| 931 | + } | ||
| 932 | + let Some(clip) = self | ||
| 933 | + .session | ||
| 934 | + .as_ref() | ||
| 935 | + .and_then(|session| session.lane_clips(lane).get(i).copied()) | ||
| 936 | + else { | ||
| 937 | + continue; | ||
| 938 | + }; | ||
| 939 | + let want = (i64::from(clip.start) + delta).max(0) as u32; | ||
| 940 | + ghosts.push(Ghost { | ||
| 941 | + lane, | ||
| 942 | + start: want, | ||
| 943 | + frames: clip.frames(), | ||
| 944 | + tint: self.clip_tint(clip.source), | ||
| 945 | + refused: anchor.refused, | ||
| 946 | + }); | ||
| 947 | + } | ||
| 948 | + } | ||
| 949 | + self.set_ghost(ghosts, cx); | ||
| 800 | } | 950 | } |
| 801 | 951 | ||
| 802 | /// The line the track in the hand would drop into, on the row the pointer | 952 | /// The line the track in the hand would drop into, on the row the pointer |
| @@ -860,7 +1010,7 @@ impl Player { | |||
| 860 | tint: file_tint(self.sources(), path).unwrap_or(BG_RAISED()), | 1010 | tint: file_tint(self.sources(), path).unwrap_or(BG_RAISED()), |
| 861 | refused: lane_refuses(path, to).is_some(), | 1011 | refused: lane_refuses(path, to).is_some(), |
| 862 | }; | 1012 | }; |
| 863 | - self.set_ghost(Some(ghost), cx); | 1013 | + self.set_ghost(vec![ghost], cx); |
| 864 | } | 1014 | } |
| 865 | 1015 | ||
| 866 | /// Sets the shadow, or takes it away, repainting only when it moved -- the | 1016 | /// Sets the shadow, or takes it away, repainting only when it moved -- the |
| @@ -868,7 +1018,7 @@ impl Player { | |||
| 868 | /// root and set again by the lane under the pointer, in that order (gpui | 1018 | /// root and set again by the lane under the pointer, in that order (gpui |
| 869 | /// runs the capture phase parent-first), so a pointer over no lane at all | 1019 | /// runs the capture phase parent-first), so a pointer over no lane at all |
| 870 | /// leaves nothing drawn. | 1020 | /// leaves nothing drawn. |
| 871 | - pub(crate) fn set_ghost(&mut self, ghost: Option<Ghost>, cx: &mut Context<Self>) { | 1021 | + pub(crate) fn set_ghost(&mut self, ghost: Vec<Ghost>, cx: &mut Context<Self>) { |
| 872 | if ghost != self.ghost { | 1022 | if ghost != self.ghost { |
| 873 | self.ghost = ghost; | 1023 | self.ghost = ghost; |
| 874 | cx.notify(); | 1024 | cx.notify(); |
| @@ -1550,6 +1700,38 @@ impl Player { | |||
| 1550 | cx.notify(); | 1700 | cx.notify(); |
| 1551 | } | 1701 | } |
| 1552 | 1702 | ||
| 1703 | + /// Widens or narrows the transition the anchor already carries, one | ||
| 1704 | + /// frame at a step, from the inspector's duration row -- ctrl+f/ctrl+x | ||
| 1705 | + /// stay the toggle that seeds a fresh one at one second; this is what | ||
| 1706 | + /// moves it afterwards. The engine clamps both kinds to what the two | ||
| 1707 | + /// clips actually offer ([`Project::set_transition_out`], | ||
| 1708 | + /// [`Project::crossfade`]), so a step past the successor's own length | ||
| 1709 | + /// lands at the successor's length instead of asking for more than | ||
| 1710 | + /// there is. | ||
| 1711 | + pub(crate) fn nudge_transition(&mut self, lane: Lane, idx: usize, step: i32, cx: &mut Context<Self>) { | ||
| 1712 | + if self.exporting().is_some() { | ||
| 1713 | + return; | ||
| 1714 | + } | ||
| 1715 | + let Some(session) = &mut self.session else { | ||
| 1716 | + return; | ||
| 1717 | + }; | ||
| 1718 | + let current = match lane.kind { | ||
| 1719 | + LaneKind::Video => session.transition_out_of(lane, idx), | ||
| 1720 | + LaneKind::Audio => session.lane_clips(lane).get(idx).map_or(0, |c| c.fade_out), | ||
| 1721 | + _ => return, | ||
| 1722 | + }; | ||
| 1723 | + let frames = (current as i32 + step).max(0) as u32; | ||
| 1724 | + let ok = match lane.kind { | ||
| 1725 | + LaneKind::Video => session.set_transition_out(lane, idx, frames), | ||
| 1726 | + LaneKind::Audio => session.crossfade(lane, idx, frames), | ||
| 1727 | + _ => false, | ||
| 1728 | + }; | ||
| 1729 | + if ok { | ||
| 1730 | + self.mark_dirty(); | ||
| 1731 | + cx.notify(); | ||
| 1732 | + } | ||
| 1733 | + } | ||
| 1734 | + | ||
| 1553 | /// The clip as the drag is showing it: an edge under the pointer moves its | 1735 | /// The clip as the drag is showing it: an edge under the pointer moves its |
| 1554 | /// own box, and the boxes of everything linked to it, before anything is | 1736 | /// own box, and the boxes of everything linked to it, before anything is |
| 1555 | /// committed. Display only -- the project is not touched until the release. | 1737 | /// committed. Display only -- the project is not touched until the release. |
| @@ -1750,9 +1932,9 @@ impl Player { | |||
| 1750 | Some(MouseButton::Left) => self.drag_split(split, event.position, window, cx), | 1932 | Some(MouseButton::Left) => self.drag_split(split, event.position, window, cx), |
| 1751 | // Released outside the window: the up below never came, so this | 1933 | // Released outside the window: the up below never came, so this |
| 1752 | // is where the gesture ends. The size is already written to | 1934 | // is where the gesture ends. The size is already written to |
| 1753 | - // `self.splits`, but the darkroom's two persisted seams still | 1935 | + // `self.splits`, but a persisted seam still owes the save |
| 1754 | - // owe the save `drag_release` would have paid -- without it | 1936 | + // `drag_release` would have paid -- without it the drag |
| 1755 | - // the drag holds for the session and reverts on restart. | 1937 | + // holds for the session and reverts on restart. |
| 1756 | _ => { | 1938 | _ => { |
| 1757 | self.split_drag = None; | 1939 | self.split_drag = None; |
| 1758 | if split_drag_owes_save(Some(split)) { | 1940 | if split_drag_owes_save(Some(split)) { |
| @@ -1889,10 +2071,10 @@ impl Player { | |||
| 1889 | } | 2071 | } |
| 1890 | if let Some(split) = self.split_drag.take() { | 2072 | if let Some(split) = self.split_drag.take() { |
| 1891 | self.drag_split(split, event.position, window, cx); | 2073 | self.drag_split(split, event.position, window, cx); |
| 1892 | - // The darkroom's own two seams outlive the window: written once, | 2074 | + // Every seam outlives the window: written once, on the release |
| 1893 | - // on the release that ends the gesture, the same small-file | 2075 | + // that ends the gesture, the same small-file round trip |
| 1894 | - // round trip `ui::dock_stance`'s tab pick uses -- not on every | 2076 | + // `ui::dock_stance`'s tab pick uses -- not on every sample in |
| 1895 | - // sample in between, which `drag_move` above never owed a write. | 2077 | + // between, which `drag_move` above never owed a write. |
| 1896 | if split_drag_owes_save(Some(split)) { | 2078 | if split_drag_owes_save(Some(split)) { |
| 1897 | save_stance_splits(&self.splits); | 2079 | save_stance_splits(&self.splits); |
| 1898 | } | 2080 | } |
crates/app/src/player/transport.rsmodified+51 -18
| @@ -46,14 +46,17 @@ impl Player { | |||
| 46 | let Some(session) = self.preview_session.as_mut().or(self.session.as_mut()) else { | 46 | let Some(session) = self.preview_session.as_mut().or(self.session.as_mut()) else { |
| 47 | return; | 47 | return; |
| 48 | }; | 48 | }; |
| 49 | - // Loop-trim (DESIGN.md §6): the transport is kept inside the subject | 49 | + // Loop-trim and the i/o range (DESIGN.md §6): the transport is kept |
| 50 | - // cut's own span while the mode is on, so a trim can be heard and | 50 | + // inside the active window while one is armed, so a trim or a marked |
| 51 | - // seen without a manual replay after every nudge. Checked off the | 51 | + // range can be heard and seen without a manual replay after every |
| 52 | - // engine's own clock, not a frame counter this pump keeps -- the | 52 | + // nudge. The range wins over the trim when both are set |
| 53 | - // same `now()` [`Player::step`] reads. | 53 | + // ([`active_loop_window`]). Checked off the engine's own clock, not |
| 54 | - if session.is_playing() && should_loop_restart(frame_at(session.now(), fps), self.loop_trim) | 54 | + // a frame counter this pump keeps -- the same `now()` |
| 55 | + // [`Player::step`] reads. | ||
| 56 | + let loop_window = active_loop_window(self.loop_on, self.range, self.loop_trim); | ||
| 57 | + if session.is_playing() && should_loop_restart(frame_at(session.now(), fps), loop_window) | ||
| 55 | { | 58 | { |
| 56 | - let start = self.loop_trim.map_or(0, |(lo, _)| lo); | 59 | + let start = loop_window.map_or(0, |(lo, _)| lo); |
| 57 | session.seek(f64::from(start) / fps); | 60 | session.seek(f64::from(start) / fps); |
| 58 | } | 61 | } |
| 59 | // Whether the span now decoding has yet to hand over a picture, read | 62 | // Whether the span now decoding has yet to hand over a picture, read |
| @@ -172,6 +175,10 @@ impl Player { | |||
| 172 | // whole-timeline loop already used, so that race has nothing | 175 | // whole-timeline loop already used, so that race has nothing |
| 173 | // left to win: reaching the end while *either* loop is armed | 176 | // left to win: reaching the end while *either* loop is armed |
| 174 | // restarts rather than halts, regardless of which one owns it. | 177 | // restarts rather than halts, regardless of which one owns it. |
| 178 | + // A bare i/o range never arms this crossing on its own -- it is | ||
| 179 | + // an export mark first ([`active_loop_window`]) -- so `range` | ||
| 180 | + // only ever widens `armed` through the `loop_on`/`loop_trim` | ||
| 181 | + // terms already here, never past them. | ||
| 175 | let armed = self.loop_on || self.loop_trim.is_some(); | 182 | let armed = self.loop_on || self.loop_trim.is_some(); |
| 176 | if crosses_into_loop(was, Transport::Ended, armed) { | 183 | if crosses_into_loop(was, Transport::Ended, armed) { |
| 177 | // The same door the restart button and key use | 184 | // The same door the restart button and key use |
| @@ -179,7 +186,8 @@ impl Player { | |||
| 179 | // spends only on a repaint -- the pump is already inside one. | 186 | // spends only on a repaint -- the pump is already inside one. |
| 180 | // One seam of a one-frame seam: the restart is a fresh seek | 187 | // One seam of a one-frame seam: the restart is a fresh seek |
| 181 | // and its reopen, not a gapless splice. | 188 | // and its reopen, not a gapless splice. |
| 182 | - let start = loop_restart_frame(self.loop_on, self.loop_trim).unwrap_or(0); | 189 | + let start = |
| 190 | + loop_restart_frame(self.loop_on, self.range, self.loop_trim).unwrap_or(0); | ||
| 183 | if let Some(session) = self.active_session_mut() { | 191 | if let Some(session) = self.active_session_mut() { |
| 184 | session.seek(f64::from(start) / fps); | 192 | session.seek(f64::from(start) / fps); |
| 185 | } | 193 | } |
| @@ -246,7 +254,7 @@ impl Player { | |||
| 246 | // ...and the shadow a drag is drawn under promises a landing on a lane | 254 | // ...and the shadow a drag is drawn under promises a landing on a lane |
| 247 | // this edit has just reshaped. The next move of the drag draws it | 255 | // this edit has just reshaped. The next move of the drag draws it |
| 248 | // again; until then it says nothing. | 256 | // again; until then it says nothing. |
| 249 | - self.ghost = None; | 257 | + self.ghost.clear(); |
| 250 | } | 258 | } |
| 251 | 259 | ||
| 252 | /// Jumps the timeline. | 260 | /// Jumps the timeline. |
| @@ -474,20 +482,45 @@ mod tests { | |||
| 474 | } | 482 | } |
| 475 | 483 | ||
| 476 | /// `loop_restart_frame` picks the seek target the crossing above plays | 484 | /// `loop_restart_frame` picks the seek target the crossing above plays |
| 477 | - /// from: the trim window's near edge when one is armed (it wins over the | 485 | + /// from: the i/o range's near edge when one is armed and set (it wins |
| 478 | - /// whole-timeline loop when both happen to be set), the top of the | 486 | + /// over both the trim window and the whole-timeline loop), the trim |
| 479 | - /// timeline for the whole-timeline loop alone, and no restart at all | 487 | + /// window's near edge next, the top of the timeline for the |
| 480 | - /// with neither armed. | 488 | + /// whole-timeline loop alone, and no restart at all with nothing armed. |
| 481 | #[test] | 489 | #[test] |
| 482 | fn loop_restart_frame_prefers_the_trim_window_then_the_whole_timeline_then_nothing() { | 490 | fn loop_restart_frame_prefers_the_trim_window_then_the_whole_timeline_then_nothing() { |
| 483 | - assert_eq!(loop_restart_frame(false, Some((30, 60))), Some(30)); | 491 | + assert_eq!(loop_restart_frame(false, None, Some((30, 60))), Some(30)); |
| 484 | assert_eq!( | 492 | assert_eq!( |
| 485 | - loop_restart_frame(true, Some((30, 60))), | 493 | + loop_restart_frame(true, None, Some((30, 60))), |
| 486 | Some(30), | 494 | Some(30), |
| 487 | "the trim window wins over the whole-timeline loop" | 495 | "the trim window wins over the whole-timeline loop" |
| 488 | ); | 496 | ); |
| 489 | - assert_eq!(loop_restart_frame(true, None), Some(0)); | 497 | + assert_eq!(loop_restart_frame(true, None, None), Some(0)); |
| 490 | - assert_eq!(loop_restart_frame(false, None), None); | 498 | + assert_eq!(loop_restart_frame(false, None, None), None); |
| 499 | + // The i/o range beats the trim window when both are set... | ||
| 500 | + assert_eq!( | ||
| 501 | + loop_restart_frame(true, Some((10, 20)), Some((30, 60))), | ||
| 502 | + Some(10), | ||
| 503 | + "the marked range wins over the subject-cut trim" | ||
| 504 | + ); | ||
| 505 | + // ...and a range alone, with loop off and no trim, never arms a | ||
| 506 | + // restart at all -- it is an export mark first. | ||
| 507 | + assert_eq!( | ||
| 508 | + loop_restart_frame(false, Some((10, 20)), None), | ||
| 509 | + None, | ||
| 510 | + "a bare i/o range must not start looping un-looped playback" | ||
| 511 | + ); | ||
| 512 | + // Clearing the range falls back to the trim window, then to the | ||
| 513 | + // whole timeline. | ||
| 514 | + assert_eq!( | ||
| 515 | + loop_restart_frame(true, None, Some((30, 60))), | ||
| 516 | + Some(30), | ||
| 517 | + "clearing the range falls back to the trim window" | ||
| 518 | + ); | ||
| 519 | + assert_eq!( | ||
| 520 | + loop_restart_frame(true, None, None), | ||
| 521 | + Some(0), | ||
| 522 | + "clearing both the range and the trim falls back to the whole timeline" | ||
| 523 | + ); | ||
| 491 | } | 524 | } |
| 492 | 525 | ||
| 493 | /// The bug this session fixed: a loop-trim window whose far edge (60) | 526 | /// The bug this session fixed: a loop-trim window whose far edge (60) |
| @@ -509,7 +542,7 @@ mod tests { | |||
| 509 | Transport::Ended, | 542 | Transport::Ended, |
| 510 | armed | 543 | armed |
| 511 | )); | 544 | )); |
| 512 | - assert_eq!(loop_restart_frame(loop_on, loop_trim), Some(30)); | 545 | + assert_eq!(loop_restart_frame(loop_on, None, loop_trim), Some(30)); |
| 513 | } | 546 | } |
| 514 | 547 | ||
| 515 | /// A loop window sitting entirely before the film's end never reaches | 548 | /// A loop window sitting entirely before the film's end never reaches |
crates/app/src/render.rsmodified+4 -4
| @@ -607,12 +607,12 @@ impl Render for Player { | |||
| 607 | // (`lane_row`), which gpui runs straight after this one: the | 607 | // (`lane_row`), which gpui runs straight after this one: the |
| 608 | // capture phase goes parent first, so a pointer over no lane at | 608 | // capture phase goes parent first, so a pointer over no lane at |
| 609 | // all -- up in the library, say -- promises nothing. | 609 | // all -- up in the library, say -- promises nothing. |
| 610 | - this.set_ghost(None, cx); | 610 | + this.set_ghost(Vec::new(), cx); |
| 611 | })) | 611 | })) |
| 612 | .on_drag_move( | 612 | .on_drag_move( |
| 613 | cx.listener(|this, event: &DragMoveEvent<AssetDrag>, _, cx| { | 613 | cx.listener(|this, event: &DragMoveEvent<AssetDrag>, _, cx| { |
| 614 | this.preview_place(event.event.position.x, cx); | 614 | this.preview_place(event.event.position.x, cx); |
| 615 | - this.set_ghost(None, cx); | 615 | + this.set_ghost(Vec::new(), cx); |
| 616 | }), | 616 | }), |
| 617 | ) | 617 | ) |
| 618 | // The same pair for the two subtitle gestures, for the same reason: | 618 | // The same pair for the two subtitle gestures, for the same reason: |
| @@ -620,7 +620,7 @@ impl Render for Player { | |||
| 620 | // lane, and both are let go somewhere else entirely. | 620 | // lane, and both are let go somewhere else entirely. |
| 621 | .on_drag_move(cx.listener(|this, event: &DragMoveEvent<SubPick>, _, cx| { | 621 | .on_drag_move(cx.listener(|this, event: &DragMoveEvent<SubPick>, _, cx| { |
| 622 | this.preview_place(event.event.position.x, cx); | 622 | this.preview_place(event.event.position.x, cx); |
| 623 | - this.set_ghost(None, cx); | 623 | + this.set_ghost(Vec::new(), cx); |
| 624 | })) | 624 | })) |
| 625 | .on_drag_move(cx.listener(|this, event: &DragMoveEvent<SubDrag>, _, cx| { | 625 | .on_drag_move(cx.listener(|this, event: &DragMoveEvent<SubDrag>, _, cx| { |
| 626 | // The placement gpui froze into the payload, whose *length* is | 626 | // The placement gpui froze into the payload, whose *length* is |
| @@ -629,7 +629,7 @@ impl Render for Player { | |||
| 629 | let (drag, x) = (*event.drag(cx), event.event.position.x); | 629 | let (drag, x) = (*event.drag(cx), event.event.position.x); |
| 630 | let cue = this.sub_drop_frame(drag.sub, x).1; | 630 | let cue = this.sub_drop_frame(drag.sub, x).1; |
| 631 | this.set_cue(cue, x, cx); | 631 | this.set_cue(cue, x, cx); |
| 632 | - this.set_ghost(None, cx); | 632 | + this.set_ghost(Vec::new(), cx); |
| 633 | })) | 633 | })) |
| 634 | // Scrubbing is tracked on the root because the pointer leaves the | 634 | // Scrubbing is tracked on the root because the pointer leaves the |
| 635 | // 6 px ruler on the first drag and its own listeners then stop | 635 | // 6 px ruler on the first drag and its own listeners then stop |
crates/app/src/tests/cards.rsmodified+70 -2
| @@ -3,6 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | use super::*; | 4 | use super::*; |
| 5 | use crate::audio_cards::EQ_GRAPH_MAX_H; | 5 | use crate::audio_cards::EQ_GRAPH_MAX_H; |
| 6 | +use crate::ui::inspector::transition_of; | ||
| 6 | use std::sync::atomic::Ordering; | 7 | use std::sync::atomic::Ordering; |
| 7 | 8 | ||
| 8 | /// FAULT 2's general shape (not just the source dot's menu): `overlaid()` | 9 | /// FAULT 2's general shape (not just the source dot's menu): `overlaid()` |
| @@ -186,8 +187,9 @@ fn only_a_chord_gets_out_of_an_export() { | |||
| 186 | assert!(!cancels_export("e", false, Some(ActionId::Export))); | 187 | assert!(!cancels_export("e", false, Some(ActionId::Export))); |
| 187 | assert!(!cancels_export("space", false, Some(ActionId::Play))); | 188 | assert!(!cancels_export("space", false, Some(ActionId::Play))); |
| 188 | assert!(!cancels_export("q", false, None)); | 189 | assert!(!cancels_export("q", false, None)); |
| 189 | - // The default keymap is what the handler feeds this: the chord reaches the | 190 | + // The default keymap is what the handler feeds this: the chord reaches |
| 190 | - // action, the bare key reaches nothing. | 191 | + // CancelExport, the bare key reaches Deselect instead -- neither of which |
| 192 | + // this guard lets cancel a running export. | ||
| 191 | let k = keymap::Keymap::defaults(); | 193 | let k = keymap::Keymap::defaults(); |
| 192 | assert!(cancels_export("escape", true, k.lookup("escape", true))); | 194 | assert!(cancels_export("escape", true, k.lookup("escape", true))); |
| 193 | assert!(!cancels_export("escape", false, k.lookup("escape", false))); | 195 | assert!(!cancels_export("escape", false, k.lookup("escape", false))); |
| @@ -1207,6 +1209,72 @@ fn a_typed_bitrate_is_a_field_and_not_a_key_capture() { | |||
| 1207 | assert!(detail.starts_with("6▏"), "{detail}"); | 1209 | assert!(detail.starts_with("6▏"), "{detail}"); |
| 1208 | } | 1210 | } |
| 1209 | 1211 | ||
| 1212 | +/// [`crate::ui::inspector::transition_of`]: the inspector's duration row | ||
| 1213 | +/// appears only for an anchor that actually carries a dissolve or a | ||
| 1214 | +/// crossfade, and the room it offers is capped at what the successor clip | ||
| 1215 | +/// actually has -- the same clamp [`engine::project::Project::set_transition_out`]/ | ||
| 1216 | +/// [`engine::project::Project::crossfade`] enforce, read back here without | ||
| 1217 | +/// either engine call so the row can never claim more than a step could land | ||
| 1218 | +/// in. | ||
| 1219 | +#[test] | ||
| 1220 | +fn a_duration_row_shows_only_for_a_transition_and_its_room_is_the_successors() { | ||
| 1221 | + // `len` is the clip's own source length (`out_frame`, `in_frame` fixed at | ||
| 1222 | + // 0, `speed` 1x, so `Clip::frames()` reads back exactly `len`). | ||
| 1223 | + fn clip(start: u32, len: u32, transition_out: u32, fade_in: u32, fade_out: u32) -> Clip { | ||
| 1224 | + Clip { | ||
| 1225 | + start, | ||
| 1226 | + in_frame: 0, | ||
| 1227 | + out_frame: len, | ||
| 1228 | + source: 0, | ||
| 1229 | + link: None, | ||
| 1230 | + eq: None, | ||
| 1231 | + color: None, | ||
| 1232 | + transform: None, | ||
| 1233 | + fit: FitPolicy::default(), | ||
| 1234 | + speed: Speed::NORMAL, | ||
| 1235 | + fade_in, | ||
| 1236 | + fade_out, | ||
| 1237 | + transition_out, | ||
| 1238 | + } | ||
| 1239 | + } | ||
| 1240 | + // A plain cut carries neither field, so the row has nothing to show. | ||
| 1241 | + let plain = clip(0, 10, 0, 0, 0); | ||
| 1242 | + let plain_next = clip(10, 15, 0, 0, 0); | ||
| 1243 | + assert_eq!(transition_of(LaneKind::Video, &plain, Some(&plain_next)), None); | ||
| 1244 | + | ||
| 1245 | + // A dissolve: video lane, `transition_out` set, an adjacent successor. | ||
| 1246 | + // The room offered is the shorter of the two -- here the successor's own | ||
| 1247 | + // 5-frame length, less than the anchor's 10. | ||
| 1248 | + let a = clip(0, 10, 4, 0, 0); | ||
| 1249 | + let b = clip(10, 5, 0, 0, 0); | ||
| 1250 | + assert_eq!( | ||
| 1251 | + transition_of(LaneKind::Video, &a, Some(&b)), | ||
| 1252 | + Some(("Dissolve", 4, 5)) | ||
| 1253 | + ); | ||
| 1254 | + // No successor, or a gap before one: no row, same as no transition. | ||
| 1255 | + assert_eq!(transition_of(LaneKind::Video, &a, None), None); | ||
| 1256 | + let gap = clip(11, 5, 0, 0, 0); | ||
| 1257 | + assert_eq!(transition_of(LaneKind::Video, &a, Some(&gap)), None); | ||
| 1258 | + | ||
| 1259 | + // A crossfade: audio lane, both ends of the join set | ||
| 1260 | + // ([`Project::crossfade`]'s own signature) -- a one-sided fade (the | ||
| 1261 | + // successor's `fade_in` still 0) is not one, and stays a plain fade. | ||
| 1262 | + let a = clip(0, 10, 0, 0, 3); | ||
| 1263 | + let b = clip(10, 2, 0, 3, 0); | ||
| 1264 | + assert_eq!( | ||
| 1265 | + transition_of(LaneKind::Audio, &a, Some(&b)), | ||
| 1266 | + Some(("Crossfade", 3, 2)), | ||
| 1267 | + "capped at the successor's own 2-frame length, though 3 was asked for" | ||
| 1268 | + ); | ||
| 1269 | + let one_sided = clip(10, 2, 0, 0, 0); | ||
| 1270 | + assert_eq!(transition_of(LaneKind::Audio, &a, Some(&one_sided)), None); | ||
| 1271 | + | ||
| 1272 | + // A dissolve field on an audio lane, or a fade-only pair on a video | ||
| 1273 | + // lane, name no transition either -- each kind reads only its own lane. | ||
| 1274 | + let dissolving = clip(0, 10, 4, 0, 0); | ||
| 1275 | + assert_eq!(transition_of(LaneKind::Audio, &dissolving, Some(&b)), None); | ||
| 1276 | +} | ||
| 1277 | + | ||
| 1210 | #[test] | 1278 | #[test] |
| 1211 | fn a_clip_with_no_sound_is_refused_in_the_same_words_whichever_kind_it_is() { | 1279 | fn a_clip_with_no_sound_is_refused_in_the_same_words_whichever_kind_it_is() { |
| 1212 | // A still and a video with no audio track are one answer to one | 1280 | // A still and a video with no audio track are one answer to one |
crates/app/src/tests/editing.rsmodified+335 -6
| @@ -1688,19 +1688,35 @@ fn a_copied_clip_is_renumbered_or_dropped_when_a_row_leaves_the_library() { | |||
| 1688 | }; | 1688 | }; |
| 1689 | // Copied from source 2, source 0 removed: the same file is source 1 now. | 1689 | // Copied from source 2, source 0 removed: the same file is source 1 now. |
| 1690 | assert_eq!( | 1690 | assert_eq!( |
| 1691 | - clipboard_after_remove(Some(clip(2)), 0).map(|c| c.source), | 1691 | + clipboard_after_remove(vec![(Lane::V1, clip(2))], 0) |
| 1692 | - Some(1), | 1692 | + .into_iter() |
| 1693 | + .map(|(_, c)| c.source) | ||
| 1694 | + .collect::<Vec<_>>(), | ||
| 1695 | + vec![1], | ||
| 1693 | "the clipboard follows its file down the list" | 1696 | "the clipboard follows its file down the list" |
| 1694 | ); | 1697 | ); |
| 1695 | // Copied from a source *before* the one that went: untouched. | 1698 | // Copied from a source *before* the one that went: untouched. |
| 1696 | assert_eq!( | 1699 | assert_eq!( |
| 1697 | - clipboard_after_remove(Some(clip(0)), 2).map(|c| c.source), | 1700 | + clipboard_after_remove(vec![(Lane::V1, clip(0))], 2) |
| 1698 | - Some(0) | 1701 | + .into_iter() |
| 1702 | + .map(|(_, c)| c.source) | ||
| 1703 | + .collect::<Vec<_>>(), | ||
| 1704 | + vec![0] | ||
| 1699 | ); | 1705 | ); |
| 1700 | // Copied from the row that was just removed: there is nothing left to | 1706 | // Copied from the row that was just removed: there is nothing left to |
| 1701 | // paste, and pasting the next file along would be a lie. | 1707 | // paste, and pasting the next file along would be a lie. |
| 1702 | - assert!(clipboard_after_remove(Some(clip(1)), 1).is_none()); | 1708 | + assert!(clipboard_after_remove(vec![(Lane::V1, clip(1))], 1).is_empty()); |
| 1703 | - assert!(clipboard_after_remove(None, 0).is_none()); | 1709 | + assert!(clipboard_after_remove(Vec::new(), 0).is_empty()); |
| 1710 | + // A set with one member's file gone loses only that member -- the rest | ||
| 1711 | + // of the set survives to be pasted, gaps and lanes intact. | ||
| 1712 | + let trimmed = clipboard_after_remove( | ||
| 1713 | + vec![(Lane::V1, clip(1)), (Lane::A1, clip(2))], | ||
| 1714 | + 1, | ||
| 1715 | + ); | ||
| 1716 | + assert_eq!( | ||
| 1717 | + trimmed.into_iter().map(|(_, c)| c.source).collect::<Vec<_>>(), | ||
| 1718 | + vec![1] | ||
| 1719 | + ); | ||
| 1704 | } | 1720 | } |
| 1705 | 1721 | ||
| 1706 | /// The trim-a-clip path through the doors the edge drag uses: | 1722 | /// The trim-a-clip path through the doors the edge drag uses: |
| @@ -1900,6 +1916,259 @@ fn a_track_can_be_added_dropped_on_edited_and_taken_back() { | |||
| 1900 | assert_eq!(format_refusal(&session, Format::Mp4), None); | 1916 | assert_eq!(format_refusal(&session, Format::Mp4), None); |
| 1901 | } | 1917 | } |
| 1902 | 1918 | ||
| 1919 | +/// [`PlaybackSession::move_selection_to`], the door a selection drag uses | ||
| 1920 | +/// ([`Player::move_clip`]'s set path): three picks across two lanes, one of | ||
| 1921 | +/// them the dragged clip, all travel the *same* frame delta in one call -- | ||
| 1922 | +/// the same all-or-nothing clamp [`Project::move_room`] already gave a | ||
| 1923 | +/// linked group, generalised to an arbitrary selection. | ||
| 1924 | +#[test] | ||
| 1925 | +fn a_selection_drag_moves_every_pick_by_the_same_delta() { | ||
| 1926 | + use engine::project::LaneKind; | ||
| 1927 | + | ||
| 1928 | + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | ||
| 1929 | + session.set_gain(0.0); | ||
| 1930 | + let path = session.sources()[0].path.clone(); | ||
| 1931 | + session.import(&asset("test_av2.mp4")).expect("av2 matches"); | ||
| 1932 | + let second = session.sources()[1].path.clone(); | ||
| 1933 | + | ||
| 1934 | + // clip0 on V1 at the fixture's own start; clip1 on V1 ten seconds in, | ||
| 1935 | + // appended to the open bed and rippling nothing. | ||
| 1936 | + assert!(session | ||
| 1937 | + .place_stream_at(10.0, &second, 0, None) | ||
| 1938 | + .expect("av2 is on this timeline")); | ||
| 1939 | + let clip0 = session.lane_clips(Lane::V1)[0]; | ||
| 1940 | + let clip1 = session.lane_clips(Lane::V1)[1]; | ||
| 1941 | + assert_eq!((clip0.start, clip1.start), (0, 300)); | ||
| 1942 | + | ||
| 1943 | + // clipC on a second video row, well past both of the above. | ||
| 1944 | + let v2 = session.add_lane(LaneKind::Video); | ||
| 1945 | + assert!(session | ||
| 1946 | + .place_stream_at(20.0, &path, 0, Some(v2)) | ||
| 1947 | + .expect("test_av.mp4 is on this timeline")); | ||
| 1948 | + let clip_c = session.lane_clips(v2)[0]; | ||
| 1949 | + assert_eq!(clip_c.start, 600); | ||
| 1950 | + | ||
| 1951 | + let picks = [(Lane::V1, 0), (Lane::V1, 1), (v2, 0)]; | ||
| 1952 | + // Drag clip1 fifty frames along its own lane -- the other two picks own | ||
| 1953 | + // no neighbours of their own here, so nothing narrows the room and the | ||
| 1954 | + // full fifty-frame ask goes through for all three. | ||
| 1955 | + assert!(session.move_selection_to(&picks, Lane::V1, 1, Lane::V1, clip1.start + 50)); | ||
| 1956 | + assert_eq!(session.lane_clips(Lane::V1)[0].start, clip0.start + 50); | ||
| 1957 | + assert_eq!(session.lane_clips(Lane::V1)[1].start, clip1.start + 50); | ||
| 1958 | + assert_eq!(session.lane_clips(v2)[0].start, clip_c.start + 50); | ||
| 1959 | + // Every pick still names the clip it named: found again by the frame it | ||
| 1960 | + // now starts at -- exactly the lookup `Player::remap_selection` makes | ||
| 1961 | + // once the move lands, which is what keeps a set-move's selection alive | ||
| 1962 | + // rather than clearing it. | ||
| 1963 | + assert_eq!( | ||
| 1964 | + session.lane_clips(Lane::V1)[0], | ||
| 1965 | + Clip { start: clip0.start + 50, ..clip0 } | ||
| 1966 | + ); | ||
| 1967 | + assert_eq!( | ||
| 1968 | + session.lane_clips(v2)[0], | ||
| 1969 | + Clip { start: clip_c.start + 50, ..clip_c } | ||
| 1970 | + ); | ||
| 1971 | + | ||
| 1972 | + assert!(session.undo(), "one step for the whole set-move"); | ||
| 1973 | + assert_eq!(session.lane_clips(Lane::V1)[0].start, clip0.start); | ||
| 1974 | + assert_eq!(session.lane_clips(Lane::V1)[1].start, clip1.start); | ||
| 1975 | + assert_eq!(session.lane_clips(v2)[0].start, clip_c.start); | ||
| 1976 | +} | ||
| 1977 | + | ||
| 1978 | +/// One pick with nowhere to go refuses the whole set: the walk onto another | ||
| 1979 | +/// clip's own span that already refuses a lone drag | ||
| 1980 | +/// (`move_clip_keeps_the_frames_and_refuses_the_rest`, in this crate's own | ||
| 1981 | +/// engine tests) refuses a selection drag exactly the same way, and every | ||
| 1982 | +/// *other* pick -- which had all the room in the world -- stays exactly | ||
| 1983 | +/// where it was rather than moving on its own. | ||
| 1984 | +#[test] | ||
| 1985 | +fn a_selection_drag_refuses_as_one_set_when_any_pick_cannot_land() { | ||
| 1986 | + use engine::project::LaneKind; | ||
| 1987 | + | ||
| 1988 | + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | ||
| 1989 | + session.set_gain(0.0); | ||
| 1990 | + let path = session.sources()[0].path.clone(); | ||
| 1991 | + session.import(&asset("test_av2.mp4")).expect("av2 matches"); | ||
| 1992 | + let second = session.sources()[1].path.clone(); | ||
| 1993 | + | ||
| 1994 | + assert!(session | ||
| 1995 | + .place_stream_at(10.0, &second, 0, None) | ||
| 1996 | + .expect("av2 is on this timeline")); | ||
| 1997 | + let clip0 = session.lane_clips(Lane::V1)[0]; | ||
| 1998 | + let clip1 = session.lane_clips(Lane::V1)[1]; | ||
| 1999 | + | ||
| 2000 | + let v2 = session.add_lane(LaneKind::Video); | ||
| 2001 | + assert!(session | ||
| 2002 | + .place_stream_at(0.0, &path, 0, Some(v2)) | ||
| 2003 | + .expect("test_av.mp4 is on this timeline")); | ||
| 2004 | + let clip_c = session.lane_clips(v2)[0]; | ||
| 2005 | + // A clip clip1 is not picked, blocking the road on V2 the drag is about | ||
| 2006 | + // to try: clip1 dragged onto V2 lands its head inside this one. | ||
| 2007 | + assert!(session | ||
| 2008 | + .place_stream_at(10.0, &second, 0, Some(v2)) | ||
| 2009 | + .expect("av2 is on this timeline")); | ||
| 2010 | + let blocker = session.lane_clips(v2)[1]; | ||
| 2011 | + assert_eq!(blocker.start, 300); | ||
| 2012 | + | ||
| 2013 | + let picks = [(Lane::V1, 0), (Lane::V1, 1), (v2, 0)]; | ||
| 2014 | + // Dragged onto V2 at a frame inside the blocker: refused outright, the | ||
| 2015 | + // way a lone drag onto another clip already is. | ||
| 2016 | + assert!(!session.move_selection_to( | ||
| 2017 | + &picks, | ||
| 2018 | + Lane::V1, | ||
| 2019 | + 1, | ||
| 2020 | + v2, | ||
| 2021 | + blocker.start + 10 | ||
| 2022 | + )); | ||
| 2023 | + // Nothing moved -- not clip1 clamped short of the blocker, and not the | ||
| 2024 | + // two picks that had all the room to spare. | ||
| 2025 | + assert_eq!(session.lane_clips(Lane::V1)[0], clip0); | ||
| 2026 | + assert_eq!(session.lane_clips(Lane::V1)[1], clip1); | ||
| 2027 | + assert_eq!(session.lane_clips(v2)[0], clip_c); | ||
| 2028 | + assert_eq!(session.lane_clips(v2)[1], blocker); | ||
| 2029 | +} | ||
| 2030 | + | ||
| 2031 | +/// A plain click's copy is one clipboard entry, and one entry still takes | ||
| 2032 | +/// [`PlaybackSession::paste_at`] -- the door it always has, unchanged by a | ||
| 2033 | +/// set ever being able to ride [`PlaybackSession::paste_set_at`] instead. | ||
| 2034 | +#[test] | ||
| 2035 | +fn a_single_pick_copy_paste_round_trips_unchanged() { | ||
| 2036 | + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | ||
| 2037 | + session.set_gain(0.0); | ||
| 2038 | + // `open` seeds V1 with the whole fixture as its own clip -- what a plain | ||
| 2039 | + // click would copy. | ||
| 2040 | + let copied = session.lane_clips(Lane::V1)[0]; | ||
| 2041 | + | ||
| 2042 | + let at = session.timeline_duration(); | ||
| 2043 | + assert!(session.paste_at(at, copied), "a free spot always takes it"); | ||
| 2044 | + let pasted = session.lane_clips(Lane::V1)[1]; | ||
| 2045 | + assert_eq!( | ||
| 2046 | + (pasted.source, pasted.in_frame, pasted.out_frame), | ||
| 2047 | + (copied.source, copied.in_frame, copied.out_frame), | ||
| 2048 | + "the pasted clip plays the same source frames the copy did" | ||
| 2049 | + ); | ||
| 2050 | + | ||
| 2051 | + assert!(session.undo(), "one step for the paste"); | ||
| 2052 | + assert_eq!(session.lane_clips(Lane::V1).len(), 1); | ||
| 2053 | +} | ||
| 2054 | + | ||
| 2055 | +/// [`PlaybackSession::paste_set_at`], the set-copy's own door | ||
| 2056 | +/// ([`Player::paste`]'s multi-entry path): three picks across two lanes, some | ||
| 2057 | +/// distance apart, keep that same distance and the same lane each landed on | ||
| 2058 | +/// -- the offset [`Project::paste_set`] moves every item by is the one from | ||
| 2059 | +/// the earliest pick to `at`, not a collapse onto `V1`/`A1`. | ||
| 2060 | +#[test] | ||
| 2061 | +fn a_three_pick_copy_paste_preserves_gaps_and_lane_assignment() { | ||
| 2062 | + use engine::project::LaneKind; | ||
| 2063 | + | ||
| 2064 | + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | ||
| 2065 | + session.set_gain(0.0); | ||
| 2066 | + let path = session.sources()[0].path.clone(); | ||
| 2067 | + session.import(&asset("test_av2.mp4")).expect("av2 matches"); | ||
| 2068 | + let second = session.sources()[1].path.clone(); | ||
| 2069 | + | ||
| 2070 | + assert!(session | ||
| 2071 | + .place_stream_at(10.0, &second, 0, None) | ||
| 2072 | + .expect("av2 is on this timeline")); | ||
| 2073 | + let clip0 = session.lane_clips(Lane::V1)[0]; | ||
| 2074 | + let clip1 = session.lane_clips(Lane::V1)[1]; | ||
| 2075 | + | ||
| 2076 | + let v2 = session.add_lane(LaneKind::Video); | ||
| 2077 | + assert!(session | ||
| 2078 | + .place_stream_at(20.0, &path, 0, Some(v2)) | ||
| 2079 | + .expect("test_av.mp4 is on this timeline")); | ||
| 2080 | + let clip_c = session.lane_clips(v2)[0]; | ||
| 2081 | + | ||
| 2082 | + // Copied in click order, out of the lanes each was clicked in -- exactly | ||
| 2083 | + // what `Player::copy_selected` builds. | ||
| 2084 | + let items = [(Lane::V1, clip0), (Lane::V1, clip1), (v2, clip_c)]; | ||
| 2085 | + let at = session.timeline_duration(); | ||
| 2086 | + assert!(session.paste_set_at(at, &items), "a free spot takes the set"); | ||
| 2087 | + | ||
| 2088 | + let new0 = session.lane_clips(Lane::V1)[2]; | ||
| 2089 | + let new1 = session.lane_clips(Lane::V1)[3]; | ||
| 2090 | + let new_c = session.lane_clips(v2)[1]; | ||
| 2091 | + // The gaps between picks survive the trip untouched. | ||
| 2092 | + assert_eq!(new1.start - new0.start, clip1.start - clip0.start); | ||
| 2093 | + assert_eq!(new_c.start - new0.start, clip_c.start - clip0.start); | ||
| 2094 | + // And each still plays the source frames it was copied with, off the | ||
| 2095 | + // lane it was copied off of. | ||
| 2096 | + assert_eq!( | ||
| 2097 | + (new0.source, new0.in_frame, new0.out_frame), | ||
| 2098 | + (clip0.source, clip0.in_frame, clip0.out_frame) | ||
| 2099 | + ); | ||
| 2100 | + assert_eq!( | ||
| 2101 | + (new_c.source, new_c.in_frame, new_c.out_frame), | ||
| 2102 | + (clip_c.source, clip_c.in_frame, clip_c.out_frame) | ||
| 2103 | + ); | ||
| 2104 | + | ||
| 2105 | + assert!(session.undo(), "one step for the whole set-paste"); | ||
| 2106 | + assert_eq!(session.lane_clips(Lane::V1).len(), 2); | ||
| 2107 | + assert_eq!(session.lane_clips(v2).len(), 1); | ||
| 2108 | +} | ||
| 2109 | + | ||
| 2110 | +/// A set-paste never ripples the bed: a landing that would overlap so much | ||
| 2111 | +/// as one existing clip on its own lane refuses the *whole* set, exactly as | ||
| 2112 | +/// [`Project::paste_set`] documents, leaving the project as it was rather | ||
| 2113 | +/// than placing the picks that had room to spare. | ||
| 2114 | +#[test] | ||
| 2115 | +fn a_colliding_set_paste_refuses_whole() { | ||
| 2116 | + use engine::project::LaneKind; | ||
| 2117 | + | ||
| 2118 | + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | ||
| 2119 | + session.set_gain(0.0); | ||
| 2120 | + let path = session.sources()[0].path.clone(); | ||
| 2121 | + session.import(&asset("test_av2.mp4")).expect("av2 matches"); | ||
| 2122 | + let second = session.sources()[1].path.clone(); | ||
| 2123 | + | ||
| 2124 | + assert!(session | ||
| 2125 | + .place_stream_at(10.0, &second, 0, None) | ||
| 2126 | + .expect("av2 is on this timeline")); | ||
| 2127 | + let clip0 = session.lane_clips(Lane::V1)[0]; | ||
| 2128 | + let clip1 = session.lane_clips(Lane::V1)[1]; | ||
| 2129 | + | ||
| 2130 | + let v2 = session.add_lane(LaneKind::Video); | ||
| 2131 | + assert!(session | ||
| 2132 | + .place_stream_at(20.0, &path, 0, Some(v2)) | ||
| 2133 | + .expect("test_av.mp4 is on this timeline")); | ||
| 2134 | + let clip_c = session.lane_clips(v2)[0]; | ||
| 2135 | + | ||
| 2136 | + let items = [(Lane::V1, clip0), (Lane::V1, clip1), (v2, clip_c)]; | ||
| 2137 | + // A blocker sat right where the V1 half of the set would land: pasting | ||
| 2138 | + // at the timeline's own start walks every item straight back onto the | ||
| 2139 | + // lanes it was copied off of, colliding with everything already there. | ||
| 2140 | + assert!(!session.paste_set_at(0.0, &items)); | ||
| 2141 | + | ||
| 2142 | + assert_eq!(session.lane_clips(Lane::V1)[0], clip0); | ||
| 2143 | + assert_eq!(session.lane_clips(Lane::V1)[1], clip1); | ||
| 2144 | + assert_eq!(session.lane_clips(v2)[0], clip_c); | ||
| 2145 | + assert_eq!(session.lane_clips(Lane::V1).len(), 2); | ||
| 2146 | + assert_eq!(session.lane_clips(v2).len(), 1); | ||
| 2147 | +} | ||
| 2148 | + | ||
| 2149 | +/// The refactor `move_clip` -> `move_selection` owes: a clip dragged from | ||
| 2150 | +/// outside the selection (or with nothing else selected) moves exactly as it | ||
| 2151 | +/// always has -- `move_clip_to`'s own door and `move_selection_to`'s | ||
| 2152 | +/// selection-of-one both walk the same code, so they cannot drift apart. | ||
| 2153 | +#[test] | ||
| 2154 | +fn a_lone_clip_drag_is_unchanged_by_the_selection_path() { | ||
| 2155 | + use engine::project::LaneKind; | ||
| 2156 | + | ||
| 2157 | + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | ||
| 2158 | + session.set_gain(0.0); | ||
| 2159 | + let v2 = session.add_lane(LaneKind::Video); | ||
| 2160 | + | ||
| 2161 | + assert!(session.move_clip_to(Lane::V1, 0, v2, 0), "V1 -> V2"); | ||
| 2162 | + assert!(session.lane_clips(Lane::V1).is_empty()); | ||
| 2163 | + assert_eq!(session.lane_clips(v2).len(), 1); | ||
| 2164 | + | ||
| 2165 | + // The other kind of lane is refused exactly as before. | ||
| 2166 | + assert!(!session.move_clip_to(v2, 0, Lane::A1, 0)); | ||
| 2167 | + // A drop back where it was picked up is a click, still refused. | ||
| 2168 | + let clip = session.lane_clips(v2)[0]; | ||
| 2169 | + assert!(!session.move_clip_to(v2, 0, v2, clip.start)); | ||
| 2170 | +} | ||
| 2171 | + | ||
| 1903 | /// A caption grouped with a clip on an *added* lane closes its lane's hole | 2172 | /// A caption grouped with a clip on an *added* lane closes its lane's hole |
| 1904 | /// too, not just the first pair's: the same law commit `cdc53a6` gave `V1` | 2173 | /// too, not just the first pair's: the same law commit `cdc53a6` gave `V1` |
| 1905 | /// (`whole_take` -> `Project::delete_members`) has to hold from every anchor | 2174 | /// (`whole_take` -> `Project::delete_members`) has to hold from every anchor |
| @@ -2182,3 +2451,63 @@ fn should_loop_restart_is_play_state_blind_the_pump_gates_it() { | |||
| 2182 | into-it -- that distinction is pump's is_playing() guard, not this" | 2451 | into-it -- that distinction is pump's is_playing() guard, not this" |
| 2183 | ); | 2452 | ); |
| 2184 | } | 2453 | } |
| 2454 | + | ||
| 2455 | +/// This binary has no `TestAppContext` to press a live escape through, so the | ||
| 2456 | +/// guard reads the ordering `render.rs`'s key listener actually runs: every | ||
| 2457 | +/// card/menu/list close returns before the fallthrough that dispatches | ||
| 2458 | +/// `ActionId::Deselect` ever runs, so escape with one of them open closes it | ||
| 2459 | +/// and never touches `self.selected` -- the picks made before the card opened | ||
| 2460 | +/// are still there once it is gone. | ||
| 2461 | +#[test] | ||
| 2462 | +fn escape_closes_a_card_before_it_can_ever_reach_deselect() { | ||
| 2463 | + let render_rs = src_text("render.rs"); | ||
| 2464 | + let dispatch = render_rs | ||
| 2465 | + .find("if let Some(action) = action {") | ||
| 2466 | + .expect("the keymap fallthrough that fires Deselect"); | ||
| 2467 | + for (guard, label) in [ | ||
| 2468 | + ("if this.keys_open {", "the keys overlay"), | ||
| 2469 | + ("if this.dock_filter_edit {", "the dock filter"), | ||
| 2470 | + ( | ||
| 2471 | + "if this.param_card_key(key, event.keystroke.modifiers.shift, cx) {", | ||
| 2472 | + "a param card", | ||
| 2473 | + ), | ||
| 2474 | + ( | ||
| 2475 | + "if escape_leaves_player_fullscreen(key, ctrl, this.player_fullscreen) {", | ||
| 2476 | + "player fullscreen", | ||
| 2477 | + ), | ||
| 2478 | + ("let clip_menu = this.context_menu.take().is_some();", "the clip/row menu or a list"), | ||
| 2479 | + ( | ||
| 2480 | + "if key == ESCAPE && !ctrl && this.preview_session.is_some() {", | ||
| 2481 | + "an open preview", | ||
| 2482 | + ), | ||
| 2483 | + ] { | ||
| 2484 | + let at = render_rs | ||
| 2485 | + .find(guard) | ||
| 2486 | + .unwrap_or_else(|| panic!("{label}'s own escape guard moved or was renamed")); | ||
| 2487 | + assert!( | ||
| 2488 | + at < dispatch, | ||
| 2489 | + "{label}'s guard reads after the Deselect dispatch -- escape would \ | ||
| 2490 | + clear the selection before this card ever got a look at the key" | ||
| 2491 | + ); | ||
| 2492 | + } | ||
| 2493 | +} | ||
| 2494 | + | ||
| 2495 | +/// The other half: with nothing on screen to claim the key, bare escape falls | ||
| 2496 | +/// all the way through to `Player::act`, whose `ActionId::Deselect` arm is | ||
| 2497 | +/// the one place `self.selected` is emptied by a bare stroke rather than by | ||
| 2498 | +/// picking something else. | ||
| 2499 | +#[test] | ||
| 2500 | +fn escape_with_nothing_open_empties_the_selection() { | ||
| 2501 | + let actions_rs = src_text("player/actions.rs"); | ||
| 2502 | + assert!( | ||
| 2503 | + actions_rs.contains("ActionId::Deselect => {") | ||
| 2504 | + && actions_rs.contains("self.selected = Selection::new();"), | ||
| 2505 | + "the Deselect arm no longer clears self.selected" | ||
| 2506 | + ); | ||
| 2507 | + let k = keymap::Keymap::defaults(); | ||
| 2508 | + assert_eq!( | ||
| 2509 | + k.lookup("escape", false), | ||
| 2510 | + Some(ActionId::Deselect), | ||
| 2511 | + "bare escape must still route to Deselect for that arm to ever run" | ||
| 2512 | + ); | ||
| 2513 | +} | ||
crates/app/src/tests/layout.rsmodified+48 -12
| @@ -2135,22 +2135,48 @@ fn the_notice_plate_declares_a_bounded_wrapping_text_layout() { | |||
| 2135 | } | 2135 | } |
| 2136 | 2136 | ||
| 2137 | /// A round trip through the file: what is saved is what the next load reads | 2137 | /// A round trip through the file: what is saved is what the next load reads |
| 2138 | -/// back, one seam touched and the other left at its default -- a scratch | 2138 | +/// back, all five seams touched -- a scratch path, not the real config, the |
| 2139 | -/// path, not the real config, the same isolation `keymap::tests`' own | 2139 | +/// same isolation `keymap::tests`' own `load_from`/`save_to` already takes. |
| 2140 | -/// `load_from`/`save_to` already takes. | 2140 | +/// One of the five is written past its own ceiling (the library, past |
| 2141 | +/// `SIDE_MAX_FRAC` of the window it is loaded back into): a file written at | ||
| 2142 | +/// a wider window must not hand a narrower one an illegal layout, so the | ||
| 2143 | +/// load clamps it back down rather than reading it verbatim. | ||
| 2141 | #[test] | 2144 | #[test] |
| 2142 | fn a_saved_seam_survives_a_reload() { | 2145 | fn a_saved_seam_survives_a_reload() { |
| 2143 | - use crate::{Split, Splits, load_stance_splits_from, save_stance_splits_to}; | 2146 | + use crate::{ |
| 2147 | + BENCH_MIN_H, SIDE_MAX_FRAC, Split, Splits, load_stance_splits_from, save_stance_splits_to, | ||
| 2148 | + }; | ||
| 2149 | + use gpui::{Pixels, Size, px, size}; | ||
| 2144 | 2150 | ||
| 2145 | let dir = engine::scratch::Scratch::dir("edith-stance-splits"); | 2151 | let dir = engine::scratch::Scratch::dir("edith-stance-splits"); |
| 2146 | let path = dir.join("stance-splits"); | 2152 | let path = dir.join("stance-splits"); |
| 2153 | + let window: Size<Pixels> = size(px(1280.), px(720.)); | ||
| 2147 | 2154 | ||
| 2148 | let mut splits = Splits::default(); | 2155 | let mut splits = Splits::default(); |
| 2156 | + splits.set(Split::Library, 9000.); | ||
| 2157 | + splits.set(Split::Inspector, 200.); | ||
| 2158 | + splits.set(Split::Timeline, 250.); | ||
| 2149 | splits.set(Split::Dock, 333.); | 2159 | splits.set(Split::Dock, 333.); |
| 2160 | + splits.set(Split::Bench, 200.); | ||
| 2150 | save_stance_splits_to(&splits, &path); | 2161 | save_stance_splits_to(&splits, &path); |
| 2151 | - let loaded = load_stance_splits_from(&path); | 2162 | + let loaded = load_stance_splits_from(&path, window); |
| 2163 | + assert_eq!( | ||
| 2164 | + loaded.get(Split::Library), | ||
| 2165 | + Some(1280. * SIDE_MAX_FRAC), | ||
| 2166 | + "a library past its own ceiling should clamp to it on load" | ||
| 2167 | + ); | ||
| 2168 | + assert_eq!(loaded.get(Split::Inspector), Some(200.)); | ||
| 2169 | + assert_eq!(loaded.get(Split::Timeline), Some(250.)); | ||
| 2152 | assert_eq!(loaded.get(Split::Dock), Some(333.)); | 2170 | assert_eq!(loaded.get(Split::Dock), Some(333.)); |
| 2153 | - assert_eq!(loaded.get(Split::Bench), None); | 2171 | + assert_eq!(loaded.get(Split::Bench), Some(200.)); |
| 2172 | + | ||
| 2173 | + // A bench saved below its own floor clamps up to it, the same ceiling | ||
| 2174 | + // logic mirrored on the one seam whose bound is a minimum. | ||
| 2175 | + let mut low_bench = Splits::default(); | ||
| 2176 | + low_bench.set(Split::Bench, 1.); | ||
| 2177 | + save_stance_splits_to(&low_bench, &path); | ||
| 2178 | + let loaded = load_stance_splits_from(&path, window); | ||
| 2179 | + assert_eq!(loaded.get(Split::Bench), Some(BENCH_MIN_H)); | ||
| 2154 | } | 2180 | } |
| 2155 | 2181 | ||
| 2156 | /// The guard [`crate::split_drag_owes_save`] runs at the moment a drag ends | 2182 | /// The guard [`crate::split_drag_owes_save`] runs at the moment a drag ends |
| @@ -2158,18 +2184,18 @@ fn a_saved_seam_survives_a_reload() { | |||
| 2158 | /// wired to a live `MouseExitEvent` a `TestAppContext`-less test binary | 2184 | /// wired to a live `MouseExitEvent` a `TestAppContext`-less test binary |
| 2159 | /// cannot raise -- see `tests/media.rs`'s own note on the same limit, and | 2185 | /// cannot raise -- see `tests/media.rs`'s own note on the same limit, and |
| 2160 | /// the harness drive `D2` in this session's report for the wiring itself). | 2186 | /// the harness drive `D2` in this session's report for the wiring itself). |
| 2161 | -/// What *is* checkable here without a window: exactly the two persisted | 2187 | +/// What *is* checkable here without a window: exactly the persisted |
| 2162 | /// seams owe that save, the same set `Split::PERSISTED` already names, and a | 2188 | /// seams owe that save, the same set `Split::PERSISTED` already names, and a |
| 2163 | /// drag that never started (`None`) owes nothing. | 2189 | /// drag that never started (`None`) owes nothing. |
| 2164 | #[test] | 2190 | #[test] |
| 2165 | -fn only_the_two_persisted_seams_owe_a_save_when_a_drag_loses_the_window() { | 2191 | +fn only_the_persisted_seams_owe_a_save_when_a_drag_loses_the_window() { |
| 2166 | use crate::{Split, player::timeline_edit::split_drag_owes_save}; | 2192 | use crate::{Split, player::timeline_edit::split_drag_owes_save}; |
| 2167 | 2193 | ||
| 2168 | assert!(split_drag_owes_save(Some(Split::Dock))); | 2194 | assert!(split_drag_owes_save(Some(Split::Dock))); |
| 2169 | assert!(split_drag_owes_save(Some(Split::Bench))); | 2195 | assert!(split_drag_owes_save(Some(Split::Bench))); |
| 2170 | - assert!(!split_drag_owes_save(Some(Split::Library))); | 2196 | + assert!(split_drag_owes_save(Some(Split::Library))); |
| 2171 | - assert!(!split_drag_owes_save(Some(Split::Inspector))); | 2197 | + assert!(split_drag_owes_save(Some(Split::Inspector))); |
| 2172 | - assert!(!split_drag_owes_save(Some(Split::Timeline))); | 2198 | + assert!(split_drag_owes_save(Some(Split::Timeline))); |
| 2173 | assert!(!split_drag_owes_save(None)); | 2199 | assert!(!split_drag_owes_save(None)); |
| 2174 | } | 2200 | } |
| 2175 | 2201 | ||
| @@ -2178,9 +2204,14 @@ fn only_the_two_persisted_seams_owe_a_save_when_a_drag_loses_the_window() { | |||
| 2178 | #[test] | 2204 | #[test] |
| 2179 | fn a_missing_stance_splits_file_leaves_every_region_at_its_default() { | 2205 | fn a_missing_stance_splits_file_leaves_every_region_at_its_default() { |
| 2180 | use crate::{Split, load_stance_splits_from}; | 2206 | use crate::{Split, load_stance_splits_from}; |
| 2207 | + use gpui::{Pixels, Size, px, size}; | ||
| 2181 | 2208 | ||
| 2182 | let dir = engine::scratch::Scratch::dir("edith-stance-splits-missing"); | 2209 | let dir = engine::scratch::Scratch::dir("edith-stance-splits-missing"); |
| 2183 | - let splits = load_stance_splits_from(&dir.join("nothing-here")); | 2210 | + let window: Size<Pixels> = size(px(1280.), px(720.)); |
| 2211 | + let splits = load_stance_splits_from(&dir.join("nothing-here"), window); | ||
| 2212 | + assert_eq!(splits.get(Split::Library), None); | ||
| 2213 | + assert_eq!(splits.get(Split::Inspector), None); | ||
| 2214 | + assert_eq!(splits.get(Split::Timeline), None); | ||
| 2184 | assert_eq!(splits.get(Split::Dock), None); | 2215 | assert_eq!(splits.get(Split::Dock), None); |
| 2185 | assert_eq!(splits.get(Split::Bench), None); | 2216 | assert_eq!(splits.get(Split::Bench), None); |
| 2186 | } | 2217 | } |
| @@ -2639,6 +2670,11 @@ fn every_action_has_a_darkroom_widget_home_or_explicit_owner() { | |||
| 2639 | clicks, so a click-through door for \"move keyboard focus\" \ | 2670 | clicks, so a click-through door for \"move keyboard focus\" \ |
| 2640 | has nothing to do that a click has not already done", | 2671 | has nothing to do that a click has not already done", |
| 2641 | ), | 2672 | ), |
| 2673 | + ( | ||
| 2674 | + ActionId::Deselect, | ||
| 2675 | + "clicking empty timeline space already clears the selection with the mouse; \ | ||
| 2676 | + bare escape is a keyboard-only accelerator for that existing door, not a new one", | ||
| 2677 | + ), | ||
| 2642 | ]; | 2678 | ]; |
| 2643 | let darkroom = [ | 2679 | let darkroom = [ |
| 2644 | "ui/bench_stance.rs", | 2680 | "ui/bench_stance.rs", |
crates/app/src/timeline_math.rsmodified+30 -8
| @@ -362,15 +362,37 @@ pub(crate) fn should_loop_restart(frame: u32, window: Option<(u32, u32)>) -> boo | |||
| 362 | window.is_some_and(|(_, hi)| frame >= hi) | 362 | window.is_some_and(|(_, hi)| frame >= hi) |
| 363 | } | 363 | } |
| 364 | 364 | ||
| 365 | +/// Which window is actually looping, in priority order: the i/o range | ||
| 366 | +/// ([`Player::range`]) beats the subject-cut trim ([`Player::loop_trim`]) | ||
| 367 | +/// beats the whole timeline -- but only once *something* is already armed | ||
| 368 | +/// (`loop_on` or `loop_trim`). A bare in/out mark with neither on is an | ||
| 369 | +/// export mark first, not a loop request, so it answers `None` here and | ||
| 370 | +/// never restarts anything on its own. | ||
| 371 | +pub(crate) fn active_loop_window( | ||
| 372 | + loop_on: bool, | ||
| 373 | + range: Option<(u32, u32)>, | ||
| 374 | + loop_trim: Option<(u32, u32)>, | ||
| 375 | +) -> Option<(u32, u32)> { | ||
| 376 | + if !loop_on && loop_trim.is_none() { | ||
| 377 | + return None; | ||
| 378 | + } | ||
| 379 | + range.or(loop_trim) | ||
| 380 | +} | ||
| 381 | + | ||
| 365 | /// Where a play resumes from on crossing into [`Transport::Ended`] | 382 | /// Where a play resumes from on crossing into [`Transport::Ended`] |
| 366 | -/// (`Player::pump`): the loop-trim window's own near edge when one is armed, | 383 | +/// (`Player::pump`): the active window's own near edge |
| 367 | -/// *even when its far edge is the film's own last frame* -- half of all cuts | 384 | +/// ([`active_loop_window`]) when one is armed, *even when its far edge is |
| 368 | -/// in a two-clip film sit on the final clip (DESIGN.md §6), so that coincidence | 385 | +/// the film's own last frame* -- half of all cuts in a two-clip film sit on |
| 369 | -/// is not an edge case and must not read as "reached the end, stop". Falls | 386 | +/// the final clip (DESIGN.md §6), so that coincidence is not an edge case |
| 370 | -/// back to the whole-timeline loop's top, and `None` -- neither armed -- | 387 | +/// and must not read as "reached the end, stop". Falls back to the |
| 371 | -/// restarts nothing, which is the halt this crossing otherwise means. | 388 | +/// whole-timeline loop's top, and `None` -- nothing armed -- restarts |
| 372 | -pub(crate) fn loop_restart_frame(loop_on: bool, loop_trim: Option<(u32, u32)>) -> Option<u32> { | 389 | +/// nothing, which is the halt this crossing otherwise means. |
| 373 | - match loop_trim { | 390 | +pub(crate) fn loop_restart_frame( |
| 391 | + loop_on: bool, | ||
| 392 | + range: Option<(u32, u32)>, | ||
| 393 | + loop_trim: Option<(u32, u32)>, | ||
| 394 | +) -> Option<u32> { | ||
| 395 | + match active_loop_window(loop_on, range, loop_trim) { | ||
| 374 | Some((lo, _)) => Some(lo), | 396 | Some((lo, _)) => Some(lo), |
| 375 | None => loop_on.then_some(0), | 397 | None => loop_on.then_some(0), |
| 376 | } | 398 | } |
crates/app/src/ui/bench_stance.rsmodified+2 -0
| @@ -1124,6 +1124,8 @@ fn lane_row( | |||
| 1124 | .children( | 1124 | .children( |
| 1125 | player | 1125 | player |
| 1126 | .ghost | 1126 | .ghost |
| 1127 | + .iter() | ||
| 1128 | + .copied() | ||
| 1127 | .filter(|g| g.lane == lane && cx.has_active_drag()) | 1129 | .filter(|g| g.lane == lane && cx.has_active_drag()) |
| 1128 | .map(|g| { | 1130 | .map(|g| { |
| 1129 | div() | 1131 | div() |
crates/app/src/ui/inspector.rsmodified+100 -0
| @@ -121,6 +121,19 @@ impl Player { | |||
| 121 | let sub = self.session.as_ref()?.sub_lane(lane).get(idx).copied()?; | 121 | let sub = self.session.as_ref()?.sub_lane(lane).get(idx).copied()?; |
| 122 | Some((lane, sub)) | 122 | Some((lane, sub)) |
| 123 | }); | 123 | }); |
| 124 | + // The transition the anchor's clip carries into its successor, if | ||
| 125 | + // any -- a dissolve on a video lane ([`Clip::transition_out`]) or a | ||
| 126 | + // crossfade on an audio lane, told apart from a plain one-sided fade | ||
| 127 | + // by [`Project::crossfade`]'s own signature: both ends of the join | ||
| 128 | + // set together. `cap` is what the pair actually offers, the same | ||
| 129 | + // ceiling the engine's own setters clamp to, so the row never claims | ||
| 130 | + // more room than a step could land in. | ||
| 131 | + let transition = self.selected.anchor().and_then(|(lane, idx)| { | ||
| 132 | + let session = self.session.as_ref()?; | ||
| 133 | + let clips = session.lane_clips(lane); | ||
| 134 | + let (label, frames, cap) = transition_of(lane.kind, clips.get(idx)?, clips.get(idx + 1))?; | ||
| 135 | + Some((lane, idx, label, frames, cap)) | ||
| 136 | + }); | ||
| 124 | // A multi-selection is named for its anchor and counted: what the | 137 | // A multi-selection is named for its anchor and counted: what the |
| 125 | // panel shows is the anchor's settings, and the count says there is | 138 | // panel shows is the anchor's settings, and the count says there is |
| 126 | // more in hand than the panel is showing. | 139 | // more in hand than the panel is showing. |
| @@ -190,6 +203,14 @@ impl Player { | |||
| 190 | .text_color(rgb(FG_SECONDARY())) | 203 | .text_color(rgb(FG_SECONDARY())) |
| 191 | .child(detail), | 204 | .child(detail), |
| 192 | ) | 205 | ) |
| 206 | + // The duration field: a value and its own two steppers, the | ||
| 207 | + // shape `mbps_steppers` already draws for the export card's | ||
| 208 | + // bitrate -- present only while the anchor carries a transition, | ||
| 209 | + // since a row for a number that means nothing is a row lying | ||
| 210 | + // about what is selected. | ||
| 211 | + .when_some(transition, |d, (lane, idx, label, frames, cap)| { | ||
| 212 | + d.child(self.transition_duration_row(lane, idx, label, frames, cap, cx)) | ||
| 213 | + }) | ||
| 193 | .child( | 214 | .child( |
| 194 | div() | 215 | div() |
| 195 | .flex() | 216 | .flex() |
| @@ -268,6 +289,56 @@ impl Player { | |||
| 268 | ) | 289 | ) |
| 269 | } | 290 | } |
| 270 | 291 | ||
| 292 | + /// The duration row a transition-carrying anchor grows under | ||
| 293 | + /// `selection_section`'s detail line: `frames` as the engine counts it, | ||
| 294 | + /// flanked by the −/+ steppers [`Player::mbps_steppers`] already draws | ||
| 295 | + /// for the export card's bitrate row -- a field, not the drag handle | ||
| 296 | + /// `659770a` deliberately shrank the join's hit target away from. Each | ||
| 297 | + /// press nudges by one frame ([`Player::nudge_transition`]); the engine's | ||
| 298 | + /// own setters clamp to `cap`, so a run of presses past what the | ||
| 299 | + /// successor offers stops there rather than erroring. | ||
| 300 | + fn transition_duration_row( | ||
| 301 | + &self, | ||
| 302 | + lane: Lane, | ||
| 303 | + idx: usize, | ||
| 304 | + label: &'static str, | ||
| 305 | + frames: u32, | ||
| 306 | + cap: u32, | ||
| 307 | + cx: &mut Context<Self>, | ||
| 308 | + ) -> impl IntoElement { | ||
| 309 | + let step = |id: &'static str, glyph: &'static str, by: i32, cx: &mut Context<Self>| { | ||
| 310 | + div() | ||
| 311 | + .id(id) | ||
| 312 | + .flex() | ||
| 313 | + .w(px(HIT_MIN)) | ||
| 314 | + .h(px(HIT_MIN)) | ||
| 315 | + .items_center() | ||
| 316 | + .justify_center() | ||
| 317 | + .rounded(px(3.)) | ||
| 318 | + .bg(rgb(BG_RAISED())) | ||
| 319 | + .cursor_pointer() | ||
| 320 | + .hover(|s| s.bg(rgb(BG_HOVER()))) | ||
| 321 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { | ||
| 322 | + this.nudge_transition(lane, idx, by, cx); | ||
| 323 | + })) | ||
| 324 | + .child(glyph) | ||
| 325 | + }; | ||
| 326 | + div() | ||
| 327 | + .flex_none() | ||
| 328 | + .flex() | ||
| 329 | + .items_center() | ||
| 330 | + .gap(px(6.)) | ||
| 331 | + .child( | ||
| 332 | + div() | ||
| 333 | + .flex_1() | ||
| 334 | + .text_size(px(11.)) | ||
| 335 | + .text_color(rgb(FG_SECONDARY())) | ||
| 336 | + .child(format!("{label} {frames}f (of {cap}f offered)")), | ||
| 337 | + ) | ||
| 338 | + .child(step("transition-down", "−", -1, cx)) | ||
| 339 | + .child(step("transition-up", "+", 1, cx)) | ||
| 340 | + } | ||
| 341 | + | ||
| 271 | /// The settings that are the *project's* rather than any clip's: the canvas | 342 | /// The settings that are the *project's* rather than any clip's: the canvas |
| 272 | /// every clip is composed onto, the rate it is cut at, the HDR rendition it | 343 | /// every clip is composed onto, the rate it is cut at, the HDR rendition it |
| 273 | /// is watched in, and the mix everything sums into. They used to be four | 344 | /// is watched in, and the mix everything sums into. They used to be four |
| @@ -418,6 +489,35 @@ impl Player { | |||
| 418 | } | 489 | } |
| 419 | } | 490 | } |
| 420 | 491 | ||
| 492 | +/// The transition a clip carries into its immediate successor, if any -- a | ||
| 493 | +/// dissolve on a video lane ([`Clip::transition_out`]) or a crossfade on an | ||
| 494 | +/// audio lane, told apart from a plain one-sided fade drag by | ||
| 495 | +/// [`Project::crossfade`]'s own signature: both ends of the join set | ||
| 496 | +/// together, not just this clip's tail. `cap` is what the pair actually | ||
| 497 | +/// offers -- the shorter of the two clips' own lengths -- the same ceiling | ||
| 498 | +/// [`Project::set_transition_out`]/[`Project::crossfade`] clamp to, so the | ||
| 499 | +/// row this feeds never claims more room than a step could land in. | ||
| 500 | +/// | ||
| 501 | +/// Free of `Context` and of [`PlaybackSession`] alike, so it is testable | ||
| 502 | +/// without either -- this test binary has neither a `TestAppContext` nor | ||
| 503 | +/// real media to open one with (`split_drag_owes_save`'s own reason for | ||
| 504 | +/// being pulled out the same way). | ||
| 505 | +pub(crate) fn transition_of( | ||
| 506 | + lane_kind: LaneKind, | ||
| 507 | + clip: &Clip, | ||
| 508 | + next: Option<&Clip>, | ||
| 509 | +) -> Option<(&'static str, u32, u32)> { | ||
| 510 | + let next = next.filter(|n| n.start == clip.end())?; | ||
| 511 | + let cap = clip.frames().min(next.frames()); | ||
| 512 | + match lane_kind { | ||
| 513 | + LaneKind::Video if clip.transition_out > 0 => Some(("Dissolve", clip.transition_out, cap)), | ||
| 514 | + LaneKind::Audio if clip.fade_out > 0 && next.fade_in > 0 => { | ||
| 515 | + Some(("Crossfade", clip.fade_out, cap)) | ||
| 516 | + } | ||
| 517 | + _ => None, | ||
| 518 | + } | ||
| 519 | +} | ||
| 520 | + | ||
| 421 | /// A region's own title bar: the same 24 px strip in the library and the | 521 | /// A region's own title bar: the same 24 px strip in the library and the |
| 422 | /// inspector, so the two columns read as the pair they are. | 522 | /// inspector, so the two columns read as the pair they are. |
| 423 | pub(crate) fn section_head(title: &'static str) -> impl IntoElement { | 523 | pub(crate) fn section_head(title: &'static str) -> impl IntoElement { |
crates/app/src/ui/timeline.rsmodified+9 -5
| @@ -850,11 +850,15 @@ impl Player { | |||
| 850 | .snap_cue | 850 | .snap_cue |
| 851 | .filter(|_| self.trim.is_some() || cx.has_active_drag()) | 851 | .filter(|_| self.trim.is_some() || cx.has_active_drag()) |
| 852 | .map(|frame| scale.px_at(f64::from(frame) / self.fps)); | 852 | .map(|frame| scale.px_at(f64::from(frame) / self.fps)); |
| 853 | - // The shadow, on the one lane the pointer is over -- and, like the line, | 853 | + // The shadow (or shadows, on a set-drag -- [`Player::preview_ghost`]), |
| 854 | - // only while the drag that asked for it is still in flight. | 854 | + // on the one lane each names -- and, like the line, only while the |
| 855 | - let ghost = self | 855 | + // drag that asked for it is still in flight. |
| 856 | + let ghost: Vec<Ghost> = self | ||
| 856 | .ghost | 857 | .ghost |
| 857 | - .filter(|g| g.lane == lane && cx.has_active_drag()); | 858 | + .iter() |
| 859 | + .copied() | ||
| 860 | + .filter(|g| g.lane == lane && cx.has_active_drag()) | ||
| 861 | + .collect(); | ||
| 858 | let clips = self | 862 | let clips = self |
| 859 | .session | 863 | .session |
| 860 | .as_ref() | 864 | .as_ref() |
| @@ -1919,7 +1923,7 @@ impl Player { | |||
| 1919 | // under a drag. Over the clips (it is translucent, so what | 1923 | // under a drag. Over the clips (it is translucent, so what |
| 1920 | // it would cover shows through) and under the line, which | 1924 | // it would cover shows through) and under the line, which |
| 1921 | // marks the frame this box merely fills. | 1925 | // marks the frame this box merely fills. |
| 1922 | - .children(ghost.map(|g| { | 1926 | + .children(ghost.into_iter().map(|g| { |
| 1923 | div() | 1927 | div() |
| 1924 | .absolute() | 1928 | .absolute() |
| 1925 | .top_0() | 1929 | .top_0() |
crates/app/src/ui/toolbar.rsmodified+13 -1
| @@ -170,6 +170,18 @@ impl Player { | |||
| 170 | - 2. * SPLIT_W; | 170 | - 2. * SPLIT_W; |
| 171 | let clock_w = TIME_W.min(room - 140.).max(96.); | 171 | let clock_w = TIME_W.min(room - 140.).max(96.); |
| 172 | let slider = room >= TRANSPORT_ROOMY; | 172 | let slider = room >= TRANSPORT_ROOMY; |
| 173 | + // Which window the loop button actually restarts, in the same | ||
| 174 | + // priority [`active_loop_window`] picks it in: the marked i/o range | ||
| 175 | + // once something is armed, the subject-cut trim next, the whole | ||
| 176 | + // timeline last. | ||
| 177 | + let armed = self.loop_on || self.loop_trim.is_some(); | ||
| 178 | + let loop_hint = if armed && self.range.is_some() { | ||
| 179 | + "restarts from the marked in point on reaching the marked out point, instead of stopping" | ||
| 180 | + } else if self.loop_trim.is_some() { | ||
| 181 | + "restarts from the subject cut's own start on reaching its end, instead of stopping" | ||
| 182 | + } else { | ||
| 183 | + "restarts from the top on reaching the end, instead of stopping" | ||
| 184 | + }; | ||
| 173 | div() | 185 | div() |
| 174 | .flex_none() | 186 | .flex_none() |
| 175 | .h(px(TRANSPORT_H)) | 187 | .h(px(TRANSPORT_H)) |
| @@ -213,7 +225,7 @@ impl Player { | |||
| 213 | }, | 225 | }, |
| 214 | None, | 226 | None, |
| 215 | "Loop", | 227 | "Loop", |
| 216 | - "restarts from the top on reaching the end, instead of stopping", | 228 | + loop_hint, |
| 217 | ActionId::Loop, | 229 | ActionId::Loop, |
| 218 | cx.listener(|this, _: &ClickEvent, window, cx| { | 230 | cx.listener(|this, _: &ClickEvent, window, cx| { |
| 219 | this.act(ActionId::Loop, window, cx) | 231 | this.act(ActionId::Loop, window, cx) |
crates/engine/src/playback.rsmodified+26 -0
| @@ -2374,6 +2374,22 @@ impl PlaybackSession { | |||
| 2374 | self.edit(Dirty::Both, |p| p.move_clip(from, idx, to, start)) | 2374 | self.edit(Dirty::Both, |p| p.move_clip(from, idx, to, start)) |
| 2375 | } | 2375 | } |
| 2376 | 2376 | ||
| 2377 | + /// [`move_clip_to`](Self::move_clip_to)'s general form: every one of | ||
| 2378 | + /// `picks` travels the same frame delta as the dragged clip at `idx` of | ||
| 2379 | + /// `from`, all-or-nothing, one undo step for the lot -- what a hand drags | ||
| 2380 | + /// on a selection rather than a lone clip. See | ||
| 2381 | + /// [`Project::move_selection`] for the clamp that makes it all-or-nothing. | ||
| 2382 | + pub fn move_selection_to( | ||
| 2383 | + &mut self, | ||
| 2384 | + picks: &[(Lane, usize)], | ||
| 2385 | + from: Lane, | ||
| 2386 | + idx: usize, | ||
| 2387 | + to: Lane, | ||
| 2388 | + start: u32, | ||
| 2389 | + ) -> bool { | ||
| 2390 | + self.edit(Dirty::Both, |p| p.move_selection(picks, from, idx, to, start)) | ||
| 2391 | + } | ||
| 2392 | + | ||
| 2377 | /// Drags one end of that clip to timeline frame `to`, changing how much of | 2393 | /// Drags one end of that clip to timeline frame `to`, changing how much of |
| 2378 | /// its source it plays and nothing else on the lane -- see [`Project::trim`] | 2394 | /// its source it plays and nothing else on the lane -- see [`Project::trim`] |
| 2379 | /// for the walls it is clamped by, which this fills the source lengths in | 2395 | /// for the walls it is clamped by, which this fills the source lengths in |
| @@ -2937,6 +2953,16 @@ impl PlaybackSession { | |||
| 2937 | self.edit(Dirty::Both, |p| p.paste(at, clip)) | 2953 | self.edit(Dirty::Both, |p| p.paste(at, clip)) |
| 2938 | } | 2954 | } |
| 2939 | 2955 | ||
| 2956 | + /// [`paste_at`](Self::paste_at)'s general form: [`Project::paste_set`]'s | ||
| 2957 | + /// door, clamped to the timeline's own end the same way -- a set let go | ||
| 2958 | + /// past the last frame lands there rather than carrying black in front of | ||
| 2959 | + /// it, exactly as a lone clip's paste does. | ||
| 2960 | + pub fn paste_set_at(&mut self, timeline_secs: f64, items: &[(Lane, Clip)]) -> bool { | ||
| 2961 | + let at = secs_to_frame(timeline_secs, self.meta.frame_rate) | ||
| 2962 | + .min(self.project.timeline_frames()); | ||
| 2963 | + self.edit(Dirty::Both, |p| p.paste_set(at, items)) | ||
| 2964 | + } | ||
| 2965 | + | ||
| 2940 | /// Places the whole of `path` played on its audio `stream` at | 2966 | /// Places the whole of `path` played on its audio `stream` at |
| 2941 | /// `timeline_secs`, the way [`paste_at`](Self::paste_at) places a copy -- | 2967 | /// `timeline_secs`, the way [`paste_at`](Self::paste_at) places a copy -- |
| 2942 | /// the door a library row goes through, and the only way a stream other | 2968 | /// the door a library row goes through, and the only way a stream other |
crates/engine/src/project.rsmodified+119 -7
| @@ -3591,23 +3591,71 @@ impl Project { | |||
| 3591 | /// is on, and a drop that changes neither lane nor frame, which is a clip | 3591 | /// is on, and a drop that changes neither lane nor frame, which is a clip |
| 3592 | /// picked up and put back down, i.e. a click. | 3592 | /// picked up and put back down, i.e. a click. |
| 3593 | pub fn move_clip(&mut self, from: Lane, idx: usize, to: Lane, start: u32) -> bool { | 3593 | pub fn move_clip(&mut self, from: Lane, idx: usize, to: Lane, start: u32) -> bool { |
| 3594 | + self.move_selection(&[(from, idx)], from, idx, to, start) | ||
| 3595 | + } | ||
| 3596 | + | ||
| 3597 | + /// [`move_clip`](Self::move_clip)'s general form: every pick in `picks` | ||
| 3598 | + /// (each with its own link group, exactly as [`group_of`](Self::group_of) | ||
| 3599 | + /// reads it) travels the same distance as the clip at `idx` of `from`, | ||
| 3600 | + /// which alone changes lane, onto `to`. One clamp across the whole set | ||
| 3601 | + /// ([`move_room`](Self::move_room)) is what makes this all-or-nothing: a | ||
| 3602 | + /// neighbour that boxes in *any* member narrows the delta every member | ||
| 3603 | + /// moves by, and a member with no room at all (`lo > hi`) refuses the | ||
| 3604 | + /// whole set rather than moving the rest and leaving that one behind. | ||
| 3605 | + /// `move_clip` is this with a selection of one -- the dragged clip's own | ||
| 3606 | + /// group and nothing else -- so a drag on a clip outside the selection is | ||
| 3607 | + /// byte-identical to before this existed. | ||
| 3608 | + pub fn move_selection( | ||
| 3609 | + &mut self, | ||
| 3610 | + picks: &[(Lane, usize)], | ||
| 3611 | + from: Lane, | ||
| 3612 | + idx: usize, | ||
| 3613 | + to: Lane, | ||
| 3614 | + start: u32, | ||
| 3615 | + ) -> bool { | ||
| 3594 | let (Some(dest), Some(clip)) = (self.index(to), self.lane(from).get(idx).copied()) else { | 3616 | let (Some(dest), Some(clip)) = (self.index(to), self.lane(from).get(idx).copied()) else { |
| 3595 | return false; | 3617 | return false; |
| 3596 | }; | 3618 | }; |
| 3597 | if from.kind != to.kind { | 3619 | if from.kind != to.kind { |
| 3598 | return false; | 3620 | return false; |
| 3599 | } | 3621 | } |
| 3600 | - let members = self.group_of(from, idx).expect("the clip was found"); | ||
| 3601 | let held = self.index(from).expect("the clip was found on it"); | 3622 | let held = self.index(from).expect("the clip was found on it"); |
| 3602 | - // The two halves of one group would land on one span of one lane, which | 3623 | + // Every pick's own group, unioned: the whole selection moves as one, |
| 3603 | - // is the one thing a link may never mean. Refused rather than clamped: | 3624 | + // and a pick's link partners (not themselves picked) come along with |
| 3604 | - // the partner moves the same distance, so there is no room for it | 3625 | + // it exactly as a lone drag's do. |
| 3605 | - // anywhere on that lane. | 3626 | + let mut members = Members::default(); |
| 3627 | + for &(lane, i) in picks { | ||
| 3628 | + let Some(group) = self.group_of(lane, i) else { | ||
| 3629 | + continue; | ||
| 3630 | + }; | ||
| 3631 | + for m in group.clips { | ||
| 3632 | + if !members.clips.contains(&m) { | ||
| 3633 | + members.clips.push(m); | ||
| 3634 | + } | ||
| 3635 | + } | ||
| 3636 | + for m in group.subs { | ||
| 3637 | + if !members.subs.contains(&m) { | ||
| 3638 | + members.subs.push(m); | ||
| 3639 | + } | ||
| 3640 | + } | ||
| 3641 | + } | ||
| 3642 | + if !members.clips.contains(&(held, idx)) { | ||
| 3643 | + members.clips.push((held, idx)); | ||
| 3644 | + } | ||
| 3645 | + // The two halves of *the dragged clip's own* group would land on one | ||
| 3646 | + // span of one lane, which is the one thing a link may never mean -- | ||
| 3647 | + // checked against that group alone, not the whole moving set: an | ||
| 3648 | + // unlinked fellow pick already sitting on `dest` is no conflict at | ||
| 3649 | + // all, since it travels by the same delta and `move_room` below | ||
| 3650 | + // leaves it the room to. Refused rather than clamped: the partner | ||
| 3651 | + // moves the same distance, so there is no room for it anywhere on | ||
| 3652 | + // that lane. | ||
| 3653 | + let own_group = self.group_of(from, idx).expect("the clip was found"); | ||
| 3606 | if dest != held | 3654 | if dest != held |
| 3607 | - && members | 3655 | + && own_group |
| 3608 | .clips | 3656 | .clips |
| 3609 | .iter() | 3657 | .iter() |
| 3610 | - .chain(&members.subs) | 3658 | + .chain(&own_group.subs) |
| 3611 | .any(|&(l, _)| l == dest) | 3659 | .any(|&(l, _)| l == dest) |
| 3612 | { | 3660 | { |
| 3613 | return false; | 3661 | return false; |
| @@ -4156,6 +4204,70 @@ impl Project { | |||
| 4156 | true | 4204 | true |
| 4157 | } | 4205 | } |
| 4158 | 4206 | ||
| 4207 | + /// [`paste`](Project::paste)'s general form: every `(lane, clip)` in | ||
| 4208 | + /// `items` lands on the lane it names, its head moved by the offset every | ||
| 4209 | + /// other item moves by too -- `at` less the earliest `start` among them, | ||
| 4210 | + /// so the set's own gaps and lane assignment survive the trip from | ||
| 4211 | + /// clipboard to bed unchanged, rather than collapsing onto `V1`/`A1` the | ||
| 4212 | + /// way a lone clip's copy does. | ||
| 4213 | + /// | ||
| 4214 | + /// All-or-nothing, and **refused** rather than opening room or splitting | ||
| 4215 | + /// a neighbour the way [`paste`](Project::paste) does for one clip: | ||
| 4216 | + /// a set-paste never ripples the bed, so a landing that overlaps so much | ||
| 4217 | + /// as one existing clip on its own lane refuses the whole set, changing | ||
| 4218 | + /// nothing -- the paste's own [`move_selection`](Project::move_selection) | ||
| 4219 | + /// clamps instead of refusing, but a paste has no drag to clamp against, | ||
| 4220 | + /// and a landing moved off the frame asked for is not what a paste means. | ||
| 4221 | + /// `items` empty, naming a lane or a source that is not there, or a clip | ||
| 4222 | + /// with `out_frame <= in_frame`, refuses too, before anything is touched. | ||
| 4223 | + /// | ||
| 4224 | + /// Exactly one history snapshot for the whole set, so one | ||
| 4225 | + /// [`Project::undo`] takes it back. Changes the timeline->source mapping | ||
| 4226 | + /// on every lane an item lands on: the caller must reseek. | ||
| 4227 | + pub fn paste_set(&mut self, at: u32, items: &[(Lane, Clip)]) -> bool { | ||
| 4228 | + let Some(anchor) = items.iter().map(|(_, c)| c.start).min() else { | ||
| 4229 | + return false; | ||
| 4230 | + }; | ||
| 4231 | + // Resolved once, up front, off the lanes as they stand now: a lane or | ||
| 4232 | + // source that is not there, or a landing that would overlap a | ||
| 4233 | + // neighbour, refuses the whole set before any of it is written. | ||
| 4234 | + let mut landings: Vec<(usize, Clip)> = Vec::with_capacity(items.len()); | ||
| 4235 | + for &(lane, clip) in items { | ||
| 4236 | + let Some(li) = self.index(lane) else { | ||
| 4237 | + return false; | ||
| 4238 | + }; | ||
| 4239 | + if self.sources.get(clip.source).is_none() || clip.out_frame <= clip.in_frame { | ||
| 4240 | + return false; | ||
| 4241 | + } | ||
| 4242 | + let delta = i64::from(clip.start) - i64::from(anchor); | ||
| 4243 | + let Ok(start) = u32::try_from(i64::from(at) + delta) else { | ||
| 4244 | + return false; | ||
| 4245 | + }; | ||
| 4246 | + let Some(end) = start.checked_add(clip.frames()) else { | ||
| 4247 | + return false; | ||
| 4248 | + }; | ||
| 4249 | + if self.lanes[li] | ||
| 4250 | + .clips | ||
| 4251 | + .iter() | ||
| 4252 | + .any(|c| c.start < end && start < c.end()) | ||
| 4253 | + { | ||
| 4254 | + return false; | ||
| 4255 | + } | ||
| 4256 | + landings.push((li, Clip { start, ..clip })); | ||
| 4257 | + } | ||
| 4258 | + self.snapshot(); | ||
| 4259 | + for (li, mut clip) in landings { | ||
| 4260 | + clip.link = Some(self.new_link()); | ||
| 4261 | + clip.fade_in = 0; | ||
| 4262 | + clip.fade_out = 0; | ||
| 4263 | + clip.transition_out = 0; | ||
| 4264 | + let clips = &mut self.lanes[li].clips; | ||
| 4265 | + let idx = clips.partition_point(|c| c.start < clip.start); | ||
| 4266 | + clips.insert(idx, clip); | ||
| 4267 | + } | ||
| 4268 | + true | ||
| 4269 | + } | ||
| 4270 | + | ||
| 4159 | /// Lift the clip at `idx` out of `lane`, leaving a gap: black frames or | 4271 | /// Lift the clip at `idx` out of `lane`, leaving a gap: black frames or |
| 4160 | /// silence, and nothing else moves. Refused only for an out-of-range index | 4272 | /// silence, and nothing else moves. Refused only for an out-of-range index |
| 4161 | /// (which a lane that is not there always is) -- lifting the last placement | 4273 | /// (which a lane that is not there always is) -- lifting the last placement |