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.
159 | `lift`, `fade`, `dissolve`, `transition`, `crossfade`, `gain`, `color`, `transform`, `fit`, `eq`, `sub_trim`, `sub_delete`, `cue_text` | clip | act on the one clip named |159 | `lift`, `fade`, `dissolve`, `transition`, `crossfade`, `gain`, `color`, `transform`, `fit`, `eq`, `sub_trim`, `sub_delete`, `cue_text` | clip | act on the one clip named |
160 | `split` | all lanes (or `lanes`) | a cut, not a ripple: nothing moves. `lanes` limits which lanes are cut; a linked partner follows its clip |160 | `split` | all lanes (or `lanes`) | a cut, not a ripple: nothing moves. `lanes` limits which lanes are cut; a linked partner follows its clip |
161 | `regroup` | all lanes | `regroup {at}` rejoins the clips that meet at `at` and groups them again: the inverse of `split`, metadata only |161 | `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 |
163 | `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` |163 | `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` |
164 | `solo` | — | `solo {lane, on}` for an audio lane: monitoring only, not project state, not saved, never exported, no undo step |164 | `solo` | — | `solo {lane, on}` for an audio lane: monitoring only, not project state, not saved, never exported, no undo step |
165 | `close_gaps` | one lane | closes the gaps on that lane only |165 | `close_gaps` | one lane | closes the gaps on that lane only |
crates/engine/src/project.rsmodified+89 -14
@@ -7971,7 +7971,9 @@ impl Project {
7971 /// so the clip list comes back exactly as it was and traversal with it.7971 /// so the clip list comes back exactly as it was and traversal with it.
7972 /// `false` when no lane has such a pair. The rejoined placement keeps the7972 /// `false` when no lane has such a pair. The rejoined placement keeps the
7973 /// **left** half's id, which is the take the split left on it: rejoining a7973 /// **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.
7975 pub fn regroup(&mut self, timeline_frame: u32) -> bool {7977 pub fn regroup(&mut self, timeline_frame: u32) -> bool {
7976 // What each lane would end up covering, if it joins here at all.7978 // What each lane would end up covering, if it joins here at all.
7977 let joined: Vec<Option<(u32, u32)>> = self7979 let joined: Vec<Option<(u32, u32)>> = self
@@ -8010,10 +8012,10 @@ impl Project {
8010 let Some(idx) = joinable(&data.clips, timeline_frame) else {8012 let Some(idx) = joinable(&data.clips, timeline_frame) else {
8011 continue;8013 continue;
8012 };8014 };
8013- match data.clips[idx].reversed {8015+ let Some(joined) = joined_clip(&data.clips[idx], &data.clips[idx + 1]) else {
8014- true => data.clips[idx].in_frame = data.clips[idx + 1].in_frame,8016+ continue;
8015- false => data.clips[idx].out_frame = data.clips[idx + 1].out_frame,8017+ };
8016- }8018+ data.clips[idx] = joined;
8017 data.clips.remove(idx + 1);8019 data.clips.remove(idx + 1);
8018 }8020 }
8019 true8021 true
@@ -11549,24 +11551,97 @@ pub fn ramp_keys_until(keys: &[SpeedKey], cut: u32) -> Vec<SpeedKey> {
11549 fn joinable(clips: &[Clip], frame: u32) -> Option<usize> {11551 fn joinable(clips: &[Clip], frame: u32) -> Option<usize> {
11550 let idx = clips.iter().position(|c| c.end() == frame)?;11552 let idx = clips.iter().position(|c| c.end() == frame)?;
11551 let next = clips.get(idx + 1)?;11553 let next = clips.get(idx + 1)?;
11552- let joined = clips[idx].len() + next.len();11554+ let left = &clips[idx];
11553 (next.start == frame11555 (next.start == frame
11554- && next.source == clips[idx].source11556+ && next.source == left.source
11555- && next.reversed == clips[idx].reversed11557+ && next.reversed == left.reversed
11556- && match clips[idx].reversed {11558+ && match left.reversed {
11557 // The halves of a reversed cut swap sides: the head holds the window's11559 // The halves of a reversed cut swap sides: the head holds the window's
11558 // upper part.11560 // upper part.
11559- true => clips[idx].in_frame == next.out_frame,11561+ true => left.in_frame == next.out_frame,
11560- false => next.in_frame == clips[idx].out_frame,11562+ false => next.in_frame == left.out_frame,
11561 }11563 }
11562 // ...at one rate, and one that puts the rejoined clip back in exactly11564 // ...at one rate, and one that puts the rejoined clip back in exactly
11563 // the room the two took up: what a split could have produced, which is11565 // the room the two took up: what a split could have produced, which is
11564- // all this undoes.11566+ // all this undoes. A ramp is held to the same test, on its own keys.
11565- && next.speed == clips[idx].speed11567+ && next.speed == left.speed
11566- && clips[idx].speed.frames(joined) == clips[idx].frames() + next.frames())11568+ && joined_clip(left, next).is_some_and(|j| j.frames() == left.frames() + next.frames()))
11567 .then_some(idx)11569 .then_some(idx)
11568 }11570 }
11569 11571
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+
11570 /// The lane invariant: sorted by `start`, no two placements overlapping, no11645 /// The lane invariant: sorted by `start`, no two placements overlapping, no
11571 /// empty placement. Checked at every constructor and asserted after every11646 /// empty placement. Checked at every constructor and asserted after every
11572 /// mutation -- the offset model is only tractable while it holds.11647 /// mutation -- the offset model is only tractable while it holds.
crates/mcp/src/tools/edit.rsmodified+36 -4
@@ -98,7 +98,7 @@ TIME
98 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.98 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.
99 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.99 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.
100 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).100 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.
102 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.102 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.
103 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.103 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.
104 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.104 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
4809 fn op_regroup(s: &mut PlaybackSession, op: &Value, fps: f64, end: u32) -> Result<Done, String> {4809 fn op_regroup(s: &mut PlaybackSession, op: &Value, fps: f64, end: u32) -> Result<Done, String> {
4810 let at = need(op, "at", fps, end)?;4810 let at = need(op, "at", fps, end)?;
4811 let shown = shown_time(op.get("at"), at);4811 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();
4812 if !s.regroup_at(parse::secs(at, fps)) {4815 if !s.regroup_at(parse::secs(at, fps)) {
4813 return Err(format!(4816 return Err(format!(
4814 "regroup {shown}: nothing to rejoin there; no cut sits at that frame, or the clips on it were never split apart"4817 "regroup {shown}: nothing to rejoin there; no cut sits at that frame, or the clips on it were never split apart"
4815 ));4818 ));
4816 }4819 }
4817- let lanes: Vec<Lane> = s.lanes().into_iter().filter(|&l| s.lane_clips(l).iter().any(|c| c.start == at)).collect();4820+ let mut lanes: Vec<Lane> = Vec::new();
4818- let touched = lanes.iter().map(|&l| (l, at)).collect();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+ }
4819 let names: Vec<String> = lanes.iter().map(|&l| parse::lane_name(l)).collect();4835 let names: Vec<String> = lanes.iter().map(|&l| parse::lane_name(l)).collect();
4820 Ok(Done { text: format!("regroup {shown}: the cut is rejoined on {}", names.join(", ")), touched, lanes })4836 Ok(Done { text: format!("regroup {shown}: the cut is rejoined on {}", names.join(", ")), touched, lanes })
4821 }4837 }
4822 4838
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+
4823 /// `solo {lane, on}`: solos an audio lane for listening, so only the soloed lanes are heard while this4844 /// `solo {lane, on}`: solos an audio lane for listening, so only the soloed lanes are heard while this
4824 /// session plays. Solo is monitoring only: it is not project state, it is not saved, and an export never4845 /// session plays. Solo is monitoring only: it is not project state, it is not saved, and an export never
4825 /// reads it, so it leaves no undo step and marks nothing changed.4846 /// 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
4937 }4958 }
4938 let addrs: Vec<String> = landed.iter().map(|&(l, start)| parse::addr(l, start)).collect();4959 let addrs: Vec<String> = landed.iter().map(|&(l, start)| parse::addr(l, start)).collect();
4939 let effects = side_effects(&shape_before, &shape(s), "copy_paste");4960 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+ };
4941 if !effects.is_empty() {4973 if !effects.is_empty() {
4942 text.push_str(&format!("; effects: {}", effects.join("; ")));4974 text.push_str(&format!("; effects: {}", effects.join("; ")));
4943 }4975 }