From 3d47b42b80e83b91942d0ce94f91391076bbc9f1 Mon Sep 17 00:00:00 2001 From: Chris Laupama <42254688+chrislaupama@users.noreply.github.com> Date: Mon, 16 Nov 2026 03:13:25 +0000 Subject: [PATCH] Add the expanded Shaper window The window draws the card's editor in its own geometry (ShGeo: SH_CARD or SH_WIN, set by ShScope while drawing and hit testing): the lane tabs over the display, the Shape, Band and Trigger strip on its caption row, and the curve across the rest of the display, with the lane's Rate and Depth, the trigger's Threshold (inert while synced), Mix and Output in the card below. Window events carry kind + 16 so points, bends and tabs are hit tested at window size. Test shaper_window_draws_the_editor_and_picks_lanes_in_its_geometry; Shaper in the window bench; docs updated. --- CHANGELOG.md | 4 + README.md | 3 +- crates/dstudio-app/src/device_editors.rs | 209 +++++++++++++++++------ crates/dstudio-app/src/device_window.rs | 93 +++++++++- docs/devices.md | 5 +- 5 files changed, 256 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd3ab1d..da1bd44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -78,3 +78,7 @@ Nothing has been released yet. The first release, 0.1.0, will cover what is on ` a pitch axis and a time axis, Cloud / Rhythm and Freeze in the header, and two cards of controls that follow the mode) and Pitch Corrector (the correction trace over cent rules labelled from +100 to −100, with Follow, Key, Scale, Speed, Retune Speed, Humanize and Mix below). +- An expanded window for Shaper: the lane tabs over the display, the Shape, Band and Trigger strip on its caption row + 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. diff --git a/README.md b/README.md index 4165fdc..252d72e 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,8 @@ history, or split over a spectrogram, and Trance Gate, whose window draws its st 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, 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, and Pitch Corrector, whose window draws the correction trace over labelled cent rules; the other devices open their card in a window for now. +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. [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_editors.rs b/crates/dstudio-app/src/device_editors.rs index 4afc989..19b45ed 100644 --- a/crates/dstudio-app/src/device_editors.rs +++ b/crates/dstudio-app/src/device_editors.rs @@ -532,26 +532,95 @@ fn sector(r0: f32, r1: f32, a0: f32, a1: f32) -> PathData { // Shaper geometry (pt at 100%, card relative). const SH_W: f32 = 501.0; -const SH_TABS_Y: f32 = 50.0; -const SH_TAB_X: [f32; 7] = [16.0, 95.5, 161.0, 232.5, 291.5, 357.0, 428.0]; -const SH_STRIP_Y: f32 = 71.5; // pill top, 19 tall -const SH_WELL: (f32, f32, f32, f32) = (8.0, 93.0, 485.0, 120.5); -const SH_PLOT: (f32, f32, f32, f32) = (48.0, 108.0, 483.0, 205.0); // x0, y top (1), x1, y bottom (0) -const SH_TRIGGER: (f32, f32, f32, f32) = (171.0, 245.0, 141.0, 19.0); const SH_TRIGGER_SPLIT: f32 = 84.5; // divider from the pill's left const SH_KNOBS: [f32; 4] = [39.0, 111.0, 371.5, 461.5]; +/// Where the Shaper's editor draws: the card's, or its window's (relative to the top left of +/// the window's canvas, which starts at the lane tabs above the display). +#[derive(Debug, Clone, Copy)] +pub(crate) struct ShGeo { + tabs_y: f32, + tab_x: [f32; 7], + /// Strip row: pill top, 19 tall. + strip_y: f32, + /// Curve well and its plot: x0, y top (1), x1, y bottom (0). + well: (f32, f32, f32, f32), + plot: (f32, f32, f32, f32), + /// Trigger pill; its caption under it (the card) or to its left (the window). + trigger: (f32, f32, f32, f32), + trigger_caption_under: bool, +} + +const SH_CARD: ShGeo = ShGeo { + tabs_y: 50.0, + tab_x: [16.0, 95.5, 161.0, 232.5, 291.5, 357.0, 428.0], + strip_y: 71.5, + well: (8.0, 93.0, 485.0, 120.5), + plot: (48.0, 108.0, 483.0, 205.0), + trigger: (171.0, 245.0, 141.0, 19.0), + trigger_caption_under: true, +}; + +/// The window: the tabs over the display, the strip and Trigger on the display's caption row, +/// the curve across the rest of the display. +pub(crate) const SH_WIN: ShGeo = ShGeo { + tabs_y: 20.0, + tab_x: [8.0, 96.0, 169.0, 248.0, 315.0, 388.0, 467.0], + strip_y: 58.0, + well: (0.0, 48.0, 1048.0, 466.0), + plot: (60.0, 92.0, 1032.0, 500.0), + trigger: (891.0, 58.0, 141.0, 19.0), + trigger_caption_under: false, +}; + +#[cfg(test)] +impl ShGeo { + /// A point on lane `l`'s name in the tab row. + pub(crate) fn tab_name(&self, l: usize) -> (f32, f32) { + (self.tab_x[l] + 20.0, self.tabs_y) + } +} + +thread_local! { + static SH_GEO: std::cell::Cell = const { std::cell::Cell::new(SH_CARD) }; +} + +fn sh_geo() -> ShGeo { + SH_GEO.with(|g| g.get()) +} + +/// Draws and hit tests the Shaper with `g` (and the window's origin) until dropped. +pub(crate) struct ShScope(ShGeo, Option); + +impl ShScope { + pub(crate) fn new(g: ShGeo) -> Self { + let origin = TgScope::new(TgGeo { origin_y: 0.0, ..tg_geo() }); + Self(SH_GEO.with(|c| c.replace(g)), Some(origin)) + } +} + +impl Drop for ShScope { + fn drop(&mut self) { + SH_GEO.with(|c| c.set(self.0)); + self.1.take(); + } +} + fn sh_px(x: f32) -> f32 { - SH_PLOT.0 + x * (SH_PLOT.2 - SH_PLOT.0) + let p = sh_geo().plot; + p.0 + x * (p.2 - p.0) } fn sh_py(y: f32) -> f32 { - SH_PLOT.3 - y * (SH_PLOT.3 - SH_PLOT.1) + let p = sh_geo().plot; + p.3 - y * (p.3 - p.1) } fn sh_x_of(px: f32) -> f32 { - ((px - SH_PLOT.0) / (SH_PLOT.2 - SH_PLOT.0)).clamp(0.0, 1.0) + let p = sh_geo().plot; + ((px - p.0) / (p.2 - p.0)).clamp(0.0, 1.0) } fn sh_y_of(py: f32) -> f32 { - ((SH_PLOT.3 - py) / (SH_PLOT.3 - SH_PLOT.1)).clamp(0.0, 1.0) + let p = sh_geo().plot; + ((p.3 - py) / (p.3 - p.1)).clamp(0.0, 1.0) } /// The Crush lane's strip controls from the row start x (pt at 100%): @@ -951,25 +1020,56 @@ impl Controller { sh::TIME_MAX_SECONDS * self.project().transport.bpm / 60.0 } - fn shaper_lane(&self, id: DeviceId) -> usize { + pub(crate) fn shaper_lane(&self, id: DeviceId) -> usize { self.devices.panel.editors.lane.get(&id).copied().unwrap_or(0).min(sh::LANE_COUNT - 1) } fn shaper_card(&self, d: &Device, def: &'static DeviceDef, card: &mut DeviceCard) { - let accent = card.accent; + let mut c = Canvas::default(); + let cursor = self.sh_draw(d, def, card.accent, &mut c); + // Knobs: the lane's Rate and Depth, then Mix and Output. + let values = self.values(d, def); + let base = sh::lane_base(self.shaper_lane(d.id)); + let idx = [base + sh::RATE, base + sh::DEPTH, 2, 3]; + let knobs: Vec = idx.iter().zip(SH_KNOBS).map(|(&i, x)| knob(def, values[i], i, x)).collect(); + card.knobs = ModelRc::from(Rc::new(VecModel::from(knobs))); + card.canvas = c.into_canvas(SH_W, cursor); + } + + /// The Shaper's expanded window picture (src/device_window.rs places it): the lane tabs + /// over the display, the strip and Trigger on its caption row, the curve below. `w` x `h` pt. + pub(crate) fn shaper_editor_window_canvas(&self, d: &Device, def: &'static DeviceDef, accent: Color, w: f32, h: f32) -> PanelCanvas { + let _g = ShScope::new(SH_WIN); + let mut c = Canvas::default(); + let cursor = self.sh_draw(d, def, accent, &mut c); + PanelCanvas { + visible: true, + w: w * Z, + h: h * Z, + paths: ModelRc::from(Rc::new(VecModel::from(c.paths))), + texts: ModelRc::from(Rc::new(VecModel::from(c.texts))), + interactive: true, + cursor, + ..Default::default() + } + } + + /// The lane tabs, strip, curve and Trigger in the current geometry ([`ShScope`]); returns + /// the cursor. + fn sh_draw(&self, d: &Device, def: &'static DeviceDef, accent: Color, c: &mut Canvas) -> i32 { + let g = sh_geo(); let (hit, hp) = self.hover_of(d.id); let lane = self.shaper_lane(d.id); let values = self.values(d, def); let base = sh::lane_base(lane); let lane_on = values[base + sh::ON] >= 0.5; let depth = values[base + sh::DEPTH] / 100.0; - let mut c = Canvas::default(); let rest_col = ink(0.45); // Lane tabs: ring switch + name. for (l, (_, name)) in sh::LANES.iter().enumerate() { let on = values[sh::lane_base(l) + sh::ON] >= 0.5; - let x = SH_TAB_X[l]; + let x = g.tab_x[l]; let sel = l == lane; let hot = matches!(hit, Hit::LaneOn(h) | Hit::Lane(h) if h == l); let ring_col = if on { @@ -979,9 +1079,9 @@ impl Controller { } else { rest_col }; - c.stroke(PathData::default().circle(x, SH_TABS_Y, 6.25 * 0.75), ring_col, 1.5); + c.stroke(PathData::default().circle(x, g.tabs_y, 6.25 * 0.75), ring_col, 1.5); if on { - c.fill(PathData::default().circle(x, SH_TABS_Y, 3.0 * 0.75), accent); + c.fill(PathData::default().circle(x, g.tabs_y, 3.0 * 0.75), accent); } let col = if sel { ink(1.0) @@ -990,14 +1090,14 @@ impl Controller { } else { rest_col }; - c.text(x + 14.5, SH_TABS_Y - 10.0, 70.0, 20.0, *name, col, 12.5, 600, 0); + c.text(x + 14.5, g.tabs_y - 10.0, 70.0, 20.0, *name, col, 12.5, 600, 0); } // Strip row: Shape, Band (+ Split), the lane's own controls. let dim = if lane_on { 1.0 } else { 0.55 }; let pts = sh::lane_points(&values, lane); let shape_name = sh::matching_shape(lane, &pts).unwrap_or("Custom"); - let y = SH_STRIP_Y; + let y = g.strip_y; c.text(8.0, y, 40.0, 19.0, "Shape", ink(0.4 * dim), 11.5, 500, 0); c.pill(48.5, y, 97.0, 19.0, hit == Hit::Shape); c.text(56.5, y, 70.0, 19.0, shape_name, ink(0.95 * dim), 11.5, 600, 0); @@ -1055,15 +1155,15 @@ impl Controller { } // Curve well. - c.fill(PathData::default().rrect(SH_WELL.0, SH_WELL.1, SH_WELL.2, SH_WELL.3, 6.0), rgba(0, 0, 0, 0.26)); + c.fill(PathData::default().rrect(g.well.0, g.well.1, g.well.2, g.well.3, 6.0), rgba(0, 0, 0, 0.26)); let grid = *self.devices.panel.editors.grid.get(&d.id).unwrap_or(&16); let (mut strong, mut weak) = (PathData::default(), PathData::default()); for k in 0..=grid { let gx = sh_px(k as f32 / grid as f32); if k % (grid / 4).max(1) == 0 { - strong = strong.m(gx, SH_PLOT.1).l(gx, SH_PLOT.3); + strong = strong.m(gx, g.plot.1).l(gx, g.plot.3); } else { - weak = weak.m(gx, SH_PLOT.1).l(gx, SH_PLOT.3); + weak = weak.m(gx, g.plot.1).l(gx, g.plot.3); } } c.stroke(weak, ink(0.05), 1.0); @@ -1082,7 +1182,7 @@ impl Controller { _ => vec![], }; if lane == 6 && depth > 0.0 { - let spacing = (SH_PLOT.3 - SH_PLOT.1) / (24.0 * depth); + let spacing = (g.plot.3 - g.plot.1) / (24.0 * depth); if spacing >= 5.0 { let (mut semis, mut fifths) = (PathData::default(), PathData::default()); for s in -12i32..=12 { @@ -1092,9 +1192,9 @@ impl Controller { } let py = sh_py(yy); if s.abs() == 7 { - fifths = fifths.m(SH_PLOT.0, py).l(SH_PLOT.2, py); + fifths = fifths.m(g.plot.0, py).l(g.plot.2, py); } else { - semis = semis.m(SH_PLOT.0, py).l(SH_PLOT.2, py); + semis = semis.m(g.plot.0, py).l(g.plot.2, py); } } c.stroke(semis, ink(0.05), 1.0); @@ -1104,15 +1204,15 @@ impl Controller { let rest = sh::REST[lane]; for (ry, text) in &rulers { let py = sh_py(*ry); - c.text(SH_PLOT.0 - 46.0, py - 7.0, 38.0, 14.0, text.as_str(), ink(0.5), 10.0, 600, 2); + c.text(g.plot.0 - 46.0, py - 7.0, 38.0, 14.0, text.as_str(), ink(0.5), 10.0, 600, 2); if (*ry - rest).abs() > 1e-4 { - c.stroke(PathData::default().m(SH_PLOT.0, py).l(SH_PLOT.2, py), ink(0.05), 1.0); + c.stroke(PathData::default().m(g.plot.0, py).l(g.plot.2, py), ink(0.05), 1.0); } } let mut dash = PathData::default(); - let mut xx = SH_PLOT.0; - while xx < SH_PLOT.2 { - dash = dash.m(xx, sh_py(rest)).l((xx + 3.0).min(SH_PLOT.2), sh_py(rest)); + let mut xx = g.plot.0; + while xx < g.plot.2 { + dash = dash.m(xx, sh_py(rest)).l((xx + 3.0).min(g.plot.2), sh_py(rest)); xx += 6.0; } c.stroke(dash, ink(0.22), 1.0); @@ -1135,10 +1235,10 @@ impl Controller { line.insert(pos, (px, sh_py(w[0].y))); } } - let area = PathData::default().poly(&line).l(SH_PLOT.2, SH_PLOT.3).l(SH_PLOT.0, SH_PLOT.3).z(); + let area = PathData::default().poly(&line).l(g.plot.2, g.plot.3).l(g.plot.0, g.plot.3).z(); c.fill(area, vgrad(alpha(accent, 0.3 * curve_alpha), alpha(accent, 0.04 * curve_alpha))); c.stroke(PathData::default().poly(&line), alpha(accent, if lane_on { 1.0 } else { 0.45 }), 2.0); - let over_plot = in_rect(hp, SH_WELL.0, SH_WELL.1, SH_WELL.2, SH_WELL.3); + let over_plot = in_rect(hp, g.well.0, g.well.1, g.well.2, g.well.3); let gesture = match &self.devices.panel.editors.gesture { Some(Gesture::Curve { device, k, mid, .. }) if *device == d.id => Some((*k, *mid)), _ => None, @@ -1186,8 +1286,8 @@ impl Controller { let text = lane_text(lane, by, depth, quarters, self.time_max_beats(), values[7], values[8]); let w = 10.0 + 6.2 * text.chars().count() as f32; let (px, py) = (sh_px(bx), sh_py(by)); - let top = if py - 30.0 < SH_WELL.1 { py + 10.0 } else { py - 28.0 }; - let left = (px - w / 2.0).clamp(SH_WELL.0 + 2.0, SH_WELL.0 + SH_WELL.2 - w - 2.0); + let top = if py - 30.0 < g.well.1 { py + 10.0 } else { py - 28.0 }; + let left = (px - w / 2.0).clamp(g.well.0 + 2.0, g.well.0 + g.well.2 - w - 2.0); c.fill(PathData::default().rrect(left, top, w, 17.0, 8.5), rgba(0x2e, 0x2f, 0x35, 0.96)); c.text(left, top, w, 17.0, text, ink(0.95), 10.5, 600, 1); } @@ -1195,8 +1295,8 @@ impl Controller { if lane == 4 { for (i, (idx, h)) in [(8usize, Hit::FilterHigh), (7usize, Hit::FilterLow)].into_iter().enumerate() { let w = 38.0; - let px = SH_WELL.0 + SH_WELL.2 - w - 6.0; - let py = if i == 0 { SH_WELL.1 + 6.0 } else { SH_WELL.1 + SH_WELL.3 - 6.0 - 16.0 }; + let px = g.well.0 + g.well.2 - w - 6.0; + let py = if i == 0 { g.well.1 + 6.0 } else { g.well.1 + g.well.3 - 6.0 - 16.0 }; c.fill( PathData::default().rrect(px, py, w, 16.0, 8.0), if hit == h { rgba(0x29, 0x2a, 0x30, 1.0) } else { rgba(0x22, 0x23, 0x28, 1.0) }, @@ -1206,7 +1306,7 @@ impl Controller { } // Trigger cell: [Sync / This track / source] | threshold, caption under. - let (tx, ty, tw, th) = SH_TRIGGER; + let (tx, ty, tw, th) = g.trigger; let audio = values[0] >= 0.5; c.pill(tx, ty, tw, th, matches!(hit, Hit::Trigger | Hit::Threshold)); let source = if !audio { @@ -1230,13 +1330,13 @@ impl Controller { ); let thr_alpha = if audio { if hit == Hit::Threshold { 0.95 } else { 0.75 } } else { 0.35 }; c.text(tx + SH_TRIGGER_SPLIT, ty, tw - SH_TRIGGER_SPLIT, th, def.params[1].format(values[1]), ink(thr_alpha), 11.0, 600, 1); - c.text(tx, 284.5, tw, 14.0, "Trigger", rgba(0xe5, 0xe5, 0xe8, 1.0), 11.0, 600, 1); + if g.trigger_caption_under { + c.text(tx, 284.5, tw, 14.0, "Trigger", rgba(0xe5, 0xe5, 0xe8, 1.0), 11.0, 600, 1); + } else { + c.text(tx - 60.0, ty, 52.0, th, "Trigger", ink(0.4), 11.5, 500, 2); + } - // Knobs: the lane's Rate and Depth, then Mix and Output. - let idx = [base + sh::RATE, base + sh::DEPTH, 2, 3]; - let knobs: Vec = idx.iter().zip(SH_KNOBS).map(|(&i, x)| knob(def, values[i], i, x)).collect(); - card.knobs = ModelRc::from(Rc::new(VecModel::from(knobs))); - let cursor = match hit { + match hit { Hit::LaneOn(_) | Hit::Lane(_) | Hit::Shape | Hit::Band | Hit::FilterType | Hit::Trigger => CURSOR_POINTER, Hit::Split | Hit::Resonance | Hit::Bits | Hit::Decimate | Hit::Threshold | Hit::FilterHigh | Hit::FilterLow => CURSOR_NS, Hit::CurvePoint(k) => { @@ -1249,25 +1349,25 @@ impl Controller { Hit::Mid(_) => CURSOR_NS, Hit::Plot if pts.len() < sh::MAX_POINTS => CURSOR_CROSSHAIR, _ => 0, - }; - card.canvas = c.into_canvas(SH_W, cursor); + } } fn sh_hit(&self, d: &Device, def: &DeviceDef, p: (f32, f32)) -> Hit { + let g = sh_geo(); let lane = self.shaper_lane(d.id); let values = self.values(d, def); let base = sh::lane_base(lane); for l in 0..sh::LANE_COUNT { - let x = SH_TAB_X[l]; - if in_rect(p, x - 8.0, SH_TABS_Y - 9.0, 16.0, 18.0) { + let x = g.tab_x[l]; + if in_rect(p, x - 8.0, g.tabs_y - 9.0, 16.0, 18.0) { return Hit::LaneOn(l); } - let end = if l + 1 < sh::LANE_COUNT { SH_TAB_X[l + 1] - 12.0 } else { x + 70.0 }; - if in_rect(p, x + 8.0, SH_TABS_Y - 10.0, end - x - 8.0, 20.0) { + let end = if l + 1 < sh::LANE_COUNT { g.tab_x[l + 1] - 12.0 } else { x + 70.0 }; + if in_rect(p, x + 8.0, g.tabs_y - 10.0, end - x - 8.0, 20.0) { return Hit::Lane(l); } } - let y = SH_STRIP_Y; + let y = g.strip_y; if in_rect(p, 48.5, y, 97.0, 19.0) { return Hit::Shape; } @@ -1296,22 +1396,22 @@ impl Controller { return Hit::Decimate; } } - let (tx, ty, tw, th) = SH_TRIGGER; + let (tx, ty, tw, th) = g.trigger; if in_rect(p, tx, ty, SH_TRIGGER_SPLIT, th) { return Hit::Trigger; } if in_rect(p, tx + SH_TRIGGER_SPLIT, ty, tw - SH_TRIGGER_SPLIT, th) { return if values[0] >= 0.5 { Hit::Threshold } else { Hit::None }; } - if !in_rect(p, SH_WELL.0, SH_WELL.1, SH_WELL.2, SH_WELL.3) { + if !in_rect(p, g.well.0, g.well.1, g.well.2, g.well.3) { return Hit::None; } if lane == 4 { - let px = SH_WELL.0 + SH_WELL.2 - 44.0; - if in_rect(p, px, SH_WELL.1 + 6.0, 38.0, 16.0) { + let px = g.well.0 + g.well.2 - 44.0; + if in_rect(p, px, g.well.1 + 6.0, 38.0, 16.0) { return Hit::FilterHigh; } - if in_rect(p, px, SH_WELL.1 + SH_WELL.3 - 22.0, 38.0, 16.0) { + if in_rect(p, px, g.well.1 + g.well.3 - 22.0, 38.0, 16.0) { return Hit::FilterLow; } } @@ -1423,6 +1523,7 @@ impl Controller { _ => return, }; let _geo = (win && name == "trance-gate").then(|| TgScope::new(TG_WIN)); + let _sh = (win && name == "shaper").then(|| ShScope::new(SH_WIN)); let p = e.pt(); let hit = match name { "trance-gate" => self.tg_hit(d, def, p), diff --git a/crates/dstudio-app/src/device_window.rs b/crates/dstudio-app/src/device_window.rs index f81e343..3df1298 100644 --- a/crates/dstudio-app/src/device_window.rs +++ b/crates/dstudio-app/src/device_window.rs @@ -130,7 +130,10 @@ pub(crate) fn has_window(def: &DeviceDef) -> bool { def.id, "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" | "pitch-shifter" | "grains" | "pitch-corrector") + || matches!( + def.id, + "utility" | "widener" | "tuner" | "spectrum" | "trance-gate" | "pitch-shifter" | "grains" | "pitch-corrector" | "shaper" + ) || is_repair_window(def) || def.id == "bitcrusher" || is_field_window(def) @@ -152,6 +155,9 @@ fn is_wave_window(def: &DeviceDef) -> bool { matches!(def.id, "distortion" | "tapesaturation" | "soft-clipper" | "declipper") } +/// Height of the Shaper's lane tabs between the top bar and its display. +const SH_TABS_H: f32 = 48.0; + /// Windows of the plotted-field family (motion and response pictures). fn is_field_window(def: &DeviceDef) -> bool { matches!(def.id, "tremolo" | "autopanner" | "chorus" | "flanger" | "phaser" | "ring-mod" | "character-mod") @@ -208,6 +214,8 @@ pub(crate) fn kit(def: &DeviceDef) -> Kit { "multiband-compressor" => field_kit(WIN_W, 336.0, 52.0, 43.0), // Pitch Shifter: the semitone field over its axis, the formant strip and legend. "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 }, // 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. @@ -710,6 +718,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 def.id == "shaper" => self.shaper_editor_window_canvas(d, def, accent, dw, dh + SH_TABS_H), _ if def.id == "pitch-corrector" => { let (w, h) = plot_size(def).unwrap_or_default(); self.trace_window_canvas(d, def, w, h, accent) @@ -729,6 +738,9 @@ impl Controller { if def.id == "trance-gate" { display.x = INSET * Z; } + if def.id == "shaper" { + display.y = (dy - SH_TABS_H) * Z; + } let height = match def.id { "auto-filter" => self.auto_filter_window(d, def, &mut b), "channeleq" => self.channel_eq_window(d, def, &mut b), @@ -741,6 +753,7 @@ impl Controller { "echo" => self.echo_window(d, def, &mut b, dy + dh + 12.0), "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), "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), @@ -2303,6 +2316,35 @@ impl Controller { row.y + row.h + 16.0 } + /// Shaper: the shown lane's Rate and Depth, the trigger's Threshold (inert while synced), + /// then Mix and Output. + fn shaper_lanes_window(&self, d: &Device, def: &'static DeviceDef, b: &mut Builder, y: f32) -> f32 { + use dstudio_core::builtin::shaper as sh; + let val = |i: usize| def.params.get(i).map_or(0.0, |p| self.panel_value(d, def, p)); + let base = sh::lane_base(self.shaper_lane(d.id)); + let rate = &def.params[base + sh::RATE]; + let synced = val(def.index_of("trigger").unwrap_or(0)) < 0.5; + let row = Row::main(y); + self.win_card( + d, + def, + b, + row, + vec![ + ( + vec![ + Item::Picker((base + sh::RATE) as i32, rate.format(val(base + sh::RATE)), "Rate", 72.0, false), + Item::Knob(def.params[base + sh::DEPTH].id, "Depth", 2, 72.0, false), + ], + 14.0, + ), + (vec![Item::Knob("threshold", "Threshold", 2, 84.0, synced)], 14.0), + (vec![Item::Knob("mix", "Mix", 2, 72.0, false), Item::Knob("output", "Output", 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 { @@ -3827,6 +3869,54 @@ mod tests { assert_eq!(bits(&c) ^ before, 1, "the card's geometry did not take the window's point"); } + /// Shaper: the editor's tabs, strip and curve over the display, Trigger on the caption + /// row; a lane tab picked in the window's geometry (the card's tabs sit lower). + #[test] + fn shaper_window_draws_the_editor_and_picks_lanes_in_its_geometry() { + use slint::Model; + let (mut c, did, def) = controller_with("shaper"); + assert!(has_window(def)); + let v = view(&c, did, def); + assert!((v.w / Z - 1200.0).abs() < 0.5 && (v.h / Z - 700.0).abs() < 0.5, "{} x {}", v.w / Z, v.h / Z); + assert!(v.display.interactive && v.display.paths.row_count() > 10); + assert_eq!(knob_names(&v), ["Depth", "Threshold", "Mix", "Output"]); + assert!(v.knobs.iter().any(|k| k.label == "Threshold" && k.inert), "Threshold inert while synced"); + let texts: Vec = v.display.texts.iter().map(|t| t.text.to_string()).collect(); + for t in ["Volume", "Pitch", "Shape", "Trigger", "Sync"] { + assert!(texts.iter().any(|x| x == t), "missing {t}: {texts:?}"); + } + let at = |(x, y): (f32, f32), kind| crate::device_editors::CanvasEvent { + kind, + x: x * Z, + y: y * Z, + wx: 0.0, + wy: 0.0, + shift: false, + alt: false, + wheel: 0.0, + }; + let points = |c: &Controller| { + let d = c.project().device(did).unwrap(); + c.panel_value(d, def, def.param("vol_points").unwrap()).round() as i32 + }; + let before = points(&c); + // A point low on the window's curve: below the card's whole editor, so the card's + // geometry takes nothing there; the window's adds a point. + let low = (300.0, 420.0); + c.panel_editor(did, at(low, 0)); + c.panel_editor(did, at(low, 2)); + assert_eq!(points(&c), before, "the card's geometry missed"); + c.panel_editor(did, at(low, 16)); + c.panel_editor(did, at(low, 18)); + assert_eq!(points(&c), before + 1, "a point added on the window's curve"); + let tab = crate::device_editors::SH_WIN.tab_name(2); + c.panel_editor(did, at(tab, 16)); + c.panel_editor(did, at(tab, 18)); + assert_eq!(c.shaper_lane(did), 2, "Width picked in the window"); + let v = view(&c, did, def); + assert!(v.pills.iter().any(|p| p.label == "1/4" || p.kind == PILL_PICKER), "the lane's Rate picker"); + } + /// Spectrum: three views from one history; Reset clears it, Hold view stops taking /// frames, the History picker is inert in 2D. #[test] @@ -3912,6 +4002,7 @@ mod tests { "pitch-shifter", "grains", "pitch-corrector", + "shaper", ] { let (mut c, did, def) = controller_with(id); let h: std::collections::VecDeque<_> = diff --git a/docs/devices.md b/docs/devices.md index 6fc28e8..9fa050c 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; De-Clipper, De-Esser, De-Hummer and De-Noiser; Pitch Shifter, Grains and Pitch Corrector), 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), 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 @@ -143,7 +143,8 @@ flowchart LR drags are hit tested at that size. Pitch Shifter and Grains draw `field_canvas` with `window` set (the field adds its axes, legend and readouts); Pitch Corrector draws `trace_window_canvas`, which shares - `trace_layers` with the card. The + `trace_layers` with the card. Shaper's window draws `sh_draw` under + `ShScope` (`SH_CARD` or `SH_WIN`), the same way as the Trance Gate. 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