Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

meters: adapt the layout to narrow and short panels, move while scrubbing

ReReddo1d1d51cbbdcc
diff --git a/crates/ui-egui/src/panels/meters.rs b/crates/ui-egui/src/panels/meters.rs
index 03555f2d4..66ddfeeb8 100644
--- a/crates/ui-egui/src/panels/meters.rs
+++ b/crates/ui-egui/src/panels/meters.rs
@@ -45,6 +45,96 @@ fn lufs_text(v: f64) -> String {
if v.is_finite() && v > -70.0 { format!("{v:.1}") } else { "—".into() }
}
+const SCALE_FONT: f32 = 8.5;
+const READOUT_FONT: f32 = 9.5;
+
+/// Where the panel's parts go. What doesn't fit is left out rather than drawn over something
+/// else: as the panel narrows, the loudness readout drops its units and then goes, and the dB
+/// scale goes once the bars would get too thin; as it gets shorter, the scale numbers thin out to
+/// every 6, 12 or 24 dB and then go, and the channel names and "dB" under the bars go.
+#[derive(Debug)]
+struct Parts {
+ /// The bars.
+ area: Rect,
+ /// Scale numbers and where their text goes.
+ scale: Vec<(i32, Rect)>,
+ /// "dB" under the scale.
+ unit: Option<Rect>,
+ /// The name under each bar.
+ names: Vec<Rect>,
+ /// The loudness readout, and whether its values keep their units.
+ readout: Option<(Rect, bool)>,
+}
+
+/// Lay out a meter of `names.len()` bars in `rect`; `size` measures a text in a font.
+fn parts(rect: Rect, names: &[&str], size: impl Fn(&str, egui::FontId) -> egui::Vec2) -> Parts {
+ let n = names.len().max(1) as f32;
+ let readout = (rect.height() > 260.0)
+ .then(|| {
+ // a row: the label at the left and the value at the right, 6 inside a box inset 4
+ let room = rect.width() - 20.0;
+ let label = size("TP", Tokens::ui(READOUT_FONT)).x;
+ let fits = |value: &str| label + 6.0 + size(value, Tokens::mono(READOUT_FONT)).x <= room;
+ if fits("-88.8 dBTP") { Some(true) } else { fits("-88.8").then_some(false) }
+ })
+ .flatten();
+ let lufs_h = if readout.is_some() { 64.0 } else { 0.0 };
+ let feet = rect.height() >= 90.0;
+ let top = rect.min.y + 8.0;
+ let bottom = (rect.max.y - lufs_h - if feet { 30.0 } else { 8.0 }).max(top);
+ let h = bottom - top;
+ let widest = size("-57", Tokens::ui(SCALE_FONT));
+ let column = (widest.x + 10.0).max(26.0);
+ let step = [3, 6, 12, 24].into_iter().find(|s| h * *s as f32 / 60.0 >= widest.y).filter(|_| rect.width() - 8.0 - column >= n * 6.0 + 4.0 * (n - 1.0));
+ let right = if step.is_some() { rect.max.x - column } else { rect.max.x - 8.0 };
+ let area = Rect::from_min_max(pos2(rect.min.x + 8.0, top), pos2(right.max(rect.min.x + 8.0), bottom));
+ let text_at = |text: &str, font: egui::FontId, at: egui::Pos2, align: Align2| align.anchor_size(at, size(text, font));
+ let scale: Vec<(i32, Rect)> = step
+ .map(|s| {
+ (0..=57 / s)
+ .map(|k| {
+ let y = area.min.y + h * (k * s) as f32 / 60.0;
+ (-(k * s), text_at(&(-(k * s)).to_string(), Tokens::ui(SCALE_FONT), pos2(rect.max.x - 6.0, y), Align2::RIGHT_CENTER))
+ })
+ .collect()
+ })
+ .unwrap_or_default();
+ let (w, pitch) = bar_pitch(area, names.len());
+ let feet_names: Vec<Rect> = names
+ .iter()
+ .enumerate()
+ .map(|(c, name)| {
+ let (text, font) = foot(name, names.len());
+ text_at(text, font, pos2(area.min.x + c as f32 * pitch + w / 2.0, area.max.y + 16.0), Align2::CENTER_CENTER)
+ })
+ .collect();
+ let names = if feet && feet_names.iter().all(|r| r.width() < pitch) { feet_names } else { Vec::new() };
+ let unit = (feet && step.is_some())
+ .then(|| text_at("dB", Tokens::ui(SCALE_FONT), pos2(rect.max.x - 6.0, area.max.y + 10.0), Align2::RIGHT_CENTER))
+ .filter(|u| !names.iter().chain(scale.iter().map(|(_, r)| r)).any(|r| overlaps(*u, *r)));
+ let readout = readout.map(|units| (Rect::from_min_max(pos2(rect.min.x + 4.0, rect.max.y - lufs_h), pos2(rect.max.x - 4.0, rect.max.y - 4.0)), units));
+ Parts { area, scale, unit, names, readout }
+}
+
+/// The text under a bar of a meter with `n` bars, and its font: an "S" under each bar of a stereo
+/// meter, the channel names under a 5.1 one.
+fn foot(name: &str, n: usize) -> (&str, egui::FontId) {
+ if n == 2 { ("S", Tokens::ui(10.0)) } else { (name, Tokens::ui(SCALE_FONT)) }
+}
+
+/// The width of a bar and the distance from one bar to the next.
+fn bar_pitch(area: Rect, n: usize) -> (f32, f32) {
+ let n = n.max(1) as f32;
+ let gap = if area.width() >= n * 6.0 + 4.0 * (n - 1.0) { 4.0 } else { 1.0 };
+ let w = ((area.width() - gap * (n - 1.0)) / n).max(1.0);
+ (w, w + gap)
+}
+
+fn overlaps(a: Rect, b: Rect) -> bool {
+ let i = a.intersect(b);
+ i.width() > 0.0 && i.height() > 0.0
+}
+
pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
let t = app.tokens;
// levels of the Mix as it plays (fast attack, 20 dB/s release, peak hold)
@@ -54,18 +144,17 @@ pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
let names = filmcraft_audio_dsp::channels::Layout::from_channels(nch).names();
// Premiere: black meter area, scale 0 … −57 dB in 3 dB steps on the right, "dB" at the foot.
// Loudness readout (BS.1770 / EBU R128) under the bars.
- let lufs_h = if rect.height() > 260.0 { 64.0 } else { 0.0 };
- let area = Rect::from_min_max(pos2(rect.min.x + 8.0, rect.min.y + 8.0), pos2(rect.max.x - 26.0, rect.max.y - 30.0 - lufs_h));
- if lufs_h > 0.0 {
+ let parts = parts(rect, names, |text, font| ui.painter().layout_no_wrap(text.to_string(), font, t.text).size());
+ let area = parts.area;
+ if let Some((lr, units)) = parts.readout {
let (m, s, i, tp) = app.loudness.as_ref().map_or((f64::NEG_INFINITY, f64::NEG_INFINITY, f64::NEG_INFINITY, f64::NEG_INFINITY), |(l, _)| {
(l.momentary(), l.short_term(), l.integrated(), l.true_peak_dbtp())
});
- let lr = Rect::from_min_max(pos2(rect.min.x + 4.0, rect.max.y - lufs_h), pos2(rect.max.x - 4.0, rect.max.y - 4.0));
ui.painter().rect_filled(lr, 2.0, t.meter_readout_bg);
let rows = [("M", lufs_text(m)), ("S", lufs_text(s)), ("I", lufs_text(i)), ("TP", lufs_text(tp))];
for (k, (label, val)) in rows.iter().enumerate() {
let y = lr.min.y + 8.0 + k as f32 * 14.0;
- ui.painter().text(pos2(lr.min.x + 6.0, y), Align2::LEFT_CENTER, *label, Tokens::ui(9.5), t.text_dim);
+ ui.painter().text(pos2(lr.min.x + 6.0, y), Align2::LEFT_CENTER, *label, Tokens::ui(READOUT_FONT), t.text_dim);
let hot = *label == "I" || (*label == "TP" && tp > -1.0);
let col = if *label == "TP" && tp > -1.0 {
egui::Color32::from_rgb(0xe0, 0x50, 0x40)
@@ -74,38 +163,163 @@ pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
} else {
t.text
};
- ui.painter().text(
- pos2(lr.max.x - 6.0, y),
- Align2::RIGHT_CENTER,
- format!("{val} {}", if *label == "TP" { "dBTP" } else { "LUFS" }),
- Tokens::mono(9.5),
- col,
- );
+ let unit = match (units, *label == "TP") {
+ (false, _) => "",
+ (true, true) => " dBTP",
+ (true, false) => " LUFS",
+ };
+ ui.painter().text(pos2(lr.max.x - 6.0, y), Align2::RIGHT_CENTER, format!("{val}{unit}"), Tokens::mono(READOUT_FONT), col);
}
app.auto.add("audioMeters.loudness", lr, &format!("M {} S {} I {} LUFS TP {} dBTP", lufs_text(m), lufs_text(s), lufs_text(i), lufs_text(tp)));
}
ui.painter().rect_filled(Rect::from_min_max(pos2(rect.min.x + 4.0, rect.min.y + 4.0), pos2(rect.max.x - 4.0, area.max.y + 4.0)), 0.0, t.meter_bg);
- let w = ((area.width() - 4.0 * (nch as f32 - 1.0)) / nch as f32).max(3.0);
- for c in 0..nch {
- let r = Rect::from_min_size(pos2(area.min.x + c as f32 * (w + 4.0), area.min.y), vec2(w, area.height()));
+ let (w, pitch) = bar_pitch(area, names.len());
+ for (c, name) in names.iter().enumerate() {
+ let r = Rect::from_min_size(pos2(area.min.x + c as f32 * pitch, area.min.y), vec2(w, area.height()));
let m = st.get(c).copied().unwrap_or([-90.0; 2]);
crate::widgets::meter_bar(ui.painter(), r, m[0], m[1], &t);
- app.auto.add(&format!("audioMeters.channel.{}", names[c]), r, &format!("{} {:.1} dB", names[c], m[0]));
+ app.auto.add(&format!("audioMeters.channel.{name}"), r, &format!("{name} {:.1} dB", m[0]));
+ }
+ for (db, r) in &parts.scale {
+ ui.painter().text(r.right_center(), Align2::RIGHT_CENTER, db.to_string(), Tokens::ui(SCALE_FONT), t.text_dim);
}
- let mut db = 0;
- while db >= -57 {
- let y = area.min.y + area.height() * (-db as f32 / 60.0);
- ui.painter().text(pos2(rect.max.x - 6.0, y), Align2::RIGHT_CENTER, format!("{db}"), Tokens::ui(8.5), t.text_dim);
- db -= 3;
+ if let Some(r) = parts.scale.iter().map(|(_, r)| *r).reduce(|a, b| a.union(b)) {
+ let numbers: Vec<String> = parts.scale.iter().map(|(db, _)| db.to_string()).collect();
+ app.auto.add("audioMeters.scale", r, &numbers.join(" "));
}
- ui.painter().text(pos2(rect.max.x - 6.0, area.max.y + 10.0), Align2::RIGHT_CENTER, "dB", Tokens::ui(8.5), t.text_dim);
- for c in 0..nch {
- let r = Rect::from_center_size(pos2(area.min.x + c as f32 * (w + 4.0) + w / 2.0, area.max.y + 16.0), vec2(14.0, 14.0));
- let label = if nch == 2 { "S" } else { names[c] };
- ui.painter().text(r.center(), Align2::CENTER_CENTER, label, Tokens::ui(if nch == 2 { 10.0 } else { 8.5 }), t.text_dim);
+ if let Some(r) = parts.unit {
+ ui.painter().text(r.right_center(), Align2::RIGHT_CENTER, "dB", Tokens::ui(SCALE_FONT), t.text_dim);
+ }
+ for (r, name) in parts.names.iter().zip(names) {
+ let (text, font) = foot(name, names.len());
+ ui.painter().text(r.center(), Align2::CENTER_CENTER, text, font, t.text_dim);
}
if app.playback.playing {
ui.ctx().request_repaint();
}
app.auto.add("audioMeters", area, "Audio Meters");
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// Run `f` with a measure of text in egui's own fonts.
+ fn with_text_size(f: impl FnOnce(&dyn Fn(&str, egui::FontId) -> egui::Vec2)) {
+ let ctx = egui::Context::default();
+ let mut f = Some(f);
+ ctx.run_ui(egui::RawInput::default(), |ui| {
+ if let Some(f) = f.take() {
+ f(&|text, font| ui.painter().layout_no_wrap(text.to_string(), font, egui::Color32::WHITE).size());
+ }
+ })
+ .textures_delta
+ .clear();
+ }
+
+ const STEREO: [&str; 2] = ["L", "R"];
+ const SURROUND: [&str; 6] = ["L", "R", "C", "LFE", "Ls", "Rs"];
+
+ fn at(w: f32, h: f32) -> Rect {
+ Rect::from_min_size(pos2(100.0, 50.0), vec2(w, h))
+ }
+
+ /// The default size in the Editing workspace shows everything, as before.
+ #[test]
+ fn a_roomy_panel_shows_every_part() {
+ with_text_size(|size| {
+ let p = parts(at(116.0, 400.0), &STEREO, size);
+ assert_eq!(p.scale.iter().map(|(db, _)| *db).collect::<Vec<_>>(), (0..20).map(|k| -3 * k).collect::<Vec<_>>());
+ assert!(p.unit.is_some());
+ assert_eq!(p.names.len(), 2);
+ assert_eq!(p.readout.map(|r| r.1), Some(true), "readout with units");
+ });
+ }
+
+ /// Narrowing drops the readout's units, then the readout, then the scale; the bars stay.
+ #[test]
+ fn narrowing_drops_readout_units_then_readout_then_scale() {
+ with_text_size(|size| {
+ let mut seen = Vec::new();
+ for w in (40..=116).rev() {
+ let p = parts(at(w as f32, 400.0), &STEREO, size);
+ let stage = match (p.readout.map(|r| r.1), p.scale.is_empty()) {
+ (Some(true), false) => 0,
+ (Some(false), false) => 1,
+ (None, false) => 2,
+ (None, true) => 3,
+ other => panic!("{w}: {other:?}"),
+ };
+ if seen.last() != Some(&stage) {
+ seen.push(stage);
+ }
+ assert!(p.area.width() >= 10.0, "{w}: bars stay readable");
+ }
+ assert_eq!(seen, [0, 1, 2, 3]);
+ });
+ }
+
+ /// Getting shorter thins the scale out (3, 6, 12, 24 dB apart) and then hides it, and the
+ /// names under the bars go. (The scale gets denser again where the readout or the names
+ /// go and give the bars their room.)
+ #[test]
+ fn shortening_thins_the_scale_then_hides_it() {
+ with_text_size(|size| {
+ let step = |h: i32| {
+ let p = parts(at(116.0, h as f32), &STEREO, size);
+ match p.scale.as_slice() {
+ [] => 99,
+ [_] => 60,
+ [a, b, ..] => a.0 - b.0,
+ }
+ };
+ let mut seen = Vec::new();
+ for range in [261..=400, 90..=260, 10..=89] {
+ let mut steps: Vec<i32> = range.rev().map(step).collect();
+ steps.dedup();
+ assert!(steps.windows(2).all(|s| s[0] < s[1]), "{steps:?}");
+ seen.extend(steps);
+ }
+ seen.sort();
+ seen.dedup();
+ assert_eq!(seen, [3, 6, 12, 24, 99]);
+ for h in 20..=400 {
+ assert_eq!(parts(at(116.0, h as f32), &STEREO, size).names.is_empty(), h < 90, "{h}");
+ }
+ });
+ }
+
+ /// At any size no text overlaps other text, the bars or the readout, and everything stays
+ /// inside the panel.
+ #[test]
+ fn no_text_overlaps_at_any_size() {
+ with_text_size(|size| {
+ for names in [&STEREO[..], &SURROUND[..]] {
+ for w in (20..=400).step_by(3) {
+ for h in (10..=800).step_by(7) {
+ let rect = at(w as f32, h as f32);
+ let p = parts(rect, names, size);
+ let mut texts: Vec<Rect> = p.scale.iter().map(|(_, r)| *r).chain(p.unit).chain(p.names.iter().copied()).collect();
+ if let Some((r, units)) = p.readout {
+ for (k, label) in ["M", "S", "I", "TP"].into_iter().enumerate() {
+ let y = r.min.y + 8.0 + k as f32 * 14.0;
+ let value = if units { "-88.8 dBTP" } else { "-88.8" };
+ let l = Align2::LEFT_CENTER.anchor_size(pos2(r.min.x + 6.0, y), size(label, Tokens::ui(READOUT_FONT)));
+ let v = Align2::RIGHT_CENTER.anchor_size(pos2(r.max.x - 6.0, y), size(value, Tokens::mono(READOUT_FONT)));
+ assert!(!overlaps(l, v) && r.contains_rect(l) && r.contains_rect(v), "{w}×{h} readout row {label}");
+ }
+ texts.push(r);
+ }
+ for (i, a) in texts.iter().enumerate() {
+ assert!(rect.contains_rect(*a), "{w}×{h}: {a:?} outside {rect:?}");
+ assert!(!overlaps(*a, p.area), "{w}×{h}: {a:?} over the bars {:?}", p.area);
+ for b in texts.iter().skip(i + 1) {
+ assert!(!overlaps(*a, *b), "{w}×{h} {}ch: {a:?} overlaps {b:?}", names.len());
+ }
+ }
+ }
+ }
+ }
+ });
+ }
+}
diff --git a/crates/ui-egui/src/panels/mixer.rs b/crates/ui-egui/src/panels/mixer.rs
index bcc1b42af..49dfb9d7b 100644
--- a/crates/ui-egui/src/panels/mixer.rs
+++ b/crates/ui-egui/src/panels/mixer.rs
@@ -106,7 +106,8 @@ pub fn poll_meters(app: &mut FilmcraftApp, ui: &egui::Ui) -> HashMap<u64, Vec<[f
m[1] = (m[1] - 6.0 * dt).max(-90.0);
}
}
- let live = app.playback.playing || app.session.voiceover.recording();
+ // scrubbing plays through the same mixer, so its grains move the meters too
+ let live = app.playback.playing || app.session.voiceover.recording() || app.scrub.is_open();
if live {
for (k, p) in fresh {
let e = st.entry(k).or_default();
diff --git a/crates/ui-egui/tests/meters_ui.rs b/crates/ui-egui/tests/meters_ui.rs
new file mode 100644
index 000000000..8d835ecfb
--- /dev/null
+++ b/crates/ui-egui/tests/meters_ui.rs
@@ -0,0 +1,172 @@
+//! The Audio Meters panel, driven headless through the control channel: what it shows as it gets
+//! narrower (the loudness readout and the dB scale give way, the bars stay), and that it moves
+//! while the playhead is scrubbed with audio scrubbing on.
+
+use std::sync::mpsc::{Sender, channel};
+use std::sync::{Arc, Mutex};
+
+use egui_kittest::Harness;
+use filmcraft_engine::Session;
+use filmcraft_ui_egui::control::ControlRequest;
+use filmcraft_ui_egui::dock::{DockNode, PanelKind, SplitSize};
+use filmcraft_ui_egui::{AudioOut, FilmcraftApp};
+use serde_json::{Value, json};
+
+type Fill = Box<dyn FnMut(&mut [f32], usize) + Send>;
+
+/// An output that keeps the callback it was started with, for the test to pull samples from.
+struct Out {
+ fill: Arc<Mutex<Option<Fill>>>,
+}
+
+impl AudioOut for Out {
+ fn start(&mut self, fill: Fill) -> Result<u32, String> {
+ *self.fill.lock().unwrap() = Some(fill);
+ Ok(48_000)
+ }
+ fn stop(&mut self) {
+ *self.fill.lock().unwrap() = None;
+ }
+ fn sample_rate(&self) -> u32 {
+ 48_000
+ }
+ fn played_frames(&self) -> Option<u64> {
+ None
+ }
+}
+
+struct Driver {
+ harness: Harness<'static, FilmcraftApp>,
+ tx: Sender<ControlRequest>,
+ fill: Arc<Mutex<Option<Fill>>>,
+}
+
+impl Driver {
+ fn demo() -> Self {
+ let mut session = Session::default();
+ session.execute("file.openDemoProject", json!({})).expect("demo project");
+ session.prefs.audio.scrub_audio = true;
+ let (tx, rx) = channel();
+ let fill = Arc::new(Mutex::new(None));
+ let mut app = FilmcraftApp::new(session).with_control(rx);
+ app.audio = Some(Box::new(Out { fill: fill.clone() }));
+ let harness = Harness::builder().with_size(egui::vec2(1600.0, 980.0)).with_max_steps(10_000).build_eframe(move |_cc| app);
+ let mut d = Driver { harness, tx, fill };
+ d.frames(4);
+ d
+ }
+ fn frames(&mut self, n: usize) {
+ for _ in 0..n {
+ let ctx = self.harness.ctx.clone();
+ let mut raw = std::mem::take(self.harness.input_mut());
+ eframe::App::raw_input_hook(self.harness.state_mut(), &ctx, &mut raw);
+ *self.harness.input_mut() = raw;
+ self.harness.step();
+ }
+ }
+ fn call(&mut self, method: &str, params: Value) -> Value {
+ let (req, reply) = ControlRequest::new(method, params.clone());
+ self.tx.send(req).unwrap();
+ for _ in 0..600 {
+ self.frames(1);
+ if let Ok(v) = reply.try_recv() {
+ return v;
+ }
+ }
+ panic!("no reply to {method} {params}");
+ }
+ fn ok(&mut self, method: &str, params: Value) -> Value {
+ let r = self.call(method, params.clone());
+ assert_eq!(r["ok"], true, "{method} {params}: {r}");
+ r["result"].clone()
+ }
+ fn element(&mut self, id: &str) -> Option<Value> {
+ let v = self.ok("ui.elements", json!({"prefix": id}));
+ v.as_array().unwrap().iter().find(|e| e["id"] == id).cloned()
+ }
+ fn label(&mut self, id: &str) -> String {
+ self.element(id).and_then(|e| e["label"].as_str().map(str::to_string)).unwrap_or_default()
+ }
+ /// Give the Audio Meters panel `width` points (it sits in a fixed-width split beside the
+ /// Timeline).
+ fn meters_width(&mut self, width: f32) {
+ fn set(n: &mut DockNode, width: f32) -> bool {
+ match n {
+ DockNode::Split { size, b, .. } if matches!(&**b, DockNode::Tabs { panels, .. } if panels.as_slice() == [PanelKind::AudioMeters]) => {
+ *size = SplitSize::FixedB(width);
+ true
+ }
+ DockNode::Split { a, b, .. } => set(a, width) || set(b, width),
+ DockNode::Tabs { .. } => false,
+ }
+ }
+ assert!(set(&mut self.harness.state_mut().ui.dock, width));
+ self.frames(3);
+ }
+ /// The level the left bar shows, in dB.
+ fn left_db(&mut self) -> f32 {
+ let label = self.label("audioMeters.channel.L");
+ label.split_whitespace().nth(1).and_then(|v| v.parse().ok()).unwrap_or_else(|| panic!("label {label:?}"))
+ }
+}
+
+/// As the panel narrows the loudness readout goes and then the dB scale, while the bars stay; at
+/// the default width it shows all of them, the scale every 3 dB.
+#[test]
+fn a_narrow_meter_panel_drops_the_readout_and_then_the_scale() {
+ let mut d = Driver::demo();
+ assert!(d.element("audioMeters.loudness").is_some(), "the readout at the default width");
+ assert_eq!(d.label("audioMeters.scale").split(' ').count(), 20, "0 to -57 every 3 dB");
+ d.meters_width(60.0);
+ assert!(d.element("audioMeters.loudness").is_none(), "no room for the readout");
+ assert!(d.element("audioMeters.scale").is_some());
+ d.meters_width(44.0);
+ assert!(d.element("audioMeters.scale").is_none(), "no room for the scale");
+ for name in ["L", "R"] {
+ let bar = d.element(&format!("audioMeters.channel.{name}")).unwrap();
+ assert!(bar["rect"][2].as_f64().unwrap() >= 5.0, "the {name} bar stays readable: {bar}");
+ }
+ d.meters_width(116.0);
+ assert!(d.element("audioMeters.loudness").is_some());
+}
+
+/// Dragging the playhead along the ruler with audio scrubbing on plays grains of the sequence, and
+/// the meters show them, as they do in playback.
+#[test]
+fn the_meters_move_while_scrubbing() {
+ let mut d = Driver::demo();
+ assert_eq!(d.left_db(), -90.0, "silent before");
+ let ruler = d.element("timeline.ruler").expect("the Timeline ruler");
+ let r = &ruler["rect"];
+ let (x, y, w) = (r[0].as_f64().unwrap() as f32, r[1].as_f64().unwrap() as f32 + r[3].as_f64().unwrap() as f32 / 2.0, r[2].as_f64().unwrap() as f32);
+ let (from, to) = (egui::pos2(x + w * 0.2, y), egui::pos2(x + w * 0.3, y));
+ d.harness.input_mut().events.push(egui::Event::PointerMoved(from));
+ d.harness.input_mut().events.push(egui::Event::PointerButton {
+ pos: from,
+ button: egui::PointerButton::Primary,
+ pressed: true,
+ modifiers: Default::default(),
+ });
+ d.frames(1);
+ d.harness.input_mut().events.push(egui::Event::PointerMoved(to));
+ // the playhead moves in this frame; the next one hears it
+ d.frames(2);
+ // the device asks for the grain
+ {
+ let mut fill = d.fill.lock().unwrap();
+ let f = fill.as_mut().expect("scrubbing opened the output");
+ let mut buf = vec![0.0; 4096 * 2];
+ f(&mut buf, 2);
+ assert!(buf.iter().any(|s| *s != 0.0), "the grain has sound");
+ }
+ d.frames(2);
+ let db = d.left_db();
+ assert!(db > -60.0, "the meter shows the grain: {db} dB");
+ d.harness.input_mut().events.push(egui::Event::PointerButton {
+ pos: to,
+ button: egui::PointerButton::Primary,
+ pressed: false,
+ modifiers: Default::default(),
+ });
+ d.frames(1);
+}