From c80b281d7d7b4931f59aa57fe85e42ca476fba3d Mon Sep 17 00:00:00 2001 From: Chris Laupama <42254688+chrislaupama@users.noreply.github.com> Date: Sun, 15 Nov 2026 23:02:25 +0000 Subject: [PATCH 1/4] Add expanded Utility and Stereo Widener windows with correlation metering --- crates/dstudio-app/src/device_window.rs | 155 ++++++++++++- .../dstudio-app/src/device_window_widener.rs | 217 ++++++++++++++++++ crates/dstudio-app/src/main.rs | 1 + crates/dstudio-engine/src/ffi.rs | 1 + crates/dstudio-engine/src/lib.rs | 6 + engine/include/dstudio_engine.h | 8 + engine/src/c_api.cpp | 9 + engine/src/devices/builtin.cpp | 22 ++ engine/src/devices/builtin.hpp | 15 ++ engine/src/engine.cpp | 9 + engine/src/engine.hpp | 1 + engine/tests/devices/test_builtin.cpp | 36 +++ 12 files changed, 479 insertions(+), 1 deletion(-) create mode 100644 crates/dstudio-app/src/device_window_widener.rs diff --git a/crates/dstudio-app/src/device_window.rs b/crates/dstudio-app/src/device_window.rs index 8743af41..ab415da9 100644 --- a/crates/dstudio-app/src/device_window.rs +++ b/crates/dstudio-app/src/device_window.rs @@ -123,6 +123,7 @@ pub(crate) fn has_window(def: &DeviceDef) -> bool { def.id, "auto-filter" | "channeleq" | "character-eq" | "transient-shaper" | "multiband-compressor" | "delay" | "reverb" | "echo" ) || is_wave_window(def) + || matches!(def.id, "utility" | "widener") || def.id == "bitcrusher" || is_field_window(def) || is_dynamics_window(def) @@ -180,6 +181,10 @@ pub(crate) fn kit(def: &DeviceDef) -> Kit { "multiband-compressor" => field_kit(WIN_W, 336.0, 52.0, 43.0), // Waveshapers: the transfer square and the wave over a dB axis and legend. "distortion" | "tapesaturation" | "soft-clipper" => field_kit(WAVE_W, 454.0, 60.0, 44.0), + // Utility: three cards and no display; the meters run the window's height. + "utility" => Kit { w: 1200.0, display: (INSET, 52.0, 1042.0, 620.0), plot: (0.0, 0.0, 0.0, 0.0), narrow: false }, + // Stereo Widener: the field over the correlation lane. + "widener" => Kit { w: 1200.0, display: (INSET, 52.0, 1042.0, 514.0), plot: (36.0, 25.0, 12.0, 8.0), narrow: false }, // Bit Crusher: one crushed cycle fills the display. "bitcrusher" => field_kit(WAVE_W, 454.0, 8.0, 8.0), "tremolo" => field_kit(WIN_W, 234.0, 60.0, 44.0), @@ -229,6 +234,8 @@ pub(crate) struct WinUi { loud_from: HashMap, /// Start of the histories' clock. epoch: Option, + /// Stereo Widener: input and output correlation of the open windows. + pub(crate) corr: HashMap>, } /// Which signal a window's analyser shows. @@ -594,6 +601,8 @@ enum Item { Momentary(&'static str, &'static str, &'static str, f32), /// Two choice pickers stacked in one column: (parameter, label) of each, name, width, inert. Pickers2([(i32, String); 2], &'static str, f32, bool), + /// A latch pill with a fixed label (lit while on): parameter, label, name, width, inert. + Latch(&'static str, &'static str, &'static str, f32, bool), /// Fixed blank (keeps a column's width). Blank(f32), } @@ -612,6 +621,7 @@ impl Item { Item::LatchPicker(.., w) => *w, Item::Pickers2(_, _, w, _) => *w, Item::Momentary(.., w) => *w, + Item::Latch(.., w, _) => *w, Item::Blank(w) => *w, } } @@ -626,7 +636,9 @@ impl Controller { let k = kit(def); let mut b = Builder::new(accent, k.w); let (dx, dy, dw, dh) = k.display; - b.rect(BOX_DISPLAY, dx, dy, dw, dh); + if def.id != "utility" { + b.rect(BOX_DISPLAY, dx, dy, dw, dh); + } let mut display = match def.layout.view { Some(View::Eq(v)) => self.eq_window_field(d, def, v, accent), Some(View::Custom("auto-filter")) => self.auto_filter_window_field(d, def, accent), @@ -636,6 +648,7 @@ impl Controller { _ if def.id == "multiband-compressor" => self.multiband_window_canvas(d, def, &k, accent), _ if is_wave_window(def) => self.wave_window_canvas(d, def, &k, accent), _ if def.id == "bitcrusher" => self.crush_window_canvas(d, def, &k, accent), + _ if def.id == "widener" => self.widener_window_canvas(d, def, &k, accent), Some(View::Custom(_)) if crate::panel_fields::field_name(def).is_some() => self.field_window_display(d, def, &k), _ => PanelCanvas::default(), }; @@ -652,6 +665,8 @@ impl Controller { "reverb" => self.reverb_window(d, def, &mut b, dy + dh + 12.0), "echo" => self.echo_window(d, def, &mut b, dy + dh + 12.0), _ if is_wave_window(def) || def.id == "bitcrusher" => self.wave_window(d, def, &mut b, dy + dh + 12.0), + "utility" => self.utility_window(d, def, &mut b), + "widener" => self.widener_window(d, def, &mut b, dy + dh + 12.0), _ => self.field_window(d, def, &mut b, dy + dh + 12.0), }; let (meters, ticks, ticks_x) = self.window_meters(d.id, &k); @@ -748,6 +763,7 @@ impl Controller { .collect(); self.devices.wins.meters.retain(|id, _| open.contains(id)); self.devices.wins.history.retain(|id, _| open.contains(id)); + self.devices.wins.corr.retain(|id, _| open.contains(id)); let epoch = *self.devices.wins.epoch.get_or_insert(now); let t = now.duration_since(epoch).as_secs_f64(); let mut out = Vec::new(); @@ -798,6 +814,16 @@ impl Controller { if self.engine.builtin_levels(id.0, &mut raw).is_err() { raw = [0.0; 4]; } + if self.project().device(id).and_then(dstudio_core::builtin::def_of).is_some_and(|def| def.id == "widener") + && !self.devices.wins.held.contains(&id) + { + let mut c = [2.0f32; 2]; + if self.engine.builtin_correlation(id.0, &mut c).is_err() { + c = [2.0; 2]; + } + crate::device_window_widener::push_corr(self.devices.wins.corr.entry(id).or_default(), (t, c[0], c[1])); + self.ui_dirty = true; + } let m = self.devices.wins.meters.entry(id).or_insert_with(Meters::new); let before = (m.level, m.hold, m.since_clip[0] < Meters::CLIP_HOLD, m.since_clip[1] < Meters::CLIP_HOLD); m.push(raw, dt); @@ -958,6 +984,13 @@ impl Controller { } b.name(x, w, row.name_y(), name, inert); } + Item::Latch(id, label, name, w, inert) => { + let pw = pill_w(label) + 12.0; + b.rect(BOX_TRACK, x + (w - pw - 4.0) / 2.0, top + row.pill - 2.0, pw + 4.0, 28.0); + let p = b.pill(PILL_TOGGLE, idx(id), 0, x + (w - pw) / 2.0, top + row.pill, pw, label, val(id) >= 0.5); + p.inert = inert; + b.name(x, w, row.name_y(), name, inert); + } Item::Blank(_) => {} } x += w + gap; @@ -1546,6 +1579,74 @@ impl Controller { row.y + row.h + 16.0 } + /// Utility: three cards in the face's left part, each its controls centred: Channel + /// Mode and the two phase switches; Width, Mono, Bass Mono with its frequency and + /// Listen; Gain, Balance, Mute and DC Filter. + fn utility_window(&self, d: &Device, def: &'static DeviceDef, b: &mut Builder) -> f32 { + let idx = |id: &str| def.index_of(id).map_or(-1, |i| i as i32); + let val = |id: &str| def.param(id).map_or(0.0, |p| self.panel_value(d, def, p)); + let label = |id: &str| def.param(id).map_or_else(String::new, |p| p.format(self.panel_value(d, def, p))); + let knob = |id, name, size, w, inert| Item::Knob(id, name, size, w, inert); + let full = b.w; + b.w = kit(def).display.2 + 2.0 * INSET; + let bass = val("bass_mono") >= 0.5; + let rows = [ + ( + Row { y: 60.0, h: 96.0, dial: 28.0, value: 45.0, pill: 11.0, picker: 11.0 }, + vec![ + Item::Picker(idx("channel_mode"), label("channel_mode"), "Channel Mode", 116.0, false), + Item::ToggleW("phase_l", "Phase L", 100.0), + Item::ToggleW("phase_r", "Phase R", 56.0), + ], + ), + ( + Row { y: 168.0, h: 112.0, dial: 29.0, value: 54.0, pill: 27.0, picker: 27.0 }, + vec![ + knob("width", "Width", 1, 78.0, false), + Item::ToggleW("mono", "Mono", 78.0), + Item::ToggleW("bass_mono", "Bass Mono", 106.0), + knob("bass_mono_freq", "Frequency", 1, 52.0, !bass), + Item::Latch("bass_mono_audition", "Listen", "Audition", 120.0, !bass), + ], + ), + ( + Row { y: 292.0, h: 118.0, dial: 32.0, value: 59.0, pill: 35.0, picker: 35.0 }, + vec![ + knob("gain", "Gain", 2, 81.0, false), + knob("balance", "Balance", 1, 87.0, false), + Item::ToggleW("mute", "Mute", 92.0), + Item::ToggleW("dc_filter", "DC Filter", 64.0), + ], + ), + ]; + for (row, items) in rows { + self.win_card(d, def, b, row, vec![(items, 0.0)]); + } + b.w = full; + 700.0 + } + + /// Stereo Widener: one card under the display: Width and Low Cut, Mid and Side Gain, Mix. + fn widener_window(&self, d: &Device, def: &'static DeviceDef, b: &mut Builder, y: f32) -> f32 { + let knob = |id, name, size, w| Item::Knob(id, name, size, w, false); + let full = b.w; + b.w = kit(def).display.2 + 2.0 * INSET; + let row = Row::main(y); + self.win_card( + d, + def, + b, + row, + vec![ + (vec![knob("width2", "Width", 2, 76.0), knob("lowcut", "Low Cut", 2, 76.0)], 10.0), + (vec![knob("midgain", "Mid Gain", 1, 76.0), knob("sidegain", "Side Gain", 1, 76.0)], 2.0), + (vec![knob("mix", "Mix", 2, 76.0)], 10.0), + ], + ); + b.w = full; + row.y + row.h + 16.0 + } + /// Transient Shaper: Hold view in the header; one card with Attack and Sustain, Sense, /// the shape picture (its handles set the two times), then Mix, Output and Clip. fn shaper_window(&self, d: &Device, def: &'static DeviceDef, b: &mut Builder, y: f32) -> f32 { @@ -3046,6 +3147,56 @@ mod tests { assert!(((card.x + card.w) / Z - (dx + dw)).abs() < 0.5, "{}", (card.x + card.w) / Z); } + /// Utility: no display, three cards with every control, the meters down the face. + #[test] + fn utility_window_shows_three_cards_and_every_control() { + use slint::Model; + let (mut c, did, def) = controller_with("utility"); + assert!(has_window(def)); + let v = view(&c, did, def); + assert!((v.w / Z - 1200.0).abs() < 0.5 && (v.h / Z - 700.0).abs() < 0.5, "{} x {}", v.w / Z, v.h / Z); + assert!(!v.boxes.iter().any(|b| b.kind == BOX_DISPLAY)); + assert_eq!(v.boxes.iter().filter(|b| b.kind == BOX_CARD).count(), 3); + let idx = |p: &str| def.index_of(p).unwrap() as i32; + for k in ["width", "bass_mono_freq", "gain", "balance"] { + assert!(v.knobs.iter().any(|n| n.param == idx(k)), "{k}"); + } + for t in ["channel_mode", "phase_l", "phase_r", "mono", "bass_mono", "bass_mono_audition", "mute", "dc_filter"] { + assert!(v.pills.iter().any(|p| p.param == idx(t)), "{t}"); + } + // The bass-mono controls are inert until Bass Mono is on. + assert!(v.pills.iter().any(|p| p.param == idx("bass_mono_audition") && p.inert)); + c.execute(Command::SetDeviceParam { device: did, param: "bass_mono".into(), value: 1.0 }); + let v = view(&c, did, def); + assert!(v.pills.iter().any(|p| p.param == idx("bass_mono_audition") && !p.inert && p.label == "Listen")); + assert!(v.meters.iter().all(|m| m.h / Z > 500.0)); + } + + /// Stereo Widener: the field caption reads the width at the top of the axis, and the + /// correlation lane draws its two series once there is history. + #[test] + fn widener_window_draws_the_field_and_the_correlation_lane() { + use slint::Model; + let (mut c, did, def) = controller_with("widener"); + assert!(has_window(def)); + let v = view(&c, did, def); + assert!((v.w / Z - 1200.0).abs() < 0.5 && (v.h / Z - 700.0).abs() < 0.5, "{} x {}", v.w / Z, v.h / Z); + assert!(v.display.texts.iter().any(|t| t.text == "Stereo Field")); + assert!(v.display.texts.iter().any(|t| t.text == "Correlation")); + let before = v.display.paths.row_count(); + let h = c.devices.wins.corr.entry(did).or_default(); + for i in 0..360 { + crate::device_window_widener::push_corr(h, (i as f64 / 60.0, 0.8, 0.2)); + } + let after = view(&c, did, def).display.paths.row_count(); + assert_eq!(after, before + 2); + let idx = |p: &str| def.index_of(p).unwrap() as i32; + for k in ["width2", "lowcut", "midgain", "sidegain", "mix"] { + assert!(v.knobs.iter().any(|n| n.param == idx(k)), "{k}"); + } + assert!(v.display.zones.iter().any(|z| z.param_y == idx("width2"))); + } + /// A full ten-second history draws as one line per series, however many samples it holds. #[test] fn dynamics_history_draws_once_per_series() { @@ -3081,6 +3232,8 @@ mod tests { "tapesaturation", "soft-clipper", "bitcrusher", + "utility", + "widener", ] { let (mut c, did, def) = controller_with(id); let h: std::collections::VecDeque<_> = diff --git a/crates/dstudio-app/src/device_window_widener.rs b/crates/dstudio-app/src/device_window_widener.rs new file mode 100644 index 00000000..f86cf241 --- /dev/null +++ b/crates/dstudio-app/src/device_window_widener.rs @@ -0,0 +1,217 @@ +//! Stereo Widener's expanded window display: the stereo field (effective width against +//! frequency, 20 Hz..2 kHz on a 0..400 % ladder, lit between the curve and 100 %), and +//! under it a correlation lane with the input and output correlation over the last +//! seconds (+1 in phase, 0 uncorrelated, −1 cancels in mono). A vertical drag on the +//! field sets Width. + +use crate::PanelCanvas; +use crate::controller::Controller; +use crate::device_canvas::{fill, path, rgba, stroke, text, white}; +use crate::device_panel::Z; +use crate::device_window::Kit; +use crate::{PanelPath, PanelText, PanelZone}; +use dstudio_core::builtin::{self, DeviceDef}; +use dstudio_core::{Device, DeviceId}; +use slint::{Color, ModelRc, VecModel}; +use std::collections::VecDeque; +use std::rc::Rc; + +fn model(v: Vec) -> ModelRc { + ModelRc::from(Rc::new(VecModel::from(v))) +} + +/// The field's frequency axis (Hz) and width ladder (%). +const F_LO: f32 = 20.0; +const F_HI: f32 = 2000.0; +const PCT_TOP: f32 = 400.0; +const HZ_TICKS: [(f32, &str); 5] = [(50.0, "50"), (100.0, "100"), (200.0, "200"), (500.0, "500"), (1000.0, "1k")]; +/// Field height and the lane under it (pt, from the plot top). +const FIELD_H: f32 = 300.0; +const LANE_Y: f32 = 359.0; +const LANE_H: f32 = 120.0; +/// Seconds the correlation lane shows, one grid division each. +pub(crate) const CORR_SPAN: f64 = 6.0; +const FILL: f32 = 0.22; +/// A correlation reading of a silent side. +const SILENT: f32 = 1.5; + +/// One correlation reading: (time s, input, output); above 1 where that side was silent. +pub(crate) type CorrSample = (f64, f32, f32); + +/// Appends a reading and drops those older than the lane shows. +pub(crate) fn push_corr(h: &mut VecDeque, s: CorrSample) { + h.push_back(s); + while h.front().is_some_and(|f| f.0 < s.0 - CORR_SPAN - 0.5) { + h.pop_front(); + } +} + +/// Polyline commands of one series, broken where it was silent. +fn series( + h: &VecDeque, + now: f64, + pick: fn(&CorrSample) -> f32, + x_of: impl Fn(f64) -> f32, + y_of: impl Fn(f32) -> f32, +) -> String { + let mut out = String::new(); + let mut open = false; + for s in h.iter().filter(|s| s.0 >= now - CORR_SPAN) { + let c = pick(s); + if c > SILENT { + open = false; + continue; + } + let (x, y) = (x_of(s.0), y_of(c)); + out.push_str(&format!("{}{x:.1} {y:.1} ", if open { "L" } else { "M" })); + open = true; + } + out +} + +impl Controller { + /// The correlation history the Widener window draws. + pub(crate) fn win_corr(&self, id: DeviceId) -> Option<&VecDeque> { + self.devices.wins.corr.get(&id) + } + + pub(crate) fn widener_window_canvas(&self, d: &Device, def: &'static DeviceDef, k: &Kit, accent: Color) -> PanelCanvas { + let v = |id: &str| def.param(id).map_or(0.0, |p| self.panel_value(d, def, p)); + let (_, _, dw, dh) = k.display; + let (pl, pt, pr, pb) = k.plot; + let (pw, ph) = ((dw - pl - pr) * Z, (dh - pt - pb) * Z); + let (width, mid_db, side_db, low, mix) = (v("width2"), v("midgain"), v("sidegain"), v("lowcut"), v("mix")); + let resp = |f: f32| builtin::widener_response(f, width, mid_db, side_db, low, mix, 48_000.0); + let fh = FIELD_H * Z; + let x_of = |f: f32| (f.clamp(F_LO, F_HI) / F_LO).ln() / (F_HI / F_LO).ln() * pw; + let y_of = |pct: f32| fh * (1.0 - (pct / PCT_TOP).clamp(0.0, 1.0)); + let dim = white(0.32); + let mut paths: Vec = Vec::new(); + let mut texts: Vec = Vec::new(); + + // The field: grid, ladder, axis. + let mut grid = String::new(); + for (f, label) in HZ_TICKS { + let x = x_of(f).round() + 0.5; + grid.push_str(&format!("M{x:.1} 0 V{fh:.1} ")); + texts.push(text(x - 20.0 * Z, fh + 10.0 * Z, 40.0 * Z, label, dim, 10.0 * Z, 1)); + } + for pct in [100.0, 200.0, 300.0] { + let y = y_of(pct).round() + 0.5; + grid.push_str(&format!("M0 {y:.1} H{pw:.1} ")); + texts.push(text(-44.0 * Z, y_of(pct), 36.0 * Z, format!("{pct:.0}"), dim, 10.0 * Z, 2)); + } + grid.push_str(&format!("M0 {fh:.1} H{pw:.1} M{pw:.1} 0 V{fh:.1}")); + paths.push(stroke(grid, white(0.05), 1.0)); + texts.push(text(-44.0 * Z, fh + 10.0 * Z, 36.0 * Z, "%", dim, 10.0 * Z, 2)); + texts.push(text(pw - 40.0 * Z, fh + 10.0 * Z, 40.0 * Z, "Hz", dim, 10.0 * Z, 2)); + + // The width curve, lit against 100 %. + let n = ((pw / Z) / 4.0).round().max(48.0) as usize; + let curve: Vec<(f32, f32)> = (0..=n) + .map(|i| { + let f = F_LO * (F_HI / F_LO).powf(i as f32 / n as f32); + (x_of(f), y_of(resp(f))) + }) + .collect(); + let line = path(&curve); + let unity = y_of(100.0); + paths.push(fill(format!("{line} L{pw:.1} {unity:.1} L0 {unity:.1} Z"), rgba(accent, FILL))); + paths.push(stroke(line, accent, 1.25 * Z)); + + // Caption above the field. + let cy = -(pt - 12.0) * Z; + let cx = -(pl - 14.0) * Z; + texts.push(text(cx, cy, 120.0 * Z, "Stereo Field", white(0.55), 12.0 * Z, 0)); + let at = cx + (crate::text_measure::value_width("Stereo Field") + 14.0) * Z; + texts.push(text(at, cy, 120.0 * Z, format!("{:.0}%", resp(F_HI)), white(0.92), 13.0 * Z, 0)); + + // The correlation lane: caption and legend, grid, the two series. + let (ly, lh) = (LANE_Y * Z, LANE_H * Z); + let ky = ly - 13.0 * Z; + texts.push(text(cx, ky, 120.0 * Z, "Correlation", white(0.55), 12.0 * Z, 0)); + let mut x = cx + (crate::text_measure::value_width("Correlation") + 14.0) * Z; + let glyph = 14.0 * Z; + for (label, ink) in [("In", white(0.5)), ("Out", accent)] { + paths.push(stroke(format!("M{x:.1} {ky:.1} h{glyph:.1}"), ink, 1.25 * Z)); + texts.push(text(x + glyph + 6.0 * Z, ky, 60.0 * Z, label, white(0.7), 10.0 * Z, 0)); + x += glyph + 6.0 * Z + (crate::text_measure::value_width(label) + 16.0) * Z; + } + x += 4.0 * Z; + for label in ["+1 in phase", "0 uncorrelated", "\u{2212}1 cancels in mono"] { + texts.push(text(x, ky, 160.0 * Z, label, white(0.3), 10.0 * Z, 0)); + x += (crate::text_measure::value_width(label) + 14.0) * Z; + } + let mut lane = String::new(); + for i in 0..=4 { + let y = (ly + lh * i as f32 / 4.0).round() + 0.5; + lane.push_str(&format!("M0 {y:.1} H{pw:.1} ")); + } + for i in 1..6 { + let x = (pw * i as f32 / 6.0).round() + 0.5; + lane.push_str(&format!("M{x:.1} {ly:.1} V{:.1} ", ly + lh)); + } + paths.push(stroke(lane, white(0.05), 1.0)); + let mid = (ly + lh / 2.0).round() + 0.5; + paths.push(stroke(format!("M0 {mid:.1} H{pw:.1}"), white(0.12), 1.0)); + if let Some(h) = self.win_corr(d.id) { + let now = h.back().map_or(0.0, |s| s.0); + let tx = |t: f64| pw - ((now - t) / CORR_SPAN) as f32 * pw; + let cy = |c: f32| ly + lh * (1.0 - c.clamp(-1.0, 1.0)) / 2.0; + let input = series(h, now, |s| s.1, tx, cy); + let output = series(h, now, |s| s.2, tx, cy); + if !input.is_empty() { + paths.push(stroke(input, white(0.5), 1.25 * Z)); + } + if !output.is_empty() { + paths.push(stroke(output, accent, 1.5 * Z)); + } + } + + // A vertical drag on the field sets Width. + let zones = vec![PanelZone { + x: 0.0, + y: 0.0, + w: pw, + h: fh, + param_x: -1, + param_y: def.index_of("width2").map_or(-1, |i| i as i32), + rate_x: 0.0, + rate_y: 1.0 / fh, + }]; + PanelCanvas { + visible: true, + w: pw, + h: ph, + paths: model(paths), + texts: model(texts), + zones: model(zones), + label: "Stereo Field".into(), + ..Default::default() + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn correlation_history_keeps_the_lane_span_and_breaks_at_silence() { + let mut h = VecDeque::new(); + for i in 0..800 { + let t = i as f64 / 60.0; + push_corr(&mut h, (t, if (300..360).contains(&i) { 2.0 } else { 0.5 }, 1.0)); + } + assert!(h.front().unwrap().0 >= h.back().unwrap().0 - CORR_SPAN - 0.5); + let now = h.back().unwrap().0; + let s = series(&h, now, |s| s.1, |t| t as f32, |c| c); + assert_eq!(s.matches('M').count(), 1, "no silence in view: one run"); + let mut h2 = VecDeque::new(); + for i in 0..300 { + push_corr(&mut h2, (i as f64 / 60.0, if (100..160).contains(&i) { 2.0 } else { 0.0 }, 0.0)); + } + let s2 = series(&h2, h2.back().unwrap().0, |s| s.1, |t| t as f32, |c| c); + assert_eq!(s2.matches('M').count(), 2, "silence splits the run"); + } +} diff --git a/crates/dstudio-app/src/main.rs b/crates/dstudio-app/src/main.rs index f6f6a892..6108cb8f 100644 --- a/crates/dstudio-app/src/main.rs +++ b/crates/dstudio-app/src/main.rs @@ -60,6 +60,7 @@ mod device_window_fields; mod device_window_multiband; mod device_window_shaper; mod device_window_wave; +mod device_window_widener; mod devices; mod devminimap; mod dialogs; diff --git a/crates/dstudio-engine/src/ffi.rs b/crates/dstudio-engine/src/ffi.rs index b365d567..2a2e51f8 100644 --- a/crates/dstudio-engine/src/ffi.rs +++ b/crates/dstudio-engine/src/ffi.rs @@ -998,6 +998,7 @@ unsafe extern "C" { pub fn se_builtin_readouts(engine: *mut se_engine, device_id: u64, out: *mut f32, capacity: usize, out_count: *mut usize) -> i32; pub fn se_builtin_set_metering(engine: *mut se_engine, device_id: u64, on: u8) -> i32; pub fn se_builtin_levels(engine: *mut se_engine, device_id: u64, out: *mut f32) -> i32; + pub fn se_builtin_correlation(engine: *mut se_engine, device_id: u64, out: *mut f32) -> i32; pub fn se_builtin_set_spectrum(engine: *mut se_engine, device_id: u64, mode: u8) -> i32; pub fn se_builtin_spectrum( engine: *mut se_engine, diff --git a/crates/dstudio-engine/src/lib.rs b/crates/dstudio-engine/src/lib.rs index 29e8fa09..8f41ce41 100644 --- a/crates/dstudio-engine/src/lib.rs +++ b/crates/dstudio-engine/src/lib.rs @@ -607,6 +607,12 @@ impl Engine { check(unsafe { ffi::se_builtin_levels(self.raw, device_id, out.as_mut_ptr()) }) } + /// Stereo correlation of a live built-in device's input and output since the previous + /// call (-1..1; 2 where that side was silent or metering is off). + pub fn builtin_correlation(&self, device_id: u64, out: &mut [f32; 2]) -> Result<(), EngineError> { + check(unsafe { ffi::se_builtin_correlation(self.raw, device_id, out.as_mut_ptr()) }) + } + /// Number of bins in an analyser frame ([`Engine::builtin_spectrum`]). pub const SPECTRUM_BINS: usize = 128; diff --git a/engine/include/dstudio_engine.h b/engine/include/dstudio_engine.h index ce65e1e1..d5e38ed3 100644 --- a/engine/include/dstudio_engine.h +++ b/engine/include/dstudio_engine.h @@ -1278,6 +1278,14 @@ int32_t se_builtin_set_metering(se_engine* engine, uint64_t device_id, uint8_t o * -> SE_ERR_INVALID_ARG. */ int32_t se_builtin_levels(se_engine* engine, uint64_t device_id, float* out); +/* Stereo correlation of a live built-in device's input (out[0]) and output + * (out[1]) since the previous call: -1 cancels in mono, 0 uncorrelated, +1 in + * phase; 2 where that side was silent or metering is off. Reading resets it. + * Measured while metering is on (se_builtin_set_metering). + * MAIN THREAD. Unknown or non-built-in device -> SE_ERR_NOT_FOUND; out NULL + * -> SE_ERR_INVALID_ARG. */ +int32_t se_builtin_correlation(se_engine* engine, uint64_t device_id, float* out); + /* The analyser of a built-in device's expanded window: mode 0 off, 1 the * device's input (Pre), 2 its output (Post). While it is on the audio thread * measures a 128-bin log-spaced level spectrum (20 Hz .. 20 kHz, dBFS, floor diff --git a/engine/src/c_api.cpp b/engine/src/c_api.cpp index 782c3195..03bbc8c7 100644 --- a/engine/src/c_api.cpp +++ b/engine/src/c_api.cpp @@ -806,6 +806,15 @@ int32_t se_builtin_levels(se_engine* engine, uint64_t device_id, float* out) { }); } +int32_t se_builtin_correlation(se_engine* engine, uint64_t device_id, float* out) { + SE_REQUIRE_ENGINE(engine); + if (out == nullptr) return fail(SE_ERR_INVALID_ARG, "out is NULL"); + return guarded([&]() -> int32_t { + const int32_t rc = engine->impl->builtin_correlation(device_id, out); + return rc == SE_OK ? rc : fail(rc, "no live built-in device with this id"); + }); +} + int32_t se_builtin_set_spectrum(se_engine* engine, uint64_t device_id, uint8_t mode) { SE_REQUIRE_ENGINE(engine); if (mode > 2) return fail(SE_ERR_INVALID_ARG, "mode must be 0 (off), 1 (pre) or 2 (post)"); diff --git a/engine/src/devices/builtin.cpp b/engine/src/devices/builtin.cpp index 80ba8f02..125d2006 100644 --- a/engine/src/devices/builtin.cpp +++ b/engine/src/devices/builtin.cpp @@ -450,6 +450,26 @@ void accumulate_peak(std::atomic& slot, const float* x, uint32_t frames) while (p > cur && !slot.compare_exchange_weak(cur, p, std::memory_order_relaxed)) { } } +// A block's (sum LR, sum LL, sum RR) added to three running sums (RT; the main thread +// resets them to 0). Mono input (r == nullptr) counts as fully correlated. +void accumulate_correlation(std::atomic* slot, const float* l, const float* r, uint32_t frames) noexcept { + if (l == nullptr) return; + const float* rr = r != nullptr ? r : l; + float s[3] = {0.0f, 0.0f, 0.0f}; + for (uint32_t i = 0; i < frames; ++i) { + s[0] += l[i] * rr[i]; + s[1] += l[i] * l[i]; + s[2] += rr[i] * rr[i]; + } + for (int k = 0; k < 3; ++k) { + if (!std::isfinite(s[k])) return; + } + for (int k = 0; k < 3; ++k) { + float cur = slot[k].load(std::memory_order_relaxed); + while (!slot[k].compare_exchange_weak(cur, cur + s[k], std::memory_order_relaxed)) { + } + } +} } // namespace void BuiltinInstance::process(float* l, float* r, uint32_t frames, const MidiEvent* events, uint32_t event_count, @@ -459,6 +479,7 @@ void BuiltinInstance::process(float* l, float* r, uint32_t frames, const MidiEve if (metering) { accumulate_peak(peaks_[0], l, frames); accumulate_peak(peaks_[1], r, frames); + accumulate_correlation(&corr_[0], l, r, frames); } const int spec_mode = spectrum_mode_.load(std::memory_order_relaxed); WindowSpectrum* const spec = spec_mode != 0 ? spectrum_rt_.load(std::memory_order_acquire) : nullptr; @@ -556,6 +577,7 @@ void BuiltinInstance::process(float* l, float* r, uint32_t frames, const MidiEve if (metering) { accumulate_peak(peaks_[2], l, frames); accumulate_peak(peaks_[3], r, frames); + accumulate_correlation(&corr_[3], l, r, frames); } if (spec != nullptr && spec_mode == 2) spec->push(l, r, frames); sc_l_ = sc_r_ = nullptr; diff --git a/engine/src/devices/builtin.hpp b/engine/src/devices/builtin.hpp index 9f3f2b00..9572acce 100644 --- a/engine/src/devices/builtin.hpp +++ b/engine/src/devices/builtin.hpp @@ -21,7 +21,9 @@ #include "../spsc_queue.hpp" #include "dstudio_engine.h" +#include #include +#include #include #include #include @@ -246,6 +248,18 @@ class BuiltinInstance final : public PluginInstance { void take_levels(float* out) noexcept { for (int i = 0; i < 4; ++i) out[i] = peaks_[i].exchange(0.0f, std::memory_order_relaxed); } + // Main thread: stereo correlation of the input and the output since the last take + // (-1 cancels in mono, 0 uncorrelated, +1 in phase); 2 where a side was silent. + // Measured while metering is on; reset by taking it. + void take_correlation(float* out) noexcept { + for (int k = 0; k < 2; ++k) { + const float lr = corr_[3 * k].exchange(0.0f, std::memory_order_relaxed); + const float ll = corr_[3 * k + 1].exchange(0.0f, std::memory_order_relaxed); + const float rr = corr_[3 * k + 2].exchange(0.0f, std::memory_order_relaxed); + const float d = ll * rr; + out[k] = d > 1e-12f ? std::clamp(lr / std::sqrt(d), -1.0f, 1.0f) : 2.0f; + } + } // Main thread: the expanded window's analyser: 0 off, 1 the input (Pre), // 2 the output (Post). The analyser is built on first use and kept. void set_spectrum(int mode); @@ -319,6 +333,7 @@ class BuiltinInstance final : public PluginInstance { std::unique_ptr[]> readout_atomic_; std::atomic metering_{false}; std::atomic peaks_[4] = {}; // in L, in R, out L, out R since the last take_levels + std::atomic corr_[6] = {}; // (sum LR, sum LL, sum RR) of the input, then the output std::unique_ptr spectrum_; // built by the main thread, kept std::atomic spectrum_rt_{nullptr}; // published to the audio thread std::atomic spectrum_mode_{0}; // 0 off, 1 input, 2 output diff --git a/engine/src/engine.cpp b/engine/src/engine.cpp index bdda8fe6..ba8f2c3c 100644 --- a/engine/src/engine.cpp +++ b/engine/src/engine.cpp @@ -1973,6 +1973,15 @@ int32_t Engine::builtin_levels(uint64_t device_id, float* out) { return SE_OK; } +int32_t Engine::builtin_correlation(uint64_t device_id, float* out) { + std::lock_guard lock(plugins_.mutex()); + PluginInstance* inst = plugins_.instance(device_id); + BuiltinInstance* b = inst != nullptr ? inst->as_builtin() : nullptr; + if (b == nullptr) return SE_ERR_NOT_FOUND; + b->take_correlation(out); + return SE_OK; +} + int32_t Engine::builtin_set_spectrum(uint64_t device_id, int mode) { std::lock_guard lock(plugins_.mutex()); PluginInstance* inst = plugins_.instance(device_id); diff --git a/engine/src/engine.hpp b/engine/src/engine.hpp index c395b66c..346f9525 100644 --- a/engine/src/engine.hpp +++ b/engine/src/engine.hpp @@ -146,6 +146,7 @@ class Engine final : private AudioDevice::Callback { int32_t builtin_analysis(uint64_t device_id, float* out, std::size_t capacity, std::size_t& count, uint64_t& seq); int32_t builtin_set_metering(uint64_t device_id, bool on); int32_t builtin_levels(uint64_t device_id, float* out); + int32_t builtin_correlation(uint64_t device_id, float* out); int32_t builtin_set_spectrum(uint64_t device_id, int mode); int32_t builtin_spectrum(uint64_t device_id, float* out, std::size_t capacity, std::size_t& count, uint64_t& seq); // Plugin card controls and modulation bases (main thread; see dstudio_engine.h). diff --git a/engine/tests/devices/test_builtin.cpp b/engine/tests/devices/test_builtin.cpp index b36ae142..7bb070ca 100644 --- a/engine/tests/devices/test_builtin.cpp +++ b/engine/tests/devices/test_builtin.cpp @@ -413,6 +413,42 @@ TEST_CASE(builtin_metering_reports_in_and_out_peaks_without_allocating) { CHECK_EQ(se_builtin_levels(e, 10, nullptr), SE_ERR_INVALID_ARG); } +TEST_CASE(builtin_metering_reports_stereo_correlation) { + EngineHandle e(48000, 256); + // Right is the left inverted: the input cancels in mono. + const uint64_t a = load_asset(e, {sine(48000, 440.0, 48000.0, 0.5), sine(48000, 440.0, 48000.0, -0.5)}); + DeviceSession s; + auto& tr = s.add_track(1, a, 48000); + DeviceSession::add_device(tr, 10, "compressor", kComp); + REQUIRE(s.publish(e) == SE_OK); + REQUIRE(se_transport_play(e) == SE_OK); + std::vector buf(2 * 256); + float c[2] = {0.f, 0.f}; + + // Off by default: both sides read as silent. + REQUIRE(se_render_offline(e, buf.data(), 256) == SE_OK); + REQUIRE(se_builtin_correlation(e, 10, c) == SE_OK); + CHECK_EQ(c[0], 2.0f); + CHECK_EQ(c[1], 2.0f); + + REQUIRE(se_builtin_set_metering(e, 10, 1) == SE_OK); + const long before = rt_alloc_count(); + for (int i = 0; i < 8; ++i) { + RtAllocGuard g; + REQUIRE(se_render_offline(e, buf.data(), 256) == SE_OK); + } + CHECK_EQ(rt_alloc_count() - before, 0); + REQUIRE(se_builtin_correlation(e, 10, c) == SE_OK); + CHECK(c[0] < -0.99f); + CHECK(c[1] < -0.9f); + + // Reading resets it. + REQUIRE(se_builtin_correlation(e, 10, c) == SE_OK); + CHECK_EQ(c[0], 2.0f); + CHECK_EQ(se_builtin_correlation(e, 999, c), SE_ERR_NOT_FOUND); + CHECK_EQ(se_builtin_correlation(e, 10, nullptr), SE_ERR_INVALID_ARG); +} + TEST_CASE(builtin_window_spectrum_measures_pre_and_post) { EngineHandle e(48000, 256); const uint64_t a = load_asset(e, {sine(48000, 1000.0, 48000.0, 0.5), sine(48000, 1000.0, 48000.0, 0.5)}); From 03ef6772532b840893a47f2fe178b484f534fa6a Mon Sep 17 00:00:00 2001 From: Chris Laupama <42254688+chrislaupama@users.noreply.github.com> Date: Sun, 15 Nov 2026 23:25:35 +0000 Subject: [PATCH 2/4] Run the Widener and Bit Crusher meters down the face; align the field labels --- crates/dstudio-app/src/device_window.rs | 25 +++++++++++++------ .../dstudio-app/src/device_window_widener.rs | 17 +++++++++---- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/crates/dstudio-app/src/device_window.rs b/crates/dstudio-app/src/device_window.rs index ab415da9..29cb00ed 100644 --- a/crates/dstudio-app/src/device_window.rs +++ b/crates/dstudio-app/src/device_window.rs @@ -153,11 +153,13 @@ pub(crate) struct Kit { pub plot: (f32, f32, f32, f32), /// The narrow strip (114 wide, columns of 54) of the field windows; else the EQs' 136. narrow: bool, + /// Height of the meter strip when it runs past the display (0: the display's). + meters_h: f32, } /// Field windows: a display 152 narrower than the window, a 12 pt gap to the control card. fn field_kit(w: f32, display_h: f32, left: f32, bottom: f32) -> Kit { - Kit { w, display: (INSET, 52.0, w - 152.0, display_h), plot: (left, 25.0, 8.0, bottom), narrow: true } + Kit { w, display: (INSET, 52.0, w - 152.0, display_h), plot: (left, 25.0, 8.0, bottom), narrow: true, meters_h: 0.0 } } pub(crate) fn kit(def: &DeviceDef) -> Kit { @@ -166,6 +168,7 @@ pub(crate) fn kit(def: &DeviceDef) -> Kit { display: (INSET, y, WIN_W - 2.0 * INSET - METERS_W - METERS_GAP, h), plot: (PLOT_L, PLOT_T, PLOT_R, PLOT_B), narrow: false, + meters_h: 0.0, }; match def.id { "character-eq" => eq(52.0, 346.0), @@ -174,7 +177,7 @@ pub(crate) fn kit(def: &DeviceDef) -> Kit { // Echo: the tape strip above a display of the tail. "echo" => Kit { plot: (8.0, 25.0, 8.0, 8.0), ..eq(160.0, 354.0) }, // Reverb: a 1200 pt window; the tail picture fills the display. - "reverb" => Kit { w: 1200.0, display: (INSET, 56.0, 1020.0, 510.0), plot: (8.0, 8.0, 8.0, 8.0), narrow: false }, + "reverb" => Kit { w: 1200.0, display: (INSET, 56.0, 1020.0, 510.0), plot: (8.0, 8.0, 8.0, 8.0), narrow: false, meters_h: 0.0 }, // Transient Shaper: the scope fills the display; its legend sits on the caption row. "transient-shaper" => field_kit(880.0, 228.0, 8.0, 8.0), // Multiband: the band field over the dB ladder, its Hz axis and legend below. @@ -182,11 +185,12 @@ pub(crate) fn kit(def: &DeviceDef) -> Kit { // Waveshapers: the transfer square and the wave over a dB axis and legend. "distortion" | "tapesaturation" | "soft-clipper" => field_kit(WAVE_W, 454.0, 60.0, 44.0), // Utility: three cards and no display; the meters run the window's height. - "utility" => Kit { w: 1200.0, display: (INSET, 52.0, 1042.0, 620.0), plot: (0.0, 0.0, 0.0, 0.0), narrow: false }, + "utility" => Kit { w: 1200.0, display: (INSET, 52.0, 1042.0, 630.0), plot: (0.0, 0.0, 0.0, 0.0), narrow: true, meters_h: 0.0 }, // Stereo Widener: the field over the correlation lane. - "widener" => Kit { w: 1200.0, display: (INSET, 52.0, 1042.0, 514.0), plot: (36.0, 25.0, 12.0, 8.0), narrow: false }, + // Its meters run down past the card, as the Bit Crusher's. + "widener" => Kit { w: 1200.0, display: (INSET, 52.0, 1042.0, 514.0), plot: (36.0, 25.0, 12.0, 8.0), narrow: true, meters_h: 630.0 }, // Bit Crusher: one crushed cycle fills the display. - "bitcrusher" => field_kit(WAVE_W, 454.0, 8.0, 8.0), + "bitcrusher" => Kit { meters_h: 575.0, ..field_kit(WAVE_W, 454.0, 8.0, 8.0) }, "tremolo" => field_kit(WIN_W, 234.0, 60.0, 44.0), "autopanner" => field_kit(WIN_W, 234.0, 40.0, 44.0), "chorus" | "flanger" => field_kit(WIN_W, 354.0, 56.0, 44.0), @@ -692,7 +696,8 @@ impl Controller { /// the field windows' is 114, two 54 pt columns with the bar at the left of each. fn window_meters(&self, id: DeviceId, k: &Kit) -> (Vec, Vec, f32) { let m = self.devices.wins.meters.get(&id).cloned().unwrap_or_else(Meters::new); - let (dx, y, dw, h) = k.display; + let (dx, y, dw, dh) = k.display; + let h = if k.meters_h > 0.0 { k.meters_h } else { dh }; let (top, bar_h) = if k.narrow { (y + 26.2, h - 48.2) } else { (y + 22.0, h - 44.0) }; let x = dx + dw + if k.narrow { 6.0 } else { METERS_GAP }; // (bar x, label centre) of each column. @@ -821,8 +826,12 @@ impl Controller { if self.engine.builtin_correlation(id.0, &mut c).is_err() { c = [2.0; 2]; } - crate::device_window_widener::push_corr(self.devices.wins.corr.entry(id).or_default(), (t, c[0], c[1])); - self.ui_dirty = true; + // Both sides empty: no block ran since the last poll, or silence; the lane + // breaks across the gap. + if c[0] <= 1.0 || c[1] <= 1.0 { + crate::device_window_widener::push_corr(self.devices.wins.corr.entry(id).or_default(), (t, c[0], c[1])); + self.ui_dirty = true; + } } let m = self.devices.wins.meters.entry(id).or_insert_with(Meters::new); let before = (m.level, m.hold, m.since_clip[0] < Meters::CLIP_HOLD, m.since_clip[1] < Meters::CLIP_HOLD); diff --git a/crates/dstudio-app/src/device_window_widener.rs b/crates/dstudio-app/src/device_window_widener.rs index f86cf241..a25142d2 100644 --- a/crates/dstudio-app/src/device_window_widener.rs +++ b/crates/dstudio-app/src/device_window_widener.rs @@ -32,6 +32,8 @@ const LANE_H: f32 = 120.0; /// Seconds the correlation lane shows, one grid division each. pub(crate) const CORR_SPAN: f64 = 6.0; const FILL: f32 = 0.22; +/// Readings further apart than this (s) are not joined. +const GAP_S: f64 = 0.25; /// A correlation reading of a silent side. const SILENT: f32 = 1.5; @@ -46,7 +48,7 @@ pub(crate) fn push_corr(h: &mut VecDeque, s: CorrSample) { } } -/// Polyline commands of one series, broken where it was silent. +/// Polyline commands of one series, broken where it was silent or readings stopped. fn series( h: &VecDeque, now: f64, @@ -56,12 +58,17 @@ fn series( ) -> String { let mut out = String::new(); let mut open = false; + let mut last = f64::NEG_INFINITY; for s in h.iter().filter(|s| s.0 >= now - CORR_SPAN) { let c = pick(s); if c > SILENT { open = false; continue; } + if s.0 - last > GAP_S { + open = false; + } + last = s.0; let (x, y) = (x_of(s.0), y_of(c)); out.push_str(&format!("{}{x:.1} {y:.1} ", if open { "L" } else { "M" })); open = true; @@ -94,17 +101,17 @@ impl Controller { for (f, label) in HZ_TICKS { let x = x_of(f).round() + 0.5; grid.push_str(&format!("M{x:.1} 0 V{fh:.1} ")); - texts.push(text(x - 20.0 * Z, fh + 10.0 * Z, 40.0 * Z, label, dim, 10.0 * Z, 1)); + texts.push(text(x, fh + 10.0 * Z, 40.0 * Z, label, dim, 10.0 * Z, 1)); } for pct in [100.0, 200.0, 300.0] { let y = y_of(pct).round() + 0.5; grid.push_str(&format!("M0 {y:.1} H{pw:.1} ")); - texts.push(text(-44.0 * Z, y_of(pct), 36.0 * Z, format!("{pct:.0}"), dim, 10.0 * Z, 2)); + texts.push(text(-8.0 * Z, y_of(pct), 36.0 * Z, format!("{pct:.0}"), dim, 10.0 * Z, 2)); } grid.push_str(&format!("M0 {fh:.1} H{pw:.1} M{pw:.1} 0 V{fh:.1}")); paths.push(stroke(grid, white(0.05), 1.0)); - texts.push(text(-44.0 * Z, fh + 10.0 * Z, 36.0 * Z, "%", dim, 10.0 * Z, 2)); - texts.push(text(pw - 40.0 * Z, fh + 10.0 * Z, 40.0 * Z, "Hz", dim, 10.0 * Z, 2)); + texts.push(text(-8.0 * Z, fh + 10.0 * Z, 36.0 * Z, "%", dim, 10.0 * Z, 2)); + texts.push(text(pw, fh + 10.0 * Z, 40.0 * Z, "Hz", dim, 10.0 * Z, 2)); // The width curve, lit against 100 %. let n = ((pw / Z) / 4.0).round().max(48.0) as usize; From beb75f2316d37b0f69dab58c7bff64ead628569a Mon Sep 17 00:00:00 2001 From: Chris Laupama <42254688+chrislaupama@users.noreply.github.com> Date: Sun, 15 Nov 2026 23:49:00 +0000 Subject: [PATCH 3/4] Add the expanded Tuner window; document the utility windows --- CHANGELOG.md | 4 ++ README.md | 3 +- crates/dstudio-app/src/analyzer_views.rs | 8 +++- crates/dstudio-app/src/device_window.rs | 59 +++++++++++++++++++++++- docs/devices.md | 9 +++- 5 files changed, 76 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 35ce4def..ed20728e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -58,3 +58,7 @@ Nothing has been released yet. The first release, 0.1.0, will cover what is on ` - Expanded windows for Distortion, Tape Saturation and Soft Clipper (the static transfer on a 48 dB square with the gain or clipping it applies lit against unity, two cycles of a full-scale sine through the device, and every control in one card) and Bit Crusher (one crushed cycle across the display under its held rate and number of levels). +- Expanded windows for Utility (its controls on three cards, the meters down the face) and Stereo Widener (the stereo + field over frequency above a correlation lane that plots the input and output correlation of the last six seconds). + The engine measures a built-in device's stereo correlation while its window is open (`se_builtin_correlation`). +- An expanded window for Tuner: the card's tuner at twice its size across the display, with its input meter. diff --git a/README.md b/README.md index c92ff0ab..3e472611 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,8 @@ Limiter adds a short-term loudness lane against a target), Transient Shaper, who gain it applied, and Multiband Compressor, whose window draws each band's level, gain and thresholds on a frequency axis with draggable crossovers, and Delay, Echo and Reverb, whose window draws the card's echo train, tail picture or repeat EQ at full size with every control in a row below, Distortion, Tape Saturation and Soft Clipper, whose window draws -the transfer curve beside a sine through the device, and Bit Crusher, whose window draws one crushed cycle; the other devices open their card in a window for now. +the transfer curve beside a sine through the device, Bit Crusher, whose window draws one crushed cycle, Utility, and Stereo Widener, whose window draws the stereo +field over a live correlation lane, and Tuner; the other devices open their card in a window for now. [docs/devices.md](docs/devices.md) explains how they work and how to add one. | Kind | Devices | diff --git a/crates/dstudio-app/src/analyzer_views.rs b/crates/dstudio-app/src/analyzer_views.rs index fa7547ee..ef616972 100644 --- a/crates/dstudio-app/src/analyzer_views.rs +++ b/crates/dstudio-app/src/analyzer_views.rs @@ -484,8 +484,12 @@ impl Controller { } fn tuner_canvas(&self, d: &Device, def: &'static DeviceDef, w_pt: f32, accent: Color) -> PanelCanvas { - let z = Z; - let (w, h) = (w_pt, TUNER_BOTTOM - FIELD_Y); // unscaled; scaled on output + self.tuner_canvas_at(d, def, w_pt, TUNER_BOTTOM - FIELD_Y, Z, accent) + } + + /// The tuner picture `w` x `h` units drawn at `z` px per unit (the card's is Z; the + /// expanded window draws it larger). + pub(crate) fn tuner_canvas_at(&self, d: &Device, def: &'static DeviceDef, w: f32, h: f32, z: f32, accent: Color) -> PanelCanvas { let empty = TunerView::default(); let tv = self.devices.panel.analyzers.tuners.get(&d.id).unwrap_or(&empty); let tuning = def.param("tuning").map_or(0, |p| self.panel_value(d, def, p).round() as usize).min(TUNING_STRINGS.len() - 1); diff --git a/crates/dstudio-app/src/device_window.rs b/crates/dstudio-app/src/device_window.rs index 29cb00ed..ea2d78cf 100644 --- a/crates/dstudio-app/src/device_window.rs +++ b/crates/dstudio-app/src/device_window.rs @@ -105,6 +105,9 @@ pub(crate) const MENU_TARGET: i32 = -5; pub(crate) const MENU_MB_BAND: i32 = -6; /// The Multiband Compressor's bands, as its band picker names them. const MB_BANDS: [&str; 3] = ["Low", "Mid", "High"]; +/// Height (units at twice the card's scale) of the Tuner window's picture: it puts the bar +/// across the middle of the display. +const TUNER_WIN_H: f32 = 194.0; /// Width of the waveshaper and Bit Crusher windows. const WAVE_W: f32 = 960.0; /// Panel-menu code of the Delay's repeat-EQ band picker. @@ -123,7 +126,7 @@ pub(crate) fn has_window(def: &DeviceDef) -> bool { def.id, "auto-filter" | "channeleq" | "character-eq" | "transient-shaper" | "multiband-compressor" | "delay" | "reverb" | "echo" ) || is_wave_window(def) - || matches!(def.id, "utility" | "widener") + || matches!(def.id, "utility" | "widener" | "tuner") || def.id == "bitcrusher" || is_field_window(def) || is_dynamics_window(def) @@ -187,6 +190,8 @@ pub(crate) fn kit(def: &DeviceDef) -> Kit { // Utility: three cards and no display; the meters run the window's height. "utility" => Kit { w: 1200.0, display: (INSET, 52.0, 1042.0, 630.0), plot: (0.0, 0.0, 0.0, 0.0), narrow: true, meters_h: 0.0 }, // Stereo Widener: the field over the correlation lane. + // Tuner: the bar across a tall display, one In meter beside it. + "tuner" => Kit { w: 1200.0, display: (INSET, 52.0, 1108.0, 550.0), plot: (0.0, 0.0, 0.0, 0.0), narrow: true, meters_h: 0.0 }, // Its meters run down past the card, as the Bit Crusher's. "widener" => Kit { w: 1200.0, display: (INSET, 52.0, 1042.0, 514.0), plot: (36.0, 25.0, 12.0, 8.0), narrow: true, meters_h: 630.0 }, // Bit Crusher: one crushed cycle fills the display. @@ -653,6 +658,8 @@ impl Controller { _ if is_wave_window(def) => self.wave_window_canvas(d, def, &k, accent), _ if def.id == "bitcrusher" => self.crush_window_canvas(d, def, &k, accent), _ if def.id == "widener" => self.widener_window_canvas(d, def, &k, accent), + // The card's tuner at twice its scale, its bar across the middle of the display. + _ if def.id == "tuner" => self.tuner_canvas_at(d, def, k.display.2 / 2.0, TUNER_WIN_H, 2.0 * Z, accent), Some(View::Custom(_)) if crate::panel_fields::field_name(def).is_some() => self.field_window_display(d, def, &k), _ => PanelCanvas::default(), }; @@ -671,9 +678,15 @@ impl Controller { _ if is_wave_window(def) || def.id == "bitcrusher" => self.wave_window(d, def, &mut b, dy + dh + 12.0), "utility" => self.utility_window(d, def, &mut b), "widener" => self.widener_window(d, def, &mut b, dy + dh + 12.0), + "tuner" => self.tuner_window(d, def, &mut b, dy + dh + 14.0), _ => self.field_window(d, def, &mut b, dy + dh + 12.0), }; - let (meters, ticks, ticks_x) = self.window_meters(d.id, &k); + let (mut meters, ticks, mut ticks_x) = self.window_meters(d.id, &k); + // The Tuner meters its input only. + if def.id == "tuner" { + meters.truncate(1); + ticks_x = meters[0].x / Z + 38.0; + } Some(WinView { visible: true, w: k.w * Z, @@ -1635,6 +1648,30 @@ impl Controller { 700.0 } + /// Tuner: a short card: Tuning and Reference, then Mute Output. + fn tuner_window(&self, d: &Device, def: &'static DeviceDef, b: &mut Builder, y: f32) -> f32 { + let idx = |id: &str| def.index_of(id).map_or(-1, |i| i as i32); + let label = |id: &str| def.param(id).map_or_else(String::new, |p| p.format(self.panel_value(d, def, p))); + let row = Row { y, h: 68.0, dial: 20.0, value: 17.0, pill: 4.0, picker: 4.0 }; + self.win_card( + d, + def, + b, + row, + vec![ + ( + vec![ + Item::Picker(idx("tuning"), label("tuning"), "Tuning", 124.0, false), + Item::Picker(idx("reference"), label("reference"), "Reference", 124.0, false), + ], + 0.0, + ), + (vec![Item::ToggleW("mute_output", "Mute Output", 96.0)], 0.0), + ], + ); + row.y + row.h + 16.0 + } + /// Stereo Widener: one card under the display: Width and Low Cut, Mid and Side Gain, Mix. fn widener_window(&self, d: &Device, def: &'static DeviceDef, b: &mut Builder, y: f32) -> f32 { let knob = |id, name, size, w| Item::Knob(id, name, size, w, false); @@ -3206,6 +3243,23 @@ mod tests { assert!(v.display.zones.iter().any(|z| z.param_y == idx("width2"))); } + /// Tuner: the bar across the display, one In meter, a short card with every control. + #[test] + fn tuner_window_shows_the_bar_and_one_meter() { + use slint::Model; + let (c, did, def) = controller_with("tuner"); + assert!(has_window(def)); + let v = view(&c, did, def); + assert!((v.w / Z - 1200.0).abs() < 0.5 && (v.h / Z - 700.0).abs() < 0.5, "{} x {}", v.w / Z, v.h / Z); + assert_eq!(v.meters.row_count(), 1); + assert_eq!(v.meters.row_data(0).unwrap().label, "In"); + assert!(v.display.visible && v.display.paths.row_count() > 0); + let idx = |p: &str| def.index_of(p).unwrap() as i32; + for p in ["tuning", "reference", "mute_output"] { + assert!(v.pills.iter().any(|q| q.param == idx(p)), "{p}"); + } + } + /// A full ten-second history draws as one line per series, however many samples it holds. #[test] fn dynamics_history_draws_once_per_series() { @@ -3243,6 +3297,7 @@ mod tests { "bitcrusher", "utility", "widener", + "tuner", ] { let (mut c, did, def) = controller_with(id); let h: std::collections::VecDeque<_> = diff --git a/docs/devices.md b/docs/devices.md index ff20e24d..ea8ed5e4 100644 --- a/docs/devices.md +++ b/docs/devices.md @@ -67,7 +67,7 @@ flowchart LR Flanger, Phaser, Ring Mod and Character Mod; and the dynamics family: Compressor, Limiter, Gate, Glue Compressor, Character Compressor and Mastering Limiter; Transient Shaper; Multiband Compressor; Delay, Echo and Reverb; Distortion, Tape Saturation, - Soft Clipper and Bit Crusher), otherwise the card itself in a window. A + Soft Clipper and Bit Crusher; Utility, Stereo Widener and Tuner), otherwise the card itself in a window. A window is a face 960 pt wide (Ring Mod 860): a top bar (power, presets, the device's header pills), a large display (the card's canvas drawn at window size with its axis and legend), In / Out meters, and rows of controls laid out with the same @@ -123,7 +123,12 @@ flowchart LR (src/device_window_wave.rs) draw the static transfer from the core's `distortion_transfer`, `tape_transfer` and `clipper_transfer` as the sine peak out against the sine peak in on a 48 dB square, and the Bit Crusher - draws `crush_picture` across its display. The + draws `crush_picture` across its display. Utility's window has no display, + only three cards. The Stereo Widener's correlation lane reads + `se_builtin_correlation` (`Engine::builtin_correlation`): while metering is + on the audio thread sums L·R, L² and R² of the input and the output of each + block, and each poll takes them as a correlation per side (2 where a side + was silent). The meters read `se_builtin_set_metering` / `se_builtin_levels` (`Engine::builtin_levels(id, &mut [f32; 4])`): while a window is open the audio thread keeps the input and output peak of each block, and the app From c4dccf890abeb6a9c8ae525ff8b15401bdede02e Mon Sep 17 00:00:00 2001 From: Chris Laupama <42254688+chrislaupama@users.noreply.github.com> Date: Mon, 16 Nov 2026 00:16:41 +0000 Subject: [PATCH 4/4] Draw the Tuner window's picture without its own well --- crates/dstudio-app/src/device_window.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/dstudio-app/src/device_window.rs b/crates/dstudio-app/src/device_window.rs index ea2d78cf..2d3b3b81 100644 --- a/crates/dstudio-app/src/device_window.rs +++ b/crates/dstudio-app/src/device_window.rs @@ -659,7 +659,9 @@ impl Controller { _ if def.id == "bitcrusher" => self.crush_window_canvas(d, def, &k, accent), _ if def.id == "widener" => self.widener_window_canvas(d, def, &k, accent), // The card's tuner at twice its scale, its bar across the middle of the display. - _ if def.id == "tuner" => self.tuner_canvas_at(d, def, k.display.2 / 2.0, TUNER_WIN_H, 2.0 * Z, accent), + _ if def.id == "tuner" => { + PanelCanvas { well: false, ..self.tuner_canvas_at(d, def, k.display.2 / 2.0, TUNER_WIN_H, 2.0 * Z, accent) } + } Some(View::Custom(_)) if crate::panel_fields::field_name(def).is_some() => self.field_window_display(d, def, &k), _ => PanelCanvas::default(), };