Merge branch 'worktree-agent-a85e89ec4eb027013'
Browse files at this commit3 changed files +229 -0
- crates/app/src/main.rs +119 -0
- crates/engine/src/playback.rs +10 -0
- crates/engine/src/project.rs +100 -0
crates/app/src/main.rsmodified+119 -0
| @@ -206,6 +206,16 @@ enum Wave { | |||
| 206 | /// change what is inserted. | 206 | /// change what is inserted. |
| 207 | struct AssetDrag(PathBuf, usize); | 207 | struct AssetDrag(PathBuf, usize); |
| 208 | 208 | ||
| 209 | +/// A clip already on the timeline being dragged: the lane it is on and its index | ||
| 210 | +/// there, which is how every other edit names a clip. Unlike an [`AssetDrag`] | ||
| 211 | +/// nothing is inserted -- the same clip changes lane and keeps its frames -- so | ||
| 212 | +/// where along the bed it is let go says nothing here either. | ||
| 213 | +#[derive(Clone, Copy)] | ||
| 214 | +struct ClipDrag { | ||
| 215 | + lane: Lane, | ||
| 216 | + idx: usize, | ||
| 217 | +} | ||
| 218 | + | ||
| 209 | /// An open clip menu: which clip it was opened on, where it hangs, and whether | 219 | /// An open clip menu: which clip it was opened on, where it hangs, and whether |
| 210 | /// it has been turned over to show what that clip *is* instead of what can be | 220 | /// it has been turned over to show what that clip *is* instead of what can be |
| 211 | /// done to it. The lane and index are the ones the same click selected, so | 221 | /// done to it. The lane and index are the ones the same click selected, so |
| @@ -1111,6 +1121,53 @@ impl Player { | |||
| 1111 | cx.notify(); | 1121 | cx.notify(); |
| 1112 | } | 1122 | } |
| 1113 | 1123 | ||
| 1124 | + /// A clip dragged off one lane and let go over another: it changes track and | ||
| 1125 | + /// keeps the frames it covers, as one undo step. Dropped back on its own | ||
| 1126 | + /// lane it is not an edit at all, so nothing is said about it. The engine | ||
| 1127 | + /// reseeks, so all this owes is the flag reset -- and the selection, whose | ||
| 1128 | + /// index was that lane's own and now names a different clip there. | ||
| 1129 | + fn move_clip(&mut self, from: Lane, idx: usize, to: Lane, cx: &mut Context<Self>) { | ||
| 1130 | + if self.exporting().is_some() || from == to { | ||
| 1131 | + return; | ||
| 1132 | + } | ||
| 1133 | + let moved = self | ||
| 1134 | + .session | ||
| 1135 | + .as_mut() | ||
| 1136 | + .is_some_and(|session| session.move_clip_to_lane(from, idx, to)); | ||
| 1137 | + let (kind, lanes) = match from.kind { | ||
| 1138 | + LaneKind::Video => ("picture", "video"), | ||
| 1139 | + LaneKind::Audio => ("sound", "audio"), | ||
| 1140 | + }; | ||
| 1141 | + match moved { | ||
| 1142 | + true => { | ||
| 1143 | + self.selected = None; | ||
| 1144 | + self.reset_after_reseek(); | ||
| 1145 | + } | ||
| 1146 | + // The two ways a drag is refused, told apart by the one thing the | ||
| 1147 | + // front-end already knows: a lane's kind. Everything else that | ||
| 1148 | + // could refuse (a clip that is not there) cannot be dragged. | ||
| 1149 | + false if from.kind != to.kind => { | ||
| 1150 | + self.notice = Some( | ||
| 1151 | + format!( | ||
| 1152 | + "NOT ON {} — that is a {kind} clip; drop it on a {lanes} lane", | ||
| 1153 | + to.label() | ||
| 1154 | + ) | ||
| 1155 | + .into(), | ||
| 1156 | + ) | ||
| 1157 | + } | ||
| 1158 | + false => { | ||
| 1159 | + self.notice = Some( | ||
| 1160 | + format!( | ||
| 1161 | + "NOT MOVED — another clip already covers those frames on {}", | ||
| 1162 | + to.label() | ||
| 1163 | + ) | ||
| 1164 | + .into(), | ||
| 1165 | + ) | ||
| 1166 | + } | ||
| 1167 | + } | ||
| 1168 | + cx.notify(); | ||
| 1169 | + } | ||
| 1170 | + | ||
| 1114 | /// The one way a library row reaches the timeline: the Add button and a row | 1171 | /// The one way a library row reaches the timeline: the Add button and a row |
| 1115 | /// dragged onto a lane both come here, so there is a single answer to what | 1172 | /// dragged onto a lane both come here, so there is a single answer to what |
| 1116 | /// "add this source" does. The whole source goes in at the playhead as one | 1173 | /// "add this source" does. The whole source goes in at the playhead as one |
| @@ -3437,6 +3494,13 @@ impl Player { | |||
| 3437 | this.insert_source(&drag.0.clone(), drag.1, Some(lane), cx) | 3494 | this.insert_source(&drag.0.clone(), drag.1, Some(lane), cx) |
| 3438 | })) | 3495 | })) |
| 3439 | .drag_over::<AssetDrag>(|s, _, _, _| s.bg(rgb(HOVER_DIM))) | 3496 | .drag_over::<AssetDrag>(|s, _, _, _| s.bg(rgb(HOVER_DIM))) |
| 3497 | + // A clip let go over another lane changes track and keeps | ||
| 3498 | + // the frames it covers -- the pointer's position along the | ||
| 3499 | + // bed says nothing here either, for the reason above. | ||
| 3500 | + .on_drop(cx.listener(move |this, drag: &ClipDrag, _, cx| { | ||
| 3501 | + this.move_clip(drag.lane, drag.idx, lane, cx) | ||
| 3502 | + })) | ||
| 3503 | + .drag_over::<ClipDrag>(|s, _, _, _| s.bg(rgb(HOVER_DIM))) | ||
| 3440 | .children(clips.iter().enumerate().map(|(i, clip)| { | 3504 | .children(clips.iter().enumerate().map(|(i, clip)| { |
| 3441 | let (start, len) = ( | 3505 | let (start, len) = ( |
| 3442 | f64::from(clip.start) / self.fps, | 3506 | f64::from(clip.start) / self.fps, |
| @@ -3467,6 +3531,12 @@ impl Player { | |||
| 3467 | f64::from(clip.out_frame) / self.fps, | 3531 | f64::from(clip.out_frame) / self.fps, |
| 3468 | ); | 3532 | ); |
| 3469 | let tip = tip.clone(); | 3533 | let tip = tip.clone(); |
| 3534 | + // What the pointer carries on the way to another lane: | ||
| 3535 | + // the file the box is showing, the same ghost a library | ||
| 3536 | + // row makes. A box too narrow for its own label still | ||
| 3537 | + // says what is moving. | ||
| 3538 | + let ghost: SharedString = | ||
| 3539 | + label.clone().unwrap_or_else(|| lane.label()).into(); | ||
| 3470 | div() | 3540 | div() |
| 3471 | // Named per lane: two rows numbering their clips | 3541 | // Named per lane: two rows numbering their clips |
| 3472 | // from zero would hand gpui the same id twice. | 3542 | // from zero would hand gpui the same id twice. |
| @@ -3490,6 +3560,13 @@ impl Player { | |||
| 3490 | .cursor_pointer() | 3560 | .cursor_pointer() |
| 3491 | .hover(|s| s.border_color(rgb(ACCENT))) | 3561 | .hover(|s| s.border_color(rgb(ACCENT))) |
| 3492 | .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) | 3562 | .tooltip(move |_, cx| cx.new(|_| Tip(tip.clone())).into()) |
| 3563 | + // Dragged onto another lane it *moves* there; the | ||
| 3564 | + // click that starts the drag still selects, so | ||
| 3565 | + // picking a clip up and putting it back down where | ||
| 3566 | + // it was is exactly a click. | ||
| 3567 | + .on_drag(ClipDrag { lane, idx: i }, move |_, _, _, cx| { | ||
| 3568 | + cx.new(|_| Tip(ghost.clone())) | ||
| 3569 | + }) | ||
| 3493 | .on_mouse_down( | 3570 | .on_mouse_down( |
| 3494 | MouseButton::Left, | 3571 | MouseButton::Left, |
| 3495 | cx.listener(move |this, _: &MouseDownEvent, _, cx| { | 3572 | cx.listener(move |this, _: &MouseDownEvent, _, cx| { |
| @@ -5102,6 +5179,48 @@ mod tests { | |||
| 5102 | ); | 5179 | ); |
| 5103 | } | 5180 | } |
| 5104 | 5181 | ||
| 5182 | + /// The move-a-clip-between-tracks path through the door the drop uses | ||
| 5183 | + /// ([`Player::move_clip`] calls exactly this): the clip changes row, the | ||
| 5184 | + /// *picture* comes from the new row afterwards -- which is what "it plays | ||
| 5185 | + /// from there" means -- and one undo puts it back. | ||
| 5186 | + #[test] | ||
| 5187 | + fn a_clip_dragged_onto_another_track_plays_from_it() { | ||
| 5188 | + use engine::project::LaneKind; | ||
| 5189 | + | ||
| 5190 | + let mut session = PlaybackSession::open(asset("test_av.mp4")).expect("open the fixture"); | ||
| 5191 | + session.set_gain(0.0); | ||
| 5192 | + let v2 = session.add_lane(LaneKind::Video); | ||
| 5193 | + assert_eq!(session.video_clip_at(0.0), Some((Lane::V1, 0))); | ||
| 5194 | + | ||
| 5195 | + assert!(session.move_clip_to_lane(Lane::V1, 0, v2), "V1 -> V2"); | ||
| 5196 | + assert!(session.lane_clips(Lane::V1).is_empty(), "it left V1"); | ||
| 5197 | + assert_eq!(session.lane_clips(v2).len(), 1, "and landed on V2"); | ||
| 5198 | + assert_eq!( | ||
| 5199 | + session.video_clip_at(0.0), | ||
| 5200 | + Some((v2, 0)), | ||
| 5201 | + "the picture now comes from V2" | ||
| 5202 | + ); | ||
| 5203 | + assert_eq!(session.lane_clips(Lane::A1).len(), 1, "its sound stayed"); | ||
| 5204 | + | ||
| 5205 | + // Dropped on a lane of the other kind it is refused and nothing moves -- | ||
| 5206 | + // the notice the front-end shows for it says which kind of lane to use. | ||
| 5207 | + // (The other refusal, landing on another clip, is the engine's own test | ||
| 5208 | + // `move_to_lane_keeps_the_frames_and_refuses_the_rest`.) | ||
| 5209 | + assert!(!session.move_clip_to_lane(v2, 0, Lane::A1), "picture on A1"); | ||
| 5210 | + assert_eq!(session.lane_clips(v2).len(), 1, "and it stayed on V2"); | ||
| 5211 | + assert!( | ||
| 5212 | + session.move_clip_to_lane(v2, 0, Lane::V1), | ||
| 5213 | + "dragged back down" | ||
| 5214 | + ); | ||
| 5215 | + | ||
| 5216 | + // One undo per move, and each is a single step. | ||
| 5217 | + assert!(session.undo(), "the drag back"); | ||
| 5218 | + assert_eq!(session.video_clip_at(0.0), Some((v2, 0))); | ||
| 5219 | + assert!(session.undo(), "the drag up"); | ||
| 5220 | + assert_eq!(session.video_clip_at(0.0), Some((Lane::V1, 0))); | ||
| 5221 | + assert!(session.lane_clips(v2).is_empty()); | ||
| 5222 | + } | ||
| 5223 | + | ||
| 5105 | /// The add-a-track path end to end through the doors the buttons and the | 5224 | /// The add-a-track path end to end through the doors the buttons and the |
| 5106 | /// drop use: `+ V` adds a row, a library row let go over it lands there and | 5225 | /// drop use: `+ V` adds a row, a library row let go over it lands there and |
| 5107 | /// nowhere else, Delete on it leaves the lanes under it where they are, and | 5226 | /// nowhere else, Delete on it leaves the lanes under it where they are, and |
crates/engine/src/playback.rsmodified+10 -0
| @@ -581,6 +581,16 @@ impl PlaybackSession { | |||
| 581 | self.edit(|p| p.lift(lane, idx)) | 581 | self.edit(|p| p.lift(lane, idx)) |
| 582 | } | 582 | } |
| 583 | 583 | ||
| 584 | + /// Moves that clip onto another lane of the same kind, keeping the frames it | ||
| 585 | + /// covers -- the drag between tracks. One undo step, and it reseeks like | ||
| 586 | + /// every other edit: which lane a clip sits on is what the compositor's | ||
| 587 | + /// topmost-lane-wins rule reads, so the frame on screen is recomposed at | ||
| 588 | + /// once. `false` for a bad index, for a move across kinds and for one that | ||
| 589 | + /// would land on another clip; nothing changes. | ||
| 590 | + pub fn move_clip_to_lane(&mut self, from: Lane, idx: usize, to: Lane) -> bool { | ||
| 591 | + self.edit(|p| p.move_to_lane(from, idx, to)) | ||
| 592 | + } | ||
| 593 | + | ||
| 584 | /// The clip the picture is coming from at `timeline_secs`: the lane it sits | 594 | /// The clip the picture is coming from at `timeline_secs`: the lane it sits |
| 585 | /// on and its index there, by the same topmost-lane-wins rule the decoder | 595 | /// on and its index there, by the same topmost-lane-wins rule the decoder |
| 586 | /// follows. `None` over a gap and past the end. What a card that grades | 596 | /// follows. `None` over a gap and past the end. What a card that grades |
crates/engine/src/project.rsmodified+100 -0
| @@ -992,6 +992,45 @@ impl Project { | |||
| 992 | true | 992 | true |
| 993 | } | 993 | } |
| 994 | 994 | ||
| 995 | + /// Move the clip at `idx` of `from` onto `to`, keeping the timeline frames | ||
| 996 | + /// it covers: the drag that rearranges takes across tracks. One snapshot, so | ||
| 997 | + /// one [`Project::undo`] puts it back where it was. | ||
| 998 | + /// | ||
| 999 | + /// Its group id travels with it, and that is not a desync: a link means | ||
| 1000 | + /// "these cover one span on however many lanes" and names no lane at all | ||
| 1001 | + /// (see [`links_are_consistent`]), so a picture moved from `V1` to `V2` is | ||
| 1002 | + /// still the same take as the sound under it. The span never changes here -- | ||
| 1003 | + /// only which lane draws it. | ||
| 1004 | + /// | ||
| 1005 | + /// Refused, changing nothing, for a lane that is not there, an index that is | ||
| 1006 | + /// not there, a move onto the lane it is already on, a move across *kinds* | ||
| 1007 | + /// (a picture cannot play on an audio lane, and the save it wrote would not | ||
| 1008 | + /// open again), and a landing that would touch another clip -- a move that | ||
| 1009 | + /// overwrote what it landed on would destroy a take the pointer never named, | ||
| 1010 | + /// which is what [`place`](Project::place) may do and a drag may not. | ||
| 1011 | + pub fn move_to_lane(&mut self, from: Lane, idx: usize, to: Lane) -> bool { | ||
| 1012 | + if from.kind != to.kind || from == to || self.index(to).is_none() { | ||
| 1013 | + return false; | ||
| 1014 | + } | ||
| 1015 | + let Some(clip) = self.lane(from).get(idx).copied() else { | ||
| 1016 | + return false; | ||
| 1017 | + }; | ||
| 1018 | + if self | ||
| 1019 | + .lane(to) | ||
| 1020 | + .iter() | ||
| 1021 | + .any(|c| c.start < clip.end() && clip.start < c.end()) | ||
| 1022 | + { | ||
| 1023 | + return false; | ||
| 1024 | + } | ||
| 1025 | + self.snapshot(); | ||
| 1026 | + self.lane_mut(from).expect("checked above").remove(idx); | ||
| 1027 | + let clips = self.lane_mut(to).expect("checked above"); | ||
| 1028 | + let at = clips.partition_point(|c| c.start < clip.start); | ||
| 1029 | + clips.insert(at, clip); | ||
| 1030 | + debug_assert!(sorted_disjoint(clips)); | ||
| 1031 | + true | ||
| 1032 | + } | ||
| 1033 | + | ||
| 995 | /// Insert `clip` into the first lane of each kind at `timeline_frame` as one | 1034 | /// Insert `clip` into the first lane of each kind at `timeline_frame` as one |
| 996 | /// new group, pushing everything from there on later by its length in | 1035 | /// new group, pushing everything from there on later by its length in |
| 997 | /// *every* lane -- the grouped, rippling paste a clipboard does. Mid-clip | 1036 | /// *every* lane -- the grouped, rippling paste a clipboard does. Mid-clip |
| @@ -2012,6 +2051,67 @@ mod tests { | |||
| 2012 | assert!(!p.place(Lane::V1, 0, clip(0, 7, 7, 0)), "empty clip"); | 2051 | assert!(!p.place(Lane::V1, 0, clip(0, 7, 7, 0)), "empty clip"); |
| 2013 | } | 2052 | } |
| 2014 | 2053 | ||
| 2054 | + /// The drag between tracks: the clip keeps its frames, one undo takes it | ||
| 2055 | + /// back, and every way it can be refused leaves the project untouched. | ||
| 2056 | + #[test] | ||
| 2057 | + fn move_to_lane_keeps_the_frames_and_refuses_the_rest() { | ||
| 2058 | + let v2 = Lane::new(LaneKind::Video, 1); | ||
| 2059 | + let mut p = three(); | ||
| 2060 | + assert_eq!(p.add_lane(LaneKind::Video), v2); | ||
| 2061 | + let before = shape(&p); | ||
| 2062 | + | ||
| 2063 | + assert!(p.move_to_lane(Lane::V1, 1, v2), "V1's middle clip moves up"); | ||
| 2064 | + assert_eq!(shape(&p)[0], vec![clip(0, 0, 3, 0), clip(5, 5, 9, 0)]); | ||
| 2065 | + assert_eq!(shape(&p)[2], vec![clip(3, 3, 5, 0)], "same frames on V2"); | ||
| 2066 | + assert_eq!(shape(&p)[1], before[1], "the audio lane is untouched"); | ||
| 2067 | + assert_eq!(p.timeline_frames(), 9, "a move is not an insert"); | ||
| 2068 | + // One snapshot: a single undo, and the lane list survives it. | ||
| 2069 | + assert!(p.undo()); | ||
| 2070 | + assert_eq!(shape(&p), before); | ||
| 2071 | + | ||
| 2072 | + // A lane that is not there, the lane it is already on, an index that is | ||
| 2073 | + // not there, and a move across kinds: all refused, nothing changed. | ||
| 2074 | + let history = p.history.len(); | ||
| 2075 | + for (from, idx, to) in [ | ||
| 2076 | + (Lane::V1, 1, Lane::new(LaneKind::Video, 7)), | ||
| 2077 | + (Lane::V1, 1, Lane::V1), | ||
| 2078 | + (Lane::V1, 9, v2), | ||
| 2079 | + (Lane::V1, 1, Lane::A1), | ||
| 2080 | + (Lane::A1, 1, v2), | ||
| 2081 | + ] { | ||
| 2082 | + assert!(!p.move_to_lane(from, idx, to), "{from:?} {idx} -> {to:?}"); | ||
| 2083 | + } | ||
| 2084 | + assert_eq!(shape(&p), before); | ||
| 2085 | + assert_eq!(p.history.len(), history, "a refusal snapshots nothing"); | ||
| 2086 | + | ||
| 2087 | + // Landing on another clip is refused rather than overwriting it: the | ||
| 2088 | + // pointer named the lane, never the take already sitting there. | ||
| 2089 | + assert!(p.place(v2, 3, clip(0, 100, 101, 0)), "V2 holds [3,4)"); | ||
| 2090 | + assert!(!p.move_to_lane(Lane::V1, 1, v2), "[3,5) would land on it"); | ||
| 2091 | + assert!(p.move_to_lane(Lane::V1, 0, v2), "[0,3) merely abuts it"); | ||
| 2092 | + assert_eq!(shape(&p)[0], vec![clip(3, 3, 5, 0), clip(5, 5, 9, 0)]); | ||
| 2093 | + assert_eq!(shape(&p)[2], vec![clip(0, 0, 3, 0), clip(3, 100, 101, 0)]); | ||
| 2094 | + } | ||
| 2095 | + | ||
| 2096 | + /// A moved half stays in its group: a link names a span, not a lane, so the | ||
| 2097 | + /// picture on `V2` is still the same take as the sound under it on `A1`. | ||
| 2098 | + #[test] | ||
| 2099 | + fn move_to_lane_keeps_the_group() { | ||
| 2100 | + let v2 = Lane::new(LaneKind::Video, 1); | ||
| 2101 | + let mut p = three(); | ||
| 2102 | + p.add_lane(LaneKind::Video); | ||
| 2103 | + let link = p.lane(Lane::V1)[1].link.expect("a split hands out ids"); | ||
| 2104 | + assert_eq!(p.lane(Lane::A1)[1].link, Some(link), "both halves grouped"); | ||
| 2105 | + assert!(p.move_to_lane(Lane::V1, 1, v2)); | ||
| 2106 | + assert_eq!(p.lane(v2)[0].link, Some(link), "the id travelled with it"); | ||
| 2107 | + links_are_consistent(&p.lanes).expect("one id per lane, one span"); | ||
| 2108 | + assert_eq!( | ||
| 2109 | + p.lane(v2)[0].start, | ||
| 2110 | + p.lane(Lane::A1)[1].start, | ||
| 2111 | + "and still covers the same span as its sound" | ||
| 2112 | + ); | ||
| 2113 | + } | ||
| 2114 | + | ||
| 2015 | #[test] | 2115 | #[test] |
| 2016 | fn ripple_delete_spans_partial_clips() { | 2116 | fn ripple_delete_spans_partial_clips() { |
| 2017 | let mut p = three(); | 2117 | let mut p = three(); |