The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.
Rust ffmpegfree-video-editormodel-context-protocolnon-linear-editoroffline-firstopen-source-video-editorself-hostedvideo-editingvideo-editing-automationvideo-editing-softwarevideo-editing-toolsvideo-editorvoice-cloningyoutube-automationyoutube-shorts
Keyframes on six properties, eased by bezier, and the audio panel after CapCut
Jareer28d652ab9ed6
diff --git a/engine/crates/concat-core/src/animate.rs b/engine/crates/concat-core/src/animate.rsindex 360ba0f6..88ede256 100644--- a/engine/crates/concat-core/src/animate.rs+++ b/engine/crates/concat-core/src/animate.rs@@ -16,37 +16,114 @@use crate::timeline::Transform;-/// How a key is approached from the one before it.-#[derive(Clone, Copy, PartialEq, Eq, Debug, Default)]-pub enum Ease {- /// Straight line.- #[default]- Linear,- /// Starts slow, arrives fast.- In,- /// Starts fast, arrives slow.- Out,- /// Slow at both ends.- InOut,+/// How a key is approached from the one before it: a CSS timing function,+/// as its two control points.+///+/// Four numbers rather than a handful of named shapes, because the named+/// shapes are four numbers each and a curve editor is not - the panel hands+/// people a bezier to drag, and the presets below are what its chips write.+/// The endpoints are pinned at (0,0) and (1,1), so only the middle two+/// points are stored, and `x` is clamped into `0..=1` where a legal timing+/// function keeps it.+#[derive(Clone, Copy, PartialEq, Debug)]+pub struct Ease {+ /// First control point's x, `0..=1`.+ pub x1: f64,+ /// First control point's y; may overshoot.+ pub y1: f64,+ /// Second control point's x, `0..=1`.+ pub x2: f64,+ /// Second control point's y; may overshoot.+ pub y2: f64,+}++impl Default for Ease {+ fn default() -> Self {+ Ease::LINEAR+ }}impl Ease {+ /// A straight line.+ pub const LINEAR: Ease = Ease::new(0.0, 0.0, 1.0, 1.0);+ /// Starts slow, arrives fast. CSS `ease-in`.+ pub const IN: Ease = Ease::new(0.42, 0.0, 1.0, 1.0);+ /// Starts fast, arrives slow. CSS `ease-out`.+ pub const OUT: Ease = Ease::new(0.0, 0.0, 0.58, 1.0);+ /// Slow at both ends. CSS `ease-in-out`.+ pub const IN_OUT: Ease = Ease::new(0.42, 0.0, 0.58, 1.0);++ /// The four control-point numbers, as given.+ pub const fn new(x1: f64, y1: f64, x2: f64, y2: f64) -> Ease {+ Ease { x1, y1, x2, y2 }+ }++ /// Whether this is the straight line, to within a hair. What lets the+ /// mixer skip resampling a ride that has nothing to resample.+ pub fn is_linear(self) -> bool {+ (self.x1 - self.y1).abs() < 1e-6 && (self.x2 - self.y2).abs() < 1e-6+ }+/// The eased fraction for a linear one.pub fn apply(self, t: f64) -> f64 {- let t = t.clamp(0.0, 1.0);- match self {- Ease::Linear => t,- Ease::In => t * t,- Ease::Out => 1.0 - (1.0 - t) * (1.0 - t),- Ease::InOut => {- if t < 0.5 {- 2.0 * t * t- } else {- 1.0 - (-2.0 * t + 2.0).powi(2) / 2.0- }- }+ if self.is_linear() {+ return t.clamp(0.0, 1.0);+ }+ bezier_y_at_x(self.x1, self.y1, self.x2, self.y2, t)+ }+}++/// x of a cubic bezier with endpoints pinned at 0 and 1, at parameter `t`.+fn bezier_axis(p1: f64, p2: f64, t: f64) -> f64 {+ let u = 1.0 - t;+ 3.0 * u * u * t * p1 + 3.0 * u * t * t * p2 + t * t * t+}++fn bezier_axis_slope(p1: f64, p2: f64, t: f64) -> f64 {+ let u = 1.0 - t;+ 3.0 * u * u * p1 + 6.0 * u * t * (p2 - p1) + 3.0 * t * t * (1.0 - p2)+}++/// Solve a CSS cubic-bezier for y at a given x: Newton first, bisection as+/// the fallback where the curve is flat enough that Newton stalls.+///+/// The one solver. The window's `Curves.ease` global reaches it through+/// `format::bezier_y_at_x`, because Slint's expression language has no loops+/// and so cannot do this itself; the engine reaches it through `Ease::apply`+/// on every frame of every keyed property. Two callers, one definition -+/// which matters here more than most, because a preview whose easing+/// disagreed with the export's would disagree invisibly.+pub fn bezier_y_at_x(x1: f64, y1: f64, x2: f64, y2: f64, x: f64) -> f64 {+ let x = x.clamp(0.0, 1.0);+ let mut t = x;++ for _ in 0..8 {+ let error = bezier_axis(x1, x2, t) - x;+ if error.abs() < 1e-7 {+ return bezier_axis(y1, y2, t);}+ let slope = bezier_axis_slope(x1, x2, t);+ if slope.abs() < 1e-9 {+ break;+ }+ t -= error / slope;+ }++ let (mut lo, mut hi) = (0.0_f64, 1.0_f64);+ t = x;+ for _ in 0..32 {+ let at = bezier_axis(x1, x2, t);+ if (at - x).abs() < 1e-7 {+ break;+ }+ if at > x {+ hi = t;+ } else {+ lo = t;+ }+ t = (lo + hi) / 2.0;}+ bezier_axis(y1, y2, t)}/// One key of one property.@@ -108,6 +185,45 @@ impl Track {}self.keys[self.keys.len() - 1].value}++ /// The same ride, with every eased segment replaced by `steps` straight+ /// ones through the same points.+ ///+ /// For callers that can interpolate but cannot ease. The mixer is the+ /// one that needs it: a clip's gain ride becomes an FFmpeg `volume`+ /// expression, and an expression can lerp but cannot run the Newton+ /// solve a bezier wants. Sampling here rather than there keeps the+ /// easing in the one place that understands it, and leaves the+ /// expression generator with nothing but straight lines to write.+ ///+ /// Linear segments are passed through untouched, so a ride nobody has+ /// eased costs nothing and reads identically on both sides.+ pub fn resample(&self, steps: usize) -> Track {+ let steps = steps.max(1);+ if self.keys.len() < 2 || self.keys.iter().all(|key| key.ease.is_linear()) {+ return self.clone();+ }+ let mut out = vec![self.keys[0]];+ for pair in self.keys.windows(2) {+ let (a, b) = (pair[0], pair[1]);+ if b.ease.is_linear() || b.at <= a.at {+ out.push(Key {+ ease: Ease::LINEAR,+ ..b+ });+ continue;+ }+ for step in 1..=steps {+ let t = step as f64 / steps as f64;+ out.push(Key {+ at: a.at + (b.at - a.at) * t,+ value: a.value + (b.value - a.value) * b.ease.apply(t),+ ease: Ease::LINEAR,+ });+ }+ }+ Track { keys: out }+ }}/// Every animatable property's keys.@@ -123,6 +239,11 @@ pub struct Animation {pub rotation: Track,/// A factor on the clip's opacity; 1 is as set.pub opacity: Track,+ /// A factor on the clip's gain; 1 is as mixed. Sound rather than+ /// picture, but the same shape of fact - a value that changes over the+ /// clip - so it is a track here and not a second mechanism somewhere+ /// else. Nothing in the compositor reads it; the mixer does.+ pub volume: Track,}impl Animation {@@ -133,6 +254,7 @@ impl Animation {&& self.offset_y.is_empty()&& self.rotation.is_empty()&& self.opacity.is_empty()+ && self.volume.is_empty()}/// The clip's transform at `x`, a fraction of its length.@@ -151,6 +273,13 @@ impl Animation {pub fn opacity_at(&self, base: f32, x: f64) -> f32 {(f64::from(base) * self.opacity.value_at(x, 1.0)).clamp(0.0, 1.0) as f32}++ /// The clip's gain at `x`. Unclamped at the top: a key above unity is a+ /// clip being lifted, which is the whole point of keying gain, and the+ /// mixer is where clipping is anyone's business.+ pub fn volume_at(&self, base: f64, x: f64) -> f64 {+ (base * self.volume.value_at(x, 1.0)).max(0.0)+ }}#[cfg(test)]@@ -164,17 +293,17 @@ mod tests {#[test]fn a_track_holds_its_ends_and_eases_between() {let track = Track::new(vec![- key(0.5, 1.0, Ease::Linear),- key(0.0, 0.0, Ease::Linear),+ key(0.5, 1.0, Ease::LINEAR),+ key(0.0, 0.0, Ease::LINEAR),]);assert_eq!(track.value_at(-1.0, 7.0), 0.0);assert_eq!(track.value_at(0.25, 7.0), 0.5);assert_eq!(track.value_at(0.9, 7.0), 1.0);assert_eq!(Track::default().value_at(0.5, 7.0), 7.0);- let eased = Track::new(vec![key(0.0, 0.0, Ease::Linear), key(1.0, 1.0, Ease::Out)]);+ let eased = Track::new(vec![key(0.0, 0.0, Ease::LINEAR), key(1.0, 1.0, Ease::OUT)]);assert!(eased.value_at(0.5, 0.0) > 0.5);- let eased = Track::new(vec![key(0.0, 0.0, Ease::Linear), key(1.0, 1.0, Ease::In)]);+ let eased = Track::new(vec![key(0.0, 0.0, Ease::LINEAR), key(1.0, 1.0, Ease::IN)]);assert!(eased.value_at(0.5, 0.0) < 0.5);}@@ -182,16 +311,16 @@ mod tests {fn an_animation_is_relative_to_the_clip() {let animation = Animation {scale: Track::new(vec![- key(0.0, 0.5, Ease::Linear),- key(1.0, 1.0, Ease::Linear),+ key(0.0, 0.5, Ease::LINEAR),+ key(1.0, 1.0, Ease::LINEAR),]),offset_x: Track::new(vec![- key(0.0, 0.5, Ease::Linear),- key(1.0, 0.0, Ease::Linear),+ key(0.0, 0.5, Ease::LINEAR),+ key(1.0, 0.0, Ease::LINEAR),]),opacity: Track::new(vec![- key(0.0, 0.0, Ease::Linear),- key(0.5, 1.0, Ease::Linear),+ key(0.0, 0.0, Ease::LINEAR),+ key(0.5, 1.0, Ease::LINEAR),]),..Animation::default()};@@ -213,4 +342,60 @@ mod tests {assert!(!animation.is_empty());assert!(Animation::default().is_empty());}++ #[test]+ fn the_eases_bend_the_way_their_names_say() {+ // The endpoints are pinned whatever the control points are.+ for ease in [Ease::LINEAR, Ease::IN, Ease::OUT, Ease::IN_OUT] {+ assert!((ease.apply(0.0) - 0.0).abs() < 1e-6, "{ease:?} at 0");+ assert!((ease.apply(1.0) - 1.0).abs() < 1e-6, "{ease:?} at 1");+ }+ // Only the straight line is straight, and it costs no solve.+ assert!(Ease::LINEAR.is_linear());+ assert_eq!(Ease::LINEAR.apply(0.37), 0.37);+ assert!(!Ease::IN.is_linear());++ // In starts slow, out starts fast, and in-out is symmetric about+ // the middle.+ assert!(Ease::IN.apply(0.5) < 0.5);+ assert!(Ease::OUT.apply(0.5) > 0.5);+ assert!((Ease::IN_OUT.apply(0.5) - 0.5).abs() < 1e-6);+ assert!(Ease::IN_OUT.apply(0.25) < 0.25);+ assert!(Ease::IN_OUT.apply(0.75) > 0.75);++ // Out of range is held, not extrapolated.+ assert_eq!(Ease::IN.apply(-1.0), 0.0);+ assert_eq!(Ease::IN.apply(2.0), 1.0);+ }++ #[test]+ fn resampling_follows_the_curve_it_flattens() {+ let track = Track::new(vec![+ key(0.0, 0.0, Ease::LINEAR),+ key(1.0, 4.0, Ease::IN_OUT),+ ]);+ let flat = track.resample(12);++ // Every segment of the flattened ride is straight, so a caller that+ // can only lerp - the mixer's filtergraph - reads it correctly.+ assert!(flat.keys().iter().all(|key| key.ease.is_linear()));+ assert!(flat.keys().len() > track.keys().len());++ // And it is the same ride, to a few thousandths of its range -+ // which on a gain ramp is a hundredth of a decibel.+ let range = 4.0;+ for step in 0..=40 {+ let x = f64::from(step) / 40.0;+ let error = (flat.value_at(x, 0.0) - track.value_at(x, 0.0)).abs();+ assert!(error < range * 0.005, "at {x}: off by {error}");+ }++ // A ride with nothing to flatten is handed back untouched, so the+ // common case costs neither keys nor expression length.+ let straight = Track::new(vec![+ key(0.0, 0.0, Ease::LINEAR),+ key(1.0, 1.0, Ease::LINEAR),+ ]);+ assert_eq!(straight.resample(12), straight);+ }}diff --git a/engine/crates/concat-export/src/flatten.rs b/engine/crates/concat-export/src/flatten.rsindex e458e694..04cacff6 100644--- a/engine/crates/concat-export/src/flatten.rs+++ b/engine/crates/concat-export/src/flatten.rs@@ -15,7 +15,7 @@use std::path::Path;-use concat_project::model::{ClipKind as ModelClipKind, Project, Timeline};+use concat_project::model::{ClipKind as ModelClipKind, KeyProperty, Project, Timeline};use crate::chains::{audio_filter_chain, video_effect_chain};use crate::{ClipKind, ExportClip, ExportKey, TransitionSpec};@@ -116,7 +116,7 @@ pub fn flatten_timeline_in(track: index,hidden: !track.visible,muted: track.muted || clip.muted == Some(true),- volume: clip.volume,+ volume: export_base(clip, KeyProperty::Volume),fade_in: clip.fade_in,fade_out: clip.fade_out,filter_chain: audio_filter_chain(&clip.filters),@@ -140,13 +140,13 @@ pub fn flatten_timeline_in(.map(|crop| [crop.left, crop.top, crop.right, crop.bottom]),effects: clip.video_effects.clone(),transition_chain: String::new(),- scale: clip.scale,- offset_x: clip.offset_x,- offset_y: clip.offset_y,- rotation: clip.rotation,+ scale: export_base(clip, KeyProperty::Scale),+ offset_x: export_base(clip, KeyProperty::OffsetX),+ offset_y: export_base(clip, KeyProperty::OffsetY),+ rotation: export_base(clip, KeyProperty::Rotation),stretch_x: clip.stretch_x,stretch_y: clip.stretch_y,- opacity: clip.opacity,+ opacity: export_base(clip, KeyProperty::Opacity),video_filter_chain: video_effect_chain(&clip.video_effects),// Passed through unconditionally: `resolve_transitions` is// the one adjacency judge (frame/2 tolerance). A fixed@@ -187,39 +187,79 @@ fn pick_timeline<'a>(project: &'a Project, timeline_id: Option<&str>) -> Option<.or_else(|| project.timelines.first())}-/// The clip's animation presets, materialised for its current length as-/// the keys the engine plays. See `concat_project::animation`.+/// The constant the engine should receive for a keyable property.+///+/// The clip's own, until that property is keyed - and then the *neutral*+/// value, because a keyed property's keys travel absolutely rather than as a+/// factor on this base. Absolute is not a preference: `Animation` multiplies+/// the base by the scale and opacity tracks, so a clip sitting at zero+/// opacity could never be keyed back up if its keys were relative to it.+///+/// Presets stay relative, which is what lets a Fade preset ride on top of a+/// hand-keyed opacity without either knowing about the other.+pub fn export_base(clip: &concat_project::model::Clip, property: KeyProperty) -> f64 {+ if !clip.is_keyed(property) {+ return clip.constant(property);+ }+ match property {+ // A factor's neutral is one; an addition's is zero.+ KeyProperty::Scale | KeyProperty::Opacity | KeyProperty::Volume => 1.0,+ KeyProperty::OffsetX | KeyProperty::OffsetY | KeyProperty::Rotation => 0.0,+ }+}++/// The keys the engine plays: the clip's own where it has them, and its+/// animation presets - materialised for its current length - everywhere it+/// does not. See `concat_project::animation`.+///+/// A property the user has keyed does not also get its preset's track. Two+/// sets of keys on one property is a question with no good answer, and the+/// hand-set ones are the ones someone will be looking at when they wonder+/// why the clip is not doing what they said.pub fn export_keys(clip: &concat_project::model::Clip) -> Vec<ExportKey> {- use concat_core::animate::Ease;- let Some(animation) = concat_project::animation::animation_of(clip) else {- return Vec::new();- };+ let presets = concat_project::animation::animation_of(clip);let mut out = Vec::new();- for (property, track) in [- ("scale", &animation.scale),- ("offsetX", &animation.offset_x),- ("offsetY", &animation.offset_y),- ("rotation", &animation.rotation),- ("opacity", &animation.opacity),- ] {- for key in track.keys() {- out.push(ExportKey {- property: property.to_owned(),++ for property in KeyProperty::ALL {+ if clip.is_keyed(property) {+ out.extend(clip.keys_on(property).map(|key| ExportKey {+ property: property.name().to_owned(),at: key.at,value: key.value,- ease: match key.ease {- Ease::Linear => "linear",- Ease::In => "in",- Ease::Out => "out",- Ease::InOut => "inOut",- }- .to_owned(),- });+ ease: key.ease.sane().0,+ }));+ continue;}+ // Gain has no presets to fall back on; the catalogue is picture only.+ let Some(animation) = presets.as_ref() else {+ continue;+ };+ let track = match property {+ KeyProperty::Scale => &animation.scale,+ KeyProperty::OffsetX => &animation.offset_x,+ KeyProperty::OffsetY => &animation.offset_y,+ KeyProperty::Rotation => &animation.rotation,+ KeyProperty::Opacity => &animation.opacity,+ KeyProperty::Volume => continue,+ };+ out.extend(track.keys().iter().map(|key| ExportKey {+ property: property.name().to_owned(),+ at: key.at,+ value: key.value,+ ease: [key.ease.x1, key.ease.y1, key.ease.x2, key.ease.y2],+ }));}out}+/// The clip's gain over its length, as `(fraction, gain)` pairs, or empty+/// for a clip whose gain is the one number in `ExportClip::volume`.+pub fn volume_curve(clip: &concat_project::model::Clip) -> Vec<(f64, f64)> {+ clip.keys_on(KeyProperty::Volume)+ .map(|key| (key.at, key.value))+ .collect()+}+#[cfg(test)]mod tests {use std::collections::BTreeMap;diff --git a/engine/crates/concat-export/src/lib.rs b/engine/crates/concat-export/src/lib.rsindex 504086cf..e16b17c1 100644--- a/engine/crates/concat-export/src/lib.rs+++ b/engine/crates/concat-export/src/lib.rs@@ -28,7 +28,7 @@ use std::path::{Path, PathBuf};use std::sync::atomic::{AtomicBool, Ordering};use concat_core::SpeedCurve;-use concat_core::animate::Animation;+use concat_core::animate::{Animation, Ease as AnimEase, Key as AnimKey, Track as AnimTrack};use concat_core::frame::Frame;use concat_core::shader::ShaderPass;use concat_core::time::{FrameRate, Rational};@@ -201,16 +201,24 @@ pub struct ExportClip {#[derive(Deserialize, Clone, Debug, PartialEq)]#[serde(rename_all = "camelCase")]pub struct ExportKey {- /// "scale", "offsetX", "offsetY", "rotation" or "opacity".+ /// "scale", "offsetX", "offsetY", "rotation", "opacity" or "volume".pub property: String,/// Where in the clip, `0..=1`.pub at: f64,- /// The value there, relative to the clip's own; see the engine's- /// `animate` module.+ /// The value there. Relative to the clip's own for a key that came+ /// from an animation preset, and absolute for one the user set - which+ /// is the same thing, because `flatten::export_base` hands the engine a+ /// neutral constant for every property the user has keyed.pub value: f64,- /// "linear", "in", "out" or "inOut".- #[serde(default)]- pub ease: String,+ /// The timing function into this key, as a CSS cubic-bezier's two+ /// control points: `[x1, y1, x2, y2]`. Absent is a straight line.+ #[serde(default = "linear_ease")]+ pub ease: [f64; 4],+}++/// A straight line, for a spec that names no easing.+fn linear_ease() -> [f64; 4] {+ [0.0, 0.0, 1.0, 1.0]}/// A transition on the cut into a clip.@@ -508,6 +516,64 @@ pub fn render(request: &ExportRequest, mut reporter: Reporter<'_>) -> Result<Strresult.map(|()| output.to_string_lossy().into_owned())}+/// The clip's gain track, or an empty one when its gain is the single number+/// in `ExportClip::volume`.+fn volume_track(clip: &ExportClip) -> AnimTrack {+ animation_of(&clip.animation)+ .map(|animation| animation.volume)+ .unwrap_or_default()+}++/// A gain track re-expressed against a piece covering `[x0, x1]` of the clip.+///+/// A piece has its own clock starting at zero, so a key three-quarters of+/// the way through the clip is nowhere near three-quarters of the way+/// through the piece that holds it. The ends are pinned to what the whole+/// track is worth there, which is what carries a ramp that started in an+/// earlier piece into this one.+fn track_slice(track: &AnimTrack, x0: f64, x1: f64) -> AnimTrack {+ if track.is_empty() {+ return AnimTrack::default();+ }+ let span = x1 - x0;+ if span <= 0.0 {+ return AnimTrack::new(vec![AnimKey {+ at: 0.0,+ value: track.value_at(x0, 1.0),+ ease: AnimEase::LINEAR,+ }]);+ }+ let mut keys = vec![AnimKey {+ at: 0.0,+ value: track.value_at(x0, 1.0),+ ease: AnimEase::LINEAR,+ }];+ keys.extend(+ track+ .keys()+ .iter()+ .filter(|key| key.at > x0 && key.at < x1)+ .map(|key| AnimKey {+ at: (key.at - x0) / span,+ value: key.value,+ ease: key.ease,+ }),+ );+ // The ease of whichever segment this end falls inside, so a ramp that+ // crosses the boundary keeps its shape rather than going linear at it.+ let closing = track+ .keys()+ .iter()+ .find(|key| key.at >= x1)+ .map_or(AnimEase::LINEAR, |key| key.ease);+ keys.push(AnimKey {+ at: 1.0,+ value: track.value_at(x1, 1.0),+ ease: closing,+ });+ AnimTrack::new(keys)+}+/// The engine's view of one audible clip - or several, when its speed/// changes over it. Sound can only change tempo in steps, so a curve is cut/// into pieces of constant rate, each at the mean of its stretch of the@@ -523,6 +589,7 @@ pub fn audio_pieces(clip: &ExportClip) -> Vec<AudioClip> {format!("areverse,{chain}")};}+ let track = volume_track(clip);let Some(curve) = SpeedCurve::new(&clip.speed_curve) else {return vec![AudioClip {path: PathBuf::from(&clip.path),@@ -532,6 +599,7 @@ pub fn audio_pieces(clip: &ExportClip) -> Vec<AudioClip> {speed: audio::clamp_speed(clip.speed),preserve_pitch: clip.preserve_pitch,volume: clip.volume,+ volume_curve: track,fade_in: clip.fade_in,fade_out: clip.fade_out,filter_chain: chain,@@ -568,6 +636,7 @@ pub fn audio_pieces(clip: &ExportClip) -> Vec<AudioClip> {speed: audio::clamp_speed(mean),preserve_pitch: clip.preserve_pitch,volume: clip.volume,+ volume_curve: track_slice(&track, x0, x1),fade_in: if clip.fade_in > 0.0 { fade_in } else { 0.0 },fade_out: if clip.fade_out > 0.0 { fade_out } else { 0.0 },filter_chain: chain.clone(),@@ -1198,7 +1267,7 @@ fn animation_of(keys: &[ExportKey]) -> Option<Animation> {if keys.is_empty() {return None;}- let mut tracks: [Vec<Key>; 5] = Default::default();+ let mut tracks: [Vec<Key>; 6] = Default::default();for key in keys {let slot = match key.property.as_str() {"scale" => 0,@@ -1206,26 +1275,24 @@ fn animation_of(keys: &[ExportKey]) -> Option<Animation> {"offsetY" => 2,"rotation" => 3,"opacity" => 4,+ "volume" => 5,_ => continue,};+ let [x1, y1, x2, y2] = key.ease;tracks[slot].push(Key {at: key.at,value: key.value,- ease: match key.ease.as_str() {- "in" => Ease::In,- "out" => Ease::Out,- "inOut" => Ease::InOut,- _ => Ease::Linear,- },+ ease: Ease::new(x1, y1, x2, y2),});}- let [scale, x, y, rotation, opacity] = tracks;+ let [scale, x, y, rotation, opacity, volume] = tracks;let animation = Animation {scale: Track::new(scale),offset_x: Track::new(x),offset_y: Track::new(y),rotation: Track::new(rotation),opacity: Track::new(opacity),+ volume: Track::new(volume),};(!animation.is_empty()).then_some(animation)}diff --git a/engine/crates/concat-host/src/playback.rs b/engine/crates/concat-host/src/playback.rsindex 57416cec..739bc0f8 100644--- a/engine/crates/concat-host/src/playback.rs+++ b/engine/crates/concat-host/src/playback.rs@@ -47,6 +47,7 @@ use std::path::{Path, PathBuf};use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};use std::sync::{Arc, Condvar, Mutex, mpsc};+use concat_core::animate::{Ease, Key, Track};use serde::Deserialize;/// Every clip is decoded to this rate; the callback resamples to the device.@@ -66,6 +67,28 @@ const DISK_CACHE_BUDGET: u64 = 2 * 1024 * 1024 * 1024;/// without letting a scrubbed trim fan out a dozen full-file decodes.const DECODE_WORKERS: usize = 2;+/// One key of a clip's gain ride, as a spec carries it.+///+/// The engine's `animate::Key` in a shape serde can read: the same three+/// facts, with the timing function as its four control-point numbers.+#[derive(Clone, Copy, Debug, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct GainKey {+ /// Where in the clip, `0..=1`.+ pub at: f64,+ /// Absolute linear gain there.+ pub gain: f64,+ /// The timing function into this key: a cubic bezier's two control+ /// points, `[x1, y1, x2, y2]`. Absent is a straight line.+ #[serde(default = "linear_ease")]+ pub ease: [f64; 4],+}++/// A straight line, for a spec that names no easing.+fn linear_ease() -> [f64; 4] {+ [0.0, 0.0, 1.0, 1.0]+}+/// One audible clip, as the window describes it.#[derive(Clone, Debug, Deserialize)]#[serde(rename_all = "camelCase")]@@ -78,8 +101,13 @@ pub struct ClipSpec {pub duration: f64,/// Seconds into the source file.pub source_start: f64,- /// Linear gain.+ /// Linear gain. The whole clip's, unless `volume_curve` says otherwise.pub volume: f32,+ /// Gain as it changes over the clip, or empty for the constant above.+ /// A curve supersedes `volume` rather than multiplying it, matching the+ /// mixer - see `concat_media::audio::AudioClip`.+ #[serde(default)]+ pub volume_curve: Vec<GainKey>,/// Fade-in length in seconds.pub fade_in: f64,/// Fade-out length in seconds.@@ -191,17 +219,47 @@ struct ActiveClip {start: f64,duration: f64,volume: f32,+ /// The gain ride, or empty for the constant in `volume`.+ volume_curve: Track,fade_in: f64,fade_out: f64,pcm: Arc<Pcm>,}+/// A spec's gain keys as the engine's track.+fn track_of(keys: &[GainKey]) -> Track {+ Track::new(+ keys.iter()+ .map(|key| {+ let [x1, y1, x2, y2] = key.ease;+ Key {+ at: key.at,+ value: key.gain,+ ease: Ease::new(x1, y1, x2, y2),+ }+ })+ .collect(),+ )+}+/// The one definition of a clip's gain envelope.fn gain_at(clip: &ActiveClip, local: f64) -> f32 {if local < 0.0 || local > clip.duration {return 0.0;}- let mut gain = f64::from(clip.volume);+ // The ride, where there is one, replaces the constant - the same+ // precedence the mixer's filtergraph gives it, so the window and the+ // file agree about how loud the clip is at every instant.+ let mut gain = if clip.volume_curve.is_empty() {+ f64::from(clip.volume)+ } else {+ let x = if clip.duration > 0.0 {+ (local / clip.duration).clamp(0.0, 1.0)+ } else {+ 0.0+ };+ clip.volume_curve.value_at(x, f64::from(clip.volume))+ };if clip.fade_in > 0.0 {gain *= (local / clip.fade_in).min(1.0);}@@ -440,6 +498,7 @@ impl Playback {start: spec.start,duration: spec.duration,volume: spec.volume,+ volume_curve: track_of(&spec.volume_curve),fade_in: spec.fade_in,fade_out: spec.fade_out,pcm: Arc::clone(&entry.pcm),diff --git a/engine/crates/concat-media/src/audio.rs b/engine/crates/concat-media/src/audio.rsindex cdd227ca..c63777e4 100644--- a/engine/crates/concat-media/src/audio.rs+++ b/engine/crates/concat-media/src/audio.rs@@ -14,6 +14,7 @@use std::path::Path;+use concat_core::animate::Track;use ffmpeg_the_third as ffmpeg;use ffmpeg_the_third::codec::encoder;use ffmpeg_the_third::filter;@@ -52,8 +53,17 @@ pub struct AudioClip {pub speed: f64,/// True holds pitch while the rate changes; false is the tape effect.pub preserve_pitch: bool,- /// Linear gain, one being unity.+ /// Linear gain, one being unity. The whole clip's, unless+ /// `volume_curve` says otherwise.pub volume: f64,+ /// Gain as it changes over the clip, in absolute linear gain against a+ /// fraction of the clip's timeline length. Empty is the constant in+ /// `volume`; a track supersedes it rather than multiplying it.+ ///+ /// The engine's own `Track` and not a list of pairs, so the ramp the+ /// mixer writes into the filtergraph and the ramp the monitor plays are+ /// read from one definition, easing included.+ pub volume_curve: Track,/// Fade up over this many seconds from the clip's start.pub fade_in: f64,/// Fade out over this many seconds into the clip's end.@@ -62,6 +72,69 @@ pub struct AudioClip {pub filter_chain: String,}+/// An FFmpeg `volume` expression for a gain that changes over a clip, or+/// Straight segments per eased one, when a gain ride is flattened for the+/// filtergraph.+///+/// A chord's error against the curve it cuts falls as the square of the+/// step count. Twelve puts the worst case on a full-span ease-in-out at a+/// few thousandths of the ride's range - about 0.03 dB on a gain ramp, which+/// is an order of magnitude under what anyone can hear - and keeps the+/// expression to a few hundred characters per key. Doubling it would buy+/// four times the accuracy nobody can hear, at twice the length.+const EASE_STEPS: usize = 12;++/// None when the track is empty and the scalar gain will do.+///+/// The shape is `Track::value_at` written out: hold the first key's value+/// before it, hold the last key's after it, and run straight between+/// neighbours. Nested `if`s rather than anything cleverer, because that is+/// what the expression language has.+///+/// Straight, and never eased, because an ease is a cubic bezier and solving+/// one for y at a given x takes a loop the expression language does not+/// have. `Track::resample` turns each eased segment into `EASE_STEPS`+/// straight ones through the same curve first, so the easing is applied in+/// the one place that understands it and this only ever writes lines.+///+/// `t` inside the graph is seconds from the clip's own start - the same+/// clock `afade`'s `st=` uses two filters later - so the fraction the track+/// is indexed by is `t / duration`.+fn volume_expr(track: &Track, duration: f64) -> Option<String> {+ let flat = track.resample(EASE_STEPS);+ let keys = flat.keys();+ let first = keys.first()?;+ if duration <= 0.0 {+ return Some(format!("{:.6}", first.value.max(0.0)));+ }+ let gain = |value: f64| format!("{:.6}", value.max(0.0));+ let x = format!("(t/{duration:.6})");++ // From the tail back: each step wraps what it has in "before this key,+ // ride this segment".+ let mut expr = gain(keys[keys.len() - 1].value);+ for pair in keys.windows(2).rev() {+ let (a, b) = (pair[0], pair[1]);+ let span = b.at - a.at;+ let segment = if span <= 0.0 {+ gain(b.value)+ } else {+ format!(+ "({}+({})*clip(({x}-{:.6})/{span:.6},0,1))",+ gain(a.value),+ format_args!("{:.6}", b.value.max(0.0) - a.value.max(0.0)),+ a.at+ )+ };+ expr = format!("if(lte({x},{:.6}),{segment},{expr})", b.at);+ }+ Some(format!(+ "if(lte({x},{:.6}),{},{expr})",+ first.at,+ gain(first.value)+ ))+}+/// Refuses a filter chain that could break out of its slot in the graph.////// A chain is spliced into a filtergraph, where `;` starts a new chain and@@ -164,8 +237,15 @@ pub fn mix_graph(clips: &[AudioClip], duration: f64) -> Result<String> {stage.push_str(&clip.filter_chain);}- if (clip.volume - 1.0).abs() > f64::EPSILON {- stage.push_str(&format!(",volume={:.4}", clip.volume.max(0.0)));+ match volume_expr(&clip.volume_curve, clip.duration) {+ // `eval=frame` is what makes the expression a curve rather than+ // a number: without it `volume` evaluates once, at init, and a+ // ride would come out as whatever the gain was at t=0.+ Some(expr) => stage.push_str(&format!(",volume=volume='{expr}':eval=frame")),+ None if (clip.volume - 1.0).abs() > f64::EPSILON => {+ stage.push_str(&format!(",volume={:.4}", clip.volume.max(0.0)));+ }+ None => {}}if clip.fade_in > 0.0 {stage.push_str(&format!(",afade=t=in:st=0:d={:.4}", clip.fade_in));@@ -640,6 +720,7 @@ mod tests {speed: 1.0,preserve_pitch: true,volume: 1.0,+ volume_curve: Track::default(),fade_in: 0.0,fade_out: 0.0,filter_chain: String::new(),diff --git a/engine/crates/concat-project/src/animation.rs b/engine/crates/concat-project/src/animation.rsindex 75c2660a..32fb8232 100644--- a/engine/crates/concat-project/src/animation.rs+++ b/engine/crates/concat-project/src/animation.rs@@ -37,53 +37,53 @@ const IN: &[Shape] = &[Shape {name: "Fade",keys: &[- (Opacity, 0.0, 0.0, Ease::Linear),- (Opacity, 1.0, 1.0, Ease::Out),+ (Opacity, 0.0, 0.0, Ease::LINEAR),+ (Opacity, 1.0, 1.0, Ease::OUT),],},Shape {name: "Zoom In",keys: &[- (Scale, 0.0, 0.5, Ease::Linear),- (Scale, 1.0, 1.0, Ease::Out),- (Opacity, 0.0, 0.0, Ease::Linear),- (Opacity, 1.0, 1.0, Ease::Out),+ (Scale, 0.0, 0.5, Ease::LINEAR),+ (Scale, 1.0, 1.0, Ease::OUT),+ (Opacity, 0.0, 0.0, Ease::LINEAR),+ (Opacity, 1.0, 1.0, Ease::OUT),],},Shape {name: "Zoom Out",keys: &[- (Scale, 0.0, 1.6, Ease::Linear),- (Scale, 1.0, 1.0, Ease::Out),- (Opacity, 0.0, 0.0, Ease::Linear),- (Opacity, 1.0, 1.0, Ease::Out),+ (Scale, 0.0, 1.6, Ease::LINEAR),+ (Scale, 1.0, 1.0, Ease::OUT),+ (Opacity, 0.0, 0.0, Ease::LINEAR),+ (Opacity, 1.0, 1.0, Ease::OUT),],},Shape {name: "Slide Up",- keys: &[(Y, 0.0, 0.6, Ease::Linear), (Y, 1.0, 0.0, Ease::Out)],+ keys: &[(Y, 0.0, 0.6, Ease::LINEAR), (Y, 1.0, 0.0, Ease::OUT)],},Shape {name: "Slide Down",- keys: &[(Y, 0.0, -0.6, Ease::Linear), (Y, 1.0, 0.0, Ease::Out)],+ keys: &[(Y, 0.0, -0.6, Ease::LINEAR), (Y, 1.0, 0.0, Ease::OUT)],},Shape {name: "Slide Left",- keys: &[(X, 0.0, 0.6, Ease::Linear), (X, 1.0, 0.0, Ease::Out)],+ keys: &[(X, 0.0, 0.6, Ease::LINEAR), (X, 1.0, 0.0, Ease::OUT)],},Shape {name: "Slide Right",- keys: &[(X, 0.0, -0.6, Ease::Linear), (X, 1.0, 0.0, Ease::Out)],+ keys: &[(X, 0.0, -0.6, Ease::LINEAR), (X, 1.0, 0.0, Ease::OUT)],},Shape {name: "Spin",keys: &[- (Rotation, 0.0, -180.0, Ease::Linear),- (Rotation, 1.0, 0.0, Ease::Out),- (Scale, 0.0, 0.3, Ease::Linear),- (Scale, 1.0, 1.0, Ease::Out),- (Opacity, 0.0, 0.0, Ease::Linear),- (Opacity, 1.0, 1.0, Ease::Out),+ (Rotation, 0.0, -180.0, Ease::LINEAR),+ (Rotation, 1.0, 0.0, Ease::OUT),+ (Scale, 0.0, 0.3, Ease::LINEAR),+ (Scale, 1.0, 1.0, Ease::OUT),+ (Opacity, 0.0, 0.0, Ease::LINEAR),+ (Opacity, 1.0, 1.0, Ease::OUT),],},];@@ -94,53 +94,53 @@ const OUT: &[Shape] = &[Shape {name: "Fade",keys: &[- (Opacity, 0.0, 1.0, Ease::Linear),- (Opacity, 1.0, 0.0, Ease::In),+ (Opacity, 0.0, 1.0, Ease::LINEAR),+ (Opacity, 1.0, 0.0, Ease::IN),],},Shape {name: "Zoom In",keys: &[- (Scale, 0.0, 1.0, Ease::Linear),- (Scale, 1.0, 1.6, Ease::In),- (Opacity, 0.0, 1.0, Ease::Linear),- (Opacity, 1.0, 0.0, Ease::In),+ (Scale, 0.0, 1.0, Ease::LINEAR),+ (Scale, 1.0, 1.6, Ease::IN),+ (Opacity, 0.0, 1.0, Ease::LINEAR),+ (Opacity, 1.0, 0.0, Ease::IN),],},Shape {name: "Zoom Out",keys: &[- (Scale, 0.0, 1.0, Ease::Linear),- (Scale, 1.0, 0.5, Ease::In),- (Opacity, 0.0, 1.0, Ease::Linear),- (Opacity, 1.0, 0.0, Ease::In),+ (Scale, 0.0, 1.0, Ease::LINEAR),+ (Scale, 1.0, 0.5, Ease::IN),+ (Opacity, 0.0, 1.0, Ease::LINEAR),+ (Opacity, 1.0, 0.0, Ease::IN),],},Shape {name: "Slide Up",- keys: &[(Y, 0.0, 0.0, Ease::Linear), (Y, 1.0, -0.6, Ease::In)],+ keys: &[(Y, 0.0, 0.0, Ease::LINEAR), (Y, 1.0, -0.6, Ease::IN)],},Shape {name: "Slide Down",- keys: &[(Y, 0.0, 0.0, Ease::Linear), (Y, 1.0, 0.6, Ease::In)],+ keys: &[(Y, 0.0, 0.0, Ease::LINEAR), (Y, 1.0, 0.6, Ease::IN)],},Shape {name: "Slide Left",- keys: &[(X, 0.0, 0.0, Ease::Linear), (X, 1.0, -0.6, Ease::In)],+ keys: &[(X, 0.0, 0.0, Ease::LINEAR), (X, 1.0, -0.6, Ease::IN)],},Shape {name: "Slide Right",- keys: &[(X, 0.0, 0.0, Ease::Linear), (X, 1.0, 0.6, Ease::In)],+ keys: &[(X, 0.0, 0.0, Ease::LINEAR), (X, 1.0, 0.6, Ease::IN)],},Shape {name: "Spin",keys: &[- (Rotation, 0.0, 0.0, Ease::Linear),- (Rotation, 1.0, 180.0, Ease::In),- (Scale, 0.0, 1.0, Ease::Linear),- (Scale, 1.0, 0.3, Ease::In),- (Opacity, 0.0, 1.0, Ease::Linear),- (Opacity, 1.0, 0.0, Ease::In),+ (Rotation, 0.0, 0.0, Ease::LINEAR),+ (Rotation, 1.0, 180.0, Ease::IN),+ (Scale, 0.0, 1.0, Ease::LINEAR),+ (Scale, 1.0, 0.3, Ease::IN),+ (Opacity, 0.0, 1.0, Ease::LINEAR),+ (Opacity, 1.0, 0.0, Ease::IN),],},];@@ -150,49 +150,49 @@ const COMBO: &[Shape] = &[Shape {name: "Pulse",keys: &[- (Scale, 0.0, 1.0, Ease::Linear),- (Scale, 0.5, 1.08, Ease::InOut),- (Scale, 1.0, 1.0, Ease::InOut),+ (Scale, 0.0, 1.0, Ease::LINEAR),+ (Scale, 0.5, 1.08, Ease::IN_OUT),+ (Scale, 1.0, 1.0, Ease::IN_OUT),],},Shape {name: "Shake",keys: &[- (X, 0.0, 0.0, Ease::Linear),- (X, 0.1, 0.02, Ease::Linear),- (X, 0.2, -0.02, Ease::Linear),- (X, 0.3, 0.02, Ease::Linear),- (X, 0.4, -0.02, Ease::Linear),- (X, 0.5, 0.02, Ease::Linear),- (X, 0.6, -0.02, Ease::Linear),- (X, 0.7, 0.02, Ease::Linear),- (X, 0.8, -0.02, Ease::Linear),- (X, 0.9, 0.02, Ease::Linear),- (X, 1.0, 0.0, Ease::Linear),+ (X, 0.0, 0.0, Ease::LINEAR),+ (X, 0.1, 0.02, Ease::LINEAR),+ (X, 0.2, -0.02, Ease::LINEAR),+ (X, 0.3, 0.02, Ease::LINEAR),+ (X, 0.4, -0.02, Ease::LINEAR),+ (X, 0.5, 0.02, Ease::LINEAR),+ (X, 0.6, -0.02, Ease::LINEAR),+ (X, 0.7, 0.02, Ease::LINEAR),+ (X, 0.8, -0.02, Ease::LINEAR),+ (X, 0.9, 0.02, Ease::LINEAR),+ (X, 1.0, 0.0, Ease::LINEAR),],},Shape {name: "Spin",keys: &[- (Rotation, 0.0, 0.0, Ease::Linear),- (Rotation, 1.0, 360.0, Ease::Linear),+ (Rotation, 0.0, 0.0, Ease::LINEAR),+ (Rotation, 1.0, 360.0, Ease::LINEAR),],},Shape {name: "Bounce",keys: &[- (Y, 0.0, 0.0, Ease::Linear),- (Y, 0.25, -0.06, Ease::Out),- (Y, 0.5, 0.0, Ease::In),- (Y, 0.75, -0.03, Ease::Out),- (Y, 1.0, 0.0, Ease::In),+ (Y, 0.0, 0.0, Ease::LINEAR),+ (Y, 0.25, -0.06, Ease::OUT),+ (Y, 0.5, 0.0, Ease::IN),+ (Y, 0.75, -0.03, Ease::OUT),+ (Y, 1.0, 0.0, Ease::IN),],},Shape {name: "Drift",keys: &[- (Scale, 0.0, 1.0, Ease::Linear),- (Scale, 1.0, 1.12, Ease::Linear),+ (Scale, 0.0, 1.0, Ease::LINEAR),+ (Scale, 1.0, 1.12, Ease::LINEAR),],},];@@ -275,6 +275,11 @@ pub fn animation_of(clip: &Clip) -> Option<Animation> {offset_y: Track::new(y),rotation: Track::new(rotation),opacity: Track::new(opacity),+ // Presets are picture only: no shape in the catalogue touches gain,+ // and a preset that silently rode the fader would be a surprise. A+ // keyed volume comes from the clip's own keys instead - see+ // `concat_export::flatten::export_keys`.+ volume: Track::default(),})}diff --git a/engine/crates/concat-project/src/commands.rs b/engine/crates/concat-project/src/commands.rsindex 61443435..c31ce4fc 100644--- a/engine/crates/concat-project/src/commands.rs+++ b/engine/crates/concat-project/src/commands.rs@@ -13,8 +13,8 @@ use serde::{Deserialize, Serialize};use crate::model::{AnimationSlot, AppliedFilter, Clip, ClipAnimation, ClipKind, Crop, CustomFont, Cutout,- CutoutMode, MediaItem, MediaKind, Project, SpeedPoint, Stroke, TextStyle, Timeline, Track,- Transition,+ CutoutMode, KeyEase, KeyProperty, MediaItem, MediaKind, Project, SpeedPoint, Stroke, TextStyle,+ Timeline, Track, Transition,};/// Fallback length for media whose container reports no duration.@@ -304,6 +304,41 @@ pub enum Command {/// The shape and its seconds, or None to take it off.animation: Option<ClipAnimation>,},+ /// Puts a key on one property at one point of a clip, replacing+ /// whichever key on that property was already within a hair of it.+ ///+ /// The value is the property's own - the number the inspector shows -+ /// not the relative factor the engine plays; see `model::ClipKey`.+ SetClipKey {+ /// The clip.+ clip_id: String,+ /// Which property is being keyed.+ property: KeyProperty,+ /// Where in the clip, `0..=1`.+ at: f64,+ /// The value there.+ value: f64,+ /// How the key is approached from the one before it.+ #[serde(default)]+ ease: KeyEase,+ },+ /// Takes the key at `at` off one property, if there is one there. The+ /// other half of the diamond: a filled diamond clicked is this.+ ClearClipKey {+ /// The clip.+ clip_id: String,+ /// Which property.+ property: KeyProperty,+ /// Where in the clip the key to remove sits, `0..=1`.+ at: f64,+ },+ /// Takes every key off one property, returning it to its constant.+ ClearClipKeys {+ /// The clip.+ clip_id: String,+ /// Which property.+ property: KeyProperty,+ },/// Sets or clears a picture's cutout: the mask that takes its/// background away. Tidied on the way in; see [`Cutout::tidy`].SetClipCutout {@@ -627,6 +662,7 @@ fn default_clip(id: String, track_id: String, media: &MediaItem, start: f64) ->animation_in: None,animation_out: None,animation_combo: None,+ keys: Vec::new(),flip_h: false,flip_v: false,blend: String::new(),@@ -971,6 +1007,7 @@ pub fn apply(animation_in: None,animation_out: None,animation_combo: None,+ keys: Vec::new(),flip_h: false,flip_v: false,blend: String::new(),@@ -1038,6 +1075,7 @@ pub fn apply(animation_in: None,animation_out: None,animation_combo: None,+ keys: Vec::new(),flip_h: false,flip_v: false,blend: String::new(),@@ -1354,6 +1392,69 @@ pub fn apply(})}+ Command::SetClipKey {+ clip_id,+ property,+ at,+ value,+ ease,+ } => {+ let timeline = project.active_mut();+ let Some(clip) = timeline.clip_mut(&clip_id) else {+ return Ok(Outcome::default());+ };+ if !at.is_finite() || !value.is_finite() {+ return Ok(Outcome::default());+ }+ // Clamped the way the field itself is, so a key can never hold a+ // value the constant would have been refused. The clamps are the+ // ones ClipPatch applies; keeping them here as well is what stops+ // a key being the back door round them.+ let value = match property {+ KeyProperty::Scale => value.clamp(MIN_SCALE, MAX_SCALE),+ KeyProperty::Opacity => value.clamp(0.0, 1.0),+ // No ceiling, matching ClipPatch: the level fader goes to+ // +24 dB because quiet material needs it, and a key is the+ // same value at a different instant.+ KeyProperty::Volume => value.max(0.0),+ KeyProperty::OffsetX | KeyProperty::OffsetY | KeyProperty::Rotation => value,+ };+ let before = clip.keys.clone();+ clip.set_key(property, at, value, ease);+ Ok(Outcome {+ created_id: None,+ applied: clip.keys != before,+ })+ }++ Command::ClearClipKey {+ clip_id,+ property,+ at,+ } => {+ let timeline = project.active_mut();+ let Some(clip) = timeline.clip_mut(&clip_id) else {+ return Ok(Outcome::default());+ };+ let applied = clip.clear_key(property, at);+ Ok(Outcome {+ created_id: None,+ applied,+ })+ }++ Command::ClearClipKeys { clip_id, property } => {+ let timeline = project.active_mut();+ let Some(clip) = timeline.clip_mut(&clip_id) else {+ return Ok(Outcome::default());+ };+ let applied = clip.clear_keys(property);+ Ok(Outcome {+ created_id: None,+ applied,+ })+ }+Command::SetClipSpeedCurve { clip_id, curve } => {let timeline = project.active_mut();let Some(clip) = timeline.clip_mut(&clip_id) else {diff --git a/engine/crates/concat-project/src/doc.rs b/engine/crates/concat-project/src/doc.rsindex 8f35cbea..745ddcfa 100644--- a/engine/crates/concat-project/src/doc.rs+++ b/engine/crates/concat-project/src/doc.rs@@ -22,8 +22,9 @@ use serde_json::{Map, Value, json};use crate::commands::{MAX_STRETCH, MIN_STRETCH};use crate::model::{- AppliedFilter, Clip, ClipAnimation, ClipKind, Crop, CustomFont, Cutout, MediaItem, MediaKind,- Project, SpeedPoint, TextAlign, TextStyle, Timeline, Track, Transition,+ AppliedFilter, Clip, ClipAnimation, ClipKey, ClipKind, Crop, CustomFont, Cutout, KeyEase,+ KeyProperty, MediaItem, MediaKind, Project, SpeedPoint, TextAlign, TextStyle, Timeline, Track,+ Transition,};/// Bumped only when a change cannot be absorbed by defaulting.@@ -236,6 +237,7 @@ fn read_clips(raw: Option<&Value>, tracks: &[Track], media: &[MediaItem]) -> Vecanimation_in: read_animation(entry.get("animationIn")),animation_out: read_animation(entry.get("animationOut")),animation_combo: read_animation(entry.get("animationCombo")),+ keys: read_keys(entry.get("keys")),flip_h: flag(entry.get("flipH"), false),flip_v: flag(entry.get("flipV"), false),blend: text(entry.get("blend"), ""),@@ -409,6 +411,58 @@ pub fn to_document(settings: &DocumentSettings, project: &Project) -> Value {Value::Object(document)}+/// The clip's own keys. Tolerant like everything else here: an entry naming+/// a property this build does not have, or sitting outside the clip, is+/// dropped rather than failing the load, and the survivors come back in the+/// order the model promises.+fn read_keys(raw: Option<&Value>) -> Vec<ClipKey> {+ let Some(entries) = raw.and_then(Value::as_array) else {+ return Vec::new();+ };+ let mut keys: Vec<ClipKey> = entries+ .iter()+ .filter_map(|entry| {+ let property = KeyProperty::from_name(entry.get("property")?.as_str()?)?;+ let at = number(entry.get("at"), -1.0);+ let value = number(entry.get("value"), f64::NAN);+ (0.0..=1.0).contains(&at)+ .then_some(ClipKey {+ property,+ at,+ value,+ ease: read_ease(entry.get("ease")),+ })+ .filter(|key| key.value.is_finite())+ })+ .collect();+ keys.sort_by(|a, b| {+ (a.property as u8)+ .cmp(&(b.property as u8))+ .then_with(|| a.at.total_cmp(&b.at))+ });+ keys+}++/// A key's easing, in either spelling.+///+/// Documents written before the curve editor name one of four shapes;+/// documents written since carry the four control-point numbers. Both are+/// read, and anything else is a straight line - the reader's standing rule+/// is that a hand-edited file degrades to something openable.+fn read_ease(value: Option<&Value>) -> KeyEase {+ match value {+ Some(Value::String(name)) => KeyEase::from_name(name),+ Some(Value::Array(points)) if points.len() == 4 => KeyEase([+ number(points.first(), 0.0),+ number(points.get(1), 0.0),+ number(points.get(2), 1.0),+ number(points.get(3), 1.0),+ ])+ .sane(),+ _ => KeyEase::LINEAR,+ }+}+/// A named animation on a slot, or None when the entry says nothing usable.fn read_animation(value: Option<&Value>) -> Option<ClipAnimation> {let value = value?;diff --git a/engine/crates/concat-project/src/lib.rs b/engine/crates/concat-project/src/lib.rsindex 07bad2a9..0e2ab305 100644--- a/engine/crates/concat-project/src/lib.rs+++ b/engine/crates/concat-project/src/lib.rs@@ -433,6 +433,44 @@ mod tests {assert_eq!(project.active().clips[0].video_effects[0].id, "sepia");}+ /// Keys were shipped with four named eases before the curve editor+ /// replaced them with control points. Both spellings have to load, or a+ /// project saved a week ago opens with its animation gone straight.+ #[test]+ fn a_key_reads_its_ease_named_or_numbered() {+ let document = json!({+ "name": "Keyed", "version": 1,+ "media": [{ "id": "m1", "path": "/a.mp4", "name": "a.mp4",+ "kind": "video", "duration": 10.0 }],+ "tracks": [{ "id": "T1", "name": "Track 1", "visible": true, "muted": false }],+ "clips": [{ "id": "c1", "trackId": "T1", "mediaId": "m1", "name": "a.mp4",+ "kind": "video", "start": 0.0, "duration": 10.0, "sourceStart": 0.0,+ "volume": 1.0, "fadeIn": 0.0, "fadeOut": 0.0, "scale": 1.0,+ "offsetX": 0.0, "offsetY": 0.0, "rotation": 0.0, "opacity": 1.0,+ "speed": 1.0, "preservePitch": true, "filters": [],+ "keys": [+ { "property": "opacity", "at": 0.0, "value": 0.0, "ease": "inOut" },+ { "property": "opacity", "at": 0.5, "value": 1.0,+ "ease": [0.1, 0.2, 0.3, 0.4] },+ { "property": "opacity", "at": 1.0, "value": 0.5 },+ { "property": "opacity", "at": 9.0, "value": 1.0 },+ { "property": "nonesuch", "at": 0.2, "value": 1.0 }+ ] }]+ });+ let editor = Editor::from_document(&document).expect("loads");+ let keys = &editor.project().active().clips[0].keys;++ // The out-of-range key and the one naming an unknown property are+ // dropped; the other three survive in order.+ assert_eq!(keys.len(), 3);+ assert!(keys.windows(2).all(|pair| pair[0].at <= pair[1].at));++ assert_eq!(keys[0].ease, crate::model::KeyEase::IN_OUT);+ assert_eq!(keys[1].ease, crate::model::KeyEase([0.1, 0.2, 0.3, 0.4]));+ // Absent is a straight line, not a refusal to load.+ assert_eq!(keys[2].ease, crate::model::KeyEase::LINEAR);+ }+#[test]fn a_legacy_flat_document_loads_as_one_timeline() {let document = json!({diff --git a/engine/crates/concat-project/src/model.rs b/engine/crates/concat-project/src/model.rsindex 53be8192..b5587db5 100644--- a/engine/crates/concat-project/src/model.rs+++ b/engine/crates/concat-project/src/model.rs@@ -318,6 +318,181 @@ pub struct ClipAnimation {pub duration: f64,}+/// Which property a user-set key belongs to.+///+/// Five of the six are the picture's; the sixth is the mix's. They are one+/// enum because a key is a key - the panel that sets them, the commands that+/// carry them and the document that stores them do not care which side of+/// the clip a value ends up on, and only the thing that finally reads them+/// does.+#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub enum KeyProperty {+ /// `Clip::scale`.+ Scale,+ /// `Clip::offset_x`.+ OffsetX,+ /// `Clip::offset_y`.+ OffsetY,+ /// `Clip::rotation`.+ Rotation,+ /// `Clip::opacity`.+ Opacity,+ /// `Clip::volume`.+ Volume,+}++impl KeyProperty {+ /// The name this property carries in a document and across the export+ /// boundary. Matches the `ExportKey::property` vocabulary.+ pub fn name(self) -> &'static str {+ match self {+ KeyProperty::Scale => "scale",+ KeyProperty::OffsetX => "offsetX",+ KeyProperty::OffsetY => "offsetY",+ KeyProperty::Rotation => "rotation",+ KeyProperty::Opacity => "opacity",+ KeyProperty::Volume => "volume",+ }+ }++ /// The property of that name, or None.+ pub fn from_name(name: &str) -> Option<KeyProperty> {+ Some(match name {+ "scale" => KeyProperty::Scale,+ "offsetX" => KeyProperty::OffsetX,+ "offsetY" => KeyProperty::OffsetY,+ "rotation" => KeyProperty::Rotation,+ "opacity" => KeyProperty::Opacity,+ "volume" => KeyProperty::Volume,+ _ => return None,+ })+ }++ /// Every property that can be keyed, in the order a panel lists them.+ pub const ALL: [KeyProperty; 6] = [+ KeyProperty::Scale,+ KeyProperty::OffsetX,+ KeyProperty::OffsetY,+ KeyProperty::Rotation,+ KeyProperty::Opacity,+ KeyProperty::Volume,+ ];+}++/// How a key is approached from the one before it: a CSS timing function's+/// two control points, `[x1, y1, x2, y2]`.+///+/// The document's spelling of `concat_core::animate::Ease`, which is what it+/// becomes. Four numbers rather than a named shape because the curve editor+/// hands people a bezier to drag and the four named shapes are only its+/// preset chips - see `KeyEase::LINEAR` and friends.+///+/// Serialised as a bare array: `"ease": [0.42, 0, 0.58, 1]`. Documents+/// written before the curve editor spell it `"linear"` / `"in"` / `"out"` /+/// `"inOut"` instead, and `from_value` still reads those.+#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]+#[serde(transparent)]+pub struct KeyEase(pub [f64; 4]);++impl Default for KeyEase {+ fn default() -> Self {+ KeyEase::LINEAR+ }+}++impl KeyEase {+ /// A straight line.+ pub const LINEAR: KeyEase = KeyEase([0.0, 0.0, 1.0, 1.0]);+ /// Starts slow, arrives fast.+ pub const IN: KeyEase = KeyEase([0.42, 0.0, 1.0, 1.0]);+ /// Starts fast, arrives slow.+ pub const OUT: KeyEase = KeyEase([0.0, 0.0, 0.58, 1.0]);+ /// Slow at both ends.+ pub const IN_OUT: KeyEase = KeyEase([0.42, 0.0, 0.58, 1.0]);++ /// The four presets and what to call them, in the order the panel's+ /// chips sit in.+ pub const PRESETS: [(&'static str, KeyEase); 4] = [+ ("Linear", KeyEase::LINEAR),+ ("In", KeyEase::IN),+ ("Out", KeyEase::OUT),+ ("In · Out", KeyEase::IN_OUT),+ ];++ /// The ease named by a v1 document, or linear for a name this build has+ /// never heard of - a document naming something unknown should still+ /// open and still move.+ pub fn from_name(name: &str) -> KeyEase {+ match name {+ "in" => KeyEase::IN,+ "out" => KeyEase::OUT,+ "inOut" => KeyEase::IN_OUT,+ _ => KeyEase::LINEAR,+ }+ }++ /// The four numbers, with the two x values clamped where a legal timing+ /// function keeps them and anything unreadable falling back to linear.+ pub fn sane(self) -> KeyEase {+ let KeyEase([x1, y1, x2, y2]) = self;+ if ![x1, y1, x2, y2].iter().all(|n| n.is_finite()) {+ return KeyEase::LINEAR;+ }+ KeyEase([x1.clamp(0.0, 1.0), y1, x2.clamp(0.0, 1.0), y2])+ }++ /// Whether this is one of the presets, to within a hair. What lights a+ /// chip in the panel.+ pub fn is(self, other: KeyEase) -> bool {+ self.0+ .iter()+ .zip(other.0.iter())+ .all(|(a, b)| (a - b).abs() < 0.005)+ }+}++impl From<KeyEase> for concat_core::animate::Ease {+ /// The one conversion into what the engine plays. Sanitised on the way,+ /// so a hand-edited document cannot hand the solver an x outside `0..=1`+ /// - where a cubic bezier stops being a function of x and the Newton+ /// iteration stops converging.+ fn from(ease: KeyEase) -> Self {+ let KeyEase([x1, y1, x2, y2]) = ease.sane();+ concat_core::animate::Ease::new(x1, y1, x2, y2)+ }+}++/// One user-set key: a property, a point in the clip, and the value there.+///+/// The value is *absolute* - the number the inspector shows, in the+/// property's own units - and not the relative factor the engine's+/// `animate::Key` carries. Storing what the user typed is what keeps a key+/// meaning the same thing after the clip's own scale or gain is changed+/// underneath it; the conversion to relative happens on the way out, in+/// `concat_export::flatten::export_keys`.+#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]+#[serde(rename_all = "camelCase")]+pub struct ClipKey {+ /// Which property.+ pub property: KeyProperty,+ /// Where in the clip, as a fraction of its timeline length, `0..=1`.+ pub at: f64,+ /// The value there, in the property's own units.+ pub value: f64,+ /// How this key is approached from the previous one.+ #[serde(default)]+ pub ease: KeyEase,+}++/// How near two keys on one property have to be to count as the same key.+///+/// A fraction and not a duration, because that is what `at` is. Two+/// thousandths of a clip is under a frame for anything up to about twenty+/// seconds, which is the length where "the playhead is on that key" stops+/// being a question a user can answer by looking.+pub const KEY_EPSILON: f64 = 0.002;+/// One point of a speed curve.#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]#[serde(rename_all = "camelCase")]@@ -484,6 +659,15 @@ pub struct Clip {/// A shape over its whole length.#[serde(default, skip_serializing_if = "Option::is_none")]pub animation_combo: Option<ClipAnimation>,+ /// The user's own keys, sorted by property and then by `at`. Empty is a+ /// clip whose properties are the constants above.+ ///+ /// These sit *under* the animation presets rather than beside them: a+ /// keyed property's value replaces the constant the preset is relative+ /// to, so a clip can carry both a hand-keyed scale and a Fade preset+ /// without either having to know about the other.+ #[serde(default, skip_serializing_if = "Vec::is_empty")]+ pub keys: Vec<ClipKey>,/// Mirrored left to right.#[serde(default, skip_serializing_if = "is_false")]pub flip_h: bool,@@ -525,6 +709,139 @@ pub struct Clip {pub text: Option<TextStyle>,}+impl Clip {+ /// The clip's own constant for a keyable property - what the property is+ /// worth everywhere its track is silent.+ pub fn constant(&self, property: KeyProperty) -> f64 {+ match property {+ KeyProperty::Scale => self.scale,+ KeyProperty::OffsetX => self.offset_x,+ KeyProperty::OffsetY => self.offset_y,+ KeyProperty::Rotation => self.rotation,+ KeyProperty::Opacity => self.opacity,+ KeyProperty::Volume => self.volume,+ }+ }++ /// This property's keys, in order. Borrowed rather than collected: the+ /// caller is usually asking a question about them, not keeping them.+ pub fn keys_on(+ &self,+ property: KeyProperty,+ ) -> impl DoubleEndedIterator<Item = &ClipKey> + Clone {+ self.keys.iter().filter(move |key| key.property == property)+ }++ /// Whether this property is keyed at all. A property with keys is one+ /// the panel shows as animated, however few there are.+ pub fn is_keyed(&self, property: KeyProperty) -> bool {+ self.keys_on(property).next().is_some()+ }++ /// The index into `keys` of this property's key at `at`, within+ /// `KEY_EPSILON`, choosing the nearest when two are in reach.+ pub fn key_at(&self, property: KeyProperty, at: f64) -> Option<usize> {+ self.keys+ .iter()+ .enumerate()+ .filter(|(_, key)| key.property == property && (key.at - at).abs() <= KEY_EPSILON)+ .min_by(|(_, a), (_, b)| (a.at - at).abs().total_cmp(&(b.at - at).abs()))+ .map(|(index, _)| index)+ }++ /// This property's keys as the engine plays them.+ pub fn track_on(&self, property: KeyProperty) -> concat_core::animate::Track {+ concat_core::animate::Track::new(+ self.keys_on(property)+ .map(|key| concat_core::animate::Key {+ at: key.at,+ value: key.value,+ ease: key.ease.into(),+ })+ .collect(),+ )+ }++ /// What a property is worth at `at`: its ride where it is keyed, and its+ /// constant where it is not.+ ///+ /// The same arithmetic the engine does, which is what makes a key put on+ /// where the ride already is change nothing on screen - and what lets a+ /// panel show the live value under the playhead without asking the+ /// renderer.+ pub fn value_at(&self, property: KeyProperty, at: f64) -> f64 {+ let constant = self.constant(property);+ if !self.is_keyed(property) {+ return constant;+ }+ self.track_on(property).value_at(at, constant)+ }++ /// The nearest key strictly before `at`, and the nearest strictly after.+ /// What the panel's two chevrons move the playhead to; `None` on a side+ /// is that chevron greyed out.+ pub fn keys_around(&self, property: KeyProperty, at: f64) -> (Option<f64>, Option<f64>) {+ let mut before: Option<f64> = None;+ let mut after: Option<f64> = None;+ for key in self.keys_on(property) {+ if key.at < at - KEY_EPSILON {+ before = Some(before.map_or(key.at, |seen: f64| seen.max(key.at)));+ } else if key.at > at + KEY_EPSILON {+ after = Some(after.map_or(key.at, |seen: f64| seen.min(key.at)));+ }+ }+ (before, after)+ }++ /// Sets a key, replacing whichever key on that property was already+ /// within `KEY_EPSILON` of `at`. Keeps `keys` sorted by property and+ /// then by `at`, which is what lets everything else read them in order+ /// without sorting first.+ pub fn set_key(&mut self, property: KeyProperty, at: f64, value: f64, ease: KeyEase) {+ if !at.is_finite() || !value.is_finite() {+ return;+ }+ let at = at.clamp(0.0, 1.0);+ match self.key_at(property, at) {+ Some(index) => self.keys[index] = ClipKey { property, at, value, ease },+ None => self.keys.push(ClipKey { property, at, value, ease }),+ }+ self.sort_keys();+ }++ /// Removes this property's key at `at`, if there is one. True when a key+ /// actually went.+ pub fn clear_key(&mut self, property: KeyProperty, at: f64) -> bool {+ match self.key_at(property, at) {+ Some(index) => {+ self.keys.remove(index);+ true+ }+ None => false,+ }+ }++ /// Takes every key off one property. True when there were any.+ pub fn clear_keys(&mut self, property: KeyProperty) -> bool {+ let before = self.keys.len();+ self.keys.retain(|key| key.property != property);+ self.keys.len() != before+ }++ /// Drops keys that are not finite or not in `0..=1`, then orders them.+ /// Called by everything that can put a key in, including the document+ /// reader, so a hand-edited file cannot produce an unsorted track.+ pub fn sort_keys(&mut self) {+ self.keys+ .retain(|key| key.at.is_finite() && key.value.is_finite() && (0.0..=1.0).contains(&key.at));+ self.keys.sort_by(|a, b| {+ (a.property as u8)+ .cmp(&(b.property as u8))+ .then_with(|| a.at.total_cmp(&b.at))+ });+ }+}+/// One timeline: a name and its lanes and clips. Every operation takes the/// project and works on whichever timeline is active.#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]diff --git a/engine/crates/concat/src/format.rs b/engine/crates/concat/src/format.rsindex bbd570dc..17e5d11a 100644--- a/engine/crates/concat/src/format.rs+++ b/engine/crates/concat/src/format.rs@@ -7,52 +7,21 @@use crate::i18n::{t, tf};use crate::ui::Bezier;-/// x of a cubic bezier with endpoints pinned at 0 and 1, at parameter `t`.-fn bezier_axis(p1: f32, p2: f32, t: f32) -> f32 {- let u = 1.0 - t;- 3.0 * u * u * t * p1 + 3.0 * u * t * t * p2 + t * t * t-}--fn bezier_axis_slope(p1: f32, p2: f32, t: f32) -> f32 {- let u = 1.0 - t;- 3.0 * u * u * p1 + 6.0 * u * t * (p2 - p1) + 3.0 * t * t * (1.0 - p2)-}--/// Solve a CSS cubic-bezier for y at a given x: Newton first, bisection as the-/// fallback where the curve is flat enough that Newton stalls. This is the-/// computation Slint's expression language cannot express — it has no loops —-/// so the timing function is evaluated here and read back through a global.+/// Solve a CSS cubic-bezier for y at a given x. This is the computation+/// Slint's expression language cannot express — it has no loops — so the+/// timing function is evaluated here and read back through `Curves.ease`.+///+/// The solve itself lives in the engine, where a keyed property's easing is+/// applied on every frame. Two implementations of one curve is how a preview+/// comes to disagree with an export invisibly, so there is only the one.pub fn bezier_y_at_x(x1: f32, y1: f32, x2: f32, y2: f32, x: f32) -> f32 {- let x = x.clamp(0.0, 1.0);- let mut t = x;-- for _ in 0..8 {- let error = bezier_axis(x1, x2, t) - x;- if error.abs() < 1e-5 {- return bezier_axis(y1, y2, t);- }- let slope = bezier_axis_slope(x1, x2, t);- if slope.abs() < 1e-6 {- break;- }- t -= error / slope;- }-- let (mut lo, mut hi) = (0.0_f32, 1.0_f32);- t = x;- for _ in 0..24 {- let at = bezier_axis(x1, x2, t);- if (at - x).abs() < 1e-5 {- break;- }- if at > x {- hi = t;- } else {- lo = t;- }- t = (lo + hi) / 2.0;- }- bezier_axis(y1, y2, t)+ concat_core::animate::bezier_y_at_x(+ f64::from(x1),+ f64::from(y1),+ f64::from(x2),+ f64::from(y2),+ f64::from(x),+ ) as f32}/// hh:mm:ss:ff, non-drop-frame, the way the ruler and the tray spell adiff --git a/engine/crates/concat/src/lib.rs b/engine/crates/concat/src/lib.rsindex 01e364af..4c0e62f6 100644--- a/engine/crates/concat/src/lib.rs+++ b/engine/crates/concat/src/lib.rs@@ -64,7 +64,7 @@ pub fn run() -> Result<(), slint::PlatformError> {app.set_macos(platform::MACOS);let studio = Studio::new(host);- let dark = studio.prefs.dark.unwrap_or(false);+ let dark = studio.prefs.dark.unwrap_or(true);app.global::<Theme>().set_dark(dark);let shell = Rc::new(Shell {@@ -616,6 +616,39 @@ pub fn run() -> Result<(), slint::PlatformError> {));// ── the inspector ──+ // The keyframe cluster. Its own global, so a row deep in a panel does+ // not have to be threaded a callback to reach here.+ {+ let keys = app.global::<Keyframes>();+ keys.on_toggle(on_lanes!(|state, field: ClipField| {+ state.toggle_key(field);+ }));+ keys.on_step(on_lanes!(|state, field: ClipField, delta: i32| {+ state.step_key(field, delta);+ }));+ keys.on_clear(on_lanes!(|state, field: ClipField| {+ state.clear_keys_on(field);+ }));+ }++ // The effect libraries' search, shelves and stars. Rust does the+ // filtering, so the panel only reports what was pressed.+ {+ let library = app.global::<Library>();+ library.on_query_changed(on_window!(|state, shelf: i32, text: SharedString| {+ state.library_query(shelf, &text);+ }));+ library.on_group_changed(on_window!(|state, shelf: i32, index: i32| {+ state.library_group(shelf, index);+ }));+ library.on_favourites_changed(on_window!(|state, shelf: i32, on: bool| {+ state.library_favourites(shelf, on);+ }));+ library.on_favourite(on_window!(|state, id: SharedString, on: bool| {+ state.library_favourite(&id, on);+ }));+ }+editor.on_clip_set(on_lanes!(|state, field: ClipField, value: f32| {state.clip_set(field, value);}));diff --git a/engine/crates/concat/src/prefs.rs b/engine/crates/concat/src/prefs.rsindex fcee6d0d..07aedc13 100644--- a/engine/crates/concat/src/prefs.rs+++ b/engine/crates/concat/src/prefs.rs@@ -15,7 +15,7 @@ const FILE: &str = "settings.json";#[derive(Clone, Debug, Default, Serialize, Deserialize)]#[serde(default, rename_all = "camelCase")]pub struct Preferences {- /// The dark theme. `None` is the app's default, which is light.+ /// The dark theme. `None` is the app's default, which is dark.pub dark: Option<bool>,/// The chosen transcriber model id, e.g. "base.en".pub transcriber_model: Option<String>,@@ -27,6 +27,11 @@ pub struct Preferences {pub transcribe_language: Option<i32>,/// The interface's locale code ("de", "pt-BR", ...); absent is English.pub locale: Option<String>,+ /// Package ids starred in the effect libraries, in no order. One list+ /// across all three shelves: a star is a fact about a package, and which+ /// library it happens to be filed in is not part of it.+ #[serde(default)]+ pub favourites: Vec<String>,}impl Preferences {diff --git a/engine/crates/concat/src/studio.rs b/engine/crates/concat/src/studio.rsindex 203ff21a..251ac8ff 100644--- a/engine/crates/concat/src/studio.rs+++ b/engine/crates/concat/src/studio.rs@@ -125,6 +125,28 @@ pub const START_RATES: [(&str, i64, i64); 5] = [("60", 60, 1),];+/// What one effect library is showing: the words typed into it, the shelf+/// picked, and whether the star is down.+///+/// Held here rather than in the panel because the filtering is done here:+/// the model a library renders arrives already narrowed, which is what lets+/// it be laid out as a grid - a tile's place is its index, and an index only+/// means a place when every entry in the model is one that shows.+#[derive(Clone, Debug, Default)]+pub struct LibraryView {+ /// The search box's text.+ pub query: String,+ /// The chosen shelf, as an index into the kind's group list.+ pub group: i32,+ /// Only starred packages show, whatever shelf they are on.+ pub favourites: bool,+}++/// Which library a shelf index names. The numbers are the panel's own -+/// `PresetStack.shelf` - and the order the tabs sit in.+pub const SHELF_KINDS: [PackageKind; 3] =+ [PackageKind::Filter, PackageKind::Effect, PackageKind::Audio];+/// The transcriber's languages: the rows of the Auto / English / Chinese/// control in Settings > Transcriber, and the whisper code each means.pub const TRANSCRIBE_LANGUAGES: [&str; 3] = ["auto", "en", "zh"];@@ -581,6 +603,9 @@ pub fn sync<T: Clone + PartialEq + 'static>(model: &VecModel<T>, next: Vec<T>) {pub struct Studio {pub host: Host,pub prefs: Preferences,+ /// What each effect library is showing, indexed the way `SHELF_KINDS`+ /// is: 0 filters, 1 effects, 2 audio.+ pub library: [LibraryView; 3],// ── the edit ──pub session: Option<Session>,@@ -738,9 +763,14 @@ fn new_title_style() -> TextStyle {/// A label for a catalogue id: "black-white" reads as "Black White"./// One kind's shelves for the inspector: the shelf labels, in catalogue/// order, and every package on them with the index of its shelf.-fn shelves(kind: PackageKind) -> (Vec<SharedString>, Vec<CatalogueEntryData>) {+fn shelves(+ kind: PackageKind,+ view: &LibraryView,+ favourites: &[String],+) -> (Vec<SharedString>, Vec<CatalogueEntryData>) {let mut groups: Vec<String> = Vec::new();let mut entries = Vec::new();+ let query = view.query.trim().to_lowercase();for package in Catalogue::builtin().of_kind(kind) {let meta = &package.manifest.effect;// The colour panel's own package: every picture clip can carry it,@@ -762,12 +792,32 @@ fn shelves(kind: PackageKind) -> (Vec<SharedString>, Vec<CatalogueEntryData>) {groups.len() - 1}};+ // The shelves are built from every package and only the entries are+ // narrowed: a strip that lost a segment because a search matched+ // nothing on it would move under the pointer as you typed.+ let name = t(&meta.name);+ let description = t(&meta.description);+ let starred = favourites.iter().any(|held| held == &meta.id);+ let shown = if view.favourites {+ starred+ } else if !query.is_empty() {+ // Across every shelf while a query is live. Someone typing+ // "echo" wants the echo, not the echo that happens to be filed+ // where they were already looking.+ name.to_lowercase().contains(&query) || description.to_lowercase().contains(&query)+ } else {+ group as i32 == view.group+ };+ if !shown {+ continue;+ }entries.push(CatalogueEntryData {id: meta.id.as_str().into(),- name: t(&meta.name).into(),+ name: name.into(),category: t(&category).into(),group: group as i32,- description: t(&meta.description).into(),+ description: description.into(),+ favourite: starred,});}(@@ -845,6 +895,19 @@ fn commit_key(commands: &[Command]) -> String {.join(",")}+/// The field a keyable property is set through - the inverse of+/// `Studio::key_property_of`, for handing a row back to the panel.+fn key_field_of(property: model::KeyProperty) -> ClipField {+ match property {+ model::KeyProperty::Scale => ClipField::Scale,+ model::KeyProperty::OffsetX => ClipField::OffsetX,+ model::KeyProperty::OffsetY => ClipField::OffsetY,+ model::KeyProperty::Rotation => ClipField::Rotation,+ model::KeyProperty::Opacity => ClipField::Opacity,+ model::KeyProperty::Volume => ClipField::Volume,+ }+}+/// The menu row of a slot's animation: -1 for none.fn slot_index(slot: concat_project::model::AnimationSlot,@@ -1011,6 +1074,7 @@ impl Studio {let text_presets = presets::all(&host.dirs);let mut studio = Self {prefs,+ library: Default::default(),session: None,echo: None,empty: Project::new(),@@ -1365,6 +1429,16 @@ impl Studio {duration: piece.duration,source_start: piece.source_start,volume: piece.volume as f32,+ volume_curve: piece+ .volume_curve+ .keys()+ .iter()+ .map(|key| concat_host::playback::GainKey {+ at: key.at,+ gain: key.value,+ ease: [key.ease.x1, key.ease.y1, key.ease.x2, key.ease.y2],+ })+ .collect(),fade_in: piece.fade_in,fade_out: piece.fade_out,speed: piece.speed,@@ -4679,6 +4753,12 @@ impl Studio {});editor.set_selected_clip(self.selected());+ // The keyframe cluster's state, on its own global: every keyable row+ // in the inspector reads it, and none of them is threaded to.+ let keys = app.global::<Keyframes>();+ let rows = self.key_rows();+ keys.set_available(!rows.is_empty());+ keys.set_rows(slint::ModelRc::from(Rc::new(VecModel::from(rows))));editor.set_inspector_jump_token(self.inspector_jump.0);editor.set_inspector_jump_tab(self.inspector_jump.1.into());editor.set_inspector_jump_section(self.inspector_jump.2.into());@@ -4756,6 +4836,181 @@ impl Studio {);}+ // ── the effect libraries ──++ /// The view state of one library, or None for a shelf index the panel+ /// should never have sent.+ fn library_at(&mut self, shelf: i32) -> Option<&mut LibraryView> {+ self.library.get_mut(usize::try_from(shelf).ok()?)+ }++ /// The search box was typed in. A live query searches every shelf, so+ /// the strip is put away while one is running - see `shelves`.+ pub fn library_query(&mut self, shelf: i32, text: &str) {+ if let Some(view) = self.library_at(shelf) {+ view.query = text.to_owned();+ }+ }++ /// A shelf was picked. Typing and then picking a shelf means the shelf,+ /// so the query goes.+ pub fn library_group(&mut self, shelf: i32, index: i32) {+ if let Some(view) = self.library_at(shelf) {+ view.group = index.max(0);+ view.query.clear();+ view.favourites = false;+ }+ }++ /// The star chip. Turning it on clears the query for the same reason+ /// picking a shelf does: two filters at once is a list nobody can+ /// predict the contents of.+ pub fn library_favourites(&mut self, shelf: i32, on: bool) {+ if let Some(view) = self.library_at(shelf) {+ view.favourites = on;+ view.query.clear();+ }+ }++ /// Star or unstar a package, and remember it. Not per library: a star is+ /// a fact about the package.+ pub fn library_favourite(&mut self, id: &str, on: bool) {+ let held = self.prefs.favourites.iter().any(|held| held == id);+ if on && !held {+ self.prefs.favourites.push(id.to_owned());+ } else if !on && held {+ self.prefs.favourites.retain(|held| held != id);+ } else {+ return;+ }+ self.prefs.save(&self.host.dirs);+ }++ // ── keyframes ──++ /// The keyable property a field names, or None for a field that is a+ /// constant and stays one.+ pub fn key_property_of(field: ClipField) -> Option<model::KeyProperty> {+ Some(match field {+ ClipField::Scale => model::KeyProperty::Scale,+ ClipField::OffsetX => model::KeyProperty::OffsetX,+ ClipField::OffsetY => model::KeyProperty::OffsetY,+ ClipField::Rotation => model::KeyProperty::Rotation,+ ClipField::Opacity => model::KeyProperty::Opacity,+ ClipField::Volume => model::KeyProperty::Volume,+ _ => return None,+ })+ }++ /// The selected clip and where the playhead is inside it, `0..=1`, or+ /// None when there is no sole selection or the playhead is outside it.+ ///+ /// Outside is not clamped to an end: a key put on from outside the clip+ /// would land on its first or last frame, which is never what the person+ /// pressing the diamond meant.+ pub fn key_point(&self) -> Option<(&Clip, f64)> {+ let clip = self.sole_selection().and_then(|id| self.clip(&id))?;+ if clip.duration <= 0.0 {+ return None;+ }+ let local = f64::from(self.playhead) - clip.start;+ (0.0..=clip.duration)+ .contains(&local)+ .then(|| (clip, local / clip.duration))+ }++ /// The keyframe cluster's six rows, in the order the `Keyframes` global+ /// indexes them. Empty when nothing can be keyed, which is what greys+ /// every cluster in the inspector at once.+ pub fn key_rows(&self) -> Vec<ClipKeyData> {+ let Some((clip, at)) = self.key_point() else {+ return Vec::new();+ };+ model::KeyProperty::ALL+ .iter()+ .map(|&property| {+ let (prev, next) = clip.keys_around(property, at);+ ClipKeyData {+ field: key_field_of(property),+ keyed: clip.is_keyed(property),+ here: clip.key_at(property, at).is_some(),+ prev: prev.is_some(),+ next: next.is_some(),+ }+ })+ .collect()+ }++ /// Puts a key on the field at the playhead, or takes off the one there.+ ///+ /// The value a new key gets is whatever the property is worth at that+ /// instant - the constant on a clip with no keys, and the ride's own+ /// value on one that has them. That is what makes the diamond safe to+ /// press: it never moves the picture, it only says "hold this here".+ pub fn toggle_key(&mut self, field: ClipField) {+ let Some(property) = Self::key_property_of(field) else {+ return;+ };+ let Some((clip, at)) = self.key_point() else {+ return;+ };+ let clip_id = clip.id.clone();+ let command = if clip.key_at(property, at).is_some() {+ Command::ClearClipKey {+ clip_id,+ property,+ at,+ }+ } else {+ let value = clip.value_at(property, at);+ // The ease of whichever key this one is joining behind, so+ // laying a run of keys down does not alternate between shapes.+ // The first key on a property has nothing to inherit and gets+ // the straight line.+ let ease = clip+ .keys_on(property)+ .filter(|key| key.at < at)+ .next_back()+ .map_or(model::KeyEase::LINEAR, |key| key.ease);+ Command::SetClipKey {+ clip_id,+ property,+ at,+ value,+ ease,+ }+ };+ self.apply(command);+ }++ /// Takes every key off a field, leaving it its constant.+ pub fn clear_keys_on(&mut self, field: ClipField) {+ let Some(property) = Self::key_property_of(field) else {+ return;+ };+ let Some(clip_id) = self.sole_selection() else {+ return;+ };+ self.apply(Command::ClearClipKeys { clip_id, property });+ }++ /// Moves the playhead to this field's previous (-1) or next (+1) key.+ pub fn step_key(&mut self, field: ClipField, delta: i32) {+ let Some(property) = Self::key_property_of(field) else {+ return;+ };+ let Some((clip, at)) = self.key_point() else {+ return;+ };+ let (start, duration) = (clip.start, clip.duration);+ let (prev, next) = clip.keys_around(property, at);+ let Some(target) = (if delta < 0 { prev } else { next }) else {+ return;+ };+ self.seek((start + target * duration) as f32);+ }++/// The selection, flattened for the inspector: exactly one clip or/// nothing.fn selected(&self) -> SelectedClipData {@@ -4874,17 +5129,31 @@ impl Studio {words.set_lang(lang);}- // The catalogue's shelves. Built in, so they never change after- // start; `sync` makes republishing them a no-op.- let (groups, entries) = shelves(PackageKind::Effect);- sync(&models.effect_groups, groups);- sync(&models.catalogue_effects, entries);- let (groups, entries) = shelves(PackageKind::Filter);+ // The catalogue's shelves. The groups are built in and never change;+ // the entries are whatever each library's search, shelf and star let+ // through, so they are rebuilt here and `sync` makes an unchanged+ // one a no-op.+ let starred = &self.prefs.favourites;+ let (groups, entries) = shelves(SHELF_KINDS[0], &self.library[0], starred);sync(&models.filter_groups, groups);sync(&models.catalogue_filters, entries);- let (groups, entries) = shelves(PackageKind::Audio);+ let (groups, entries) = shelves(SHELF_KINDS[1], &self.library[1], starred);+ sync(&models.effect_groups, groups);+ sync(&models.catalogue_effects, entries);+ let (groups, entries) = shelves(SHELF_KINDS[2], &self.library[2], starred);sync(&models.audio_groups, groups);sync(&models.catalogue_audio, entries);+ app.global::<Library>()+ .set_views(slint::ModelRc::from(Rc::new(VecModel::from(+ self.library+ .iter()+ .map(|view| LibraryViewData {+ query: view.query.as_str().into(),+ group: view.group,+ favourites: view.favourites,+ })+ .collect::<Vec<_>>(),+ ))));app.set_on_start(self.on_start);app.set_project_name(self.project_name.as_str().into());diff --git a/engine/crates/concat/ui/app.slint b/engine/crates/concat/ui/app.slintindex dcb2cde9..a3f2182d 100644--- a/engine/crates/concat/ui/app.slint+++ b/engine/crates/concat/ui/app.slint@@ -33,27 +33,27 @@ import { PaneKind } from "workspace/pane-switcher.slint";import { RecentProjectData, StartData, StartScreen } from "start.slint";import { TitleBar } from "title-bar.slint";import {- AppliedEntryData, AppliedParamData, CatalogueEntryData,+ AppliedEntryData, AppliedParamData, CatalogueEntryData, Library, LibraryViewData,} from "inspector/clip-inspector.slint";import { ParamFormat } from "inspector/controls.slint";import { ToastData, ToastLayer } from "primitives/toast.slint";import { TooltipLayer } from "primitives/tooltip.slint";import { Workspace } from "workspace/workspace.slint";import {- ClipData, ClipField, ClipKind, ClipTextField, DropData, SelectedClipData,- StageGuideData, StageItemData, TextAlignment, TimelineTabData, TimelineTool,- TrackData, TrackSize,+ ClipData, ClipField, ClipKeyData, ClipKind, ClipTextField, DropData, Keyframes,+ SelectedClipData, StageGuideData, StageItemData, TextAlignment, TimelineTabData,+ TimelineTool, TrackData, TrackSize,} from "timeline/model.slint";// Re-exported so main.rs can reach the globals and the struct.export {Curves, Fmt, Payload, Theme, Bezier, Editor, I18n,- AppliedEntryData, AppliedParamData, CatalogueEntryData, ParamFormat,+ AppliedEntryData, AppliedParamData, CatalogueEntryData, Library, LibraryViewData, ParamFormat,DockDivider, DockSide, PaneKind, SeatBox,EffectData, MediaFilter, MediaItemData, MediaKind, TextPresetData,- ClipData, ClipField, ClipKind, ClipTextField, DropData, SelectedClipData,- StageGuideData, StageItemData, TextAlignment, TimelineTabData, TimelineTool,- TrackData, TrackSize, MenuItemData, MenuRow, ExportData, ExportPhase, ModelData, SettingsData,+ ClipData, ClipField, ClipKeyData, ClipKind, ClipTextField, DropData, Keyframes,+ SelectedClipData, StageGuideData, StageItemData, TextAlignment, TimelineTabData,+ TimelineTool, TrackData, TrackSize, MenuItemData, MenuRow, ExportData, ExportPhase, ModelData, SettingsData,RecentProjectData, StartData, SystemFactData, ToastData, ProjectSheetData,CaptionsSheetData, SpeechSheetData,}diff --git a/engine/crates/concat/ui/icons.slint b/engine/crates/concat/ui/icons.slintindex 218b4c5d..5e27e558 100644--- a/engine/crates/concat/ui/icons.slint+++ b/engine/crates/concat/ui/icons.slint@@ -46,6 +46,7 @@ export enum Glyph {close,check,chevron-down,+ chevron-left,chevron-right,sparkle,eye,@@ -55,6 +56,7 @@ export enum Glyph {flip-h,flip-v,keyframe,+ reset,angle,align-left,align-center-x,@@ -206,6 +208,11 @@ export component Icon inherits Rectangle {}// lucide/chevron-right+ if root.glyph == Glyph.chevron-left: Stroked {+ size: root.size; tint: root.tint; weight: root.weight;+ commands: "M15 18l-6-6 6-6";+ }+if root.glyph == Glyph.chevron-right: Stroked {size: root.size; tint: root.tint; weight: root.weight;commands: "M9 18l6-6-6-6";@@ -383,6 +390,12 @@ export component Icon inherits Rectangle {}// lucide/diamond+ // lucide's rotate-ccw: the arrow every panel means by "put it back".+ if root.glyph == Glyph.reset: Stroked {+ size: root.size; tint: root.tint; weight: root.weight;+ commands: "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8M3 3v5h5";+ }+if root.glyph == Glyph.keyframe: Stroked {size: root.size; tint: root.tint; weight: root.weight;fill: root.filled ? root.tint : Colors.transparent;diff --git a/engine/crates/concat/ui/inspector/clip-inspector.slint b/engine/crates/concat/ui/inspector/clip-inspector.slintindex 4a8e8bb7..91630cb1 100644--- a/engine/crates/concat/ui/inspector/clip-inspector.slint+++ b/engine/crates/concat/ui/inspector/clip-inspector.slint@@ -9,10 +9,10 @@ import { Button } from "../primitives/modal.slint";import { SegmentedControl } from "../primitives/segmented-control.slint";import { Select } from "../primitives/select.slint";import {- Fader, HelpButton, InspectorFmt, InspectorSearch, Note, Param, ParamFormat,- SearchField, Switch, SwitchRow,+ Fader, HelpButton, InspectorFmt, Note, Param, ParamFormat,+ Rail, ResetButton, SearchField, Switch, SwitchRow,} from "controls.slint";-import { ClipField, ClipKind, SelectedClipData } from "../timeline/model.slint";+import { ClipField, ClipKind, Keyframes, SelectedClipData } from "../timeline/model.slint";// The editor's clip inspector: one panel, three tabs. Adjust is direct// controls; Filters and Effects differ only in their catalogue, so both are@@ -27,12 +27,54 @@ import { ClipField, ClipKind, SelectedClipData } from "../timeline/model.slint";export struct CatalogueEntryData {id: string,name: string,+ /// Starred, so it shows under the star chip whatever shelf it is on.+ favourite: bool,/// The shelf's label, and its index into the kind's group list.category: string,group: int,description: string,}+/// What one effect library is currently showing.+export struct LibraryViewData {+ /// The words in its search box.+ query: string,+ /// Which shelf is selected, as an index into the kind's group list.+ group: int,+ /// The star is down: only favourites show, whatever shelf they are on.+ favourites: bool,+}++/// The three effect libraries' view state and the verbs that change it.+///+/// A global for the same reason `Keyframes` is one: the state belongs to+/// Rust - which does the searching, shelving and starring before the model+/// is published - and threading nine properties and four callbacks down+/// through the workspace to reach three sibling panels would be a lot of+/// plumbing for a fact that has one owner.+export global Library {+ /// One view per shelf, indexed by the numbers `PresetStack.shelf` uses:+ /// 0 filters, 1 effects, 2 audio.+ in property <[LibraryViewData]> views;++ /// The search box was typed in.+ callback query-changed(shelf: int, text: string);+ /// A shelf was picked from the strip.+ callback group-changed(shelf: int, index: int);+ /// The star chip was pressed.+ callback favourites-changed(shelf: int, on: bool);+ /// A package was starred or unstarred. Not per shelf: a star is a fact+ /// about the package, and it is remembered across sessions.+ callback favourite(id: string, on: bool);++ pure public function view(shelf: int) -> LibraryViewData {+ if (Library.views.length < 3) {+ return { query: "", group: 0, favourites: false };+ }+ return Library.views[shelf];+ }+}+/// One link of the selected clip's chain, in chain order.export struct AppliedEntryData {id: string,@@ -60,6 +102,36 @@ export struct AppliedParamData {fmt: ParamFormat,}+/// The favourites chip: a star that filters the shelf down to what is on it.+component StarChip inherits Rectangle {+ in property <bool> on;++ callback clicked();++ width: 30px;+ height: Theme.h;+ border-radius: Theme.r;+ border-width: 1px;+ border-color: root.on ? Theme.accent : Theme.line;+ background: root.on ? Theme.accent-soft+ : touch.has-hover ? Theme.field-hover+ : Theme.field;++ animate background, border-color { duration: 100ms; easing: cubic-bezier(0.4, 0, 0.2, 1); }++ Icon {+ glyph: Glyph.sparkle;+ size: 12px;+ filled: root.on;+ tint: root.on ? Theme.accent : Theme.fg-muted;+ }++ touch := TouchArea {+ mouse-cursor: pointer;+ clicked => { root.clicked(); }+ }+}+/// A chain and its library: the links applied to the selected clip, each/// with a control per parameter its package declares, and under it the/// shelves of packages that can be added. One component serves effects,@@ -75,6 +147,20 @@ export component PresetStack inherits VerticalLayout {in property <[AppliedEntryData]> applied;in property <[AppliedParamData]> params;+ /// Which of the three libraries this is: 0 filters, 1 effects, 2 audio.+ /// The index its view state and its callbacks are keyed by.+ in property <int> shelf;++ /// Which shelf is showing, which words are in the search box, and+ /// whether the star is down. Owned by Rust, because the list below is:+ /// the catalogue arrives already narrowed by all three, and a control+ /// showing one thing while the list shows another is the bug that+ /// arrangement is there to make impossible.+ property <LibraryViewData> view: Library.view(root.shelf);+ property <int> group: root.view.group;+ property <string> query: root.view.query;+ property <bool> favourites-only: root.view.favourites;+callback add(id: string);callback toggle(index: int);callback move-by(index: int, delta: int);@@ -83,14 +169,24 @@ export component PresetStack inherits VerticalLayout {callback set-param(index: int, key: string, value: float);callback commit();- property <int> group;- property <string> query;property <bool> help;- function shown(entry: CatalogueEntryData) -> bool {- return entry.group == root.group- && (root.query == "" || InspectorSearch.matches(entry.name, root.query));- }+ // The grid. Three columns at the inspector's width, which puts a tile at+ // about 70px - wide enough for "Voice Focus" on two lines and narrow+ // enough that a shelf of twenty is four rows rather than seven.+ property <int> columns: 3;+ property <length> pad: Theme.pad;+ property <length> cell-gap: 6px;+ property <length> cell-w: (root.width - 2 * root.pad+ - (root.columns - 1) * root.cell-gap) / root.columns;+ property <length> cell-h: 44px;+ property <int> rows: ceil(root.catalogue.length / root.columns);++ // The field owns its own text once it has been typed in - a TextInput+ // assigns to `text`, and an assignment replaces the binding declared on+ // it - so the box has to be put back by hand when Rust clears the query,+ // which picking a shelf and pressing the star both do.+ changed query => { search.text = root.query; }function in-chain(id: string) -> bool {// A real member test wants a model lookup Slint cannot express, so@@ -225,9 +321,10 @@ export component PresetStack inherits VerticalLayout {SectionHeader { title: root.library-title; }Row {- SearchField {- text <=> root.query;+ search := SearchField {+ text: root.query;placeholder: I18n.t1("Search {0}s", "\{root.noun}");+ edited(text) => { Library.query-changed(root.shelf, text); }}}@@ -235,76 +332,223 @@ export component PresetStack inherits VerticalLayout {// together read as one control, and they are not.Rectangle { height: 8px; }+ // The star and the shelves. Favourites is not one more shelf: it+ // cuts across all of them, so it is a chip beside the strip rather+ // than a segment inside it, and it takes the strip's place when it+ // is on because a shelf inside a starred set is a filter of a filter+ // nobody asked for.Row {- SegmentedControl {+ StarChip {+ on: root.favourites-only;+ clicked => { Library.favourites-changed(root.shelf, !root.favourites-only); }+ }++ if !root.favourites-only: SegmentedControl {options: root.group-labels;- current <=> root.group;+ current: root.group;+ changed(index) => { Library.group-changed(root.shelf, index); }+ }++ if root.favourites-only: Text {+ vertical-alignment: center;+ text: I18n.t("Favourites");+ color: Theme.fg-muted;+ font-size: Theme.fs;}}- Rectangle { height: 4px; }+ Rectangle { height: 6px; }- VerticalLayout {- padding-left: Theme.pad;- padding-right: Theme.pad;- padding-top: 4px;-- // `visible` toggles, not `if`: the filter changes with every- // keystroke and a hidden row costing zero height is the cheap,- // geometry-proof way to narrow the list (see media-pane's- // sidebar for the scar tissue behind this choice).- for entry[index] in root.catalogue: row := Rectangle {- // Named rather than reached through `parent`: a layout is not- // transparent to a parent chain, so a descendant inside the- // HorizontalLayout below cannot see the row's own properties- // any other way.- property <bool> shown: root.shown(entry);+ // The shelf itself, as tiles rather than rows.+ //+ // Rust hands this list over already searched, shelved and starred,+ // which is the whole reason a grid is possible: a cell's place is+ // its index, and an index only means a place when every entry in the+ // model is one that shows. Filtering in Slint - the `visible: false`+ // trick a vertical list can get away with - would leave holes in the+ // grid where the hidden ones were.+ Rectangle {+ height: root.rows * (root.cell-h + root.cell-gap);++ for entry[index] in root.catalogue: tile := Rectangle {property <bool> in-chain: root.in-chain(entry.id);- visible: row.shown;- height: row.shown ? 26px : 0;+ x: root.pad + mod(index, root.columns) * (root.cell-w + root.cell-gap);+ y: floor(index / root.columns) * (root.cell-h + root.cell-gap);+ width: root.cell-w;+ height: root.cell-h;border-radius: Theme.r-sm;- background: row-touch.has-hover && !row.in-chain- ? Theme.field : Colors.transparent;-- HorizontalLayout {- padding-left: 6px;- padding-right: 8px;- spacing: 6px;-- VerticalLayout {- alignment: center;- Icon {- glyph: row.in-chain ? Glyph.check : Glyph.plus;- size: 11px;- tint: row.in-chain ? Theme.green : Theme.fg-muted;- }- }+ border-width: 1px;+ border-color: tile.in-chain ? Theme.accent+ : tile-touch.has-hover ? Theme.line-strong+ : Theme.line;+ background: tile.in-chain ? Theme.accent-soft+ : tile-touch.has-hover ? Theme.field-hover+ : Theme.field;++ animate background, border-color {+ duration: 100ms; easing: cubic-bezier(0.4, 0, 0.2, 1);+ }- Text {- horizontal-stretch: 1;- text: entry.name;- color: row.in-chain ? Theme.fg-dim : Theme.fg;- font-size: Theme.fs;- vertical-alignment: center;- overflow: elide;+ // The name, centred and given the whole cell: at this size a+ // glyph would be a guess about what an effect looks like, and+ // the word is the thing being chosen.+ Text {+ x: 4px;+ width: parent.width - 8px;+ height: parent.height;+ text: entry.name;+ color: tile.in-chain ? Theme.accent : Theme.fg;+ font-size: Theme.fs-sm;+ horizontal-alignment: center;+ vertical-alignment: center;+ wrap: word-wrap;+ overflow: elide;+ }++ // The star rides the tile's corner and takes its own clicks,+ // so starring is never a step on the way to applying.+ star := Rectangle {+ x: parent.width - self.width - 2px;+ y: 2px;+ width: 15px;+ height: 15px;+ border-radius: Theme.r-xs;+ visible: entry.favourite || tile-touch.has-hover || star-touch.has-hover;+ background: star-touch.has-hover ? Theme.field-active : Colors.transparent;++ Icon {+ glyph: Glyph.sparkle;+ size: 10px;+ filled: entry.favourite;+ tint: entry.favourite ? Theme.accent : Theme.fg-dim;}- if row.in-chain: Text {- text: I18n.t("in chain");- color: Theme.fg-dim;- font-size: Theme.fs-xs;- vertical-alignment: center;+ star-touch := TouchArea {+ mouse-cursor: pointer;+ clicked => { Library.favourite(entry.id, !entry.favourite); }}}- row-touch := TouchArea {- enabled: !row.in-chain;+ tile-touch := TouchArea {+ // Below the star in the tree, so the star's own area wins+ // the clicks that land on it.+ enabled: !tile.in-chain;mouse-cursor: pointer;clicked => { root.add(entry.id); }}}}++ if root.catalogue.length == 0: HorizontalLayout {+ padding-left: Theme.pad;+ padding-right: Theme.pad;+ padding-top: 2px;++ Text {+ text: root.favourites-only+ ? I18n.t("Nothing starred yet — hover a tile and press its star.")+ : I18n.t1("No {0} matches that.", "\{root.noun}");+ color: Theme.fg-dim;+ font-size: Theme.fs-sm;+ wrap: word-wrap;+ }+ }+ }+}++/// One treatment: a switch, its name, and one line saying what it does.+component Processor inherits VerticalLayout {+ in property <string> label;+ in property <string> note;+ in property <bool> on;++ callback toggled();++ padding-bottom: 6px;++ SwitchRow {+ label: root.label;+ checked: root.on;+ toggled(value) => { root.toggled(); }+ }++ // Under the switch and inside its padding, so the sentence reads as this+ // row's own rather than as a note about the section.+ HorizontalLayout {+ padding-left: Theme.pad;+ padding-right: Theme.pad;++ Text {+ text: root.note;+ color: Theme.fg-dim;+ font-size: Theme.fs-sm;+ wrap: word-wrap;+ }+ }+}++/// The three treatments a sound clip almost always wants, promoted out of+/// the effect library and onto the tab itself.+///+/// They are ordinary links of the audio chain - the same packages the+/// library lists, added and removed by the same callbacks - and nothing here+/// knows what they do. What they get is a switch instead of a search: a+/// person opening the Sound tab to fix a noisy lavalier should not have to+/// know that "Reduce noise" is filed under a shelf.+///+/// Their knobs stay in the chain's Applied section rather than being+/// duplicated here. One set of controls per link, in the order the link runs.+export component ProcessorRows inherits VerticalLayout {+ in property <[AppliedEntryData]> applied;++ callback add(id: string);+ callback remove(index: int);++ /// Where a package sits on the chain, or -1. The same eight-deep scan+ /// PresetStack does, and for the same reason: Slint has no lookup.+ pure function at(id: string) -> int {+ return root.applied.length > 0 && root.applied[0].id == id ? 0+ : root.applied.length > 1 && root.applied[1].id == id ? 1+ : root.applied.length > 2 && root.applied[2].id == id ? 2+ : root.applied.length > 3 && root.applied[3].id == id ? 3+ : root.applied.length > 4 && root.applied[4].id == id ? 4+ : root.applied.length > 5 && root.applied[5].id == id ? 5+ : root.applied.length > 6 && root.applied[6].id == id ? 6+ : root.applied.length > 7 && root.applied[7].id == id ? 7+ : -1;+ }++ function toggle(id: string) {+ if (root.at(id) >= 0) {+ root.remove(root.at(id));+ } else {+ root.add(id);+ }+ }++ Section {+ SectionHeader { title: I18n.t("Treatments"); }+ SectionBody {+ Processor {+ label: I18n.t("Normalize loudness");+ note: I18n.t("Brings the clip to a broadcast level without riding the fader.");+ on: root.at("concat.loudness") >= 0;+ toggled => { root.toggle("concat.loudness"); }+ }+ Processor {+ label: I18n.t("Reduce noise");+ note: I18n.t("Takes the room's hiss and hum out from under the voice.");+ on: root.at("concat.denoise") >= 0;+ toggled => { root.toggle("concat.denoise"); }+ }+ Processor {+ label: I18n.t("Enhance voice");+ note: I18n.t("Lifts speech out of the mix: a little presence, a little control.");+ on: root.at("concat.enhance-voice") >= 0;+ toggled => { root.toggle("concat.enhance-voice"); }+ }+ }}}@@ -426,6 +670,8 @@ export component VideoPanel inherits VerticalLayout {Param {label: I18n.t("Scale");+ keyable: true;+ field: ClipField.scale;value <=> root.scale;minimum: 0.05;maximum: 8;@@ -436,6 +682,8 @@ export component VideoPanel inherits VerticalLayout {}Param {label: I18n.t("Position X");+ keyable: true;+ field: ClipField.offset-x;value <=> root.offset-x;minimum: -1;maximum: 1;@@ -446,6 +694,8 @@ export component VideoPanel inherits VerticalLayout {}Param {label: I18n.t("Position Y");+ keyable: true;+ field: ClipField.offset-y;value <=> root.offset-y;minimum: -1;maximum: 1;@@ -456,6 +706,8 @@ export component VideoPanel inherits VerticalLayout {}Param {label: I18n.t("Rotation");+ keyable: true;+ field: ClipField.rotation;value <=> root.rotation;minimum: -180;maximum: 180;@@ -498,6 +750,8 @@ export component VideoPanel inherits VerticalLayout {if blend.open: SectionBody {Param {label: I18n.t("Opacity");+ keyable: true;+ field: ClipField.opacity;value <=> root.alpha;minimum: 0;maximum: 1;@@ -747,10 +1001,22 @@ export component AudioPanel inherits VerticalLayout {title: I18n.t("Volume");collapsible: true;summary: InspectorFmt.format(ParamFormat.gain, root.level);++ ResetButton {+ dirty: root.level != 0 || Keyframes.row(ClipField.volume).keyed;+ reset => {+ Keyframes.clear(ClipField.volume);+ root.set(ClipField.volume, 1);+ root.commit();+ }+ }}if volume.open: SectionBody {Param {label: I18n.t("Level");+ keyable: true;+ field: ClipField.volume;+ rail: true;value <=> root.level;// The bottom is silence, not -60. +24 at the top because quiet// material genuinely needs it — a distant lavalier is routinely@@ -776,10 +1042,20 @@ export component AudioPanel inherits VerticalLayout {summary: (root.fade-in == 0 && root.fade-out == 0) ? I18n.t("none"): InspectorFmt.format(ParamFormat.seconds2, root.fade-in)+ " / " + InspectorFmt.format(ParamFormat.seconds2, root.fade-out);++ ResetButton {+ dirty: root.fade-in != 0 || root.fade-out != 0;+ reset => {+ root.set(ClipField.fade-in, 0);+ root.set(ClipField.fade-out, 0);+ root.commit();+ }+ }}if fades.open: SectionBody {Param {label: I18n.t("Fade in");+ rail: true;value <=> root.fade-in;minimum: 0;maximum: root.fade-limit;@@ -789,6 +1065,7 @@ export component AudioPanel inherits VerticalLayout {}Param {label: I18n.t("Fade out");+ rail: true;value <=> root.fade-out;minimum: 0;maximum: root.fade-limit;diff --git a/engine/crates/concat/ui/inspector/controls.slint b/engine/crates/concat/ui/inspector/controls.slintindex af23f2b9..c93ae309 100644--- a/engine/crates/concat/ui/inspector/controls.slint+++ b/engine/crates/concat/ui/inspector/controls.slint@@ -6,6 +6,7 @@ import { Theme } from "../theme/theme.slint";import { Fmt } from "../util.slint";import { Glyph, Icon } from "../icons.slint";import { NumberField } from "../primitives/number-field.slint";+import { ClipField, ClipKeyData, Keyframes } from "../timeline/model.slint";// The clip inspector's controls: a horizontal fader, the Param row that// repeats down every tab, a switch, a help disclosure, a note, and a search@@ -133,14 +134,6 @@ export global InspectorFmt {}}-export global InspectorSearch {- // Slint's string type has no contains(), so the library search match is- // implemented in Rust and bound in main.rs — the same seam as- // Fmt.parse-timecode. Unbound it returns false, so main.rs must bind it- // or the library lists nothing while a query is typed.- pure callback matches(name: string, query: string) -> bool;-}-// Horizontal fader. Click to jump, drag to ride, double-click to reset.//// A sunken track the height of a field, filled from the left in the soft@@ -227,6 +220,187 @@ export component Fader inherits Rectangle {}}+// The other slider, and the other half of the pair: where the Fader is a+// filled box the height of a field, the Rail is a hairline track with a+// raised chip you push along it.+//+// Which one a row gets is a question of how loud the row is, not of taste.+// The Fader is a *field*: it is the height of the number box beside it, it+// carries its own ground, and a column of them reads as a form — which is+// what an effect's six knobs should read as. The Rail is a *control*: it is+// mostly air, the dragger is the only solid thing in it, and one of them in+// a section says this is the setting the section is about. Volume is that.+// A chorus's wet/dry is not.+//+// The dragger is a chip and not a bead for the reason the Fader's cap is a+// bar: flat sides land on a value. It is light rather than accent-coloured+// because the fill it slides over is already the accent, and a dragger in+// the colour of the thing behind it stops being a dragger.+export component Rail inherits Rectangle {+ in-out property <float> value;+ in property <float> minimum: 0;+ in property <float> maximum: 1;+ in property <float> step: 0.01;+ /// restored on double-click+ in property <float> default-value: root.minimum;+ in property <bool> enabled: true;++ callback changed(value: float);++ height: Theme.h;+ opacity: root.enabled ? 1.0 : 0.45;++ property <float> span: Math.max(root.maximum - root.minimum, 0.000001);+ /// Half the dragger, so it stays inside the track at both ends and the+ /// value under the pointer is the value under the dragger's middle.+ property <length> inset: 5.5px;+ property <length> usable: Math.max(1px, root.width - 2 * root.inset);+ property <float> percent: Fmt.clamp((root.value - root.minimum) / root.span, 0, 1);+ property <bool> live: (touch.has-hover || touch.pressed) && root.enabled;++ function settle(raw: float) {+ root.value = Fmt.clamp(+ root.minimum + Math.round((raw - root.minimum) / root.step) * root.step,+ root.minimum, root.maximum);+ root.changed(root.value);+ }++ function apply-at(at: length) {+ root.settle(root.minimum+ + Fmt.clamp((at - root.inset) / root.usable, 0, 1) * root.span);+ }++ // The track. Four pixels and a hairline: enough to read as a groove, not+ // enough to compete with the dragger for the eye.+ track := Rectangle {+ y: (parent.height - self.height) / 2;+ width: parent.width;+ height: 4px;+ border-radius: 2px;+ border-width: 1px;+ border-color: Theme.line;+ background: Theme.well;++ // Runs to the dragger's middle rather than to its near edge, so the+ // fill and the chip meet instead of leaving a gap that grows with+ // the dragger's width.+ Rectangle {+ x: 0;+ y: 0;+ width: root.inset + root.usable * root.percent;+ height: parent.height;+ border-radius: parent.border-radius;+ background: Theme.accent;+ }+ }++ grip := Rectangle {+ x: root.inset + root.usable * root.percent - self.width / 2;+ y: (parent.height - self.height) / 2;+ width: 11px;+ // Grows under the pointer: the chip is small enough that the target+ // wants confirming, and the growth is the confirmation.+ height: touch.pressed ? 22px : (root.live ? 20px : 18px);+ border-radius: Theme.r-xs;+ border-width: 1px;+ border-color: Theme.grip-edge;+ background: touch.pressed ? Theme.grip-active : Theme.grip;+ drop-shadow-blur: 3px;+ drop-shadow-offset-y: 1px;+ drop-shadow-color: Theme.grip-edge;++ animate height, background { duration: 100ms; easing: cubic-bezier(0.4, 0, 0.2, 1); }+ }++ touch := TouchArea {+ enabled: root.enabled;+ mouse-cursor: ew-resize;++ pointer-event(event) => {+ if (event.kind == PointerEventKind.down+ && event.button == PointerEventButton.left) {+ root.apply-at(self.mouse-x);+ }+ }+ moved => {+ root.apply-at(self.mouse-x);+ }+ double-clicked => {+ root.settle(root.default-value);+ }+ }+}++// One target of the cluster. Small, quiet, and greyed rather than hidden+// when there is nowhere to go.+component KeyButton inherits Rectangle {+ in property <Glyph> glyph;+ in property <bool> filled;+ in property <bool> enabled: true;+ in property <color> tint: Theme.fg-dim;++ callback clicked();++ width: 17px;+ height: 17px;+ border-radius: Theme.r-xs;+ background: touch.has-hover && root.enabled ? Theme.field : Colors.transparent;+ opacity: root.enabled ? 1.0 : 0.35;++ Icon {+ glyph: root.glyph;+ size: 11px;+ filled: root.filled;+ tint: touch.has-hover && root.enabled ? Theme.fg : root.tint;+ }++ touch := TouchArea {+ enabled: root.enabled;+ mouse-cursor: pointer;+ clicked => { root.clicked(); }+ }+}++// The keyframe cluster: step back, put one on or take it off, step forward.+//+// Three targets in the width of one, which is what makes it a cluster rather+// than three buttons - they are read as one control ("is this animated, and+// where am I in it") and only pressed as three. The chevrons move the+// playhead rather than the value: a key is set where the playhead is, so+// arriving at one is how you edit it.+export component KeyCluster inherits HorizontalLayout {+ in property <ClipField> field;++ property <ClipKeyData> state: Keyframes.row(root.field);+ property <bool> live: Keyframes.available;++ spacing: 1px;++ prev := KeyButton {+ glyph: Glyph.chevron-left;+ enabled: root.live && root.state.prev;+ clicked => { Keyframes.step(root.field, -1); }+ }++ diamond := KeyButton {+ glyph: Glyph.keyframe;+ // Filled on a key, outlined on a keyed property between keys, and+ // plain grey on one that is still a constant. Three states because+ // there are three answers, and the middle one - "animated, but not+ // here" - is the one a two-state diamond loses.+ filled: root.state.here;+ enabled: root.live;+ tint: root.state.here || root.state.keyed ? Theme.accent : Theme.fg-dim;+ clicked => { Keyframes.toggle(root.field); }+ }++ next := KeyButton {+ glyph: Glyph.chevron-right;+ enabled: root.live && root.state.next;+ clicked => { Keyframes.step(root.field, 1); }+ }+}+// The inspector's repeating unit: a formatted readout above (the value in a// unit you reason about — "none", "auto", "1.00x"), the fader and a raw// number field below. Keeping both is what lets a fade of zero say "none"@@ -240,6 +414,15 @@ export component Param inherits VerticalLayout {in property <float> default-value: root.minimum;in property <ParamFormat> fmt;in property <bool> enabled: true;+ /// Ride the Rail instead of the Fader — for the one setting a section is+ /// named after, not for a list of knobs.+ in property <bool> rail: false;+ /// Show the keyframe cluster, and which field it keys. Opt-in rather+ /// than derived from `field`, because a Slint enum property with nothing+ /// assigned to it is its first variant and not "none" - every unkeyable+ /// row would otherwise claim to be keying scale.+ in property <bool> keyable: false;+ in property <ClipField> field;callback changed(value: float);@@ -264,12 +447,35 @@ export component Param inherits VerticalLayout {font-size: Theme.fs;vertical-alignment: center;}++ // On the readout's side rather than under the slider: the cluster is+ // about the value, and the value is what it sits beside.+ if root.keyable: Rectangle { width: 6px; }+ if root.keyable: VerticalLayout {+ alignment: center;+ KeyCluster { field: root.field; }+ }}HorizontalLayout {spacing: 8px;- Fader {+ // One row, either slider. See Rail's header for which belongs where;+ // the rest of the row - the readout above, the number field beside -+ // is the same either way, which is the point of putting the choice+ // here rather than in two near-identical Param components.+ if !root.rail: Fader {+ horizontal-stretch: 1;+ value <=> root.value;+ minimum: root.minimum;+ maximum: root.maximum;+ step: root.step;+ default-value: root.default-value;+ enabled: root.enabled;+ changed(v) => { root.changed(v); }+ }++ if root.rail: Rail {horizontal-stretch: 1;value <=> root.value;minimum: root.minimum;@@ -394,6 +600,38 @@ export component HelpButton inherits Rectangle {}}+// Put a section back the way it was found.+//+// Sits in a SectionHeader's action slot beside the help disclosure, and is+// dimmed rather than hidden when there is nothing to undo: a control that+// appears only once you have made a mess is one you cannot learn is there.+export component ResetButton inherits Rectangle {+ /// Something in the section is off its default. False greys it.+ in property <bool> dirty: true;++ callback reset();++ width: 16px;+ height: 16px;+ border-radius: 8px;+ background: touch.has-hover && root.dirty ? Theme.field-hover : Theme.field;+ opacity: root.dirty ? 1.0 : 0.4;++ animate background { duration: 100ms; easing: cubic-bezier(0.4, 0, 0.2, 1); }++ Icon {+ glyph: Glyph.reset;+ size: 10px;+ tint: touch.has-hover && root.dirty ? Theme.fg : Theme.fg-muted;+ }++ touch := TouchArea {+ enabled: root.dirty;+ mouse-cursor: pointer;+ clicked => { root.reset(); }+ }+}+export component Note inherits HorizontalLayout {in property <string> text;diff --git a/engine/crates/concat/ui/theme/dark.slint b/engine/crates/concat/ui/theme/dark.slintindex 8cf890e3..c0688d5f 100644--- a/engine/crates/concat/ui/theme/dark.slint+++ b/engine/crates/concat/ui/theme/dark.slint@@ -110,6 +110,15 @@ export global Dark {out property <color> on-accent: #15220a;out property <color> on-green: #06210f;+ // The Rail's dragger — the raised chip you push along a hairline rail, as+ // distinct from the Fader's flat bar. It is a light chip and not the+ // accent because the rail's fill is already the accent: a dragger in the+ // same colour would disappear into the value it is marking. The edge is+ // what keeps it legible when it is sitting on that fill.+ out property <color> grip: #dcdce4;+ out property <color> grip-active: #ffffff;+ out property <color> grip-edge: #0000008c; // rgb(0 0 0 / 0.55)+// meter rampout property <color> meter-low: #34c759;out property <color> meter-mid: #ffd60a;diff --git a/engine/crates/concat/ui/theme/light.slint b/engine/crates/concat/ui/theme/light.slintindex 03621689..2ef6ef46 100644--- a/engine/crates/concat/ui/theme/light.slint+++ b/engine/crates/concat/ui/theme/light.slint@@ -94,6 +94,13 @@ export global Light {out property <color> on-accent: #ffffff;out property <color> on-green: #ffffff;+ // The Rail's dragger. White rather than the dark palette's near-white,+ // and with a heavier edge: on a light panel a pale chip has nothing but+ // that hairline and its shadow to stand it off the rail.+ out property <color> grip: #ffffff;+ out property <color> grip-active: #ffffff;+ out property <color> grip-edge: #00000061; // rgb(0 0 0 / 0.38)+// meter ramp — the same three readings, each deep enough to be told from// the light well it is drawn in. The yellow is the one that has to move// furthest: #ffd60a on near-white is a smear.diff --git a/engine/crates/concat/ui/theme/theme.slint b/engine/crates/concat/ui/theme/theme.slintindex 763d0383..95fcd6de 100644--- a/engine/crates/concat/ui/theme/theme.slint+++ b/engine/crates/concat/ui/theme/theme.slint@@ -127,6 +127,11 @@ export global Theme {out property <color> on-accent: dark ? Dark.on-accent : Light.on-accent;out property <color> on-green: dark ? Dark.on-green : Light.on-green;+ // the Rail's dragger+ out property <color> grip: dark ? Dark.grip : Light.grip;+ out property <color> grip-active: dark ? Dark.grip-active : Light.grip-active;+ out property <color> grip-edge: dark ? Dark.grip-edge : Light.grip-edge;+// meter rampout property <color> meter-low: dark ? Dark.meter-low : Light.meter-low;out property <color> meter-mid: dark ? Dark.meter-mid : Light.meter-mid;diff --git a/engine/crates/concat/ui/timeline/model.slint b/engine/crates/concat/ui/timeline/model.slintindex 0923090d..64dee708 100644--- a/engine/crates/concat/ui/timeline/model.slint+++ b/engine/crates/concat/ui/timeline/model.slint@@ -159,6 +159,68 @@ export enum ClipField {cutout-feather,}+/// One keyable property's state at the playhead, as the inspector needs it.+export struct ClipKeyData {+ /// Which property this row is about.+ field: ClipField,+ /// It carries keys at all: the value is a ride and not a constant.+ keyed: bool,+ /// There is a key exactly here, so the diamond is filled and clicking it+ /// takes that key off rather than putting another one on.+ here: bool,+ /// There is a key behind the playhead to step back to.+ prev: bool,+ /// There is a key ahead of it to step on to.+ next: bool,+}++/// The keyframe cluster's state and its two verbs.+///+/// A global rather than five panels' worth of threaded properties: every row+/// that can be keyed asks the same question about a different field, and the+/// answer is built in one place in Rust either way. The panels only say+/// which field a row is.+export global Keyframes {+ /// One row per keyable property, in the order `row` indexes them. Empty+ /// when the selection cannot carry keys at all.+ in property <[ClipKeyData]> rows;+ /// The playhead is inside the selected clip, so a key put on now would+ /// land somewhere. False greys the whole cluster rather than hiding it:+ /// a control that comes and goes is harder to aim at than one that dims.+ in property <bool> available;++ /// Put a key on this field at the playhead, or take off the one there.+ callback toggle(field: ClipField);+ /// Move the playhead to this field's previous (-1) or next (+1) key.+ callback step(field: ClipField, delta: int);+ /// Take every key off this field, leaving it the constant it shows. What+ /// a section's reset calls before it puts the value back: restoring a+ /// number under a ride that is still running would change nothing a+ /// person could see.+ callback clear(field: ClipField);++ /// A row for a field with no keys and nowhere to step.+ pure public function blank(field: ClipField) -> ClipKeyData {+ return { field: field, keyed: false, here: false, prev: false, next: false };+ }++ /// This field's row. Slint has no lookup and the list is six long, so+ /// the order Rust publishes them in *is* the index; `blank` covers the+ /// moment before the first publish.+ pure public function row(field: ClipField) -> ClipKeyData {+ if (Keyframes.rows.length < 6) {+ return Keyframes.blank(field);+ }+ return field == ClipField.scale ? Keyframes.rows[0]+ : field == ClipField.offset-x ? Keyframes.rows[1]+ : field == ClipField.offset-y ? Keyframes.rows[2]+ : field == ClipField.rotation ? Keyframes.rows[3]+ : field == ClipField.opacity ? Keyframes.rows[4]+ : field == ClipField.volume ? Keyframes.rows[5]+ : Keyframes.blank(field);+ }+}+/// The same again for the properties that are text rather than numbers.export enum ClipTextField {content, font-family, color, stroke-color, background,diff --git a/engine/crates/concat/ui/workspace/config-pane.slint b/engine/crates/concat/ui/workspace/config-pane.slintindex 9faaa54e..6a53895d 100644--- a/engine/crates/concat/ui/workspace/config-pane.slint+++ b/engine/crates/concat/ui/workspace/config-pane.slint@@ -8,7 +8,7 @@ import { Pane, PaneBody, PaneScroll } from "pane.slint";import { PaneKind, PaneSwitcher } from "pane-switcher.slint";import { EffectData } from "../demo/effects-panel.slint";import {- AdjustPanel, AnimationPanel, AppliedEntryData, AppliedParamData, AudioPanel,+ AdjustPanel, AnimationPanel, AppliedEntryData, AppliedParamData, AudioPanel, ProcessorRows,CatalogueEntryData, FilterPanel, PresetStack, SpeedPanel, VideoPanel,} from "../inspector/clip-inspector.slint";import { TextPanel } from "../inspector/text-panel.slint";@@ -557,9 +557,19 @@ export component ConfigPane inherits Rectangle {set(field, value) => { root.clip-set(field, value); }commit => { root.clip-commit(); }}+ // The three treatments, between the mix and the library:+ // they are chain links like any other, but they are the+ // ones a sound clip usually needs, so they get a switch+ // rather than a search.+ ProcessorRows {+ applied: root.applied-audio;+ add(id) => { root.chain-add(true, id); }+ remove(index) => { root.chain-remove(true, index); }+ }PresetStack {noun: I18n.t("audio effect");library-title: I18n.t("Audio effects");+ shelf: 2;group-labels: root.audio-groups;catalogue: root.catalogue-audio;applied: root.applied-audio;@@ -582,6 +592,7 @@ export component ConfigPane inherits Rectangle {if root.showing == "Filters": PresetStack {noun: I18n.t("filter");library-title: I18n.t("Filter library");+ shelf: 0;group-labels: root.filter-groups;catalogue: root.catalogue-filters;applied: root.applied-visual;@@ -600,6 +611,7 @@ export component ConfigPane inherits Rectangle {if root.showing == "Effects": PresetStack {noun: I18n.t("effect");library-title: I18n.t("Effect library");+ shelf: 1;group-labels: root.effect-groups;catalogue: root.catalogue-effects;applied: root.applied-visual;