Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
124 changes: 123 additions & 1 deletion crates/dstudio-app/src/device_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,25 @@ 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()
}

/// 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).
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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),
(
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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<_> =
Expand Down
30 changes: 29 additions & 1 deletion crates/dstudio-app/src/device_window_wave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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)),
Expand Down Expand Up @@ -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() {
Expand Down
Loading
Loading