FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
#223: audio waveforms follow the clip volume
Oskare9baec015468
diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rsindex 70a18c30c..30351a763 100644--- a/crates/ui-egui/src/panels/timeline.rs+++ b/crates/ui-egui/src/panels/timeline.rs@@ -734,6 +734,8 @@ fn draw_waveform(app: &mut FilmcraftApp, p: &egui::Painter, body: Rect, it: &Trafor (a, b) in peaks.iter().skip(s0).take(s1 - s0) {m = m.max(a.abs()).max(b.abs());}+ // as in Premiere, the waveform shows the clip's Volume+ m *= super::timeline_volume::gain_at(it, t0);// View ▸ Dynamic Audio Waveforms (default): logarithmic scale, −48 dB → 0, 0 dB → full;// off: linear amplitudelet h = if dynamic {diff --git a/crates/ui-egui/src/panels/timeline_volume.rs b/crates/ui-egui/src/panels/timeline_volume.rsindex a0330383b..c6a052507 100644--- a/crates/ui-egui/src/panels/timeline_volume.rs+++ b/crates/ui-egui/src/panels/timeline_volume.rs@@ -38,6 +38,15 @@ fn level_at(it: &TrackItem, t: Tick) -> f64 {level(it).map_or(0.0, |p| p.f64_at(it.source_time_at(t)))}+/// The clip's Volume as a gain at timeline time `t`, for its waveform (1 when Volume is off or+/// bypassed, as the mixer plays it).+pub fn gain_at(it: &TrackItem, t: Tick) -> f32 {+ match it.effect("volume").filter(|e| e.enabled && !e.param("bypass").and_then(|p| p.value.as_bool()).unwrap_or(false)) {+ Some(e) => filmcraft_render::audio::db_to_gain(e.f64_at("level", it.source_time_at(t))),+ None => 1.0,+ }+}+/// Timeline time of media time `m`, the inverse of [`TrackItem::moving_source_time_at`].fn timeline_time(it: &TrackItem, m: Tick) -> Tick {let rel = if it.reverse { it.source_out().0.saturating_sub(1).saturating_sub(m.0) } else { m.0.saturating_sub(it.source_in.0) };@@ -352,6 +361,18 @@ mod tests {}}+ #[test]+ fn the_waveform_gain_is_the_volume_that_plays() {+ let mut it = clip(1.0, false);+ assert_eq!(gain_at(&it, Tick(2_000)), 1.0);+ let e = it.effect_mut("volume").unwrap();+ e.param_mut("level").unwrap().value = filmcraft_project::ParamValue::Float(-6.0);+ assert!((gain_at(&it, Tick(2_000)) - 0.501).abs() < 0.01);+ let e = it.effect_mut("volume").unwrap();+ e.param_mut("bypass").unwrap().value = filmcraft_project::ParamValue::Bool(true);+ assert_eq!(gain_at(&it, Tick(2_000)), 1.0, "bypassed");+ }+#[test]fn the_line_follows_the_level() {let mut it = clip(1.0, false);