forge
Explore
Log in

Don't you dare go Hollow

🐛 Regroup keeps the right half's keys, ramp and end edge; MCP regroup names its lanes and copy_paste says a paste past the end appends

Browse files at this commit

d1444454fe7b735179f69a0b8c2aa28da1ccfdcbAhmet Kaan GümüşParent: 8e0ee9c
MCP.mdmodified+1 -1
@@ -159,7 +159,7 @@ in the GUI. Ops take `scope: "group" | "clip"` where it matters.
159159 | `lift`, `fade`, `dissolve`, `transition`, `crossfade`, `gain`, `color`, `transform`, `fit`, `eq`, `sub_trim`, `sub_delete`, `cue_text` | clip | act on the one clip named |
160160 | `split` | all lanes (or `lanes`) | a cut, not a ripple: nothing moves. `lanes` limits which lanes are cut; a linked partner follows its clip |
161161 | `regroup` | all lanes | `regroup {at}` rejoins the clips that meet at `at` and groups them again: the inverse of `split`, metadata only |
162-| `copy_paste` | the copied clips | `copy_paste {clips:[addr…], at, lane?}`: one clip pastes as the GUI paste does (splits and ripples the room open); several, or any with `lane`, land as one set and are refused whole if they would overlap. Copies that were one take (a picture and its sound) come back as one new take; a copy whose partner was not copied comes back unlinked. A `lane` override keeps a take only where its members land on different lanes |
162+| `copy_paste` | the copied clips | `copy_paste {clips:[addr…], at, lane?}`: one clip pastes as the GUI paste does (splits and ripples the room open); several, or any with `lane`, land as one set and are refused whole if they would overlap. A paste past the end appends at the end, and the reply says where the copies landed. Copies that were one take (a picture and its sound) come back as one new take; a copy whose partner was not copied comes back unlinked. A `lane` override keeps a take only where its members land on different lanes |
163163 | `close_gap` | the gap's take | `close_gap {lane, at}` closes the one gap on `lane` that `at` stands in (the GUI's Close gap); a linked take's other lane closes with it. Captions use `close_gaps` |
164164 | `solo` | — | `solo {lane, on}` for an audio lane: monitoring only, not project state, not saved, never exported, no undo step |
165165 | `close_gaps` | one lane | closes the gaps on that lane only |
crates/engine/src/project.rsmodified+89 -14
@@ -7971,7 +7971,9 @@ impl Project {
79717971 /// so the clip list comes back exactly as it was and traversal with it.
79727972 /// `false` when no lane has such a pair. The rejoined placement keeps the
79737973 /// **left** half's id, which is the take the split left on it: rejoining a
7974- /// cut take puts the take back, id and all.
7974+ /// cut take puts the take back, id and all. Its animation is both halves'
7975+ /// keys merged, so the right half's keys after the cut come back with it; a
7976+ /// lane whose merged animation would not fit is left as it is.
79757977 pub fn regroup(&mut self, timeline_frame: u32) -> bool {
79767978 // What each lane would end up covering, if it joins here at all.
79777979 let joined: Vec<Option<(u32, u32)>> = self
@@ -8010,10 +8012,10 @@ impl Project {
80108012 let Some(idx) = joinable(&data.clips, timeline_frame) else {
80118013 continue;
80128014 };
8013- match data.clips[idx].reversed {
8014- true => data.clips[idx].in_frame = data.clips[idx + 1].in_frame,
8015- false => data.clips[idx].out_frame = data.clips[idx + 1].out_frame,
8016- }
8015+ let Some(joined) = joined_clip(&data.clips[idx], &data.clips[idx + 1]) else {
8016+ continue;
8017+ };
8018+ data.clips[idx] = joined;
80178019 data.clips.remove(idx + 1);
80188020 }
80198021 true
@@ -11549,24 +11551,97 @@ pub fn ramp_keys_until(keys: &[SpeedKey], cut: u32) -> Vec<SpeedKey> {
1154911551 fn joinable(clips: &[Clip], frame: u32) -> Option<usize> {
1155011552 let idx = clips.iter().position(|c| c.end() == frame)?;
1155111553 let next = clips.get(idx + 1)?;
11552- let joined = clips[idx].len() + next.len();
11554+ let left = &clips[idx];
1155311555 (next.start == frame
11554- && next.source == clips[idx].source
11555- && next.reversed == clips[idx].reversed
11556- && match clips[idx].reversed {
11556+ && next.source == left.source
11557+ && next.reversed == left.reversed
11558+ && match left.reversed {
1155711559 // The halves of a reversed cut swap sides: the head holds the window's
1155811560 // upper part.
11559- true => clips[idx].in_frame == next.out_frame,
11560- false => next.in_frame == clips[idx].out_frame,
11561+ true => left.in_frame == next.out_frame,
11562+ false => next.in_frame == left.out_frame,
1156111563 }
1156211564 // ...at one rate, and one that puts the rejoined clip back in exactly
1156311565 // the room the two took up: what a split could have produced, which is
11564- // all this undoes.
11565- && next.speed == clips[idx].speed
11566- && clips[idx].speed.frames(joined) == clips[idx].frames() + next.frames())
11566+ // all this undoes. A ramp is held to the same test, on its own keys.
11567+ && next.speed == left.speed
11568+ && joined_clip(left, next).is_some_and(|j| j.frames() == left.frames() + next.frames()))
1156711569 .then_some(idx)
1156811570 }
1156911571
11572+/// The clip that two halves of one cut rejoin into: `left` extended to the end of
11573+/// `right`, with the animation both halves hold merged ([`merge_keys`]) and the
11574+/// right half's end edge kept (its `fade_out` and dissolve), which a split takes
11575+/// away from the left half. The speed ramp is [`joined_speed_keys`]. `None` when
11576+/// the merged animation would not fit or is not a ramp the engine plays.
11577+fn joined_clip(left: &Clip, right: &Clip) -> Option<Clip> {
11578+ let mut out = left.clone();
11579+ out.speed_keys = joined_speed_keys(left, right)?;
11580+ out.transform_keys =
11581+ merge_keys(&left.transform_keys, &right.transform_keys, |k| k.at, MAX_TRANSFORM_KEYS)?;
11582+ out.opacity_keys =
11583+ merge_keys(&left.opacity_keys, &right.opacity_keys, |k| k.at, MAX_TRANSFORM_KEYS)?;
11584+ out.color_keys = merge_keys(&left.color_keys, &right.color_keys, |k| k.at, MAX_COLOR_KEYS)?;
11585+ out.gain_keys = merge_keys(&left.gain_keys, &right.gain_keys, |k| k.at, MAX_GAIN_KEYS)?;
11586+ // Effects are matched by stack slot, and only when both halves carry the same
11587+ // stack; otherwise the left half's effects stand as they are.
11588+ let same_stack = left.effects.len() == right.effects.len()
11589+ && left.effects.iter().zip(&right.effects).all(|(l, r)| l.kind == r.kind);
11590+ if same_stack {
11591+ for (e, r) in out.effects.iter_mut().zip(&right.effects) {
11592+ e.keys = merge_keys(&e.keys, &r.keys, |k| k.at, MAX_TRANSFORM_KEYS)?;
11593+ }
11594+ }
11595+ out.fade_out = right.fade_out;
11596+ out.transition_out = right.transition_out;
11597+ out.transition_kind = right.transition_kind;
11598+ match left.reversed {
11599+ true => out.in_frame = right.in_frame,
11600+ false => out.out_frame = right.out_frame,
11601+ }
11602+ Some(out)
11603+}
11604+
11605+/// The keys of one animation, both halves of a cut joined: the left half's keys,
11606+/// then the right half's keys whose source frame the left does not already hold
11607+/// (the cut is a key on both halves, so it is kept once), sorted by frame. Keys
11608+/// are source frames on both sides, so the union is the same whichever half
11609+/// comes first. `None` when the union holds more than `cap` keys.
11610+fn merge_keys<K: Clone>(
11611+ left: &[K],
11612+ right: &[K],
11613+ at: impl Fn(&K) -> u32,
11614+ cap: usize,
11615+) -> Option<Vec<K>> {
11616+ let mut out = left.to_vec();
11617+ out.extend(right.iter().filter(|r| left.iter().all(|l| at(l) != at(r))).cloned());
11618+ out.sort_by_key(|k| at(k));
11619+ (out.len() <= cap).then_some(out)
11620+}
11621+
11622+/// The speed ramp of two rejoined halves ([`Clip::speed_keys`]). Ramp keys count
11623+/// clip-relative timeline frames, so the right half's keys move on by the left
11624+/// half's timeline length and the left's last key and the right's first are the
11625+/// same cut, kept once. Two constant halves have no ramp; one ramped half and one
11626+/// constant half, or a reversed ramp (which no split makes), do not join. `None`
11627+/// when the joined keys are not a ramp the engine plays.
11628+fn joined_speed_keys(left: &Clip, right: &Clip) -> Option<Vec<SpeedKey>> {
11629+ match (left.speed_keys.is_empty(), right.speed_keys.is_empty()) {
11630+ (true, true) => return Some(Vec::new()),
11631+ (false, false) if !left.reversed => {}
11632+ _ => return None,
11633+ }
11634+ let off = left.frames();
11635+ let mut keys = left.speed_keys.clone();
11636+ for k in &right.speed_keys {
11637+ let at = k.at + off;
11638+ if keys.last().map_or(true, |l| l.at < at) {
11639+ keys.push(SpeedKey { at, speed: k.speed });
11640+ }
11641+ }
11642+ valid_speed_keys(&keys).then_some(keys)
11643+}
11644+
1157011645 /// The lane invariant: sorted by `start`, no two placements overlapping, no
1157111646 /// empty placement. Checked at every constructor and asserted after every
1157211647 /// mutation -- the offset model is only tractable while it holds.
crates/mcp/src/tools/edit.rsmodified+36 -4
@@ -98,7 +98,7 @@ TIME
9898 speed {clip, x, ripple?, lanes?} — rate 0.25..4. [group] Its length changes, so a neighbour in its way refuses; ripple:true moves the later items in the RIPPLE RULE scope (titles too) by the length change: slower pushes them later, faster closes the gap. A clip on another lane that spans the change is never cut: outside the scope it is left in place and the reply names it; a scope lane (named in lanes) that holds one refuses, naming it. One undo step.
9999 speed_ramp {clip, keys:[{at, speed}...], ripple?, lanes?} [group] — a speed that changes over the clip: each key sets a speed 0.25–4 at a clip-relative time `at` ("0s", "2s", "end" or frames), linear between keys and held before the first and after the last. Keys must be in increasing `at`, at most 8, and keys:[] clears the ramp back to the clip's constant speed. The clip's length follows the ramp, and ripple:true moves the later items as speed does. preset:"speed_up"|"slow_down"|"fast_middle"|"slow_middle" lays one of the speed card's shapes across the clip's length instead of keys (speed_up: 1x to 2x; slow_down: 2x to 1x; fast_middle: slow–fast–slow; slow_middle: fast–slow–fast); not with keys.
100100 regroup {at} — rejoins the clips that meet at `at` in every lane and puts them back in one group: the inverse of split (metadata only, one undo step; refused when no cut sits there).
101-copy_paste {clips:[addr,...], at, lane?} — pastes copies of the named clips at `at`, with their effects, keys and volume, keeping their spacing. One clip splits and ripples the room open as the GUI's paste does; several (or any with `lane`) land as one set on their own lanes, refused whole when a landing would overlap. `lane` puts every copy on that lane (the same kind, V or A, as each copy). Links come back among the copies: copied clips that were one take (a picture and its sound, say) land as one new take, while a clip whose partner was not copied comes back unlinked. A set with a `lane` override keeps a take only where its members land on different lanes.
101+copy_paste {clips:[addr,...], at, lane?} — pastes copies of the named clips at `at`, with their effects, keys and volume, keeping their spacing. A paste past the end appends at the end, and the reply says where the copies landed. One clip splits and ripples the room open as the GUI's paste does; several (or any with `lane`) land as one set on their own lanes, refused whole when a landing would overlap. `lane` puts every copy on that lane (the same kind, V or A, as each copy). Links come back among the copies: copied clips that were one take (a picture and its sound, say) land as one new take, while a clip whose partner was not copied comes back unlinked. A set with a `lane` override keeps a take only where its members land on different lanes.
102102 close_gap {lane, at} — closes the one gap on `lane` that `at` stands in (the GUI's Close gap): a gap that borders a linked take closes with the take's other lane too; nothing else moves. Refused for a clip at `at`, the time past the lane's last clip, and the empty lead-in before its first clip. Captions use close_gaps.
103103 solo {lane, on} — solos an audio lane for listening: while any is soloed, the other audio lanes are silent in this session's playback. It is monitoring only: not project state, not saved, never exported, and it leaves no undo step.
104104 reverse {clip, on?} — the clip plays backward, picture and sound: on true/false, or omit `on` to toggle. [group] Its length and place do not change, so nothing ripples, and it composes with speed and a speed ramp. Fades stay on the timeline's ends and gain and transform keys keep their time on the timeline. A trim, split or join follows the footage (a reversed clip's start edge trims its source's end). A still refuses. One undo step. clip_info and timeline say "reversed". Limits: a reversed clip decodes at 8 bits (a 10-bit source loses its low 2 bits on a 10-bit export; banding is possible on HDR), hardware decode is off for it, a dissolve's B side plays forward, and waveforms and thumbnails draw forward.
@@ -4809,17 +4809,38 @@ fn op_close_gap(s: &mut PlaybackSession, op: &Value, fps: f64, end: u32) -> Resu
48094809 fn op_regroup(s: &mut PlaybackSession, op: &Value, fps: f64, end: u32) -> Result<Done, String> {
48104810 let at = need(op, "at", fps, end)?;
48114811 let shown = shown_time(op.get("at"), at);
4812+ // A rejoin takes one placement out of each lane it joins, and the joined one no longer starts at
4813+ // `at`, so the lanes are the ones that lost a placement, counted before and after.
4814+ let before: Vec<(Lane, usize)> = s.lanes().into_iter().map(|l| (l, placements(s, l))).collect();
48124815 if !s.regroup_at(parse::secs(at, fps)) {
48134816 return Err(format!(
48144817 "regroup {shown}: nothing to rejoin there; no cut sits at that frame, or the clips on it were never split apart"
48154818 ));
48164819 }
4817- let lanes: Vec<Lane> = s.lanes().into_iter().filter(|&l| s.lane_clips(l).iter().any(|c| c.start == at)).collect();
4818- let touched = lanes.iter().map(|&l| (l, at)).collect();
4820+ let mut lanes: Vec<Lane> = Vec::new();
4821+ let mut touched: Vec<(Lane, u32)> = Vec::new();
4822+ for (l, n) in before {
4823+ if placements(s, l) >= n {
4824+ continue;
4825+ }
4826+ // The rejoined placement is the one that now covers the cut, and its new address is what a reply names.
4827+ let start = if l.kind == LaneKind::Subtitle {
4828+ s.sub_lane(l).iter().find(|c| c.start < at && at < c.start + c.frames).map(|c| c.start)
4829+ } else {
4830+ s.lane_clips(l).iter().find(|c| c.start < at && at < c.end()).map(|c| c.start)
4831+ };
4832+ lanes.push(l);
4833+ touched.extend(start.map(|st| (l, st)));
4834+ }
48194835 let names: Vec<String> = lanes.iter().map(|&l| parse::lane_name(l)).collect();
48204836 Ok(Done { text: format!("regroup {shown}: the cut is rejoined on {}", names.join(", ")), touched, lanes })
48214837 }
48224838
4839+/// How many placements a lane holds: its clips, or its captions for a subtitle lane.
4840+fn placements(s: &PlaybackSession, lane: Lane) -> usize {
4841+ if lane.kind == LaneKind::Subtitle { s.sub_lane(lane).len() } else { s.lane_clips(lane).len() }
4842+}
4843+
48234844 /// `solo {lane, on}`: solos an audio lane for listening, so only the soloed lanes are heard while this
48244845 /// session plays. Solo is monitoring only: it is not project state, it is not saved, and an export never
48254846 /// reads it, so it leaves no undo step and marks nothing changed.
@@ -4937,7 +4958,18 @@ fn op_copy_paste(s: &mut PlaybackSession, op: &Value, fps: f64, end: u32) -> Res
49374958 }
49384959 let addrs: Vec<String> = landed.iter().map(|&(l, start)| parse::addr(l, start)).collect();
49394960 let effects = side_effects(&shape_before, &shape(s), "copy_paste");
4940- let mut text = format!("copy_paste {} clip(s) at {shown}: pasted {}", items.len(), addrs.join(", "));
4961+ // A paste past the end is clamped to the end, so the copies append there; say so rather than
4962+ // print an asked frame the copies did not land on.
4963+ let mut text = if at > end {
4964+ format!(
4965+ "copy_paste {} clip(s) at {shown} is past the end, so the copies append at {:.3}s ({end}f): pasted {}",
4966+ items.len(),
4967+ parse::secs(end, fps),
4968+ addrs.join(", ")
4969+ )
4970+ } else {
4971+ format!("copy_paste {} clip(s) at {shown}: pasted {}", items.len(), addrs.join(", "))
4972+ };
49414973 if !effects.is_empty() {
49424974 text.push_str(&format!("; effects: {}", effects.join("; ")));
49434975 }