forge
Explore
Log in

Don't you dare go Hollow

✨ Title keyframes: TitleKey (offset, scale, opacity), ttkeys (v56), MCP title_add/title_set keys

Browse files at this commit

24f79085136b5f8b6f675a818e32b986ca4d7991Ahmet Kaan GümüşParent: b0e72a4
MCP.mdmodified+1 -1
@@ -335,7 +335,7 @@ prints it live, and `help {topic:"<op>"}` gives one op's entry. The recipes and
335 | captions | edit ops, not tools: `subtitles_import {path}` (tracks, no lane yet) · `captions_place {track, lane?, at?}` · `sub_move {clip, at, to_lane?}` [group] · `sub_trim {clip, edge:in|out, to}` · `sub_delete {clip}` · `captions_remove {track, force?}` · `cue_add {track, at, to, text, overwrite?}` · `cue_text {track, index, text}` (`\n` = line break) · `cue_delete {track, index}` · `cue_time {track, index, at?, to?}` (timeline times: trim or move one cue inside its neighbours, 0.1 s minimum) · `cue_merge {track, index}` (with the next cue) · `cue_split {track, index, at}` · `cue_replace {track?, find, replace, case_sensitive?}` (every cue of one track, or all tracks; case-insensitive unless `case_sensitive`; reports occurrences and cues). Written as `edit {ops:[{op:"cue_text", …}]}`; `captions` (the tool) lists the cues as `track T cue C` |335 | captions | edit ops, not tools: `subtitles_import {path}` (tracks, no lane yet) · `captions_place {track, lane?, at?}` · `sub_move {clip, at, to_lane?}` [group] · `sub_trim {clip, edge:in|out, to}` · `sub_delete {clip}` · `captions_remove {track, force?}` · `cue_add {track, at, to, text, overwrite?}` · `cue_text {track, index, text}` (`\n` = line break) · `cue_delete {track, index}` · `cue_time {track, index, at?, to?}` (timeline times: trim or move one cue inside its neighbours, 0.1 s minimum) · `cue_merge {track, index}` (with the next cue) · `cue_split {track, index, at}` · `cue_replace {track?, find, replace, case_sensitive?}` (every cue of one track, or all tracks; case-insensitive unless `case_sensitive`; reports occurrences and cues). Written as `edit {ops:[{op:"cue_text", …}]}`; `captions` (the tool) lists the cues as `track T cue C` |
336 | markers | `chapter_add {at, title}` · `chapter_set {chapter, title?, at?}` · `chapter_remove {chapter}` (a chapter is `C@<frame>` or `C#n`, its place in the list, 1 first; cuts and inserts move chapters with the picture; `timeline` prints them as a YouTube description, with warnings) |336 | markers | `chapter_add {at, title}` · `chapter_set {chapter, title?, at?}` · `chapter_remove {chapter}` (a chapter is `C@<frame>` or `C#n`, its place in the list, 1 first; cuts and inserts move chapters with the picture; `timeline` prints them as a YouTube description, with warnings) |
337 | comment markers | `marker_add {at, name, note?, color?, length?}` · `marker_set {marker, name?, note?, color?, at?, length?}` · `marker_remove {marker}` · `beats {clip, every?=1}` (finds the tempo of a sound clip and marks each `every`th beat, 1, 2 or 4 for bars, as a yellow marker noted "Beat"; the reply gives the BPM, the count and the `M@` addresses; the clip's earlier beat markers are replaced in the same undo step; a clip with no sound, a silent one or one with no steady pulse is refused; `engine::beats`) (a marker is `M@<frame>`, the first on that frame, or `M#n`; color is red, orange, yellow, green, blue or purple, default blue; a `length` makes a range and `length: 0` turns it back into a point; several markers may share a frame; they move with the picture as chapters do, a range growing or shrinking with an insert or cut; `timeline` prints a `markers:` line and a `markers` list; `export_start chapters: "markers"` writes them as the file's chapters) |337 | comment markers | `marker_add {at, name, note?, color?, length?}` · `marker_set {marker, name?, note?, color?, at?, length?}` · `marker_remove {marker}` · `beats {clip, every?=1}` (finds the tempo of a sound clip and marks each `every`th beat, 1, 2 or 4 for bars, as a yellow marker noted "Beat"; the reply gives the BPM, the count and the `M@` addresses; the clip's earlier beat markers are replaced in the same undo step; a clip with no sound, a silent one or one with no steady pulse is refused; `engine::beats`) (a marker is `M@<frame>`, the first on that frame, or `M#n`; color is red, orange, yellow, green, blue or purple, default blue; a `length` makes a range and `length: 0` turns it back into a point; several markers may share a frame; they move with the picture as chapters do, a range growing or shrinking with an insert or cut; `timeline` prints a `markers:` line and a `markers` list; `export_start chapters: "markers"` writes them as the file's chapters) |
338-| titles | `title_add {at, duration, text, preset?=lower_third\|centered\|caption_bar, size?=80, outline?, boxed?, place?=centre\|top\|bottom, hplace?=centre\|left\|right, color?=#ffffff, weight?=regular\|bold, align?=centre\|left\|right, box_color?, box_opacity?, fade_in?, fade_out?, in_anim?=none\|fade\|typewriter\|slide_up\|slide_left\|pop\|word_by_word, out_anim?=(same), anim_secs?=0.5}` · `title_set {title, …}` · `title_remove {title}`. The title and burned-caption text draws Latin, Greek, Cyrillic, Arabic, Hebrew, Devanagari and Thai from bundled Noto faces, shaped, right-to-left in order. Colour emoji and CJK come from the system's Noto Color Emoji and Noto Sans CJK when installed; otherwise emoji draw monochrome and CJK draws as empty boxes (soft subtitle tracks keep that text). Only a character no face has draws as a box. `title_remove` renumbers the titles after it (T2 becomes T1). `preset` is the app's one-click look (the same values as the Title menu's styles): the fields given with it win, and `title_set {preset}` applies it to an existing title keeping its words and timing. `hplace` is the side the block sits against (a lower third is `place:bottom, hplace:left`), `align` how its lines line up in it, `color` the letters (`#rrggbb`), `weight` Archivo Medium or Bold (Latin only), `box_color` `#rrggbb` (keeps the opacity) or `#rrggbbaa`, `box_opacity` 0..1. A title with any of these off the default saves as format v49 (`titlestyle` lines); older projects load with the defaults. `in_anim` and `out_anim` are the entrance and exit animations, each of the seven names above; an exit is the entrance played backwards, eased in on the way out and out on the way in. `anim_secs` is how long each takes (a bare number is seconds, unlike the frame fades), `title_set` takes all three too. Typewriter and word_by_word reveal the text over the animation. A title with an animation saves as format v54 (`titleanim` lines) |338+| titles | `title_add {at, duration, text, preset?=lower_third\|centered\|caption_bar, size?=80, outline?, boxed?, place?=centre\|top\|bottom, hplace?=centre\|left\|right, color?=#ffffff, weight?=regular\|bold, align?=centre\|left\|right, box_color?, box_opacity?, fade_in?, fade_out?, in_anim?=none\|fade\|typewriter\|slide_up\|slide_left\|pop\|word_by_word, out_anim?=(same), anim_secs?=0.5, keys?=[{at, x?, y?, scale?, opacity?, ease?}]}` · `title_set {title, …}` · `title_remove {title}`. `keys` animates the title over its own length: `at` is a time from the title's first frame (a key past the end holds its value), `x` and `y` shift it as a share of the picture (-1..1, y down positive), `scale` multiplies its size (0.05..10) and `opacity` multiplies its alpha (0..1); missing fields are 0, 0, 1, 1, and `keys:[]` takes the animation off. A title with keys saves as format v56, and the title readback lists them. The title and burned-caption text draws Latin, Greek, Cyrillic, Arabic, Hebrew, Devanagari and Thai from bundled Noto faces, shaped, right-to-left in order. Colour emoji and CJK come from the system's Noto Color Emoji and Noto Sans CJK when installed; otherwise emoji draw monochrome and CJK draws as empty boxes (soft subtitle tracks keep that text). Only a character no face has draws as a box. `title_remove` renumbers the titles after it (T2 becomes T1). `preset` is the app's one-click look (the same values as the Title menu's styles): the fields given with it win, and `title_set {preset}` applies it to an existing title keeping its words and timing. `hplace` is the side the block sits against (a lower third is `place:bottom, hplace:left`), `align` how its lines line up in it, `color` the letters (`#rrggbb`), `weight` Archivo Medium or Bold (Latin only), `box_color` `#rrggbb` (keeps the opacity) or `#rrggbbaa`, `box_opacity` 0..1. A title with any of these off the default saves as format v49 (`titlestyle` lines); older projects load with the defaults. `in_anim` and `out_anim` are the entrance and exit animations, each of the seven names above; an exit is the entrance played backwards, eased in on the way out and out on the way in. `anim_secs` is how long each takes (a bare number is seconds, unlike the frame fades), `title_set` takes all three too. Typewriter and word_by_word reveal the text over the animation. A title with an animation saves as format v54 (`titleanim` lines) |
339 339
340 `freeze` writes the composed frame at `at` to `<project>/freeze/<stem>-<frame>-<hash8>.png`340 `freeze` writes the composed frame at `at` to `<project>/freeze/<stem>-<frame>-<hash8>.png`
341 and places it as a still on `lane`. The hash is of the pixels, so an identical341 and places it as a still on `lane`. The hash is of the pixels, so an identical
crates/app/src/player/titling.rsmodified+3 -2
@@ -154,6 +154,7 @@ impl Player {
154 in_anim: Default::default(),154 in_anim: Default::default(),
155 out_anim: Default::default(),155 out_anim: Default::default(),
156 anim_frames: 0,156 anim_frames: 0,
157+ keys: Vec::new(),
157 };158 };
158 title.apply_preset(Preset::Centered, fps);159 title.apply_preset(Preset::Centered, fps);
159 // Up at once: a fade-in would have the new words nearly invisible where the playhead is.160 // Up at once: a fade-in would have the new words nearly invisible where the playhead is.
@@ -434,7 +435,7 @@ mod tests {
434 use engine::text::{Align, HPlace, Outline, Place, Weight};435 use engine::text::{Align, HPlace, Outline, Place, Weight};
435 436
436 fn title() -> Title {437 fn title() -> Title {
437- Title { start: 100, frames: 125, text: "Hi".into(), style: TextStyle::default(), fade_in: 0, fade_out: 0, in_anim: Default::default(), out_anim: Default::default(), anim_frames: 0 }438+ Title { start: 100, frames: 125, text: "Hi".into(), style: TextStyle::default(), fade_in: 0, fade_out: 0, in_anim: Default::default(), out_anim: Default::default(), anim_frames: 0, keys: Vec::new() }
438 }439 }
439 440
440 #[test]441 #[test]
@@ -490,7 +491,7 @@ mod tests {
490 491
491 #[test]492 #[test]
492 fn a_new_title_goes_after_the_one_on_the_playhead_and_fits_before_the_next() {493 fn a_new_title_goes_after_the_one_on_the_playhead_and_fits_before_the_next() {
493- let t = |start, frames| Title { start, frames, text: "t".into(), style: TextStyle::default(), fade_in: 0, fade_out: 0, in_anim: Default::default(), out_anim: Default::default(), anim_frames: 0 };494+ let t = |start, frames| Title { start, frames, text: "t".into(), style: TextStyle::default(), fade_in: 0, fade_out: 0, in_anim: Default::default(), out_anim: Default::default(), anim_frames: 0, keys: Vec::new() };
494 let titles = [t(0, 150), t(200, 150)];495 let titles = [t(0, 150), t(200, 150)];
495 // Free: where it was asked, and cut to the room before the next title.496 // Free: where it was asked, and cut to the room before the next title.
496 assert_eq!(free_title_slot(&[], 10, 150, 30.), (10, 150));497 assert_eq!(free_title_slot(&[], 10, 150, 30.), (10, 150));
crates/app/src/tests/titles.rsmodified+1 -0
@@ -21,6 +21,7 @@ fn title(start: u32, frames: u32, fade_in: u32, fade_out: u32) -> Title {
21 in_anim: Default::default(),21 in_anim: Default::default(),
22 out_anim: Default::default(),22 out_anim: Default::default(),
23 anim_frames: 0,23 anim_frames: 0,
24+ keys: Vec::new(),
24 }25 }
25 }26 }
26 27
crates/engine/src/edith.rsmodified+55 -2
@@ -234,6 +234,12 @@
234 //! only a mask's position, size and soft edge, are still read. A project with none is the bytes a234 //! only a mask's position, size and soft edge, are still read. A project with none is the bytes a
235 //! v55 one was bar the version line.235 //! v55 one was bar the version line.
236 //!236 //!
237+//! A `ttkeys` line is `ttkeys <title> <at>:<ease>:<x>,<y>,<scale>,<opacity> ...`: a title's own
238+//! keyframe animation ([`crate::titleanim::TitleKey`]), the title named by its place in the list
239+//! and the keys in frame order, `at` counted from the title's first frame. Written after the
240+//! title's `titleanim` line, one per title that has keys. It is also v56, so a project with title
241+//! keys is written as v56 and a project with none is the bytes a v55 one was bar the version line.
242+//!
237 //! A `cueadd` line is one cue added to a subtitle track, which no file has:243 //! A `cueadd` line is one cue added to a subtitle track, which no file has:
238 //! `cueadd <track> <start_us> <end_us> <text>`, the track by its position in244 //! `cueadd <track> <start_us> <end_us> <text>`, the track by its position in
239 //! the `subtitle` lines, the times in microseconds on the track's own clock, and245 //! the `subtitle` lines, the times in microseconds on the track's own clock, and
@@ -430,7 +436,7 @@ use crate::subtitle::SubtitleTrack;
430 use crate::captionanim::{CaptionAnim, CaptionStyle, MAX_WORDS_PER_LINE};436 use crate::captionanim::{CaptionAnim, CaptionStyle, MAX_WORDS_PER_LINE};
431 use crate::voice::{Compressor, DeEsser, Gate, NoiseReduction, VoiceFx};437 use crate::voice::{Compressor, DeEsser, Gate, NoiseReduction, VoiceFx};
432 use crate::text::{Align, HPlace, Outline, Place, TextStyle, Weight};438 use crate::text::{Align, HPlace, Outline, Place, TextStyle, Weight};
433-use crate::titleanim::TitleAnim;439+use crate::titleanim::{TitleAnim, TitleKey};
434 use crate::color::{ColorKey, MAX_COLOR_KEYS};440 use crate::color::{ColorKey, MAX_COLOR_KEYS};
435 use crate::transitions::TransitionKind;441 use crate::transitions::TransitionKind;
436 use crate::transform::{KeyEase, MAX_TRANSFORM_KEYS, OpacityKey, TransformKey, TransformParams};442 use crate::transform::{KeyEase, MAX_TRANSFORM_KEYS, OpacityKey, TransformKey, TransformParams};
@@ -819,7 +825,9 @@ pub fn encode_flagged(
819 let keyed = lanes.iter().any(|(_, clips)| clips.iter().any(|c| c.effects.iter().any(|e| !e.keys.is_empty())));825 let keyed = lanes.iter().any(|(_, clips)| clips.iter().any(|c| c.effects.iter().any(|e| !e.keys.is_empty())));
820 // ...and one with a clip's pitch shift is v55.826 // ...and one with a clip's pitch shift is v55.
821 let pitched = lanes.iter().any(|(_, clips)| clips.iter().any(|c| c.pitch != 0));827 let pitched = lanes.iter().any(|(_, clips)| clips.iter().any(|c| c.pitch != 0));
822- let curved = keyed || lanes.iter().any(|(_, clips)| clips.iter().any(has_bezier));828+ // ...and one with a title's own keys is v56 (`ttkeys`).
829+ let title_keyed = titles.iter().any(|t| !t.keys.is_empty());
830+ let curved = keyed || title_keyed || lanes.iter().any(|(_, clips)| clips.iter().any(has_bezier));
823 if curved || pitched || titled || panned || styled || marked || angled || named || deinterlaced || steadied || looked || effected || voiced || captioned || animated || reversed || transitioned || ramped || !chapters.is_empty() || !markers.is_empty() {831 if curved || pitched || titled || panned || styled || marked || angled || named || deinterlaced || steadied || looked || effected || voiced || captioned || animated || reversed || transitioned || ramped || !chapters.is_empty() || !markers.is_empty() {
824 let first_end = bytes.iter().position(|&b| b == b'\n').unwrap_or(bytes.len());832 let first_end = bytes.iter().position(|&b| b == b'\n').unwrap_or(bytes.len());
825 let header = if curved {833 let header = if curved {
@@ -1947,6 +1955,17 @@ fn title_lines(titles: &[Title]) -> Vec<u8> {
1947 }1955 }
1948 out.extend_from_slice(format!("titleanim {i} {} {} {}\n", t.in_anim.name(), t.out_anim.name(), t.anim_frames).as_bytes());1956 out.extend_from_slice(format!("titleanim {i} {} {} {}\n", t.in_anim.name(), t.out_anim.name(), t.anim_frames).as_bytes());
1949 }1957 }
1958+ // A title's own keys, one line per title that has any, after its `titleanim` line.
1959+ for (i, t) in titles.iter().enumerate() {
1960+ if t.keys.is_empty() {
1961+ continue;
1962+ }
1963+ out.extend_from_slice(format!("ttkeys {i}").as_bytes());
1964+ for k in &t.keys {
1965+ out.extend_from_slice(format!(" {}:{}:{},{},{},{}", k.at, k.ease.token(), k.x, k.y, k.scale, k.opacity).as_bytes());
1966+ }
1967+ out.push(b'\n');
1968+ }
1950 out1969 out
1951 }1970 }
1952 1971
@@ -3235,6 +3254,7 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
3235 in_anim: TitleAnim::None,3254 in_anim: TitleAnim::None,
3236 out_anim: TitleAnim::None,3255 out_anim: TitleAnim::None,
3237 anim_frames: 0,3256 anim_frames: 0,
3257+ keys: Vec::new(),
3238 };3258 };
3239 check_title(&title).map_err(|e| format!("line {n}: {e}"))?;3259 check_title(&title).map_err(|e| format!("line {n}: {e}"))?;
3240 doc.titles.push(title);3260 doc.titles.push(title);
@@ -3484,6 +3504,37 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> {
3484 title.anim_frames = anim_frames;3504 title.anim_frames = anim_frames;
3485 check_title(title).map_err(|e| format!("line {n}: {e}"))?;3505 check_title(title).map_err(|e| format!("line {n}: {e}"))?;
3486 }3506 }
3507+ // A title's own keys (v56): the title by its place in the list, then each key as
3508+ // `at:ease:x,y,scale,opacity`, in frame order. `check_title` holds the ranges and order.
3509+ b"ttkeys" if v56 => {
3510+ let f: Vec<&[u8]> = rest.split(|&b| b == b' ').filter(|f| !f.is_empty()).collect();
3511+ if f.is_empty() {
3512+ return Err(format!("line {n}: ttkeys wants a title and its keys").into());
3513+ }
3514+ let idx = number(f[0], n)? as usize;
3515+ let mut keys = Vec::with_capacity(f.len() - 1);
3516+ for point in &f[1..] {
3517+ let parts: Vec<&[u8]> = point.splitn(3, |&b| b == b':').collect();
3518+ if parts.len() != 3 {
3519+ return Err(format!("line {n}: ttkeys key wants at:ease:x,y,scale,opacity").into());
3520+ }
3521+ let at = number(parts[0], n)?;
3522+ let ease = KeyEase::from_token(parts[1])
3523+ .ok_or_else(|| format!("line {n}: ttkeys ease is lin, in, out, ease, hold or a bezier curve"))?;
3524+ let v: Vec<&[u8]> = parts[2].split(|&b| b == b',').collect();
3525+ if v.len() != 4 {
3526+ return Err(format!("line {n}: ttkeys key wants 4 values").into());
3527+ }
3528+ let (x, y, scale, opacity) = (float(v[0], n)?, float(v[1], n)?, float(v[2], n)?, float(v[3], n)?);
3529+ keys.push(TitleKey { at, x, y, scale, opacity, ease });
3530+ }
3531+ let title = doc
3532+ .titles
3533+ .get_mut(idx)
3534+ .ok_or_else(|| format!("line {n}: ttkeys names title {idx}, which the file does not have"))?;
3535+ title.keys = keys;
3536+ check_title(title).map_err(|e| format!("line {n}: {e}"))?;
3537+ }
3487 b"mark" if v48 => {3538 b"mark" if v48 => {
3488 let f: Vec<&[u8]> = rest.split(|&b| b == b' ').collect();3539 let f: Vec<&[u8]> = rest.split(|&b| b == b' ').collect();
3489 if f.len() != 5 {3540 if f.len() != 5 {
@@ -7800,6 +7851,7 @@ mod title_tests {
7800 in_anim: TitleAnim::None,7851 in_anim: TitleAnim::None,
7801 out_anim: TitleAnim::None,7852 out_anim: TitleAnim::None,
7802 anim_frames: 0,7853 anim_frames: 0,
7854+ keys: Vec::new(),
7803 },7855 },
7804 Title {7856 Title {
7805 start: 60,7857 start: 60,
@@ -7811,6 +7863,7 @@ mod title_tests {
7811 in_anim: Default::default(),7863 in_anim: Default::default(),
7812 out_anim: Default::default(),7864 out_anim: Default::default(),
7813 anim_frames: 0,7865 anim_frames: 0,
7866+ keys: Vec::new(),
7814 },7867 },
7815 ]7868 ]
7816 }7869 }
crates/engine/src/export.rsmodified+1 -0
@@ -10925,6 +10925,7 @@ mod tests {
10925 in_anim: Default::default(),10925 in_anim: Default::default(),
10926 out_anim: Default::default(),10926 out_anim: Default::default(),
10927 anim_frames: 0,10927 anim_frames: 0,
10928+ keys: Vec::new(),
10928 };10929 };
10929 // Captions 86.0 to 88.0 s; a bottom title from frame 2163 (86.52 s at 25 fps) for 3 s.10930 // Captions 86.0 to 88.0 s; a bottom title from frame 2163 (86.52 s at 25 fps) for 3 s.
10930 let cues = [cue(86.0, 88.0, "hello")];10931 let cues = [cue(86.0, 88.0, "hello")];
crates/engine/src/project.rsmodified+22 -2
@@ -98,7 +98,7 @@ use sequence::{FlatCache, Seqs};
98 /// drops it.98 /// drops it.
99 const CUT_SLIVER_FRAMES: f64 = 4.0;99 const CUT_SLIVER_FRAMES: f64 = 4.0;
100 use crate::text::{Align, HPlace, Outline, Place, SIZE_RANGE, TextStyle, Weight};100 use crate::text::{Align, HPlace, Outline, Place, SIZE_RANGE, TextStyle, Weight};
101-use crate::titleanim::TitleAnim;101+use crate::titleanim::{KEY_SCALE_RANGE, TitleAnim, TitleKey};
102 use crate::color::{ColorKey, MAX_COLOR_KEYS, evaluate_color};102 use crate::color::{ColorKey, MAX_COLOR_KEYS, evaluate_color};
103 use crate::transform::{103 use crate::transform::{
104 KeyEase, Keyed, MAX_TRANSFORM_KEYS, OpacityKey, TransformKey, TransformParams, ease_shape,104 KeyEase, Keyed, MAX_TRANSFORM_KEYS, OpacityKey, TransformKey, TransformParams, ease_shape,
@@ -2554,7 +2554,7 @@ pub const MAX_TITLE_END: u32 = 100_000_000;
2554 /// lane: they are drawn over the composed picture (black where no clip plays),2554 /// lane: they are drawn over the composed picture (black where no clip plays),
2555 /// in list order, so a later title sits on top of an earlier one. Saved as2555 /// in list order, so a later title sits on top of an earlier one. Saved as
2556 /// `title` lines ([`crate::edith`]).2556 /// `title` lines ([`crate::edith`]).
2557-#[derive(Clone, Debug, PartialEq, Eq)]2557+#[derive(Clone, Debug, PartialEq)]
2558 pub struct Title {2558 pub struct Title {
2559 /// The first timeline frame the title shows on.2559 /// The first timeline frame the title shows on.
2560 pub start: u32,2560 pub start: u32,
@@ -2577,6 +2577,9 @@ pub struct Title {
2577 pub out_anim: TitleAnim,2577 pub out_anim: TitleAnim,
2578 /// How many frames each animation takes; `>= 1` when either is set and at most `frames`.2578 /// How many frames each animation takes; `>= 1` when either is set and at most `frames`.
2579 pub anim_frames: u32,2579 pub anim_frames: u32,
2580+ /// The title's own keyframe animation, counted from its first frame: sorted by `at`, no two
2581+ /// at one frame, at most [`MAX_TRANSFORM_KEYS`]. Empty for a title without one.
2582+ pub keys: Vec<TitleKey>,
2580 }2583 }
2581 2584
2582 impl Title {2585 impl Title {
@@ -2683,6 +2686,22 @@ pub fn check_title(title: &Title) -> crate::Result<()> {
2683 )2686 )
2684 .into());2687 .into());
2685 }2688 }
2689+ if title.keys.len() > MAX_TRANSFORM_KEYS {
2690+ return Err(format!("a title holds at most {MAX_TRANSFORM_KEYS} keys").into());
2691+ }
2692+ for (i, k) in title.keys.iter().enumerate() {
2693+ // A NaN fails every range check, so it is refused along with the out-of-range values.
2694+ let in_range = (-1.0..=1.0).contains(&k.x)
2695+ && (-1.0..=1.0).contains(&k.y)
2696+ && (KEY_SCALE_RANGE.0..=KEY_SCALE_RANGE.1).contains(&k.scale)
2697+ && (0.0..=1.0).contains(&k.opacity);
2698+ if !in_range {
2699+ return Err("a title key's x and y are -1..=1, its scale 0.05..=10 and its opacity 0..=1".into());
2700+ }
2701+ if i > 0 && title.keys[i - 1].at >= k.at {
2702+ return Err("a title's keys are in frame order, with no two at one frame".into());
2703+ }
2704+ }
2686 Ok(())2705 Ok(())
2687 }2706 }
2688 2707
@@ -19771,6 +19790,7 @@ mod title_tests {
19771 in_anim: Default::default(),19790 in_anim: Default::default(),
19772 out_anim: Default::default(),19791 out_anim: Default::default(),
19773 anim_frames: 0,19792 anim_frames: 0,
19793+ keys: Vec::new(),
19774 }19794 }
19775 }19795 }
19776 19796
crates/engine/src/titleanim.rsmodified+68 -2
@@ -5,6 +5,52 @@
5 //! resting state down to nothing, with the easing reversed (ease-out in, ease-in out).5 //! resting state down to nothing, with the easing reversed (ease-out in, ease-in out).
6 6
7 use crate::project::Title;7 use crate::project::Title;
8+use crate::transform::{KeyEase, Keyed, sample};
9+
10+/// The shortest and longest scale a title key may set, as a multiple of the title's size.
11+pub const KEY_SCALE_RANGE: (f32, f32) = (0.05, 10.0);
12+
13+/// One point of a title's own keyframe animation: how far the title is moved, how much it is
14+/// scaled and how much it is faded at `at` frames from its first frame. Its values add onto
15+/// (shift) or multiply (scale, opacity) what the title's entrance and exit already do, and
16+/// between two keys they blend the way a clip's keys do.
17+#[derive(Clone, Copy, Debug, PartialEq)]
18+pub struct TitleKey {
19+ /// Frames from the title's first frame. A key past the title's length holds its value.
20+ pub at: u32,
21+ /// Added to the horizontal shift, as a share of the picture's width, `-1..=1`.
22+ pub x: f32,
23+ /// Added to the vertical shift, as a share of the picture's height, `-1..=1`; down is positive.
24+ pub y: f32,
25+ /// Multiplies the size, within [`KEY_SCALE_RANGE`]. `1` leaves it alone.
26+ pub scale: f32,
27+ /// Multiplies the opacity, `0..=1`. `1` leaves it alone.
28+ pub opacity: f32,
29+ /// The easing of the segment that leaves this key.
30+ pub ease: KeyEase,
31+}
32+
33+impl Keyed for TitleKey {
34+ fn at(&self) -> u32 {
35+ self.at
36+ }
37+ fn ease(&self) -> KeyEase {
38+ self.ease
39+ }
40+ fn placed(self, at: u32, ease: KeyEase) -> Self {
41+ Self { at, ease, ..self }
42+ }
43+ fn mix(a: &Self, b: &Self, t: f32) -> Self {
44+ let l = |x: f32, y: f32| x + (y - x) * t;
45+ Self {
46+ x: l(a.x, b.x),
47+ y: l(a.y, b.y),
48+ scale: l(a.scale, b.scale),
49+ opacity: l(a.opacity, b.opacity),
50+ ..*a
51+ }
52+ }
53+}
8 54
9 /// One of the animations a title plays on the way in or out.55 /// One of the animations a title plays on the way in or out.
10 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]56 #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
@@ -255,13 +301,21 @@ impl Title {
255 (Some(x), Some(y)) => Some(if x.1 <= y.1 { x } else { y }),301 (Some(x), Some(y)) => Some(if x.1 <= y.1 { x } else { y }),
256 (x, y) => x.or(y),302 (x, y) => x.or(y),
257 };303 };
258- Some(Motion {304+ let mut motion = Motion {
259 alpha: (alpha * a.alpha * b.alpha * 255.0) as u8,305 alpha: (alpha * a.alpha * b.alpha * 255.0) as u8,
260 dx: a.dx + b.dx,306 dx: a.dx + b.dx,
261 dy: a.dy + b.dy,307 dy: a.dy + b.dy,
262 scale: a.scale * b.scale,308 scale: a.scale * b.scale,
263 reveal,309 reveal,
264- })310+ };
311+ // The title's own keys come last: they shift, scale and fade whatever the entrance left.
312+ if let Some(key) = sample(&self.keys, f64::from(k)) {
313+ motion.dx += key.x;
314+ motion.dy += key.y;
315+ motion.scale *= key.scale;
316+ motion.alpha = (f32::from(motion.alpha) * key.opacity).round() as u8;
317+ }
318+ Some(motion)
265 }319 }
266 }320 }
267 321
@@ -282,9 +336,21 @@ mod tests {
282 in_anim: anim,336 in_anim: anim,
283 out_anim: TitleAnim::None,337 out_anim: TitleAnim::None,
284 anim_frames: 12,338 anim_frames: 12,
339+ keys: Vec::new(),
285 }340 }
286 }341 }
287 342
343+ #[test]
344+ fn two_keys_fade_and_shift_a_title_halfway_between_them() {
345+ // Opacity goes 0 to 1 and x 0 to 0.2 over the first ten frames: at frame 5 that is half
346+ // the alpha and a shift of 0.1 of the width.
347+ let key = |at, x, opacity| crate::titleanim::TitleKey { at, x, y: 0.0, scale: 1.0, opacity, ease: crate::transform::KeyEase::Linear };
348+ let t = Title { keys: vec![key(0, 0.0, 0.0), key(10, 0.2, 1.0)], ..title(TitleAnim::None, 60) };
349+ let m = t.motion_at(5).expect("up");
350+ assert!(m.alpha.abs_diff(128) <= 1, "alpha {}", m.alpha);
351+ assert!((m.dx - 0.1).abs() < 1e-6, "dx {}", m.dx);
352+ }
353+
288 #[test]354 #[test]
289 fn a_typewriter_title_shows_more_letters_from_its_start_to_its_middle_to_its_end() {355 fn a_typewriter_title_shows_more_letters_from_its_start_to_its_middle_to_its_end() {
290 // A 26-frame typewriter in a 60-frame title: the letters come up over its first 26 frames.356 // A 26-frame typewriter in a 60-frame title: the letters come up over its first 26 frames.
crates/engine/tests/burn_subs.rsmodified+1 -0
@@ -221,6 +221,7 @@ fn a_title_past_the_clip_is_exported_over_black() {
221 in_anim: Default::default(),221 in_anim: Default::default(),
222 out_anim: Default::default(),222 out_anim: Default::default(),
223 anim_frames: 0,223 anim_frames: 0,
224+ keys: Vec::new(),
224 })225 })
225 .expect("the title is added");226 .expect("the title is added");
226 let out = Scratch::file("ve_title_gap", "mp4");227 let out = Scratch::file("ve_title_gap", "mp4");
crates/engine/tests/it/compose_at.rsmodified+1 -0
@@ -146,6 +146,7 @@ fn title(start: u32, frames: u32, place: Place) -> Title {
146 in_anim: Default::default(),146 in_anim: Default::default(),
147 out_anim: Default::default(),147 out_anim: Default::default(),
148 anim_frames: 0,148 anim_frames: 0,
149+ keys: Vec::new(),
149 }150 }
150 }151 }
151 152
crates/engine/tests/it/export_deep_ten_bit.rsmodified+1 -1
@@ -303,7 +303,7 @@ fn title() {
303 check(303 check(
304 "title",304 "title",
305 |s, _| {305 |s, _| {
306- s.add_title(Title { start: 0, frames: 25, text: "T".into(), style: TextStyle::default(), fade_in: 0, fade_out: 0, in_anim: Default::default(), out_anim: Default::default(), anim_frames: 0 })306+ s.add_title(Title { start: 0, frames: 25, text: "T".into(), style: TextStyle::default(), fade_in: 0, fade_out: 0, in_anim: Default::default(), out_anim: Default::default(), anim_frames: 0, keys: Vec::new() })
307 .expect("title");307 .expect("title");
308 },308 },
309 None,309 None,
crates/engine/tests/it/fps_round_trip.rsmodified+2 -0
@@ -87,6 +87,7 @@ fn edit() -> PlaybackSession {
87 in_anim: Default::default(),87 in_anim: Default::default(),
88 out_anim: Default::default(),88 out_anim: Default::default(),
89 anim_frames: 0,89 anim_frames: 0,
90+ keys: Vec::new(),
90 })91 })
91 .expect("title");92 .expect("title");
92 s93 s
@@ -188,6 +189,7 @@ fn on_grid_edit() -> PlaybackSession {
188 in_anim: Default::default(),189 in_anim: Default::default(),
189 out_anim: Default::default(),190 out_anim: Default::default(),
190 anim_frames: 0,191 anim_frames: 0,
192+ keys: Vec::new(),
191 })193 })
192 .expect("title");194 .expect("title");
193 s195 s
crates/engine/tests/it/project_fuzz.rsmodified+2 -0
@@ -391,6 +391,7 @@ fn random_project(rng: &mut Rng, dir: &Path) -> Project {
391 in_anim: Default::default(),391 in_anim: Default::default(),
392 out_anim: Default::default(),392 out_anim: Default::default(),
393 anim_frames: 0,393 anim_frames: 0,
394+ keys: Vec::new(),
394 });395 });
395 }396 }
396 for _ in 0..rng.range(0, 3) {397 for _ in 0..rng.range(0, 3) {
@@ -1052,6 +1053,7 @@ fn wild_values_the_setters_accept_still_save_and_load() {
1052 in_anim: Default::default(),1053 in_anim: Default::default(),
1053 out_anim: Default::default(),1054 out_anim: Default::default(),
1054 anim_frames: 0,1055 anim_frames: 0,
1056+ keys: Vec::new(),
1055 });1057 });
1056 let _ = project.add_chapter(Chapter {1058 let _ = project.add_chapter(Chapter {
1057 frame: rng.range(0, 1000),1059 frame: rng.range(0, 1000),
crates/engine/tests/it/saveload.rsmodified+3 -1
@@ -1790,6 +1790,7 @@ fn titles_survive_a_save_and_an_open() {
1790 in_anim: Default::default(),1790 in_anim: Default::default(),
1791 out_anim: Default::default(),1791 out_anim: Default::default(),
1792 anim_frames: 0,1792 anim_frames: 0,
1793+ keys: Vec::new(),
1793 };1794 };
1794 let lower = Title {1795 let lower = Title {
1795 start: 60,1796 start: 60,
@@ -1801,6 +1802,7 @@ fn titles_survive_a_save_and_an_open() {
1801 in_anim: Default::default(),1802 in_anim: Default::default(),
1802 out_anim: Default::default(),1803 out_anim: Default::default(),
1803 anim_frames: 0,1804 anim_frames: 0,
1805+ keys: Vec::new(),
1804 };1806 };
1805 saved.add_title(card.clone()).expect("the card is added");1807 saved.add_title(card.clone()).expect("the card is added");
1806 saved1808 saved
@@ -1837,7 +1839,7 @@ fn a_title_look_survives_a_save_and_an_open_as_v49() {
1837 let dir = scratch("title_look");1839 let dir = scratch("title_look");
1838 let source = copy_in(&dir, "test_av.mp4");1840 let source = copy_in(&dir, "test_av.mp4");
1839 let mut plain = PlaybackSession::open(&source).expect("open the fixture");1841 let mut plain = PlaybackSession::open(&source).expect("open the fixture");
1840- let mk = |style: TextStyle| Title { start: 30, frames: 60, text: "Jane\nDirector".into(), style, fade_in: 0, fade_out: 0, in_anim: Default::default(), out_anim: Default::default(), anim_frames: 0 };1842+ let mk = |style: TextStyle| Title { start: 30, frames: 60, text: "Jane\nDirector".into(), style, fade_in: 0, fade_out: 0, in_anim: Default::default(), out_anim: Default::default(), anim_frames: 0, keys: Vec::new() };
1841 plain.add_title(mk(TextStyle::default())).expect("added");1843 plain.add_title(mk(TextStyle::default())).expect("added");
1842 let p0 = dir.join("plain.edith");1844 let p0 = dir.join("plain.edith");
1843 plain.save_project(&p0).expect("save");1845 plain.save_project(&p0).expect("save");
crates/engine/tests/it/undo_stress.rsmodified+1 -0
@@ -186,6 +186,7 @@ fn random_title(rng: &mut Rng) -> Title {
186 in_anim: Default::default(),186 in_anim: Default::default(),
187 out_anim: Default::default(),187 out_anim: Default::default(),
188 anim_frames: 0,188 anim_frames: 0,
189+ keys: Vec::new(),
189 }190 }
190 }191 }
191 192
crates/mcp/src/help.rsmodified+1 -1
@@ -177,7 +177,7 @@ RECIPES
177 Intro title and a lower third: a centred card over black, then a boxed caption over the picture.177 Intro title and a lower third: a centred card over black, then a boxed caption over the picture.
178 edit {ops:[{op:\"title_add\", at:\"0\", duration:3, text:\"Episode 17\", place:\"centre\", fade_in:12, fade_out:12}, {op:\"title_add\", at:\"5.0s\", duration:4, text:\"Jane Doe, director\", place:\"bottom\", boxed:true, fade_in:12, fade_out:12}]}178 edit {ops:[{op:\"title_add\", at:\"0\", duration:3, text:\"Episode 17\", place:\"centre\", fade_in:12, fade_out:12}, {op:\"title_add\", at:\"5.0s\", duration:4, text:\"Jane Doe, director\", place:\"bottom\", boxed:true, fade_in:12, fade_out:12}]}
179 A title past the last clip extends the timeline; edit {ops:[{op:\"title_set\", title:\"T2\", size:60}]} changes one, edit {ops:[{op:\"title_remove\", title:\"T1\"}]} takes it off (the titles after it renumber: T2 becomes T1), and timeline lists them as T lines.179 A title past the last clip extends the timeline; edit {ops:[{op:\"title_set\", title:\"T2\", size:60}]} changes one, edit {ops:[{op:\"title_remove\", title:\"T1\"}]} takes it off (the titles after it renumber: T2 becomes T1), and timeline lists them as T lines.
180- A title can start in one of the app's looks with preset (lower_third, centered or caption_bar): edit {ops:[{op:\"title_add\", at:\"5.0s\", duration:4, text:\"Jane Doe\", preset:\"lower_third\"}]}; fields given with it win. A title can carry a look: color (\"#ffcc00\"), weight (regular|bold; Latin letters, other scripts keep their one weight), hplace (centre|left|right: the side the block sits against, the margin from the edge), align (centre|left|right: how its lines line up inside the block), box_color (\"#000000\" keeps the opacity, \"#000000c8\" sets it) and box_opacity (0..1). A lower third: edit {ops:[{op:\"title_add\", at:\"5.0s\", duration:4, text:\"Jane Doe\\nDirector\", place:\"bottom\", hplace:\"left\", align:\"left\", weight:\"bold\", boxed:true, box_color:\"#112233\", box_opacity:0.8}]}. A project that uses one saves as format v49 (an older edith refuses it by name). A title can animate in and out: in_anim and out_anim are none, fade, typewriter (letters appear one by one), slide_up, slide_left, pop (grows from 60% with a slight overshoot) or word_by_word; anim_secs is how long each takes (a bare number is seconds, default 0.5). An exit is the entrance played backwards. Example: edit {ops:[{op:\"title_add\", at:\"0\", duration:4, text:\"Episode 17\", in_anim:\"typewriter\", out_anim:\"fade\", anim_secs:0.6}]}. An animated title saves as format v54 (a titleanim line; an older edith refuses it by name).180+ A title can start in one of the app's looks with preset (lower_third, centered or caption_bar): edit {ops:[{op:\"title_add\", at:\"5.0s\", duration:4, text:\"Jane Doe\", preset:\"lower_third\"}]}; fields given with it win. A title can carry a look: color (\"#ffcc00\"), weight (regular|bold; Latin letters, other scripts keep their one weight), hplace (centre|left|right: the side the block sits against, the margin from the edge), align (centre|left|right: how its lines line up inside the block), box_color (\"#000000\" keeps the opacity, \"#000000c8\" sets it) and box_opacity (0..1). A lower third: edit {ops:[{op:\"title_add\", at:\"5.0s\", duration:4, text:\"Jane Doe\\nDirector\", place:\"bottom\", hplace:\"left\", align:\"left\", weight:\"bold\", boxed:true, box_color:\"#112233\", box_opacity:0.8}]}. A project that uses one saves as format v49 (an older edith refuses it by name). A title can animate in and out: in_anim and out_anim are none, fade, typewriter (letters appear one by one), slide_up, slide_left, pop (grows from 60% with a slight overshoot) or word_by_word; anim_secs is how long each takes (a bare number is seconds, default 0.5). An exit is the entrance played backwards. Example: edit {ops:[{op:\"title_add\", at:\"0\", duration:4, text:\"Episode 17\", in_anim:\"typewriter\", out_anim:\"fade\", anim_secs:0.6}]}. An animated title saves as format v54 (a titleanim line; an older edith refuses it by name). A title can also carry its own keys, which move, scale and fade it over its length: title_add keys:[{at:\"0s\", opacity:0}, {at:\"1s\", opacity:1, x:0.1, scale:1.2}] (at counts from the title's first frame; x and y are a share of the picture, scale multiplies its size, opacity its alpha; missing fields are 0, 0, 1, 1; keys:[] takes them off). Keys save as format v56 (a ttkeys line).
181 Black lead-in for an intro title: edit {ops:[{op:\"insert_time\", at:\"0\", duration:\"3s\"}]} opens black before the picture, then title_add at 0 sits over that black.181 Black lead-in for an intro title: edit {ops:[{op:\"insert_time\", at:\"0\", duration:\"3s\"}]} opens black before the picture, then title_add at 0 sits over that black.
182 edit {ops:[{op:\"insert_time\", at:\"0\", duration:\"3s\"}, {op:\"title_add\", at:\"0\", duration:3, text:\"Episode 17\", place:\"centre\", fade_in:12, fade_out:12}]}182 edit {ops:[{op:\"insert_time\", at:\"0\", duration:\"3s\"}, {op:\"title_add\", at:\"0\", duration:3, text:\"Episode 17\", place:\"centre\", fade_in:12, fade_out:12}]}
183 Speed a clip that has narration over it (the examples need a picture clip at V1@0, and the narration lane A3 from first_video): narration on its own lane (A3, as in first_video) is outside the ripple by default, so edit {ops:[{op:\"speed\", clip:\"V1@0\", x:0.5, ripple:true}]} changes the picture's length and the narration keeps its times.183 Speed a clip that has narration over it (the examples need a picture clip at V1@0, and the narration lane A3 from first_video): narration on its own lane (A3, as in first_video) is outside the ripple by default, so edit {ops:[{op:\"speed\", clip:\"V1@0\", x:0.5, ripple:true}]} changes the picture's length and the narration keeps its times.
crates/mcp/src/tools/edit.rsmodified+4 -3
@@ -151,8 +151,9 @@ cue_time {track, index, at?, to?} — trim or move one cue: its new start (at) a
151 cue_merge {track, index} — join a cue with the next one. cue_split {track, index, at} — divide a cue in two at a timeline time.151 cue_merge {track, index} — join a cue with the next one. cue_split {track, index, at} — divide a cue in two at a timeline time.
152 cue_replace {track?, find, replace, case_sensitive?} — replace a word or phrase in every cue of a track (all tracks when track is omitted); case-insensitive unless case_sensitive. Reports occurrences and cues; one undo step.152 cue_replace {track?, find, replace, case_sensitive?} — replace a word or phrase in every cue of a track (all tracks when track is omitted); case-insensitive unless case_sensitive. Reports occurrences and cues; one undo step.
153 TITLES153 TITLES
154-title_add {at, duration, text, preset?=lower_third|centered|caption_bar, size?=80, outline?=thin|none|thick, boxed?=false, place?=centre|top|bottom, hplace?=centre|left|right, color?=#ffffff, weight?=regular|bold, align?=centre|left|right, box_color?=#000000 (or #rrggbbaa), box_opacity?=0.6 (0..1), fade_in?, fade_out?} — a card over the picture (black where no clip plays). place is the vertical position, hplace the side the block sits against (a lower third is place:bottom, hplace:left), align how its lines line up inside it. preset gives the app's one-click look (lower_third: bold, bottom left, boxed; centered: large, outlined, middle; caption_bar: boxed, bottom, no fades); the fields given with it win over its look, and title_set applies a preset to a title and keeps its words and timing. A look off the default saves as format v49. at and duration are times (a bare number is seconds). Fades: int = frames, "0.5s" = time. Past the last clip it extends the timeline. Named T1.. in start order.154+title_add {at, duration, text, preset?=lower_third|centered|caption_bar, size?=80, outline?=thin|none|thick, boxed?=false, place?=centre|top|bottom, hplace?=centre|left|right, color?=#ffffff, weight?=regular|bold, align?=centre|left|right, box_color?=#000000 (or #rrggbbaa), box_opacity?=0.6 (0..1), fade_in?, fade_out?, in_anim?, out_anim?, anim_secs?, keys?=[{at, x?, y?, scale?, opacity?, ease?}]} — a card over the picture (black where no clip plays). place is the vertical position, hplace the side the block sits against (a lower third is place:bottom, hplace:left), align how its lines line up inside it. preset gives the app's one-click look (lower_third: bold, bottom left, boxed; centered: large, outlined, middle; caption_bar: boxed, bottom, no fades); the fields given with it win over its look, and title_set applies a preset to a title and keeps its words and timing. A look off the default saves as format v49. at and duration are times (a bare number is seconds). Fades: int = frames, "0.5s" = time. Past the last clip it extends the timeline. Named T1.. in start order.
155 title_set {title:"T1" or "T@45", ...any of the same fields} — merged onto the title. A title is named T1.. in start order, or by its start frame as T@45 (the form a reply prints after each title op, which stays right when titles renumber). title_remove {title} — takes it off.155 title_set {title:"T1" or "T@45", ...any of the same fields} — merged onto the title. A title is named T1.. in start order, or by its start frame as T@45 (the form a reply prints after each title op, which stays right when titles renumber). title_remove {title} — takes it off.
156+Title keys animate the title over its own length: keys:[{at:"0s", opacity:0}, {at:"1s", opacity:1, x:0.1, scale:1.2, y:-0.05, ease:"ease_out"}]. at is a time from the title's first frame (a bare number is seconds, "50%" or "end" also work); a key past the title's end holds its value. x and y shift the title as a share of the picture (-1..1, y down is positive), scale multiplies its size (0.05..10), opacity multiplies its alpha (0..1). A missing field is x 0, y 0, scale 1, opacity 1, and ease is the segment's easing as for transform_keys. keys:[] takes the animation off. Titles with keys save as format v56.
156 GENERATED157 GENERATED
157 generator_add {kind: solid|gradient|countdown|bars|tone|rectangle|ellipse|line|arrow, color?, color2?, angle?, from?, fill?, stroke?, width?, radius?, lane?=V1, at?, duration?=5s} — a clip made from numbers, not a file, on a video lane that exists (else lane_add first). color is hex such as ff3366 or #ff3366 (solid; gradient start), color2 the gradient end, angle 0..359 degrees (0 left to right, 90 top to bottom), from the countdown's seconds (1..3600; its duration defaults to the count). Shapes (rectangle, ellipse, line, arrow) draw on a transparent canvas and land at 40% scale over the lanes below: fill and stroke are hex or none, width the stroke in pixels (0..400), radius rounds a rectangle; size and place come from the transform op. at defaults to the end of the lane. It trims, moves, grades and takes effects like any clip; it overwrites what it lands on, as a still does.158 generator_add {kind: solid|gradient|countdown|bars|tone|rectangle|ellipse|line|arrow, color?, color2?, angle?, from?, fill?, stroke?, width?, radius?, lane?=V1, at?, duration?=5s} — a clip made from numbers, not a file, on a video lane that exists (else lane_add first). color is hex such as ff3366 or #ff3366 (solid; gradient start), color2 the gradient end, angle 0..359 degrees (0 left to right, 90 top to bottom), from the countdown's seconds (1..3600; its duration defaults to the count). Shapes (rectangle, ellipse, line, arrow) draw on a transparent canvas and land at 40% scale over the lanes below: fill and stroke are hex or none, width the stroke in pixels (0..400), radius rounds a rectangle; size and place come from the transform op. at defaults to the end of the lane. It trims, moves, grades and takes effects like any clip; it overwrites what it lands on, as a still does.
158 generator_set {clip, color?, color2?, angle?, from?, fill?, stroke?, width?, radius?} — change a generator clip's params, keeping its place and length; a clip that plays a file is refused.159 generator_set {clip, color?, color2?, angle?, from?, fill?, stroke?, width?, radius?} — change a generator clip's params, keeping its place and length; a clip that plays a file is refused.
@@ -335,8 +336,8 @@ fn accepted_keys(name: &str) -> Option<&'static [&'static str]> {
335 "group" => &["clips"],336 "group" => &["clips"],
336 "ungroup" => &["clip"],337 "ungroup" => &["clip"],
337 "subtitles_import" => &["path", "lang"],338 "subtitles_import" => &["path", "lang"],
338- "title_add" => &["at", "duration", "text", "preset", "size", "outline", "boxed", "place", "hplace", "color", "colour", "weight", "align", "box_color", "box_colour", "box_opacity", "fade_in", "fade_out", "in_anim", "out_anim", "anim_secs"],339+ "title_add" => &["at", "duration", "text", "preset", "size", "outline", "boxed", "place", "hplace", "color", "colour", "weight", "align", "box_color", "box_colour", "box_opacity", "fade_in", "fade_out", "in_anim", "out_anim", "anim_secs", "keys"],
339- "title_set" => &["title", "at", "duration", "text", "preset", "size", "outline", "boxed", "place", "hplace", "color", "colour", "weight", "align", "box_color", "box_colour", "box_opacity", "fade_in", "fade_out", "in_anim", "out_anim", "anim_secs"],340+ "title_set" => &["title", "at", "duration", "text", "preset", "size", "outline", "boxed", "place", "hplace", "color", "colour", "weight", "align", "box_color", "box_colour", "box_opacity", "fade_in", "fade_out", "in_anim", "out_anim", "anim_secs", "keys"],
340 "title_remove" => &["title"],341 "title_remove" => &["title"],
341 "chapter_add" => &["at", "title"],342 "chapter_add" => &["at", "title"],
342 "chapter_set" => &["chapter", "title", "at"],343 "chapter_set" => &["chapter", "title", "at"],
crates/mcp/src/tools/edit_fx.rsmodified+136 -6
@@ -24,7 +24,7 @@ use engine::scale::FitPolicy;
24 use engine::text::{layout_share, missing_glyphs, Align, HPlace, Outline, Place, TextStyle, Weight, SIZE_RANGE};24 use engine::text::{layout_share, missing_glyphs, Align, HPlace, Outline, Place, TextStyle, Weight, SIZE_RANGE};
25 use engine::color::{ColorKey, MAX_COLOR_KEYS};25 use engine::color::{ColorKey, MAX_COLOR_KEYS};
26 use engine::transform::{Bezier, Corner, KeyEase, OpacityKey, TransformKey, TransformParams, MAX_TRANSFORM_KEYS};26 use engine::transform::{Bezier, Corner, KeyEase, OpacityKey, TransformKey, TransformParams, MAX_TRANSFORM_KEYS};
27-use engine::titleanim::TitleAnim;27+use engine::titleanim::{KEY_SCALE_RANGE, TitleAnim, TitleKey};
28 use engine::PlaybackSession;28 use engine::PlaybackSession;
29 use serde_json::{json, Value};29 use serde_json::{json, Value};
30 30
@@ -2360,7 +2360,7 @@ pub(super) fn title_line(name: &str, t: &Title, fps: f64) -> String {
2360 }2360 }
2361 let boxed = if t.style.boxed { " boxed" } else { "" };2361 let boxed = if t.style.boxed { " boxed" } else { "" };
2362 format!(2362 format!(
2363- "title {name} \"{}\" {:.3}–{:.3} {} size {} outline {}{boxed}{look} fade {}f/{}f{anim}",2363+ "title {name} \"{}\" {:.3}–{:.3} {} size {} outline {}{boxed}{look} fade {}f/{}f{anim}{keys}",
2364 t.text.replace('\n', "\\n"),2364 t.text.replace('\n', "\\n"),
2365 parse::secs(t.start, fps),2365 parse::secs(t.start, fps),
2366 parse::secs(t.end(), fps),2366 parse::secs(t.end(), fps),
@@ -2373,7 +2373,8 @@ pub(super) fn title_line(name: &str, t: &Title, fps: f64) -> String {
2373 String::new()2373 String::new()
2374 } else {2374 } else {
2375 format!(" anim in {} out {} {}f", t.in_anim.name(), t.out_anim.name(), t.anim_frames)2375 format!(" anim in {} out {} {}f", t.in_anim.name(), t.out_anim.name(), t.anim_frames)
2376- }2376+ },
2377+ keys = title_keys_text(t, fps)
2377 )2378 )
2378 }2379 }
2379 2380
@@ -2505,9 +2506,132 @@ fn title_preset_arg(op: &Value) -> Result<Option<TitlePreset>, String> {
2505 }2506 }
2506 }2507 }
2507 2508
2508-/// `title_add {at, duration, text, preset?, size?=80, outline?="thin", boxed?=false, place?="centre", fade_in?=0, fade_out?=0, in_anim?, out_anim?, anim_secs?=0.5}`.2509+/// The `at` of a title key: a time from the title's first frame, read as `title_add` reads its
2510+/// times (a bare number is seconds), `end` for the title's last frame, or a percentage of its length.
2511+fn title_key_offset(n: usize, at: &Value, frames: u32, fps: f64) -> Result<u32, String> {
2512+ if let Some(text) = at.as_str() {
2513+ let text = text.trim();
2514+ if text.eq_ignore_ascii_case("end") {
2515+ return Ok(frames);
2516+ }
2517+ if let Some(pct) = text.strip_suffix('%') {
2518+ let share: f64 = pct
2519+ .trim()
2520+ .parse()
2521+ .map_err(|_| format!("title keys: key {n} at {text:?} is not a percentage"))?;
2522+ if !(0.0..=100.0).contains(&share) {
2523+ return Err(format!("title keys: key {n} at {text} is outside the title, 0% to 100%"));
2524+ }
2525+ return Ok((f64::from(frames) * share / 100.0).round() as u32);
2526+ }
2527+ }
2528+ parse::frame(at, fps, u32::MAX).map_err(|e| format!("title keys: key {n}: {e}"))
2529+}
2530+
2531+/// The `keys` of a `title_add` or `title_set`: a list of `{at, x?, y?, scale?, opacity?, ease?}`,
2532+/// each `at` a time from the title's first frame. A key leaves x and y at 0 and scale and opacity
2533+/// at 1 when it does not name them. `[]` takes the animation off, and `None` means the op gives no
2534+/// `keys`. A key past the title's `frames` holds its value there.
2535+fn title_keys_arg(op: &Value, fps: f64, frames: u32) -> Result<Option<Vec<TitleKey>>, String> {
2536+ let list = match op.get("keys") {
2537+ None | Some(Value::Null) => return Ok(None),
2538+ Some(Value::Array(a)) => a,
2539+ Some(v) => {
2540+ return Err(format!(
2541+ "title keys must be a list of {{at, x?, y?, scale?, opacity?, ease?}} objects, got {}",
2542+ kind_of(v)
2543+ ))
2544+ }
2545+ };
2546+ if list.len() > MAX_TRANSFORM_KEYS {
2547+ return Err(format!("title keys: {} keys, and at most {MAX_TRANSFORM_KEYS} fit", list.len()));
2548+ }
2549+ let who = "title keys";
2550+ let mut keys: Vec<TitleKey> = Vec::with_capacity(list.len());
2551+ for (i, k) in list.iter().enumerate() {
2552+ let n = i + 1;
2553+ let obj = k.as_object().ok_or_else(|| {
2554+ format!("{who}: key {n} must be an object such as {{\"at\": \"0s\", \"opacity\": 0}}")
2555+ })?;
2556+ if let Some(bad) = obj
2557+ .keys()
2558+ .find(|name| !matches!(name.as_str(), "at" | "x" | "y" | "scale" | "opacity" | "ease"))
2559+ {
2560+ return Err(format!(
2561+ "{who}: key {n} has `{bad}`, which a title key does not take: x, y, scale, opacity, ease, at"
2562+ ));
2563+ }
2564+ let at = obj
2565+ .get("at")
2566+ .ok_or_else(|| format!("{who}: key {n} has no `at`, the time from the title's first frame"))?;
2567+ keys.push(TitleKey {
2568+ at: title_key_offset(n, at, frames, fps)?,
2569+ x: or_default(who, k, "x", 0.0, -1.0, 1.0)?,
2570+ y: or_default(who, k, "y", 0.0, -1.0, 1.0)?,
2571+ scale: or_default(who, k, "scale", 1.0, KEY_SCALE_RANGE.0, KEY_SCALE_RANGE.1)?,
2572+ opacity: or_default(who, k, "opacity", 1.0, 0.0, 1.0)?,
2573+ ease: ease_of(who, n, k)?,
2574+ });
2575+ }
2576+ keys.sort_by_key(|k| k.at);
2577+ if keys.windows(2).any(|w| w[0].at == w[1].at) {
2578+ return Err(format!("{who}: two keys at the same time; space them further apart"));
2579+ }
2580+ Ok(Some(keys))
2581+}
2582+
2583+/// A title's keys as the JSON a listing carries: each `at` in seconds from the title's start.
2584+pub(super) fn title_keys_json(t: &Title, fps: f64) -> Value {
2585+ Value::Array(
2586+ t.keys
2587+ .iter()
2588+ .map(|k| {
2589+ json!({
2590+ "at": parse::secs(k.at, fps),
2591+ "x": k.x,
2592+ "y": k.y,
2593+ "scale": k.scale,
2594+ "opacity": k.opacity,
2595+ "ease": k.ease.name(),
2596+ })
2597+ })
2598+ .collect(),
2599+ )
2600+}
2601+
2602+/// A title's keys as a reply fragment, ` keys 2: +0.000s x 0.00 y 0.00 scale 1.00 opacity 0.00 · …`,
2603+/// at most twelve, then `(+N more)`. Empty for a title with none.
2604+pub(super) fn title_keys_text(t: &Title, fps: f64) -> String {
2605+ const SHOWN: usize = 12;
2606+ if t.keys.is_empty() {
2607+ return String::new();
2608+ }
2609+ let mut parts: Vec<String> = t
2610+ .keys
2611+ .iter()
2612+ .take(SHOWN)
2613+ .map(|k| {
2614+ format!(
2615+ "+{} x {:.2} y {:.2} scale {:.2} opacity {:.2}{}",
2616+ tsec(f64::from(k.at), fps),
2617+ k.x,
2618+ k.y,
2619+ k.scale,
2620+ k.opacity,
2621+ ease_suffix(k.ease)
2622+ )
2623+ })
2624+ .collect();
2625+ if t.keys.len() > SHOWN {
2626+ parts.push(format!("(+{} more)", t.keys.len() - SHOWN));
2627+ }
2628+ format!(" keys {}: {}", t.keys.len(), parts.join(" · "))
2629+}
2630+
2631+/// `title_add {at, duration, text, preset?, size?=80, outline?="thin", boxed?=false, place?="centre", fade_in?=0, fade_out?=0, in_anim?, out_anim?, anim_secs?=0.5, keys?}`.
2509 /// `at` and `duration` are times (a bare number is seconds). Fades are frames as2632 /// `at` and `duration` are times (a bare number is seconds). Fades are frames as
2510-/// an integer, or a time string. The title lands in start order; the reply gives2633+/// an integer, or a time string. `keys` animates the title itself ([`title_keys_arg`]).
2634+/// The title lands in start order; the reply gives
2511 /// the `T<n>` it now holds, and says when titles after it renumber.2635 /// the `T<n>` it now holds, and says when titles after it renumber.
2512 fn title_add(s: &mut PlaybackSession, op: &Value, fps: f64) -> Result<Applied, String> {2636 fn title_add(s: &mut PlaybackSession, op: &Value, fps: f64) -> Result<Applied, String> {
2513 let end = parse::session_end(s);2637 let end = parse::session_end(s);
@@ -2516,7 +2640,7 @@ fn title_add(s: &mut PlaybackSession, op: &Value, fps: f64) -> Result<Applied, S
2516 let text = req_str(op, "text")?.to_string();2640 let text = req_str(op, "text")?.to_string();
2517 let base = TextStyle { size: 80, outline: Outline::Thin, boxed: false, place: Place::Centre, ..TextStyle::default() };2641 let base = TextStyle { size: 80, outline: Outline::Thin, boxed: false, place: Place::Centre, ..TextStyle::default() };
2518 // A preset is the look the title starts in; the fields given after it win over the preset.2642 // A preset is the look the title starts in; the fields given after it win over the preset.
2519- let mut t = Title { start, frames, text, style: base, fade_in: 0, fade_out: 0, in_anim: Default::default(), out_anim: Default::default(), anim_frames: 0 };2643+ let mut t = Title { start, frames, text, style: base, fade_in: 0, fade_out: 0, in_anim: Default::default(), out_anim: Default::default(), anim_frames: 0, keys: Vec::new() };
2520 if let Some(p) = title_preset_arg(op)? {2644 if let Some(p) = title_preset_arg(op)? {
2521 t.apply_preset(p, fps);2645 t.apply_preset(p, fps);
2522 }2646 }
@@ -2524,6 +2648,9 @@ fn title_add(s: &mut PlaybackSession, op: &Value, fps: f64) -> Result<Applied, S
2524 t.fade_in = length(op, "fade_in", fps)?.unwrap_or(t.fade_in);2648 t.fade_in = length(op, "fade_in", fps)?.unwrap_or(t.fade_in);
2525 t.fade_out = length(op, "fade_out", fps)?.unwrap_or(t.fade_out);2649 t.fade_out = length(op, "fade_out", fps)?.unwrap_or(t.fade_out);
2526 title_anim_fields(op, &mut t, fps)?;2650 title_anim_fields(op, &mut t, fps)?;
2651+ if let Some(keys) = title_keys_arg(op, fps, t.frames)? {
2652+ t.keys = keys;
2653+ }
2527 check_title(&t).map_err(|e| format!("title_add: {e}"))?;2654 check_title(&t).map_err(|e| format!("title_add: {e}"))?;
2528 let warnings = title_warnings(s, &t);2655 let warnings = title_warnings(s, &t);
2529 // The new title is not in the list yet, so every title there is one it may overlap.2656 // The new title is not in the list yet, so every title there is one it may overlap.
@@ -2585,6 +2712,9 @@ fn title_set(s: &mut PlaybackSession, op: &Value, fps: f64) -> Result<Applied, S
2585 t.fade_out = f;2712 t.fade_out = f;
2586 }2713 }
2587 title_anim_fields(op, &mut t, fps)?;2714 title_anim_fields(op, &mut t, fps)?;
2715+ if let Some(keys) = title_keys_arg(op, fps, t.frames)? {
2716+ t.keys = keys;
2717+ }
2588 let name = title_name(idx);2718 let name = title_name(idx);
2589 if t == old {2719 if t == old {
2590 return Ok(Applied { text: format!("{name} unchanged"), touched: Vec::new() });2720 return Ok(Applied { text: format!("{name} unchanged"), touched: Vec::new() });
crates/mcp/src/tools/look.rsmodified+6 -4
@@ -462,6 +462,7 @@ fn title_rows(s: &PlaybackSession, fps: f64, range: Option<(u32, u32)>, full: bo
462 "fade_out": t.fade_out,462 "fade_out": t.fade_out,
463 "in_anim": t.in_anim.name(),463 "in_anim": t.in_anim.name(),
464 "out_anim": t.out_anim.name(),464 "out_anim": t.out_anim.name(),
465+ "keys": super::edit_fx::title_keys_json(t, fps),
465 })466 })
466 })467 })
467 .collect();468 .collect();
@@ -469,12 +470,13 @@ fn title_rows(s: &PlaybackSession, fps: f64, range: Option<(u32, u32)>, full: bo
469 let mut used = 0;470 let mut used = 0;
470 for (k, (i, t)) in shown.iter().enumerate() {471 for (k, (i, t)) in shown.iter().enumerate() {
471 let line = format!(472 let line = format!(
472- "T {} {:.3}–{:.3} \"{}\" {}",473+ "T {} {:.3}–{:.3} \"{}\" {}{}",
473 title_name(*i),474 title_name(*i),
474 parse::secs(t.start, fps),475 parse::secs(t.start, fps),
475 parse::secs(t.end(), fps),476 parse::secs(t.end(), fps),
476 short_text(&t.text),477 short_text(&t.text),
477- place_word(t.style.place)478+ place_word(t.style.place),
479+ super::edit_fx::title_keys_text(t, fps)
478 );480 );
479 if !full && k > 0 && used + line.len() + 1 > room {481 if !full && k > 0 && used + line.len() + 1 > room {
480 lines.push(format!("T … {} more titles (use range)", shown.len() - k));482 lines.push(format!("T … {} more titles (use range)", shown.len() - k));
@@ -2525,9 +2527,9 @@ mod tests {
2525 let style = TextStyle { size: 80, outline: Outline::Thin, boxed: false, place: Place::Centre, ..TextStyle::default() };2527 let style = TextStyle { size: 80, outline: Outline::Thin, boxed: false, place: Place::Centre, ..TextStyle::default() };
2526 let sess = srv.session.as_mut().unwrap();2528 let sess = srv.session.as_mut().unwrap();
2527 let long = "x".repeat(60);2529 let long = "x".repeat(60);
2528- sess.add_title(Title { start: 0, frames: 90, text: "Episode 17".into(), style: style.clone(), fade_in: 0, fade_out: 0, in_anim: Default::default(), out_anim: Default::default(), anim_frames: 0 })2530+ sess.add_title(Title { start: 0, frames: 90, text: "Episode 17".into(), style: style.clone(), fade_in: 0, fade_out: 0, in_anim: Default::default(), out_anim: Default::default(), anim_frames: 0, keys: Vec::new() })
2529 .unwrap();2531 .unwrap();
2530- sess.add_title(Title { start: 150, frames: 30, text: long.clone(), style, fade_in: 0, fade_out: 0, in_anim: Default::default(), out_anim: Default::default(), anim_frames: 0 }).unwrap();2532+ sess.add_title(Title { start: 150, frames: 30, text: long.clone(), style, fade_in: 0, fade_out: 0, in_anim: Default::default(), out_anim: Default::default(), anim_frames: 0, keys: Vec::new() }).unwrap();
2531 2533
2532 let r = call(&mut srv, "timeline", json!({}));2534 let r = call(&mut srv, "timeline", json!({}));
2533 let t1 = format!("T T1 0.000–{:.3} \"Episode 17\" centre", 90.0 / fps);2535 let t1 = format!("T T1 0.000–{:.3} \"Episode 17\" centre", 90.0 / fps);