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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,6 @@ Nothing has been released yet. The first release, 0.1.0, will cover what is on `
and the curve editor across the rest of it (points, bends and the lane's own pills edited in place), with the
lane's Rate and Depth, the trigger's Threshold, Mix and Output below. The editor is the card's, drawn and hit
tested in the window's geometry.
- An expanded window for LFO: two cycles of the wave across the window with phase quarters, the live position
dotted and the same Rate / Depth drag as the card, captioned with the shape and the cycle length, over Shape,
Timebase, Rate, Phase and Depth.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ panel beside the envelope, De-Clipper, whose window draws its transfer beside a
De-Noiser, whose window draws the card's graph at full size over a dB ladder, Pitch Shifter, whose window shows the
interval against an A4 reference with the formant strip, Grains, whose window draws the buffer with its pitch and time
axes over two cards of controls, Pitch Corrector, whose window draws the correction trace over labelled cent rules, and Shaper, whose window draws
its lane tabs and curve editor across the display; the other devices open their card in a window for now.
its lane tabs and curve editor across the display, and LFO, whose window draws two cycles of its wave across the
window; 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
72 changes: 72 additions & 0 deletions crates/dstudio-app/src/device_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,78 @@ impl Controller {
};
}

/// The LFO window's wave (w x h px): two cycles over phase quarters and a centre line,
/// the live position dotted on the first; drag sideways for Rate, up or down for Depth.
pub(crate) fn lfo_window_wave(&self, d: &Device, def: &'static DeviceDef, w: f32, h: f32, accent: slint::Color) -> PanelCanvas {
let idx = |id: &str| def.index_of(id).map_or(-1, |i| i as i32);
let val = |id: &str| def.param(id).map_or(0.0, |p| self.panel_value_of(d, def, p));
let sync = val("sync") >= 0.5;
let depth = val("depth");
let phase = val("phase") as f64 / 100.0;
let (wave, wave_fill) = wave_paths(val("shape").round() as usize, phase, depth / 100.0, w, h);
let (cyc, pos) = self.devices.modu.lfo.get(&d.id).map_or((phase as f32, 0.5), |r| (r.2, r.0));
let dot_x = ((cyc as f64 - phase).rem_euclid(1.0) as f32) * w / 2.0;
let dot_y = h / 2.0 - (h / 2.0 - 3.0) * (depth / 100.0).max(0.04) * (pos * 2.0 - 1.0);
let clear = slint::Color::from_argb_u8(0, 0, 0, 0);
let path = |commands: String, stroke: slint::Color, width: f32, fill: slint::Color| PanelPath {
commands: s(commands),
stroke,
width,
fill,
fill2: fill,
};
let mut grid = format!("M0 {:.1} L{w:.1} {:.1} ", h / 2.0, h / 2.0);
let mut quarters = String::new();
for q in 0..=8 {
let x = w * q as f32 / 8.0;
let line = format!("M{x:.1} 0 L{x:.1} {h:.1} ");
if q % 4 == 0 { grid.push_str(&line) } else { quarters.push_str(&line) }
}
let r = 4.5 * Z;
let label = |x: f32, text: &str, align: i32| PanelText {
x: x - if align == 1 { 30.0 * Z } else { 0.0 },
y: h + 4.0 * Z,
w: 60.0 * Z,
h: 14.0 * Z,
text: s(text),
color: slint::Color::from_argb_u8(0x73, 255, 255, 255),
size: 9.5 * Z,
weight: 600,
align,
};
let texts = vec![label(0.0, "0", 0), label(w / 2.0, "1 cycle", 1), label(w - 60.0 * Z, "2", 2)];
PanelCanvas {
visible: true,
well: false,
w,
h,
paths: model(vec![
path(quarters, slint::Color::from_argb_u8(0x0d, 255, 255, 255), 1.0, clear),
path(grid, slint::Color::from_argb_u8(0x1f, 255, 255, 255), 1.0, clear),
path(wave_fill, clear, 0.0, accent.with_alpha(0.18)),
path(wave, accent, 2.0 * Z, clear),
path(
format!("M{:.1} {dot_y:.1} m-{r} 0 a{r} {r} 0 1 0 {} 0 a{r} {r} 0 1 0 -{} 0", dot_x, 2.0 * r, 2.0 * r),
accent,
1.2,
slint::Color::from_rgb_u8(0xf2, 0xf2, 0xf2),
),
]),
texts: model(texts),
zones: model(vec![PanelZone {
x: 0.0,
y: 0.0,
w,
h,
param_x: idx(if sync { "rateSync" } else { "rate" }),
param_y: idx("depth"),
rate_x: 1.0 / 400.0,
rate_y: 1.0 / 400.0,
}]),
..Default::default()
}
}

fn chain_body(&self, d: &Device, def: &'static DeviceDef, card: &mut DeviceCard) {
let open = self.devices.modu.macro_open.get(&d.id).copied();
let knobs = def
Expand Down
94 changes: 92 additions & 2 deletions crates/dstudio-app/src/device_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,16 @@ pub(crate) fn has_window(def: &DeviceDef) -> bool {
) || is_wave_window(def)
|| matches!(
def.id,
"utility" | "widener" | "tuner" | "spectrum" | "trance-gate" | "pitch-shifter" | "grains" | "pitch-corrector" | "shaper"
"utility"
| "widener"
| "tuner"
| "spectrum"
| "trance-gate"
| "pitch-shifter"
| "grains"
| "pitch-corrector"
| "shaper"
| "lfo"
)
|| is_repair_window(def)
|| def.id == "bitcrusher"
Expand Down Expand Up @@ -216,6 +225,14 @@ pub(crate) fn kit(def: &DeviceDef) -> Kit {
"pitch-shifter" => field_kit(1200.0, 514.0, 12.0, 8.0),
// Shaper: the lane tabs above the display (its canvas starts at the tabs, y 52).
"shaper" => Kit { w: 1200.0, display: (INSET, 100.0, 1048.0, 466.0), plot: (0.0, 0.0, 0.0, 0.0), narrow: true, meters_h: 0.0 },
// LFO: two cycles of the wave across the whole width (it has no meters).
"lfo" => Kit {
w: 960.0,
display: (INSET, 52.0, 960.0 - 2.0 * INSET, 360.0),
plot: (12.0, 25.0, 12.0, 25.0),
narrow: true,
meters_h: 0.0,
},
// Pitch Corrector: the trace fills the display.
"pitch-corrector" => field_kit(1200.0, 514.0, 12.0, 8.0).with_plot_top(8.0),
// Grains: the buffer over its time axis, the pitch axis down its right edge.
Expand Down Expand Up @@ -754,6 +771,7 @@ impl Controller {
"pitch-shifter" => self.pitch_shifter_window(d, def, &mut b, dy + dh + 12.0),
"pitch-corrector" => self.pitch_corrector_window(d, def, &mut b, dy + dh + 12.0),
"shaper" => self.shaper_lanes_window(d, def, &mut b, dy + dh + 12.0),
"lfo" => self.lfo_window(d, def, &mut b, &k, dy + dh + 12.0),
"grains" => self.grains_window(d, def, &mut b, dy + dh + 12.0),
_ if is_wave_window(def) || def.id == "bitcrusher" => self.wave_window(d, def, &mut b, dy + dh + 12.0),
"utility" => self.utility_window(d, def, &mut b),
Expand All @@ -765,7 +783,7 @@ impl Controller {
_ => 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);
if def.id == "trance-gate" {
if def.id == "trance-gate" || def.id == "lfo" {
meters.clear();
ticks.clear();
}
Expand Down Expand Up @@ -2345,6 +2363,53 @@ impl Controller {
row.y + row.h + 16.0
}

/// LFO: the wave (two cycles, the live position dotted; drag sideways for Rate, up or
/// down for Depth) across the display, captioned with the shape and the cycle length,
/// over Shape, Timebase, Rate, Phase and Depth.
fn lfo_window(&self, d: &Device, def: &'static DeviceDef, b: &mut Builder, k: &Kit, y: f32) -> f32 {
use slint::Model;
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 fmt = |id: &str| def.param(id).map_or_else(String::new, |p| p.format(val(id)));
let sync = val("sync") >= 0.5;
let rate = if sync { "rateSync" } else { "rate" };
let (dx, dy, dw, dh) = k.display;
let (l, t, r, bt) = k.plot;
let mut wave = self.lfo_window_wave(d, def, (dw - l - r) * Z, (dh - t - bt) * Z, accent_of(b));
wave.x = (dx + l) * Z;
wave.y = (dy + t) * Z;
let cy = -(t - 12.0) * Z;
let cycle = if sync { format!("{} per cycle", fmt("rateSync")) } else { fmt("rate") };
let mut texts: Vec<PanelText> = wave.texts.iter().collect();
texts.push(crate::device_canvas::text(0.0, cy, 60.0 * Z, "Shape", Color::from_argb_u8(0x8c, 0xe5, 0xe5, 0xe8), 12.0 * Z, 0));
let shape = fmt("shape");
let at = (crate::text_measure::value_width("Shape") + 12.0) * Z;
texts.push(crate::device_canvas::text(at, cy, 200.0 * Z, shape.clone(), TEXT, 13.0 * Z, 0));
let at = at + (crate::text_measure::value_width(&shape) + 16.0) * Z;
texts.push(crate::device_canvas::text(at, cy, 200.0 * Z, cycle, Color::from_argb_u8(0xb3, 0xe5, 0xe5, 0xe8), 11.0 * Z, 0));
wave.texts = model(texts);
b.square = wave;
let row = Row::main(y);
self.win_card(
d,
def,
b,
row,
vec![
(
vec![
Item::Picker(idx("shape"), fmt("shape"), "Shape", 118.0, false),
Item::Pills("sync", vec![("Free", 0.0), ("Sync", 1.0)], "Timebase", 108.0),
],
14.0,
),
(vec![Item::Knob(rate, "Rate", 2, 72.0, false), Item::Knob("phase", "Phase", 2, 72.0, false)], 14.0),
(vec![Item::Knob("depth", "Depth", 2, 72.0, false)], 14.0),
],
);
row.y + row.h + 16.0
}

/// Pitch Corrector: Follow, Key and Scale (the Key picker inert while the project's key is
/// followed), then Speed, Retune Speed and Humanize, then Mix.
fn pitch_corrector_window(&self, d: &Device, def: &'static DeviceDef, b: &mut Builder, y: f32) -> f32 {
Expand Down Expand Up @@ -3917,6 +3982,30 @@ mod tests {
assert!(v.pills.iter().any(|p| p.label == "1/4" || p.kind == PILL_PICKER), "the lane's Rate picker");
}

/// LFO: the wave across the display (a Rate / Depth drag zone), captioned with the shape
/// and the cycle; Timebase swaps the Rate knob.
#[test]
fn lfo_window_draws_the_wave_and_every_control() {
use slint::Model;
let (mut c, did, def) = controller_with("lfo");
assert!(has_window(def));
let v = view(&c, did, def);
assert!((v.w / Z - 960.0).abs() < 0.5, "{}", v.w / Z);
assert_eq!(v.meters.row_count(), 0);
assert!(v.square.visible && v.square.paths.row_count() == 5);
let zones: Vec<_> = v.square.zones.iter().collect();
assert_eq!((zones[0].param_x, zones[0].param_y), (def.index_of("rateSync").unwrap() as i32, def.index_of("depth").unwrap() as i32));
let texts: Vec<String> = v.square.texts.iter().map(|t| t.text.to_string()).collect();
for t in ["Shape", "Sine", "1/4 per cycle", "1 cycle"] {
assert!(texts.iter().any(|x| x == t), "missing {t}: {texts:?}");
}
assert_eq!(knob_names(&v), ["Rate", "Phase", "Depth"]);
c.execute(Command::SetDeviceParam { device: did, param: "sync".into(), value: 0.0 });
let v = view(&c, did, def);
let rate = v.knobs.iter().find(|k| k.label == "Rate").unwrap();
assert_eq!(rate.param, def.index_of("rate").unwrap() as i32);
}

/// Spectrum: three views from one history; Reset clears it, Hold view stops taking
/// frames, the History picker is inert in 2D.
#[test]
Expand Down Expand Up @@ -4003,6 +4092,7 @@ mod tests {
"grains",
"pitch-corrector",
"shaper",
"lfo",
] {
let (mut c, did, def) = controller_with(id);
let h: std::collections::VecDeque<_> =
Expand Down
2 changes: 1 addition & 1 deletion docs/devices.md
Original file line number Diff line number Diff line change
Expand Up @@ -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; De-Clipper, De-Esser, De-Hummer and De-Noiser; Pitch Shifter, Grains and Pitch Corrector; Shaper), 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; Pitch Shifter, Grains and Pitch Corrector; Shaper; LFO), 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
Expand Down
Loading