diff --git a/CHANGELOG.md b/CHANGELOG.md index 850abbc..bd3ab1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -73,3 +73,8 @@ Nothing has been released yet. The first release, 0.1.0, will cover what is on ` 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. +- Expanded windows for the pitch devices: Pitch Shifter (the interval field with the In and Out notes against an A4 + reference, the semitone axis, the formant strip and a legend), Grains (the buffer with Position and Spray readouts, + 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). diff --git a/README.md b/README.md index 055e6b8..4165fdc 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,9 @@ the transfer curve beside a sine through the device, Bit Crusher, whose window d 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, 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. +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. [docs/devices.md](docs/devices.md) explains how they work and how to add one. | Kind | Devices | diff --git a/crates/dstudio-app/src/analyzer_views.rs b/crates/dstudio-app/src/analyzer_views.rs index ed267fa..dd430a4 100644 --- a/crates/dstudio-app/src/analyzer_views.rs +++ b/crates/dstudio-app/src/analyzer_views.rs @@ -439,6 +439,53 @@ impl Controller { } layers.push(line(g, white(a), 1.0)); } + let over = self.trace_layers(d, def, x0, w, &y_of, accent, &mut layers); + canvas(FIELD_X * Z, FIELD_Y * Z, w, h, body_y, "Pitch", String::new(), [Vec::new(), layers, over], Vec::new()) + } + + /// The Pitch Corrector's window display (w x h px): the trace over rules every 25 ct, + /// the ±100 / ±50 / 0 rules labelled in the left gutter and "ct" under them. + pub(crate) fn trace_window_canvas(&self, d: &Device, def: &'static DeviceDef, w: f32, h: f32, accent: Color) -> PanelCanvas { + let edge = 43.0 * Z; + let mid = h / 2.0; + let y_of = |ct: f32| (mid - ct / 100.0 * (mid - edge)).clamp(2.0 * Z, h - 2.0 * Z); + let gutter = 34.0 * Z; + let mut layers = Vec::new(); + let mut texts = Vec::new(); + for (cts, a) in [(&[0.0][..], 0.2), (&[50.0, -50.0, 100.0, -100.0][..], 0.09), (&[25.0, -25.0, 75.0, -75.0][..], 0.045)] { + let mut g = String::new(); + for c in cts { + let labelled = (*c as i32) % 50 == 0; + hline(&mut g, if labelled { gutter } else { 0.0 }, w, y_of(*c).round() + 0.5); + if labelled { + let t = match *c as i32 { + 0 => "0".to_string(), + v if v > 0 => format!("+{v}"), + v => format!("\u{2212}{}", -v), + }; + texts.push(text(6.0 * Z, y_of(*c) - 7.0 * Z, gutter, 14.0 * Z, &t, white(0.4), 9.5 * Z, 600, 0)); + } + } + layers.push(line(g, white(a), 1.0)); + } + texts.push(text(6.0 * Z, y_of(-100.0) + 8.0 * Z, gutter, 14.0 * Z, "ct", white(0.4), 9.5 * Z, 600, 0)); + let over = self.trace_layers(d, def, gutter, w, &y_of, accent, &mut layers); + PanelCanvas { well: false, ..canvas(0.0, 0.0, w, h, 0.0, "", String::new(), [Vec::new(), layers, over], texts) } + } + + /// The trace's runs (input against corrected, per target note) into `layers`, from x0 to + /// the now edge at w; returns the marker of the newest voiced frame. + #[allow(clippy::too_many_arguments)] + fn trace_layers( + &self, + d: &Device, + def: &'static DeviceDef, + x0: f32, + w: f32, + y_of: &dyn Fn(f32) -> f32, + accent: Color, + layers: &mut Vec, + ) -> Vec { let mixv = def.param("mix").map_or(100.0, |p| self.panel_value(d, def, p)) / 100.0; let corr_color = alpha(accent, 0.25 + 0.75 * mixv); let mut over = Vec::new(); @@ -479,14 +526,13 @@ impl Controller { layers.push(area(fill, alpha(accent, 0.09), alpha(accent, 0.09))); layers.push(line(raw_l, white(0.55), 1.4 * Z)); layers.push(line(fix_l, corr_color, 1.6 * Z)); - if let Some(f) = frames.back().filter(|f| f.voiced) + if frames.back().is_some_and(|f| f.voiced) && let Some(p) = runs.last().and_then(|r| r.last()) { - let _ = f; over.push(rect(p.0 - 2.0 * Z, p.2 - 2.0 * Z, 4.0 * Z, 4.0 * Z, 2.0 * Z, corr_color)); } } - canvas(FIELD_X * Z, FIELD_Y * Z, w, h, body_y, "Pitch", String::new(), [Vec::new(), layers, over], Vec::new()) + over } /// A Spectrum card's newest frame: (analyser sequence, shown curve, peak hold), dB per band. diff --git a/crates/dstudio-app/src/device_window.rs b/crates/dstudio-app/src/device_window.rs index 7f26918..f81e343 100644 --- a/crates/dstudio-app/src/device_window.rs +++ b/crates/dstudio-app/src/device_window.rs @@ -130,7 +130,7 @@ 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") + || matches!(def.id, "utility" | "widener" | "tuner" | "spectrum" | "trance-gate" | "pitch-shifter" | "grains" | "pitch-corrector") || is_repair_window(def) || def.id == "bitcrusher" || is_field_window(def) @@ -175,6 +175,17 @@ fn field_kit(w: f32, display_h: f32, left: f32, bottom: f32) -> Kit { Kit { w, display: (INSET, 52.0, w - 152.0, display_h), plot: (left, 25.0, 8.0, bottom), narrow: true, meters_h: 0.0 } } +impl Kit { + fn with_plot_top(mut self, t: f32) -> Kit { + self.plot.1 = t; + self + } + fn with_plot_right(mut self, r: f32) -> Kit { + self.plot.2 = r; + self + } +} + pub(crate) fn kit(def: &DeviceDef) -> Kit { let eq = |y: f32, h: f32| Kit { w: WIN_W, @@ -195,6 +206,12 @@ pub(crate) fn kit(def: &DeviceDef) -> Kit { "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), + // 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), + // 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. + "grains" => field_kit(1200.0, 402.0, 16.0, 24.0).with_plot_right(70.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 @@ -693,6 +710,10 @@ 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 == "pitch-corrector" => { + let (w, h) = plot_size(def).unwrap_or_default(); + self.trace_window_canvas(d, def, w, h, 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), @@ -718,6 +739,9 @@ impl Controller { "delay" => self.delay_window(d, def, &mut b, dy + dh + 12.0), "reverb" => self.reverb_window(d, def, &mut b, dy + dh + 12.0), "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), + "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), "widener" => self.widener_window(d, def, &mut b, dy + dh + 12.0), @@ -2059,6 +2083,10 @@ impl Controller { let val = |id: &str| def.param(id).map_or(0.0, |p| self.panel_value(d, def, p)); match def.id { "echo" => ("Tail".into(), String::new(), String::new()), + "grains" => ("Buffer".into(), String::new(), String::new()), + "pitch-shifter" => { + ("Interval".into(), dstudio_core::builtin::pitch_shifter::interval_text(val("semitones"), val("cents")), String::new()) + } "delay" => { let synced = val("sync") >= 0.5; let (l, r) = if synced { (fmt("timeDivision"), fmt("timeDivisionR")) } else { (fmt("timeMs"), fmt("timeMsR")) }; @@ -2257,6 +2285,144 @@ impl Controller { row.y + row.h + 16.0 } + /// Pitch Shifter: Semitones and Cents, the Formant switch (Shift, or Keep), Mix. + fn pitch_shifter_window(&self, d: &Device, def: &'static DeviceDef, b: &mut Builder, y: f32) -> f32 { + let keep = def.param("formant_preserve").is_some_and(|p| self.panel_value(d, def, p) >= 0.5); + let row = Row::main(y); + self.win_card( + d, + def, + b, + row, + vec![ + (vec![Item::Knob("semitones", "Semitones", 2, 72.0, false), Item::Knob("cents", "Cents", 2, 72.0, false)], 14.0), + (vec![Item::Latch("formant_preserve", if keep { "Keep" } else { "Shift" }, "Formant", 120.0, false)], 14.0), + (vec![Item::Knob("mix", "Mix", 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 { + 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 row = Row::main(y); + self.win_card( + d, + def, + b, + row, + vec![ + ( + vec![ + Item::Pills("key_follow", vec![("Manual", 0.0), ("Project", 1.0)], "Follow", 136.0), + Item::Picker(idx("key"), fmt("key"), "Key", 56.0, val("key_follow") >= 0.5), + Item::Pills("scale", vec![("Chromatic", 0.0), ("Major", 1.0), ("Minor", 2.0)], "Scale", 210.0), + ], + 16.0, + ), + ( + vec![ + Item::Knob("speed", "Speed", 2, 72.0, false), + Item::Knob("retune_speed_ms", "Retune Speed", 2, 96.0, false), + Item::Knob("humanize", "Humanize", 1, 72.0, false), + ], + 14.0, + ), + (vec![Item::Knob("mix", "Mix", 2, 72.0, false)], 14.0), + ], + ); + row.y + row.h + 16.0 + } + + /// Grains: Cloud / Rhythm and Freeze in the header; the grain card (where, how long and + /// how often, pitch) over the sound card (texture, Character, Mix, Output). Rhythm swaps + /// Position, Size and Density for its note, Gate, Rate and Chance. + fn grains_window(&self, d: &Device, def: &'static DeviceDef, b: &mut Builder, y: f32) -> f32 { + 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 x = self.header_latch(d, def, b, "freeze", b.w - INSET); + let x = Self::header_rule(b, x); + self.header_choice(d, def, b, "mode", x); + + let rhythm = val("mode").round() as u32 == dstudio_core::builtin::grains::RHYTHM; + let (where_, timing) = if rhythm { + ( + vec![ + Item::Picker(idx("position_note"), fmt("position_note"), "Position", 72.0, false), + Item::Knob("spray", "Spray", 1, 62.0, false), + Item::Knob("drift", "Drift", 1, 62.0, false), + ], + vec![ + Item::Picker(idx("rate"), fmt("rate"), "Rate", 72.0, false), + Item::Knob("gate", "Gate", 1, 62.0, false), + Item::Knob("chance", "Chance", 1, 62.0, false), + Item::Knob("shape", "Shape", 1, 62.0, false), + ], + ) + } else { + ( + vec![ + Item::Knob("position", "Position", 1, 62.0, false), + Item::Knob("spray", "Spray", 1, 62.0, false), + Item::Knob("drift", "Drift", 1, 62.0, false), + ], + vec![ + Item::Knob("size", "Size", 1, 62.0, false), + Item::Knob("density", "Density", 1, 62.0, false), + Item::Knob("shape", "Shape", 1, 62.0, false), + ], + ) + }; + let row = Row::main(y); + self.win_card( + d, + def, + b, + row, + vec![ + (where_, 8.0), + (timing, 8.0), + ( + vec![ + Item::Knob("pitch", "Pitch", 1, 62.0, false), + Item::Knob("spread", "Spread", 1, 62.0, rhythm), + Item::Picker(idx("scale"), fmt("scale"), "Scale", 84.0, false), + Item::Knob("reverse", "Reverse", 1, 62.0, false), + ], + 8.0, + ), + ], + ); + let row2 = Row { h: 100.0, ..Row::main(row.y + row.h + 12.0) }; + self.win_card( + d, + def, + b, + row2, + vec![ + ( + vec![ + Item::Knob("width", "Width", 1, 56.0, false), + Item::Knob("feedback", "Feedback", 1, 56.0, false), + Item::Knob("blur", "Blur", 1, 56.0, false), + Item::Knob("tone", "Tone", 1, 56.0, false), + Item::Knob("space", "Space", 1, 56.0, false), + ], + 8.0, + ), + (vec![Item::Picker(idx("character"), fmt("character"), "Character", 96.0, false)], 8.0), + (vec![Item::Knob("mix", "Mix", 1, 56.0, false), Item::Toggle("mix_lock", "Mix Lock", false)], 10.0), + (vec![Item::Knob("output", "Output", 1, 62.0, false)], 8.0), + ], + ); + row2.y + row2.h + 16.0 + } + /// A two-handle range on a line (Reverb's Filter): the span between the handles lit, each /// handle dragged along the line in its parameter's control range. fn range_canvas(&self, d: &Device, def: &'static DeviceDef, ids: (&str, &str), w: f32, accent: Color) -> PanelCanvas { @@ -3091,6 +3257,91 @@ mod tests { assert_eq!(knob_names(&view(&c, did, def)), ["Frequency", "Spread", "Bias", "Rectify", "Mix", "Output"]); } + /// Pitch Shifter: the interval caption, the note readouts against A4, the axis, the + /// formant strip and legend over a card of every control; the Formant switch says Shift + /// or Keep. + #[test] + fn pitch_shifter_window_shows_the_interval_and_every_control() { + use slint::Model; + let (mut c, did, def) = controller_with("pitch-shifter"); + 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_eq!(knob_names(&v), ["Semitones", "Cents", "Mix"]); + let texts: Vec = v.display.texts.iter().map(|t| t.text.to_string()).collect(); + for t in ["Interval", "Unison", "A4", "+24 st", "Formant", "Follows the shift", "Interval"] { + assert!(texts.iter().any(|x| x == t), "missing {t}: {texts:?}"); + } + assert!(v.pills.iter().any(|p| p.label == "Shift" && !p.active)); + c.execute(Command::SetDeviceParam { device: did, param: "semitones".into(), value: 7.0 }); + c.execute(Command::SetDeviceParam { device: did, param: "formant_preserve".into(), value: 1.0 }); + let v = view(&c, did, def); + let texts: Vec = v.display.texts.iter().map(|t| t.text.to_string()).collect(); + for t in ["Fifth up", "E5", "Out 659.3 Hz", "Held in place"] { + assert!(texts.iter().any(|x| x == t), "missing {t}: {texts:?}"); + } + assert!(v.pills.iter().any(|p| p.label == "Keep" && p.active)); + } + + /// Pitch Corrector: the cent rules labelled in the gutter over a card of every control. + #[test] + fn pitch_corrector_window_shows_the_trace_rules_and_every_control() { + use slint::Model; + let (c, did, def) = controller_with("pitch-corrector"); + 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_eq!(knob_names(&v), ["Speed", "Retune Speed", "Humanize", "Mix"]); + let texts: Vec = v.display.texts.iter().map(|t| t.text.to_string()).collect(); + for t in ["+100", "+50", "0", "\u{2212}50", "\u{2212}100", "ct"] { + assert!(texts.iter().any(|x| x == t), "missing {t}: {texts:?}"); + } + for l in ["Manual", "Project", "Chromatic", "Major", "Minor"] { + assert!(v.pills.iter().any(|p| p.label == l), "pill {l}"); + } + assert!(v.display.visible && v.display.paths.row_count() >= 3); + } + + /// Grains: the buffer with both readouts and its two axes; Cloud and Rhythm swap the + /// grain card's timing controls; Freeze and the mode sit in the header. + #[test] + fn grains_window_shows_the_buffer_and_both_cards() { + use slint::Model; + let (mut c, did, def) = controller_with("grains"); + 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_eq!( + knob_names(&v), + [ + "Position", "Spray", "Drift", "Size", "Density", "Shape", "Pitch", "Spread", "Reverse", "Width", "Feedback", "Blur", + "Tone", "Space", "Mix", "Output" + ] + ); + let grips: Vec = v.display.grips.iter().map(|g| g.label.to_string()).collect(); + assert_eq!(grips, ["Position", "Spray"]); + let texts: Vec = v.display.texts.iter().map(|t| t.text.to_string()).collect(); + for t in ["Buffer", "+24", "\u{2212}24", "s", "st"] { + assert!(texts.iter().any(|x| x == t), "missing {t}: {texts:?}"); + } + for l in ["Cloud", "Rhythm", "Freeze"] { + assert!(v.pills.iter().any(|p| p.label == l), "header {l}"); + } + c.execute(Command::SetDeviceParam { device: did, param: "mode".into(), value: 1.0 }); + let v = view(&c, did, def); + assert_eq!( + knob_names(&v), + [ + "Spray", "Drift", "Gate", "Chance", "Shape", "Pitch", "Spread", "Reverse", "Width", "Feedback", "Blur", "Tone", "Space", + "Mix", "Output" + ] + ); + assert!(v.knobs.iter().any(|k| k.label == "Spread" && k.inert)); + for k in v.knobs.iter() { + assert!(k.y > 0.0 && k.y < v.h, "{} outside", k.label); + } + } + /// Cost of rebuilding a field window against its card, per device /// (`cargo test -p dstudio-app --release bench_field_windows -- --ignored --nocapture`). #[test] @@ -3658,6 +3909,9 @@ mod tests { "deesser", "dehummer", "denoiser", + "pitch-shifter", + "grains", + "pitch-corrector", ] { let (mut c, did, def) = controller_with(id); let h: std::collections::VecDeque<_> = diff --git a/crates/dstudio-app/src/panel_fields.rs b/crates/dstudio-app/src/panel_fields.rs index c092109..f5edde1 100644 --- a/crates/dstudio-app/src/panel_fields.rs +++ b/crates/dstudio-app/src/panel_fields.rs @@ -1308,7 +1308,8 @@ impl Controller { fn draw_pitch(c: &mut Canvas, v: &dyn Fn(&str) -> f32, accent: Color, w: f32, h: f32, hot: bool) { let x_of = |st: f32| (st + 24.5) / 49.0 * w; - let main = h * 0.72; + // The window keeps a band under the field for the axis, the formant strip and the legend. + let main = if c.window { h - 96.0 * Z } else { h * 0.72 }; let (mut major, mut minor) = (String::new(), String::new()); for st in -24..=24 { let x = x_of(st as f32); @@ -1336,7 +1337,7 @@ fn draw_pitch(c: &mut Canvas, v: &dyn Fn(&str) -> f32, accent: Color, w: f32, h: seg(&mut wet, x1, 0.0, x1, main); c.stroke(wet, accent.with_alpha(0.25 + 0.75 * mix), if hot { 2.15 } else { 1.4 } * Z); // Formant strip: baseline and the formant marker (held at 0 st, or following the shift). - let base_y = main + (h - main) * 0.55; + let base_y = if c.window { main + 40.0 * Z } else { main + (h - main) * 0.55 }; let mut base = String::new(); seg(&mut base, 0.0, base_y, w, base_y); c.stroke(base, ink(0.06), 1.0); @@ -1350,6 +1351,84 @@ fn draw_pitch(c: &mut Canvas, v: &dyn Fn(&str) -> f32, accent: Color, w: f32, h: let mut tri = String::new(); let _ = write!(tri, "M{:.2} {:.2} L{:.2} {:.2} L{:.2} {:.2} Z", fx, base_y - 8.0 * Z, fx + 5.0 * Z, base_y, fx - 5.0 * Z, base_y); c.fill(tri, if held { accent.with_alpha(0.9) } else { ink(0.55) }); + if c.window { + pitch_window_marks(c, accent, x0, x1, v("semitones") + v("cents") / 100.0, held, w, main); + } +} + +/// Note name of a frequency (A4 = 440 Hz), e.g. "C#5". +fn note_name(hz: f32) -> String { + const NAMES: [&str; 12] = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]; + let midi = (69.0 + 12.0 * (hz / 440.0).log2()).round() as i32; + format!("{}{}", NAMES[midi.rem_euclid(12) as usize], midi.div_euclid(12) - 1) +} + +/// The Pitch Shifter window's labels: the In / Out notes on their lines (against the A4 +/// reference), the semitone axis, the formant caption and the legend. +#[allow(clippy::too_many_arguments)] +fn pitch_window_marks(c: &mut Canvas, accent: Color, x0: f32, x1: f32, shift: f32, held: bool, w: f32, main: f32) { + let (dim, faint) = (ink(0.55), ink(0.4)); + let note = |c: &mut Canvas, x: f32, hz: f32, tag: &str, color: Color| { + let right = x > w - 150.0 * Z; + let (tx, align) = if right { (x - 8.0 * Z - 150.0 * Z, 2) } else { (x + 8.0 * Z, 0) }; + c.text(tx, 11.0 * Z, 150.0 * Z, note_name(hz), color, 11.0 * Z, align); + c.text(tx, 25.0 * Z, 150.0 * Z, format!("{tag} {hz:.1} Hz"), faint, 9.5 * Z, align); + }; + note(c, x0, 440.0, "In (ref)", dim); + if (x1 - x0).abs() > 0.5 { + note(c, x1, 440.0 * 2f32.powf(shift / 12.0), "Out", accent); + } + for st in [-24, -12, 0, 12, 24] { + let x = (st as f32 + 24.5) / 49.0 * w; + let t = match st { + 0 => "0".to_string(), + 24 => "+24 st".to_string(), + s if s > 0 => format!("+{s}"), + s => format!("{MINUS}{}", -s), + }; + c.text(x - 30.0 * Z, main + 10.0 * Z, 60.0 * Z, t, faint, 9.5 * Z, 1); + } + let fy = main + 61.0 * Z; + c.text(0.0, fy, 60.0 * Z, "Formant", ink(0.6), 10.5 * Z, 0); + let follow = if held { "Held in place" } else { "Follows the shift" }; + c.text(58.0 * Z, fy, 200.0 * Z, follow, if held { accent } else { ink(0.75) }, 12.0 * Z, 0); + // Legend: In, Out, Interval, Formant. + let ly = main + 85.0 * Z; + let mut x = 6.0 * Z; + let mut marks = |c: &mut Canvas, label: &str, draw: &dyn Fn(&mut Canvas, f32)| { + draw(c, x); + c.text(x + 14.0 * Z, ly, 80.0 * Z, label.to_string(), dim, 9.5 * Z, 0); + x += (crate::text_measure::value_width(label) * 0.8 + 38.0) * Z; + }; + marks(c, "In", &|c, x| { + let mut l = String::new(); + seg(&mut l, x + 3.0 * Z, ly - 5.0 * Z, x + 3.0 * Z, ly + 5.0 * Z); + c.stroke(l, ink(0.5), 1.0); + }); + marks(c, "Out", &|c, x| { + let mut l = String::new(); + seg(&mut l, x + 3.0 * Z, ly - 5.0 * Z, x + 3.0 * Z, ly + 5.0 * Z); + c.stroke(l, accent, 1.6 * Z); + }); + marks(c, "Interval", &|c, x| { + let mut r = String::new(); + rect(&mut r, x - 2.0 * Z, ly - 4.0 * Z, 14.0 * Z, 8.0 * Z); + c.fill(r, accent.with_alpha(0.18)); + }); + marks(c, "Formant", &|c, x| { + let mut t = String::new(); + let _ = write!( + t, + "M{:.2} {:.2} L{:.2} {:.2} L{:.2} {:.2} Z", + x + 4.0 * Z, + ly - 5.0 * Z, + x + 9.0 * Z, + ly + 4.0 * Z, + x - 1.0 * Z, + ly + 4.0 * Z + ); + c.fill(t, accent.with_alpha(0.9)); + }); } #[allow(clippy::too_many_arguments)] @@ -1646,6 +1725,19 @@ fn draw_grains( -9.0 * Z ); c.fill(tab, ink(0.95)); + if c.window { + // The window keeps both readouts up, Position at the top and Spray at the foot. + let position = if r.rhythm { + grains::POSITION_NOTES[(v("position_note").round() as usize).min(9)].to_string() + } else { + grains::ms_text(r.position * 1000.0) + }; + let dragged = drag.map(|g| g.grab); + c.pill(xp + 6.0 * Z, 15.0 * Z, w, "Position", &position, matches!(dragged, Some(Grab::GrainsPosition { .. }))); + c.pill(xs + 6.0 * Z, h - 18.0 * Z, w, "Spray", &grains::ms_text(r.spray * 1000.0), dragged == Some(Grab::GrainsSpray)); + grains_window_axes(c, span, w, h, &y_of); + return; + } match drag.map(|g| g.grab) { Some(Grab::GrainsPosition { .. }) => c.pill(xp + 6.0 * Z, 26.0 * Z, w, "Position", &grains::ms_text(r.position * 1000.0), true), Some(Grab::GrainsSpray) => c.pill(xs + 6.0 * Z, 26.0 * Z, w, "Spray", &grains::ms_text(r.spray * 1000.0), true), @@ -1653,6 +1745,37 @@ fn draw_grains( } } +/// The Grains window's axes: pitch (st) down the right edge, time back from now (s) below. +fn grains_window_axes(c: &mut Canvas, span: f32, w: f32, h: f32, y_of: &dyn Fn(f32) -> f32) { + let faint = ink(0.45); + let mut edge = String::new(); + seg(&mut edge, w, 0.0, w, h); + c.stroke(edge, ink(0.1), 1.0); + for st in [24, 12, 0, -12, -24] { + let t = match st { + 0 => "0".to_string(), + s if s > 0 => format!("+{s}"), + s => format!("{MINUS}{}", -s), + }; + c.text(w + 12.0 * Z, y_of(st as f32), 40.0 * Z, t, faint, 9.5 * Z, 0); + } + let y = h + 11.0 * Z; + c.text(2.0 * Z, y, 20.0 * Z, "s", faint, 9.5 * Z, 0); + c.text(w + 12.0 * Z, y, 20.0 * Z, "st", faint, 9.5 * Z, 0); + let step = ruler_step(span, w, 150.0 * Z); + let mut t = step; + for _ in 0..64 { + if t >= span * 0.97 { + break; + } + let x = grains_x(t, span, w); + if x > 30.0 * Z { + c.text(x - 30.0 * Z, y, 60.0 * Z, seconds_label(t), faint, 9.5 * Z, 1); + } + t += step; + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/docs/devices.md b/docs/devices.md index 8f02623..6fc28e8 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), 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), 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 @@ -140,7 +140,10 @@ flowchart LR (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 + 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 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