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
feat(ui): waveforms stand on the floor, and the part over -6 dBFS goes amber
Jareer0212b70995ce
diff --git a/src/crates/concat/src/format.rs b/src/crates/concat/src/format.rsindex 4711ad28..b61f4dcc 100644--- a/src/crates/concat/src/format.rs+++ b/src/crates/concat/src/format.rs@@ -149,40 +149,61 @@ pub fn hex_of(colour: slint::Color) -> String {)}+/// Where a bar goes hot: the peak level, as a fraction of full scale,+/// above which the part of the bar that is over it is drawn in the hot+/// colour. -6 dBFS. A mix that keeps its peaks under this has headroom; one+/// that crosses it often is on its way to clipping, which is the thing a+/// glance at the lane should catch.+pub const WAVE_HOT: f32 = 0.5012;++/// A drawn waveform: two sets of SVG path commands in a 1x1 box, drawn on+/// top of each other. See [`wave_path`].+#[derive(Clone, Debug, Default, PartialEq)]+pub struct Wave {+ /// Every column's bar, from the floor up to its peak or to+ /// [`WAVE_HOT`], whichever is lower.+ pub body: String,+ /// The part of each bar over [`WAVE_HOT`], for the columns that reach+ /// it; empty when none does.+ pub hot: String,+}+/// A waveform as SVG path commands in a 1x1 box: one column per slot, each-/// a bar from the slot's lowest sample to its highest, mirrored about the-/// middle. Mirrored because that is what a waveform looks like; a bar-/// from the axis up is the rounded shape that reads as a graph of-/// something rather than as audio.+/// a bar standing on the floor, as tall as the loudest sample under it.+/// A level meter laid along the clip rather than the mirrored fish of a+/// waveform: the height of a bar is a level, read from one edge, and the+/// part of it above [`WAVE_HOT`] is a second path so it can be drawn in a+/// colour that says so.////// Built from the engine's real peaks at the level that fits the column:/// each column takes the extremes of the buckets under it, so a trim shows/// the material it kept and a zoom shows the buckets it reveals. `columns`/// is how many the drawing has room for - the clip's width in pixels, held-/// to a few thousand - and the path is normalised so the Path that renders-/// it stretches the box onto the clip's current width.+/// to a few thousand - and the paths are normalised so the Path that+/// renders them stretches the box onto the clip's current width.pub fn wave_path(peaks: &concat_media::Pyramid,source_start: f32,duration: f32,gain: f32,columns: usize,-) -> String {+) -> Wave {/// Fewest columns worth drawing, and the most: enough that a clip a/// screen wide reads a column a pixel, few enough that the string stays/// under a few hundred kilobytes.const COLUMNS: std::ops::RangeInclusive<usize> = 8..=2048;- /// Silence still draws a sliver: a hairline through the middle of a clip+ /// Silence still draws a sliver: a hairline along the floor of a clip/// rather than a gap in it.- const FLOOR: f32 = 0.012;+ const FLOOR: f32 = 0.024;if duration.is_nan() || duration <= 0.0 || peaks.finest().is_empty() {- return String::new();+ return Wave::default();}let columns = columns.clamp(*COLUMNS.start(), *COLUMNS.end());let gain = gain.max(0.0);let level = peaks.level_for(duration / columns as f32);- let mut path = String::with_capacity(columns * 56);+ let mut body = String::with_capacity(columns * 56);+ let mut hot = String::new();for column in 0..columns {let left = column as f32 / columns as f32;@@ -191,14 +212,21 @@ pub fn wave_path(source_start + left * duration,source_start + right * duration,);- let amplitude = ((high.max(-low) * gain).clamp(0.0, 1.0) * 0.48).max(FLOOR);- let (top, bottom) = (0.5 - amplitude, 0.5 + amplitude);- path.push_str(&format!(+ let amplitude = (high.max(-low) * gain).clamp(0.0, 1.0).max(FLOOR);+ let top = 1.0 - amplitude.min(WAVE_HOT);+ body.push_str(&format!("M {left:.4} {top:.4} L {right:.4} {top:.4} \- L {right:.4} {bottom:.4} L {left:.4} {bottom:.4} Z "+ L {right:.4} 1.0000 L {left:.4} 1.0000 Z "));+ if amplitude > WAVE_HOT {+ let (peak, limit) = (1.0 - amplitude, 1.0 - WAVE_HOT);+ hot.push_str(&format!(+ "M {left:.4} {peak:.4} L {right:.4} {peak:.4} \+ L {right:.4} {limit:.4} L {left:.4} {limit:.4} Z "+ ));+ }}- path+ Wave { body, hot }}/// How many columns a clip `seconds` long gets at `seconds_per_pixel`: one@@ -361,27 +389,78 @@ mod tests {});let loud = wave_path(&peaks, 0.0, 2.0, 1.0, 128);let quiet = wave_path(&peaks, 0.0, 2.0, 0.25, 128);- assert_eq!(loud.matches('M').count(), 128);+ assert_eq!(loud.body.matches('M').count(), 128);+ // A bar stands on the floor: its top is one less its height.assert!(- loud.contains("0.2600"),- "half amplitude at unity gain: {loud}"+ loud.body.contains(" 0.5000 L") && loud.body.contains(" 1.0000 Z"),+ "half amplitude at unity gain, floored: {}",+ loud.body);+ assert!(loud.hot.is_empty(), "half scale is under the hot line");assert!(- quiet.contains("0.4400"),- "an eighth at a quarter gain: {quiet}"+ quiet.body.contains(" 0.8750 L"),+ "an eighth at a quarter gain: {}",+ quiet.body);- assert!(wave_path(&peaks, 0.0, 0.0, 1.0, 128).is_empty());- assert!(wave_path(&peaks, 0.0, f32::NAN, 1.0, 128).is_empty());+ assert_eq!(wave_path(&peaks, 0.0, 0.0, 1.0, 128), Wave::default());+ assert_eq!(wave_path(&peaks, 0.0, f32::NAN, 1.0, 128), Wave::default());// The column count is held to what is worth drawing, either way.- assert_eq!(wave_path(&peaks, 0.0, 2.0, 1.0, 0).matches('M').count(), 8);+ assert_eq!(+ wave_path(&peaks, 0.0, 2.0, 1.0, 0)+ .body+ .matches('M')+ .count(),+ 8+ );assert_eq!(wave_path(&peaks, 0.0, 2.0, 1.0, 1_000_000)+ .body.matches('M').count(),2048);}+ /// A bar over the hot line is two bars: the body stops at the line,+ /// and the hot path carries what is over it, and nothing else. A bar+ /// under it has no hot part; a gain can push it over.+ #[test]+ fn only_the_part_of_a_bar_over_the_hot_line_goes_hot() {+ let peaks = concat_media::Pyramid::of(concat_media::Peaks {+ min: vec![-0.8; 1000],+ max: vec![0.8; 1000],+ buckets_per_second: 1000.0,+ });+ let wave = wave_path(&peaks, 0.0, 1.0, 1.0, 10);+ let limit = format!("{:.4}", 1.0 - WAVE_HOT);+ assert!(+ wave.body.contains(&format!(" {limit} L")),+ "the body stops at the line: {}",+ wave.body+ );+ assert!(+ !wave.body.contains(" 0.2000 "),+ "and never reaches the peak"+ );+ assert_eq!(wave.hot.matches('M').count(), 10, "every column is over");+ assert!(+ wave.hot.contains(" 0.2000 L") && wave.hot.contains(&format!(" {limit} Z")),+ "the hot part runs from the peak down to the line: {}",+ wave.hot+ );++ let under = wave_path(&peaks, 0.0, 1.0, 0.5, 10);+ assert!(under.hot.is_empty(), "at half gain nothing is over");+ assert!(under.body.contains(" 0.6000 L"), "{}", under.body);+ let pushed = wave_path(&peaks, 0.0, 1.0, 2.0, 10);+ assert_eq!(+ pushed.hot.matches('M').count(),+ 10,+ "a gain can push it over"+ );+ assert!(pushed.hot.contains(" 0.0000 L"), "clamped at full scale");+ }+/// A zoomed-in clip reads the fine buckets: a single loud millisecond/// shows in one column at a column a millisecond, and is folded into/// its neighbours' column, still at full height, when a column is a@@ -397,26 +476,25 @@ mod tests {max,buckets_per_second: 1000.0,});+ // A full-scale spike is a column whose hot part reaches the top.let fine = wave_path(&peaks, 0.0, 1.0, 1.0, 1000);- let tall: Vec<&str> = fine- .split("Z ")- .filter(|bar| bar.contains(" 0.0200"))- .collect();assert_eq!(- tall.len(),+ fine.hot.matches('M').count(),1,"one column carries the spike: {}",- tall.len()+ fine.hot);+ assert!(fine.hot.contains(" 0.0000 L"), "at full height");let coarse = wave_path(&peaks, 0.0, 1.0, 1.0, 10);assert_eq!(- coarse.matches(" 0.0200").count(),- 2,- "the spike survives the fold at full height"+ coarse.hot.matches('M').count(),+ 1,+ "the spike survives the fold, in one column");+ assert!(coarse.hot.contains(" 0.0000 L"), "at full height");let trimmed = wave_path(&peaks, 0.6, 0.4, 1.0, 10);assert!(- !trimmed.contains(" 0.0200"),+ trimmed.hot.is_empty(),"a trim past the spike does not show it");}diff --git a/src/crates/concat/src/lib.rs b/src/crates/concat/src/lib.rsindex 13040cae..e3b7d28c 100644--- a/src/crates/concat/src/lib.rs+++ b/src/crates/concat/src/lib.rs@@ -1321,7 +1321,7 @@ pub fn run() -> Result<(), slint::PlatformError> {.peaks.get(&plan.media).filter(|_| plan.kind == ClipKind::Audio)- .map(|peaks| format::wave_path(peaks, 0.0, plan.duration, 1.0, 128))+ .map(|peaks| format::wave_path(peaks, 0.0, plan.duration, 1.0, 128).body).unwrap_or_default();let document = chips::drag_chip_svg(chips::chip_glyph(plan.kind),diff --git a/src/crates/concat/src/panes/media_bin.rs b/src/crates/concat/src/panes/media_bin.rsindex 8baee306..082c131f 100644--- a/src/crates/concat/src/panes/media_bin.rs+++ b/src/crates/concat/src/panes/media_bin.rs@@ -17,7 +17,6 @@ use std::path::PathBuf;use concat_host::media::{self, MediaSummary};use concat_project::Command;use concat_project::model::{self, MediaItem, Project};-use slint::SharedString;use crate::format::wave_path;use crate::host::{probe_error, spawn};@@ -295,27 +294,31 @@ impl MediaBin {pub fn rows(&self, studio: &Studio) -> Vec<MediaItemData> {self.visible(studio.project()).into_iter()- .map(|item| MediaItemData {- id: *self.rows.get(&item.id).unwrap_or(&0),- name: item.name.as_str().into(),- kind: media_kind_of(item.kind),- duration: item.duration.unwrap_or(0.0) as f32,- format: std::path::Path::new(&item.path)- .extension()- .and_then(|extension| extension.to_str())- .map(|extension| extension.to_ascii_lowercase())- .unwrap_or_default()- .into(),- thumbnail: self.thumbs.get(&item.id).cloned().unwrap_or_default(),- wave: match studio.peaks.get(&item.id) {+ .map(|item| {+ // A card is a couple of hundred pixels: a column each is+ // all the detail it can show.+ let wave = match studio.peaks.get(&item.id) {Some(peaks) if item.kind == model::MediaKind::Audio => {- // A card is a couple of hundred pixels: a column- // each is all the detail it can show.- wave_path(peaks, 0.0, item.duration.unwrap_or(0.0) as f32, 1.0, 256).into()+ wave_path(peaks, 0.0, item.duration.unwrap_or(0.0) as f32, 1.0, 256)}- _ => SharedString::new(),- },- selected: self.selected.contains(&item.id),+ _ => Default::default(),+ };+ MediaItemData {+ id: *self.rows.get(&item.id).unwrap_or(&0),+ name: item.name.as_str().into(),+ kind: media_kind_of(item.kind),+ duration: item.duration.unwrap_or(0.0) as f32,+ format: std::path::Path::new(&item.path)+ .extension()+ .and_then(|extension| extension.to_str())+ .map(|extension| extension.to_ascii_lowercase())+ .unwrap_or_default()+ .into(),+ thumbnail: self.thumbs.get(&item.id).cloned().unwrap_or_default(),+ wave: wave.body.as_str().into(),+ wave_hot: wave.hot.as_str().into(),+ selected: self.selected.contains(&item.id),+ }}).collect()}diff --git a/src/crates/concat/src/studio.rs b/src/crates/concat/src/studio.rsindex 0de31052..ea24052f 100644--- a/src/crates/concat/src/studio.rs+++ b/src/crates/concat/src/studio.rs@@ -543,7 +543,7 @@ pub struct Studio {window_pending: HashSet<String>,/// Envelopes, keyed by the things they are computed from. A move/// changes none of them, and a publish happens on every frame of one.- waves: RefCell<HashMap<String, SharedString>>,+ waves: RefCell<HashMap<String, (SharedString, SharedString)>>,// ── the view ──/// The timeline's view: scroll, zoom, tool, and what the lanes know@@ -2106,16 +2106,19 @@ impl Studio {/// it at each step of that and not at every pixel. A sound clip's/// whole body, a picture clip's band under its frames; a picture that/// is muted, or whose file has no sound, shows the empty band.- fn wave(&self, clip: &Clip) -> SharedString {+ ///+ /// Two paths: the bars, and the part of each bar over the hot line -+ /// see `format::wave_path`.+ fn wave(&self, clip: &Clip) -> (SharedString, SharedString) {if clip.muted == Some(true) {- return SharedString::new();+ return Default::default();}// The stream this clip plays; its peaks come when they are decoded,// and until then the lane is bare rather than showing another// track's shape.let art = art_key(&clip.media_id, clip.audio_stream);let Some(peaks) = self.peaks.get(&art) else {- return SharedString::new();+ return Default::default();};let step = |seconds: f32| (seconds * WAVE_STEPS).round() / WAVE_STEPS;let (source_start, duration) = (step(clip.source_start as f32), step(clip.duration as f32));@@ -2125,7 +2128,8 @@ impl Studio {if let Some(cached) = self.waves.borrow().get(&key) {return cached.clone();}- let built = SharedString::from(wave_path(peaks, source_start, duration, gain, columns));+ let wave = wave_path(peaks, source_start, duration, gain, columns);+ let built = (SharedString::from(wave.body), SharedString::from(wave.hot));self.waves.borrow_mut().insert(key, built.clone());built}@@ -4978,31 +4982,36 @@ impl Studio {clip.duration as f32,)})- .map(|clip| ClipData {- id: clip.id.as_str().into(),- name: clip.name.as_str().into(),- kind: kind_of(clip),- row: self.row_of(&clip.track_id),- start: clip.start as f32,- duration: clip.duration as f32,- selected: self.selection.iter().any(|id| id == &clip.id),- fx: clip.video_effects.iter().any(|effect| effect.enabled),- transition_in: clip.transition_in.is_some(),- fade_in: clip.fade_in as f32,- fade_out: clip.fade_out as f32,- volume: clip.volume as f32,- text_body: clip- .text- .as_ref()- .map(|text| text.content.as_str())- .unwrap_or_default()- .into(),- wave: if matches!(clip.kind, model::ClipKind::Audio | model::ClipKind::Video) {- self.wave(clip)- } else {- SharedString::new()- },- strip: self.strip_of(clip),+ .map(|clip| {+ let wave =+ if matches!(clip.kind, model::ClipKind::Audio | model::ClipKind::Video) {+ self.wave(clip)+ } else {+ Default::default()+ };+ ClipData {+ id: clip.id.as_str().into(),+ name: clip.name.as_str().into(),+ kind: kind_of(clip),+ row: self.row_of(&clip.track_id),+ start: clip.start as f32,+ duration: clip.duration as f32,+ selected: self.selection.iter().any(|id| id == &clip.id),+ fx: clip.video_effects.iter().any(|effect| effect.enabled),+ transition_in: clip.transition_in.is_some(),+ fade_in: clip.fade_in as f32,+ fade_out: clip.fade_out as f32,+ volume: clip.volume as f32,+ text_body: clip+ .text+ .as_ref()+ .map(|text| text.content.as_str())+ .unwrap_or_default()+ .into(),+ wave: wave.0,+ wave_hot: wave.1,+ strip: self.strip_of(clip),+ }}).collect(),);diff --git a/src/crates/concat/ui/theme/dark.slint b/src/crates/concat/ui/theme/dark.slintindex ed0348de..f813b7b2 100644--- a/src/crates/concat/ui/theme/dark.slint+++ b/src/crates/concat/ui/theme/dark.slint@@ -198,6 +198,10 @@ export global Dark {// The same wash in the video's blue, for the sound band under a// video's frames: the band is the video's, not a sound clip's.out property <color> wave-video: #a9c8f5b3; // 0.7 alpha+ // The part of a bar over the hot line: an amber that reads as a+ // warning on the green and on the blue alike, short of the red a+ // clip's own meter keeps for clipping.+ out property <color> wave-hot: #ffb340d9; // 0.85 alpha// clip ink//diff --git a/src/crates/concat/ui/theme/light.slint b/src/crates/concat/ui/theme/light.slintindex 33882d98..a9756c39 100644--- a/src/crates/concat/ui/theme/light.slint+++ b/src/crates/concat/ui/theme/light.slint@@ -148,6 +148,7 @@ export global Light {// the kind's hue — the dark palette's light one would vanish into it.out property <color> wave: #16703bb3; // 0.7 alphaout property <color> wave-video: #255a9eb3; // 0.7 alpha, the video's blue+ out property <color> wave-hot: #e07b00d9; // 0.85 alpha, the part over the hot line// clip ink//diff --git a/src/crates/concat/ui/theme/theme.slint b/src/crates/concat/ui/theme/theme.slintindex ae6ff366..93bd3272 100644--- a/src/crates/concat/ui/theme/theme.slint+++ b/src/crates/concat/ui/theme/theme.slint@@ -157,6 +157,7 @@ export global Theme {out property <color> playhead: dark ? Dark.playhead : Light.playhead;out property <color> wave: dark ? Dark.wave : Light.wave;out property <color> wave-video: dark ? Dark.wave-video : Light.wave-video;+ out property <color> wave-hot: dark ? Dark.wave-hot : Light.wave-hot;// clip inkout property <color> clip-ink: dark ? Dark.clip-ink : Light.clip-ink;diff --git a/src/crates/concat/ui/timeline/lanes.slint b/src/crates/concat/ui/timeline/lanes.slintindex de539b18..f5bb5620 100644--- a/src/crates/concat/ui/timeline/lanes.slint+++ b/src/crates/concat/ui/timeline/lanes.slint@@ -206,6 +206,10 @@ component Clip inherits Rectangle {// Rust rebuilds the string with a column a pixel at each step of// the zoom, from the peaks at the level that fits the column, so// zooming in reveals the buckets rather than stretching a shape.+ // The bars stand on the clip's floor, as tall as the level under+ // them, and the part of a bar over the hot line is drawn again in+ // the hot colour on top: a level meter laid along the clip, so a+ // stretch that is too loud is seen without being heard.if root.item.wave != "" && !root.banded: Path {x: 0;y: 0;@@ -217,10 +221,22 @@ component Clip inherits Rectangle {fit: fill;fill: Theme.wave;}+ if root.item.wave-hot != "" && !root.banded: Path {+ x: 0;+ y: 0;+ width: parent.width;+ height: parent.height;+ commands: root.item.wave-hot;+ viewbox-width: 1;+ viewbox-height: 1;+ fit: fill;+ fill: Theme.wave-hot;+ }+ // The floor the bars stand on.if root.item.wave != "" && !root.banded: Rectangle {x: 0;- y: (parent.height - 1px) / 2;+ y: parent.height - 1px;width: parent.width;height: 1px;background: Theme.wave-centre;@@ -324,10 +340,22 @@ component Clip inherits Rectangle {fit: fill;fill: Theme.wave-video;}+ if root.item.wave-hot != "": Path {+ x: 0;+ y: 1px;+ width: parent.width;+ height: parent.height - 1px;+ commands: root.item.wave-hot;+ viewbox-width: 1;+ viewbox-height: 1;+ fit: fill;+ fill: Theme.wave-hot;+ }+ // The floor the bars stand on.Rectangle {x: 0;- y: (parent.height - 1px) / 2 + 0.5px;+ y: parent.height - 1px;width: parent.width;height: 1px;background: Theme.wave-centre;diff --git a/src/crates/concat/ui/timeline/model.slint b/src/crates/concat/ui/timeline/model.slintindex 1a213edc..a8b31f0e 100644--- a/src/crates/concat/ui/timeline/model.slint+++ b/src/crates/concat/ui/timeline/model.slint@@ -112,6 +112,9 @@ export struct ClipData {/// that draws it is `fit: fill`, which stretches the box onto whatever/// width the clip currently has. Built once in Rust, where the peaks are.wave: string,+ /// The part of each bar over the hot line, on the same terms, drawn+ /// over `wave` in the hot colour; empty when no bar reaches it.+ wave-hot: string,/// The frames a picture clip tiles along its body; `frames` is 0 when/// there are none yet.strip: StripData,diff --git a/src/crates/concat/ui/workspace/media-pane.slint b/src/crates/concat/ui/workspace/media-pane.slintindex d8851548..1199002a 100644--- a/src/crates/concat/ui/workspace/media-pane.slint+++ b/src/crates/concat/ui/workspace/media-pane.slint@@ -61,6 +61,8 @@ export struct MediaItemData {/// Same shape, same source and same normalisation as a timeline clip's:/// a file should look like itself wherever it is drawn.wave: string,+ /// The part over the hot line, as on a clip.+ wave-hot: string,selected: bool,}@@ -489,6 +491,17 @@ component MediaCard inherits Rectangle {fit: fill;fill: root.mark;}+ if root.item.wave-hot != "": Path {+ x: 0;+ y: 0;+ width: parent.width;+ height: parent.height;+ commands: root.item.wave-hot;+ viewbox-width: 1;+ viewbox-height: 1;+ fit: fill;+ fill: Theme.wave-hot;+ }// What everything else shows before its artwork exists. Large and// faint on purpose: at the badge's own size and colour it read as