Copy/paste carries the whole selection set
Browse files at this commit778034fc64329a9f2e9c88708772b3727a0e1a1cParent: 1dc3c45- feat
- copy/paste carries the whole selection set
8 changed files +289 -42
- crates/app/src/library_meta.rs +20 -13
- crates/app/src/main.rs +8 -4
- crates/app/src/player/actions.rs +1 -1
- crates/app/src/player/library.rs +3 -3
- crates/app/src/player/timeline_edit.rs +43 -15
- crates/app/src/tests/editing.rs +140 -6
- crates/engine/src/playback.rs +10 -0
- crates/engine/src/project.rs +64 -0
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+8 -4
| @@ -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, |
| @@ -932,7 +936,7 @@ fn main() { | |||
| 932 | decoders: HashMap::new(), | 936 | decoders: HashMap::new(), |
| 933 | export_seat: None, | 937 | export_seat: None, |
| 934 | hw_caps: None, | 938 | hw_caps: None, |
| 935 | - clipboard: None, | 939 | + clipboard: Vec::new(), |
| 936 | scrubbing: false, | 940 | scrubbing: false, |
| 937 | splits: load_stance_splits(), | 941 | splits: load_stance_splits(), |
| 938 | split_drag: None, | 942 | split_drag: None, |
crates/app/src/player/actions.rsmodified+1 -1
| @@ -354,7 +354,7 @@ impl Player { | |||
| 354 | }), | 354 | }), |
| 355 | playhead: frame_at(session.now(), self.fps), | 355 | playhead: frame_at(session.now(), self.fps), |
| 356 | timeline: true, | 356 | timeline: true, |
| 357 | - clipboard: self.clipboard.is_some(), | 357 | + clipboard: !self.clipboard.is_empty(), |
| 358 | subtitles: !session.subtitles().is_empty(), | 358 | subtitles: !session.subtitles().is_empty(), |
| 359 | playable: !nothing_to_play(self.active_session()), | 359 | playable: !nothing_to_play(self.active_session()), |
| 360 | exporting: self.exporting().is_some(), | 360 | 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+43 -15
| @@ -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 | } |
crates/app/src/tests/editing.rsmodified+140 -6
| @@ -1685,19 +1685,35 @@ fn a_copied_clip_is_renumbered_or_dropped_when_a_row_leaves_the_library() { | |||
| 1685 | }; | 1685 | }; |
| 1686 | // Copied from source 2, source 0 removed: the same file is source 1 now. | 1686 | // Copied from source 2, source 0 removed: the same file is source 1 now. |
| 1687 | assert_eq!( | 1687 | assert_eq!( |
| 1688 | - clipboard_after_remove(Some(clip(2)), 0).map(|c| c.source), | 1688 | + clipboard_after_remove(vec![(Lane::V1, clip(2))], 0) |
| 1689 | - Some(1), | 1689 | + .into_iter() |
| 1690 | + .map(|(_, c)| c.source) | ||
| 1691 | + .collect::<Vec<_>>(), | ||
| 1692 | + vec![1], | ||
| 1690 | "the clipboard follows its file down the list" | 1693 | "the clipboard follows its file down the list" |
| 1691 | ); | 1694 | ); |
| 1692 | // Copied from a source *before* the one that went: untouched. | 1695 | // Copied from a source *before* the one that went: untouched. |
| 1693 | assert_eq!( | 1696 | assert_eq!( |
| 1694 | - clipboard_after_remove(Some(clip(0)), 2).map(|c| c.source), | 1697 | + clipboard_after_remove(vec![(Lane::V1, clip(0))], 2) |
| 1695 | - Some(0) | 1698 | + .into_iter() |
| 1699 | + .map(|(_, c)| c.source) | ||
| 1700 | + .collect::<Vec<_>>(), | ||
| 1701 | + vec![0] | ||
| 1696 | ); | 1702 | ); |
| 1697 | // Copied from the row that was just removed: there is nothing left to | 1703 | // Copied from the row that was just removed: there is nothing left to |
| 1698 | // paste, and pasting the next file along would be a lie. | 1704 | // paste, and pasting the next file along would be a lie. |
| 1699 | - assert!(clipboard_after_remove(Some(clip(1)), 1).is_none()); | 1705 | + assert!(clipboard_after_remove(vec![(Lane::V1, clip(1))], 1).is_empty()); |
| 1700 | - assert!(clipboard_after_remove(None, 0).is_none()); | 1706 | + assert!(clipboard_after_remove(Vec::new(), 0).is_empty()); |
| 1707 | + // A set with one member's file gone loses only that member -- the rest | ||
| 1708 | + // of the set survives to be pasted, gaps and lanes intact. | ||
| 1709 | + let trimmed = clipboard_after_remove( | ||
| 1710 | + vec![(Lane::V1, clip(1)), (Lane::A1, clip(2))], | ||
| 1711 | + 1, | ||
| 1712 | + ); | ||
| 1713 | + assert_eq!( | ||
| 1714 | + trimmed.into_iter().map(|(_, c)| c.source).collect::<Vec<_>>(), | ||
| 1715 | + vec![1] | ||
| 1716 | + ); | ||
| 1701 | } | 1717 | } |
| 1702 | 1718 | ||
| 1703 | /// The trim-a-clip path through the doors the edge drag uses: | 1719 | /// The trim-a-clip path through the doors the edge drag uses: |
| @@ -2009,6 +2025,124 @@ fn a_selection_drag_refuses_as_one_set_when_any_pick_cannot_land() { | |||
| 2009 | assert_eq!(session.lane_clips(v2)[1], blocker); | 2025 | assert_eq!(session.lane_clips(v2)[1], blocker); |
| 2010 | } | 2026 | } |
| 2011 | 2027 | ||
| 2028 | +/// A plain click's copy is one clipboard entry, and one entry still takes | ||
| 2029 | +/// [`PlaybackSession::paste_at`] -- the door it always has, unchanged by a | ||
| 2030 | +/// set ever being able to ride [`PlaybackSession::paste_set_at`] instead. | ||
| 2031 | +#[test] | ||
| 2032 | +fn a_single_pick_copy_paste_round_trips_unchanged() { | ||
| 2033 | + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | ||
| 2034 | + session.set_gain(0.0); | ||
| 2035 | + // `open` seeds V1 with the whole fixture as its own clip -- what a plain | ||
| 2036 | + // click would copy. | ||
| 2037 | + let copied = session.lane_clips(Lane::V1)[0]; | ||
| 2038 | + | ||
| 2039 | + let at = session.timeline_duration(); | ||
| 2040 | + assert!(session.paste_at(at, copied), "a free spot always takes it"); | ||
| 2041 | + let pasted = session.lane_clips(Lane::V1)[1]; | ||
| 2042 | + assert_eq!( | ||
| 2043 | + (pasted.source, pasted.in_frame, pasted.out_frame), | ||
| 2044 | + (copied.source, copied.in_frame, copied.out_frame), | ||
| 2045 | + "the pasted clip plays the same source frames the copy did" | ||
| 2046 | + ); | ||
| 2047 | + | ||
| 2048 | + assert!(session.undo(), "one step for the paste"); | ||
| 2049 | + assert_eq!(session.lane_clips(Lane::V1).len(), 1); | ||
| 2050 | +} | ||
| 2051 | + | ||
| 2052 | +/// [`PlaybackSession::paste_set_at`], the set-copy's own door | ||
| 2053 | +/// ([`Player::paste`]'s multi-entry path): three picks across two lanes, some | ||
| 2054 | +/// distance apart, keep that same distance and the same lane each landed on | ||
| 2055 | +/// -- the offset [`Project::paste_set`] moves every item by is the one from | ||
| 2056 | +/// the earliest pick to `at`, not a collapse onto `V1`/`A1`. | ||
| 2057 | +#[test] | ||
| 2058 | +fn a_three_pick_copy_paste_preserves_gaps_and_lane_assignment() { | ||
| 2059 | + use engine::project::LaneKind; | ||
| 2060 | + | ||
| 2061 | + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | ||
| 2062 | + session.set_gain(0.0); | ||
| 2063 | + let path = session.sources()[0].path.clone(); | ||
| 2064 | + session.import(&asset("test_av2.mp4")).expect("av2 matches"); | ||
| 2065 | + let second = session.sources()[1].path.clone(); | ||
| 2066 | + | ||
| 2067 | + assert!(session | ||
| 2068 | + .place_stream_at(10.0, &second, 0, None) | ||
| 2069 | + .expect("av2 is on this timeline")); | ||
| 2070 | + let clip0 = session.lane_clips(Lane::V1)[0]; | ||
| 2071 | + let clip1 = session.lane_clips(Lane::V1)[1]; | ||
| 2072 | + | ||
| 2073 | + let v2 = session.add_lane(LaneKind::Video); | ||
| 2074 | + assert!(session | ||
| 2075 | + .place_stream_at(20.0, &path, 0, Some(v2)) | ||
| 2076 | + .expect("test_av.mp4 is on this timeline")); | ||
| 2077 | + let clip_c = session.lane_clips(v2)[0]; | ||
| 2078 | + | ||
| 2079 | + // Copied in click order, out of the lanes each was clicked in -- exactly | ||
| 2080 | + // what `Player::copy_selected` builds. | ||
| 2081 | + let items = [(Lane::V1, clip0), (Lane::V1, clip1), (v2, clip_c)]; | ||
| 2082 | + let at = session.timeline_duration(); | ||
| 2083 | + assert!(session.paste_set_at(at, &items), "a free spot takes the set"); | ||
| 2084 | + | ||
| 2085 | + let new0 = session.lane_clips(Lane::V1)[2]; | ||
| 2086 | + let new1 = session.lane_clips(Lane::V1)[3]; | ||
| 2087 | + let new_c = session.lane_clips(v2)[1]; | ||
| 2088 | + // The gaps between picks survive the trip untouched. | ||
| 2089 | + assert_eq!(new1.start - new0.start, clip1.start - clip0.start); | ||
| 2090 | + assert_eq!(new_c.start - new0.start, clip_c.start - clip0.start); | ||
| 2091 | + // And each still plays the source frames it was copied with, off the | ||
| 2092 | + // lane it was copied off of. | ||
| 2093 | + assert_eq!( | ||
| 2094 | + (new0.source, new0.in_frame, new0.out_frame), | ||
| 2095 | + (clip0.source, clip0.in_frame, clip0.out_frame) | ||
| 2096 | + ); | ||
| 2097 | + assert_eq!( | ||
| 2098 | + (new_c.source, new_c.in_frame, new_c.out_frame), | ||
| 2099 | + (clip_c.source, clip_c.in_frame, clip_c.out_frame) | ||
| 2100 | + ); | ||
| 2101 | + | ||
| 2102 | + assert!(session.undo(), "one step for the whole set-paste"); | ||
| 2103 | + assert_eq!(session.lane_clips(Lane::V1).len(), 2); | ||
| 2104 | + assert_eq!(session.lane_clips(v2).len(), 1); | ||
| 2105 | +} | ||
| 2106 | + | ||
| 2107 | +/// A set-paste never ripples the bed: a landing that would overlap so much | ||
| 2108 | +/// as one existing clip on its own lane refuses the *whole* set, exactly as | ||
| 2109 | +/// [`Project::paste_set`] documents, leaving the project as it was rather | ||
| 2110 | +/// than placing the picks that had room to spare. | ||
| 2111 | +#[test] | ||
| 2112 | +fn a_colliding_set_paste_refuses_whole() { | ||
| 2113 | + use engine::project::LaneKind; | ||
| 2114 | + | ||
| 2115 | + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | ||
| 2116 | + session.set_gain(0.0); | ||
| 2117 | + let path = session.sources()[0].path.clone(); | ||
| 2118 | + session.import(&asset("test_av2.mp4")).expect("av2 matches"); | ||
| 2119 | + let second = session.sources()[1].path.clone(); | ||
| 2120 | + | ||
| 2121 | + assert!(session | ||
| 2122 | + .place_stream_at(10.0, &second, 0, None) | ||
| 2123 | + .expect("av2 is on this timeline")); | ||
| 2124 | + let clip0 = session.lane_clips(Lane::V1)[0]; | ||
| 2125 | + let clip1 = session.lane_clips(Lane::V1)[1]; | ||
| 2126 | + | ||
| 2127 | + let v2 = session.add_lane(LaneKind::Video); | ||
| 2128 | + assert!(session | ||
| 2129 | + .place_stream_at(20.0, &path, 0, Some(v2)) | ||
| 2130 | + .expect("test_av.mp4 is on this timeline")); | ||
| 2131 | + let clip_c = session.lane_clips(v2)[0]; | ||
| 2132 | + | ||
| 2133 | + let items = [(Lane::V1, clip0), (Lane::V1, clip1), (v2, clip_c)]; | ||
| 2134 | + // A blocker sat right where the V1 half of the set would land: pasting | ||
| 2135 | + // at the timeline's own start walks every item straight back onto the | ||
| 2136 | + // lanes it was copied off of, colliding with everything already there. | ||
| 2137 | + assert!(!session.paste_set_at(0.0, &items)); | ||
| 2138 | + | ||
| 2139 | + assert_eq!(session.lane_clips(Lane::V1)[0], clip0); | ||
| 2140 | + assert_eq!(session.lane_clips(Lane::V1)[1], clip1); | ||
| 2141 | + assert_eq!(session.lane_clips(v2)[0], clip_c); | ||
| 2142 | + assert_eq!(session.lane_clips(Lane::V1).len(), 2); | ||
| 2143 | + assert_eq!(session.lane_clips(v2).len(), 1); | ||
| 2144 | +} | ||
| 2145 | + | ||
| 2012 | /// The refactor `move_clip` -> `move_selection` owes: a clip dragged from | 2146 | /// The refactor `move_clip` -> `move_selection` owes: a clip dragged from |
| 2013 | /// outside the selection (or with nothing else selected) moves exactly as it | 2147 | /// outside the selection (or with nothing else selected) moves exactly as it |
| 2014 | /// always has -- `move_clip_to`'s own door and `move_selection_to`'s | 2148 | /// always has -- `move_clip_to`'s own door and `move_selection_to`'s |
crates/engine/src/playback.rsmodified+10 -0
| @@ -2953,6 +2953,16 @@ impl PlaybackSession { | |||
| 2953 | self.edit(Dirty::Both, |p| p.paste(at, clip)) | 2953 | self.edit(Dirty::Both, |p| p.paste(at, clip)) |
| 2954 | } | 2954 | } |
| 2955 | 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 | + | ||
| 2956 | /// Places the whole of `path` played on its audio `stream` at | 2966 | /// Places the whole of `path` played on its audio `stream` at |
| 2957 | /// `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 -- |
| 2958 | /// 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+64 -0
| @@ -4204,6 +4204,70 @@ impl Project { | |||
| 4204 | true | 4204 | true |
| 4205 | } | 4205 | } |
| 4206 | 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 | + | ||
| 4207 | /// 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 |
| 4208 | /// 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 |
| 4209 | /// (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 |