From e78ffd4f3b9198123c71e531be761dfb191083c0 Mon Sep 17 00:00:00 2001 From: Chris Laupama <42254688+chrislaupama@users.noreply.github.com> Date: Mon, 16 Nov 2026 02:09:41 +0000 Subject: [PATCH] Add expanded De-Clipper, De-Esser, De-Hummer and De-Noiser windows De-Clipper joins the waveshaper windows with its card's law: the transfer held at the threshold beside two cycles of a sine, the reduction lit against unity, and a card with Threshold, Ceiling, Oversampling and Mix. De-Esser, De-Hummer and De-Noiser draw the card's graph at window size (WindowScope, WIN_PLOT) with a dB ladder, a frequency axis, a caption and a legend, and one card of every control; their pointer events carry phase + 16 so drags are hit tested at that size. Tests declipper_window_shows_the_transfer_and_every_control, repair_windows_draw_the_graph_and_every_control and declipper_transfer_holds_at_the_threshold; all four in the window bench; docs updated. --- CHANGELOG.md | 4 + README.md | 3 +- crates/dstudio-app/src/device_window.rs | 124 +++++++++++- crates/dstudio-app/src/device_window_wave.rs | 30 ++- crates/dstudio-app/src/panel_graph.rs | 199 ++++++++++++++++++- crates/dstudio-app/ui/device_panel.slint | 15 +- docs/devices.md | 8 +- 7 files changed, 366 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f645cb6..850abbce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,3 +69,7 @@ Nothing has been released yet. The first release, 0.1.0, will cover what is on ` - An expanded window for Trance Gate: the step ring (step count, rate) and the pattern track on a panel down the left, the envelope with its draggable handles across the display, and a card with Attack, Decay, Sustain, Release, Swing and Mix. The ring and envelope are the card's, drawn and hit tested in the window's geometry. +- Expanded windows for the restoration devices: De-Clipper (its transfer held at the threshold on a 48 dB square + beside two cycles of a sine through it, with the Reduction lit against unity) and De-Esser, De-Hummer and De-Noiser + (the card's graph at full size with its handles, over a dB ladder and frequency axis, captioned and with a legend), + each with one card of every control. diff --git a/README.md b/README.md index 56af70d0..055e6b89 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,8 @@ EQ at full size with every control in a row below, Distortion, Tape Saturation a the transfer curve beside a sine through the device, Bit Crusher, whose window draws one crushed cycle, Utility, and Stereo Widener, whose window draws the stereo field over a live correlation lane, Tuner, and Spectrum, whose window shows the spectrum flat, as a 3D waterfall of its history, or split over a spectrogram, and Trance Gate, whose window draws its step ring and pattern track on a -panel beside the envelope; the other devices open their card in a window for now. +panel beside the envelope, De-Clipper, whose window draws its transfer beside a sine, and De-Esser, De-Hummer and +De-Noiser, whose window draws the card's graph at full size over a dB ladder; 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_window.rs b/crates/dstudio-app/src/device_window.rs index 002e82b8..7f269185 100644 --- a/crates/dstudio-app/src/device_window.rs +++ b/crates/dstudio-app/src/device_window.rs @@ -131,11 +131,17 @@ pub(crate) fn has_window(def: &DeviceDef) -> bool { "auto-filter" | "channeleq" | "character-eq" | "transient-shaper" | "multiband-compressor" | "delay" | "reverb" | "echo" ) || is_wave_window(def) || matches!(def.id, "utility" | "widener" | "tuner" | "spectrum" | "trance-gate") + || is_repair_window(def) || def.id == "bitcrusher" || is_field_window(def) || is_dynamics_window(def) } +/// The restoration graphs drawn at window size (src/panel_graph.rs). +fn is_repair_window(def: &DeviceDef) -> bool { + matches!(def.id, "deesser" | "dehummer" | "denoiser") +} + /// Windows of the level-history family (src/device_window_dynamics.rs). fn is_dynamics_window(def: &DeviceDef) -> bool { crate::device_window_dynamics::spec(def.id).is_some() @@ -143,7 +149,7 @@ fn is_dynamics_window(def: &DeviceDef) -> bool { /// Windows of the waveshaper family (src/device_window_wave.rs). fn is_wave_window(def: &DeviceDef) -> bool { - matches!(def.id, "distortion" | "tapesaturation" | "soft-clipper") + matches!(def.id, "distortion" | "tapesaturation" | "soft-clipper" | "declipper") } /// Windows of the plotted-field family (motion and response pictures). @@ -191,6 +197,11 @@ pub(crate) fn kit(def: &DeviceDef) -> Kit { "multiband-compressor" => field_kit(WIN_W, 336.0, 52.0, 43.0), // Waveshapers: the transfer square and the wave over a dB axis and legend. "distortion" | "tapesaturation" | "soft-clipper" => field_kit(WAVE_W, 454.0, 60.0, 44.0), + // De-Esser, De-Hummer, De-Noiser: the graph over its ladder, the axis and legend below + // (its plot is crate::panel_graph::WIN_PLOT). + "deesser" | "dehummer" | "denoiser" => field_kit(1200.0, 510.0, 46.0, 44.0), + // De-Clipper: the same picture on the wider face. + "declipper" => field_kit(1200.0, 510.0, 60.0, 44.0), // Utility: three cards and no display; the meters run the window's height. "utility" => Kit { w: 1200.0, display: (INSET, 52.0, 1042.0, 630.0), plot: (0.0, 0.0, 0.0, 0.0), narrow: true, meters_h: 0.0 }, // Stereo Widener: the field over the correlation lane. @@ -682,6 +693,7 @@ impl Controller { _ if def.id == "bitcrusher" => self.crush_window_canvas(d, def, &k, accent), _ if def.id == "widener" => self.widener_window_canvas(d, def, &k, accent), _ if def.id == "spectrum" => self.spectrum_window_canvas(d, def, &k, accent), + _ if is_repair_window(def) => self.graph_window(d, def, accent), // The ring panel and the envelope display share one canvas from the panel's corner. _ if def.id == "trance-gate" => self.trance_gate_window_canvas(d, def, accent, dx + dw - INSET, dh), // The card's tuner at twice its scale, its bar across the middle of the display. @@ -712,6 +724,7 @@ impl Controller { "tuner" => self.tuner_window(d, def, &mut b, dy + dh + 14.0), "spectrum" => self.spectrum_window(d, def, &mut b, dy + dh + 12.0), "trance-gate" => self.trance_gate_window(d, def, &mut b, dy + dh + 12.0), + _ if is_repair_window(def) => self.repair_window(d, def, &mut b, dy + dh + 12.0), _ => self.field_window(d, def, &mut b, dy + dh + 12.0), }; let (mut meters, mut ticks, mut ticks_x) = self.window_meters(d.id, &k); @@ -1637,6 +1650,11 @@ impl Controller { 14.0, ), ], + "declipper" => vec![ + (vec![knob("threshold", "Threshold", 2, 76.0), knob("ceiling", "Ceiling", 2, 76.0)], 8.0), + (vec![Item::Pills("oversampling", pills("oversampling"), "Oversampling", 130.0)], 8.0), + (vec![knob("mix", "Mix", 1, 62.0)], 8.0), + ], _ => vec![ (vec![knob("bitdepth", "Bit Depth", 2, 70.0)], 8.0), ( @@ -1812,6 +1830,51 @@ impl Controller { row.y + row.h + 16.0 } + /// De-Esser, De-Hummer and De-Noiser: one card with every control (the De-Esser's Listen + /// switch in a cluster of its own). + fn repair_window(&self, d: &Device, def: &'static DeviceDef, b: &mut Builder, y: f32) -> f32 { + let knob = |id, name, size, w| Item::Knob(id, name, size, w, false); + let row = Row::main(y); + let clusters = match def.id { + "deesser" => vec![ + ( + vec![ + knob("frequency", "Frequency", 2, 86.0), + knob("bandwidth", "Bandwidth", 2, 86.0), + knob("threshold", "Threshold", 1, 76.0), + knob("reduction", "Reduction", 1, 76.0), + knob("mix", "Mix", 1, 76.0), + ], + 0.0, + ), + (vec![Item::Pills("listen", vec![("Off", 0.0), ("On", 1.0)], "Listen", 96.0)], 0.0), + ], + "dehummer" => vec![( + vec![ + knob("frequency", "Frequency", 2, 86.0), + knob("num_harmonics", "Harmonics", 2, 86.0), + knob("notch_width", "Q", 1, 66.0), + knob("depth", "Depth", 1, 66.0), + knob("mix", "Mix", 1, 66.0), + ], + 0.0, + )], + _ => vec![( + vec![ + knob("threshold", "Threshold", 2, 86.0), + knob("reduction", "Reduction", 2, 86.0), + knob("frequency_smoothing", "Freq Smooth", 1, 92.0), + knob("attack", "Attack", 1, 92.0), + knob("release", "Release", 1, 92.0), + knob("mix", "Mix", 1, 92.0), + ], + 0.0, + )], + }; + self.win_card(d, def, b, row, clusters); + row.y + row.h + 16.0 + } + /// Trance Gate: the ring panel down the left; under the envelope, one card with the /// envelope's Attack, Decay, Sustain and Release, Swing, and Mix. fn trance_gate_window(&self, d: &Device, def: &'static DeviceDef, b: &mut Builder, y: f32) -> f32 { @@ -3425,6 +3488,61 @@ mod tests { } } + /// De-Esser, De-Hummer, De-Noiser: the graph at window size with its caption, ladder and + /// legend, one card with every control, and a drag in the window moves the De-Noiser's + /// threshold line where the window draws it. + #[test] + fn repair_windows_draw_the_graph_and_every_control() { + use slint::Model; + for (id, caption, legend) in [("deesser", "Band", "Removing"), ("dehummer", "Hum", "Notches"), ("denoiser", "Noise gate", "Gate")] { + let (c, did, def) = controller_with(id); + assert!(has_window(def), "{id}"); + let v = view(&c, did, def); + assert!((v.w / Z - 1200.0).abs() < 0.5 && (v.h / Z - 696.0).abs() < 0.5, "{id} {} x {}", v.w / Z, v.h / Z); + for p in def.params { + let i = def.index_of(p.id).unwrap() as i32; + assert!(v.knobs.iter().any(|k| k.param == i) || v.pills.iter().any(|q| q.param == i), "{id} {}", p.id); + } + for t in [caption, legend, "0 dB", "Hz"] { + assert!(v.display.texts.iter().any(|x| x.text == t), "{id} {t}"); + } + assert!(v.display.pointer && !v.display.well, "{id}"); + } + let (mut c, did, def) = controller_with("denoiser"); + let t0 = c.panel_value(c.project().device(did).unwrap(), def, def.param("threshold").unwrap()); + let (w, h) = crate::panel_graph::WIN_PLOT; + let y = (-t0 / 80.0) * h * Z; + c.panel_graph(did, 16, 0.5 * w * Z, y, false, false); + c.panel_graph(did, 17, 0.5 * w * Z, y - 40.0, false, false); + c.panel_graph(did, 18, 0.5 * w * Z, y - 40.0, false, false); + let t1 = c.panel_value(c.project().device(did).unwrap(), def, def.param("threshold").unwrap()); + assert!(t1 > t0 + 3.0, "{t0} -> {t1}"); + } + + /// De-Clipper: the transfer held at the threshold beside the wave, captioned with the + /// transfer at 0 dBFS, and one card with every control. + #[test] + fn declipper_window_shows_the_transfer_and_every_control() { + use slint::Model; + let (mut c, did, def) = controller_with("declipper"); + assert!(has_window(def)); + let v = view(&c, did, def); + assert!((v.w / Z - 1200.0).abs() < 0.5 && (v.h / Z - 696.0).abs() < 0.5, "{} x {}", v.w / Z, v.h / Z); + let idx = |p: &str| def.index_of(p).unwrap() as i32; + for k in ["threshold", "ceiling", "mix"] { + assert!(v.knobs.iter().any(|n| n.param == idx(k)), "{k}"); + } + assert_eq!(v.pills.iter().filter(|p| p.param == idx("oversampling")).count(), 3); + assert_eq!(v.meters.row_count(), 2); + for t in ["Wave", "Reduction"] { + assert!(v.display.texts.iter().any(|x| x.text == t), "{t}"); + } + c.execute(Command::SetDeviceParam { device: did, param: "threshold".into(), value: -6.0 }); + c.execute(Command::SetDeviceParam { device: did, param: "mix".into(), value: 0.0 }); + let v = view(&c, did, def); + assert!(v.display.texts.iter().any(|x| x.text.contains("6.0 dB")), "caption reads the threshold"); + } + /// Trance Gate: the ring panel and envelope share one interactive canvas, no meters, and /// a press on the window's ring toggles the step under it (window geometry, not the card's). #[test] @@ -3536,6 +3654,10 @@ mod tests { "tuner", "spectrum", "trance-gate", + "declipper", + "deesser", + "dehummer", + "denoiser", ] { let (mut c, did, def) = controller_with(id); let h: std::collections::VecDeque<_> = diff --git a/crates/dstudio-app/src/device_window_wave.rs b/crates/dstudio-app/src/device_window_wave.rs index fe42fb68..29d74919 100644 --- a/crates/dstudio-app/src/device_window_wave.rs +++ b/crates/dstudio-app/src/device_window_wave.rs @@ -44,6 +44,12 @@ pub(crate) fn law(def: &DeviceDef, v: &dyn Fn(&str) -> f32) -> Law { let (dr, cp, mx, out, mode) = (v("drive"), v("compression"), v("mix"), v("output_gain"), v("mode").round() as u32); Law { curve: Box::new(move |x| builtin::tape_transfer(x, dr, cp, mx, out, mode)), open: Box::new(|x| x), clipper: false } } + // The De-Clipper's picture: the repaired signal held at the threshold, then scaled + // under the ceiling (the card's model). + "declipper" => { + let (t, c, mx) = (v("threshold"), v("ceiling"), v("mix") / 100.0); + Law { curve: Box::new(move |x| crate::panel_graph::declipper_wave(x, t, c, mx).0), open: Box::new(|x| x), clipper: false } + } "soft-clipper" => { let (inp, ceil, soft, shape, gm, mx, out) = (v("input"), v("ceiling"), v("softness"), v("shape").round() as u32, v("gain_match") >= 0.5, v("mix"), v("output_gain")); @@ -185,7 +191,13 @@ impl Controller { let ly = side + 31.0 * Z; let (glyph, gap) = (14.0 * Z, 6.0 * Z); let mut x = 0.0; - let band_name = if l.clipper { "Clipping" } else { "Gain" }; + let band_name = if l.clipper { + "Clipping" + } else if def.id == "declipper" { + "Reduction" + } else { + "Gain" + }; for (kind, label) in [(0, "Transfer"), (1, "Unity"), (2, band_name)] { match kind { 0 => paths.push(stroke(format!("M{x:.1} {ly:.1} h{glyph:.1}"), white(0.9), 1.5 * Z)), @@ -330,6 +342,22 @@ mod tests { } } + /// The De-Clipper holds the transfer at its threshold above it and passes it below. + #[test] + fn declipper_transfer_holds_at_the_threshold() { + let def = builtin::find("declipper").unwrap(); + let v = |id: &str| match id { + "threshold" => -6.0, + "ceiling" => -0.3, + "mix" => 0.0, + _ => 0.0, + }; + let l = law(def, &v); + assert!((peak_db(&*l.curve, -12.0) + 12.0).abs() < 0.1); + assert!((peak_db(&*l.curve, 0.0) + 6.0).abs() < 0.1); + assert!((peak_db(&*l.curve, 12.0) + 6.0).abs() < 0.1); + } + /// The soft clipper holds a hot sine under its open path. #[test] fn clipper_holds_a_hot_sine_under_the_open_path() { diff --git a/crates/dstudio-app/src/panel_graph.rs b/crates/dstudio-app/src/panel_graph.rs index 64e9a5f7..218d5a12 100644 --- a/crates/dstudio-app/src/panel_graph.rs +++ b/crates/dstudio-app/src/panel_graph.rs @@ -139,6 +139,34 @@ pub struct GraphState { drag: Option, hover: Option<(DeviceId, Zone)>, spectra: HashMap, + /// The last pointer event came from a device window (its menu is hit tested there). + in_window: bool, +} + +/// Plot size (pt) of a restoration graph in its expanded window (src/device_window.rs). +pub(crate) const WIN_PLOT: (f32, f32) = (994.0, 441.0); + +thread_local! { + static IN_WINDOW: std::cell::Cell = const { std::cell::Cell::new(false) }; +} + +/// Draws and hit tests the graph at its window size until dropped. +pub(crate) struct WindowScope(bool); + +impl WindowScope { + pub(crate) fn new(on: bool) -> Self { + Self(IN_WINDOW.with(|c| c.replace(on))) + } +} + +impl Drop for WindowScope { + fn drop(&mut self) { + IN_WINDOW.with(|c| c.set(self.0)); + } +} + +fn in_window() -> bool { + IN_WINDOW.with(|c| c.get()) } /// Plot geometry in well pixels: x is a log frequency axis (or 0..1 for the @@ -181,7 +209,7 @@ fn placement(def: &DeviceDef) -> (f32, f32, f32, f32) { fn geo(kind: Kind, def: &DeviceDef) -> Geo { let (_, _, w, h) = placement(def); - let (w, h) = (w * Z, (h - CAPTION) * Z); + let (w, h) = if in_window() { (WIN_PLOT.0 * Z, WIN_PLOT.1 * Z) } else { (w * Z, (h - CAPTION) * Z) }; let full = |lo, hi, top, bottom| Geo { w, h, x0: 0.0, x1: w, y0: 0.0, y1: h, lo, hi, top, bottom }; match kind { // Wave plot inset 8 pt in the well, amplitude axis +-1.25. @@ -568,8 +596,57 @@ impl Controller { value = String::new(); } } + let win = in_window(); + if win { + // The window's ladder and axis: finer rungs and more frequencies, labelled outside. + let (step, ticks): (f32, &[(f32, &str)]) = match kind { + Kind::Deesser => { + (5.0, &[(2000.0, "2k"), (3000.0, "3k"), (5000.0, "5k"), (7000.0, "7k"), (10000.0, "10k"), (15000.0, "15k")]) + } + Kind::Dehummer => ( + 6.0, + &[ + (30.0, "30"), + (50.0, "50"), + (70.0, "70"), + (100.0, "100"), + (200.0, "200"), + (300.0, "300"), + (500.0, "500"), + (700.0, "700"), + (1000.0, "1k"), + (2000.0, "2k"), + ], + ), + _ => ( + 10.0, + &[ + (50.0, "50"), + (100.0, "100"), + (200.0, "200"), + (500.0, "500"), + (1000.0, "1k"), + (2000.0, "2k"), + (5000.0, "5k"), + (10000.0, "10k"), + (20000.0, "20k"), + ], + ), + }; + hrules.clear(); + vrules.clear(); + let mut db = g.top; + while db >= g.bottom - 0.01 { + let t = if db == 0.0 { "0 dB".to_string() } else { axis_db(db) }; + hrules.push(Rule { pos: g.y_of(db).min(g.h - 1.0), text: s(t), strong: db == 0.0 }); + db -= step; + } + for &(hz, t) in ticks { + vrules.push(Rule { pos: g.x_of(hz).min(g.w - 1.0), text: s(t), strong: false }); + } + } // Draw order: rules, spectrum, layers, axis labels, dots, grip pills. - let (ww, wh) = (w * Z, (h - CAPTION) * Z); + let (ww, wh) = if win { (g.w, g.h) } else { (w * Z, (h - CAPTION) * Z) }; let rule = |commands: String, a: f32| PanelPath { commands: s(commands), stroke: ink(a), width: 1.0, fill: none(), fill2: none() }; let mut paths: Vec = Vec::new(); paths.extend( @@ -596,9 +673,14 @@ impl Controller { weight: 500, align, }; - let mut texts: Vec = - hrules.iter().filter(|r| !r.text.is_empty()).map(|r| label_text(3.0 * Z, r.pos + 1.0, 40.0 * Z, &r.text, 0)).collect(); - texts.extend(vrules.iter().map(|r| label_text(r.pos - 20.0 * Z, wh - 13.0 * Z, 40.0 * Z, &r.text, 1))); + let mut texts: Vec = if win { + Vec::new() + } else { + hrules.iter().filter(|r| !r.text.is_empty()).map(|r| label_text(3.0 * Z, r.pos + 1.0, 40.0 * Z, &r.text, 0)).collect() + }; + if !win { + texts.extend(vrules.iter().map(|r| label_text(r.pos - 20.0 * Z, wh - 13.0 * Z, 40.0 * Z, &r.text, 1))); + } let mut grips = Vec::new(); let mut next_x = 0.0; for p in &pills { @@ -606,6 +688,9 @@ impl Controller { next_x = x + pill_width(p) + 8.0 * Z; grips.push(PanelGrip { x, y: p.y, label: s(p.label), value: s(p.value.as_str()), hot: p.hot, ..Default::default() }); } + if win { + return self.graph_window_canvas(kind, d, def, accent, (ww, wh), &hrules, &vrules, (caption, value), paths, grips, cursor); + } PanelCanvas { visible: true, well: true, @@ -628,6 +713,104 @@ impl Controller { } } + /// The graph at window size: the ladder left of the plot, the axis under it, the caption + /// above and a legend under the axis, as on the other expanded windows. + #[allow(clippy::too_many_arguments)] + fn graph_window_canvas( + &self, + kind: Kind, + d: &Device, + def: &'static DeviceDef, + accent: Color, + (w, h): (f32, f32), + hrules: &[Rule], + vrules: &[Rule], + (caption, value): (&'static str, String), + mut paths: Vec, + grips: Vec, + cursor: i32, + ) -> PanelCanvas { + let v = |id: &str| def.param(id).map_or(0.0, |p| self.panel_value(d, def, p)); + let dim = Color::from_argb_u8(0x52, 255, 255, 255); + let text = |x: f32, y: f32, w: f32, t: SharedString, color: Color, size: f32, align: i32| PanelText { + x: match align { + 1 => x - w / 2.0, + 2 => x - w, + _ => x, + }, + y: y - 8.0 * Z, + w, + h: 16.0 * Z, + text: t, + color, + size: size * Z, + weight: 500, + align, + }; + let mut texts: Vec = Vec::new(); + for r in hrules { + texts.push(text(-8.0 * Z, r.pos, 44.0 * Z, r.text.clone(), dim, 10.0, 2)); + } + let axis_y = h + 10.0 * Z; + texts.push(text(6.0 * Z, axis_y, 30.0 * Z, s("Hz"), dim, 10.0, 0)); + for r in vrules { + let right = r.pos > w - 12.0 * Z; + texts.push(text(r.pos, axis_y, 40.0 * Z, r.text.clone(), dim, 10.0, if right { 2 } else { 1 })); + } + // Caption above the plot. + let cy = -13.0 * Z; + let value = if kind == Kind::Denoiser { db_text(v("threshold")) } else { value }; + texts.push(text(0.0, cy, 120.0 * Z, s(caption), Color::from_argb_u8(0x8c, 255, 255, 255), 12.0, 0)); + let at = (crate::text_measure::value_width(caption) + 12.0) * Z; + texts.push(text(at, cy, 160.0 * Z, s(value), Color::from_argb_u8(0xeb, 255, 255, 255), 13.0, 0)); + // Legend under the axis: the response line, the band it takes out, the signal. + let spectrum = self.devices.panel.graph.spectra.get(&d.id); + let level = spectrum.and_then(|sp| sp.shown.iter().copied().reduce(f32::max)).filter(|db| *db > -120.0); + let signal = match level { + Some(db) if kind != Kind::Denoiser => format!("Signal {} dBFS", axis_db(db.round())), + _ => "Signal".to_string(), + }; + let items: Vec<(u8, String)> = match kind { + Kind::Deesser => vec![(0, "Reach".into()), (1, "Removing".into()), (2, signal)], + Kind::Dehummer => vec![(0, "Notches".into()), (2, signal)], + _ => vec![(1, "Gate".into()), (2, signal)], + }; + let ly = h + 31.0 * Z; + let (glyph, gap) = (14.0 * Z, 6.0 * Z); + let mut x = 0.0; + for (k, label) in items { + let commands = match k { + 0 => format!("M{x:.1} {ly:.1} h{glyph:.1}"), + _ => format!("M{x:.1} {:.1} h{glyph:.1} v{:.1} h{:.1} Z", ly - 4.0 * Z, 8.0 * Z, -glyph), + }; + paths.push(match k { + 0 => PanelPath { commands: s(commands), stroke: ink(0.9), width: 1.5 * Z, fill: none(), fill2: none() }, + 1 => layer(commands, none(), 0.0, alpha(accent, 0.34)), + _ => layer(commands, none(), 0.0, ink(0.3)), + }); + texts.push(text(x + glyph + gap, ly, 140.0 * Z, s(label.as_str()), Color::from_argb_u8(0xb3, 255, 255, 255), 9.0, 0)); + x += glyph + gap + crate::text_measure::value_width(&label) * 0.9 * Z + 16.0 * Z; + } + PanelCanvas { + visible: true, + w, + h, + paths: model(paths), + texts: model(texts), + grips: model(grips), + pointer: true, + cursor, + label: s(caption), + ..Default::default() + } + } + + /// The restoration graph drawn for its expanded window. + pub(crate) fn graph_window(&self, d: &Device, def: &'static DeviceDef, accent: Color) -> PanelCanvas { + let _w = WindowScope::new(true); + self.graph_canvas(d, def, accent) + } + pub(crate) fn panel_poll_graphs(&mut self) { let Some(t) = self.selected_track.and_then(|t| self.project().track(t)) else { return }; let ids: Vec<(DeviceId, bool, bool)> = t @@ -737,6 +920,7 @@ impl Controller { /// Right press on a canvas well: the parameter menu (modulate, map to a macro) of the /// handle under the pointer, as a right press on its knob opens. pub fn panel_graph_menu(&mut self, device: DeviceId, x: f32, y: f32, wx: f32, wy: f32) { + let _w = WindowScope::new(self.devices.panel.graph.in_window); let param = match self.graph_def(device) { Some((d, def, kind)) => self.graph_hit(d, def, kind, x, y).and_then(|z| z.params(kind).iter().find_map(|id| def.index_of(id))), None => self.field_param_at(device, x, y), @@ -747,6 +931,11 @@ impl Controller { } pub fn panel_graph(&mut self, device: DeviceId, phase: i32, x: f32, y: f32, fine: bool, alt: bool) { + // Phase + 16: the event comes from the device's expanded window. + let win = phase >= 16; + let phase = phase % 16; + self.devices.panel.graph.in_window = win; + let _w = WindowScope::new(win); let Some((d, def, kind)) = self.graph_def(device) else { if matches!(phase, 2 | 3) && self.devices.panel.graph.drag.take().is_some() { self.ui_dirty = true; diff --git a/crates/dstudio-app/ui/device_panel.slint b/crates/dstudio-app/ui/device_panel.slint index d61e56c6..bb7dc446 100644 --- a/crates/dstudio-app/ui/device_panel.slint +++ b/crates/dstudio-app/ui/device_panel.slint @@ -437,7 +437,8 @@ export component DeviceCanvas inherits Rectangle { in property accent; // In a device window: Rust maps the well with the window's geometry (src/device_window.rs). in property window; - // Editor events from a device window carry kind + 16 (src/device_editors.rs). + // Editor and graph events from a device window carry kind + 16 (src/device_editors.rs, + // src/panel_graph.rs). property ekind: root.window ? 16 : 0; property zm: PanelStyle.z; property mouse-cursor: root.f.cursor == 1 ? MouseCursor.move : root.f.cursor == 2 ? MouseCursor.ew-resize : root.f.cursor == 3 ? MouseCursor.ns-resize @@ -506,14 +507,14 @@ export component DeviceCanvas inherits Rectangle { mouse-cursor: root.mouse-cursor; pointer-event(e) => { Studio.canvas-surface(root.window); - if (e.button == PointerEventButton.left && e.kind == PointerEventKind.down) { keys.focus(); Studio.panel-graph(root.device, 0, self.mouse-x / 1px, self.mouse-y / 1px, e.modifiers.shift, e.modifiers.alt); } + if (e.button == PointerEventButton.left && e.kind == PointerEventKind.down) { keys.focus(); Studio.panel-graph(root.device, root.ekind + 0, self.mouse-x / 1px, self.mouse-y / 1px, e.modifiers.shift, e.modifiers.alt); } if (e.button == PointerEventButton.right && e.kind == PointerEventKind.down) { Studio.panel-graph-menu(root.device, self.mouse-x / 1px, self.mouse-y / 1px, self.absolute-position.x + self.mouse-x, (self.absolute-position.y - Studio.menu-dy) + self.mouse-y); } - if (e.kind == PointerEventKind.move) { Studio.panel-graph(root.device, self.pressed ? 1 : 4, self.mouse-x / 1px, self.mouse-y / 1px, e.modifiers.shift, e.modifiers.alt); } - if (e.button == PointerEventButton.left && e.kind == PointerEventKind.up) { Studio.panel-graph(root.device, 2, self.mouse-x / 1px, self.mouse-y / 1px, false, false); } - if (e.kind == PointerEventKind.cancel) { Studio.panel-graph(root.device, 3, 0, 0, false, false); } + if (e.kind == PointerEventKind.move) { Studio.panel-graph(root.device, root.ekind + (self.pressed ? 1 : 4), self.mouse-x / 1px, self.mouse-y / 1px, e.modifiers.shift, e.modifiers.alt); } + if (e.button == PointerEventButton.left && e.kind == PointerEventKind.up) { Studio.panel-graph(root.device, root.ekind + 2, self.mouse-x / 1px, self.mouse-y / 1px, false, false); } + if (e.kind == PointerEventKind.cancel) { Studio.panel-graph(root.device, root.ekind + 3, 0, 0, false, false); } } - changed has-hover => { if (!self.has-hover && !self.pressed) { Studio.canvas-surface(root.window); Studio.panel-graph(root.device, 5, 0, 0, false, false); } } - double-clicked => { Studio.canvas-surface(root.window); Studio.panel-graph(root.device, 6, self.mouse-x / 1px, self.mouse-y / 1px, false, false); } + changed has-hover => { if (!self.has-hover && !self.pressed) { Studio.canvas-surface(root.window); Studio.panel-graph(root.device, root.ekind + 5, 0, 0, false, false); } } + double-clicked => { Studio.canvas-surface(root.window); Studio.panel-graph(root.device, root.ekind + 6, self.mouse-x / 1px, self.mouse-y / 1px, false, false); } scroll-event(e) => { Studio.canvas-surface(root.window); if (Studio.panel-graph-wheel(root.device, self.mouse-x / 1px, self.mouse-y / 1px, e.delta-y / 1px)) { return accept; } diff --git a/docs/devices.md b/docs/devices.md index 27db2b5f..8f02623d 100644 --- a/docs/devices.md +++ b/docs/devices.md @@ -67,7 +67,7 @@ flowchart LR Flanger, Phaser, Ring Mod and Character Mod; and the dynamics family: Compressor, Limiter, Gate, Glue Compressor, Character Compressor and Mastering Limiter; Transient Shaper; Multiband Compressor; Delay, Echo and Reverb; Distortion, Tape Saturation, - Soft Clipper and Bit Crusher; Utility, Stereo Widener, Tuner and Spectrum; Trance Gate), otherwise the card itself in a window. A + Soft Clipper and Bit Crusher; Utility, Stereo Widener, Tuner and Spectrum; Trance Gate; De-Clipper, De-Esser, De-Hummer and De-Noiser), 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 @@ -136,7 +136,11 @@ flowchart LR window reuses the card's editor (src/device_editors.rs): `tg_draw` and `tg_hit` read their geometry from `TgScope` (`TG_CARD` or `TG_WIN`), and the window's canvas sends its editor events with kind + 16 so they are hit - tested in the window's geometry. The + tested in the window's geometry. The De-Clipper joins the waveshapers + (its law is the card's `declipper_wave`); De-Esser, De-Hummer and + De-Noiser draw `graph_canvas` under a `WindowScope` (plot + `panel_graph::WIN_PLOT`), and their pointer events carry phase + 16 so + drags are hit tested at that size. 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