forge
Explore
Log in

Don't you dare go Hollow

✨ MCP: regroup, copy_paste, close_gap, solo ops; speed_ramp presets; cut_silence modes speed_up and keep_silence

Browse files at this commit

c439c14612e5d6e2402abd87f6b7d7cd5bd8da7aAhmet Kaan GümüşParent: b0e72a4
MCP.mdmodified+6 -2
@@ -152,12 +152,16 @@ in the GUI. Ops take `scope: "group" | "clip"` where it matters.
152152 | `move` | group | `to_lane` must be the same kind (V to V). A drop on empty frames lands exactly there, jumping over the clips between; a head that would land inside a clip stops short, and the reply says what was asked |
153153 | `delete` | group | closes the gap; a ripple (below) |
154154 | `speed` | group | |
155-| `speed_ramp` | group | `keys:[{at, speed}…]` (`[]` clears it); a ramp, not a constant rate |
155+| `speed_ramp` | group | `keys:[{at, speed}…]` (`[]` clears it); a ramp, not a constant rate. `preset:"speed_up"\|"slow_down"\|"fast_middle"\|"slow_middle"` lays the speed card's shape across the clip instead of `keys` |
156156 | `reverse` | group | `on?` (absent toggles); picture and sound play backward, length and place unchanged |
157157 | `sub_move` | group | captions |
158158 | `group` / `ungroup` | — | `group {clips:[…]}`, `ungroup {clip}` |
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 |
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. Each copy gets a new link, so group the halves of a copied take after |
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 |
161165 | `close_gaps` | one lane | closes the gaps on that lane only |
162166 | `delete`, `ripple_delete`, `cut_regions`, `insert_time`, `remove_time`, `speed` with `ripple:true`, `find_words` with `cut:true`, `cut_silence` | the ripple scope (below) | ripple ops: later items move |
163167 | `freeze` | one lane | `lane` defaults to V1; `insert` defaults to true |
@@ -284,7 +288,7 @@ with timecodes and the source's own frame count.
284288 | `scenes` | **source**, range (`{from, to}`, or the array form `[from, to]`), threshold=0.35, min_shot=0.6, sheet | shot list in source frames as `{from, to}` pairs, ready for `keep`: hard cuts and fades to black. Each boundary is the first frame of the new shot, exact to the frame; a fade through black is placed at the first picture frame after the dark run. A range gives the same boundaries as the whole file inside it. A clip address (`V1@450`) scans that clip's source within its span and adds timeline times. A source with no picture is refused. Cached per file and settings; `sheet:true` adds one contact-sheet image, saved in `~/.cache/edith/frames/<project>/` and named in the reply |
285289 | `levels` | **target**, range, per_sec=2 (a number: buckets per second, default 2, max 50) | RMS dBFS in 20 ms windows, grouped per second; text rows and a summary. Clip gain, its volume envelope and lane gain are included; fades and EQ are not |
286290 | `silence` | target, threshold_db, min_silence, padding, min_keep | quiet stretches as timeline frames, the same shape `cut_regions` takes. Clip gain, its envelope and lane gain are applied before judging; fades and EQ are not |
287-| `cut_silence` | target, threshold_db, min_silence, padding, min_keep, keep=0.4, lanes, force, dry_run | runs `silence`, then shortens every silence to `keep` seconds of pause inside its padded edges (a natural beat survives). The padding at each end is never cut, so the pause left is max(`keep`, 2 × `padding`), and the reply measures it. A silence at or under `keep` is left alone; when none is longer the reply says nothing was cut. A listed silence is at least `min_silence` with its padding counted; `min_keep` defaults to 0. One undo step. `lanes` default: the target's lane and its linked lanes; a mix target cuts every lane. A cut that would remove more than half the target's sound is refused unless `force`. With no target and two or more audio `lanes`, it is a joint cut: the silence is where every listed lane is quiet at once, so their turns stay in step. `src:N` is refused |
291+| `cut_silence` | target, threshold_db, min_silence, padding, min_keep, keep=0.4, lanes, force, dry_run, mode=cut\|speed_up\|keep_silence, rate=4 | `mode:"speed_up"` plays each silence at `rate` (1.05–4) instead of cutting it, as the GUI's speed silences do; `mode:"keep_silence"` cuts the speech and keeps the silence (one target, no joint cut), as keep-only silence does; both take no `keep`, and neither is limited by the more-than-half guard (`force` is for `cut`); `speed_up` leaves titles where they were. Default `mode:"cut"`: runs `silence`, then shortens every silence to `keep` seconds of pause inside its padded edges (a natural beat survives). The padding at each end is never cut, so the pause left is max(`keep`, 2 × `padding`), and the reply measures it. A silence at or under `keep` is left alone; when none is longer the reply says nothing was cut. A listed silence is at least `min_silence` with its padding counted; `min_keep` defaults to 0. One undo step. `lanes` default: the target's lane and its linked lanes; a mix target cuts every lane. A cut that would remove more than half the target's sound is refused unless `force`. With no target and two or more audio `lanes`, it is a joint cut: the silence is where every listed lane is quiet at once, so their turns stay in step. `src:N` is refused |
288292 | `loudness` | **target**, range | EBU R128: integrated LUFS, loudness range, true peak, max momentary and short-term. Clip and lane gain, clip speed, fades and EQ are included as played |
289293 | `clean_voice` | lane=A1, strength=medium (light, medium, strong), noise_from | gate + spectral noise reduction + compressor + de-esser on one audio lane, as one undo step. The noise profile is learned from `noise_from` (`{from, to}`) or, by default, the quietest half second of the lane; if none is found noise reduction is left off and the reply says so. The timeline, `clip_info` and `project_status` list the processors that are on |
290294 | `track` | clip, effect_index, from?, to?, direction?=forward\|backward, apply?=mask, cancel? | follows a rect or ellipse mask's box through a clip in the background (sub-pixel normalised cross-correlation, the template learned slowly); the mask's centre takes the feature's path, size and soft edge kept. from/to are clip-relative times, default the whole clip. Stops where the feature is lost (flat or line-only patch, or a rival match nearly as good) and says at which frame. Titles cannot be tracked (no keyable position). The path follows the clip's placement (position, scale, rotation, crop and transform keys). Not yet: a source stored turned (a phone's portrait video) or with non-square pixels is tracked as stored. `cancel:true` stops the clip's tracks |
crates/app/src/audio_cards.rsmodified+10 -10
@@ -68,17 +68,17 @@ impl RampPreset {
6868 /// The keys of the shape over a clip `frames` timeline frames long. `None` when the
6969 /// clip is too short to hold the shape's keys one frame apart.
7070 pub(crate) fn keys(self, frames: u32) -> Option<Vec<engine::project::SpeedKey>> {
71- let key = |at: u32, permille: u16| engine::project::SpeedKey {
72- at,
73- speed: Speed::from_permille(permille),
74- };
71+ self.shape().keys(frames)
72+ }
73+
74+ /// The engine's shape this chip lays: the same four, named there so the MCP can take them too.
75+ pub(crate) fn shape(self) -> engine::project::SpeedRampShape {
76+ use engine::project::SpeedRampShape as Shape;
7577 match self {
76- RampPreset::Up => (frames >= 1).then(|| vec![key(0, 1000), key(frames, 2000)]),
77- RampPreset::Down => (frames >= 1).then(|| vec![key(0, 2000), key(frames, 1000)]),
78- RampPreset::SlowFastSlow => (frames >= 2)
79- .then(|| vec![key(0, 500), key(frames / 2, 2000), key(frames, 500)]),
80- RampPreset::FastSlowFast => (frames >= 2)
81- .then(|| vec![key(0, 2000), key(frames / 2, 500), key(frames, 2000)]),
78+ RampPreset::Up => Shape::SpeedUp,
79+ RampPreset::Down => Shape::SlowDown,
80+ RampPreset::SlowFastSlow => Shape::FastMiddle,
81+ RampPreset::FastSlowFast => Shape::SlowMiddle,
8282 }
8383 }
8484 }
crates/app/src/player/editkeys.rsmodified+1 -1
@@ -66,7 +66,7 @@ pub(crate) fn gap_under(session: &PlaybackSession, frame: u32) -> Option<(Lane,
6666 .lanes()
6767 .into_iter()
6868 .filter(|l| l.kind != LaneKind::Subtitle)
69- .find_map(|l| crate::timeline_math::between_clips(session.gap_at(l, frame)).map(|(start, frames)| (l, start, frames)))
69+ .find_map(|l| session.closable_gap_at(l, frame).map(|(start, frames)| (l, start, frames)))
7070 }
7171
7272
crates/app/src/player/timeline_edit.rsmodified+2 -10
@@ -1718,16 +1718,8 @@ impl Player {
17181718 let Some(session) = self.session.as_mut() else {
17191719 return;
17201720 };
1721- let scope = match session.gap_take_scope(lane, start, frames) {
1722- Ok(scope) => scope,
1723- Err(e) => {
1724- self.notify_user(e.to_string().into());
1725- cx.notify();
1726- return;
1727- }
1728- };
1729- match session.cut_regions(&[(start, frames)], &scope) {
1730- Ok(()) => {
1721+ match session.close_gap_at(lane, start, frames) {
1722+ Ok(scope) => {
17311723 self.mark_dirty();
17321724 // The ripple moves every index after the gap on the scoped
17331725 // lanes, the same reason a delete drops the selection.
crates/engine/src/playback.rsmodified+17 -0
@@ -3266,6 +3266,23 @@ impl PlaybackSession {
32663266 self.project.gap_at(lane, frame)
32673267 }
32683268
3269+ /// The gap a Close gap verb closes on `lane` at `frame`: [`gap_at`](Self::gap_at), but
3270+ /// only a gap that starts after frame 0. A lead-in before a lane's first clip is empty
3271+ /// time, not a gap a hand made, so it is never closed.
3272+ pub fn closable_gap_at(&self, lane: Lane, frame: u32) -> Option<(u32, u32)> {
3273+ self.gap_at(lane, frame).filter(|&(start, _)| start > 0)
3274+ }
3275+
3276+ /// Closes the gap `(start, frames)` on `lane` and, when it borders a take, on the take's
3277+ /// other lane too: the scope [`gap_take_scope`](Self::gap_take_scope) names, cut out by
3278+ /// [`cut_regions`](Self::cut_regions). Returns that scope, so a caller can say what moved.
3279+ /// The `Err` names what is in the way and nothing changes.
3280+ pub fn close_gap_at(&mut self, lane: Lane, start: u32, frames: u32) -> crate::Result<Vec<Lane>> {
3281+ let scope = self.gap_take_scope(lane, start, frames)?;
3282+ self.cut_regions(&[(start, frames)], &scope)?;
3283+ Ok(scope)
3284+ }
3285+
32693286 /// How many bounded gaps that same right-click lane holds. The tail after
32703287 /// the last placement is not counted, because nothing would ripple there.
32713288 pub fn gap_count(&self, lane: Lane) -> usize {
crates/engine/src/project.rsmodified+50 -0
@@ -347,6 +347,56 @@ pub struct SpeedKey {
347347 pub speed: Speed,
348348 }
349349
350+/// The four ramp shapes a clip's speed can be laid in: the speed card and the palette lay them
351+/// across a clip's length, and the MCP `speed_ramp` takes them by name ([`SpeedRampShape::name`]).
352+#[derive(Clone, Copy, PartialEq, Eq, Debug)]
353+pub enum SpeedRampShape {
354+ /// Real time easing up to double.
355+ SpeedUp,
356+ /// Double easing down to real time.
357+ SlowDown,
358+ /// Slow, then fast through the middle, then slow: the classic speed ramp.
359+ FastMiddle,
360+ /// Fast, then slow through the middle, then fast: the hero shot.
361+ SlowMiddle,
362+}
363+
364+impl SpeedRampShape {
365+ /// Every shape, in the order the speed card shows them.
366+ pub const ALL: [SpeedRampShape; 4] = [
367+ SpeedRampShape::SpeedUp,
368+ SpeedRampShape::SlowDown,
369+ SpeedRampShape::FastMiddle,
370+ SpeedRampShape::SlowMiddle,
371+ ];
372+
373+ /// The shape's name as the MCP takes it: `speed_up`, `slow_down`, `fast_middle` or `slow_middle`.
374+ pub fn name(self) -> &'static str {
375+ match self {
376+ SpeedRampShape::SpeedUp => "speed_up",
377+ SpeedRampShape::SlowDown => "slow_down",
378+ SpeedRampShape::FastMiddle => "fast_middle",
379+ SpeedRampShape::SlowMiddle => "slow_middle",
380+ }
381+ }
382+
383+ /// The keys of the shape over a clip `frames` timeline frames long. `None` when the clip is
384+ /// too short to hold the shape's keys one frame apart.
385+ pub fn keys(self, frames: u32) -> Option<Vec<SpeedKey>> {
386+ let key = |at: u32, permille: u16| SpeedKey { at, speed: Speed::from_permille(permille) };
387+ match self {
388+ SpeedRampShape::SpeedUp => (frames >= 1).then(|| vec![key(0, 1000), key(frames, 2000)]),
389+ SpeedRampShape::SlowDown => (frames >= 1).then(|| vec![key(0, 2000), key(frames, 1000)]),
390+ SpeedRampShape::FastMiddle => {
391+ (frames >= 2).then(|| vec![key(0, 500), key(frames / 2, 2000), key(frames, 500)])
392+ }
393+ SpeedRampShape::SlowMiddle => {
394+ (frames >= 2).then(|| vec![key(0, 2000), key(frames / 2, 500), key(frames, 2000)])
395+ }
396+ }
397+ }
398+}
399+
350400 /// The source position a speed ramp has carried a clip through by its clip-relative
351401 /// timeline frame `t`: the integral of the piecewise-linear speed from frame 0 to
352402 /// `t`, in source frames (fractional). Each segment's integral is the trapezoid of
crates/mcp/src/help.rsmodified+1 -0
@@ -145,6 +145,7 @@ RECIPES
145145 silence: judged inside clips only; the timeline gaps between a lane's clips are structure and are reported, never listed or cut. Default threshold: 30 dB under the target's median speech level (−90..−10 dBFS); the reply names the value used. min_silence is judged before padding.
146146 cut_silence: a silence that runs to the end of its clip keeps `keep` in all after the last speech, its end padding included. Gaps between clips are never cut.
147147 Caption lanes ripple with the cut; locked caption lanes stay (a locked caption lane in the scope is skipped with a note).
148+ mode:\"speed_up\" plays each silence faster instead of cutting it (rate 1.05–4, default 4); mode:\"keep_silence\" cuts the speech and keeps the silence (one target, no joint cut). Both take dry_run and undo like the cut.
148149 Normalize loudness: measure the mix, then set it.
149150 loudness {target:\"mix\"}, then normalize {target:\"mix\", lufs:-14}; its reply leads with whether the target was reached.
150151 When the true-peak ceiling holds the gain back (the reply's capped_by is true_peak), add allow_limiter:true with true_peak set to the ceiling (-1 for lossless, -2 for lossy): the limiter then lets the mix reach the target, and the reply says it switched the limiter on.
crates/mcp/src/tools/edit.rsmodified+217 -22
@@ -33,7 +33,7 @@ const OWN_OPS: &[&str] = &[
3333 "chapter_add", "chapter_set", "chapter_remove", "marker_add", "marker_set", "marker_remove", "beats",
3434 "place", "insert", "overwrite", "append", "keep", "assemble", "split", "trim", "split_edit", "roll", "slip", "slide", "move", "delete", "lift", "ripple_delete",
3535 "close_gaps", "cut_regions", "insert_time", "remove_time", "freeze", "speed", "speed_ramp", "reverse", "fade", "dissolve", "transition", "crossfade", "visualizer",
36- "swap", "copy_look", "replace", "nudge",
36+ "swap", "copy_look", "replace", "nudge", "regroup", "copy_paste", "close_gap", "solo",
3737 ];
3838
3939 /// Ops `edit_fx` answers.
@@ -96,7 +96,11 @@ insert_time {at, duration, lanes?} — ripple empty time in at `at`: clips, capt
9696 remove_time {at, duration, lanes?} — ripple a span out of the unlocked lanes (or `lanes`): the cut_regions cut for one span. Titles after it move back; a title wholly inside the span is removed and one straddling an edge is trimmed to the part outside (both named in the reply).
9797 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.
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.
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).
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). Each copy gets a new link, as the GUI's paste gives it: the halves of a copied take come back unlinked to each other, so group them after with group {clips}.
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.
100104 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.
101105 fade {clip, in?, out?, linked?} — ramp lengths: int = frames, "0.5s" = time. A linked partner (V1+A1) gets the same ramp; linked:false = this clip only.
102106 dissolve {clip, frames, linked?} — VIDEO transition into the next clip. A linked sound partner crossfades into its next clip when they meet; linked:false = picture only.
@@ -268,6 +272,10 @@ fn accepted_keys(name: &str) -> Option<&'static [&'static str]> {
268272 "keep" => &["source", "ranges", "lane", "at", "audio", "audio_lane", "overwrite"],
269273 "assemble" => &["items", "lane", "at", "gap", "audio", "audio_lane", "overwrite"],
270274 "split" => &["at", "lanes"],
275+ "regroup" => &["at"],
276+ "copy_paste" => &["clips", "at", "lane"],
277+ "close_gap" => &["lane", "at"],
278+ "solo" => &["lane", "on"],
271279 "trim" => &["clip", "edge", "to", "scope", "ripple"],
272280 "roll" => &["clip", "by", "to", "edge"],
273281 "split_edit" => &["clip", "side", "edge", "to"],
@@ -284,7 +292,7 @@ fn accepted_keys(name: &str) -> Option<&'static [&'static str]> {
284292 "insert_time" | "remove_time" => &["at", "duration", "lanes"],
285293 "freeze" => &["at", "duration", "lane", "insert"],
286294 "speed" => &["clip", "x", "ripple", "lanes"],
287- "speed_ramp" => &["clip", "keys", "ripple", "lanes"],
295+ "speed_ramp" => &["clip", "keys", "preset", "ripple", "lanes"],
288296 "reverse" => &["clip", "on"],
289297 "fade" => &["clip", "in", "out", "linked"],
290298 "dissolve" | "transition" => &["clip", "frames", "length", "kind", "direction", "linked"],
@@ -4766,6 +4774,176 @@ fn op_close_gaps(s: &mut PlaybackSession, op: &Value) -> Result<Done, String> {
47664774 Ok(Done { text, touched, lanes: vec![lane] })
47674775 }
47684776
4777+/// `close_gap {lane, at}`: closes the one gap on `lane` that `at` stands in, the way the GUI's Close
4778+/// gap does: the gap's take scope ([`PlaybackSession::gap_take_scope`]) is cut out together, so a
4779+/// linked partner closes with it. Nothing else moves.
4780+fn op_close_gap(s: &mut PlaybackSession, op: &Value, fps: f64, end: u32) -> Result<Done, String> {
4781+ let lane = lane_arg(op, "lane")?.ok_or("missing `lane`: give a lane such as V1")?;
4782+ let at = need(op, "at", fps, end)?;
4783+ let name = parse::lane_name(lane);
4784+ if lane.kind == LaneKind::Subtitle {
4785+ return Err(format!("close_gap {name}: captions have no gap closed this way; use close_gaps {{lane:\"{name}\"}}"));
4786+ }
4787+ let Some((start, frames)) = s.closable_gap_at(lane, at) else {
4788+ return Err(format!(
4789+ "close_gap {name}: no gap on {name} at {}; a clip is there, the time is past the last clip, or it is the empty lead-in before the first clip",
4790+ shown_time(op.get("at"), at)
4791+ ));
4792+ };
4793+ let scope = s.gap_take_scope(lane, start, frames).map_err(|e| e.to_string())?;
4794+ check_unlocked(s, &scope)?;
4795+ let scope = s.close_gap_at(lane, start, frames).map_err(|e| e.to_string())?;
4796+ let names: Vec<String> = scope.iter().map(|&l| parse::lane_name(l)).collect();
4797+ let take = if scope.len() > 1 { format!(" with its take on {}", names.join(", ")) } else { String::new() };
4798+ let text = format!(
4799+ "close_gap {name}: closed {}–{} ({frames}f){take}",
4800+ secs_text(start, fps),
4801+ secs_text(start + frames, fps)
4802+ );
4803+ Ok(Done { text, touched: ripple_touched(s, &scope, start), lanes: scope })
4804+}
4805+
4806+/// `regroup {at}`: rejoins the clips that meet at `at` in every lane and puts them back in one group,
4807+/// the inverse of `split`. The GUI's Regroup does the same at the playhead, through the same engine door.
4808+fn op_regroup(s: &mut PlaybackSession, op: &Value, fps: f64, end: u32) -> Result<Done, String> {
4809+ let at = need(op, "at", fps, end)?;
4810+ let shown = shown_time(op.get("at"), at);
4811+ if !s.regroup_at(parse::secs(at, fps)) {
4812+ return Err(format!(
4813+ "regroup {shown}: nothing to rejoin there; no cut sits at that frame, or the clips on it were never split apart"
4814+ ));
4815+ }
4816+ let lanes: Vec<Lane> = s.lanes().into_iter().filter(|&l| s.lane_clips(l).iter().any(|c| c.start == at)).collect();
4817+ let touched = lanes.iter().map(|&l| (l, at)).collect();
4818+ let names: Vec<String> = lanes.iter().map(|&l| parse::lane_name(l)).collect();
4819+ Ok(Done { text: format!("regroup {shown}: the cut is rejoined on {}", names.join(", ")), touched, lanes })
4820+}
4821+
4822+/// `solo {lane, on}`: solos an audio lane for listening, so only the soloed lanes are heard while this
4823+/// session plays. Solo is monitoring only: it is not project state, it is not saved, and an export never
4824+/// reads it, so it leaves no undo step and marks nothing changed.
4825+fn op_solo(s: &mut PlaybackSession, op: &Value) -> Result<Done, String> {
4826+ let lane = lane_arg(op, "lane")?.ok_or("missing `lane`: give an audio lane such as A1")?;
4827+ let name = parse::lane_name(lane);
4828+ if lane.kind != LaneKind::Audio {
4829+ return Err(format!("solo {name}: only audio lanes solo, and {name} is not one"));
4830+ }
4831+ let on = match op.get("on") {
4832+ Some(Value::Bool(b)) => *b,
4833+ None | Some(Value::Null) => return Err("missing `on`: true solos the lane, false un-solos it".into()),
4834+ Some(_) => return Err("`on` must be true or false".into()),
4835+ };
4836+ let mut solo: Vec<Lane> = s.soloed().to_vec();
4837+ if on {
4838+ if !solo.contains(&lane) {
4839+ solo.push(lane);
4840+ }
4841+ } else {
4842+ solo.retain(|&l| l != lane);
4843+ }
4844+ let changed = s.set_solo(&solo);
4845+ let text = if s.soloed().is_empty() {
4846+ format!("solo {name}: {}", if changed { "solo cleared, every audio lane plays" } else { "no solo to clear" })
4847+ } else {
4848+ let names: Vec<String> = s.soloed().iter().map(|&l| parse::lane_name(l)).collect();
4849+ let state = if changed { "soloed" } else { "already soloed" };
4850+ format!("solo {name}: {state}; only {} play while listening (monitoring only: not saved, not exported)", names.join(", "))
4851+ };
4852+ Ok(Done { text, touched: Vec::new(), lanes: Vec::new() })
4853+}
4854+
4855+/// The ramp shape `preset` names, or None when it is absent. The names are the speed card's chips.
4856+fn preset_arg(op: &Value) -> Result<Option<engine::project::SpeedRampShape>, String> {
4857+ let Some(v) = op.get("preset").filter(|v| !v.is_null()) else { return Ok(None) };
4858+ let t = v.as_str().ok_or("`preset` must be one of speed_up, slow_down, fast_middle, slow_middle")?;
4859+ engine::project::SpeedRampShape::ALL
4860+ .into_iter()
4861+ .find(|shape| shape.name() == t)
4862+ .map(Some)
4863+ .ok_or_else(|| format!("`preset` {t} is not one of speed_up, slow_down, fast_middle, slow_middle"))
4864+}
4865+
4866+/// `copy_paste {clips:[addr...], at, lane?}`: the GUI's copy and paste, through the same engine doors.
4867+/// One clip goes in as the GUI's single paste does (`paste_at`: it splits the clip under `at` and ripples
4868+/// the room open). Several, or any clip with `lane`, go in as one set (`paste_set_at`): each keeps its
4869+/// own lane and its spacing from the others, and the set is refused whole rather than opening room.
4870+/// `lane` puts every copy on that lane, which must be the kind (V or A) of each copied clip.
4871+fn op_copy_paste(s: &mut PlaybackSession, op: &Value, fps: f64, end: u32) -> Result<Done, String> {
4872+ let at = need(op, "at", fps, end)?;
4873+ let shown = shown_time(op.get("at"), at);
4874+ let raw = op
4875+ .get("clips")
4876+ .and_then(Value::as_array)
4877+ .filter(|a| !a.is_empty())
4878+ .ok_or("missing `clips`: give the clip addresses to copy, e.g. [\"V1@0\", \"A1@0\"]")?;
4879+ let mut picks: Vec<(Lane, usize)> = Vec::with_capacity(raw.len());
4880+ for v in raw {
4881+ let addr = v.as_str().ok_or("`clips` lists clip addresses such as \"V1@0\"")?;
4882+ let (lane, idx) = clip_addr(s, addr).map_err(|e| format!("copy_paste clips: {e}"))?;
4883+ if lane.kind == LaneKind::Subtitle {
4884+ return Err(format!("{addr} is a caption lane; copy_paste takes media clips"));
4885+ }
4886+ if !picks.contains(&(lane, idx)) {
4887+ picks.push((lane, idx));
4888+ }
4889+ }
4890+ let target = lane_arg(op, "lane")?;
4891+ let mut items: Vec<(Lane, Clip)> = picks.iter().map(|&(l, i)| (l, s.lane_clips(l)[i].clone())).collect();
4892+ if let Some(to) = target {
4893+ if let Some(&(l, _)) = items.iter().find(|(l, _)| l.kind != to.kind) {
4894+ return Err(format!(
4895+ "copy_paste: {} is on {} and `lane` {} is not, so the copy would not go there; name a lane of the same kind",
4896+ parse::lane_name(l),
4897+ if l.kind == LaneKind::Audio { "a sound lane" } else { "a picture lane" },
4898+ parse::lane_name(to)
4899+ ));
4900+ }
4901+ for item in &mut items {
4902+ item.0 = to;
4903+ }
4904+ }
4905+ let mut locks: Vec<Lane> = picks.iter().map(|&(l, _)| l).collect();
4906+ locks.extend(target);
4907+ check_unlocked(s, &locks)?;
4908+ // The clips already there, as (lane, source, in, out): what the paste adds is read by difference.
4909+ let key = |l: Lane, c: &Clip| (l, c.source, c.in_frame, c.out_frame);
4910+ let before: Vec<(Lane, usize, u32, u32)> = s.lanes().into_iter().flat_map(|l| s.lane_clips(l).iter().map(move |c| key(l, c)).collect::<Vec<_>>()).collect();
4911+ let shape_before = shape(s);
4912+ let pasted = match items.as_slice() {
4913+ [(_, clip)] if target.is_none() => s.paste_at(parse::secs(at, fps), clip.clone()),
4914+ _ => s.paste_set_at(parse::secs(at, fps), &items),
4915+ };
4916+ if !pasted {
4917+ let why = if items.len() > 1 || target.is_some() {
4918+ format!("the set would land on a clip on its lane at {shown} (a set-paste opens no room)")
4919+ } else {
4920+ format!("the clip would not go in at {shown}")
4921+ };
4922+ return Err(format!("copy_paste refused: {why}; nothing changed"));
4923+ }
4924+ // The copies are the clips the paste added: the before list minus what is still there, by key.
4925+ let mut pending = before;
4926+ let mut landed: Vec<(Lane, u32)> = Vec::new();
4927+ for l in s.lanes() {
4928+ for c in s.lane_clips(l) {
4929+ match pending.iter().position(|k| *k == key(l, c)) {
4930+ Some(p) => {
4931+ pending.swap_remove(p);
4932+ }
4933+ None => landed.push((l, c.start)),
4934+ }
4935+ }
4936+ }
4937+ let addrs: Vec<String> = landed.iter().map(|&(l, start)| parse::addr(l, start)).collect();
4938+ let effects = side_effects(&shape_before, &shape(s), "copy_paste");
4939+ let mut text = format!("copy_paste {} clip(s) at {shown}: pasted {}", items.len(), addrs.join(", "));
4940+ if !effects.is_empty() {
4941+ text.push_str(&format!("; effects: {}", effects.join("; ")));
4942+ }
4943+ let lanes: Vec<Lane> = landed.iter().map(|&(l, _)| l).collect();
4944+ Ok(Done { text, touched: landed, lanes })
4945+}
4946+
47694947 /// Where the last clip or caption on `lane` ends, in timeline frames (0 for an empty lane).
47704948 fn lane_end(s: &PlaybackSession, lane: Lane) -> u32 {
47714949 if lane.kind == LaneKind::Subtitle {
@@ -5054,26 +5232,39 @@ fn op_speed_ramp(s: &mut PlaybackSession, op: &Value, fps: f64) -> Result<Done,
50545232 check_unlocked(s, &take_lanes(s, lane, idx))?;
50555233 let clip = s.lane_clips(lane)[idx].clone();
50565234 let clip_frames = clip.frames();
5057- let raw = match op.get("keys") {
5058- None | Some(Value::Null) => return Err("missing `keys`: give a list of {at, speed}, or [] to clear the ramp".into()),
5059- Some(Value::Array(a)) => a,
5060- Some(_) => return Err("`keys` must be a list of {at, speed} objects".into()),
5061- };
5062- if raw.len() > engine::project::MAX_SPEED_KEYS {
5063- return Err(format!("a speed ramp takes at most {} keys", engine::project::MAX_SPEED_KEYS));
5064- }
5065- let mut keys = Vec::with_capacity(raw.len());
5066- for k in raw {
5067- let at = k.get("at").ok_or_else(|| "each key needs `at`: a time such as 0s, 2s or end".to_string())?;
5068- let at = parse::frame(at, fps, clip_frames)?;
5069- let speed = match k.get("speed") {
5070- None | Some(Value::Null) => return Err("each key needs `speed`: a number between 0.25 and 4".into()),
5071- Some(v) => v.as_f64().ok_or_else(|| format!("`speed` must be a number between 0.25 and 4, not {v}"))?,
5072- };
5073- if !(0.25..=4.0).contains(&speed) {
5074- return Err(format!("speed {} is outside 0.25–4", compact(speed)));
5235+ let mut keys: Vec<engine::project::SpeedKey> = Vec::new();
5236+ match preset_arg(op)? {
5237+ // A preset lays the speed card's shape across the clip's length, as the card's chip does.
5238+ Some(shape) => {
5239+ if op.get("keys").is_some_and(|v| !v.is_null()) {
5240+ return Err("speed_ramp takes `keys` or `preset`, not both".into());
5241+ }
5242+ keys = shape.keys(clip_frames).ok_or_else(|| {
5243+ format!("speed_ramp {addr}: the clip is too short for {} (it needs at least 2 frames)", shape.name())
5244+ })?;
5245+ }
5246+ None => {
5247+ let raw = match op.get("keys") {
5248+ None | Some(Value::Null) => return Err("missing `keys`: give a list of {at, speed}, a `preset` (speed_up, slow_down, fast_middle, slow_middle), or [] to clear the ramp".into()),
5249+ Some(Value::Array(a)) => a,
5250+ Some(_) => return Err("`keys` must be a list of {at, speed} objects".into()),
5251+ };
5252+ if raw.len() > engine::project::MAX_SPEED_KEYS {
5253+ return Err(format!("a speed ramp takes at most {} keys", engine::project::MAX_SPEED_KEYS));
5254+ }
5255+ for k in raw {
5256+ let at = k.get("at").ok_or_else(|| "each key needs `at`: a time such as 0s, 2s or end".to_string())?;
5257+ let at = parse::frame(at, fps, clip_frames)?;
5258+ let speed = match k.get("speed") {
5259+ None | Some(Value::Null) => return Err("each key needs `speed`: a number between 0.25 and 4".into()),
5260+ Some(v) => v.as_f64().ok_or_else(|| format!("`speed` must be a number between 0.25 and 4, not {v}"))?,
5261+ };
5262+ if !(0.25..=4.0).contains(&speed) {
5263+ return Err(format!("speed {} is outside 0.25–4", compact(speed)));
5264+ }
5265+ keys.push(engine::project::SpeedKey { at, speed: Speed::from_permille((speed * 1000.0).round() as u16) });
5266+ }
50755267 }
5076- keys.push(engine::project::SpeedKey { at, speed: Speed::from_permille((speed * 1000.0).round() as u16) });
50775268 }
50785269 if !keys.is_empty() && !engine::project::valid_speed_keys(&keys) {
50795270 return Err("speed ramp keys must be in strictly increasing order of `at`, one per time".into());
@@ -6282,6 +6473,10 @@ fn run_op_inner(s: &mut PlaybackSession, name: &str, op: &Value, fps: f64, proje
62826473 "keep" => op_keep(s, op, fps, end),
62836474 "assemble" => op_assemble(s, op, fps, end),
62846475 "split" => op_split(s, op, fps, end),
6476+ "regroup" => op_regroup(s, op, fps, end),
6477+ "copy_paste" => op_copy_paste(s, op, fps, end),
6478+ "close_gap" => op_close_gap(s, op, fps, end),
6479+ "solo" => op_solo(s, op),
62856480 "trim" => op_trim(s, op, fps, end),
62866481 "split_edit" => op_split_edit(s, op, fps, end),
62876482 "roll" => op_roll(s, op, fps, end),
crates/mcp/src/tools/hear.rsmodified+175 -19
@@ -20,7 +20,7 @@ use engine::project::{
2020 GainKey, Lane, LaneKind, MAX_CLIP_GAIN_DB, MAX_GAIN_DB, MIN_GAIN_DB, RedoCheckpoint, gain_keys_db_at,
2121 };
2222 use engine::silence::{self, SILENT_DB, Settings, WINDOWS_PER_SEC};
23-use engine::{Clip, PlaybackSession};
23+use engine::{Clip, PlaybackSession, Speed};
2424 use serde_json::{Value, json};
2525
2626 use crate::parse;
@@ -54,7 +54,8 @@ force: a cut that would remove more than half the target's sound is refused, wit
5454 lanes: the lanes to cut. With a target, lanes is the RIPPLE SCOPE: the silence is judged on the target alone, and the same spans are cut on every listed lane (the target's own lane is added when it is not listed). Default with no lanes: the target's lane and the lanes of clips linked (grouped) to it, so linked video follows the sound while picture-only B-roll stays put; a mix target cuts every lane. A take must stay whole, or the engine refuses and says why; a lane not named never moves, and the reply names it as left in place (a music bed: name it in lanes to move it too).
5555 JOINT CUT: lanes:["A1","A2"] (two speakers in a conversation, say) with no target. The silence is where EVERY listed audio lane is quiet at once: each lane is judged on its own clips at its own threshold (or threshold_db for all when given), and a timeline gap on a lane counts as quiet for it, so the joint silence is a stretch where the other listed lanes are quiet too, and a stretch where no listed lane has a clip is never cut. The cut is made on the listed lanes together, so their turns stay in step. A video lane in a joint list is cut with the spans but not judged, and a joint cut needs two or more audio lanes in its list. A target with lanes is never a joint cut: there lanes is the ripple scope, judged on the target alone. Locks follow the ripple rule: a locked target, or a locked lane named in lanes, refuses the cut with the lane_flags way out; a mix's default scope (every lane) refuses the same way, naming each locked lane, and changes nothing.
5656 dry_run: report what would be cut, then roll back. Nothing changed and no undo step is added.
57-The reply names the pause each cut left as "pauses now X s", measured back from the sound after the cut: the lane's for a lane or clip, the mix as exported for a mix, the joint quiet for a joint cut (frames are 1/fps, so a keep that is not a whole frame reads a frame over at most)."#;
57+The reply names the pause each cut left as "pauses now X s", measured back from the sound after the cut: the lane's for a lane or clip, the mix as exported for a mix, the joint quiet for a joint cut (frames are 1/fps, so a keep that is not a whole frame reads a frame over at most).
58+mode: cut (default, as above) · speed_up: each silence plays at rate (1.05–4, default 4) instead of being cut, the room it no longer needs closed, as the GUI's speed silences do; keep and force do not apply, and titles keep their times · keep_silence: the speech is cut and the silence kept, the GUI's keep-only silence; one target only (no joint cut), its share guard does not apply since the speech is the point. Both take dry_run and undo as cut does."#;
5859
5960 /// The pause cut_silence leaves at each cut when neither `keep` nor `padding` is given.
6061 const DEFAULT_KEEP: f64 = 0.4;
@@ -176,6 +177,21 @@ fn cut_silence_schema() -> Value {
176177 "dry_run".into(),
177178 json!({ "type": "boolean", "description": "Report what would be cut, then roll back." }),
178179 );
180+ props.insert(
181+ "mode".into(),
182+ json!({
183+ "type": "string",
184+ "enum": ["cut", "speed_up", "keep_silence"],
185+ "description": "cut (default): shorten each silence to keep. speed_up: play each silence at rate instead of cutting it (the GUI's speed-silences). keep_silence: cut the speech and keep the silence (the GUI's keep-only silence); one target only."
186+ }),
187+ );
188+ props.insert(
189+ "rate".into(),
190+ json!({
191+ "type": "number", "minimum": 1.05, "maximum": 4,
192+ "description": "mode speed_up only: the speed each silence plays at, 1.05 to 4. Default 4 (the GUI's default)."
193+ }),
194+ );
179195 json!({ "type": "object", "properties": props })
180196 }
181197
@@ -1326,6 +1342,94 @@ pub(super) fn record_pushes(srv: &mut Server, start: u64, label: String) {
13261342 /// The shortest pause a cut may leave: below it the pause is not a pause a person can hear.
13271343 const MIN_KEEP_SECS: f64 = 0.05;
13281344
1345+/// The slowest a speed_up plays a silence at: the GUI's silence rate starts one step above real time.
1346+const MIN_SILENCE_RATE: f64 = 1.05;
1347+
1348+/// What cut_silence does to each silence it finds: cut it back to `keep` (the default), play it at a
1349+/// speed, or cut the speech and keep the silence (the GUI's keep-only silence).
1350+#[derive(Clone, Copy, PartialEq, Eq, Debug)]
1351+enum CutMode {
1352+ Cut,
1353+ SpeedUp,
1354+ KeepSilence,
1355+}
1356+
1357+impl CutMode {
1358+ /// The word the `mode` argument takes for this mode.
1359+ fn name(self) -> &'static str {
1360+ match self {
1361+ CutMode::Cut => "cut",
1362+ CutMode::SpeedUp => "speed_up",
1363+ CutMode::KeepSilence => "keep_silence",
1364+ }
1365+ }
1366+}
1367+
1368+/// `mode`, or cut when it is absent.
1369+fn cut_mode(args: &Value) -> Result<CutMode, String> {
1370+ match args.get("mode") {
1371+ None | Some(Value::Null) => Ok(CutMode::Cut),
1372+ Some(Value::String(t)) => match t.as_str() {
1373+ "cut" => Ok(CutMode::Cut),
1374+ "speed_up" => Ok(CutMode::SpeedUp),
1375+ "keep_silence" => Ok(CutMode::KeepSilence),
1376+ other => Err(format!("`mode` {other} is not one of cut, speed_up, keep_silence")),
1377+ },
1378+ Some(_) => Err("`mode` is a word: cut, speed_up or keep_silence".into()),
1379+ }
1380+}
1381+
1382+/// `rate`, the speed a speed_up plays each silence at: 1.05 to 4 (the GUI's silence rate), or None when
1383+/// it is absent. The GUI's default is the top rate, 4, which the caller applies.
1384+fn speed_rate(args: &Value) -> Result<Option<Speed>, String> {
1385+ match args.get("rate") {
1386+ None | Some(Value::Null) => Ok(None),
1387+ Some(v) => match v.as_f64() {
1388+ Some(x) if x.is_finite() && (MIN_SILENCE_RATE..=4.0).contains(&x) => {
1389+ Ok(Some(Speed::from_permille((x * 1000.0).round() as u16)))
1390+ }
1391+ _ => Err(format!("`rate` is the speed a silence plays at, from {MIN_SILENCE_RATE} to 4")),
1392+ },
1393+ }
1394+}
1395+
1396+/// The timeline spans a target's sound covers, as `(from, to)` frames: a clip's own span, a lane's
1397+/// clips, or the whole mix. Empty for a source file, which has no place on the timeline.
1398+fn target_windows(s: &PlaybackSession, t: &Target) -> Vec<(u32, u32)> {
1399+ match t {
1400+ Target::Clip(_, c) => vec![(c.start, c.end())],
1401+ Target::Lane(l) => s.lane_clips(*l).iter().map(|c| (c.start, c.end())).collect(),
1402+ Target::Mix => vec![(0, parse::session_end(s))],
1403+ Target::Source(_) => Vec::new(),
1404+ }
1405+}
1406+
1407+/// The speech a keep_silence cut takes out: the stretches of each window that the quiet `quiet`
1408+/// does not cover, as `(start, len)` timeline frames. The complement is taken with
1409+/// `silence::invert` inside each window, as the GUI's keep-only silence does per clip.
1410+fn speech_within(windows: &[(u32, u32)], quiet: &[(u32, u32)], fps: f64) -> Vec<(u32, u32)> {
1411+ let mut out = Vec::new();
1412+ for &(a, b) in windows {
1413+ if b <= a {
1414+ continue;
1415+ }
1416+ let duration = f64::from(b - a) / fps;
1417+ let inside: Vec<(f64, f64)> = quiet
1418+ .iter()
1419+ .filter(|&&(qa, qb)| qb > a && qa < b)
1420+ .map(|&(qa, qb)| (f64::from(qa.max(a) - a) / fps, f64::from(qb.min(b) - a) / fps))
1421+ .collect();
1422+ for (from, to) in silence::invert(duration, &inside) {
1423+ let start = a + (from * fps).round() as u32;
1424+ let end = (a + (to * fps).round() as u32).min(b);
1425+ if end > start {
1426+ out.push((start, end - start));
1427+ }
1428+ }
1429+ }
1430+ out
1431+}
1432+
13291433 /// `keep` in seconds, 0.05 to 10, or absent.
13301434 fn keep_secs(args: &Value) -> Result<Option<f64>, String> {
13311435 match args.get("keep") {
@@ -1490,6 +1594,22 @@ fn run_cut_silence(srv: &mut Server, args: &Value) -> Reply {
14901594 Ok(k) => k.unwrap_or(DEFAULT_KEEP),
14911595 Err(e) => return fail(e),
14921596 };
1597+ let mode = match cut_mode(args) {
1598+ Ok(m) => m,
1599+ Err(e) => return fail(e),
1600+ };
1601+ let rate = match speed_rate(args) {
1602+ Ok(r) => r,
1603+ Err(e) => return fail(e),
1604+ };
1605+ if mode != CutMode::Cut && args.get("keep").is_some_and(|v| !v.is_null()) {
1606+ return fail(format!("`keep` is the pause mode cut leaves; {} takes no keep", mode.name()));
1607+ }
1608+ if mode != CutMode::SpeedUp && rate.is_some() {
1609+ return fail(format!("`rate` is the speed of mode speed_up; {} takes no rate", mode.name()));
1610+ }
1611+ // The GUI's silence rate defaults to its top speed.
1612+ let speed = rate.unwrap_or(Speed::MAX);
14931613 let dry = opt_bool(args, "dry_run").unwrap_or(false);
14941614 // A cut that is rolled back (a dry run, or a refused cut) leaves the project as it was.
14951615 let was_clean = !super::project::dirty(srv);
@@ -1501,6 +1621,9 @@ fn run_cut_silence(srv: &mut Server, args: &Value) -> Reply {
15011621 Ok(j) => j,
15021622 Err(e) => return fail(e),
15031623 };
1624+ if mode == CutMode::KeepSilence && joint.is_some() {
1625+ return fail("mode keep_silence takes one target, not a joint cut: name the target and drop lanes".into());
1626+ }
15041627 let target = match &joint {
15051628 Some(_) => None,
15061629 None => match target_arg(s, args) {
@@ -1626,15 +1749,28 @@ fn run_cut_silence(srv: &mut Server, args: &Value) -> Reply {
16261749 .iter()
16271750 .flat_map(|&l| s.lane_clips(l).iter().map(|c| c.end()))
16281751 .collect();
1629- let spans = cut_spans_for(&found.regions, keep, cfg.padding, fps, &clip_ends);
1752+ // What each mode acts on: the silence cut back to keep, the silence itself (played fast), or the
1753+ // speech inside the target (kept silence). All are (start, len) timeline frames.
1754+ let spans = match mode {
1755+ CutMode::Cut => cut_spans_for(&found.regions, keep, cfg.padding, fps, &clip_ends),
1756+ CutMode::SpeedUp => found.regions.iter().map(|&(a, b)| (a, b - a)).collect(),
1757+ CutMode::KeepSilence => match &target {
1758+ Some(t) => speech_within(&target_windows(s, t), &found.regions, fps),
1759+ None => Vec::new(),
1760+ },
1761+ };
16301762 let gaps = match (&joint, &target) {
16311763 (Some(lanes), _) => gap_note(s, lanes, fps),
16321764 (None, Some(Target::Lane(l))) => gap_note(s, &[*l], fps),
16331765 _ => String::new(),
16341766 };
16351767 if spans.is_empty() {
1768+ let why = match mode {
1769+ CutMode::KeepSilence => format!("the silence covers all of {name}, so there is no speech to cut"),
1770+ _ => format!("all ≤ keep ({keep} s)"),
1771+ };
16361772 return Reply::ok(format!(
1637- "{} silence(s) found on {name}, all ≤ keep ({keep} s); nothing cut{other_lanes}",
1773+ "{} silence(s) found on {name}, {why}; nothing cut{other_lanes}",
16381774 found.regions.len()
16391775 ))
16401776 .with(json!({
@@ -1657,7 +1793,11 @@ fn run_cut_silence(srv: &mut Server, args: &Value) -> Reply {
16571793 // Each span is cut as found: its edges are inside the silence, so no kept sliver of speech
16581794 // lies between two spans for the edit's sliver join to delete.
16591795 let shape0 = super::edit::shape(s);
1660- if let Err(e) = s.cut_regions(&spans, &scope) {
1796+ let applied = match mode {
1797+ CutMode::SpeedUp => s.speed_regions(&spans, speed, &scope),
1798+ _ => s.cut_regions(&spans, &scope),
1799+ };
1800+ if let Err(e) = applied {
16611801 let rolled = roll_back_cut(srv, start, trial);
16621802 srv.trim_ledger();
16631803 keep_clean_marks(srv, was_clean);
@@ -1666,10 +1806,13 @@ fn run_cut_silence(srv: &mut Server, args: &Value) -> Reply {
16661806 } else {
16671807 " (could not roll every step back; check the project)"
16681808 };
1669- return fail(format!("cut refused: {e}; nothing changed{note}"));
1809+ let verb = if mode == CutMode::SpeedUp { "speed refused" } else { "cut refused" };
1810+ return fail(format!("{verb}: {e}; nothing changed{note}"));
16701811 }
1671- // Titles move with the cut as they do for cut_regions, and the reply names what the cut left behind.
1672- let moved = if super::edit::has_picture(&scope) {
1812+ // Titles move with a cut as they do for cut_regions. A speed-up closes only part of each silence's
1813+ // room, which moves the later titles by an amount move_titles_for_cuts does not model, so they keep
1814+ // their times there.
1815+ let moved = if mode != CutMode::SpeedUp && super::edit::has_picture(&scope) {
16731816 match super::edit::move_titles_for_cuts(s, &spans, fps) {
16741817 Ok(m) => m,
16751818 Err(e) => {
@@ -1697,9 +1840,11 @@ fn run_cut_silence(srv: &mut Server, args: &Value) -> Reply {
16971840 let lanes_after = super::listen::media_end(s, &scope);
16981841 let sound_after = sound_frames(s, &scope);
16991842 // The pause actually left, read back from the sound after the cut and before any undo below.
1700- let pauses = match &target {
1701- Some(t) => measured_cut_pauses(s, t, &spans, cfg, fps),
1702- None => measured_joint_pauses(s, &judged, &spans, fps),
1843+ // A pause is what a cut leaves; a speed-up or a kept silence leaves none to measure.
1844+ let pauses = match (mode, &target) {
1845+ (CutMode::Cut, Some(t)) => measured_cut_pauses(s, t, &spans, cfg, fps),
1846+ (CutMode::Cut, None) => measured_joint_pauses(s, &judged, &spans, fps),
1847+ _ => Ok(Vec::new()),
17031848 };
17041849 // Measured on the cut lanes: a cut on A1 alone shortens A1 even when a longer lane sets the timeline end.
17051850 let removed = lanes_before.saturating_sub(lanes_after);
@@ -1714,7 +1859,9 @@ fn run_cut_silence(srv: &mut Server, args: &Value) -> Reply {
17141859 } else {
17151860 0.0
17161861 };
1717- if !force && share > CUT_SHARE_LIMIT {
1862+ // The guard is for a cut that takes sound away by accident. A speed-up removes none, and keep_silence
1863+ // removes the speech on purpose, so neither is limited by it.
1864+ if mode == CutMode::Cut && !force && share > CUT_SHARE_LIMIT {
17181865 let rolled = roll_back_cut(srv, start, trial);
17191866 srv.trim_ledger();
17201867 keep_clean_marks(srv, was_clean);
@@ -1740,11 +1887,20 @@ fn run_cut_silence(srv: &mut Server, args: &Value) -> Reply {
17401887 keep_clean_marks(srv, was_clean);
17411888 }
17421889 // `s` is not used past this point, so the ledger can be written.
1890+ // The count phrase and the verbs for this mode: a kept silence counts the speech it cuts.
1891+ let counted = match mode {
1892+ CutMode::KeepSilence => format!("{} speech stretch(es) between {} silence(s)", spans.len(), found.regions.len()),
1893+ _ => format!("{} of {} silence(s)", spans.len(), found.regions.len()),
1894+ };
1895+ let rate_txt = format!("{:.2}x", f64::from(speed.permille()) / 1000.0);
1896+ let (dry_verb, done_verb) = match mode {
1897+ CutMode::Cut => ("would cut".to_string(), "cut".to_string()),
1898+ CutMode::SpeedUp => (format!("would speed up to {rate_txt}"), format!("sped up to {rate_txt}")),
1899+ CutMode::KeepSilence => ("would cut the speech out".to_string(), "cut the speech out".to_string()),
1900+ };
17431901 let head = if dry {
17441902 format!(
1745- "dry run — would cut {} of {} silence(s) from {lanes_named}, and would remove {removed_secs:.3} s (the timeline's loss, not the silence found); timeline {:.3} s → {:.3} s; nothing changed{note}",
1746- spans.len(),
1747- found.regions.len(),
1903+ "dry run — {dry_verb} {counted} from {lanes_named}, and would remove {removed_secs:.3} s (the timeline's loss, not the silence found); timeline {:.3} s → {:.3} s; nothing changed{note}",
17481904 parse::secs(end_before, fps),
17491905 parse::secs(end_after, fps),
17501906 )
@@ -1755,9 +1911,7 @@ fn run_cut_silence(srv: &mut Server, args: &Value) -> Reply {
17551911 format!("cut_silence {name} ({} regions)", spans.len()),
17561912 );
17571913 format!(
1758- "cut {} of {} silence(s) from {lanes_named}, {removed_secs:.3} s removed; timeline {:.3} s → {:.3} s ({end_after}f) · undo step {}",
1759- spans.len(),
1760- found.regions.len(),
1914+ "{done_verb} {counted} from {lanes_named}, {removed_secs:.3} s removed; timeline {:.3} s → {:.3} s ({end_after}f) · undo step {}",
17611915 parse::secs(end_before, fps),
17621916 parse::secs(end_after, fps),
17631917 srv.ledger.len(),
@@ -1792,7 +1946,9 @@ fn run_cut_silence(srv: &mut Server, args: &Value) -> Reply {
17921946 Ok(_) => "none (no cut joints)".to_string(),
17931947 Err(e) => format!("not measured ({e})"),
17941948 };
1795- text.push_str(&format!(" · pauses now {pause_note} (measured after the cut on {name})"));
1949+ if mode == CutMode::Cut {
1950+ text.push_str(&format!(" · pauses now {pause_note} (measured after the cut on {name})"));
1951+ }
17961952 if let Some(note) = &thr_note {
17971953 text.push_str(&format!("\nthreshold: {note}"));
17981954 }