From 611443481d017832552fe1558164d5c3c51b1667 Mon Sep 17 00:00:00 2001 From: Chris Laupama <42254688+chrislaupama@users.noreply.github.com> Date: Sun, 15 Nov 2026 19:16:50 +0000 Subject: [PATCH 1/4] Add the expanded Character Compressor window --- crates/dstudio-app/src/device_window.rs | 232 ++++++++++++++++-- .../dstudio-app/src/device_window_dynamics.rs | 32 ++- .../src/builtin/character_compressor.rs | 6 +- 3 files changed, 247 insertions(+), 23 deletions(-) diff --git a/crates/dstudio-app/src/device_window.rs b/crates/dstudio-app/src/device_window.rs index f8acfdb5..85ee2065 100644 --- a/crates/dstudio-app/src/device_window.rs +++ b/crates/dstudio-app/src/device_window.rs @@ -88,6 +88,11 @@ pub(crate) const MENU_BANDS: i32 = -3; /// Panel-menu code of the analyser view picker (Character EQ). pub(crate) const MENU_ANALYZER: i32 = -4; +/// Character Compressor models (its `model` choices). +const CC_CLEAN: i32 = 0; +const CC_OPTO: i32 = 4; +const CC_RMS_VCA: i32 = 5; + /// Devices with an expanded window. pub(crate) fn has_window(def: &DeviceDef) -> bool { matches!(def.id, "auto-filter" | "channeleq" | "character-eq") || is_field_window(def) || is_dynamics_window(def) @@ -137,6 +142,7 @@ pub(crate) fn kit(def: &DeviceDef) -> Kit { // The level-history family: the plot's ladder in a 52 pt column, the caption band above. "compressor" | "limiter" | "gate" => field_kit(WIN_W, 394.0, 52.0, 6.0), "glue-compressor" => field_kit(WIN_W, 282.0, 52.0, 6.0), + "character-compressor" => field_kit(WIN_W, 342.0, 52.0, 6.0), _ => eq(56.0, 394.0), } } @@ -1102,6 +1108,18 @@ impl Controller { self.engine.transport().playing } + /// The 1s / 4s / 10s pills, right-aligned at `right`; returns their left edge. + fn win_span_pills(&self, b: &mut Builder, span: f32, right: f32) -> f32 { + let widths = [33.2, 36.1, 40.8]; + let left = right - widths.iter().sum::() - 2.0 * 8.0; + let mut x = left; + for (i, (s, w)) in crate::device_window_dynamics::SPANS.iter().zip(widths).enumerate() { + b.pill(PILL_GHOST, ACT_SPAN, i as i32, x, 10.5, w, &format!("{s:.0}s"), (span - s).abs() < 1e-3); + x += w + 8.0; + } + left + } + /// Header and control cards of a level-history window: the window lengths (and the /// Compressor's Hold view and style), then the device's controls with its transfer square. fn dynamics_window(&self, d: &Device, def: &'static DeviceDef, b: &mut Builder, y: f32) -> f32 { @@ -1111,27 +1129,38 @@ impl Controller { // Header, from the right: the style pills, Hold view, then the window lengths. let span = self.win_span(d.id, &sp); let mut x = b.w - INSET; - if def.id == "compressor" { - let style = val("style").round() as i32; - let items: Vec<(String, bool, i32)> = ["Clean", "Opto", "Punch", "Smooth"] - .iter() - .enumerate() - .map(|(i, l)| (l.to_string(), style == i as i32, i as i32)) - .collect(); - let w = Builder::row_w(&["Clean", "Opto", "Punch", "Smooth"], 8.0); - x -= w; - b.pill_row(PILL_CHOICE, idx("style"), x, 7.5, &items, 8.0, true); + // The circuit pills: Compressor's style (then Hold view), Character Compressor's model. + let circuit = match def.id { + "compressor" => Some("style"), + "character-compressor" => Some("model"), + _ => None, + }; + // Character Compressor keeps its window lengths at the right edge. + let spans_first = def.id == "character-compressor"; + if spans_first { + x = self.win_span_pills(b, span, x); b.rect(BOX_HEADER_RULE, x - 17.0, 11.5, 1.0, 20.0); - x -= 34.0 + 77.5; - b.pill(PILL_GHOST_LATCH, ACT_HOLD, 0, x, 10.5, 77.5, "Hold view", self.win_held(d.id)); + x -= 34.0; + } + if let Some(id) = circuit { + let cur = val(id).round() as i32; + let labels: Vec<&str> = def.param(id).map_or_else(Vec::new, |p| p.choices.to_vec()); + let items: Vec<(String, bool, i32)> = + labels.iter().enumerate().map(|(i, l)| (l.to_string(), cur == i as i32, i as i32)).collect(); + let w = Builder::row_w(&labels, 8.0); + x -= w; + b.pill_row(PILL_CHOICE, idx(id), x, 7.5, &items, 8.0, true); b.rect(BOX_HEADER_RULE, x - 17.0, 11.5, 1.0, 20.0); x -= 34.0; + if id == "style" { + x -= 77.5; + b.pill(PILL_GHOST_LATCH, ACT_HOLD, 0, x, 10.5, 77.5, "Hold view", self.win_held(d.id)); + b.rect(BOX_HEADER_RULE, x - 17.0, 11.5, 1.0, 20.0); + x -= 34.0; + } } - let widths = [33.2, 36.1, 40.8]; - x -= widths.iter().sum::() + 2.0 * 8.0; - for (i, (s, w)) in crate::device_window_dynamics::SPANS.iter().zip(widths).enumerate() { - b.pill(PILL_GHOST, ACT_SPAN, i as i32, x, 10.5, w, &format!("{s:.0}s"), (span - s).abs() < 1e-3); - x += w + 8.0; + if !spans_first { + self.win_span_pills(b, span, x); } let sidechain = || { @@ -1187,6 +1216,41 @@ impl Controller { ), (vec![Item::Knob("mix", "Mix", 1, 64.0, false)], 14.0), ], + "character-compressor" => { + let model = val("model").round() as i32; + let first = if model == CC_OPTO { + let ratio = vec![("Comp", 3.0), ("Limit", 8.0)]; + (vec![Item::Knob("threshold", "Threshold", 2, 64.0, false), Item::Pills("ratio", ratio, "Ratio", 112.0)], 10.0) + } else { + (vec![Item::Knob("threshold", "Threshold", 2, 64.0, false), Item::Knob("ratio", "Ratio", 2, 64.0, false)], 10.0) + }; + let os = vec![("2x", 0.0), ("4x", 1.0)]; + let drive = + (vec![Item::Knob("drive", "Drive", 1, 56.0, false), Item::Pills("oversampling", os, "Oversampling", 112.0)], 10.0); + let out = ( + vec![ + Item::Knob("mix", "Mix", 1, 56.0, false), + Item::Knob("makeup", "Makeup", 1, 56.0, false), + Item::ToggleW("auto_gain", "Auto Gain", 64.0), + Item::ToggleW("delta_monitor", "Delta", 64.0), + ], + 10.0, + ); + let times = |knee: bool| { + let mut v = Vec::new(); + if knee { + v.push(Item::Knob("knee", "Knee", 1, 56.0, false)); + } + v.push(Item::Knob("attack", "Attack", 1, 56.0, false)); + v.push(Item::Knob("release", "Release", 1, 56.0, false)); + (v, 10.0) + }; + match model { + CC_CLEAN => vec![first, times(true), (vec![square], 10.0), out], + CC_OPTO | CC_RMS_VCA => vec![first, (vec![square], 10.0), drive, out], + _ => vec![first, times(false), (vec![square], 10.0), drive, out], + } + } _ => { // The unit is in the column's name: the pills carry the numbers alone. let pills = |id: &'static str| -> Vec<(&'static str, f32)> { @@ -1221,6 +1285,12 @@ impl Controller { sq.y = (row.top() + 4.0) * Z; b.square = sq; } + if def.id == "character-compressor" { + let rack = Row::rack(row.y + row.h + 12.0); + let clusters = self.character_compressor_rack(d, def); + self.win_card(d, def, b, rack, clusters); + return rack.y + rack.h + 16.0; + } if def.id != "glue-compressor" { return row.y + row.h + 16.0; } @@ -1243,6 +1313,90 @@ impl Controller { rack.y + rack.h + 16.0 } + /// Character Compressor's rack card: the Section pills, then the section's controls + /// (Detector: release behaviour, lookahead and stereo; Sidechain: the detector's source + /// and filters; Level: the slow rider and its weighting bands). + fn character_compressor_rack(&self, d: &Device, def: &'static DeviceDef) -> Vec<(Vec, f32)> { + let val = |id: &str| def.param(id).map_or(0.0, |p| self.panel_value(d, def, p)); + let section = self.devices.wins.section.get(&d.id).copied().unwrap_or(0).min(2); + let pills = |id: &'static str| -> Vec<(&'static str, f32)> { + def.param(id).map_or_else(Vec::new, |p| p.choices.iter().enumerate().map(|(i, c)| (*c, i as f32)).collect()) + }; + let head = (vec![Item::ActionPills(ACT_SECTION, vec!["Detector", "Sidechain", "Level"], section, "Section", 220.0, false)], 10.0); + match section { + 1 => vec![ + head, + (vec![Item::Pills("sc_source", pills("sc_source"), "Source", 156.0)], 10.0), + (vec![Item::ToggleW("sc_hpf_on", "HPF", 64.0), Item::Knob("sc_hpf_freq", "HPF Freq", 1, 64.0, false)], 10.0), + ( + vec![ + Item::Knob("sc_eq_freq", "Bell Freq", 1, 64.0, false), + Item::Knob("sc_eq_gain", "Bell Gain", 1, 64.0, false), + Item::Knob("sc_eq_q", "Bell Q", 1, 64.0, false), + ], + 6.0, + ), + (vec![Item::ToggleW("sc_listen", "Listen", 64.0)], 10.0), + ], + 2 => { + const BANDS: [[&str; 4]; 4] = [ + ["level1_enabled", "level1_freq", "level1_q", "level1_weight"], + ["level2_enabled", "level2_freq", "level2_q", "level2_weight"], + ["level3_enabled", "level3_freq", "level3_q", "level3_weight"], + ["level4_enabled", "level4_freq", "level4_q", "level4_weight"], + ]; + let band = self.devices.wins.tame_band.get(&d.id).copied().unwrap_or(0).min(3); + let [on, freq, q, weight] = BANDS[band]; + vec![ + head, + ( + vec![ + Item::ToggleW("level_enabled", "Level", 64.0), + Item::Knob("level_amount", "Amount", 1, 58.0, false), + Item::Knob("level_response", "Response", 1, 58.0, false), + Item::Knob("level_tilt", "Tilt", 1, 58.0, false), + ], + 10.0, + ), + ( + vec![ + Item::ActionPills(ACT_TAME_BAND, vec!["1", "2", "3", "4"], band, "Band", 136.0, false), + Item::ToggleW(on, "Band On", 64.0), + Item::Knob(freq, "Freq", 1, 56.0, false), + Item::Knob(q, "Q", 1, 56.0, false), + Item::Knob(weight, "Weight", 1, 56.0, false), + ], + 10.0, + ), + ] + } + _ => { + let model = val("model").round() as i32; + let release = if matches!(model, CC_OPTO | CC_RMS_VCA) { + vec![Item::Knob("range", "Range", 1, 56.0, false)] + } else { + vec![ + Item::ToggleW("adapt", "Adapt", 64.0), + Item::Knob("hold", "Hold", 1, 56.0, false), + Item::Knob("range", "Range", 1, 56.0, false), + ] + }; + vec![ + head, + (release, 10.0), + (vec![Item::Knob("lookahead", "Lookahead", 1, 64.0, false)], 10.0), + ( + vec![ + Item::Knob("stereo_link", "Stereo Link", 1, 64.0, false), + Item::Pills("ms_mode", pills("ms_mode"), "M/S Mode", 156.0), + ], + 10.0, + ), + ] + } + } + } + // ------------------------------------------------------------ EQs /// Band pills of an EQ header: the selected band lit, bands out of the chain dimmed. @@ -1768,7 +1922,7 @@ mod tests { #[test] fn dynamics_windows_show_levels_and_every_control() { use slint::Model; - for id in ["compressor", "limiter", "gate", "glue-compressor"] { + for id in ["compressor", "limiter", "gate", "glue-compressor", "character-compressor"] { let (mut c, did, def) = controller_with(id); assert!(has_window(def), "{id}"); let v = view(&c, did, def); @@ -1789,6 +1943,46 @@ mod tests { } } + /// Character Compressor: each model lays out its own main card (Opto's Comp / Limit + /// pills, Drive and Oversampling for the coloured models), and the Section pills switch + /// the rack card; every control sits once inside the face. + #[test] + fn character_compressor_window_follows_model_and_section() { + use slint::Model; + let (mut c, did, def) = controller_with("character-compressor"); + let model = def.index_of("model").unwrap() as i32; + let check = |c: &Controller, what: &str| { + let v = view(c, did, def); + assert!((v.h / Z - 640.0).abs() < 0.5, "{what}: {}", v.h / Z); + let mut params = std::collections::HashSet::new(); + for k in v.knobs.iter() { + assert!(k.x >= 0.0 && k.x + 40.0 * Z <= v.w && k.y > 0.0 && k.y < v.h, "{what}: {} outside", k.label); + assert!(params.insert(k.param), "{what}: {} shown twice", k.label); + } + for p in v.pills.iter() { + assert!(p.x >= 0.0 && p.x + p.w <= v.w, "{what}: pill {} outside", p.label); + } + knob_names(&v) + }; + assert_eq!( + check(&c, "Clean"), + ["Threshold", "Ratio", "Knee", "Attack", "Release", "Mix", "Makeup", "Hold", "Range", "Lookahead", "Stereo Link"] + ); + c.win_choice(did, model, 1); + assert!(check(&c, "Vari-Mu").contains(&"Drive".to_string())); + c.win_choice(did, model, 4); + let opto = check(&c, "Opto"); + assert!(!opto.contains(&"Ratio".to_string()) && !opto.contains(&"Hold".to_string()), "{opto:?}"); + assert!(view(&c, did, def).pills.iter().any(|p| p.label == "Limit")); + c.win_action(did, ACT_SECTION, 1); + assert!(check(&c, "Sidechain").contains(&"Bell Q".to_string())); + c.win_action(did, ACT_SECTION, 2); + let level = check(&c, "Level"); + assert!(level.contains(&"Weight".to_string()) && level.contains(&"Tilt".to_string()), "{level:?}"); + c.win_action(did, ACT_TAME_BAND, 3); + check(&c, "Level band 4"); + } + /// A full ten-second history draws as one line per series, however many samples it holds. #[test] fn dynamics_history_draws_once_per_series() { @@ -1808,7 +2002,7 @@ mod tests { #[ignore] fn bench_dynamics_windows() { let n = 500; - for id in ["compressor", "limiter", "gate", "glue-compressor"] { + for id in ["compressor", "limiter", "gate", "glue-compressor", "character-compressor"] { let (mut c, did, def) = controller_with(id); let h: std::collections::VecDeque<_> = (0..630).map(|i| (i as f64 / 60.0, -12.0 + (i as f32 * 0.1).sin() * 6.0, -18.0, -6.0)).collect(); diff --git a/crates/dstudio-app/src/device_window_dynamics.rs b/crates/dstudio-app/src/device_window_dynamics.rs index 7f088f91..cbfc006b 100644 --- a/crates/dstudio-app/src/device_window_dynamics.rs +++ b/crates/dstudio-app/src/device_window_dynamics.rs @@ -75,6 +75,7 @@ pub(crate) fn spec(id: &str) -> Option { "limiter" => s(12.0, -30.0, 6.0, "ceiling", "Ceiling", false, false, 4.0), "gate" => s(12.0, -60.0, 12.0, "threshold", "Threshold", false, false, 4.0), "glue-compressor" => s(0.0, -48.0, 6.0, "threshold", "Threshold", false, true, 4.0), + "character-compressor" => s(0.0, -60.0, 6.0, "threshold", "Threshold", false, true, 4.0), _ => return None, }) } @@ -375,7 +376,9 @@ impl Controller { let out_y = |db: f32| m + (db / -RANGE).clamp(0.0, 1.0) * s; let num = |id: &str| def.param(id).map_or(0.0, |p| self.panel_value(d, def, p)); let face = def.layout.faces.first().map(|f| f.1); - let Some((law, at, knee)) = face.and_then(|f| crate::device_panel::face_law(f, num)) else { return PanelCanvas::default() }; + let Some((law, at, knee)) = face.and_then(|f| crate::device_panel::face_law(f, num)).or_else(|| behavior_law(def, d)) else { + return PanelCanvas::default(); + }; let mut paths = Vec::new(); for i in 1..4 { let q = m + i as f32 / 4.0 * s; @@ -407,6 +410,33 @@ impl Controller { } } +/// The static curve a device's behaviour computes (Character Compressor's models), as a law +/// over all input levels: unity below the computed span, its last slope above it. +#[allow(clippy::type_complexity)] +fn behavior_law(def: &DeviceDef, d: &Device) -> Option<(Box f32>, f32, (f32, f32))> { + let t = dstudio_core::builtin::behavior(def).and_then(|b| (b.transfer)(def, d))?; + let pts = t.points; + if pts.len() < 2 { + return None; + } + let at = def.param("threshold").map_or(t.bend.0, |p| def.value(d, p)); + let law = move |x: f32| { + let (first, last) = (pts[0], pts[pts.len() - 1]); + if x <= first.0 { + return x + (first.1 - first.0); + } + if x >= last.0 { + let prev = pts[pts.len() - 2]; + let slope = (last.1 - prev.1) / (last.0 - prev.0).max(1e-6); + return last.1 + slope * (x - last.0); + } + let i = pts.partition_point(|p| p.0 < x).clamp(1, pts.len() - 1); + let (a, b) = (pts[i - 1], pts[i]); + a.1 + (b.1 - a.1) * (x - a.0) / (b.0 - a.0).max(1e-6) + }; + Some((Box::new(law), at, t.bend)) +} + /// The accessible value of the display: the reduction now. fn value_of(pts: &[Sample]) -> String { format!("{} dB", gr_text(pts.last().map_or(0.0, |s| s.3))) diff --git a/crates/dstudio-core/src/builtin/character_compressor.rs b/crates/dstudio-core/src/builtin/character_compressor.rs index 07f8b5d3..e6ac8793 100644 --- a/crates/dstudio-core/src/builtin/character_compressor.rs +++ b/crates/dstudio-core/src/builtin/character_compressor.rs @@ -127,16 +127,16 @@ pub static CHARACTER_COMPRESSOR: DeviceDef = DeviceDef { ParamDef::new("release", "Release", 20.0, 8000.0, 200.0, Taper::Linear { skew: 0.3 }, "ms", Format::Custom(TextFn(release_text))) .help("How fast reduction lets go."), ParamDef::choice("adapt", "Adapt", OFF_ON, 0).help("Program-dependent release: sustained reduction recovers more slowly."), - ParamDef::new("hold", "Hold", 0.0, 500.0, 0.0, Taper::Linear { skew: 0.5 }, "ms", Format::Custom(TextFn(release_text))) + ParamDef::new("hold", "Hold", 0.0, 500.0, 0.0, Taper::Linear { skew: 0.5 }, "ms", Format::Ms(2)) .help("Time the reduction is held before it releases."), - ParamDef::new("range", "Range", 0.0, 24.0, 24.0, LINEAR, "dB", Format::Db).step(0.1).help("Largest gain reduction allowed."), + ParamDef::new("range", "Range", 0.0, 24.0, 24.0, LINEAR, "dB", Format::DbNoPlus).step(0.1).help("Largest gain reduction allowed."), ParamDef::new("drive", "Drive", 0.0, 2.0, 1.0, LINEAR, "", Format::Plain(2)) .help("Amount of the model's saturation; 1 is the model's normal colour."), ParamDef::new("mix", "Mix", 0.0, 200.0, 100.0, LINEAR, "%", PCT) .help("Blend of dry and compressed signal; above 100% the compression is exaggerated."), ParamDef::new("makeup", "Makeup", -12.0, 24.0, 0.0, LINEAR, "dB", Format::Db).step(0.1).help("Gain after compression."), ParamDef::choice("auto_gain", "Auto Gain", OFF_ON, 0).help("Adds make-up gain that follows the threshold and ratio."), - ParamDef::new("lookahead", "Lookahead", 0.0, 20.0, 0.0, LINEAR, "ms", Format::Time) + ParamDef::new("lookahead", "Lookahead", 0.0, 20.0, 0.0, LINEAR, "ms", Format::MsAuto) .step(0.1) .help("Delays the audio so the detector reacts before peaks arrive (adds latency)."), ParamDef::choice("oversampling", "Oversampling", &["2x", "4x"], 0).help("Oversampling of the saturation stage."), From 5842b35fcb939aff4dd61c3ec68321d60fd43a64 Mon Sep 17 00:00:00 2001 From: Chris Laupama <42254688+chrislaupama@users.noreply.github.com> Date: Sun, 15 Nov 2026 19:31:37 +0000 Subject: [PATCH 2/4] Add the expanded Mastering Limiter window --- crates/dstudio-app/src/device_panel.rs | 1 + crates/dstudio-app/src/device_window.rs | 130 +++++++++- .../dstudio-app/src/device_window_dynamics.rs | 235 +++++++++++++----- .../src/builtin/mastering_limiter.rs | 25 +- crates/dstudio-core/src/builtin/mod.rs | 1 + 5 files changed, 327 insertions(+), 65 deletions(-) diff --git a/crates/dstudio-app/src/device_panel.rs b/crates/dstudio-app/src/device_panel.rs index 3b43e44c..a0ae8c2b 100644 --- a/crates/dstudio-app/src/device_panel.rs +++ b/crates/dstudio-app/src/device_panel.rs @@ -1699,6 +1699,7 @@ impl Controller { let check = |on: bool| if on { "✓".to_string() } else { String::new() }; let rows = match which { crate::device_window::MENU_ANALYZER => self.win_analyzer_rows(device), + crate::device_window::MENU_TARGET => self.win_target_rows(device), crate::device_window::MENU_BANDS => match self.win_band_rows(device) { Some(rows) => rows, None => return, diff --git a/crates/dstudio-app/src/device_window.rs b/crates/dstudio-app/src/device_window.rs index 85ee2065..6586734f 100644 --- a/crates/dstudio-app/src/device_window.rs +++ b/crates/dstudio-app/src/device_window.rs @@ -79,6 +79,10 @@ pub(crate) const ACT_HOLD: i32 = 8; pub(crate) const ACT_SEED: i32 = 9; /// Dynamics windows: the history's length (value: index into 1 s, 4 s, 10 s). pub(crate) const ACT_SPAN: i32 = 10; +/// Mastering Limiter: the loudness target (value: index into device_window_dynamics::TARGETS). +pub(crate) const ACT_TARGET: i32 = 11; +/// Mastering Limiter: restart the loudness measurement. +pub(crate) const ACT_LOUD_RESET: i32 = 12; const PILL_GHOST: i32 = 6; /// Character Mod's Mode parameter of each circuit (Ensemble has none). const CM_MODES: [Option<&str>; 11] = dstudio_core::builtin::character_mod::MODE_PARAMS; @@ -87,6 +91,10 @@ const PILL_GHOST_LATCH: i32 = 7; pub(crate) const MENU_BANDS: i32 = -3; /// Panel-menu code of the analyser view picker (Character EQ). pub(crate) const MENU_ANALYZER: i32 = -4; +/// Panel-menu code of the loudness target picker (Mastering Limiter). +pub(crate) const MENU_TARGET: i32 = -5; + +use crate::device_window_dynamics::TARGETS; /// Character Compressor models (its `model` choices). const CC_CLEAN: i32 = 0; @@ -142,7 +150,7 @@ pub(crate) fn kit(def: &DeviceDef) -> Kit { // The level-history family: the plot's ladder in a 52 pt column, the caption band above. "compressor" | "limiter" | "gate" => field_kit(WIN_W, 394.0, 52.0, 6.0), "glue-compressor" => field_kit(WIN_W, 282.0, 52.0, 6.0), - "character-compressor" => field_kit(WIN_W, 342.0, 52.0, 6.0), + "character-compressor" | "mastering-limiter" => field_kit(WIN_W, 342.0, 52.0, 6.0), _ => eq(56.0, 394.0), } } @@ -175,6 +183,9 @@ pub(crate) struct WinUi { /// Level histories of the open dynamics windows, and the window each shows (s). history: HashMap>, span: HashMap, + /// Mastering Limiter: loudness target per window, and where its measurement restarts (s). + target: HashMap, + loud_from: HashMap, /// Start of the histories' clock. epoch: Option, } @@ -529,6 +540,8 @@ enum Item { Pills(&'static str, Vec<(&'static str, f32)>, &'static str, f32), /// Pill row of window actions: action, labels, selected index, name, width, inert. ActionPills(i32, Vec<&'static str>, usize, &'static str, f32, bool), + /// One unlit pill that runs a window action: action, label, name, width. + Button(i32, &'static str, &'static str, f32), /// Fixed blank (keeps a column's width). Blank(f32), } @@ -540,6 +553,7 @@ impl Item { Item::Toggle(..) => 56.0, Item::ToggleW(.., w) => *w, Item::Action(.., w) => *w, + Item::Button(.., w) => *w, Item::Picker(_, _, _, w, _) => *w, Item::Pills(.., w) => *w, Item::ActionPills(_, _, _, _, w, _) => *w, @@ -827,6 +841,12 @@ impl Controller { b.pill(PILL_ACTION, action, 1, x + (w - pw) / 2.0, top + row.pill, pw, &label, true); b.name(x, w, row.name_y(), name, false); } + Item::Button(action, label, name, w) => { + let pw = pill_w(label); + b.rect(BOX_TRACK, x + (w - pw - 4.0) / 2.0, top + row.pill - 2.0, pw + 4.0, 28.0); + b.pill(PILL_ACTION, action, 1, x + (w - pw) / 2.0, top + row.pill, pw, label, false); + b.name(x, w, row.name_y(), name, false); + } Item::Picker(param, label, name, w, inert) => { let p = b.pill(PILL_PICKER, param, 0, x + w / 2.0, top + row.pill, 0.0, &label, false); p.inert = inert; @@ -1091,6 +1111,32 @@ impl Controller { self.devices.wins.span.get(&id).copied().unwrap_or(sp.span) } + pub(crate) fn win_target(&self, id: DeviceId) -> usize { + self.devices.wins.target.get(&id).copied().unwrap_or(0).min(TARGETS.len() - 1) + } + + /// Where the loudness measurement starts (history clock, s). + pub(crate) fn win_loud_from(&self, id: DeviceId) -> f64 { + self.devices.wins.loud_from.get(&id).copied().unwrap_or(f64::MIN) + } + + /// Loudness target menu rows (panel-menu code MENU_TARGET). + pub(crate) fn win_target_rows(&self, device: DeviceId) -> crate::device_mod::MenuRows { + let cur = self.win_target(device); + TARGETS + .iter() + .enumerate() + .map(|(i, (name, lufs))| { + ( + format!("{name} \u{2212}{:.0} LUFS", -lufs), + if i == cur { "\u{2713}".to_string() } else { String::new() }, + Some(crate::devices::MenuPick::Window(device, ACT_TARGET, i as i32)), + false, + ) + }) + .collect() + } + pub(crate) fn win_held(&self, id: DeviceId) -> bool { self.devices.wins.held.contains(&id) } @@ -1133,10 +1179,11 @@ impl Controller { let circuit = match def.id { "compressor" => Some("style"), "character-compressor" => Some("model"), + "mastering-limiter" => Some("style"), _ => None, }; // Character Compressor keeps its window lengths at the right edge. - let spans_first = def.id == "character-compressor"; + let spans_first = matches!(def.id, "character-compressor" | "mastering-limiter"); if spans_first { x = self.win_span_pills(b, span, x); b.rect(BOX_HEADER_RULE, x - 17.0, 11.5, 1.0, 20.0); @@ -1152,7 +1199,7 @@ impl Controller { b.pill_row(PILL_CHOICE, idx(id), x, 7.5, &items, 8.0, true); b.rect(BOX_HEADER_RULE, x - 17.0, 11.5, 1.0, 20.0); x -= 34.0; - if id == "style" { + if def.id == "compressor" { x -= 77.5; b.pill(PILL_GHOST_LATCH, ACT_HOLD, 0, x, 10.5, 77.5, "Hold view", self.win_held(d.id)); b.rect(BOX_HEADER_RULE, x - 17.0, 11.5, 1.0, 20.0); @@ -1216,6 +1263,22 @@ impl Controller { ), (vec![Item::Knob("mix", "Mix", 1, 64.0, false)], 14.0), ], + "mastering-limiter" => { + let target = TARGETS[self.win_target(d.id)].0.to_string(); + vec![ + (vec![Item::Knob("threshold", "Threshold", 2, 64.0, false), Item::Knob("ceiling", "Ceiling", 2, 64.0, false)], 10.0), + (vec![Item::Knob("release", "Release", 1, 64.0, false), Item::ToggleW("auto_release", "Auto", 56.0)], 10.0), + (vec![square], 10.0), + (vec![Item::ToggleW("unity_monitor", "Unity", 64.0), Item::ToggleW("delta_monitor", "Delta", 64.0)], 10.0), + ( + vec![ + Item::Picker(MENU_TARGET, target, "Target", 104.0, false), + Item::Button(ACT_LOUD_RESET, "Reset", "Loudness", 64.0), + ], + 10.0, + ), + ] + } "character-compressor" => { let model = val("model").round() as i32; let first = if model == CC_OPTO { @@ -1285,9 +1348,35 @@ impl Controller { sq.y = (row.top() + 4.0) * Z; b.square = sq; } - if def.id == "character-compressor" { + if matches!(def.id, "character-compressor" | "mastering-limiter") { let rack = Row::rack(row.y + row.h + 12.0); - let clusters = self.character_compressor_rack(d, def); + let clusters = if def.id == "mastering-limiter" { + let choice = |id: &str| def.param(id).and_then(|p| p.choices.get(val(id).round() as usize)).map_or("", |c| *c).to_string(); + let os = def + .param("oversampling") + .map_or_else(Vec::new, |p| p.choices.iter().enumerate().map(|(i, c)| (*c, i as f32)).collect()); + vec![ + (vec![Item::Knob("lookahead", "Lookahead", 1, 64.0, false), Item::Knob("attack", "Attack", 1, 56.0, false)], 10.0), + ( + vec![ + Item::Knob("transient_link", "Transient Link", 2, 80.0, false), + Item::Knob("release_link", "Release Link", 2, 80.0, false), + Item::ToggleW("ms_mode", "Mid-Side", 56.0), + ], + 10.0, + ), + (vec![Item::Pills("oversampling", os, "Oversampling", 156.0), Item::ToggleW("true_peak", "True Peak", 56.0)], 10.0), + ( + vec![ + Item::Picker(idx("dither_bits"), choice("dither_bits"), "Dither", 88.0, false), + Item::Picker(idx("dither_shape"), choice("dither_shape"), "Shape", 88.0, false), + ], + 10.0, + ), + ] + } else { + self.character_compressor_rack(d, def) + }; self.win_card(d, def, b, rack, clusters); return rack.y + rack.h + 16.0; } @@ -1721,6 +1810,13 @@ impl Controller { let next = p.min + (cur + step).rem_euclid(span) as f32; self.panel_commit(Command::SetDeviceParam { device, param: p.id.into(), value: next }); } + (ACT_TARGET, _) => { + self.devices.wins.target.insert(device, value.clamp(0, TARGETS.len() as i32 - 1) as usize); + } + (ACT_LOUD_RESET, _) => { + let now = self.win_now(); + self.devices.wins.loud_from.insert(device, now); + } (ACT_SPAN, _) => { let span = crate::device_window_dynamics::SPANS[value.clamp(0, 2) as usize]; self.devices.wins.span.insert(device, span); @@ -1983,6 +2079,28 @@ mod tests { check(&c, "Level band 4"); } + /// Mastering Limiter: the target picker moves the loudness lane's ladder, the caption + /// reads the short-term level of the output, and Reset starts the measurement again. + #[test] + fn mastering_limiter_measures_loudness_against_the_target() { + use slint::Model; + let (mut c, did, def) = controller_with("mastering-limiter"); + let texts = |c: &Controller| view(c, did, def).display.texts.iter().map(|t| t.text.to_string()).collect::>(); + assert!(texts(&c).contains(&"\u{2212}14".to_string()), "{:?}", texts(&c)); + c.win_action(did, ACT_TARGET, 1); + assert!(texts(&c).contains(&"\u{2212}23".to_string())); + assert!(view(&c, did, def).pills.iter().any(|p| p.param == MENU_TARGET && p.label == "Broadcast")); + // Four seconds at -14 dB out read as -14.0 short-term. + let h: std::collections::VecDeque<_> = (0..240).map(|i| (i as f64 / 60.0, -10.0, -14.0, -2.0)).collect(); + c.devices.wins.history.insert(did, h); + c.devices.wins.epoch = Some(Instant::now() - std::time::Duration::from_secs(4)); + assert!(texts(&c).iter().any(|t| t == "\u{2212}14.0 LUFS"), "{:?}", texts(&c)); + c.win_action(did, ACT_LOUD_RESET, 0); + assert!(!texts(&c).iter().any(|t| t.ends_with("LUFS"))); + let ceiling = view(&c, did, def).display.grips.iter().next().unwrap(); + assert_eq!((ceiling.label.as_str(), ceiling.value.as_str()), ("Ceiling", "\u{2212}1.0 dBTP")); + } + /// A full ten-second history draws as one line per series, however many samples it holds. #[test] fn dynamics_history_draws_once_per_series() { @@ -2002,7 +2120,7 @@ mod tests { #[ignore] fn bench_dynamics_windows() { let n = 500; - for id in ["compressor", "limiter", "gate", "glue-compressor", "character-compressor"] { + for id in ["compressor", "limiter", "gate", "glue-compressor", "character-compressor", "mastering-limiter"] { let (mut c, did, def) = controller_with(id); let h: std::collections::VecDeque<_> = (0..630).map(|i| (i as f64 / 60.0, -12.0 + (i as f32 * 0.1).sin() * 6.0, -18.0, -6.0)).collect(); diff --git a/crates/dstudio-app/src/device_window_dynamics.rs b/crates/dstudio-app/src/device_window_dynamics.rs index cbfc006b..ae5975ea 100644 --- a/crates/dstudio-app/src/device_window_dynamics.rs +++ b/crates/dstudio-app/src/device_window_dynamics.rs @@ -16,7 +16,7 @@ use crate::device_window::Kit; use crate::{PanelCanvas, PanelGrip, PanelPath, PanelText, PanelZone}; use dstudio_core::Device; use dstudio_core::builtin::DeviceDef; -use slint::{Color, ModelRc, SharedString, VecModel}; +use slint::{Color, ModelRc, VecModel}; use std::collections::VecDeque; use std::rc::Rc; @@ -57,6 +57,10 @@ pub(crate) struct DynSpec { pub detector: bool, /// Default window (s). pub span: f32, + /// A second, solid line (Mastering Limiter's ceiling): parameter and pill name. + pub line2: Option<(&'static str, &'static str)>, + /// A short-term loudness lane above the reduction lane (Mastering Limiter). + pub loudness: bool, } pub(crate) fn spec(id: &str) -> Option { @@ -69,6 +73,8 @@ pub(crate) fn spec(id: &str) -> Option { pre_gain, detector, span, + line2: None, + loudness: false, }; Some(match id { "compressor" => s(0.0, -36.0, 6.0, "threshold", "Threshold", true, true, 10.0), @@ -76,17 +82,58 @@ pub(crate) fn spec(id: &str) -> Option { "gate" => s(12.0, -60.0, 12.0, "threshold", "Threshold", false, false, 4.0), "glue-compressor" => s(0.0, -48.0, 6.0, "threshold", "Threshold", false, true, 4.0), "character-compressor" => s(0.0, -60.0, 6.0, "threshold", "Threshold", false, true, 4.0), + "mastering-limiter" => DynSpec { + line2: Some(("ceiling", "Ceiling")), + loudness: true, + ..s(12.0, -36.0, 6.0, "threshold", "Threshold", false, false, 4.0) + }, _ => return None, }) } +/// The loudness lane's span (dB, centred on the target) and the band under it that holds +/// the reduction lane's caption. +const LOUD_DB: f32 = 12.0; +const LOUD_GAP: f32 = 25.0; +/// Short-term loudness integrates the last 3 s. +const SHORT_TERM: f64 = 3.0; +/// Loudness targets (name, LUFS) of the Mastering Limiter's Target picker. +pub(crate) const TARGETS: [(&str, f32); 3] = [("Streaming", -14.0), ("Broadcast", -23.0), ("Hot", -9.0)]; + /// The lane and plot geometry of a display h pt high (plot-local, reference points): -/// (lane height, plot top, plot height, px per dB). -pub(crate) fn geometry(sp: &DynSpec, display_h: f32) -> (f32, f32, f32, f32) { - let avail = display_h - PAD * 2.0 - CAP_H - LANE_GAP - TIME_H; - let per_db = avail / (-GR_FLOOR + (sp.top - sp.bottom)); +/// (reduction lane top, lane height, plot top, plot height, px per dB). A loudness lane, +/// when there is one, fills 0 .. lane top - LOUD_GAP. +pub(crate) fn geometry(sp: &DynSpec, display_h: f32) -> (f32, f32, f32, f32, f32) { + let loud = if sp.loudness { LOUD_DB } else { 0.0 }; + let avail = display_h - PAD * 2.0 - CAP_H - LANE_GAP - TIME_H - if sp.loudness { LOUD_GAP } else { 0.0 }; + let per_db = avail / (loud - GR_FLOOR + (sp.top - sp.bottom)); + let off = if sp.loudness { per_db * loud + LOUD_GAP } else { 0.0 }; let lane = per_db * -GR_FLOOR; - (lane, lane + LANE_GAP, per_db * (sp.top - sp.bottom), per_db) + (off, lane, off + lane + LANE_GAP, per_db * (sp.top - sp.bottom), per_db) +} + +/// Short-term level (dB, unweighted mean power over the last 3 s) of the output at each of +/// `times`, from the samples after `from`; None while nothing was heard. +fn short_term(h: &VecDeque, from: f64, times: &[f64]) -> Vec> { + let (mut t, mut sum) = (Vec::with_capacity(h.len()), Vec::with_capacity(h.len() + 1)); + sum.push(0.0f64); + for s in h.iter().filter(|s| s.0 >= from) { + t.push(s.0); + let p = if s.2 > -100.0 { 10f64.powf(s.2 as f64 / 10.0) } else { 0.0 }; + sum.push(sum[sum.len() - 1] + p); + } + times + .iter() + .map(|&at| { + let hi = t.partition_point(|x| *x <= at); + let lo = t.partition_point(|x| *x < at - SHORT_TERM); + if hi <= lo { + return None; + } + let mean = (sum[hi] - sum[lo]) / (hi - lo) as f64; + (mean > 1e-10).then(|| (10.0 * mean.log10()) as f32) + }) + .collect() } /// A gain-reduction amount as the caption reads it: "0.0", "−3.2". @@ -94,6 +141,11 @@ fn gr_text(gr: f32) -> String { if gr < -0.05 { format!("\u{2212}{:.1}", -gr) } else { "0.0".into() } } +/// A level with one decimal and a true minus: "−14.2", "0.3". +fn db_tenth(db: f32) -> String { + if db < -0.05 { format!("\u{2212}{:.1}", -db) } else { format!("{:.1}", db.max(0.0)) } +} + fn db_rung(db: f32) -> String { if db > 0.5 { format!("+{db:.0}") @@ -126,8 +178,8 @@ impl Controller { let (_, _, dw, dh) = k.display; let (l, _, r, _) = k.plot; let pw = (dw - l - r) * Z; - let (lane_h, plot_t, plot_h, per_db) = geometry(&sp, dh); - let (lane_h, plot_t, plot_h) = (lane_h * Z, plot_t * Z, plot_h * Z); + let (off, lane_h, plot_t, plot_h, per_db) = geometry(&sp, dh); + let (off, lane_h, plot_t, plot_h) = (off * Z, lane_h * Z, plot_t * Z, plot_h * Z); let span = self.win_span(d.id, &sp); let held = self.win_held(d.id); let hist = self.win_history(d.id); @@ -136,7 +188,7 @@ impl Controller { let mut texts: Vec = Vec::new(); let db_y = |db: f32| plot_t + ((sp.top - db) / (sp.top - sp.bottom)).clamp(0.0, 1.0) * plot_h; - let gr_y = |gr: f32| (gr / GR_FLOOR).clamp(0.0, 1.0) * lane_h; + let gr_y = |gr: f32| off + (gr / GR_FLOOR).clamp(0.0, 1.0) * lane_h; let grid = if span <= 1.0 { 0.25 } else if span <= 4.0 { @@ -168,32 +220,76 @@ impl Controller { let gr_now = pts.last().map_or(0.0, |s| s.3); let gr_peak = pts.iter().map(|s| s.3).fold(0.0f32, f32::min); - // Caption: the reduction now, then its peak over the window. - let base = -(CAP_H - 6.0) * Z; + // Caption: the reduction now, then its peak (the limiter's maximum) over the window. + let base = off - (CAP_H - 6.0) * Z; let label = "Gain Reduction"; texts.push(PanelText { weight: 700, ..text(2.0 * Z, base, 120.0 * Z, label, MUTE_TEXT, 12.0 * Z, 0) }); let vx = 2.0 * Z + (crate::text_measure::value_width(label) * 1.2 + 12.0) * Z; let value = format!("{} dB", gr_text(gr_now)); texts.push(text(vx, base - 0.3 * Z, 80.0 * Z, value.clone(), white(0.92), 13.0 * Z, 0)); let px = vx + (crate::text_measure::value_width(&value) * 1.3 + 12.0) * Z; - texts.push(text(px, base, 80.0 * Z, format!("Peak {}", gr_text(gr_peak)), white(0.55), 11.0 * Z, 0)); + let peak = if sp.loudness { "Max" } else { "Peak" }; + texts.push(text(px, base, 80.0 * Z, format!("{peak} {}", gr_text(gr_peak)), white(0.55), 11.0 * Z, 0)); - // The lane: a light box, time rules, the reduction filled down from its top edge. + // A lane: a light box with time rules. let r = LANE_R * Z; - let lane_box = format!( - "M{r:.1} 0 L{:.1} 0 Q{pw:.1} 0 {pw:.1} {r:.1} L{pw:.1} {:.1} Q{pw:.1} {lane_h:.1} {:.1} {lane_h:.1} L{r:.1} {lane_h:.1} Q0 {lane_h:.1} 0 {:.1} L0 {r:.1} Q0 0 {r:.1} 0 Z", - pw - r, - lane_h - r, - pw - r, - lane_h - r - ); - paths.push(fill(lane_box.clone(), white(0.035))); - let mut sec = grid; - while sec < span - 1e-3 { - let x = ((1.0 - sec / span) * pw).round() + 0.5; - paths.push(stroke(format!("M{x:.1} 0 L{x:.1} {lane_h:.1}"), white(0.04), 1.0)); - sec += grid; + let lane_box = |top: f32, h: f32| { + let b = top + h; + format!( + "M{r:.1} {top:.1} L{:.1} {top:.1} Q{pw:.1} {top:.1} {pw:.1} {:.1} L{pw:.1} {:.1} Q{pw:.1} {b:.1} {:.1} {b:.1} L{r:.1} {b:.1} Q0 {b:.1} 0 {:.1} L0 {:.1} Q0 {top:.1} {r:.1} {top:.1} Z", + pw - r, + top + r, + b - r, + pw - r, + b - r, + top + r + ) + }; + let time_rules = |paths: &mut Vec, top: f32, h: f32, ink: f32| { + let mut sec = grid; + while sec < span - 1e-3 { + let x = ((1.0 - sec / span) * pw).round() + 0.5; + paths.push(stroke(format!("M{x:.1} {top:.1} L{x:.1} {:.1}", top + h), white(ink), 1.0)); + sec += grid; + } + }; + + // The loudness lane: short-term loudness of the output against the target. + if sp.loudness { + let target = TARGETS[self.win_target(d.id)].1; + let loud_h = LOUD_DB * per_db * Z; + let ly = |db: f32| ((target + LOUD_DB / 2.0 - db) / LOUD_DB).clamp(0.0, 1.0) * loud_h; + let lb = lane_box(0.0, loud_h); + paths.push(fill(lb.clone(), white(0.035))); + time_rules(&mut paths, 0.0, loud_h, 0.04); + for db in [target + 6.0, target, target - 6.0] { + texts.push(text(-8.0 * Z, ly(db), 40.0 * Z, db_rung(db), white(if db == target { 0.7 } else { 0.3 }), 11.0 * Z, 2)); + } + let ty = ly(target).round() + 0.5; + paths.push(stroke(crate::device_canvas::dashed(&[(0.0, ty), (pw, ty)], 3.0 * Z, 3.0 * Z), rgba(accent, 0.7), 1.0)); + let from = self.win_loud_from(d.id); + let times: Vec = pts.iter().map(|s| s.0).collect(); + let st = hist.map(|h| short_term(h, from, ×)).unwrap_or_default(); + let loud_now = st.last().copied().flatten(); + let line: Vec<(f32, f32, bool)> = + pts.iter().zip(&st).map(|(s, v)| (x_of(s.0), ly(v.unwrap_or(-120.0)), v.is_some_and(|v| v > -70.0))).collect(); + paths.push(stroke(runs(&line), accent, 1.5 * Z)); + paths.push(stroke(lb, white(0.06), 1.0)); + let cap = -(CAP_H - 6.0) * Z; + texts.push(PanelText { weight: 700, ..text(2.0 * Z, cap, 120.0 * Z, "Loudness", MUTE_TEXT, 12.0 * Z, 0) }); + let lx = 2.0 * Z + (crate::text_measure::value_width("Loudness") * 1.2 + 12.0) * Z; + let lv = loud_now.map_or("\u{2014}".to_string(), |v| format!("{} LUFS", db_tenth(v))); + texts.push(text(lx, cap - 0.3 * Z, 90.0 * Z, lv.clone(), white(0.92), 13.0 * Z, 0)); + let tx = lx + (crate::text_measure::value_width(&lv) * 1.3 + 12.0) * Z; + let tp = pts.iter().map(|s| s.2).fold(f32::MIN, f32::max); + let tp = if tp > -100.0 { db_tenth(tp) } else { "\u{2014}".into() }; + texts.push(text(tx, cap, 90.0 * Z, format!("True Peak {tp}"), white(0.55), 11.0 * Z, 0)); } + + // The reduction lane, the reduction filled down from its top edge. + let lb = lane_box(off, lane_h); + paths.push(fill(lb.clone(), white(0.035))); + time_rules(&mut paths, off, lane_h, 0.04); for g in [6.0, 12.0] { let y = gr_y(-g).round() + 0.5; paths.push(stroke(format!("M0 {y:.1} L{pw:.1} {y:.1}"), white(0.05), 1.0)); @@ -203,15 +299,15 @@ impl Controller { } if pts.len() > 1 { let line: Vec<(f32, f32)> = pts.iter().map(|s| (x_of(s.0), gr_y(s.3))).collect(); - let mut area = format!("M{:.1} 0 ", line[0].0); + let mut area = format!("M{:.1} {off:.1} ", line[0].0); for (x, y) in &line { area.push_str(&format!("L{x:.1} {y:.1} ")); } - area.push_str(&format!("L{:.1} 0 Z", line[line.len() - 1].0)); + area.push_str(&format!("L{:.1} {off:.1} Z", line[line.len() - 1].0)); paths.push(fill(area, rgba(accent, 0.55))); paths.push(stroke(crate::device_canvas::path(&line), accent, 1.25 * Z)); } - paths.push(stroke(lane_box, white(0.06), 1.0)); + paths.push(stroke(lb, white(0.06), 1.0)); // The level plot: time rules, the ladder, then the traces. let mut sec = grid; @@ -282,17 +378,22 @@ impl Controller { let sidechain = d.sidechain.is_some(); let thresh_ink = Color::from_argb_u8(140, 200, 198, 188); let detector_ink = Color::from_argb_u8(115, 200, 198, 188); + let ceiling_ink = Color::from_argb_u8(120, 200, 198, 188); let mut entries: Vec<(&str, u8)> = vec![("Input", 0), ("Output", 1)]; - if sp.pre_gain { + if sp.loudness { + entries.extend([(sp.line_name, 5), ("Ceiling", 6), ("Short-term", 7), ("Target", 8)]); + } else if sp.pre_gain { entries.push(("Pre-Gain", 2)); } - entries.push(("Reduction", 3)); - if sp.detector && def.id == "compressor" { - entries.push(("Detector", 4)); - } - entries.push((sp.line_name, 5)); - if sp.detector && def.id != "compressor" { - entries.push(("Detector", 4)); + if !sp.loudness { + entries.push(("Reduction", 3)); + if sp.detector && def.id == "compressor" { + entries.push(("Detector", 4)); + } + entries.push((sp.line_name, 5)); + if sp.detector && def.id != "compressor" { + entries.push(("Detector", 4)); + } } let mut x = 0.0; for (name, kind) in entries { @@ -310,6 +411,11 @@ impl Controller { rgba(detector_ink, 0.45 * a), 1.0, )), + 6 => paths.push(stroke(line, ceiling_ink, 1.5 * Z)), + 7 => paths.push(stroke(line, accent, 1.5 * Z)), + 8 => { + paths.push(stroke(crate::device_canvas::dashed(&[(x, ly), (x + glyph, ly)], 3.0 * Z, 3.0 * Z), rgba(accent, 0.7), 1.0)) + } _ => paths.push(stroke(crate::device_canvas::dashed(&[(x, ly), (x + glyph, ly)], 6.0 * Z, 5.0 * Z), thresh_ink, 1.5 * Z)), } let w = crate::text_measure::value_width(name) * 0.9 * Z; @@ -333,25 +439,37 @@ impl Controller { texts.push(text(pw - 8.0 * Z - 60.0 * Z, plot_t + 12.0 * Z, 60.0 * Z, "Held", accent, 9.0 * Z, 2)); } - // The dashed line and its grip pill at the oldest edge; dragging the band moves it. - let p = def.param(sp.line); - let v = p.map_or(0.0, |p| self.panel_value(d, def, p)); - let ly = db_y(v.clamp(sp.bottom, sp.top)).round() + 0.5; - paths.push(stroke(crate::device_canvas::dashed(&[(0.0, ly), (pw, ly)], 6.0 * Z, 5.0 * Z), thresh_ink, 1.5 * Z)); - let value: SharedString = p.map_or_else(String::new, |p| def.text(d, p, v)).into(); - let grips = vec![PanelGrip { x: 6.0 * Z, y: ly, anchor: 0, label: sp.line_name.into(), value, hot: false, plain: false }]; - let index = def.index_of(sp.line).map_or(-1, |i| i as i32); - let range = p.map_or(1.0, |p| (p.max - p.min).max(1e-3)); - let zone = PanelZone { - x: 0.0, - y: ly - 8.0 * Z, - w: pw, - h: 16.0 * Z, - param_x: -1, - param_y: index, - rate_x: 0.0, - rate_y: 1.0 / (per_db * Z * range), - }; + // The lines (the solid ceiling first, then the dashed threshold), each with a grip + // pill from the oldest edge; dragging a line's band moves it. + let mut grips = Vec::new(); + let mut zones = Vec::new(); + let mut gx = 6.0 * Z; + let lines = sp.line2.map(|l| (l, true)).into_iter().chain([((sp.line, sp.line_name), false)]); + for ((id, name), solid) in lines { + let p = def.param(id); + let v = p.map_or(0.0, |p| self.panel_value(d, def, p)); + let ly = db_y(v.clamp(sp.bottom, sp.top)).round() + 0.5; + if solid { + paths.push(stroke(format!("M0 {ly:.1} L{pw:.1} {ly:.1}"), ceiling_ink, 1.5 * Z)); + } else { + paths.push(stroke(crate::device_canvas::dashed(&[(0.0, ly), (pw, ly)], 6.0 * Z, 5.0 * Z), thresh_ink, 1.5 * Z)); + } + let value: String = p.map_or_else(String::new, |p| def.text(d, p, v)); + let gw = (30.0 + crate::text_measure::value_width(name) + crate::text_measure::value_width(&value) * 1.1) * Z; + grips.push(PanelGrip { x: gx, y: ly, anchor: 0, label: name.into(), value: value.into(), hot: false, plain: false }); + gx += gw + 10.0 * Z; + let range = p.map_or(1.0, |p| (p.max - p.min).max(1e-3)); + zones.push(PanelZone { + x: 0.0, + y: ly - 8.0 * Z, + w: pw, + h: 16.0 * Z, + param_x: -1, + param_y: def.index_of(id).map_or(-1, |i| i as i32), + rate_x: 0.0, + rate_y: 1.0 / (per_db * Z * range), + }); + } PanelCanvas { visible: true, w: pw, @@ -359,7 +477,7 @@ impl Controller { paths: model(paths), texts: model(texts), grips: model(grips), - zones: model(vec![zone]), + zones: model(zones), label: label.into(), value: value_of(&pts).into(), ..Default::default() @@ -461,7 +579,8 @@ mod tests { #[test] fn one_px_per_db_serves_lane_and_plot() { let sp = spec("compressor").unwrap(); - let (lane, plot_t, plot_h, per_db) = geometry(&sp, 394.0); + let (off, lane, plot_t, plot_h, per_db) = geometry(&sp, 394.0); + assert_eq!(off, 0.0); assert!((lane - 101.7).abs() < 0.2, "{lane}"); assert!((plot_h - 203.3).abs() < 0.2, "{plot_h}"); assert!((plot_t - lane - 20.0).abs() < 1e-3); diff --git a/crates/dstudio-core/src/builtin/mastering_limiter.rs b/crates/dstudio-core/src/builtin/mastering_limiter.rs index 86ad0c88..87b1952a 100644 --- a/crates/dstudio-core/src/builtin/mastering_limiter.rs +++ b/crates/dstudio-core/src/builtin/mastering_limiter.rs @@ -39,7 +39,7 @@ pub static MASTERING_LIMITER: DeviceDef = DeviceDef { .not_automatable() .overlays(STYLE_OVERLAYS) .help("Clean is transparent, Loud recovers fastest, Gentle is a single slow stage, Dense leans on the slow stage."), - ParamDef::new("lookahead", "Lookahead", 0.1, 5.0, 2.0, LINEAR, "ms", Format::Ms(1)) + ParamDef::new("lookahead", "Lookahead", 0.1, 5.0, 2.0, LINEAR, "ms", Format::Ms(2)) .step(0.01) .not_automatable() .help("How far ahead peaks are seen; longer is smoother, shorter is punchier."), @@ -154,3 +154,26 @@ pub static MASTERING_LIMITER: DeviceDef = DeviceDef { sidechain: false, samples: 0, }; + +/// The ceiling reads in dBTP while True Peak limiting is on: "−1.0 dBTP". +fn text(def: &DeviceDef, d: &Device, p: &ParamDef, v: f32) -> Option { + let true_peak = def.param("true_peak").is_some_and(|tp| def.value(d, tp) >= 0.5); + (p.id == "ceiling" && true_peak).then(|| if v < -0.05 { format!("\u{2212}{:.1} dBTP", -v) } else { "0.0 dBTP".into() }) +} + +pub(super) static BEHAVIOR: Behavior = Behavior { text, ..Behavior::NONE }; + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn ceiling_reads_true_peak_while_limiting_true_peak() { + let def = &MASTERING_LIMITER; + let mut d = def.instantiate(); + let ceiling = def.param("ceiling").unwrap(); + assert_eq!(def.text(&d, ceiling, -1.0), "\u{2212}1.0 dBTP"); + d.params.insert("true_peak".into(), 0.0); + assert!(!def.text(&d, ceiling, -1.0).contains("TP")); + } +} diff --git a/crates/dstudio-core/src/builtin/mod.rs b/crates/dstudio-core/src/builtin/mod.rs index ce5d27a3..fc5e0fdb 100644 --- a/crates/dstudio-core/src/builtin/mod.rs +++ b/crates/dstudio-core/src/builtin/mod.rs @@ -1012,6 +1012,7 @@ pub fn behavior(def: &DeviceDef) -> Option<&'static Behavior> { "delay" => Some(&delay::BEHAVIOR), "echo" => Some(&echo::BEHAVIOR), "grains" => Some(&grains::BEHAVIOR), + "mastering-limiter" => Some(&mastering_limiter::BEHAVIOR), "reverb" => Some(&reverb::BEHAVIOR), _ => None, } From 7ba00843125b6bec263e40b86c8fa286864a29cf Mon Sep 17 00:00:00 2001 From: Chris Laupama <42254688+chrislaupama@users.noreply.github.com> Date: Sun, 15 Nov 2026 19:38:18 +0000 Subject: [PATCH 3/4] Document the Character Compressor and Mastering Limiter windows --- CHANGELOG.md | 4 ++++ README.md | 5 +++-- docs/devices.md | 13 +++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebedbedf..c7de05fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,3 +40,7 @@ Nothing has been released yet. The first release, 0.1.0, will cover what is on ` - Expanded windows for Compressor, Limiter, Gate and Glue Compressor: the last 1, 4 or 10 seconds of input, output and gain reduction (Hold view freezes it) under a threshold or ceiling line you can drag, a transfer curve with the live operating point beside the main controls, In and Out meters and every control laid out in rows. +- Expanded windows for Character Compressor (the model pills in the header, a main card that follows the model, and a + rack card with Detector, Sidechain and Level sections) and Mastering Limiter (its style pills, a short-term loudness + lane against a Streaming, Broadcast or Hot target with Loudness Reset, and ceiling and threshold lines you can drag). + Mastering Limiter's ceiling reads in dBTP while True Peak is on. diff --git a/README.md b/README.md index e65086d3..6536b165 100644 --- a/README.md +++ b/README.md @@ -124,8 +124,9 @@ factory presets) that the model, undo, saving, automation, engine and panel all behind it. Auto Filter, Channel EQ and Character EQ also open an expanded window with a large display and live analyser, In and Out meters and every control laid out in rows, and so do Tremolo, Auto-Panner, Chorus, Flanger, Phaser, Ring Mod and Character Mod, whose window plots their motion or response with a time or frequency axis and a legend, and -Compressor, Limiter, Gate and Glue Compressor, whose window scrolls the last 1, 4 or 10 seconds of input, output and gain -reduction under a draggable threshold, beside a transfer curve; the other devices open their card in a window for now. +Compressor, Limiter, Gate, Glue Compressor, Character Compressor and Mastering Limiter, whose window scrolls the last 1, 4 +or 10 seconds of input, output and gain reduction under a draggable threshold, beside a transfer curve (the Mastering +Limiter adds a short-term loudness lane against a target); 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/docs/devices.md b/docs/devices.md index 645b311c..67ead00a 100644 --- a/docs/devices.md +++ b/docs/devices.md @@ -65,7 +65,8 @@ flowchart LR device has one (`device_window::has_window`; Auto Filter, Channel EQ, Character EQ and the plotted-field family: Tremolo, Auto-Panner, Chorus, Flanger, Phaser, Ring Mod and Character Mod; and the dynamics family: - Compressor, Limiter, Gate and Glue Compressor), otherwise the card itself in a window. A + Compressor, Limiter, Gate, Glue Compressor, Character Compressor and Mastering + Limiter), 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 @@ -84,7 +85,15 @@ flowchart LR over a dBFS level plot, one pixel per dB in both, with the threshold (or ceiling) as a dashed line you drag. Hold view freezes the history. Each device's first card carries a transfer square: the static curve of the - card's law over −48..0 dB with the knee and the live operating point. The + card's law over −48..0 dB with the knee and the live operating point + (Character Compressor's comes from its model's computed curve). Character + Compressor's rack card switches between Detector, Sidechain and Level + sections (`ACT_SECTION`; the Level band pills reuse `ACT_TAME_BAND`). + Mastering Limiter's display adds a loudness lane: the output's short-term + level (unweighted mean power over 3 s) against the Target picker's level + (`MENU_TARGET`: Streaming −14, Broadcast −23, Hot −9 LUFS), restarted by + Loudness Reset (`ACT_LOUD_RESET`), and draws its ceiling as a second, + solid line with its own grip. 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 1bc36511ba2e2856c698a30fb36ba19a5762bc29 Mon Sep 17 00:00:00 2001 From: Chris Laupama <42254688+chrislaupama@users.noreply.github.com> Date: Sun, 15 Nov 2026 19:50:36 +0000 Subject: [PATCH 4/4] Track field drags in window coordinates so a moving line or handle drags evenly --- crates/dstudio-app/ui/device_panel.slint | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/dstudio-app/ui/device_panel.slint b/crates/dstudio-app/ui/device_panel.slint index b913c942..411f7c57 100644 --- a/crates/dstudio-app/ui/device_panel.slint +++ b/crates/dstudio-app/ui/device_panel.slint @@ -399,24 +399,28 @@ component ButtonCell inherits Rectangle { // Drag zone of a device field: one or two parameters (horizontal / vertical), Shift fine, // Alt-click or double-click resets them. -component ZoneDrag inherits TouchArea { +// The pointer is tracked in window coordinates: a zone that follows its line (a threshold, +// a handle) moves under the pointer while it is dragged. +export component ZoneDrag inherits TouchArea { in property device; in property zone; property last-x; property last-y; + property at-x: self.absolute-position.x + self.mouse-x; + property at-y: self.absolute-position.y + self.mouse-y; mouse-cursor: root.zone.param-x >= 0 && root.zone.param-y >= 0 ? MouseCursor.move : root.zone.param-x >= 0 ? MouseCursor.ew-resize : MouseCursor.ns-resize; function reset() { Studio.panel-reset-xy(root.device, root.zone.param-x, root.zone.param-y); } pointer-event(e) => { if (e.button == PointerEventButton.left && e.kind == PointerEventKind.down) { if (e.modifiers.alt) { root.reset(); return; } - root.last-x = self.mouse-x; - root.last-y = self.mouse-y; + root.last-x = root.at-x; + root.last-y = root.at-y; Studio.panel-drag-xy(root.device, root.zone.param-x, root.zone.param-y, 0, 0, 0, root.zone.rate-x, root.zone.rate-y, e.modifiers.shift); } if (e.kind == PointerEventKind.move && self.pressed) { - Studio.panel-drag-xy(root.device, root.zone.param-x, root.zone.param-y, 1, (self.mouse-x - root.last-x) / 1px, (root.last-y - self.mouse-y) / 1px, root.zone.rate-x, root.zone.rate-y, e.modifiers.shift); - root.last-x = self.mouse-x; - root.last-y = self.mouse-y; + Studio.panel-drag-xy(root.device, root.zone.param-x, root.zone.param-y, 1, (root.at-x - root.last-x) / 1px, (root.last-y - root.at-y) / 1px, root.zone.rate-x, root.zone.rate-y, e.modifiers.shift); + root.last-x = root.at-x; + root.last-y = root.at-y; } if (e.button == PointerEventButton.left && e.kind == PointerEventKind.up) { Studio.panel-drag-xy(root.device, root.zone.param-x, root.zone.param-y, 2, 0, 0, root.zone.rate-x, root.zone.rate-y, false); } if (e.kind == PointerEventKind.cancel) { Studio.panel-drag-xy(root.device, root.zone.param-x, root.zone.param-y, 3, 0, 0, root.zone.rate-x, root.zone.rate-y, false); }