diff --git a/CHANGELOG.md b/CHANGELOG.md index c7de05fe..f140f109 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,3 +44,7 @@ Nothing has been released yet. The first release, 0.1.0, will cover what is on ` 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. +- Expanded windows for Transient Shaper (a scope of the output with the gain it applied, and a picture of a model hit + whose two handles set Attack, Sustain and their times) and Multiband Compressor (the three bands on a frequency axis + with each band's level, gain, threshold and up threshold, crossovers you can drag, and a rack card for the selected + band with its transfer curve). diff --git a/README.md b/README.md index 6536b165..98bc280b 100644 --- a/README.md +++ b/README.md @@ -126,7 +126,9 @@ In and Out meters and every control laid out in rows, and so do Tremolo, Auto-Pa 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, 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. +Limiter adds a short-term loudness lane against a target), Transient Shaper, whose window scopes the output with the +gain it applied, and Multiband Compressor, whose window draws each band's level, gain and thresholds on a frequency +axis with draggable crossovers; 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/device_panel.rs b/crates/dstudio-app/src/device_panel.rs index a0ae8c2b..aac31fab 100644 --- a/crates/dstudio-app/src/device_panel.rs +++ b/crates/dstudio-app/src/device_panel.rs @@ -631,7 +631,7 @@ impl Controller { } /// Transfer curve of a `Face::Transfer` knob. - fn device_transfer(&self, live: &Device, def: &DeviceDef) -> Option { + pub(crate) fn device_transfer(&self, live: &Device, def: &DeviceDef) -> Option { dstudio_core::builtin::behavior(def).and_then(|b| (b.transfer)(def, live)).or_else(|| self.view_transfer(live, def)) } @@ -1217,6 +1217,10 @@ impl Controller { } let now_ms = self.devices.panel.scope_clock.get_or_insert_with(std::time::Instant::now).elapsed().as_secs_f64() * 1e3; for id in scopes { + // Hold view (the expanded window) freezes the scope. + if self.win_held(id) { + continue; + } // Merge the newest column frame; the head moves while there is something to show. let seq = self.engine.builtin_analysis(id.0, &mut out).unwrap_or(0); let h = self.devices.panel.scopes.entry(id).or_default(); @@ -1700,6 +1704,7 @@ impl Controller { 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_MB_BAND => self.win_mb_band_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 6586734f..0d9d2687 100644 --- a/crates/dstudio-app/src/device_window.rs +++ b/crates/dstudio-app/src/device_window.rs @@ -83,6 +83,8 @@ pub(crate) const ACT_SPAN: i32 = 10; pub(crate) const ACT_TARGET: i32 = 11; /// Mastering Limiter: restart the loudness measurement. pub(crate) const ACT_LOUD_RESET: i32 = 12; +/// Multiband Compressor: the band the rack card edits (value: 0 Low, 1 Mid, 2 High). +pub(crate) const ACT_MB_BAND: i32 = 13; 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; @@ -93,6 +95,10 @@ pub(crate) const MENU_BANDS: i32 = -3; pub(crate) const MENU_ANALYZER: i32 = -4; /// Panel-menu code of the loudness target picker (Mastering Limiter). pub(crate) const MENU_TARGET: i32 = -5; +/// Panel-menu code of the Multiband Compressor's band picker. +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"]; use crate::device_window_dynamics::TARGETS; @@ -103,7 +109,9 @@ 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) + matches!(def.id, "auto-filter" | "channeleq" | "character-eq" | "transient-shaper" | "multiband-compressor") + || is_field_window(def) + || is_dynamics_window(def) } /// Windows of the level-history family (src/device_window_dynamics.rs). @@ -141,6 +149,10 @@ pub(crate) fn kit(def: &DeviceDef) -> Kit { }; match def.id { "character-eq" => eq(52.0, 346.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. + "multiband-compressor" => field_kit(WIN_W, 336.0, 52.0, 43.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), @@ -512,6 +524,10 @@ impl Row { fn main(y: f32) -> Row { Row { y, h: 106.0, dial: 28.0, value: 54.0, pill: 30.0, picker: 46.0 } } + /// A tall card (Transient Shaper's, around its 104 pt picture): 132 high. + fn tall(y: f32) -> Row { + Row { y, h: 132.0, dial: 54.0, value: 80.0, pill: 56.0, picker: 72.0 } + } /// The rack card (Character EQ's sections): 100 high. fn rack(y: f32) -> Row { Row { y, h: 100.0, dial: 22.0, value: 48.0, pill: 22.0, picker: 40.0 } @@ -577,6 +593,8 @@ impl Controller { Some(View::Custom("auto-filter")) => self.auto_filter_window_field(d, def, accent), Some(View::Field(f)) => self.field_window_canvas(d, def, f, &k, accent), _ if is_dynamics_window(def) => self.dynamics_window_canvas(d, def, &k, accent), + _ if def.id == "transient-shaper" => self.shaper_window_canvas(d, def, &k, accent), + _ if def.id == "multiband-compressor" => self.multiband_window_canvas(d, def, &k, accent), _ => PanelCanvas::default(), }; display.x = (dx + k.plot.0) * Z; @@ -586,6 +604,8 @@ impl Controller { "channeleq" => self.channel_eq_window(d, def, &mut b), "character-eq" => self.character_eq_window(d, def, &mut b), _ if is_dynamics_window(def) => self.dynamics_window(d, def, &mut b, dy + dh + 12.0), + "transient-shaper" => self.shaper_window(d, def, &mut b, dy + dh + 12.0), + "multiband-compressor" => self.multiband_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); @@ -1402,6 +1422,112 @@ impl Controller { rack.y + rack.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 { + let x = b.w - INSET - 77.5; + b.pill(PILL_GHOST_LATCH, ACT_HOLD, 0, x, 10.5, 77.5, "Hold view", self.win_held(d.id)); + let row = Row::tall(y); + let pic = crate::device_window_shaper::PIC_W; + let clusters = vec![ + (vec![Item::Knob("attack", "Attack", 2, 70.0, false), Item::Knob("sustain", "Sustain", 2, 70.0, false)], 10.0), + (vec![Item::Knob("sensitivity", "Sense", 1, 52.0, false)], 10.0), + (vec![Item::Blank(pic)], 10.0), + ( + vec![ + Item::Knob("mix", "Mix", 1, 56.0, false), + Item::Knob("output_gain", "Output", 1, 56.0, false), + Item::ToggleW("clip", "Clip", 56.0), + ], + 10.0, + ), + ]; + let widths: Vec = clusters + .iter() + .map(|(items, gap)| items.iter().map(Item::width).sum::() + gap * (items.len().saturating_sub(1)) as f32) + .collect(); + self.win_card(d, def, b, row, clusters); + let (xs, _) = gutter(INSET, b.w - 2.0 * INSET, &widths); + let mut sq = self.shaper_picture(d, def, accent_of(b)); + sq.x = xs[2] * Z; + sq.y = (row.top() + 4.0) * Z; + b.square = sq; + row.y + row.h + 16.0 + } + + /// Multiband Compressor: the global card (Input, the crossovers, Depth and Time, the + /// upward and downward amounts, Mix and Output), then the rack card of the selected band + /// (picker, Band Input, its thresholds and ratios, its times and makeup, its transfer). + fn multiband_window(&self, d: &Device, def: &'static DeviceDef, b: &mut Builder, y: f32) -> f32 { + let row = Row::main(y); + self.win_card( + d, + def, + b, + row, + vec![ + (vec![Item::Knob("input_gain", "Input", 1, 52.0, false)], 10.0), + ( + vec![ + Item::Knob("low_crossover", "Low Crossover", 1, 84.0, false), + Item::Knob("high_crossover", "High Crossover", 1, 84.0, false), + ], + 10.0, + ), + (vec![Item::Knob("depth", "Depth", 2, 64.0, false), Item::Knob("time", "Time", 2, 64.0, false)], 10.0), + (vec![Item::Knob("upward", "Upward", 2, 64.0, false), Item::Knob("downward", "Downward", 2, 64.0, false)], 10.0), + (vec![Item::Knob("mix", "Mix", 1, 52.0, false), Item::Knob("output_gain", "Output", 1, 52.0, false)], 10.0), + ], + ); + let band = self.multiband_band(d.id); + let ids = dstudio_core::builtin::MULTIBAND_BANDS[band]; + let rack = Row::main(row.y + row.h + 12.0); + let clusters = vec![ + ( + vec![ + Item::Picker(MENU_MB_BAND, MB_BANDS[band].to_string(), "Band", 72.0, false), + Item::Knob(ids[5], "Band Input", 2, 64.0, false), + ], + 10.0, + ), + (vec![Item::Knob(ids[0], "Threshold", 2, 64.0, false), Item::Knob(ids[1], "Ratio", 2, 64.0, false)], 10.0), + (vec![Item::Knob(ids[6], "Up Threshold", 2, 80.0, false), Item::Knob(ids[7], "Up Ratio", 2, 60.0, false)], 10.0), + ( + vec![ + Item::Knob(ids[2], "Attack", 1, 56.0, false), + Item::Knob(ids[3], "Release", 1, 56.0, false), + Item::Knob(ids[4], "Makeup", 1, 56.0, false), + ], + 6.0, + ), + (vec![Item::Blank(86.0)], 10.0), + ]; + let widths: Vec = clusters + .iter() + .map(|(items, gap)| items.iter().map(Item::width).sum::() + gap * (items.len().saturating_sub(1)) as f32) + .collect(); + self.win_card(d, def, b, rack, clusters); + let (xs, _) = gutter(INSET, b.w - 2.0 * INSET, &widths); + let mut sq = self.dynamics_square(d, def, accent_of(b)); + sq.x = (xs[4] + 4.0) * Z; + sq.y = (rack.top() + 4.0) * Z; + b.square = sq; + rack.y + rack.h + 16.0 + } + + /// Band picker menu rows (panel-menu code MENU_MB_BAND). + pub(crate) fn win_mb_band_rows(&self, device: DeviceId) -> crate::device_mod::MenuRows { + let cur = self.multiband_band(device); + MB_BANDS + .iter() + .enumerate() + .map(|(i, name)| { + let pick = Some(crate::devices::MenuPick::Window(device, ACT_MB_BAND, i as i32)); + (name.to_string(), if i == cur { "\u{2713}".to_string() } else { String::new() }, pick, false) + }) + .collect() + } + /// 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). @@ -1813,6 +1939,9 @@ impl Controller { (ACT_TARGET, _) => { self.devices.wins.target.insert(device, value.clamp(0, TARGETS.len() as i32 - 1) as usize); } + (ACT_MB_BAND, _) => { + self.devices.panel.views.entry(device).or_default().band = value.clamp(0, 2) as usize; + } (ACT_LOUD_RESET, _) => { let now = self.win_now(); self.devices.wins.loud_from.insert(device, now); @@ -2101,6 +2230,85 @@ mod tests { assert_eq!((ceiling.label.as_str(), ceiling.value.as_str()), ("Ceiling", "\u{2212}1.0 dBTP")); } + /// Transient Shaper: the scope fills the display, one card holds every control but the + /// two times, which are the shape picture's handles (drag zones). + #[test] + fn transient_shaper_window_sets_times_from_the_picture() { + use slint::Model; + let (mut c, did, def) = controller_with("transient-shaper"); + assert!(has_window(def)); + let v = view(&c, did, def); + assert!((v.h / Z - 440.0).abs() < 0.5 && (v.w / Z - 880.0).abs() < 0.5, "{} x {}", v.w / Z, v.h / Z); + assert_eq!(knob_names(&v), ["Attack", "Sustain", "Sense", "Mix", "Output"]); + assert!(v.display.visible && v.display.paths.row_count() > 3); + let zones: Vec<_> = v.square.zones.iter().collect(); + let idx = |id: &str| def.index_of(id).unwrap() as i32; + assert_eq!(zones.len(), 2); + assert_eq!((zones[0].param_x, zones[0].param_y), (idx("attack_time"), idx("attack"))); + assert_eq!((zones[1].param_x, zones[1].param_y), (idx("sustain_time"), idx("sustain"))); + for z in &zones { + assert!(z.x + z.w / 2.0 >= 0.0 && z.x + z.w / 2.0 <= v.square.w && z.y + z.h / 2.0 <= v.square.h); + } + // Raising Attack lifts its handle. + let y0 = zones[0].y; + c.execute(Command::SetDeviceParam { device: did, param: "attack".into(), value: 80.0 }); + assert!(view(&c, did, def).square.zones.iter().next().unwrap().y < y0); + c.win_action(did, ACT_HOLD, 0); + assert!(view(&c, did, def).pills.iter().any(|p| p.param == ACT_HOLD && p.active)); + } + + /// Multiband Compressor: the band field's handles edit the selected band's thresholds + /// and the crossovers; the band picker switches the rack card to another band. + #[test] + fn multiband_window_edits_the_selected_band() { + use slint::Model; + let (mut c, did, def) = controller_with("multiband-compressor"); + assert!(has_window(def)); + let v = view(&c, did, def); + assert!((v.h / Z - 640.0).abs() < 0.5 && (v.w / Z - WIN_W).abs() < 0.5, "{} x {}", v.w / Z, v.h / Z); + assert_eq!( + knob_names(&v), + [ + "Input", + "Low Crossover", + "High Crossover", + "Depth", + "Time", + "Upward", + "Downward", + "Mix", + "Output", + "Band Input", + "Threshold", + "Ratio", + "Up Threshold", + "Up Ratio", + "Attack", + "Release", + "Makeup" + ] + ); + let idx = |id: &str| def.index_of(id).unwrap() as i32; + let zones: Vec<_> = v.display.zones.iter().collect(); + // Two threshold lines per band, then the two crossovers. + assert_eq!(zones.len(), 8); + assert_eq!(zones[0].param_y, idx("low_threshold")); + assert_eq!(zones[5].param_y, idx("high_up_threshold")); + assert_eq!((zones[6].param_x, zones[7].param_x), (idx("low_crossover"), idx("high_crossover"))); + assert!(v.square.visible && v.square.paths.row_count() > 0); + assert!(v.knobs.iter().any(|k| k.param == idx("low_threshold"))); + // Picking Mid moves the rack to the mid band's parameters and lights its pills. + c.win_action(did, ACT_MB_BAND, 1); + let v = view(&c, did, def); + assert!(v.pills.iter().any(|p| p.param == MENU_MB_BAND && p.label == "Mid")); + assert!(v.knobs.iter().any(|k| k.param == idx("mid_up_ratio")) && !v.knobs.iter().any(|k| k.param == idx("low_threshold"))); + assert_eq!(v.display.grips.iter().filter(|g| g.hot).count(), 2); + assert_eq!(c.win_mb_band_rows(did)[1].1, "\u{2713}"); + // A narrow low band (crossover at its floor) drops its handles. + c.execute(Command::SetDeviceParam { device: did, param: "low_crossover".into(), value: 20.0 }); + assert_eq!(view(&c, did, def).display.zones.iter().count(), 6); + } + /// A full ten-second history draws as one line per series, however many samples it holds. #[test] fn dynamics_history_draws_once_per_series() { @@ -2120,7 +2328,16 @@ mod tests { #[ignore] fn bench_dynamics_windows() { let n = 500; - for id in ["compressor", "limiter", "gate", "glue-compressor", "character-compressor", "mastering-limiter"] { + for id in [ + "compressor", + "limiter", + "gate", + "glue-compressor", + "character-compressor", + "mastering-limiter", + "transient-shaper", + "multiband-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 ae5975ea..b9baced0 100644 --- a/crates/dstudio-app/src/device_window_dynamics.rs +++ b/crates/dstudio-app/src/device_window_dynamics.rs @@ -494,7 +494,11 @@ 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)).or_else(|| behavior_law(def, d)) else { + let Some((law, at, knee)) = face.and_then(|f| crate::device_panel::face_law(f, num)).or_else(|| { + let t = self.device_transfer(d, def)?; + let at = def.param("threshold").map_or(0.5 * (t.bend.0 + t.bend.1), |p| self.panel_value(d, def, p)); + transfer_law(t, at) + }) else { return PanelCanvas::default(); }; let mut paths = Vec::new(); @@ -528,16 +532,14 @@ 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. +/// A computed static curve (Character Compressor's models, the Multiband's selected band) +/// 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))?; +fn transfer_law(t: dstudio_core::builtin::Transfer, at: f32) -> Option<(Box f32>, f32, (f32, f32))> { 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 { diff --git a/crates/dstudio-app/src/device_window_multiband.rs b/crates/dstudio-app/src/device_window_multiband.rs new file mode 100644 index 00000000..c98eeb49 --- /dev/null +++ b/crates/dstudio-app/src/device_window_multiband.rs @@ -0,0 +1,196 @@ +//! Multiband Compressor's expanded window display: the three bands on a log frequency +//! axis (20 Hz..20 kHz) against a 0..−80 dBFS ladder. Each band shows the region its +//! thresholds act on, its detector level (a wash under a hairline) and its gain hanging +//! off that level, with its Threshold (dashed) and Up Threshold (dotted) lines and the two +//! crossovers as drag handles with value pills. The selected band (the rack card's Band +//! picker) is lit. + +use crate::PanelCanvas; +use crate::controller::Controller; +use crate::device_canvas::{dashed, fill, rgba, stroke, text, white}; +use crate::device_panel::Z; +use crate::device_window::Kit; +use crate::{PanelGrip, PanelPath, PanelText, PanelZone}; +use dstudio_core::Device; +use dstudio_core::builtin::{DeviceDef, MULTIBAND_BANDS}; +use slint::{Color, ModelRc, VecModel}; +use std::rc::Rc; + +fn model(v: Vec) -> ModelRc { + ModelRc::from(Rc::new(VecModel::from(v))) +} + +const F_LO: f32 = 20.0; +const F_HI: f32 = 20000.0; +const DB_TOP: f32 = 0.0; +const DB_BOTTOM: f32 = -80.0; +const DB_RUNG: f32 = 10.0; +const HZ_TICKS: [f32; 8] = [50.0, 100.0, 200.0, 500.0, 1000.0, 2000.0, 5000.0, 10000.0]; +/// Inks: the selected band, a threshold's region, the level wash (top, floor), the gain. +const SELECT_FILL: f32 = 0.03; +const ACT_FILL: f32 = 0.035; +const LEVEL_TOP: f32 = 0.09; +const LEVEL_FLOOR: f32 = 0.015; +const GAIN_FILL: f32 = 0.30; +const GAIN_LINE: f32 = 0.85; +const PILL_INSET: f32 = 6.0; + +/// A band's level as drawn: "−60.0 dB". +fn db_text(db: f32) -> String { + if db < -0.05 { format!("\u{2212}{:.1} dB", -db) } else { format!("{:.1} dB", db.max(0.0)) } +} + +/// Hertz on the axis: "50", "1k", "10k". +fn hz_label(hz: f32) -> String { + if hz >= 1000.0 { format!("{}k", hz / 1000.0) } else { format!("{hz}") } +} + +impl Controller { + /// The band currently selected on the Multiband card and window. + pub(crate) fn multiband_band(&self, id: dstudio_core::DeviceId) -> usize { + self.devices.panel.views.get(&id).map_or(0, |v| v.band).min(2) + } + + pub(crate) fn multiband_window_canvas(&self, d: &Device, def: &'static DeviceDef, k: &Kit, accent: Color) -> PanelCanvas { + let (_, _, dw, dh) = k.display; + let (l, t, r, b) = k.plot; + let (pw, ph) = ((dw - l - r) * Z, (dh - t - b) * Z); + let val = |id: &str| def.param(id).map_or(0.0, |p| self.panel_value(d, def, p)); + let idx = |id: &str| def.index_of(id).map_or(-1, |i| i as i32); + let x_of = |hz: f32| (hz.clamp(F_LO, F_HI) / F_LO).ln() / (F_HI / F_LO).ln() * pw; + let y_of = |db: f32| ((DB_TOP - db) / (DB_TOP - DB_BOTTOM)).clamp(0.0, 1.0) * ph; + let (f1, f2) = (val("low_crossover"), val("high_crossover")); + let edges = [0.0, x_of(f1), x_of(f2).max(x_of(f1)), pw]; + let sel = self.multiband_band(d.id); + let (levels, gains) = self.devices.panel.views.get(&d.id).map_or(([-100.0; 3], [0.0; 3]), |v| v.meters()); + let (down, up, depth) = (val("downward"), val("upward"), val("depth")); + let handle = Color::from_argb_u8(140, 200, 198, 188); + let mut paths: Vec = Vec::new(); + let mut texts: Vec = Vec::new(); + let rect = |x0: f32, y0: f32, x1: f32, y1: f32| format!("M{x0:.1} {y0:.1} H{x1:.1} V{y1:.1} H{x0:.1} Z"); + + paths.push(fill(rect(edges[sel], 0.0, edges[sel + 1], ph), white(SELECT_FILL))); + for hz in HZ_TICKS { + let x = x_of(hz).round() + 0.5; + paths.push(stroke(format!("M{x:.1} 0 V{ph:.1}"), white(0.04), 1.0)); + } + let mut db = DB_TOP; + while db >= DB_BOTTOM - 1e-3 { + let y = y_of(db).round() + 0.5; + if db != DB_TOP && db != DB_BOTTOM { + paths.push(stroke(format!("M0 {y:.1} H{pw:.1}"), white(0.05), 1.0)); + } + let label = if db == 0.0 { "0".to_string() } else { format!("\u{2212}{}", -db as i32) }; + texts.push(text(-8.0 * Z, y_of(db), 40.0 * Z, label, white(0.3), 11.0 * Z, 2)); + db -= DB_RUNG; + } + + // The regions each band acts on, then its level and gain. + for band in 0..3 { + let ids = MULTIBAND_BANDS[band]; + let (x0, x1) = (edges[band], edges[band + 1]); + if x1 - x0 < 1.0 { + continue; + } + let down_acts = depth > 0.0 && down > 0.0 && val(ids[1]) > 1.0; + let up_acts = depth > 0.0 && up > 0.0 && val(ids[7]) > 1.0; + if down_acts { + paths.push(fill(rect(x0, 0.0, x1, y_of(val(ids[0]))), white(ACT_FILL))); + } + if up_acts { + paths.push(fill(rect(x0, y_of(val(ids[6])), x1, ph), white(ACT_FILL))); + } + let level = levels[band]; + let ly = y_of(level); + paths.push(PanelPath { fill2: white(LEVEL_FLOOR), ..fill(rect(x0, ly, x1, ph), white(LEVEL_TOP)) }); + let gy = y_of(level + gains[band]); + if (gy - ly).abs() > 0.5 { + paths.push(fill(rect(x0, ly.min(gy), x1, ly.max(gy)), rgba(accent, GAIN_FILL))); + paths.push(stroke(format!("M{x0:.1} {gy:.1} H{x1:.1}"), rgba(accent, GAIN_LINE), 1.25 * Z)); + } + let ink = if level > DB_BOTTOM + 0.5 { 0.55 } else { 0.12 }; + paths.push(stroke(format!("M{x0:.1} {ly:.1} H{x1:.1}"), white(ink), 1.5 * Z)); + } + + // The frequency axis, the ruler's unit, the transport word and the legend. + let axis_y = ph + 12.0 * Z; + for hz in HZ_TICKS { + texts.push(text(x_of(hz), axis_y, 40.0 * Z, hz_label(hz), white(0.3), 9.0 * Z, 1)); + } + texts.push(text(0.0, axis_y, 30.0 * Z, "Hz", white(0.3), 9.0 * Z, 0)); + texts.push(text(-8.0 * Z, axis_y, 40.0 * Z, "dBFS", white(0.3), 9.0 * Z, 2)); + if !self.project_playing() { + texts.push(text(pw, axis_y, 60.0 * Z, "stopped", white(0.55), 9.0 * Z, 2)); + } + let ly = ph + 31.0 * Z; + let (glyph, gap, entry) = (14.0 * Z, 6.0 * Z, 16.0 * Z); + let mut x = 0.0; + for (kind, label) in [(0, "Level"), (1, "Gain"), (2, "Threshold"), (3, "Up Threshold")] { + match kind { + 0 => paths.push(stroke(format!("M{x:.1} {ly:.1} h{glyph:.1}"), white(0.55), 1.5 * Z)), + 1 => paths.push(fill(rect(x, ly - 4.0 * Z, x + glyph, ly + 4.0 * Z), rgba(accent, GAIN_FILL + 0.02))), + 2 => paths.push(stroke(dashed(&[(x, ly), (x + glyph, ly)], 6.0 * Z, 5.0 * Z), handle, 1.5 * Z)), + _ => paths.push(stroke(dashed(&[(x, ly), (x + glyph, ly)], 2.0 * Z, 3.0 * Z), handle, 1.5 * Z)), + } + texts.push(text(x + glyph + gap, ly, 90.0 * Z, label, white(0.7), 9.0 * Z, 0)); + x += glyph + gap + crate::text_measure::value_width(label) * 0.9 * Z + entry; + } + + // Handles: each band's two thresholds across its own slice, then the crossovers. + let mut grips = Vec::new(); + let mut zones = Vec::new(); + let pill_w = |v: &str| (16.0 + crate::text_measure::value_width(v) * 1.1) * Z; + let per_db = ph / (DB_TOP - DB_BOTTOM); + for band in 0..3 { + let ids = MULTIBAND_BANDS[band]; + let (x0, x1) = (edges[band], edges[band + 1]); + if x1 - x0 < 1.0 { + continue; + } + for (id, up_line) in [(ids[0], false), (ids[6], true)] { + let v = val(id); + let y = y_of(v).round() + 0.5; + let pattern = if up_line { (2.0, 3.0) } else { (6.0, 5.0) }; + paths.push(stroke(dashed(&[(x0, y), (x1, y)], pattern.0 * Z, pattern.1 * Z), handle, 1.5 * Z)); + let value = db_text(v); + if x1 - x0 >= pill_w(&value) + 2.0 * PILL_INSET * Z { + let (gx, anchor) = if up_line { (x1 - PILL_INSET * Z, 2) } else { (x0 + PILL_INSET * Z, 0) }; + grips.push(PanelGrip { x: gx, y, anchor, label: "".into(), value: value.into(), hot: band == sel, plain: false }); + } + let range = def.param(id).map_or(1.0, |p| (p.max - p.min).max(1e-3)); + zones.push(PanelZone { + x: x0, + y: y - 6.0 * Z, + w: x1 - x0, + h: 12.0 * Z, + param_x: -1, + param_y: idx(id), + rate_x: 0.0, + rate_y: 1.0 / (per_db * range), + }); + } + } + for (id, hz, edge) in [("low_crossover", f1, edges[1]), ("high_crossover", f2, edges[2])] { + let x = edge.round() + 0.5; + paths.push(stroke(format!("M{x:.1} 0 V{ph:.1}"), handle, 1.5 * Z)); + let value = def.param(id).map_or_else(String::new, |p| p.format(hz)); + let w = pill_w(&value); + let gx = (x - w / 2.0).clamp(2.0 * Z, pw - w - 2.0 * Z); + grips.push(PanelGrip { x: gx, y: ph - 14.0 * Z, anchor: 0, label: "".into(), value: value.into(), hot: false, plain: false }); + // Norm per px: the axis is log 20 Hz..20 kHz, the parameter log over its own range. + let rate = def.param(id).map_or(0.0, |p| (F_HI / F_LO).ln() / pw / (p.max / p.min).ln()); + zones.push(PanelZone { x: x - 6.0 * Z, y: 0.0, w: 12.0 * Z, h: ph, param_x: idx(id), param_y: -1, rate_x: rate, rate_y: 0.0 }); + } + PanelCanvas { + visible: true, + w: pw, + h: ph, + paths: model(paths), + texts: model(texts), + grips: model(grips), + zones: model(zones), + label: "Bands".into(), + ..Default::default() + } + } +} diff --git a/crates/dstudio-app/src/device_window_shaper.rs b/crates/dstudio-app/src/device_window_shaper.rs new file mode 100644 index 00000000..277a4326 --- /dev/null +++ b/crates/dstudio-app/src/device_window_shaper.rs @@ -0,0 +1,287 @@ +//! Transient Shaper's expanded window: the gain scope at window size (the output's peaks +//! as a mirrored grey silhouette, what Clip shaved as a faint ghost, and the gain the +//! shaper applied as one accent line over the last 4 s), and the shape picture in its +//! control card: a model hit run through the shaper's own detector, with the gain curve +//! the settings ask for and its two handles (Attack amount and time, Sustain amount and +//! time) to drag. + +use crate::PanelCanvas; +use crate::controller::Controller; +use crate::device_canvas::{dashed, fill, path, rgba, stroke, text, white}; +use crate::device_panel::Z; +use crate::device_window::Kit; +use crate::{PanelPath, PanelText, PanelZone}; +use dstudio_core::Device; +use dstudio_core::builtin::DeviceDef; +use slint::{Color, ModelRc, VecModel}; +use std::cell::RefCell; +use std::rc::Rc; + +fn model(v: Vec) -> ModelRc { + ModelRc::from(Rc::new(VecModel::from(v))) +} + +/// The picture's size in the card (reference points), and its inner margin. +pub(crate) const PIC_W: f32 = 332.0; +pub(crate) const PIC_H: f32 = 104.0; +const PIC_M: f32 = 6.0; +/// The model hit: sample rate, length (the longest front plus the longest tail, ms), +/// decay (ms), and where the log time axis turns (ms). +const MODEL_SR: f32 = 8000.0; +const T_MAX: f32 = 2100.0; +const DECAY_MS: f32 = 180.0; +const TAU: f32 = 6.0; +/// Silhouette release per plot point (ms). +const RELEASE_MS: f32 = 3.0; +/// Inks. +const INK_WAVE: f32 = 0.30; +const INK_CLIP: f32 = 0.11; +/// The scope's gain scale (dB at the well's edge). +const GAIN_DB: f32 = 12.0; + +fn warp(ms: f32) -> f32 { + (ms.max(0.0) / TAU).ln_1p() / (T_MAX / TAU).ln_1p() +} + +/// One pole at `ms` for the model's rate (as the kernel's `dsp::pole`). +fn pole(ms: f32) -> f32 { + if ms <= 0.0 { 0.0 } else { (-1000.0 / (ms * MODEL_SR)).exp() } +} + +/// The model hit through the shaper, binned to `cols` columns on the log time axis: +/// each column's output peak (released like the scope's bars). +fn run_model(v: &dyn Fn(&str) -> f32, cols: usize) -> Vec { + type Key = (usize, [u32; 6]); + thread_local! { + static CACHE: RefCell)>> = const { RefCell::new(None) }; + } + let ids = ["attack", "sustain", "sensitivity", "attack_time", "sustain_time", "mix"]; + let vals: [f32; 6] = ids.map(v); + let key: Key = (cols, vals.map(f32::to_bits)); + if let Some(hit) = CACHE.with(|c| c.borrow().as_ref().filter(|(k, _)| *k == key).map(|(_, h)| h.clone())) { + return hit; + } + let [attack, sustain, sens, att_ms, sus_ms, mix] = vals; + let (attack, sustain, sens, mix) = (attack / 100.0, sustain / 100.0, sens / 100.0, mix / 100.0); + let k = ((sens - 0.5) * 2.4).exp2(); + let floor = 10f32.powf((-50.0 - 40.0 * sens) / 20.0); + let a_slow = pole(att_ms.clamp(0.5, 1000.0)); + let fall_sus = pole(if sus_ms >= 1999.0 { 10_000.0 } else { sus_ms.clamp(1.0, 10_000.0) }); + let (ka, ks) = (0.5 * k * attack, 0.6 * k * sustain); + let (rise, fall, smooth) = (pole(0.3), pole(40.0), pole(0.5)); + let (mut env, mut slow, mut tail, mut gdb) = (floor, floor, floor, 0.0f32); + let mut peak = vec![0.0f32; cols]; + let n = (T_MAX * 0.001 * MODEL_SR) as usize; + let mut phase = 0.0f32; + for i in 0..n { + let ms = i as f32 * 1000.0 / MODEL_SR; + let hz = 55.0 + 125.0 * (-ms / 22.0).exp(); + phase += std::f32::consts::TAU * hz / MODEL_SR; + let s = (-ms / DECAY_MS).exp() * phase.sin(); + let x = s.abs().max(floor); + env = x + if x > env { rise } else { fall } * (env - x); + slow = if env < slow { env } else { env + a_slow * (slow - env) }; + tail = if env > tail { env } else { env + fall_sus * (tail - env) }; + let att = (6.020_6 * (env / slow).log2()).min(24.0); + let sus = (6.020_6 * (tail / env).log2()).min(30.0); + let target = (ka * att + ks * sus).clamp(-30.0, 24.0); + gdb = target + smooth * (gdb - target); + let y = s + mix * (s * 10f32.powf(gdb / 20.0) - s); + let b = ((warp(ms) * cols as f32) as usize).min(cols - 1); + peak[b] = peak[b].max(y.abs()); + } + // The scope's silhouette: each column's peak, released over the time it spans. + let unwarp = |u: f32| TAU * (u * (T_MAX / TAU).ln_1p()).exp_m1(); + let mut e = 0.0f32; + for (x, p) in peak.iter_mut().enumerate() { + let span = (unwarp((x + 1) as f32 / cols as f32) - unwarp(x as f32 / cols as f32)).max(1e-3); + e = p.max(e * (-span / RELEASE_MS).exp()); + *p = e; + } + CACHE.with(|c| *c.borrow_mut() = Some((key, peak.clone()))); + peak +} + +impl Controller { + /// The window's scope: legend on the caption row, the well with the output's + /// silhouette, the clipped ghost, the rest line and the applied gain. + pub(crate) fn shaper_window_canvas(&self, d: &Device, def: &'static DeviceDef, k: &Kit, accent: Color) -> PanelCanvas { + let (_, _, dw, dh) = k.display; + let (l, t, r, b) = k.plot; + let (pw, ph) = ((dw - l - r) * Z, (dh - t - b) * Z); + let val = |id: &str| def.param(id).map_or(0.0, |p| self.panel_value(d, def, p)); + let clip = val("clip") >= 0.5; + let mut paths: Vec = Vec::new(); + let mut texts: Vec = Vec::new(); + + // Legend: Output (grey block), Applied Gain (accent line), Clipped (ghost block). + let base = -12.0 * Z; + let (sw, sh, sg, eg) = (12.0 * Z, 8.0 * Z, 6.0 * Z, 18.0 * Z); + let mut x = 2.0 * Z; + for (kind, label) in [(0, "Output"), (1, "Applied Gain"), (2, "Clipped")] { + let sy = base - sh / 2.0; + let block = format!("M{x:.1} {sy:.1} h{sw:.1} v{sh:.1} h{:.1} Z", -sw); + match kind { + 0 => paths.push(fill(block, white(INK_WAVE))), + 1 => paths.push(stroke(format!("M{x:.1} {base:.1} h{sw:.1}"), accent, 2.0 * Z)), + _ => { + paths.push(fill(block.clone(), white(INK_CLIP))); + paths.push(stroke(block, white(0.22), 1.0)); + } + } + texts.push(PanelText { weight: 600, ..text(x + sw + sg, base, 120.0 * Z, label, white(0.7), 12.0 * Z, 0) }); + x += sw + sg + crate::text_measure::value_width(label) * 1.2 * Z + eg; + } + + // The well. + let rr = 4.0 * Z; + let well = format!( + "M{rr:.1} 0 H{:.1} Q{pw:.1} 0 {pw:.1} {rr:.1} V{:.1} Q{pw:.1} {ph:.1} {:.1} {ph:.1} H{rr:.1} Q0 {ph:.1} 0 {:.1} V{rr:.1} Q0 0 {rr:.1} 0 Z", + pw - rr, + ph - rr, + pw - rr, + ph - rr + ); + paths.push(fill(well.clone(), white(0.025))); + let mid = ph / 2.0; + let reach = mid - Z; + let r_of = |peak: f32| (peak.abs().min(1.41) / 1.41).sqrt() * reach; + let y_of = |db: f32| mid - db.clamp(-GAIN_DB, GAIN_DB) / GAIN_DB * (reach - 4.0 * Z); + let bars = (pw / Z).floor().max(1.0); + let px = self.devices.panel.scopes.get(&d.id).map(|h| h.pixels(bars, 2.0)); + if let Some(px) = px.as_ref().filter(|p| !p.out.is_empty()) { + let n = px.out.len(); + let x_of = |i: usize| ((i as f32 - 1.0 + px.offset) * Z).clamp(0.0, pw); + let band = |outer: &dyn Fn(usize) -> f32, inner: &dyn Fn(usize) -> f32| { + let mut pts: Vec<(f32, f32)> = (0..n).map(|i| (x_of(i), mid - outer(i))).collect(); + pts.extend((0..n).rev().map(|i| (x_of(i), mid - inner(i)))); + format!("{} Z", path(&pts)) + }; + let out_r = |i: usize| r_of(px.out[i]); + paths.push(fill(band(&out_r, &|i| -out_r(i)), white(INK_WAVE))); + if clip && (0..n).any(|i| px.pre[i] > px.out[i] * 1.005) { + let pre_r = |i: usize| if px.pre[i] > px.out[i] * 1.005 { r_of(px.pre[i]) } else { out_r(i) }; + paths.push(fill(format!("{} {}", band(&pre_r, &out_r), band(&|i| -out_r(i), &|i| -pre_r(i))), white(INK_CLIP))); + } + let zy = mid.round() + 0.5; + paths.push(stroke(dashed(&[(0.0, zy), (pw, zy)], 3.0 * Z, 4.0 * Z), white(0.14), 1.0)); + let mut gain: Vec<(f32, f32)> = (0..n).map(|i| (x_of(i), y_of(px.gain[i]))).collect(); + gain.push((pw, y_of(px.gain[n - 1]))); + paths.push(stroke(path(&gain), accent, 2.0 * Z)); + } else { + let zy = mid.round() + 0.5; + paths.push(stroke(dashed(&[(0.0, zy), (pw, zy)], 3.0 * Z, 4.0 * Z), white(0.14), 1.0)); + paths.push(stroke(format!("M0 {mid:.1} L{pw:.1} {mid:.1}"), accent, 2.0 * Z)); + } + paths.push(stroke(well.clone(), white(0.06), 1.0)); + if self.win_held(d.id) { + paths.push(stroke(well, rgba(accent, 0.8), 1.0)); + texts.push(text(pw - 68.0 * Z, 12.0 * Z, 60.0 * Z, "Held", accent, 9.0 * Z, 2)); + } + PanelCanvas { + visible: true, + w: pw, + h: ph, + paths: model(paths), + texts: model(texts), + label: "Applied Gain".into(), + ..Default::default() + } + } + + /// The shape picture: the model hit's output, the gain curve these settings ask for, + /// and the Attack and Sustain handles, each a drag zone for its amount (up) and time + /// (across). + pub(crate) fn shaper_picture(&self, d: &Device, def: &'static DeviceDef, accent: Color) -> PanelCanvas { + let val = |id: &str| def.param(id).map_or(0.0, |p| self.panel_value(d, def, p)); + let (w, h) = (PIC_W * Z, PIC_H * Z); + let (l, top) = (PIC_M * Z, PIC_M * Z); + let (iw, ih) = (w - 2.0 * l, h - 2.0 * top); + let mid = top + ih / 2.0; + let half = ih / 2.0 - Z; + let cols = iw.round().max(2.0) as usize; + let x_at = |ms: f32| l + warp(ms) * iw; + let y_amp = |a: f32| mid - a.signum() * (a.abs() / 4.0).sqrt().min(1.0) * half; + let y_amount = |pct: f32| mid - (pct / 100.0).clamp(-1.0, 1.0) * half; + let mut paths: Vec = Vec::new(); + let my = mid.round() + 0.5; + paths.push(stroke(format!("M{l:.1} {my:.1} L{:.1} {my:.1}", l + iw), white(0.08), 1.0)); + + let peak = run_model(&val, cols); + let col_x = |i: usize| l + i as f32 * iw / (cols - 1) as f32; + let mut band: Vec<(f32, f32)> = peak.iter().enumerate().map(|(i, p)| (col_x(i), y_amp(*p))).collect(); + band.extend(peak.iter().enumerate().rev().map(|(i, p)| (col_x(i), y_amp(-*p)))); + paths.push(fill(format!("{} Z", path(&band)), white(INK_WAVE))); + + // The curve: Attack's amount through the front, handing over to Sustain's, which + // falls back to nothing over Sustain Time (or holds, at Full). + let (att, sus) = (val("attack"), val("sustain")); + let att_ms = val("attack_time"); + let sus_ms = val("sustain_time"); + let full = sus_ms >= 1999.0; + let hand_off = (att_ms * 0.5).max(1.0); + let gain_at = |ms: f32| { + if ms <= att_ms { + return att; + } + let after = ms - att_ms; + let w = (-after / hand_off).exp(); + let tail = if full { sus } else { sus * (-after / sus_ms).exp() }; + att * w + tail * (1.0 - w) + }; + let unwarp = |u: f32| TAU * (u * (T_MAX / TAU).ln_1p()).exp_m1(); + let curve: Vec<(f32, f32)> = + (0..=cols).map(|i| i as f32 / cols as f32).map(|u| (l + u * iw, y_amount(gain_at(unwarp(u))))).collect(); + paths.push(stroke(path(&curve), accent, 2.0 * Z)); + + // The handles, and their drag zones. + let sus_end = if full { T_MAX } else { att_ms + sus_ms }; + let handles = [("attack", "attack_time", x_at(att_ms), y_amount(att)), ("sustain", "sustain_time", x_at(sus_end), y_amount(sus))]; + let mut zones = Vec::new(); + let r = 4.5 * Z; + for (amount, time, hx, hy) in handles { + let dot = format!("M{:.2} {hy:.2} a{r:.2} {r:.2} 0 1 0 {:.2} 0 a{r:.2} {r:.2} 0 1 0 {:.2} 0 Z", hx - r, 2.0 * r, -2.0 * r); + paths.push(PanelPath { width: 2.0 * Z, stroke: accent, ..fill(dot, white(0.92)) }); + let hit = 12.0 * Z; + zones.push(PanelZone { + x: hx - hit, + y: hy - hit, + w: 2.0 * hit, + h: 2.0 * hit, + param_x: def.index_of(time).map_or(-1, |i| i as i32), + param_y: def.index_of(amount).map_or(-1, |i| i as i32), + rate_x: 1.0 / iw.max(1.0), + rate_y: 1.0 / (2.0 * half).max(1.0), + }); + } + PanelCanvas { visible: true, w, h, paths: model(paths), zones: model(zones), ..Default::default() } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + /// Attack lifts the front of the hit and leaves the tail; Sustain does the opposite. + #[test] + fn model_hit_follows_attack_and_sustain() { + let at = |attack: f32, sustain: f32| { + move |id: &str| match id { + "attack" => attack, + "sustain" => sustain, + "sensitivity" => 50.0, + "attack_time" => 30.0, + "sustain_time" => 2000.0, + _ => 100.0, + } + }; + let flat = run_model(&at(0.0, 0.0), 300); + let punch = run_model(&at(100.0, 0.0), 300); + let long = run_model(&at(0.0, 100.0), 300); + let front = (warp(5.0) * 300.0) as usize; + let tail = (warp(600.0) * 300.0) as usize; + assert!(punch[front] > flat[front] * 1.2, "{} {}", punch[front], flat[front]); + assert!((punch[tail] - flat[tail]).abs() < flat[tail] * 0.3); + assert!(long[tail] > flat[tail] * 1.2, "{} {}", long[tail], flat[tail]); + } +} diff --git a/crates/dstudio-app/src/main.rs b/crates/dstudio-app/src/main.rs index 88855a1e..b876f840 100644 --- a/crates/dstudio-app/src/main.rs +++ b/crates/dstudio-app/src/main.rs @@ -57,6 +57,8 @@ mod device_views; mod device_window; mod device_window_dynamics; mod device_window_fields; +mod device_window_multiband; +mod device_window_shaper; mod devices; mod devminimap; mod dialogs; diff --git a/crates/dstudio-app/src/panel_multiband.rs b/crates/dstudio-app/src/panel_multiband.rs index b3f9cadb..3bfdd618 100644 --- a/crates/dstudio-app/src/panel_multiband.rs +++ b/crates/dstudio-app/src/panel_multiband.rs @@ -54,6 +54,11 @@ impl Default for ViewState { } impl ViewState { + /// The smoothed band meters: levels and gain changes (dB). + pub(crate) fn meters(&self) -> ([f32; 3], [f32; 3]) { + (self.level, self.gain) + } + /// Fold in engine readouts (in, out, 3 band levels, 3 band gains): rising /// values follow in 30 ms, falling ones in 300 ms. True when the meters moved. pub fn poll(&mut self, r: &[f32]) -> bool { diff --git a/crates/dstudio-app/ui/device_window.slint b/crates/dstudio-app/ui/device_window.slint index 4bc3ee50..ac5293aa 100644 --- a/crates/dstudio-app/ui/device_window.slint +++ b/crates/dstudio-app/ui/device_window.slint @@ -7,7 +7,7 @@ // with 40 / 48 pt knobs whose value and name stack under the ring. import { Studio, DeviceCard, PanelKnob, WinPill, WinBox, WinMeter, PanelTick } from "studio.slint"; -import { PanelStyle, ParamDrag, ParamKeys, ValueEditor, DeviceCanvas } from "device_panel.slint"; +import { PanelStyle, ParamDrag, ParamKeys, ValueEditor, DeviceCanvas, ZoneDrag } from "device_panel.slint"; export global WinStyle { out property well: #0e0e11; // window body @@ -383,6 +383,7 @@ export component DeviceWindowFace inherits Rectangle { x: t.x; y: t.y; width: t.w; height: t.h; text: t.text; color: t.color; font-size: t.size; font-weight: t.weight; vertical-alignment: center; } + for z in root.card.win.square.zones: ZoneDrag { x: z.x; y: z.y; width: z.w; height: z.h; device: root.card.id; zone: z; } } Rectangle { opacity: root.card.enabled ? 1 : 0.45; diff --git a/docs/devices.md b/docs/devices.md index 67ead00a..ca72f083 100644 --- a/docs/devices.md +++ b/docs/devices.md @@ -66,7 +66,7 @@ flowchart LR 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, Glue Compressor, Character Compressor and Mastering - Limiter), otherwise the card itself in a window. A + Limiter; Transient Shaper; Multiband Compressor), 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 @@ -93,7 +93,17 @@ flowchart LR 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 + solid line with its own grip. Transient Shaper's window + (`device_window_shaper.rs`) scopes the output (the card's gain scope) with + the gain it applied, and its card holds a picture of a model hit (the + kernel's detector run on a synthetic kick) whose two handles drag Attack + with its time and Sustain with its time. Multiband Compressor's window + (`device_window_multiband.rs`) draws the three bands on a log 20 Hz..20 kHz + axis against 0..−80 dBFS: each band's level and gain (the card's smoothed + band meters), its Threshold and Up Threshold as lines you drag, and the two + crossovers as vertical handles. Its rack card edits the band picked in its + Band menu (`MENU_MB_BAND`, `ACT_MB_BAND`; the same selection as the card's) + beside that band's transfer square. 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