✨ Keyframes on every effect parameter: EffectKey, ekeys (v56), MCP effect_keys, key diamond on every effect
Browse files at this commitb0e72a42e482f7603c72a380b36a5fe895f8c226Parent: 70d113012 changed files +426 -201
- MCP.md +3 -2
- crates/app/src/player/effects.rs +24 -27
- crates/app/src/ui/cards/effects.rs +11 -6
- crates/engine/src/edith.rs +113 -55
- crates/engine/src/effects.rs +46 -41
- crates/engine/src/playback.rs +15 -13
- crates/engine/src/project.rs +28 -22
- crates/mcp/src/help.rs +9 -0
- crates/mcp/src/tools/edit.rs +3 -2
- crates/mcp/src/tools/edit_fx.rs +111 -32
- crates/mcp/src/tools/effects.rs +1 -1
- crates/mcp/src/tools/look.rs +62 -0
MCP.mdmodified+3 -2
| @@ -353,10 +353,11 @@ Also: `undo {steps?=1}`, `redo {steps?=1}` (an edit clears redo history). | |||
| 353 | | `set` | **clip**, **index**, params, on, color, mode | changes the effect at `index`; unnamed values keep theirs; `on:false` switches it off and keeps its settings. Out-of-range numbers are clamped and the reply says so | | 353 | | `set` | **clip**, **index**, params, on, color, mode | changes the effect at `index`; unnamed values keep theirs; `on:false` switches it off and keeps its settings. Out-of-range numbers are clamped and the reply says so | |
| 354 | | `remove` | **clip**, **index** | takes the effect out | | 354 | | `remove` | **clip**, **index** | takes the effect out | |
| 355 | | `move` | **clip**, **from**, **to** | moves an effect within the stack | | 355 | | `move` | **clip**, **from**, **to** | moves an effect within the stack | |
| 356 | +| `effect_keys` | **clip**, **effect**, **keys**, clear | sets the whole key list of any effect at stack position `effect`, over the clip's own time. Every numeric parameter can be keyed, named as the effect names it (a blur's `radius`, a vignette's `amount` and `softness`, a chroma_key's `tolerance`, a pixelate's `size`, a mask's `x`, `y`, `width`, `height`, `feather`). Each key is `{at, <parameter>?: value, ease?}`. A switch or a choice (a blend's `mode`, a mask's `invert`) is refused by name. A parameter a key leaves out takes the value the effect shows at that time. Keys sort by time and the values are clamped; up to 256 keys; `ease` as in `mask_keys`. `clear:true` takes the keys off. | | ||
| 356 | | `mask_keys` | **clip**, **effect**, **keys**, clear | sets the whole key list of a rect_mask or ellipse_mask at stack position `effect`. Each key is `{at, x?, y?, w?, h?, feather?, ease?}`: `at` a time, `x`/`y` the centre and `w`/`h` the size as fractions of the frame, `feather` the soft edge, `ease` the move into the next key (linear, ease_in, ease_out, ease_in_out, hold, or bezier(x1,y1,x2,y2)). Keys sort by time; a key that names no field holds the previous key's values, and the first key the mask's own. Between keys the mask moves smoothly; before the first and after the last it holds. Up to 256 keys. `clear:true` takes the keys off and the mask goes back to its static values. Refused on any other kind | | 357 | | `mask_keys` | **clip**, **effect**, **keys**, clear | sets the whole key list of a rect_mask or ellipse_mask at stack position `effect`. Each key is `{at, x?, y?, w?, h?, feather?, ease?}`: `at` a time, `x`/`y` the centre and `w`/`h` the size as fractions of the frame, `feather` the soft edge, `ease` the move into the next key (linear, ease_in, ease_out, ease_in_out, hold, or bezier(x1,y1,x2,y2)). Keys sort by time; a key that names no field holds the previous key's values, and the first key the mask's own. Between keys the mask moves smoothly; before the first and after the last it holds. Up to 256 keys. `clear:true` takes the keys off and the mask goes back to its static values. Refused on any other kind | |
| 357 | -| `list` | clip | the stack with each effect's position, kind, on/off and named values, and `keys=N` for a keyed mask; with no `clip`, every kind with its parameters and ranges | | 358 | +| `list` | clip | the stack with each effect's position, kind, on/off and named values, and `keys=N` for a keyed effect; with no `clip`, every kind with its parameters and ranges | |
| 358 | 359 | ||
| 359 | -Effects are static, one value for the whole clip, except a mask with `mask_keys`, which moves between its keys; Ken Burns stays in `transform_keys`. A pixelate is limited by the first rect_mask or ellipse_mask after it (that mask only shapes the pixelation and does not cut the clip), so an ellipse after a pixelate censors a region. Distances (blur radius, shake amount) are pixels at 1080 lines and scale with the frame height. The stack applies in order on the clip's placed picture in preview and export; chroma_key and the masks reveal the lanes below, `blend` picks how the clip lies over them. An empty or all-off stack changes nothing. Setting what is already there is no undo step. Errors are specific: an unknown kind lists the kinds, an unknown parameter lists the parameters, a bad position gives the valid range, an audio lane is refused, a 17th effect is refused. | 360 | +Effects are static, one value for the whole clip, unless keyed: any numeric parameter moves between the keys of `effect_keys` (and a mask's position between its `mask_keys`); Ken Burns stays in `transform_keys`. A pixelate is limited by the first rect_mask or ellipse_mask after it (that mask only shapes the pixelation and does not cut the clip), so an ellipse after a pixelate censors a region. Distances (blur radius, shake amount) are pixels at 1080 lines and scale with the frame height. The stack applies in order on the clip's placed picture in preview and export; chroma_key and the masks reveal the lanes below, `blend` picks how the clip lies over them. An empty or all-off stack changes nothing. Setting what is already there is no undo step. Errors are specific: an unknown kind lists the kinds, an unknown parameter lists the parameters, a bad position gives the valid range, an audio lane is refused, a 17th effect is refused. |
| 360 | 361 | ||
| 361 | Recipes: *Vignette plus soft blur* -- `effect {op:"add", clip:"V1#0", kind:"vignette", params:{amount:0.6}}`, then `effect {op:"add", clip:"V1#0", kind:"blur", params:{radius:4}}`. *Green screen over a background lane* -- background on V1, the green-screen take on V2: `effect {op:"add", clip:"V2#0", kind:"chroma_key", color:"#00ff00", params:{tolerance:0.35, softness:0.1, spill:0.5}}`; the keyed-out part shows V1. | 362 | Recipes: *Vignette plus soft blur* -- `effect {op:"add", clip:"V1#0", kind:"vignette", params:{amount:0.6}}`, then `effect {op:"add", clip:"V1#0", kind:"blur", params:{radius:4}}`. *Green screen over a background lane* -- background on V1, the green-screen take on V2: `effect {op:"add", clip:"V2#0", kind:"chroma_key", color:"#00ff00", params:{tolerance:0.35, softness:0.1, spill:0.5}}`; the keyed-out part shows V1. |
| 362 | 363 | ||
crates/app/src/player/effects.rsmodified+24 -27
| @@ -5,7 +5,7 @@ | |||
| 5 | 5 | ||
| 6 | use crate::*; | 6 | use crate::*; |
| 7 | use crate::player::cards::{bar_fraction, value_at}; | 7 | use crate::player::cards::{bar_fraction, value_at}; |
| 8 | -use engine::effects::{BlendMode, Effect, EffectKind, MAX_EFFECTS, MAX_PARAMS, MaskKey, ParamSpec}; | 8 | +use engine::effects::{BlendMode, Effect, EffectKey, EffectKind, MAX_EFFECTS, MAX_PARAMS, ParamSpec}; |
| 9 | use engine::transform::KeyEase; | 9 | use engine::transform::KeyEase; |
| 10 | 10 | ||
| 11 | /// How a parameter is drawn: a bar, an on/off switch (a step of 1 over 0..1), or the | 11 | /// How a parameter is drawn: a bar, an on/off switch (a step of 1 over 0..1), or the |
| @@ -83,31 +83,26 @@ pub(crate) fn param_display(kind: EffectKind, spec: &ParamSpec, value: f32) -> S | |||
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | /// The plain word for a blend mode. | 85 | /// The plain word for a blend mode. |
| 86 | -/// The mask key a mask effect holds at source frame `at`: the shape it shows there, as a key of its own. | 86 | +/// The key an effect holds at source frame `at`: every parameter as the effect shows it there, |
| 87 | -fn mask_key_at(e: &Effect, at: u32) -> MaskKey { | 87 | +/// as a key of its own. |
| 88 | - let base = e.posed(f64::from(at)).into_owned(); | 88 | +fn effect_key_at(e: &Effect, at: u32) -> EffectKey { |
| 89 | - let v = base.values; | 89 | + let values = e.posed(f64::from(at)).values; |
| 90 | - MaskKey { at, x: v[0], y: v[1], width: v[2], height: v[3], feather: v[4], ease: KeyEase::Linear } | 90 | + EffectKey { at, values, ease: KeyEase::Linear } |
| 91 | } | 91 | } |
| 92 | 92 | ||
| 93 | -/// Writes parameter `p` of `e`. A keyed mask takes the change on its key at source frame | 93 | +/// Writes parameter `p` of `e`. A keyed effect takes the change on its key at source frame |
| 94 | -/// `at`, made there from what it shows when none is, so an edit at the playhead animates; any | 94 | +/// `at` for a keyable parameter, the key made there from what the effect shows when none is, |
| 95 | -/// other effect, or an unkeyed mask, takes it as its static value. | 95 | +/// so an edit at the playhead animates; a switch or a choice, an unkeyed effect, or no playhead |
| 96 | +/// takes it as its static value. | ||
| 96 | fn write_param(e: &mut Effect, p: usize, v: f32, at: Option<u32>) { | 97 | fn write_param(e: &mut Effect, p: usize, v: f32, at: Option<u32>) { |
| 97 | - let mask = matches!(e.kind, EffectKind::RectMask | EffectKind::EllipseMask) && p < 5; | 98 | + let keyable = e.kind.params().get(p).is_some_and(|s| s.keyable()); |
| 98 | match at { | 99 | match at { |
| 99 | - Some(at) if mask && !e.keys.is_empty() => { | 100 | + Some(at) if keyable && !e.keys.is_empty() => { |
| 100 | let mut key = match e.keys.iter().position(|k| k.at == at) { | 101 | let mut key = match e.keys.iter().position(|k| k.at == at) { |
| 101 | Some(i) => e.keys[i], | 102 | Some(i) => e.keys[i], |
| 102 | - None => mask_key_at(e, at), | 103 | + None => effect_key_at(e, at), |
| 103 | }; | 104 | }; |
| 104 | - match p { | 105 | + key.values[p] = v; |
| 105 | - 0 => key.x = v, | ||
| 106 | - 1 => key.y = v, | ||
| 107 | - 2 => key.width = v, | ||
| 108 | - 3 => key.height = v, | ||
| 109 | - _ => key.feather = v, | ||
| 110 | - } | ||
| 111 | match e.keys.binary_search_by_key(&at, |k| k.at) { | 106 | match e.keys.binary_search_by_key(&at, |k| k.at) { |
| 112 | Ok(i) => e.keys[i] = key, | 107 | Ok(i) => e.keys[i] = key, |
| 113 | Err(i) => e.keys.insert(i, key), | 108 | Err(i) => e.keys.insert(i, key), |
| @@ -192,27 +187,29 @@ impl Player { | |||
| 192 | }) | 187 | }) |
| 193 | } | 188 | } |
| 194 | 189 | ||
| 195 | - /// The keyframe diamond on a mask row: a key for the mask's shape at the playhead, or that | 190 | + /// The keyframe diamond on an effect's row: a key for the effect's parameters at the |
| 196 | - /// key taken off. Taking off the last key leaves the shape it had there as the static one. | 191 | + /// playhead, or that key taken off. Taking off the last key leaves the values it had there |
| 197 | - pub(crate) fn toggle_mask_key(&mut self, i: usize, cx: &mut Context<Self>) { | 192 | + /// as the static ones (the switches and choices keep theirs). |
| 193 | + pub(crate) fn toggle_effect_key(&mut self, i: usize, cx: &mut Context<Self>) { | ||
| 198 | let Some(at) = self.effects_src() else { | 194 | let Some(at) = self.effects_src() else { |
| 199 | self.notify_user("The playhead is not on this clip".into()); | 195 | self.notify_user("The playhead is not on this clip".into()); |
| 200 | cx.notify(); | 196 | cx.notify(); |
| 201 | return; | 197 | return; |
| 202 | }; | 198 | }; |
| 203 | let mut stack = self.effects_shown(); | 199 | let mut stack = self.effects_shown(); |
| 204 | - if let Some(e) = stack.get_mut(i) | 200 | + if let Some(e) = stack.get_mut(i) { |
| 205 | - && matches!(e.kind, EffectKind::RectMask | EffectKind::EllipseMask) | ||
| 206 | - { | ||
| 207 | match e.keys.binary_search_by_key(&at, |k| k.at) { | 201 | match e.keys.binary_search_by_key(&at, |k| k.at) { |
| 208 | Ok(pos) => { | 202 | Ok(pos) => { |
| 209 | let key = e.keys.remove(pos); | 203 | let key = e.keys.remove(pos); |
| 210 | if e.keys.is_empty() { | 204 | if e.keys.is_empty() { |
| 211 | - e.values[..5].copy_from_slice(&[key.x, key.y, key.width, key.height, key.feather]); | 205 | + let specs = e.kind.params(); |
| 206 | + for (j, _) in specs.iter().enumerate().filter(|(_, s)| s.keyable()) { | ||
| 207 | + e.values[j] = key.values[j]; | ||
| 208 | + } | ||
| 212 | } | 209 | } |
| 213 | } | 210 | } |
| 214 | Err(pos) => { | 211 | Err(pos) => { |
| 215 | - let key = mask_key_at(e, at); | 212 | + let key = effect_key_at(e, at); |
| 216 | e.keys.insert(pos, key); | 213 | e.keys.insert(pos, key); |
| 217 | } | 214 | } |
| 218 | } | 215 | } |
crates/app/src/ui/cards/effects.rsmodified+11 -6
| @@ -69,7 +69,7 @@ impl Player { | |||
| 69 | let (lane, idx) = self.effects_open?; | 69 | let (lane, idx) = self.effects_open?; |
| 70 | let session = self.session.as_ref()?; | 70 | let session = self.session.as_ref()?; |
| 71 | let on_picture = lane.kind == LaneKind::Video && session.lane_clips(lane).get(idx).is_some(); | 71 | let on_picture = lane.kind == LaneKind::Video && session.lane_clips(lane).get(idx).is_some(); |
| 72 | - // The rows show what each effect is at the playhead: a keyed mask's shape there. | 72 | + // The rows show what each effect is at the playhead: a keyed effect's values there. |
| 73 | let at = self.effects_src().unwrap_or(0); | 73 | let at = self.effects_src().unwrap_or(0); |
| 74 | let stack: Vec<Effect> = self.effects_shown().iter().map(|e| e.posed(f64::from(at)).into_owned()).collect(); | 74 | let stack: Vec<Effect> = self.effects_shown().iter().map(|e| e.posed(f64::from(at)).into_owned()).collect(); |
| 75 | let count = stack.len(); | 75 | let count = stack.len(); |
| @@ -396,10 +396,15 @@ impl Player { | |||
| 396 | .into_any_element() | 396 | .into_any_element() |
| 397 | } | 397 | } |
| 398 | }; | 398 | }; |
| 399 | - // A mask's position and size rows carry the keyframe diamond: a key for the shape at the | 399 | + // An effect's keyframe diamond sits on its first keyable row (a mask's position and size |
| 400 | - // playhead. It sits above the slider whether or not a key is there, so nothing moves. | 400 | + // rows) and keys the whole effect at the playhead. It sits above the slider whether or |
| 401 | - let mask_row = matches!(e.kind, EffectKind::RectMask | EffectKind::EllipseMask) && (p == 0 || p == 2); | 401 | + // not a key is there, so nothing moves. |
| 402 | - if mask_row { | 402 | + let mask = matches!(e.kind, EffectKind::RectMask | EffectKind::EllipseMask); |
| 403 | + let key_row = match mask { | ||
| 404 | + true => p == 0 || p == 2, | ||
| 405 | + false => spec.keyable() && e.kind.params()[..p].iter().all(|s| !s.keyable()), | ||
| 406 | + }; | ||
| 407 | + if key_row { | ||
| 403 | let here = self.effects_src(); | 408 | let here = self.effects_src(); |
| 404 | let filled = here.is_some_and(|at| e.keys.iter().any(|k| k.at == at)); | 409 | let filled = here.is_some_and(|at| e.keys.iter().any(|k| k.at == at)); |
| 405 | let t = crate::ui::theme::tokens(); | 410 | let t = crate::ui::theme::tokens(); |
| @@ -418,7 +423,7 @@ impl Player { | |||
| 418 | "", | 423 | "", |
| 419 | None, | 424 | None, |
| 420 | )) | 425 | )) |
| 421 | - .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| this.toggle_mask_key(i, cx))) | 426 | + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| this.toggle_effect_key(i, cx))) |
| 422 | .child(super::keys::diamond(12., if filled { t.accent } else { t.ink3 }, filled)); | 427 | .child(super::keys::diamond(12., if filled { t.accent } else { t.ink3 }, filled)); |
| 423 | controls.push( | 428 | controls.push( |
| 424 | div() | 429 | div() |
crates/engine/src/edith.rsmodified+113 -55
| @@ -226,6 +226,14 @@ | |||
| 226 | //! none) and `frames` how long each takes. A project with none is the bytes a v53 one was bar the | 226 | //! none) and `frames` how long each takes. A project with none is the bytes a v53 one was bar the |
| 227 | //! version line. | 227 | //! version line. |
| 228 | //! | 228 | //! |
| 229 | +//! **Version 56** animates any effect parameter: an `ekeys video <ord> <index> <slot> <at>:<ease>:<v0>,<v1>,...` | ||
| 230 | +//! line per effect with keys, the keys in source order, with one value for each of the effect's | ||
| 231 | +//! parameters ([`crate::effects::EffectKind::params`]) and the ease of the segment that leaves each | ||
| 232 | +//! key (a custom bezier is written as [`KeyEase::token`] gives it). A parameter that cannot be | ||
| 233 | +//! keyed (a switch or a choice) holds its static value. A v53 file's `mkeys` lines, which keyed | ||
| 234 | +//! 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. | ||
| 236 | +//! | ||
| 229 | //! A `cueadd` line is one cue added to a subtitle track, which no file has: | 237 | //! A `cueadd` line is one cue added to a subtitle track, which no file has: |
| 230 | //! `cueadd <track> <start_us> <end_us> <text>`, the track by its position in | 238 | //! `cueadd <track> <start_us> <end_us> <text>`, the track by its position in |
| 231 | //! the `subtitle` lines, the times in microseconds on the track's own clock, and | 239 | //! the `subtitle` lines, the times in microseconds on the track's own clock, and |
| @@ -807,13 +815,12 @@ pub fn encode_flagged( | |||
| 807 | || lanes.iter().any(|(_, clips)| clips.iter().any(|c| !c.mark.is_default())); | 815 | || lanes.iter().any(|(_, clips)| clips.iter().any(|c| !c.mark.is_default())); |
| 808 | // ...and one with a clip pan or a lane pan is v50. | 816 | // ...and one with a clip pan or a lane pan is v50. |
| 809 | let panned = lanes.iter().any(|(_, clips)| clips.iter().any(|c| c.pan != 0)) || flags.iter().any(|f| f.pan != 0.0); | 817 | let panned = lanes.iter().any(|(_, clips)| clips.iter().any(|c| c.pan != 0)) || flags.iter().any(|f| f.pan != 0.0); |
| 810 | - // ...and one with a mask's keys is v53. | 818 | + // ...and one with an effect's keys is v56 (`ekeys`), as is one with a custom bezier key easing. |
| 811 | - let masked = lanes.iter().any(|(_, clips)| clips.iter().any(|c| c.effects.iter().any(|e| !e.keys.is_empty()))); | 819 | + let keyed = lanes.iter().any(|(_, clips)| clips.iter().any(|c| c.effects.iter().any(|e| !e.keys.is_empty()))); |
| 812 | // ...and one with a clip's pitch shift is v55. | 820 | // ...and one with a clip's pitch shift is v55. |
| 813 | let pitched = lanes.iter().any(|(_, clips)| clips.iter().any(|c| c.pitch != 0)); | 821 | let pitched = lanes.iter().any(|(_, clips)| clips.iter().any(|c| c.pitch != 0)); |
| 814 | - // ...and one with a custom bezier key easing is v56. | 822 | + let curved = keyed || lanes.iter().any(|(_, clips)| clips.iter().any(has_bezier)); |
| 815 | - let curved = 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() { |
| 816 | - if curved || pitched || titled || masked || panned || styled || marked || angled || named || deinterlaced || steadied || looked || effected || voiced || captioned || animated || reversed || transitioned || ramped || !chapters.is_empty() || !markers.is_empty() { | ||
| 817 | let first_end = bytes.iter().position(|&b| b == b'\n').unwrap_or(bytes.len()); | 824 | let first_end = bytes.iter().position(|&b| b == b'\n').unwrap_or(bytes.len()); |
| 818 | let header = if curved { | 825 | let header = if curved { |
| 819 | MAGIC | 826 | MAGIC |
| @@ -821,8 +828,6 @@ pub fn encode_flagged( | |||
| 821 | MAGIC_V55 | 828 | MAGIC_V55 |
| 822 | } else if titled { | 829 | } else if titled { |
| 823 | MAGIC_V54 | 830 | MAGIC_V54 |
| 824 | - } else if masked { | ||
| 825 | - MAGIC_V53 | ||
| 826 | } else if panned { | 831 | } else if panned { |
| 827 | MAGIC_V50 | 832 | MAGIC_V50 |
| 828 | } else if styled { | 833 | } else if styled { |
| @@ -872,7 +877,7 @@ pub fn encode_flagged( | |||
| 872 | bytes.extend_from_slice(&opacity_key_lines(lanes)); | 877 | bytes.extend_from_slice(&opacity_key_lines(lanes)); |
| 873 | bytes.extend_from_slice(&color_key_lines(lanes)); | 878 | bytes.extend_from_slice(&color_key_lines(lanes)); |
| 874 | bytes.extend_from_slice(&effect_lines(lanes)); | 879 | bytes.extend_from_slice(&effect_lines(lanes)); |
| 875 | - bytes.extend_from_slice(&mask_key_lines(lanes)); | 880 | + bytes.extend_from_slice(&effect_key_lines(lanes)); |
| 876 | bytes.extend_from_slice(&look_lines(color, dir)); | 881 | bytes.extend_from_slice(&look_lines(color, dir)); |
| 877 | bytes.extend_from_slice(&stab_lines(lanes)); | 882 | bytes.extend_from_slice(&stab_lines(lanes)); |
| 878 | bytes.extend_from_slice(&deint_lines(lanes)); | 883 | bytes.extend_from_slice(&deint_lines(lanes)); |
| @@ -890,7 +895,7 @@ pub fn encode_flagged( | |||
| 890 | /// such a project is the bytes it was before v51. | 895 | /// such a project is the bytes it was before v51. |
| 891 | /// `current` (a file's first line, without its newline) with `candidate` in its place when | 896 | /// `current` (a file's first line, without its newline) with `candidate` in its place when |
| 892 | /// `candidate` is a newer dialect, else `current` untouched. The library and notes lines raise | 897 | /// `candidate` is a newer dialect, else `current` untouched. The library and notes lines raise |
| 893 | -/// the header to what they need and never lower it, so a file with mask keys (v53) keeps v53. | 898 | +/// the header to what they need and never lower it, so a file with effect keys (v56) keeps v56. |
| 894 | fn raise_header(current: &[u8], candidate: &[u8]) -> Vec<u8> { | 899 | fn raise_header(current: &[u8], candidate: &[u8]) -> Vec<u8> { |
| 895 | let version = |h: &[u8]| { | 900 | let version = |h: &[u8]| { |
| 896 | std::str::from_utf8(h).ok().and_then(|l| l.strip_prefix("edith ")).and_then(|n| n.parse::<u32>().ok()).unwrap_or(0) | 901 | std::str::from_utf8(h).ok().and_then(|l| l.strip_prefix("edith ")).and_then(|n| n.parse::<u32>().ok()).unwrap_or(0) |
| @@ -1652,10 +1657,10 @@ fn effect_lines(lanes: &[(LaneKind, Vec<Clip>)]) -> Vec<u8> { | |||
| 1652 | out.into_bytes() | 1657 | out.into_bytes() |
| 1653 | } | 1658 | } |
| 1654 | 1659 | ||
| 1655 | -/// The `mkeys` lines (v53): `mkeys video <ord> <index> <slot> <at>:<ease>:<x>,<y>,<w>,<h>,<feather> ...`, | 1660 | +/// The `ekeys` lines (v56): `ekeys video <ord> <index> <slot> <at>:<ease>:<v0>,<v1>,... ...`, |
| 1656 | -/// the keys of the rect or ellipse mask at stack position `slot`, in source order. Only a | 1661 | +/// the keys of the effect at stack position `slot`, in source order, with one value for each |
| 1657 | -/// mask with keys gets a line. | 1662 | +/// of its [`crate::effects::EffectKind::params`]. Only an effect with keys gets a line. |
| 1658 | -fn mask_key_lines(lanes: &[(LaneKind, Vec<Clip>)]) -> Vec<u8> { | 1663 | +fn effect_key_lines(lanes: &[(LaneKind, Vec<Clip>)]) -> Vec<u8> { |
| 1659 | let mut out = String::new(); | 1664 | let mut out = String::new(); |
| 1660 | let mut video = 0u32; | 1665 | let mut video = 0u32; |
| 1661 | for (kind, clips) in lanes { | 1666 | for (kind, clips) in lanes { |
| @@ -1668,9 +1673,11 @@ fn mask_key_lines(lanes: &[(LaneKind, Vec<Clip>)]) -> Vec<u8> { | |||
| 1668 | if e.keys.is_empty() { | 1673 | if e.keys.is_empty() { |
| 1669 | continue; | 1674 | continue; |
| 1670 | } | 1675 | } |
| 1671 | - out += &format!("mkeys video {video} {idx} {slot}"); | 1676 | + out += &format!("ekeys video {video} {idx} {slot}"); |
| 1677 | + let count = e.kind.params().len(); | ||
| 1672 | for k in &e.keys { | 1678 | for k in &e.keys { |
| 1673 | - out += &format!(" {}:{}:{},{},{},{},{}", k.at, k.ease.token(), k.x, k.y, k.width, k.height, k.feather); | 1679 | + let values: Vec<String> = k.values[..count].iter().map(|v| v.to_string()).collect(); |
| 1680 | + out += &format!(" {}:{}:{}", k.at, k.ease.token(), values.join(",")); | ||
| 1674 | } | 1681 | } |
| 1675 | out.push('\n'); | 1682 | out.push('\n'); |
| 1676 | } | 1683 | } |
| @@ -2955,8 +2962,9 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> { | |||
| 2955 | })?; | 2962 | })?; |
| 2956 | clip.stabilise = Some(crate::stabilise::Stabilise::new(strength, crop)); | 2963 | clip.stabilise = Some(crate::stabilise::Stabilise::new(strength, crop)); |
| 2957 | } | 2964 | } |
| 2965 | + // A v53 mask's keys: five values, the mask's invert stays at its static value. | ||
| 2958 | b"mkeys" if v53 => { | 2966 | b"mkeys" if v53 => { |
| 2959 | - use crate::effects::{EffectKind, MaskKey}; | 2967 | + use crate::effects::EffectKind; |
| 2960 | let f: Vec<&[u8]> = rest.split(|&b| b == b' ').filter(|f| !f.is_empty()).collect(); | 2968 | let f: Vec<&[u8]> = rest.split(|&b| b == b' ').filter(|f| !f.is_empty()).collect(); |
| 2961 | if f.len() < 5 || f[0] != b"video" { | 2969 | if f.len() < 5 || f[0] != b"video" { |
| 2962 | return Err(format!("line {n}: mkeys wants a video clip, a slot and a key").into()); | 2970 | return Err(format!("line {n}: mkeys wants a video clip, a slot and a key").into()); |
| @@ -2972,38 +2980,6 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> { | |||
| 2972 | .ok_or_else(|| format!("line {n}: mkeys names a lane that is not there"))?; | 2980 | .ok_or_else(|| format!("line {n}: mkeys names a lane that is not there"))?; |
| 2973 | let idx = number(f[2], n)? as usize; | 2981 | let idx = number(f[2], n)? as usize; |
| 2974 | let slot = number(f[3], n)? as usize; | 2982 | let slot = number(f[3], n)? as usize; |
| 2975 | - let points = &f[4..]; | ||
| 2976 | - if points.len() > MAX_TRANSFORM_KEYS { | ||
| 2977 | - return Err(format!("line {n}: mkeys has more than {MAX_TRANSFORM_KEYS} keys").into()); | ||
| 2978 | - } | ||
| 2979 | - let r = EffectKind::RectMask.params(); | ||
| 2980 | - let mut keys: Vec<MaskKey> = Vec::new(); | ||
| 2981 | - for point in points { | ||
| 2982 | - let parts: Vec<&[u8]> = point.splitn(3, |&b| b == b':').collect(); | ||
| 2983 | - if parts.len() != 3 { | ||
| 2984 | - return Err(format!("line {n}: mkeys key wants at:ease:values").into()); | ||
| 2985 | - } | ||
| 2986 | - let at_frame = number(parts[0], n)?; | ||
| 2987 | - let ease = KeyEase::from_token(parts[1]) | ||
| 2988 | - .filter(|e| v56 || !matches!(e, KeyEase::Bezier(_))) | ||
| 2989 | - .ok_or_else(|| format!("line {n}: mkeys ease is lin, in, out, ease or hold"))?; | ||
| 2990 | - if keys.last().is_some_and(|k| k.at >= at_frame) { | ||
| 2991 | - return Err(format!("line {n}: mkeys keys are not in source order").into()); | ||
| 2992 | - } | ||
| 2993 | - let v: Vec<&[u8]> = parts[2].split(|&b| b == b',').collect(); | ||
| 2994 | - if v.len() != 5 { | ||
| 2995 | - return Err(format!("line {n}: mkeys key wants 5 values").into()); | ||
| 2996 | - } | ||
| 2997 | - let mut val = [0.0f32; 5]; | ||
| 2998 | - for (i, (x, field)) in val.iter_mut().zip(&v).enumerate() { | ||
| 2999 | - *x = float(field, n)?; | ||
| 3000 | - if !(r[i].min..=r[i].max).contains(x) { | ||
| 3001 | - return Err(format!("line {n}: mkeys {} is out of its range", r[i].name).into()); | ||
| 3002 | - } | ||
| 3003 | - } | ||
| 3004 | - let [x, y, width, height, feather] = val; | ||
| 3005 | - keys.push(MaskKey { at: at_frame, x, y, width, height, feather, ease }); | ||
| 3006 | - } | ||
| 3007 | let clip = doc.lanes[at] | 2983 | let clip = doc.lanes[at] |
| 3008 | .1 | 2984 | .1 |
| 3009 | .get_mut(idx) | 2985 | .get_mut(idx) |
| @@ -3013,6 +2989,45 @@ fn parse(data: &[u8], dir: &Path) -> crate::Result<Document> { | |||
| 3013 | .get_mut(slot) | 2989 | .get_mut(slot) |
| 3014 | .filter(|e| matches!(e.kind, EffectKind::RectMask | EffectKind::EllipseMask)) | 2990 | .filter(|e| matches!(e.kind, EffectKind::RectMask | EffectKind::EllipseMask)) |
| 3015 | .ok_or_else(|| format!("line {n}: mkeys names an effect that is not a mask"))?; | 2991 | .ok_or_else(|| format!("line {n}: mkeys names an effect that is not a mask"))?; |
| 2992 | + let invert = effect.values[5]; | ||
| 2993 | + let mut keys = read_effect_keys("mkeys", &f[4..], &EffectKind::RectMask.params()[..5], n, v56)?; | ||
| 2994 | + for k in &mut keys { | ||
| 2995 | + k.values[5] = invert; | ||
| 2996 | + } | ||
| 2997 | + effect.keys = keys; | ||
| 2998 | + } | ||
| 2999 | + b"ekeys" if v56 => { | ||
| 3000 | + let f: Vec<&[u8]> = rest.split(|&b| b == b' ').filter(|f| !f.is_empty()).collect(); | ||
| 3001 | + if f.len() < 4 || f[0] != b"video" { | ||
| 3002 | + return Err(format!("line {n}: ekeys wants a video clip, a slot and a key").into()); | ||
| 3003 | + } | ||
| 3004 | + let ord = number(f[1], n)?; | ||
| 3005 | + let at = doc | ||
| 3006 | + .lanes | ||
| 3007 | + .iter() | ||
| 3008 | + .enumerate() | ||
| 3009 | + .filter(|(_, (k, _))| *k == LaneKind::Video) | ||
| 3010 | + .nth(ord.saturating_sub(1) as usize) | ||
| 3011 | + .map(|(at, _)| at) | ||
| 3012 | + .ok_or_else(|| format!("line {n}: ekeys names a lane that is not there"))?; | ||
| 3013 | + let idx = number(f[2], n)? as usize; | ||
| 3014 | + let slot = number(f[3], n)? as usize; | ||
| 3015 | + let clip = doc.lanes[at] | ||
| 3016 | + .1 | ||
| 3017 | + .get_mut(idx) | ||
| 3018 | + .ok_or_else(|| format!("line {n}: ekeys names clip {idx}, which the lane does not have"))?; | ||
| 3019 | + let effect = clip | ||
| 3020 | + .effects | ||
| 3021 | + .get_mut(slot) | ||
| 3022 | + .ok_or_else(|| format!("line {n}: ekeys names an effect the clip does not have"))?; | ||
| 3023 | + let specs = effect.kind.params(); | ||
| 3024 | + let mut keys = read_effect_keys("ekeys", &f[4..], specs, n, v56)?; | ||
| 3025 | + // A parameter that cannot be keyed (a switch or a choice) keeps its static value. | ||
| 3026 | + for k in &mut keys { | ||
| 3027 | + for (i, _) in specs.iter().enumerate().filter(|(_, s)| !s.keyable()) { | ||
| 3028 | + k.values[i] = effect.values[i]; | ||
| 3029 | + } | ||
| 3030 | + } | ||
| 3016 | effect.keys = keys; | 3031 | effect.keys = keys; |
| 3017 | } | 3032 | } |
| 3018 | b"okeys" | b"ckeys" if v39 => { | 3033 | b"okeys" | b"ckeys" if v39 => { |
| @@ -4586,6 +4601,49 @@ fn band(field: &[u8], line: usize) -> crate::Result<Band> { | |||
| 4586 | }) | 4601 | }) |
| 4587 | } | 4602 | } |
| 4588 | 4603 | ||
| 4604 | +/// The `at:ease:values` points of an `mkeys` or `ekeys` line (`name`), in source order. | ||
| 4605 | +/// Each point holds one value per spec in `specs`, each within that spec's range, and the | ||
| 4606 | +/// rest of the key is zero. A custom bezier ease is read only from v56 on, and at most | ||
| 4607 | +/// [`MAX_TRANSFORM_KEYS`] points are read. | ||
| 4608 | +fn read_effect_keys( | ||
| 4609 | + name: &str, | ||
| 4610 | + points: &[&[u8]], | ||
| 4611 | + specs: &[crate::effects::ParamSpec], | ||
| 4612 | + n: usize, | ||
| 4613 | + v56: bool, | ||
| 4614 | +) -> crate::Result<Vec<crate::effects::EffectKey>> { | ||
| 4615 | + if points.len() > MAX_TRANSFORM_KEYS { | ||
| 4616 | + return Err(format!("line {n}: {name} has more than {MAX_TRANSFORM_KEYS} keys").into()); | ||
| 4617 | + } | ||
| 4618 | + let mut keys: Vec<crate::effects::EffectKey> = Vec::new(); | ||
| 4619 | + for point in points { | ||
| 4620 | + let parts: Vec<&[u8]> = point.splitn(3, |&b| b == b':').collect(); | ||
| 4621 | + if parts.len() != 3 { | ||
| 4622 | + return Err(format!("line {n}: {name} key wants at:ease:values").into()); | ||
| 4623 | + } | ||
| 4624 | + let at = number(parts[0], n)?; | ||
| 4625 | + let ease = KeyEase::from_token(parts[1]) | ||
| 4626 | + .filter(|e| v56 || !matches!(e, KeyEase::Bezier(_))) | ||
| 4627 | + .ok_or_else(|| format!("line {n}: {name} ease is lin, in, out, ease, hold or a bezier curve"))?; | ||
| 4628 | + if keys.last().is_some_and(|k| k.at >= at) { | ||
| 4629 | + return Err(format!("line {n}: {name} keys are not in source order").into()); | ||
| 4630 | + } | ||
| 4631 | + let v: Vec<&[u8]> = parts[2].split(|&b| b == b',').collect(); | ||
| 4632 | + if v.len() != specs.len() { | ||
| 4633 | + return Err(format!("line {n}: {name} key wants {} values", specs.len()).into()); | ||
| 4634 | + } | ||
| 4635 | + let mut values = [0.0f32; crate::effects::MAX_PARAMS]; | ||
| 4636 | + for (i, (x, field)) in values.iter_mut().zip(&v).enumerate() { | ||
| 4637 | + *x = float(field, n)?; | ||
| 4638 | + if !(specs[i].min..=specs[i].max).contains(x) { | ||
| 4639 | + return Err(format!("line {n}: {name} {} is out of its range", specs[i].name).into()); | ||
| 4640 | + } | ||
| 4641 | + } | ||
| 4642 | + keys.push(crate::effects::EffectKey { at, values, ease }); | ||
| 4643 | + } | ||
| 4644 | + Ok(keys) | ||
| 4645 | +} | ||
| 4646 | + | ||
| 4589 | /// A band's number: whatever `{:?}` wrote, read back to the same bits. Infinity | 4647 | /// A band's number: whatever `{:?}` wrote, read back to the same bits. Infinity |
| 4590 | /// and NaN are refused rather than carried -- they are the values a coefficient | 4648 | /// and NaN are refused rather than carried -- they are the values a coefficient |
| 4591 | /// cannot be built from, and the ones that would not compare equal to | 4649 | /// cannot be built from, and the ones that would not compare equal to |
| @@ -7069,7 +7127,7 @@ mod tests { | |||
| 7069 | /// The v51 library lines: bins, filed sources and starred ones round-trip; a project with | 7127 | /// The v51 library lines: bins, filed sources and starred ones round-trip; a project with |
| 7070 | /// none keeps its v50 bytes; the lines are refused in v50 and bad ones by name. | 7128 | /// none keeps its v50 bytes; the lines are refused in v50 and bad ones by name. |
| 7071 | #[test] | 7129 | #[test] |
| 7072 | - fn library_lines_round_trip_with_mask_keys_in_v53() { | 7130 | + fn library_lines_round_trip_with_effect_keys_in_v56() { |
| 7073 | use crate::project::Bin; | 7131 | use crate::project::Bin; |
| 7074 | let dir = std::env::temp_dir().join(format!("edith-bins-{}", std::process::id())); | 7132 | let dir = std::env::temp_dir().join(format!("edith-bins-{}", std::process::id())); |
| 7075 | std::fs::create_dir_all(&dir).unwrap(); | 7133 | std::fs::create_dir_all(&dir).unwrap(); |
| @@ -7080,8 +7138,8 @@ mod tests { | |||
| 7080 | ]; | 7138 | ]; |
| 7081 | let mut lanes = two(vec![clip(0, 0, 30, 0, Some(0))], vec![clip(0, 0, 30, 0, Some(0))]); | 7139 | let mut lanes = two(vec![clip(0, 0, 30, 0, Some(0))], vec![clip(0, 0, 30, 0, Some(0))]); |
| 7082 | let mut mask = crate::effects::Effect::new(crate::effects::EffectKind::EllipseMask); | 7140 | let mut mask = crate::effects::Effect::new(crate::effects::EffectKind::EllipseMask); |
| 7083 | - mask.keys = vec![crate::effects::MaskKey { | 7141 | + mask.keys = vec![crate::effects::EffectKey { |
| 7084 | - at: 0, x: 0.5, y: 0.5, width: 0.4, height: 0.4, feather: 0.02, ease: KeyEase::Linear, | 7142 | + at: 0, values: [0.5, 0.5, 0.4, 0.4, 0.02, 0.0], ease: KeyEase::Linear, |
| 7085 | }]; | 7143 | }]; |
| 7086 | lanes[0].1[0].effects = vec![mask]; | 7144 | lanes[0].1[0].effects = vec![mask]; |
| 7087 | let save = |src: &[Source], bins: &[Bin]| { | 7145 | let save = |src: &[Source], bins: &[Bin]| { |
| @@ -7105,11 +7163,11 @@ mod tests { | |||
| 7105 | src[1].fav = true; | 7163 | src[1].fav = true; |
| 7106 | src[1].bin = 1; | 7164 | src[1].bin = 1; |
| 7107 | let text = save(&src, &bins); | 7165 | let text = save(&src, &bins); |
| 7108 | - // A mask key is v53, and the library and the notes lines keep it there. | 7166 | + // An effect key is v56, and the library and the notes lines keep it there. |
| 7109 | - assert!(text.starts_with("edith 53\n"), "{text}"); | 7167 | + assert!(text.starts_with("edith 56\n"), "{text}"); |
| 7110 | assert!(text.contains("\nsrcbin 0 3\n") && text.contains("\nsrcfav 1\n"), "{text}"); | 7168 | assert!(text.contains("\nsrcbin 0 3\n") && text.contains("\nsrcfav 1\n"), "{text}"); |
| 7111 | - assert!(text.contains("\nmkeys video ") && text.contains("\nnotes Two cuts\n"), "{text}"); | 7169 | + assert!(text.contains("\nekeys video 1 0 0 0:lin:0.5,0.5,0.4,0.4,0.02,0\n") && text.contains("\nnotes Two cuts\n"), "{text}"); |
| 7112 | - let back = load(&path).expect("v53 loads"); | 7170 | + let back = load(&path).expect("v56 loads"); |
| 7113 | assert_eq!(back.notes, "Two cuts"); | 7171 | assert_eq!(back.notes, "Two cuts"); |
| 7114 | assert_eq!(back.bins, bins); | 7172 | assert_eq!(back.bins, bins); |
| 7115 | assert_eq!((back.sources[0].bin, back.sources[0].fav), (3, false)); | 7173 | assert_eq!((back.sources[0].bin, back.sources[0].fav), (3, false)); |
crates/engine/src/effects.rsmodified+46 -41
| @@ -17,9 +17,9 @@ | |||
| 17 | //! reach) are pixels *of a 1080-line frame* and scale with the frame's height, so | 17 | //! reach) are pixels *of a 1080-line frame* and scale with the frame's height, so |
| 18 | //! a preview at a smaller size shows the effect at the size the export will. | 18 | //! a preview at a smaller size shows the effect at the size the export will. |
| 19 | //! | 19 | //! |
| 20 | -//! The parameters are static (one value for the whole clip), except the two masks' | 20 | +//! The parameters are static (one value for the whole clip) unless the effect has |
| 21 | -//! position, size and soft edge, which take keys ([`MaskKey`]) at source frames and | 21 | +//! keys ([`EffectKey`]) at source frames: then every keyable parameter (not a switch |
| 22 | -//! are read at the frame shown ([`Effect::posed`]). A pixelate is a filter; a mask | 22 | +//! or a choice such as a blend mode) is read at the frame shown ([`Effect::posed`]). A pixelate is a filter; a mask |
| 23 | //! placed right after it limits it to that mask's shape, and that mask then does | 23 | //! placed right after it limits it to that mask's shape, and that mask then does |
| 24 | //! not cut the clip's coverage. An empty list, and a list whose every effect is | 24 | //! not cut the clip's coverage. An empty list, and a list whose every effect is |
| 25 | //! switched off, is no effect at all -- not a sample is touched and no path changes | 25 | //! switched off, is no effect at all -- not a sample is touched and no path changes |
| @@ -166,6 +166,15 @@ pub struct ParamSpec { | |||
| 166 | pub step: f32, | 166 | pub step: f32, |
| 167 | } | 167 | } |
| 168 | 168 | ||
| 169 | +impl ParamSpec { | ||
| 170 | + /// Whether the parameter can take keys. A switch or a choice (a whole-number step | ||
| 171 | + /// over a short range, such as a blend mode or an invert) cannot be eased between | ||
| 172 | + /// two values, so it stays at its static value; every other parameter can. | ||
| 173 | + pub fn keyable(&self) -> bool { | ||
| 174 | + !(self.step >= 1.0 && self.max - self.min <= 10.0) | ||
| 175 | + } | ||
| 176 | +} | ||
| 177 | + | ||
| 169 | /// How a clip is laid over the lanes beneath it. Defined on RGB, as every | 178 | /// How a clip is laid over the lanes beneath it. Defined on RGB, as every |
| 170 | /// editor defines them, and worked per pixel through the output's matrix. | 179 | /// editor defines them, and worked per pixel through the output's matrix. |
| 171 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] | 180 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] |
| @@ -228,24 +237,21 @@ impl BlendMode { | |||
| 228 | } | 237 | } |
| 229 | } | 238 | } |
| 230 | 239 | ||
| 231 | -/// One point of a mask's animation ([`Effect::keys`]): the shape's centre, size and | 240 | +/// One point of an effect's animation ([`Effect::keys`]): every parameter of the |
| 232 | -/// soft edge at source frame `at`, with the ease of the segment that leaves it. The | 241 | +/// effect at source frame `at`, with the ease of the segment that leaves it. The |
| 233 | -/// fields are the mask's [`EffectKind::params`] in order, so [`Effect::posed`] reads | 242 | +/// values are in [`EffectKind::params`] order and the unused tail is zero, so |
| 234 | -/// them like the static values. | 243 | +/// [`Effect::posed`] reads them like the static values. A parameter that is not |
| 244 | +/// [`ParamSpec::keyable`] holds the effect's static value in every key. | ||
| 235 | #[derive(Clone, Copy, Debug, PartialEq)] | 245 | #[derive(Clone, Copy, Debug, PartialEq)] |
| 236 | -pub struct MaskKey { | 246 | +pub struct EffectKey { |
| 237 | /// Source frame of the key. | 247 | /// Source frame of the key. |
| 238 | pub at: u32, | 248 | pub at: u32, |
| 239 | - pub x: f32, | 249 | + pub values: [f32; MAX_PARAMS], |
| 240 | - pub y: f32, | ||
| 241 | - pub width: f32, | ||
| 242 | - pub height: f32, | ||
| 243 | - pub feather: f32, | ||
| 244 | /// The easing of the segment that leaves this key. | 250 | /// The easing of the segment that leaves this key. |
| 245 | pub ease: KeyEase, | 251 | pub ease: KeyEase, |
| 246 | } | 252 | } |
| 247 | 253 | ||
| 248 | -impl Keyed for MaskKey { | 254 | +impl Keyed for EffectKey { |
| 249 | fn at(&self) -> u32 { | 255 | fn at(&self) -> u32 { |
| 250 | self.at | 256 | self.at |
| 251 | } | 257 | } |
| @@ -256,29 +262,21 @@ impl Keyed for MaskKey { | |||
| 256 | Self { at, ease, ..self } | 262 | Self { at, ease, ..self } |
| 257 | } | 263 | } |
| 258 | fn mix(a: &Self, b: &Self, t: f32) -> Self { | 264 | fn mix(a: &Self, b: &Self, t: f32) -> Self { |
| 259 | - let l = |x: f32, y: f32| x + (y - x) * t; | 265 | + Self { values: std::array::from_fn(|i| a.values[i] + (b.values[i] - a.values[i]) * t), ..*a } |
| 260 | - Self { | ||
| 261 | - x: l(a.x, b.x), | ||
| 262 | - y: l(a.y, b.y), | ||
| 263 | - width: l(a.width, b.width), | ||
| 264 | - height: l(a.height, b.height), | ||
| 265 | - feather: l(a.feather, b.feather), | ||
| 266 | - ..*a | ||
| 267 | - } | ||
| 268 | } | 266 | } |
| 269 | } | 267 | } |
| 270 | 268 | ||
| 271 | /// One effect of a stack: what it is, whether it is switched on, and its | 269 | /// One effect of a stack: what it is, whether it is switched on, and its |
| 272 | -/// parameters in [`EffectKind::params`] order (the unused tail is zero). A mask | 270 | +/// parameters in [`EffectKind::params`] order (the unused tail is zero). Any |
| 273 | -/// may carry [`MaskKey`]s, which replace its position, size and soft edge. | 271 | +/// keyable parameter may be animated by [`EffectKey`]s in `keys`. |
| 274 | #[derive(Clone, Debug, PartialEq)] | 272 | #[derive(Clone, Debug, PartialEq)] |
| 275 | pub struct Effect { | 273 | pub struct Effect { |
| 276 | pub kind: EffectKind, | 274 | pub kind: EffectKind, |
| 277 | pub on: bool, | 275 | pub on: bool, |
| 278 | pub values: [f32; MAX_PARAMS], | 276 | pub values: [f32; MAX_PARAMS], |
| 279 | - /// The mask's animation, sorted by [`MaskKey::at`] with no two alike. Empty is | 277 | + /// The effect's animation, sorted by [`EffectKey::at`] with no two alike. Empty is |
| 280 | - /// the static values. Only a rect or ellipse mask has keys. | 278 | + /// the static values. |
| 281 | - pub keys: Vec<MaskKey>, | 279 | + pub keys: Vec<EffectKey>, |
| 282 | } | 280 | } |
| 283 | 281 | ||
| 284 | impl Effect { | 282 | impl Effect { |
| @@ -291,15 +289,20 @@ impl Effect { | |||
| 291 | Effect { kind, on: true, values, keys: Vec::new() } | 289 | Effect { kind, on: true, values, keys: Vec::new() } |
| 292 | } | 290 | } |
| 293 | 291 | ||
| 294 | - /// The effect as it draws at source frame `src`: a keyed mask with its | 292 | + /// The effect as it draws at source frame `src`: each keyable parameter |
| 295 | - /// position, size and soft edge interpolated from its keys; anything else as it | 293 | + /// interpolated from its keys (rounded when its step is a whole number), the |
| 296 | - /// is, borrowed. | 294 | + /// others as they are. An effect with no keys is borrowed as it is. |
| 297 | pub fn posed(&self, src: f64) -> Cow<'_, Effect> { | 295 | pub fn posed(&self, src: f64) -> Cow<'_, Effect> { |
| 298 | match sample(&self.keys, src) { | 296 | match sample(&self.keys, src) { |
| 299 | None => Cow::Borrowed(self), | 297 | None => Cow::Borrowed(self), |
| 300 | Some(k) => { | 298 | Some(k) => { |
| 301 | let mut e = self.clone(); | 299 | let mut e = self.clone(); |
| 302 | - e.values[..5].copy_from_slice(&[k.x, k.y, k.width, k.height, k.feather]); | 300 | + for (i, spec) in self.kind.params().iter().enumerate().filter(|(_, s)| s.keyable()) { |
| 301 | + e.values[i] = match spec.step >= 1.0 { | ||
| 302 | + true => k.values[i].round(), | ||
| 303 | + false => k.values[i], | ||
| 304 | + }; | ||
| 305 | + } | ||
| 303 | Cow::Owned(e) | 306 | Cow::Owned(e) |
| 304 | } | 307 | } |
| 305 | } | 308 | } |
| @@ -1143,15 +1146,17 @@ mod tests { | |||
| 1143 | } | 1146 | } |
| 1144 | 1147 | ||
| 1145 | #[test] | 1148 | #[test] |
| 1146 | - fn a_mask_key_track_is_interpolated_at_the_frame_shown() { | 1149 | + fn a_keyed_blur_is_interpolated_and_a_blend_mode_is_not() { |
| 1147 | - use crate::transform::KeyEase; | 1150 | + let key = |at, radius: f32, mode: f32| EffectKey { at, values: [radius, mode, 0.0, 0.0, 0.0, 0.0], ease: KeyEase::Linear }; |
| 1148 | - let key = |at, x| MaskKey { at, x, y: 0.5, width: 0.2, height: 0.2, feather: 0.0, ease: KeyEase::Linear }; | 1151 | + let mut blur = Effect::new(EffectKind::Blur); |
| 1149 | - let mut fx = Effect::new(EffectKind::RectMask); | 1152 | + blur.keys = vec![key(0, 2.0, 0.0), key(100, 10.0, 0.0)]; |
| 1150 | - fx.keys = vec![key(0, 0.2), key(100, 0.8)]; | 1153 | + assert!((blur.posed(50.0).get("radius").unwrap() - 6.0).abs() < 1e-6, "halfway between the keys"); |
| 1151 | - assert!((fx.posed(50.0).get("x").unwrap() - 0.5).abs() < 1e-6, "halfway between the keys"); | 1154 | + assert_eq!(blur.posed(-5.0).get("radius"), Some(2.0), "held before the first key"); |
| 1152 | - assert_eq!(fx.posed(-5.0).get("x"), Some(0.2), "held before the first key"); | 1155 | + assert!(animated(std::slice::from_ref(&blur)), "a keyed effect redraws as the frames change"); |
| 1153 | - assert_eq!(fx.posed(300.0).get("x"), Some(0.8), "held after the last key"); | 1156 | + let mut blend = Effect::new(EffectKind::Blend); |
| 1154 | - assert!(animated(std::slice::from_ref(&fx)), "a keyed mask redraws as the frames change"); | 1157 | + blend.set("mode", 1.0).unwrap(); |
| 1158 | + blend.keys = vec![key(0, 0.0, 0.0), key(100, 0.0, 6.0)]; | ||
| 1159 | + assert_eq!(blend.posed(50.0).get("mode"), Some(1.0), "a switch keeps its static value"); | ||
| 1155 | } | 1160 | } |
| 1156 | 1161 | ||
| 1157 | #[test] | 1162 | #[test] |
crates/engine/src/playback.rsmodified+15 -13
| @@ -5002,15 +5002,15 @@ impl PlaybackSession { | |||
| 5002 | self.project.effects_of(lane, idx) | 5002 | self.project.effects_of(lane, idx) |
| 5003 | } | 5003 | } |
| 5004 | 5004 | ||
| 5005 | - /// The keys of the mask at stack position `slot` ([`Project::mask_keys_of`]). | 5005 | + /// The keys of the effect at stack position `slot` ([`Project::effect_keys_of`]). |
| 5006 | - pub fn mask_keys_of(&self, lane: Lane, idx: usize, slot: usize) -> &[crate::effects::MaskKey] { | 5006 | + pub fn effect_keys_of(&self, lane: Lane, idx: usize, slot: usize) -> &[crate::effects::EffectKey] { |
| 5007 | - self.project.mask_keys_of(lane, idx, slot) | 5007 | + self.project.effect_keys_of(lane, idx, slot) |
| 5008 | } | 5008 | } |
| 5009 | 5009 | ||
| 5010 | - /// Replaces the keys of the mask at stack position `slot`, or clears them with an | 5010 | + /// Replaces the keys of the effect at stack position `slot`, or clears them with an |
| 5011 | - /// empty list ([`Project::set_mask_keys`]). One undo step and one reseek. | 5011 | + /// empty list ([`Project::set_effect_keys`]). One undo step and one reseek. |
| 5012 | - pub fn set_mask_keys(&mut self, lane: Lane, idx: usize, slot: usize, keys: Vec<crate::effects::MaskKey>) -> bool { | 5012 | + pub fn set_effect_keys(&mut self, lane: Lane, idx: usize, slot: usize, keys: Vec<crate::effects::EffectKey>) -> bool { |
| 5013 | - self.edit(Dirty::Picture, |p| p.set_mask_keys(lane, idx, slot, keys)) | 5013 | + self.edit(Dirty::Picture, |p| p.set_effect_keys(lane, idx, slot, keys)) |
| 5014 | } | 5014 | } |
| 5015 | 5015 | ||
| 5016 | /// Replaces the clip's effects stack ([`Project::set_effects`]). One undo | 5016 | /// Replaces the clip's effects stack ([`Project::set_effects`]). One undo |
| @@ -5553,7 +5553,7 @@ impl PlaybackSession { | |||
| 5553 | /// values they have at each frame. Keys inside the tracked frames are replaced and | 5553 | /// values they have at each frame. Keys inside the tracked frames are replaced and |
| 5554 | /// keys outside them stay. Returns how many keys were written. One undo step. | 5554 | /// keys outside them stay. Returns how many keys were written. One undo step. |
| 5555 | pub fn track_mask_apply(&mut self, job: &TrackJob, track: &crate::track::Track) -> Result<usize, String> { | 5555 | pub fn track_mask_apply(&mut self, job: &TrackJob, track: &crate::track::Track) -> Result<usize, String> { |
| 5556 | - use crate::effects::MaskKey; | 5556 | + use crate::effects::EffectKey; |
| 5557 | use crate::track::{KEY_TOLERANCE, simplify}; | 5557 | use crate::track::{KEY_TOLERANCE, simplify}; |
| 5558 | use crate::transform::{KeyEase, MAX_TRANSFORM_KEYS}; | 5558 | use crate::transform::{KeyEase, MAX_TRANSFORM_KEYS}; |
| 5559 | let Some(&(_, x0, y0)) = track.points.first() else { | 5559 | let Some(&(_, x0, y0)) = track.points.first() else { |
| @@ -5566,8 +5566,8 @@ impl PlaybackSession { | |||
| 5566 | .collect(); | 5566 | .collect(); |
| 5567 | pts.sort_by_key(|p| p.0); | 5567 | pts.sort_by_key(|p| p.0); |
| 5568 | let (first, last) = (pts[0].0, pts[pts.len() - 1].0); | 5568 | let (first, last) = (pts[0].0, pts[pts.len() - 1].0); |
| 5569 | - let outside: Vec<MaskKey> = | 5569 | + let outside: Vec<EffectKey> = |
| 5570 | - self.mask_keys_of(job.lane, job.idx, job.slot).iter().filter(|k| k.at < first || k.at > last).copied().collect(); | 5570 | + self.effect_keys_of(job.lane, job.idx, job.slot).iter().filter(|k| k.at < first || k.at > last).copied().collect(); |
| 5571 | let room = MAX_TRANSFORM_KEYS.saturating_sub(outside.len()).max(2); | 5571 | let room = MAX_TRANSFORM_KEYS.saturating_sub(outside.len()).max(2); |
| 5572 | let mut tolerance = KEY_TOLERANCE; | 5572 | let mut tolerance = KEY_TOLERANCE; |
| 5573 | let mut kept = simplify(&pts, tolerance); | 5573 | let mut kept = simplify(&pts, tolerance); |
| @@ -5585,15 +5585,17 @@ impl PlaybackSession { | |||
| 5585 | kept.iter() | 5585 | kept.iter() |
| 5586 | .map(|&i| { | 5586 | .map(|&i| { |
| 5587 | let (f, x, y) = pts[i]; | 5587 | let (f, x, y) = pts[i]; |
| 5588 | - let v = e.posed(f64::from(f)); | 5588 | + let mut values = e.posed(f64::from(f)).values; |
| 5589 | - MaskKey { at: f, x, y, width: v.values[2], height: v.values[3], feather: v.values[4], ease: KeyEase::Linear } | 5589 | + values[0] = x; |
| 5590 | + values[1] = y; | ||
| 5591 | + EffectKey { at: f, values, ease: KeyEase::Linear } | ||
| 5590 | }) | 5592 | }) |
| 5591 | .collect::<Vec<_>>() | 5593 | .collect::<Vec<_>>() |
| 5592 | }; | 5594 | }; |
| 5593 | keys.extend(outside); | 5595 | keys.extend(outside); |
| 5594 | keys.sort_by_key(|k| k.at); | 5596 | keys.sort_by_key(|k| k.at); |
| 5595 | let count = keys.len(); | 5597 | let count = keys.len(); |
| 5596 | - if !self.set_mask_keys(job.lane, job.idx, job.slot, keys) { | 5598 | + if !self.set_effect_keys(job.lane, job.idx, job.slot, keys) { |
| 5597 | return Err("the engine refused the keys (is the mask still there?)".into()); | 5599 | return Err("the engine refused the keys (is the mask still there?)".into()); |
| 5598 | } | 5600 | } |
| 5599 | Ok(count) | 5601 | Ok(count) |
crates/engine/src/project.rsmodified+28 -22
| @@ -1161,8 +1161,8 @@ fn rekey_trimmed(c: &mut Clip, old: &Clip, edge: Edge, still: bool) { | |||
| 1161 | if !old.color_keys.is_empty() { | 1161 | if !old.color_keys.is_empty() { |
| 1162 | c.color_keys = rekey(&old.color_keys, old, c, edge, still); | 1162 | c.color_keys = rekey(&old.color_keys, old, c, edge, still); |
| 1163 | } | 1163 | } |
| 1164 | - // A mask's keys follow its stack position: the same effect, rekeyed the same way. | 1164 | + // An effect's keys follow its stack position: the same effect, rekeyed the same way. |
| 1165 | - let masks: Vec<Option<Vec<crate::effects::MaskKey>>> = old | 1165 | + let masks: Vec<Option<Vec<crate::effects::EffectKey>>> = old |
| 1166 | .effects | 1166 | .effects |
| 1167 | .iter() | 1167 | .iter() |
| 1168 | .map(|e| (!e.keys.is_empty()).then(|| rekey(&e.keys, old, c, edge, still))) | 1168 | .map(|e| (!e.keys.is_empty()).then(|| rekey(&e.keys, old, c, edge, still))) |
| @@ -6048,38 +6048,44 @@ impl Project { | |||
| 6048 | true | 6048 | true |
| 6049 | } | 6049 | } |
| 6050 | 6050 | ||
| 6051 | - /// The keys of the mask at stack position `slot` of the clip at `idx` of `lane` | 6051 | + /// The keys of the effect at stack position `slot` of the clip at `idx` of `lane` |
| 6052 | - /// ([`crate::effects::Effect::keys`]); empty for anything else. | 6052 | + /// ([`crate::effects::Effect::keys`]); empty for an effect with none. |
| 6053 | - pub fn mask_keys_of(&self, lane: Lane, idx: usize, slot: usize) -> &[crate::effects::MaskKey] { | 6053 | + pub fn effect_keys_of(&self, lane: Lane, idx: usize, slot: usize) -> &[crate::effects::EffectKey] { |
| 6054 | self.lane(lane).get(idx).and_then(|c| c.effects.get(slot)).map_or(&[], |e| &e.keys) | 6054 | self.lane(lane).get(idx).and_then(|c| c.effects.get(slot)).map_or(&[], |e| &e.keys) |
| 6055 | } | 6055 | } |
| 6056 | 6056 | ||
| 6057 | - /// Replaces the keys of the mask at stack position `slot` of the clip at `idx` of | 6057 | + /// Replaces the keys of the effect at stack position `slot` of the clip at `idx` of |
| 6058 | - /// `lane`; an empty list clears them. Keys are source-frame keyed, sorted here with | 6058 | + /// `lane`; an empty list clears them. Keys are source-frame keyed and sorted here with |
| 6059 | - /// no two alike, each field clamped into the mask's range. Refused for a clip that is | 6059 | + /// no two alike. Each value is clamped into its parameter's range, a parameter that is |
| 6060 | - /// not a picture clip on a video lane, a slot that is not a rect or ellipse mask, | 6060 | + /// not keyable (a switch or a choice) takes the effect's static value, and the unused |
| 6061 | - /// more than [`MAX_TRANSFORM_KEYS`] keys, or a list equal to the current one. One undo step. | 6061 | + /// tail is zeroed. Refused for a clip that is not a picture clip on a video lane, more |
| 6062 | - pub fn set_mask_keys(&mut self, lane: Lane, idx: usize, slot: usize, mut keys: Vec<crate::effects::MaskKey>) -> bool { | 6062 | + /// than [`MAX_TRANSFORM_KEYS`] keys, a non-finite value, or a list equal to the current |
| 6063 | - use crate::effects::{EffectKind, MaskKey}; | 6063 | + /// one. One undo step. |
| 6064 | + pub fn set_effect_keys(&mut self, lane: Lane, idx: usize, slot: usize, mut keys: Vec<crate::effects::EffectKey>) -> bool { | ||
| 6064 | if lane.kind != LaneKind::Video || keys.len() > MAX_TRANSFORM_KEYS { | 6065 | if lane.kind != LaneKind::Video || keys.len() > MAX_TRANSFORM_KEYS { |
| 6065 | return false; | 6066 | return false; |
| 6066 | } | 6067 | } |
| 6067 | - if keys.iter().any(|k| ![k.x, k.y, k.width, k.height, k.feather].iter().all(|v| v.is_finite())) { | ||
| 6068 | - return false; | ||
| 6069 | - } | ||
| 6070 | keys.sort_by_key(|k| k.at); | 6068 | keys.sort_by_key(|k| k.at); |
| 6071 | if keys.windows(2).any(|w| w[0].at == w[1].at) { | 6069 | if keys.windows(2).any(|w| w[0].at == w[1].at) { |
| 6072 | return false; | 6070 | return false; |
| 6073 | } | 6071 | } |
| 6074 | - let r = EffectKind::RectMask.params(); | ||
| 6075 | - for k in &mut keys { | ||
| 6076 | - let c = |v: f32, i: usize| v.clamp(r[i].min, r[i].max); | ||
| 6077 | - *k = MaskKey { x: c(k.x, 0), y: c(k.y, 1), width: c(k.width, 2), height: c(k.height, 3), feather: c(k.feather, 4), ..*k }; | ||
| 6078 | - } | ||
| 6079 | let Some(current) = self.lane(lane).get(idx).and_then(|c| c.effects.get(slot)) else { | 6072 | let Some(current) = self.lane(lane).get(idx).and_then(|c| c.effects.get(slot)) else { |
| 6080 | return false; | 6073 | return false; |
| 6081 | }; | 6074 | }; |
| 6082 | - if !matches!(current.kind, EffectKind::RectMask | EffectKind::EllipseMask) || current.keys == keys { | 6075 | + let specs = current.kind.params(); |
| 6076 | + if keys.iter().any(|k| k.values[..specs.len()].iter().any(|v| !v.is_finite())) { | ||
| 6077 | + return false; | ||
| 6078 | + } | ||
| 6079 | + for k in &mut keys { | ||
| 6080 | + for (i, v) in k.values.iter_mut().enumerate() { | ||
| 6081 | + *v = match specs.get(i) { | ||
| 6082 | + Some(s) if s.keyable() => v.clamp(s.min, s.max), | ||
| 6083 | + Some(_) => current.values[i], | ||
| 6084 | + None => 0.0, | ||
| 6085 | + }; | ||
| 6086 | + } | ||
| 6087 | + } | ||
| 6088 | + if current.keys == keys { | ||
| 6083 | return false; | 6089 | return false; |
| 6084 | } | 6090 | } |
| 6085 | self.snapshot(); | 6091 | self.snapshot(); |
| @@ -11354,7 +11360,7 @@ fn mirror_keys(c: &mut Clip) { | |||
| 11354 | c.opacity_keys = mirrored(&c.opacity_keys, top, |k| k.at, |k| k.ease, |k, at, ease| OpacityKey { at, ease, ..*k }); | 11360 | c.opacity_keys = mirrored(&c.opacity_keys, top, |k| k.at, |k| k.ease, |k, at, ease| OpacityKey { at, ease, ..*k }); |
| 11355 | c.color_keys = mirrored(&c.color_keys, top, |k| k.at, |k| k.ease, |k, at, ease| ColorKey { at, ease, ..*k }); | 11361 | c.color_keys = mirrored(&c.color_keys, top, |k| k.at, |k| k.ease, |k, at, ease| ColorKey { at, ease, ..*k }); |
| 11356 | for e in &mut c.effects { | 11362 | for e in &mut c.effects { |
| 11357 | - e.keys = mirrored(&e.keys, top, |k| k.at, |k| k.ease, |k, at, ease| crate::effects::MaskKey { at, ease, ..*k }); | 11363 | + e.keys = mirrored(&e.keys, top, |k| k.at, |k| k.ease, |k, at, ease| crate::effects::EffectKey { at, ease, ..*k }); |
| 11358 | } | 11364 | } |
| 11359 | } | 11365 | } |
| 11360 | 11366 | ||
crates/mcp/src/help.rsmodified+9 -0
| @@ -730,6 +730,15 @@ const OP_TEXTS: &[(&str, &str)] = &[ | |||
| 730 | stays censored as it moves. clear:true takes the keys off. Up to 256 keys, sorted and clamped like opacity_keys. \ | 730 | stays censored as it moves. clear:true takes the keys off. Up to 256 keys, sorted and clamped like opacity_keys. \ |
| 731 | edit {ops:[{op:\"mask_keys\", clip:\"V1@0\", effect:1, keys:[{at:\"0s\", x:0.3, y:0.5}, {at:\"2s\", x:0.7}]}]}.", | 731 | edit {ops:[{op:\"mask_keys\", clip:\"V1@0\", effect:1, keys:[{at:\"0s\", x:0.3, y:0.5}, {at:\"2s\", x:0.7}]}]}.", |
| 732 | ), | 732 | ), |
| 733 | + ( | ||
| 734 | + "effect_keys", | ||
| 735 | + "effect_keys {clip, effect, keys:[{at, <parameter>?, ease?}], clear?} — animates any numeric parameter of the effect at stack \ | ||
| 736 | + position effect over the clip's own time: every effect's parameters can be keyed (a blur's radius, a vignette's amount and \ | ||
| 737 | + softness, a glow's threshold, a pixelate's size, a chroma key's tolerance, a mask's x, y, width, height and feather), named as \ | ||
| 738 | + the effect names them. A switch or a choice (a blend's mode, a mask's invert) cannot be keyed. A parameter a key leaves out \ | ||
| 739 | + takes the value the effect shows at that time. Up to 256 keys, sorted and clamped. \ | ||
| 740 | + edit {ops:[{op:\"effect_keys\", clip:\"V1@0\", effect:0, keys:[{at:\"0s\", radius:2}, {at:\"3s\", radius:20, ease:\"ease_in_out\"}]}]}.", | ||
| 741 | + ), | ||
| 733 | ( | 742 | ( |
| 734 | "opacity_keys", | 743 | "opacity_keys", |
| 735 | "opacity_keys {clip, keys:[{at, opacity, ease?}], clear?} — the clip's opacity over its own time, 0 (clear) to 1 (opaque): \ | 744 | "opacity_keys {clip, keys:[{at, opacity, ease?}], clear?} — the clip's opacity over its own time, 0 (clear) to 1 (opaque): \ |
crates/mcp/src/tools/edit.rsmodified+3 -2
| @@ -38,7 +38,7 @@ const OWN_OPS: &[&str] = &[ | |||
| 38 | 38 | ||
| 39 | /// Ops `edit_fx` answers. | 39 | /// Ops `edit_fx` answers. |
| 40 | const FX_OPS: &[&str] = &[ | 40 | const FX_OPS: &[&str] = &[ |
| 41 | - "color", "lut", "wheels", "curves", "look", "auto_color", "transform", "transform_keys", "opacity_keys", "mask_keys", "color_keys", "fit", "eq", "gain", "gain_keys", "gain_key", "gain_key_remove", "gain_ramp", | 41 | + "color", "lut", "wheels", "curves", "look", "auto_color", "transform", "transform_keys", "opacity_keys", "mask_keys", "effect_keys", "color_keys", "fit", "eq", "gain", "gain_keys", "gain_key", "gain_key_remove", "gain_ramp", |
| 42 | "gain_dip", "lane_gain", "pan", "pitch", "lane_pan", "limiter", "lane_add", "lane_remove", | 42 | "gain_dip", "lane_gain", "pan", "pitch", "lane_pan", "limiter", "lane_add", "lane_remove", |
| 43 | "lane_move", "lane_flags", "lane_name", "deinterlace", "group", "ungroup", "subtitles_import", "duck", "dynamics", "stabilize", "reframe", "nest", "break_apart", "place_sequence", "angle", "title_add", "title_set", "title_remove", | 43 | "lane_move", "lane_flags", "lane_name", "deinterlace", "group", "ungroup", "subtitles_import", "duck", "dynamics", "stabilize", "reframe", "nest", "break_apart", "place_sequence", "angle", "title_add", "title_set", "title_remove", |
| 44 | "generator_add", "generator_set", "adjustment_add", "label", "enable", | 44 | "generator_add", "generator_set", "adjustment_add", "label", "enable", |
| @@ -115,6 +115,7 @@ transform {clip, x?, y?, scale?, rotate?, crop?:[l,r,t,b], opacity?, reset?} — | |||
| 115 | transform_keys {clip, keys?:[{at, x?, y?, scale?, rotate?, opacity?, ease?}...], clear?} — animates the transform over the clip's own time (at is a clip-relative time, e.g. "0s" or "end"); clear:true takes the keys off, back to the single transform. ease (on every kind of key, the segment that leaves the key): linear (default), ease_in, ease_out, ease_in_out, hold (a step), or bezier(x1,y1,x2,y2) / [x1,y1,x2,y2] for a custom curve (each point 0 to 1). | 115 | transform_keys {clip, keys?:[{at, x?, y?, scale?, rotate?, opacity?, ease?}...], clear?} — animates the transform over the clip's own time (at is a clip-relative time, e.g. "0s" or "end"); clear:true takes the keys off, back to the single transform. ease (on every kind of key, the segment that leaves the key): linear (default), ease_in, ease_out, ease_in_out, hold (a step), or bezier(x1,y1,x2,y2) / [x1,y1,x2,y2] for a custom curve (each point 0 to 1). |
| 116 | opacity_keys {clip, keys?:[{at, opacity, ease?}...], clear?} — opacity (0..1) over the clip's own time; the fades multiply on top. | 116 | opacity_keys {clip, keys?:[{at, opacity, ease?}...], clear?} — opacity (0..1) over the clip's own time; the fades multiply on top. |
| 117 | mask_keys {clip, effect, keys?:[{at, x?, y?, w?, h?, feather?, ease?}...], clear?} — a rect or ellipse mask's position, size and soft edge over the clip's own time; effect is its stack position. | 117 | mask_keys {clip, effect, keys?:[{at, x?, y?, w?, h?, feather?, ease?}...], clear?} — a rect or ellipse mask's position, size and soft edge over the clip's own time; effect is its stack position. |
| 118 | +effect_keys {clip, effect, keys?:[{at, <parameter>?: value, ease?}...], clear?} — animates any numeric parameter of the effect at stack position effect over the clip's own time, named as the effect names it (a blur's radius, a vignette's amount and softness, a mask's x, y, width, height and feather). A switch or a choice (a blend's mode, a mask's invert) cannot be keyed. A parameter a key leaves out takes the value the effect shows at that time. ease as transform_keys. | ||
| 118 | color_keys {clip, keys?:[{at, brightness?, contrast?, saturation?, tint?, ease?}...], clear?} — the grade over the clip's own time; fields a key leaves out keep the previous key's value. | 119 | color_keys {clip, keys?:[{at, brightness?, contrast?, saturation?, tint?, ease?}...], clear?} — the grade over the clip's own time; fields a key leaves out keep the previous key's value. |
| 119 | fit {clip, policy: fit|fill|stretch|center} — canvas fit. | 120 | fit {clip, policy: fit|fill|stretch|center} — canvas fit. |
| 120 | deinterlace {clip, mode: frame|field|off} — how a video clip's interlaced source is made progressive (default frame); stored on the clip, and only matters for an interlaced source (media_probe says interlaced). field (double rate) and off are stored; the render acts on frame for now. | 121 | deinterlace {clip, mode: frame|field|off} — how a video clip's interlaced source is made progressive (default frame); stored on the clip, and only matters for an interlaced source (media_probe says interlaced). field (double rate) and off are stored; the render acts on frame for now. |
| @@ -298,7 +299,7 @@ fn accepted_keys(name: &str) -> Option<&'static [&'static str]> { | |||
| 298 | "transform" => &["clip", "x", "y", "corner", "margin", "scale", "rotate", "crop", "reset", "opacity"], | 299 | "transform" => &["clip", "x", "y", "corner", "margin", "scale", "rotate", "crop", "reset", "opacity"], |
| 299 | "transform_keys" => &["clip", "keys", "clear"], | 300 | "transform_keys" => &["clip", "keys", "clear"], |
| 300 | "opacity_keys" | "color_keys" => &["clip", "keys", "clear"], | 301 | "opacity_keys" | "color_keys" => &["clip", "keys", "clear"], |
| 301 | - "mask_keys" => &["clip", "effect", "keys", "clear"], | 302 | + "mask_keys" | "effect_keys" => &["clip", "effect", "keys", "clear"], |
| 302 | "fit" => &["clip", "policy"], | 303 | "fit" => &["clip", "policy"], |
| 303 | "eq" => &["clip", "bands", "reset"], | 304 | "eq" => &["clip", "bands", "reset"], |
| 304 | "gain" => &["clip", "db", "add_db"], | 305 | "gain" => &["clip", "db", "add_db"], |
crates/mcp/src/tools/edit_fx.rsmodified+111 -32
| @@ -9,7 +9,7 @@ | |||
| 9 | use std::path::Path; | 9 | use std::path::Path; |
| 10 | 10 | ||
| 11 | use engine::color::ColorParams; | 11 | use engine::color::ColorParams; |
| 12 | -use engine::effects::{EffectKind, MaskKey}; | 12 | +use engine::effects::{EffectKey, EffectKind, ParamSpec}; |
| 13 | use engine::duck::{ | 13 | use engine::duck::{ |
| 14 | Duck, MAX_ATTACK_MS, MAX_DEPTH_DB, MAX_RELEASE_MS, MAX_THRESHOLD_DB, MIN_DEPTH_DB, | 14 | Duck, MAX_ATTACK_MS, MAX_DEPTH_DB, MAX_RELEASE_MS, MAX_THRESHOLD_DB, MIN_DEPTH_DB, |
| 15 | MIN_THRESHOLD_DB, MIN_TIME_MS, | 15 | MIN_THRESHOLD_DB, MIN_TIME_MS, |
| @@ -51,6 +51,7 @@ pub fn apply(s: &mut PlaybackSession, op: &Value, fps: f64) -> Option<Result<App | |||
| 51 | "transform_keys" => transform_keys(s, op, fps), | 51 | "transform_keys" => transform_keys(s, op, fps), |
| 52 | "opacity_keys" => opacity_keys(s, op, fps), | 52 | "opacity_keys" => opacity_keys(s, op, fps), |
| 53 | "mask_keys" => mask_keys(s, op, fps), | 53 | "mask_keys" => mask_keys(s, op, fps), |
| 54 | + "effect_keys" => effect_keys(s, op, fps), | ||
| 54 | "color_keys" => color_keys(s, op, fps), | 55 | "color_keys" => color_keys(s, op, fps), |
| 55 | "lut" => lut(s, op), | 56 | "lut" => lut(s, op), |
| 56 | "wheels" => wheels(s, op), | 57 | "wheels" => wheels(s, op), |
| @@ -853,21 +854,16 @@ fn mask_keys(s: &mut PlaybackSession, op: &Value, fps: f64) -> Result<Applied, S | |||
| 853 | return Err(format!("{who}: {raw} is on an audio lane; mask keys belong to a picture clip")); | 854 | return Err(format!("{who}: {raw} is on an audio lane; mask keys belong to a picture clip")); |
| 854 | } | 855 | } |
| 855 | let c = s.lane_clips(lane).get(idx).cloned().ok_or_else(|| refused(&who))?; | 856 | let c = s.lane_clips(lane).get(idx).cloned().ok_or_else(|| refused(&who))?; |
| 856 | - let slot = match op.get("effect") { | 857 | + let slot = effect_slot(&who, op, &c)?; |
| 857 | - None | Some(Value::Null) => return Err(format!("{who}: missing `effect`: the mask's stack position, 0 for the first effect")), | 858 | + let e = &c.effects[slot]; |
| 858 | - Some(v) => v.as_u64().ok_or_else(|| format!("{who}: effect must be a stack position, 0 for the first"))? as usize, | ||
| 859 | - }; | ||
| 860 | - let e = c.effects.get(slot).ok_or_else(|| { | ||
| 861 | - format!("{who}: effect {slot} is out of range: the clip has {} effects", c.effects.len()) | ||
| 862 | - })?; | ||
| 863 | if !matches!(e.kind, EffectKind::RectMask | EffectKind::EllipseMask) { | 859 | if !matches!(e.kind, EffectKind::RectMask | EffectKind::EllipseMask) { |
| 864 | return Err(format!("{who}: effect {slot} is {}, and only a rect or ellipse mask takes keys", e.kind.name())); | 860 | return Err(format!("{who}: effect {slot} is {}, and only a rect or ellipse mask takes keys", e.kind.name())); |
| 865 | } | 861 | } |
| 866 | if flag(op, "clear")? { | 862 | if flag(op, "clear")? { |
| 867 | - if s.mask_keys_of(lane, idx, slot).is_empty() { | 863 | + if s.effect_keys_of(lane, idx, slot).is_empty() { |
| 868 | return Ok(done(format!("{who} → already no keys"), Vec::new())); | 864 | return Ok(done(format!("{who} → already no keys"), Vec::new())); |
| 869 | } | 865 | } |
| 870 | - if !s.set_mask_keys(lane, idx, slot, Vec::new()) { | 866 | + if !s.set_effect_keys(lane, idx, slot, Vec::new()) { |
| 871 | return Err(refused(&who)); | 867 | return Err(refused(&who)); |
| 872 | } | 868 | } |
| 873 | return Ok(done(format!("{who} → cleared (0 keys)"), vec![(lane, start)])); | 869 | return Ok(done(format!("{who} → cleared (0 keys)"), vec![(lane, start)])); |
| @@ -893,48 +889,131 @@ fn mask_keys(s: &mut PlaybackSession, op: &Value, fps: f64) -> Result<Applied, S | |||
| 893 | prev[j] = ranged(&who, name, v, f64::from(r[j].min), f64::from(r[j].max))?; | 889 | prev[j] = ranged(&who, name, v, f64::from(r[j].min), f64::from(r[j].max))?; |
| 894 | } | 890 | } |
| 895 | } | 891 | } |
| 896 | - keys.push(MaskKey { | 892 | + keys.push(EffectKey { |
| 897 | at: src_at(&c, start + off), | 893 | at: src_at(&c, start + off), |
| 898 | - x: prev[0], | 894 | + values: [prev[0], prev[1], prev[2], prev[3], prev[4], e.values[5]], |
| 899 | - y: prev[1], | ||
| 900 | - width: prev[2], | ||
| 901 | - height: prev[3], | ||
| 902 | - feather: prev[4], | ||
| 903 | ease: ease_of(&who, n, k)?, | 895 | ease: ease_of(&who, n, k)?, |
| 904 | }); | 896 | }); |
| 905 | } | 897 | } |
| 906 | let at: Vec<u32> = keys.iter().map(|k| k.at).collect(); | 898 | let at: Vec<u32> = keys.iter().map(|k| k.at).collect(); |
| 907 | clash_check(&who, &c, &at, &timed, start, fps)?; | 899 | clash_check(&who, &c, &at, &timed, start, fps)?; |
| 908 | - let text = format!("{who} → {}", mask_keys_text(&c, fps, &keys)); | 900 | + let text = format!("{who} → {}", effect_keys_text(&c, fps, r, &keys)); |
| 909 | - if keys == s.mask_keys_of(lane, idx, slot) { | 901 | + if keys == s.effect_keys_of(lane, idx, slot) { |
| 910 | - return Ok(done(format!("{who} → already {}", mask_keys_text(&c, fps, &keys)), Vec::new())); | 902 | + return Ok(done(format!("{who} → already {}", effect_keys_text(&c, fps, r, &keys)), Vec::new())); |
| 903 | + } | ||
| 904 | + if !s.set_effect_keys(lane, idx, slot, keys) { | ||
| 905 | + return Err(refused(&who)); | ||
| 906 | + } | ||
| 907 | + Ok(done(text, vec![(lane, start)])) | ||
| 908 | +} | ||
| 909 | + | ||
| 910 | +/// `effect_keys {clip, effect, keys:[{at, <param>?: n, ease?}], clear?}`: animates any numeric | ||
| 911 | +/// parameter of the effect at stack position `effect` over the clip's own time. The parameter | ||
| 912 | +/// names are the effect's own (a blur's `radius`, a vignette's `amount` and `softness`, a mask's | ||
| 913 | +/// `x`, `y`, `width`, `height` and `feather`). A switch or a choice (a blend's `mode`, a mask's | ||
| 914 | +/// `invert`) cannot be keyed and is refused by name. A key leaves each parameter it does not name | ||
| 915 | +/// at the value the effect shows at that time. `clear:true` takes the keys off. | ||
| 916 | +fn effect_keys(s: &mut PlaybackSession, op: &Value, fps: f64) -> Result<Applied, String> { | ||
| 917 | + let (lane, idx, raw, start) = clip_arg(s, op)?; | ||
| 918 | + let who = format!("effect_keys {raw}"); | ||
| 919 | + if lane.kind != LaneKind::Video { | ||
| 920 | + return Err(format!("{who}: {raw} is on an audio lane; effect keys belong to a picture clip")); | ||
| 921 | + } | ||
| 922 | + let c = s.lane_clips(lane).get(idx).cloned().ok_or_else(|| refused(&who))?; | ||
| 923 | + let slot = effect_slot(&who, op, &c)?; | ||
| 924 | + let e = c.effects[slot].clone(); | ||
| 925 | + let specs = e.kind.params(); | ||
| 926 | + if flag(op, "clear")? { | ||
| 927 | + if s.effect_keys_of(lane, idx, slot).is_empty() { | ||
| 928 | + return Ok(done(format!("{who} → already no keys"), Vec::new())); | ||
| 929 | + } | ||
| 930 | + if !s.set_effect_keys(lane, idx, slot, Vec::new()) { | ||
| 931 | + return Err(refused(&who)); | ||
| 932 | + } | ||
| 933 | + return Ok(done(format!("{who} → cleared (0 keys)"), vec![(lane, start)])); | ||
| 934 | + } | ||
| 935 | + let list = match op.get("keys") { | ||
| 936 | + Some(Value::Array(a)) => a, | ||
| 937 | + None | Some(Value::Null) => { | ||
| 938 | + return Err(format!("{who}: missing `keys`: a list of {{at, <parameter>, ease?}} objects, or clear:true")) | ||
| 939 | + } | ||
| 940 | + Some(v) => return Err(format!("{who}: keys must be a list of {{at, <parameter>, ease?}} objects, got {}", kind_of(v))), | ||
| 941 | + }; | ||
| 942 | + for k in list.iter().filter_map(Value::as_object) { | ||
| 943 | + for spec in specs.iter().filter(|p| !p.keyable()) { | ||
| 944 | + if k.contains_key(spec.name) { | ||
| 945 | + return Err(format!("{who}: {} cannot be keyed: a switch or a choice holds its static value", spec.name)); | ||
| 946 | + } | ||
| 947 | + } | ||
| 948 | + } | ||
| 949 | + let keyable: Vec<&str> = specs.iter().filter(|p| p.keyable()).map(|p| p.name).collect(); | ||
| 950 | + let end = parse::session_end(s); | ||
| 951 | + let timed = timed_keys(&who, list, &keyable, &c, fps, end, MAX_TRANSFORM_KEYS)?; | ||
| 952 | + let mut keys = Vec::with_capacity(timed.len()); | ||
| 953 | + for (i, (off, k)) in timed.iter().enumerate() { | ||
| 954 | + let n = i + 1; | ||
| 955 | + let at = src_at(&c, start + off); | ||
| 956 | + // A parameter the key does not name holds the value the effect shows at that frame. | ||
| 957 | + let mut values = e.posed(f64::from(at)).values; | ||
| 958 | + for (j, spec) in specs.iter().enumerate().filter(|(_, p)| p.keyable()) { | ||
| 959 | + if let Some(v) = num_of(k, spec.name)? { | ||
| 960 | + values[j] = ranged(&who, spec.name, v, f64::from(spec.min), f64::from(spec.max))?; | ||
| 961 | + } | ||
| 962 | + } | ||
| 963 | + keys.push(EffectKey { at, values, ease: ease_of(&who, n, k)? }); | ||
| 964 | + } | ||
| 965 | + let at: Vec<u32> = keys.iter().map(|k| k.at).collect(); | ||
| 966 | + clash_check(&who, &c, &at, &timed, start, fps)?; | ||
| 967 | + let text = format!("{who} → {}", effect_keys_text(&c, fps, specs, &keys)); | ||
| 968 | + if keys == s.effect_keys_of(lane, idx, slot) { | ||
| 969 | + return Ok(done(format!("{who} → already {}", effect_keys_text(&c, fps, specs, &keys)), Vec::new())); | ||
| 911 | } | 970 | } |
| 912 | - if !s.set_mask_keys(lane, idx, slot, keys) { | 971 | + if !s.set_effect_keys(lane, idx, slot, keys) { |
| 913 | return Err(refused(&who)); | 972 | return Err(refused(&who)); |
| 914 | } | 973 | } |
| 915 | Ok(done(text, vec![(lane, start)])) | 974 | Ok(done(text, vec![(lane, start)])) |
| 916 | } | 975 | } |
| 917 | 976 | ||
| 918 | -/// The mask keys as timeline times: at most twelve, then `(+N more)`. | 977 | +/// The stack position a keys op names with `effect`, checked to be on the clip. |
| 919 | -fn mask_keys_text(c: &Clip, fps: f64, keys: &[MaskKey]) -> String { | 978 | +fn effect_slot(who: &str, op: &Value, c: &Clip) -> Result<usize, String> { |
| 979 | + let slot = match op.get("effect") { | ||
| 980 | + None | Some(Value::Null) => { | ||
| 981 | + return Err(format!("{who}: missing `effect`: the effect's stack position, 0 for the first")) | ||
| 982 | + } | ||
| 983 | + Some(v) => v.as_u64().ok_or_else(|| format!("{who}: effect must be a stack position, 0 for the first"))? as usize, | ||
| 984 | + }; | ||
| 985 | + if slot >= c.effects.len() { | ||
| 986 | + return Err(format!("{who}: effect {slot} is out of range: the clip has {} effects", c.effects.len())); | ||
| 987 | + } | ||
| 988 | + Ok(slot) | ||
| 989 | +} | ||
| 990 | + | ||
| 991 | +/// One keyed value as a reply prints it: whole for a stepped parameter, else to two or three places. | ||
| 992 | +fn value_text(v: f32, spec: &ParamSpec) -> String { | ||
| 993 | + if spec.step >= 1.0 { | ||
| 994 | + format!("{v:.0}") | ||
| 995 | + } else if spec.step >= 0.01 { | ||
| 996 | + format!("{v:.2}") | ||
| 997 | + } else { | ||
| 998 | + format!("{v:.3}") | ||
| 999 | + } | ||
| 1000 | +} | ||
| 1001 | + | ||
| 1002 | +/// The effect keys as timeline times, each with its keyable parameters' values: at most twelve, | ||
| 1003 | +/// then `(+N more)`. | ||
| 1004 | +fn effect_keys_text(c: &Clip, fps: f64, specs: &[ParamSpec], keys: &[EffectKey]) -> String { | ||
| 920 | const SHOWN: usize = 12; | 1005 | const SHOWN: usize = 12; |
| 921 | if keys.is_empty() { | 1006 | if keys.is_empty() { |
| 922 | return "cleared (0 keys)".to_string(); | 1007 | return "cleared (0 keys)".to_string(); |
| 923 | } | 1008 | } |
| 1009 | + let keyed: Vec<(usize, &ParamSpec)> = specs.iter().enumerate().filter(|(_, p)| p.keyable()).collect(); | ||
| 924 | let mut parts: Vec<String> = keys | 1010 | let mut parts: Vec<String> = keys |
| 925 | .iter() | 1011 | .iter() |
| 926 | .take(SHOWN) | 1012 | .take(SHOWN) |
| 927 | .map(|k| { | 1013 | .map(|k| { |
| 928 | - format!( | 1014 | + let values: Vec<String> = |
| 929 | - "{} x {:.2} y {:.2} w {:.2} h {:.2} feather {:.3}{}", | 1015 | + keyed.iter().map(|(i, p)| format!("{} {}", p.name, value_text(k.values[*i], p))).collect(); |
| 930 | - tsec(timeline_of(c, k.at), fps), | 1016 | + format!("{} {}{}", tsec(timeline_of(c, k.at), fps), values.join(" "), ease_suffix(k.ease)) |
| 931 | - k.x, | ||
| 932 | - k.y, | ||
| 933 | - k.width, | ||
| 934 | - k.height, | ||
| 935 | - k.feather, | ||
| 936 | - ease_suffix(k.ease) | ||
| 937 | - ) | ||
| 938 | }) | 1017 | }) |
| 939 | .collect(); | 1018 | .collect(); |
| 940 | if keys.len() > SHOWN { | 1019 | if keys.len() > SHOWN { |
crates/mcp/src/tools/effects.rsmodified+1 -1
| @@ -20,7 +20,7 @@ const EFFECT_DOC: &str = r##"A video clip's effects stack: ops add, set, remove, | |||
| 20 | - remove {clip, index} · move {clip, from, to} (stack positions; `to` is where it lands). | 20 | - remove {clip, index} · move {clip, from, to} (stack positions; `to` is where it lands). |
| 21 | - list {clip}: the stack with each effect's position, kind, on/off and named values. list with no clip: the kinds with their parameters and ranges. | 21 | - list {clip}: the stack with each effect's position, kind, on/off and named values. list with no clip: the kinds with their parameters and ranges. |
| 22 | params is {name: number}; a number outside a range is clamped and the reply says so. color:"#rrggbb" sets a chroma_key's red, green and blue; mode:"screen" sets a blend's mode (normal, multiply, screen, overlay, add, darken, lighten). Masks take invert as 1/0 or true/false. | 22 | params is {name: number}; a number outside a range is clamped and the reply says so. color:"#rrggbb" sets a chroma_key's red, green and blue; mode:"screen" sets a blend's mode (normal, multiply, screen, overlay, add, darken, lighten). Masks take invert as 1/0 or true/false. |
| 23 | -Effects are static: one value for the whole clip, except a rect or ellipse mask's position, size and soft edge, which take keys through edit's mask_keys (the stack position is the effect index), or follow a picture feature through the clip with track {clip, effect_index}. Distances (blur radius, shake amount, pixelate block size) are pixels at 1080 lines and scale with the frame height, so preview and export agree at any size. Ken Burns stays in transform_keys. Pixelate (size 2..200) makes mosaic blocks; a mask placed right after it limits the mosaic to that mask's shape and does not cut the clip, so an ellipse after a pixelate censors a face. Without a mask the whole picture is mosaiced. A stack that is empty or all switched off changes nothing. chroma_key and the masks reveal the lanes below; blend picks how the clip lies over them."##; | 23 | +Effects are static: one value for the whole clip, unless keyed. Every numeric parameter of every effect can take keys through edit's effect_keys (the stack position is the effect index); a switch or a choice, such as a blend's mode or a mask's invert, stays static. A rect or ellipse mask's position can also follow a picture feature through the clip with track {clip, effect_index}. Distances (blur radius, shake amount, pixelate block size) are pixels at 1080 lines and scale with the frame height, so preview and export agree at any size. Ken Burns stays in transform_keys. Pixelate (size 2..200) makes mosaic blocks; a mask placed right after it limits the mosaic to that mask's shape and does not cut the clip, so an ellipse after a pixelate censors a face. Without a mask the whole picture is mosaiced. A stack that is empty or all switched off changes nothing. chroma_key and the masks reveal the lanes below; blend picks how the clip lies over them."##; |
| 24 | 24 | ||
| 25 | pub fn tools() -> Vec<Tool> { | 25 | pub fn tools() -> Vec<Tool> { |
| 26 | vec![Tool { name: "effect", description: EFFECT_DOC, schema: effect_schema, run: run_effect }] | 26 | vec![Tool { name: "effect", description: EFFECT_DOC, schema: effect_schema, run: run_effect }] |
crates/mcp/src/tools/look.rsmodified+62 -0
| @@ -13,6 +13,7 @@ use engine::project::{Edge, Lane, LaneKind, Title, TrimWalls}; | |||
| 13 | use engine::scale::FitPolicy; | 13 | use engine::scale::FitPolicy; |
| 14 | use engine::color::ColorKey; | 14 | use engine::color::ColorKey; |
| 15 | use engine::transform::{OpacityKey, TransformKey}; | 15 | use engine::transform::{OpacityKey, TransformKey}; |
| 16 | +use engine::effects::Effect; | ||
| 16 | use engine::{Clip, PlaybackSession}; | 17 | use engine::{Clip, PlaybackSession}; |
| 17 | 18 | ||
| 18 | use super::edit::audio_tracks; | 19 | use super::edit::audio_tracks; |
| @@ -946,6 +947,61 @@ fn color_key_lines(c: &Clip, fps: f64, keys: &[ColorKey]) -> Vec<String> { | |||
| 946 | .collect() | 947 | .collect() |
| 947 | } | 948 | } |
| 948 | 949 | ||
| 950 | +/// An effect's keys, one line each: the clip time and the timeline time, then each keyed | ||
| 951 | +/// parameter by name with its value, and the ease that leaves the key. | ||
| 952 | +fn effect_key_lines(c: &Clip, fps: f64, e: &Effect) -> Vec<String> { | ||
| 953 | + e.keys | ||
| 954 | + .iter() | ||
| 955 | + .map(|k| { | ||
| 956 | + let at = timeline_of(c, k.at); | ||
| 957 | + let values: String = e | ||
| 958 | + .kind | ||
| 959 | + .params() | ||
| 960 | + .iter() | ||
| 961 | + .enumerate() | ||
| 962 | + .filter(|(_, p)| p.keyable()) | ||
| 963 | + .map(|(i, p)| format!(" {} {}", p.name, num(f64::from(k.values[i])))) | ||
| 964 | + .collect(); | ||
| 965 | + format!( | ||
| 966 | + " at clip {:.3}s (timeline {:.3}s){values} ease {}", | ||
| 967 | + (at - f64::from(c.start)) / fps, | ||
| 968 | + at / fps, | ||
| 969 | + k.ease.name() | ||
| 970 | + ) | ||
| 971 | + }) | ||
| 972 | + .collect() | ||
| 973 | +} | ||
| 974 | + | ||
| 975 | +/// The keyed effects as JSON: each one's stack position and kind, then its keys with the | ||
| 976 | +/// timeline time, the source frame, every keyed parameter by name, and the ease. | ||
| 977 | +fn effect_keys_json(c: &Clip, fps: f64, effects: &[Effect]) -> Value { | ||
| 978 | + Value::Array( | ||
| 979 | + effects | ||
| 980 | + .iter() | ||
| 981 | + .enumerate() | ||
| 982 | + .filter(|(_, e)| !e.keys.is_empty()) | ||
| 983 | + .map(|(slot, e)| { | ||
| 984 | + let keys: Vec<Value> = e | ||
| 985 | + .keys | ||
| 986 | + .iter() | ||
| 987 | + .map(|k| { | ||
| 988 | + let mut v = json!({ | ||
| 989 | + "time": timeline_of(c, k.at) / fps, | ||
| 990 | + "source_frame": k.at, | ||
| 991 | + "ease": k.ease.name(), | ||
| 992 | + }); | ||
| 993 | + for (i, p) in e.kind.params().iter().enumerate().filter(|(_, p)| p.keyable()) { | ||
| 994 | + v[p.name] = json!(k.values[i]); | ||
| 995 | + } | ||
| 996 | + v | ||
| 997 | + }) | ||
| 998 | + .collect(); | ||
| 999 | + json!({ "index": slot, "kind": e.kind.name(), "keys": keys }) | ||
| 1000 | + }) | ||
| 1001 | + .collect(), | ||
| 1002 | + ) | ||
| 1003 | +} | ||
| 1004 | + | ||
| 949 | fn opacity_keys_json(c: &Clip, fps: f64, keys: &[OpacityKey]) -> Value { | 1005 | fn opacity_keys_json(c: &Clip, fps: f64, keys: &[OpacityKey]) -> Value { |
| 950 | Value::Array( | 1006 | Value::Array( |
| 951 | keys.iter() | 1007 | keys.iter() |
| @@ -1249,6 +1305,11 @@ fn media_info(s: &PlaybackSession, lane: Lane, idx: usize, fps: f64) -> Reply { | |||
| 1249 | lines.push(format!("color keys: {}", ckeys.len())); | 1305 | lines.push(format!("color keys: {}", ckeys.len())); |
| 1250 | lines.extend(color_key_lines(c, fps, ckeys)); | 1306 | lines.extend(color_key_lines(c, fps, ckeys)); |
| 1251 | } | 1307 | } |
| 1308 | + // Each effect with keys: its keyed values at every key, with the ease that leaves it. | ||
| 1309 | + for (slot, e) in s.effects_of(lane, idx).iter().enumerate().filter(|(_, e)| !e.keys.is_empty()) { | ||
| 1310 | + lines.push(format!("effect {slot} {} keys: {}", e.kind.name(), e.keys.len())); | ||
| 1311 | + lines.extend(effect_key_lines(c, fps, e)); | ||
| 1312 | + } | ||
| 1252 | if let Some(n) = engine::project::label_name(c.mark.label) { | 1313 | if let Some(n) = engine::project::label_name(c.mark.label) { |
| 1253 | lines.push(format!("label {n}")); | 1314 | lines.push(format!("label {n}")); |
| 1254 | } | 1315 | } |
| @@ -1328,6 +1389,7 @@ fn media_info(s: &PlaybackSession, lane: Lane, idx: usize, fps: f64) -> Reply { | |||
| 1328 | "transform_keys": transform_keys_json(c, fps, keys), | 1389 | "transform_keys": transform_keys_json(c, fps, keys), |
| 1329 | "opacity_keys": opacity_keys_json(c, fps, okeys), | 1390 | "opacity_keys": opacity_keys_json(c, fps, okeys), |
| 1330 | "color_keys": color_keys_json(c, fps, ckeys), | 1391 | "color_keys": color_keys_json(c, fps, ckeys), |
| 1392 | + "effect_keys": effect_keys_json(c, fps, s.effects_of(lane, idx)), | ||
| 1331 | "trim_walls": { | 1393 | "trim_walls": { |
| 1332 | "start": walls_json(walls_start), | 1394 | "start": walls_json(walls_start), |
| 1333 | "end": walls_json(walls_end), | 1395 | "end": walls_json(walls_end), |