From d649f2a7666c15d301a35094dece1fc130d6bea8 Mon Sep 17 00:00:00 2001 From: Chris Laupama <42254688+chrislaupama@users.noreply.github.com> Date: Thu, 12 Nov 2026 02:38:18 +0000 Subject: [PATCH 1/4] Make dstudio-core clippy clean Fixes the clippy findings in dstudio-core (including the deny-level approx_constant in the EQ tests) and allows two lints where the fix doesn't fit: large_enum_variant on Command and AssistantAction (built once per edit, boxing Track would touch every caller) and too_many_arguments on clipper_transfer (one argument per device parameter). !(x > 0.0) in AddAsset becomes an explicit NaN check with the same meaning. --- crates/dstudio-core/benches/steps.rs | 2 +- crates/dstudio-core/src/assistant.rs | 1 + crates/dstudio-core/src/builtin/echo.rs | 6 ++-- crates/dstudio-core/src/builtin/eq.rs | 27 +++++++++-------- .../dstudio-core/src/builtin/soft_clipper.rs | 1 + crates/dstudio-core/src/command.rs | 3 +- crates/dstudio-core/src/history.rs | 30 +++++++++---------- crates/dstudio-core/src/midi.rs | 11 ++++--- crates/dstudio-core/src/midi_record.rs | 2 +- crates/dstudio-core/src/model.rs | 3 +- crates/dstudio-core/src/scale.rs | 4 +-- crates/dstudio-core/src/shape.rs | 4 +-- crates/dstudio-core/src/steps.rs | 18 ++++++----- crates/dstudio-core/tests/midi.rs | 3 +- crates/dstudio-core/tests/warp.rs | 2 +- 15 files changed, 62 insertions(+), 55 deletions(-) diff --git a/crates/dstudio-core/benches/steps.rs b/crates/dstudio-core/benches/steps.rs index 5614562a..42764268 100644 --- a/crates/dstudio-core/benches/steps.rs +++ b/crates/dstudio-core/benches/steps.rs @@ -13,7 +13,7 @@ use std::time::Instant; fn pattern(steps: u16, rate: StepRate, every: u16, repeat: i32) -> StepPattern { let mut p = StepPattern { rate, steps, ..StepPattern::default() }; for pad in 0..16u8 { - for s in (0..steps).filter(|s| (s + pad as u16) % every == 0) { + for s in (0..steps).filter(|s| (s + pad as u16).is_multiple_of(every)) { p = p.toggled(36 + pad, s).with_lane(36 + pad, s, StepLane::Repeat, repeat).with_lane( 36 + pad, s, diff --git a/crates/dstudio-core/src/assistant.rs b/crates/dstudio-core/src/assistant.rs index c0c9186e..ec27ed57 100644 --- a/crates/dstudio-core/src/assistant.rs +++ b/crates/dstudio-core/src/assistant.rs @@ -30,6 +30,7 @@ pub enum Mode { /// One action proposed by the model. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(tag = "type", rename_all = "snake_case")] +#[allow(clippy::large_enum_variant, reason = "a handful per assistant turn; `Edit` holds a `Command`, see its note")] pub enum AssistantAction { /// Any validated edit command (see `Command`). Edit { command: Command }, diff --git a/crates/dstudio-core/src/builtin/echo.rs b/crates/dstudio-core/src/builtin/echo.rs index 0c08c935..fc2b8454 100644 --- a/crates/dstudio-core/src/builtin/echo.rs +++ b/crates/dstudio-core/src/builtin/echo.rs @@ -214,7 +214,7 @@ pub fn picture(def: &DeviceDef, d: &Device, bpm: f64) -> Picture { if authored(machine, &v) { let span = (ms.loop_mm - ms.gap_mm - 1.1).max(1.0); for n in 1..=(v("heads").round() as usize).clamp(1, 6) { - let h = |f: &str| head_param(n, f).map_or(0.0, |id| v(id)); + let h = |f: &str| head_param(n, f).map_or(0.0, &v); if h("present") < 0.5 { continue; } @@ -241,8 +241,8 @@ pub fn picture(def: &DeviceDef, d: &Device, bpm: f64) -> Picture { let spacing = v("spacing").round().clamp(0.0, 4.0) as u32; let morph = v("spacing_morph").clamp(0.0, 1.0); let count = ms.heads_mm.len(); - for i in 0..count { - let mut mm = if machine == 2 { ms.heads_mm[0] - motor * CARTRIDGE_TRAVEL } else { ms.heads_mm[i] }; + for (i, &head_mm) in ms.heads_mm.iter().enumerate() { + let mut mm = if machine == 2 { ms.heads_mm[0] - motor * CARTRIDGE_TRAVEL } else { head_mm }; if spacing > 0 && i > 0 { let k = i as f32; let f = match spacing { diff --git a/crates/dstudio-core/src/builtin/eq.rs b/crates/dstudio-core/src/builtin/eq.rs index db4afa10..d9db40e0 100644 --- a/crates/dstudio-core/src/builtin/eq.rs +++ b/crates/dstudio-core/src/builtin/eq.rs @@ -121,7 +121,7 @@ fn cdiv(a: f64, b: f64, c: f64, d: f64) -> (f64, f64) { pub fn butterworth_qs(order: u32) -> (Vec, bool) { let n = order.max(1); // Pole angles from the negative real axis: (2i - 1) pi / 2n (even), i pi / n (odd). - let angle = |i: u32| if n % 2 == 0 { (2 * i - 1) as f64 * PI / (2 * n) as f64 } else { i as f64 * PI / n as f64 }; + let angle = |i: u32| if n.is_multiple_of(2) { (2 * i - 1) as f64 * PI / (2 * n) as f64 } else { i as f64 * PI / n as f64 }; let mut qs: Vec = (1..=n / 2).map(|i| 1.0 / (2.0 * angle(i).cos())).collect(); qs.sort_by(|a, b| b.total_cmp(a)); (qs, n % 2 == 1) @@ -504,7 +504,7 @@ impl EqView { .unwrap_or(12.0); let mut gain_db = value(d.gain); if with_dyn && d.dyn_on.is_some_and(|p| value(p) >= 0.5) { - gain_db += d.dyn_range.map_or(0.0, |p| value(p)); + gain_db += d.dyn_range.map_or(0.0, value); } let b = Band { shape, @@ -514,7 +514,7 @@ impl EqView { slope_db, prop_q: d.prop_q.is_some_and(|p| value(p) >= 0.5), overshoot: d.overshoot.map_or(0.0, |p| value(p) / 100.0), - low_atten_db: d.low_atten.map_or(0.0, |p| value(p)), + low_atten_db: d.low_atten.map_or(0.0, value), }; match self.bank { Some(p) => bank(value(p)).voice(b), @@ -541,6 +541,7 @@ pub fn choice_number(name: &str) -> f32 { #[cfg(test)] mod tests { use super::*; + use std::f32::consts::FRAC_1_SQRT_2; const FS: f64 = 48_000.0; @@ -560,19 +561,19 @@ mod tests { #[test] fn shelves_reach_their_gain_and_split_by_slope() { for slope in [6.0, 12.0, 18.0, 24.0] { - let mut ls = Band::new(Shape::LowShelf, 200.0, 9.0, 0.7071); + let mut ls = Band::new(Shape::LowShelf, 200.0, 9.0, FRAC_1_SQRT_2); ls.slope_db = slope; assert!((band_db(&ls, 20.0, FS) - 9.0).abs() < 0.6, "low shelf {slope}: {}", band_db(&ls, 20.0, FS)); assert!(band_db(&ls, 15_000.0, FS).abs() < 0.1); - let mut hs = Band::new(Shape::HighShelf, 2000.0, -6.0, 0.7071); + let mut hs = Band::new(Shape::HighShelf, 2000.0, -6.0, FRAC_1_SQRT_2); hs.slope_db = slope; assert!((band_db(&hs, 20_000.0, FS) + 6.0).abs() < 0.6, "high shelf {slope}: {}", band_db(&hs, 20_000.0, FS)); assert!(band_db(&hs, 20.0, FS).abs() < 0.05); assert!((band_db(&ls, 200.0, FS) - 4.5).abs() < 0.6, "low shelf {slope} corner {}", band_db(&ls, 200.0, FS)); } - let mut steep = Band::new(Shape::LowShelf, 200.0, 9.0, 0.7071); + let mut steep = Band::new(Shape::LowShelf, 200.0, 9.0, FRAC_1_SQRT_2); steep.slope_db = 24.0; - let gentle = Band::new(Shape::LowShelf, 200.0, 9.0, 0.7071); + let gentle = Band::new(Shape::LowShelf, 200.0, 9.0, FRAC_1_SQRT_2); assert!(band_db(&steep, 100.0, FS) > band_db(&gentle, 100.0, FS), "steeper shelves reach full gain sooner"); } @@ -599,7 +600,7 @@ mod tests { let n = Band::new(Shape::Notch, 1000.0, 0.0, 2.0); assert!(band_db(&n, 1000.0, FS) < -100.0); assert!(band_db(&n, 100.0, FS).abs() < 0.1); - let mut d = Band::new(Shape::DualLow, 60.0, 8.0, 0.7071); + let mut d = Band::new(Shape::DualLow, 60.0, 8.0, FRAC_1_SQRT_2); d.low_atten_db = 6.0; let deep = band_db(&d, 20.0, FS); assert!(deep < 8.0 && deep > 0.0, "boost minus cut at the bottom ({deep})"); @@ -612,9 +613,9 @@ mod tests { let wide = band_db(&b, 1500.0, FS); b.prop_q = true; assert!(band_db(&b, 1500.0, FS) < wide, "proportional Q narrows a strong bell"); - let mut s = Band::new(Shape::LowShelf, 100.0, 6.0, 0.7071); + let mut s = Band::new(Shape::LowShelf, 100.0, 6.0, FRAC_1_SQRT_2); s.overshoot = 1.0; - assert!(band_db(&s, 160.0, FS) < band_db(&Band::new(Shape::LowShelf, 100.0, 6.0, 0.7071), 160.0, FS)); + assert!(band_db(&s, 160.0, FS) < band_db(&Band::new(Shape::LowShelf, 100.0, 6.0, FRAC_1_SQRT_2), 160.0, FS)); assert_eq!(sections(&s, FS).len(), 2); } @@ -623,12 +624,12 @@ mod tests { /// if these change, the panel and the engine drift apart. #[test] fn engine_contract_points() { - let mut a = Band::new(Shape::LowShelf, 200.0, 9.0, 0.7071); + let mut a = Band::new(Shape::LowShelf, 200.0, 9.0, FRAC_1_SQRT_2); a.slope_db = 18.0; a.overshoot = 0.5; let mut b = Band::new(Shape::HighPass, 1000.0, 0.0, 2.0); b.slope_db = 36.0; - let mut c = Band::new(Shape::DualLow, 60.0, 8.0, 0.7071); + let mut c = Band::new(Shape::DualLow, 60.0, 8.0, FRAC_1_SQRT_2); c.low_atten_db = 6.0; let mut d = Band::new(Shape::Bell, 2500.0, -7.5, 1.3); d.prop_q = true; @@ -658,7 +659,7 @@ mod tests { #[test] fn auto_gain_cancels_the_average() { - let s = sections(&Band::new(Shape::HighShelf, 1000.0, 12.0, 0.7071), FS); + let s = sections(&Band::new(Shape::HighShelf, 1000.0, 12.0, FRAC_1_SQRT_2), FS); let g = auto_gain_db(&s, FS); assert!(g < -3.0 && g > -12.0, "{g}"); assert_eq!(auto_gain_db(&[], FS), 0.0); diff --git a/crates/dstudio-core/src/builtin/soft_clipper.rs b/crates/dstudio-core/src/builtin/soft_clipper.rs index d4363b61..69dfe409 100644 --- a/crates/dstudio-core/src/builtin/soft_clipper.rs +++ b/crates/dstudio-core/src/builtin/soft_clipper.rs @@ -83,6 +83,7 @@ pub fn clip_curve(shape: u32, u: f32, s: f32) -> f32 { } /// Drawn transfer: (x (1 - mix) + c clip(x a / c) m mix) o. +#[allow(clippy::too_many_arguments, reason = "one argument per device parameter, in panel order")] pub fn clipper_transfer( x: f32, input_db: f32, diff --git a/crates/dstudio-core/src/command.rs b/crates/dstudio-core/src/command.rs index d886425e..05617035 100644 --- a/crates/dstudio-core/src/command.rs +++ b/crates/dstudio-core/src/command.rs @@ -66,6 +66,7 @@ pub const MAX_BPM: f64 = 999.0; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[serde(tag = "op", rename_all = "snake_case")] +#[allow(clippy::large_enum_variant, reason = "built once per edit, never on the audio path; boxing `Track` would touch every caller")] pub enum Command { /// Insert a track. If `track.id` is 0 a fresh id is allocated. AddTrack { @@ -693,7 +694,7 @@ impl Command { } else { p.next_id = p.next_id.max(asset.id.0 + 1); } - if !(asset.sample_rate > 0.0) || asset.channels == 0 { + if asset.sample_rate.is_nan() || asset.sample_rate <= 0.0 || asset.channels == 0 { return Err(invalid("asset", "sample_rate and channels must be positive")); } let id = asset.id; diff --git a/crates/dstudio-core/src/history.rs b/crates/dstudio-core/src/history.rs index 009810f8..8f827462 100644 --- a/crates/dstudio-core/src/history.rs +++ b/crates/dstudio-core/src/history.rs @@ -268,21 +268,6 @@ pub fn sentence_case(label: &str) -> String { .join(" ") } -#[cfg(test)] -mod sentence_case_tests { - #[test] - fn labels_read_in_sentence_case() { - use super::sentence_case; - assert_eq!(sentence_case("Track Volume Change"), "Track volume change"); - assert_eq!(sentence_case("Insert MIDI Clip"), "Insert MIDI clip"); - assert_eq!(sentence_case("Move Effect into Chain"), "Move effect into chain"); - assert_eq!(sentence_case("Use Built-in Synth"), "Use built-in synth"); - assert_eq!(sentence_case("Mute"), "Mute"); - assert_eq!(sentence_case("Convert MIDI-to-Audio"), "Convert MIDI-to-audio"); - assert_eq!(sentence_case("Re-Pitch Clip"), "Re-pitch clip"); - } -} - /// Replace zero ids with freshly allocated ones, recursively. pub fn assign_ids(cmd: &mut Command, p: &mut Project) { use crate::model::{AssetId, ClipId, TrackId}; @@ -306,3 +291,18 @@ pub fn assign_ids(cmd: &mut Command, p: &mut Project) { _ => {} } } + +#[cfg(test)] +mod sentence_case_tests { + #[test] + fn labels_read_in_sentence_case() { + use super::sentence_case; + assert_eq!(sentence_case("Track Volume Change"), "Track volume change"); + assert_eq!(sentence_case("Insert MIDI Clip"), "Insert MIDI clip"); + assert_eq!(sentence_case("Move Effect into Chain"), "Move effect into chain"); + assert_eq!(sentence_case("Use Built-in Synth"), "Use built-in synth"); + assert_eq!(sentence_case("Mute"), "Mute"); + assert_eq!(sentence_case("Convert MIDI-to-Audio"), "Convert MIDI-to-audio"); + assert_eq!(sentence_case("Re-Pitch Clip"), "Re-pitch clip"); + } +} diff --git a/crates/dstudio-core/src/midi.rs b/crates/dstudio-core/src/midi.rs index 63f28cd1..d65fe6a6 100644 --- a/crates/dstudio-core/src/midi.rs +++ b/crates/dstudio-core/src/midi.rs @@ -76,6 +76,10 @@ impl ClipLoop { self.end - self.start } + pub fn is_empty(&self) -> bool { + self.end <= self.start + } + /// The shortest loop: below the finest grid step (1/48), so every snapped range fits, /// and long enough that unrolling stays small. pub const MIN_LEN: Ticks = crate::PPQ / 16; @@ -291,11 +295,10 @@ pub fn legato(notes: &[Note], clip_length: Ticks) -> Vec { /// Duplicate the clip's content after itself. Returns (notes, new clip length). pub fn double(notes: &[Note], clip_length: Ticks) -> (Vec, Ticks) { - let mut next_id = notes.iter().map(|n| n.id + 1).max().unwrap_or(1); + let first_id = notes.iter().map(|n| n.id + 1).max().unwrap_or(1); let mut out = notes.to_vec(); - for n in notes.iter().filter(|n| n.start < clip_length) { - out.push(Note { id: next_id, start: n.start + clip_length, ..*n }); - next_id += 1; + for (id, n) in (first_id..).zip(notes.iter().filter(|n| n.start < clip_length)) { + out.push(Note { id, start: n.start + clip_length, ..*n }); } (out, clip_length * 2) } diff --git a/crates/dstudio-core/src/midi_record.rs b/crates/dstudio-core/src/midi_record.rs index 3ea0d725..c8235e8b 100644 --- a/crates/dstudio-core/src/midi_record.rs +++ b/crates/dstudio-core/src/midi_record.rs @@ -263,7 +263,7 @@ mod tests { assert_eq!(t.midi_clips.len(), before + 1); let c = t.midi_clips.iter().find(|c| c.notes.len() == 1 && c.notes[0].start == PPQ).unwrap(); assert_eq!(c.length, 8 * PPQ); - assert_eq!(doc.undo_label().as_deref(), Some("Record")); + assert_eq!(doc.undo_label(), Some("Record")); assert!(doc.undo().unwrap()); assert_eq!(doc.project().track(inst).unwrap().midi_clips.len(), before); } diff --git a/crates/dstudio-core/src/model.rs b/crates/dstudio-core/src/model.rs index b0143cee..783da6da 100644 --- a/crates/dstudio-core/src/model.rs +++ b/crates/dstudio-core/src/model.rs @@ -357,8 +357,7 @@ pub fn return_letter(index: usize) -> char { impl Project { pub fn empty(name: &str) -> Self { - let mut p = Project::default(); - p.name = name.into(); + let mut p = Project { name: name.into(), ..Default::default() }; p.tracks.clear(); p } diff --git a/crates/dstudio-core/src/scale.rs b/crates/dstudio-core/src/scale.rs index 2e4c885b..485d3c26 100644 --- a/crates/dstudio-core/src/scale.rs +++ b/crates/dstudio-core/src/scale.rs @@ -133,8 +133,8 @@ impl ClipScale { /// pitches of any notes outside the scale. pub fn fold_rows(key: ScaleKey, note_pitches: impl IntoIterator) -> Vec { let mut show = [false; 128]; - for p in 0..128 { - show[p] = key.contains(p as i32); + for (p, shown) in show.iter_mut().enumerate() { + *shown = key.contains(p as i32); } for p in note_pitches { show[p as usize & 127] = true; diff --git a/crates/dstudio-core/src/shape.rs b/crates/dstudio-core/src/shape.rs index 547628ef..31d8a733 100644 --- a/crates/dstudio-core/src/shape.rs +++ b/crates/dstudio-core/src/shape.rs @@ -766,13 +766,13 @@ fn arpeggiate(v: &[Note], shape: &Shape) -> Vec { } "Thumb" => { let j = k % (2 * (m - 1)).max(1); - vec![if m < 2 || j % 2 == 0 { pool[0] } else { pool[1 + j / 2] }] + vec![if m < 2 || j.is_multiple_of(2) { pool[0] } else { pool[1 + j / 2] }] } "Pinky" => { let j = k % (2 * (m - 1)).max(1); vec![if m < 2 { pool[0] - } else if j % 2 == 0 { + } else if j.is_multiple_of(2) { pool[j / 2] } else { pool[m - 1] diff --git a/crates/dstudio-core/src/steps.rs b/crates/dstudio-core/src/steps.rs index 02784921..12d065b2 100644 --- a/crates/dstudio-core/src/steps.rs +++ b/crates/dstudio-core/src/steps.rs @@ -283,10 +283,10 @@ impl StepPattern { return Err(format!("cell {}:{} {} {v} outside {}..={}", c.key, c.step, s.label, s.min, s.max)); } } - if let Some(p) = i.checked_sub(1).map(|j| &self.cells[j]) { - if (p.key, p.step) >= (c.key, c.step) { - return Err(format!("cells not sorted or duplicated at {}:{}", c.key, c.step)); - } + if let Some(p) = i.checked_sub(1).map(|j| &self.cells[j]) + && (p.key, p.step) >= (c.key, c.step) + { + return Err(format!("cells not sorted or duplicated at {}:{}", c.key, c.step)); } } Ok(()) @@ -830,10 +830,12 @@ mod tests { }; let (mut rows, mut bad) = (0, 0); for _ in 0..5000 { - let mut p = StepPattern::default(); - p.rate = StepRate::ALL[rnd(9) as usize]; - p.steps = STEP_COUNTS[rnd(8) as usize]; - p.swing = rnd(5) as f32 / 4.0; + let mut p = StepPattern { + rate: StepRate::ALL[rnd(9) as usize], + steps: STEP_COUNTS[rnd(8) as usize], + swing: rnd(5) as f32 / 4.0, + ..Default::default() + }; for _ in 0..rnd(40) { let (k, st) = (pad(rnd(16) as u8), rnd(p.steps as u32) as u16); if p.cell(k, st).is_some() { diff --git a/crates/dstudio-core/tests/midi.rs b/crates/dstudio-core/tests/midi.rs index 7e70340e..14655d11 100644 --- a/crates/dstudio-core/tests/midi.rs +++ b/crates/dstudio-core/tests/midi.rs @@ -106,8 +106,7 @@ fn snapshot_emits_notes_in_frames_cut_at_clip_end() { #[test] fn v1_project_files_without_midi_still_load() { let dir = tempfile::tempdir().unwrap(); - let mut p = Project::default(); - p.name = "Old".into(); + let p = Project { name: "Old".into(), ..Default::default() }; persist::save(&p, dir.path()).unwrap(); // Strip the midi_clips field to simulate a file written before MIDI existed. let path = dir.path().join("project.json"); diff --git a/crates/dstudio-core/tests/warp.rs b/crates/dstudio-core/tests/warp.rs index 78594f0b..3de7e936 100644 --- a/crates/dstudio-core/tests/warp.rs +++ b/crates/dstudio-core/tests/warp.rs @@ -453,7 +453,7 @@ fn looped_clip_snapshot_carries_its_loop_in_content_frames() { let l = AudioLoop { on: true, start: 2 * PPQ, end: 4 * PPQ, length: 16 * PPQ }; d.execute(Command::SetClipLoop { clip: c, clip_loop: Some(l) }, Origin::User).unwrap(); assert_eq!(d.project().clip_length_ticks(d.project().clip(c).unwrap()), 16 * PPQ); - assert_eq!(d.undo_label().as_deref(), Some("Clip Loop")); + assert_eq!(d.undo_label(), Some("Clip Loop")); let (s, _) = snapshot::build(d.project(), RATE, &HashMap::from([(a, 7)])); let cs = &s.tracks[0].clips[0]; assert_eq!((cs.length, cs.clip_loop), (8 * 48_000, Some((48_000, 2 * 48_000)))); From 897657212c0af73a13963db0f031af32bc473e7a Mon Sep 17 00:00:00 2001 From: Chris Laupama <42254688+chrislaupama@users.noreply.github.com> Date: Thu, 12 Nov 2026 02:41:56 +0000 Subject: [PATCH 2/4] Make dstudio-engine clippy clean --- crates/dstudio-engine/src/lib.rs | 6 +++--- crates/dstudio-engine/tests/automation.rs | 4 ++-- crates/dstudio-engine/tests/warp.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/dstudio-engine/src/lib.rs b/crates/dstudio-engine/src/lib.rs index 6da03a6d..6b75352c 100644 --- a/crates/dstudio-engine/src/lib.rs +++ b/crates/dstudio-engine/src/lib.rs @@ -922,8 +922,8 @@ pub struct DeviceStatus { pub buffer_size: u32, pub input_channels: u32, pub output_channels: u32, - /// Input-side latency in engine frames (device + safety offset + stream - /// + one buffer). Recorded takes are compensated by + /// Input-side latency in engine frames (device, safety offset, stream + /// and one buffer). Recorded takes are compensated by /// `input_latency_frames + output_latency_frames`. pub input_latency_frames: u32, pub output_latency_frames: u32, @@ -1040,7 +1040,7 @@ impl Engine { /// .input_name` is `None`, [`Engine::input_error`] says why, and a /// running restart returns `SE_ERR_DEVICE` with that message. pub fn configure_device(&self, cfg: &DeviceConfig) -> Result<(), EngineError> { - let out = cfg.output.as_deref().map(|s| CString::new(s)).transpose().map_err(|_| nul_error())?; + let out = cfg.output.as_deref().map(CString::new).transpose().map_err(|_| nul_error())?; let input_enabled = cfg.input.is_some(); let inp = cfg.input.as_deref().filter(|s| !s.is_empty()).map(CString::new).transpose().map_err(|_| nul_error())?; let c = ffi::se_device_config { diff --git a/crates/dstudio-engine/tests/automation.rs b/crates/dstudio-engine/tests/automation.rs index faad4155..8a363d0f 100644 --- a/crates/dstudio-engine/tests/automation.rs +++ b/crates/dstudio-engine/tests/automation.rs @@ -31,14 +31,14 @@ fn random_lane(rng: &mut Rng, target: AutomationTarget) -> AutomationLane { let mut points = Vec::new(); for i in 0..n { // Vertical steps (equal times) now and then, including at the first point. - if i > 0 && rng.next() % 4 != 0 { + if i > 0 && !rng.next().is_multiple_of(4) { t += 1 + (rng.next() % 5000) as i64; } let curve = match rng.next() % 4 { 0 => 0.0, 1 => 1.0 - 2.0 * rng.unit(), 2 => { - if rng.next() % 2 == 0 { + if rng.next().is_multiple_of(2) { 1.0 } else { -1.0 diff --git a/crates/dstudio-engine/tests/warp.rs b/crates/dstudio-engine/tests/warp.rs index 1354c175..74fbeb68 100644 --- a/crates/dstudio-engine/tests/warp.rs +++ b/crates/dstudio-engine/tests/warp.rs @@ -50,7 +50,7 @@ impl Rig { let engine = Engine::new(Config { sample_rate: RATE, max_block_size: 512 }).unwrap(); let mut doc = Document::new(Project::default()); let info = engine.load_file(path).unwrap(); - let frames = info.frames as u64; + let frames = info.frames; doc.execute( Command::AddAsset { asset: Asset { From 60999219ebac60fc83f3f95ddeceb9ba4536acb5 Mon Sep 17 00:00:00 2001 From: Chris Laupama <42254688+chrislaupama@users.noreply.github.com> Date: Thu, 12 Nov 2026 02:57:39 +0000 Subject: [PATCH 3/4] Make dstudio-app clippy clean Fixes the clippy findings in the app crate. too_many_arguments and type_complexity are allowed crate-wide (drawing and layout code passes geometry and state as plain arguments), and one negated float comparison in live_import.rs stays as is because it must reject NaN. --- crates/dstudio-app/src/controller.rs | 2 +- crates/dstudio-app/src/device_canvas.rs | 2 +- crates/dstudio-app/src/device_fields.rs | 2 +- crates/dstudio-app/src/device_mod.rs | 78 +++++++++---------- crates/dstudio-app/src/device_panel.rs | 91 +++++++++++------------ crates/dstudio-app/src/devminimap.rs | 2 +- crates/dstudio-app/src/dialogs.rs | 2 +- crates/dstudio-app/src/files.rs | 10 +-- crates/dstudio-app/src/gain_scope.rs | 4 +- crates/dstudio-app/src/live_import.rs | 1 + crates/dstudio-app/src/main.rs | 15 ++-- crates/dstudio-app/src/minimap.rs | 2 +- crates/dstudio-app/src/panel_fields.rs | 6 +- crates/dstudio-app/src/panel_graph.rs | 4 +- crates/dstudio-app/src/panel_multiband.rs | 3 +- crates/dstudio-app/src/pianoroll.rs | 9 +-- crates/dstudio-app/src/sampler_panel.rs | 8 +- crates/dstudio-app/src/selftest.rs | 41 +++++----- crates/dstudio-app/src/splitters.rs | 2 +- crates/dstudio-app/src/stepseq.rs | 6 +- crates/dstudio-app/src/synth.rs | 12 +-- crates/dstudio-app/src/timeline.rs | 11 ++- 22 files changed, 153 insertions(+), 160 deletions(-) diff --git a/crates/dstudio-app/src/controller.rs b/crates/dstudio-app/src/controller.rs index b08d7f16..a7e27bd2 100644 --- a/crates/dstudio-app/src/controller.rs +++ b/crates/dstudio-app/src/controller.rs @@ -996,7 +996,7 @@ impl Controller { // Applied immediately when no device runs (engine ABI), else at the next block. if self.engine.seek(frame).is_ok() { self.paused = false; - self.cue = Some(frame as i64); + self.cue = Some(frame); } } diff --git a/crates/dstudio-app/src/device_canvas.rs b/crates/dstudio-app/src/device_canvas.rs index 7120b141..838d0da1 100644 --- a/crates/dstudio-app/src/device_canvas.rs +++ b/crates/dstudio-app/src/device_canvas.rs @@ -534,7 +534,7 @@ impl Controller { on_param: idx(band.on), on: v.band_on(sel, &val), latch_x: latch_x * Z, - bank_param: v.bank.map_or(-1, |b| idx(b)), + bank_param: v.bank.map_or(-1, &idx), bank_value: s(v.bank.and_then(|b| def.param(b).map(|p| p.format(val(b)))).unwrap_or_default()), bank_x: (width - PAD - bank_w) * Z, bank_w: bank_w * Z, diff --git a/crates/dstudio-app/src/device_fields.rs b/crates/dstudio-app/src/device_fields.rs index c8794bce..81a016f4 100644 --- a/crates/dstudio-app/src/device_fields.rs +++ b/crates/dstudio-app/src/device_fields.rs @@ -545,7 +545,7 @@ fn character_mod(i: &Input) -> Plot { SINGLE if mode == 1 => (4.0, 2.2, 0.0), SINGLE => (6.5, 3.0, 0.0), TWIN => (3.55, if mode == 2 { 0.35 } else { 1.85 }, 0.0), - CROSSED => CROSSED_MODES[(mode as usize).min(3)], + CROSSED => CROSSED_MODES[mode.min(3)], _ => (0.0, 0.0, 0.0), }; let roff = if circuit == FLANGER { 0.25 * w } else { 0.5 * w }; diff --git a/crates/dstudio-app/src/device_mod.rs b/crates/dstudio-app/src/device_mod.rs index 49f8bb9d..18c5be66 100644 --- a/crates/dstudio-app/src/device_mod.rs +++ b/crates/dstudio-app/src/device_mod.rs @@ -1277,34 +1277,6 @@ impl Controller { } } -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn wave_paths_span_the_box() { - let (line, fill) = wave_paths(0, 0.0, 1.0, 100.0, 50.0); - assert!(line.starts_with("M0.0 25.0"), "{line}"); - assert!(fill.ends_with('Z')); - // Square at depth 0 still draws a visible line around the middle. - let (flat, _) = wave_paths(4, 0.0, 0.0, 100.0, 50.0); - assert!(flat.starts_with("M0.0 24.1"), "{flat}"); - } - - /// Model cost of an LFO picture per refresh - /// (`cargo test -p dstudio-app --release bench_lfo_wave -- --ignored --nocapture`). - #[test] - #[ignore] - fn bench_lfo_wave() { - let n = 5000; - let t0 = std::time::Instant::now(); - for i in 0..n { - std::hint::black_box(wave_paths(i % 7, 0.25, 0.8, 160.0, 128.0)); - } - println!("lfo picture: {:.2} us per refresh", t0.elapsed().as_secs_f64() * 1e6 / n as f64); - } -} - /// The accent needs dark ink on it: its relative luminance is above 0.3, where /// white text on it falls under 3:1 contrast (switch thumb, selected segments). pub fn is_light(c: slint::Color) -> bool { @@ -1324,25 +1296,53 @@ pub fn accent_text(c: slint::Color) -> slint::Color { if v <= 0.04045 { v / 12.92 } else { ((v + 0.055) / 1.055).powf(2.4) } }; let (r, g, b) = (lin(c.red()), lin(c.green()), lin(c.blue())); - let l = (0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b).cbrt(); - let m = (0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b).cbrt(); - let s = (0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b).cbrt(); - let a = 1.9779984951 * l - 2.4285922050 * m + 0.4505937099 * s; - let bb = 0.0259040371 * l + 0.7827717662 * m - 0.8086757660 * s; + let l = (0.412_221_46 * r + 0.536_332_55 * g + 0.051_445_995 * b).cbrt(); + let m = (0.211_903_5 * r + 0.680_699_5 * g + 0.107_396_96 * b).cbrt(); + let s = (0.088_302_46 * r + 0.281_718_85 * g + 0.629_978_7 * b).cbrt(); + let a = 1.977_998_5 * l - 2.428_592_2 * m + 0.450_593_7 * s; + let bb = 0.025_904_037 * l + 0.782_771_77 * m - 0.808_675_77 * s; let chroma = a.hypot(bb).min(0.11); let hue = bb.atan2(a); let (a, bb, ll) = (chroma * hue.cos(), chroma * hue.sin(), 0.87f32); - let l = (ll + 0.3963377774 * a + 0.2158037573 * bb).powi(3); - let m = (ll - 0.1055613458 * a - 0.0638541728 * bb).powi(3); - let s = (ll - 0.0894841775 * a - 1.2914855480 * bb).powi(3); + let l = (ll + 0.396_337_78 * a + 0.215_803_76 * bb).powi(3); + let m = (ll - 0.105_561_346 * a - 0.063_854_17 * bb).powi(3); + let s = (ll - 0.089_484_18 * a - 1.291_485_5 * bb).powi(3); let gamma = |v: f32| { let v = v.clamp(0.0, 1.0); let v = if v <= 0.0031308 { v * 12.92 } else { 1.055 * v.powf(1.0 / 2.4) - 0.055 }; (v * 255.0).round() as u8 }; slint::Color::from_rgb_u8( - gamma(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s), - gamma(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s), - gamma(-0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s), + gamma(4.076_741_7 * l - 3.307_711_6 * m + 0.230_969_94 * s), + gamma(-1.268_438 * l + 2.609_757_4 * m - 0.341_319_38 * s), + gamma(-0.0041960863 * l - 0.703_418_6 * m + 1.707_614_7 * s), ) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn wave_paths_span_the_box() { + let (line, fill) = wave_paths(0, 0.0, 1.0, 100.0, 50.0); + assert!(line.starts_with("M0.0 25.0"), "{line}"); + assert!(fill.ends_with('Z')); + // Square at depth 0 still draws a visible line around the middle. + let (flat, _) = wave_paths(4, 0.0, 0.0, 100.0, 50.0); + assert!(flat.starts_with("M0.0 24.1"), "{flat}"); + } + + /// Model cost of an LFO picture per refresh + /// (`cargo test -p dstudio-app --release bench_lfo_wave -- --ignored --nocapture`). + #[test] + #[ignore] + fn bench_lfo_wave() { + let n = 5000; + let t0 = std::time::Instant::now(); + for i in 0..n { + std::hint::black_box(wave_paths(i % 7, 0.25, 0.8, 160.0, 128.0)); + } + println!("lfo picture: {:.2} us per refresh", t0.elapsed().as_secs_f64() * 1e6 / n as f64); + } +} diff --git a/crates/dstudio-app/src/device_panel.rs b/crates/dstudio-app/src/device_panel.rs index e1b1ac20..3927d760 100644 --- a/crates/dstudio-app/src/device_panel.rs +++ b/crates/dstudio-app/src/device_panel.rs @@ -530,7 +530,7 @@ fn strip_paths(slots: &VecDeque<(f32, f32, f32)>, strip: Strip, w: f32, wh: f32) // Curves through every 3 pt or so (the newest point always kept): denser cubic traces cost // render time without a visible difference. let step = ((3.0 * Z) / (w / (HISTORY - 1) as f32)).ceil().max(1.0) as usize; - let kept = |i: usize| (n - 1 - i) % step == 0 || i == 0; + let kept = |i: usize| (n - 1 - i).is_multiple_of(step) || i == 0; let input: Vec<(f32, f32)> = slots.iter().enumerate().filter(|(i, _)| kept(*i)).map(|(i, s)| (x_of(i), y_of(s.0))).collect(); let output: Vec<(f32, f32)> = slots.iter().enumerate().filter(|(i, _)| kept(*i)).map(|(i, s)| (x_of(i), y_of(s.1))).collect(); let audible = |v: &[(f32, f32)]| v.iter().any(|p| p.1 < wh - 0.5); @@ -1060,7 +1060,6 @@ impl Controller { second_label: s(q.map_or("", |q| q.label)), second_value: s(q.map(|q| q.format(second)).unwrap_or_default()), second_rate: q.map_or(0.0, |q| span / wh / (q.max - q.min)), - ..Default::default() } } @@ -1680,11 +1679,9 @@ impl Controller { let _ = self.engine.builtin_set_param(device.0, i as u32, p.max); self.ui_dirty = true; } - 2 => { - if self.devices.panel.held.take().is_some() { - let _ = self.engine.builtin_set_param(device.0, i as u32, p.min); - self.ui_dirty = true; - } + 2 if self.devices.panel.held.take().is_some() => { + let _ = self.engine.builtin_set_param(device.0, i as u32, p.min); + self.ui_dirty = true; } _ => {} } @@ -1823,6 +1820,46 @@ impl Controller { } } +impl Controller { + /// A parameter menu row: Bank re-snaps the EQ bands; a type menu that + /// shares a mode switch also leaves the mode (Auto Filter: DJ -> Filter). + pub(crate) fn panel_pick_param(&mut self, device: DeviceId, param: usize, value: f32) { + let Some((d, def)) = self.panel_def(device) else { return }; + let Some(p) = def.params.get(param) else { return }; + if let Some(View::Eq(v)) = def.layout.view + && v.bank == Some(p.id) + { + return self.panel_pick_bank(device, param, value); + } + let mode = def.layout.picker.iter().find_map(|c| match c { + Control::ModeDropdown { param: q, mode } if *q == p.id => def.param(mode), + _ => None, + }); + let mut commands = vec![Command::SetDeviceParam { device, param: p.id.into(), value }]; + if let Some(m) = mode.filter(|m| def.value(d, m) >= 0.5) { + commands.push(Command::SetDeviceParam { device, param: m.id.into(), value: 0.0 }); + } else if def.value(d, p) == value { + return; + } + self.panel_commit(Command::Batch { label: "Device Parameter Change".into(), commands }); + } + + /// The mode entry of a type menu: switches the mode on. Entering Auto + /// Filter's DJ mode with no resonance gives it a little, so the sweep is audible. + pub(crate) fn panel_pick_mode(&mut self, device: DeviceId, mode: usize) { + let Some((d, def)) = self.panel_def(device) else { return }; + let Some(m) = def.params.get(mode) else { return }; + if def.value(d, m) >= 0.5 { + return; + } + let mut commands = vec![Command::SetDeviceParam { device, param: m.id.into(), value: 1.0 }]; + if let Some(r) = def.param("resonance").filter(|r| def.value(d, r) <= 0.0) { + commands.push(Command::SetDeviceParam { device, param: r.id.into(), value: DJ_RESONANCE }); + } + self.panel_commit(Command::Batch { label: "Device Parameter Change".into(), commands }); + } +} + #[cfg(test)] mod tests { use super::*; @@ -1994,43 +2031,3 @@ mod tests { assert_eq!(fmt_db(-3.26), "\u{2212}3.3 dB"); } } - -impl Controller { - /// A parameter menu row: Bank re-snaps the EQ bands; a type menu that - /// shares a mode switch also leaves the mode (Auto Filter: DJ -> Filter). - pub(crate) fn panel_pick_param(&mut self, device: DeviceId, param: usize, value: f32) { - let Some((d, def)) = self.panel_def(device) else { return }; - let Some(p) = def.params.get(param) else { return }; - if let Some(View::Eq(v)) = def.layout.view - && v.bank == Some(p.id) - { - return self.panel_pick_bank(device, param, value); - } - let mode = def.layout.picker.iter().find_map(|c| match c { - Control::ModeDropdown { param: q, mode } if *q == p.id => def.param(mode), - _ => None, - }); - let mut commands = vec![Command::SetDeviceParam { device, param: p.id.into(), value }]; - if let Some(m) = mode.filter(|m| def.value(d, m) >= 0.5) { - commands.push(Command::SetDeviceParam { device, param: m.id.into(), value: 0.0 }); - } else if def.value(d, p) == value { - return; - } - self.panel_commit(Command::Batch { label: "Device Parameter Change".into(), commands }); - } - - /// The mode entry of a type menu: switches the mode on. Entering Auto - /// Filter's DJ mode with no resonance gives it a little, so the sweep is audible. - pub(crate) fn panel_pick_mode(&mut self, device: DeviceId, mode: usize) { - let Some((d, def)) = self.panel_def(device) else { return }; - let Some(m) = def.params.get(mode) else { return }; - if def.value(d, m) >= 0.5 { - return; - } - let mut commands = vec![Command::SetDeviceParam { device, param: m.id.into(), value: 1.0 }]; - if let Some(r) = def.param("resonance").filter(|r| def.value(d, r) <= 0.0) { - commands.push(Command::SetDeviceParam { device, param: r.id.into(), value: DJ_RESONANCE }); - } - self.panel_commit(Command::Batch { label: "Device Parameter Change".into(), commands }); - } -} diff --git a/crates/dstudio-app/src/devminimap.rs b/crates/dstudio-app/src/devminimap.rs index e7be59f6..8941d4c3 100644 --- a/crates/dstudio-app/src/devminimap.rs +++ b/crates/dstudio-app/src/devminimap.rs @@ -872,7 +872,7 @@ mod tests { let (base, acc) = art.paths(); assert!(base.starts_with('M') && acc.starts_with('M'), "{art:?}"); assert!(base.ends_with('Z') && acc.ends_with('Z'), "{art:?}"); - assert_eq!(base.matches('M').count() >= 1, true); + assert!(base.matches('M').count() >= 1); } let (_, none) = Art { view: true, sliders: 0, knobs: 0 }.paths(); assert_eq!(none.matches('M').count(), 1, "only the title dot is accent without dials"); diff --git a/crates/dstudio-app/src/dialogs.rs b/crates/dstudio-app/src/dialogs.rs index 50ed6f47..d4f83ec1 100644 --- a/crates/dstudio-app/src/dialogs.rs +++ b/crates/dstudio-app/src/dialogs.rs @@ -588,7 +588,7 @@ impl Controller { live_set::validate(&xml, Some(folder)).map_err(|e| format!("the Live set failed its structure check: {e}"))?; let als = folder.join(format!("{name}.als")); let bytes = live_set::gzip(&xml).map_err(|e| e.to_string())?; - std::fs::create_dir_all(&folder).map_err(|e| e.to_string())?; + std::fs::create_dir_all(folder).map_err(|e| e.to_string())?; std::fs::write(&als, bytes).map_err(|e| e.to_string())?; let _ = writeln!(notes, "Exported from Device Studio for Ableton Live 11 or later.\n"); if rendered.is_empty() { diff --git a/crates/dstudio-app/src/files.rs b/crates/dstudio-app/src/files.rs index e6383701..d9aefec0 100644 --- a/crates/dstudio-app/src/files.rs +++ b/crates/dstudio-app/src/files.rs @@ -417,7 +417,7 @@ impl Builder<'_> { fn top_items(ui: &FilesUi, folders: &[String]) -> Vec<(FileItem, String)> { let mut top: Vec<(FileItem, String)> = if ui.tab == TAB_PROJECTS { let mut ps = ui.projects.clone(); - ps.sort_by(|a, b| b.1.cmp(&a.1)); + ps.sort_by_key(|p| std::cmp::Reverse(p.1)); ps.into_iter() .map(|(p, _)| { let name = p.file_stem().map(|s| s.to_string_lossy().into_owned()).unwrap_or_default(); @@ -563,11 +563,9 @@ impl Controller { if let FileItem::Audio(p) = &item { self.audition(p.clone()); } - if matches!(item, FileItem::Folder(_)) || (chevron && item.expandable()) { - if !self.files.expanded.remove(&key) { - self.files.expanded.insert(key); - self.files_load(&item); - } + if (matches!(item, FileItem::Folder(_)) || (chevron && item.expandable())) && !self.files.expanded.remove(&key) { + self.files.expanded.insert(key); + self.files_load(&item); } self.ui_dirty = true; } diff --git a/crates/dstudio-app/src/gain_scope.rs b/crates/dstudio-app/src/gain_scope.rs index d0bafd6d..8987015b 100644 --- a/crates/dstudio-app/src/gain_scope.rs +++ b/crates/dstudio-app/src/gain_scope.rs @@ -275,8 +275,8 @@ mod tests { h.head = 256.0; let px = h.pixels(300.0, 2.0); assert_eq!(px.out.len(), 301); - assert!(px.out.iter().any(|&o| o == 0.9)); - assert!(px.pre.iter().any(|&p| p == 1.2)); + assert!(px.out.contains(&0.9)); + assert!(px.pre.contains(&1.2)); assert!(px.gain.iter().any(|&g| g == -6.0)); assert_eq!(px.out[0], 0.0); } diff --git a/crates/dstudio-app/src/live_import.rs b/crates/dstudio-app/src/live_import.rs index 4832b17b..4b658b28 100644 --- a/crates/dstudio-app/src/live_import.rs +++ b/crates/dstudio-app/src/live_import.rs @@ -248,6 +248,7 @@ fn span(c: roxmltree::Node) -> Result { loop_end: number(c, "Loop/LoopEnd")?, start_relative: number(c, "Loop/StartRelative").unwrap_or(0.0), }; + #[allow(clippy::neg_cmp_op_on_partial_ord, reason = "NaN bounds must be rejected too")] if !(s.end > s.start) || !(s.loop_end > s.loop_start || !s.loop_on) { return Err(format!("clip {} has an empty span", c.attribute("Id").unwrap_or("?"))); } diff --git a/crates/dstudio-app/src/main.rs b/crates/dstudio-app/src/main.rs index 4f5527df..77368490 100644 --- a/crates/dstudio-app/src/main.rs +++ b/crates/dstudio-app/src/main.rs @@ -20,6 +20,11 @@ //! [--card-accent (device cards in that colour, e.g. white as on the Master track)] //! ``` +// Drawing and layout code passes geometry, colours and state as plain arguments and keeps +// per-widget closures and tuples inline; splitting those into structs and type aliases +// would add names without making the code clearer. +#![allow(clippy::too_many_arguments, clippy::type_complexity)] + static CLIP_MENU_AUDIO: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); /// With `review-clip-bounce-menu`: the audio clip menu opens with its Bounce submenu showing. static CLIP_MENU_BOUNCE: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); @@ -2172,10 +2177,10 @@ fn run() -> Result<(), Box> { // Typing in a name field only records the draft: no model push per keystroke. let ctl2 = ctl.clone(); studio.on_track_rename_draft(move |id, t, epoch| { - if let Ok(mut c) = ctl2.try_borrow_mut() { - if epoch == c.doc_epoch as i32 { - c.rename_draft = Some((TrackId(id as u64), t.to_string())); - } + if let Ok(mut c) = ctl2.try_borrow_mut() + && epoch == c.doc_epoch as i32 + { + c.rename_draft = Some((TrackId(id as u64), t.to_string())); } }); let ctl2 = ctl.clone(); @@ -3281,7 +3286,7 @@ fn run() -> Result<(), Box> { } ms.sort_by(f64::total_cmp); let mean = ms.iter().sum::() / n as f64; - let median = if n % 2 == 0 { (ms[n / 2 - 1] + ms[n / 2]) / 2.0 } else { ms[n / 2] }; + let median = if n.is_multiple_of(2) { (ms[n / 2 - 1] + ms[n / 2]) / 2.0 } else { ms[n / 2] }; println!( "{{\"renders\":{n},\"mean_ms\":{mean:.3},\"median_ms\":{median:.3},\"p95_ms\":{:.3},\"update_ui_mean_ms\":{:.3}}}", ms[(n * 95 / 100).min(n - 1)], diff --git a/crates/dstudio-app/src/minimap.rs b/crates/dstudio-app/src/minimap.rs index 281d6b8f..ab363a87 100644 --- a/crates/dstudio-app/src/minimap.rs +++ b/crates/dstudio-app/src/minimap.rs @@ -116,7 +116,7 @@ pub fn bars(tracks: &[TrackInfo], clips: &[ClipVis], map_end: f64) -> Vec { return Vec::new(); } let row = (HEIGHT - 2.0 * PAD) / tracks.len() as f32; - let h = (row * BAND_FILL).min(BAND_MAX).max(1.0); + let h = (row * BAND_FILL).clamp(1.0, BAND_MAX); clips .iter() .filter_map(|c| { diff --git a/crates/dstudio-app/src/panel_fields.rs b/crates/dstudio-app/src/panel_fields.rs index 45ab5f82..7aaa6a2c 100644 --- a/crates/dstudio-app/src/panel_fields.rs +++ b/crates/dstudio-app/src/panel_fields.rs @@ -1667,9 +1667,9 @@ mod tests { #[test] fn biquad_magnitudes() { assert!((biquad_db(2, 1000.0, 1.0, 6.0, 1000.0) - 6.0).abs() < 0.05); - assert!((biquad_db(0, 1000.0, 0.7071, 0.0, 1000.0) + 3.01).abs() < 0.1); - assert!(biquad_db(4, 1000.0, 0.7071, 0.0, 100.0).abs() < 0.05); - assert!((biquad_db(1, 200.0, 0.7071, -12.0, 20.0) + 12.0).abs() < 0.3); + assert!((biquad_db(0, 1000.0, std::f32::consts::FRAC_1_SQRT_2, 0.0, 1000.0) + 3.01).abs() < 0.1); + assert!(biquad_db(4, 1000.0, std::f32::consts::FRAC_1_SQRT_2, 0.0, 100.0).abs() < 0.05); + assert!((biquad_db(1, 200.0, std::f32::consts::FRAC_1_SQRT_2, -12.0, 20.0) + 12.0).abs() < 0.3); } #[test] diff --git a/crates/dstudio-app/src/panel_graph.rs b/crates/dstudio-app/src/panel_graph.rs index 6f3047a9..64e9a5f7 100644 --- a/crates/dstudio-app/src/panel_graph.rs +++ b/crates/dstudio-app/src/panel_graph.rs @@ -943,7 +943,7 @@ fn spectrum_points(shown: &[f32; BANDS], g: &Geo) -> Vec<(f32, f32)> { let band_hz = |i: usize| BAND_LO_HZ * (BAND_HI_HZ / BAND_LO_HZ).powf(i as f32 / (BANDS - 1) as f32); let y = |db: f32| g.y0 + (-db / SPEC_SCALE_DB).clamp(0.0, 1.0) * (g.y1 - g.y0); let mut pts = Vec::new(); - for i in 0..BANDS { + for (i, &level) in sm.iter().enumerate() { let f = band_hz(i); let prev = if i > 0 { band_hz(i - 1) } else { 0.0 }; let next = if i + 1 < BANDS { band_hz(i + 1) } else { f32::MAX }; @@ -951,7 +951,7 @@ fn spectrum_points(shown: &[f32; BANDS], g: &Geo) -> Vec<(f32, f32)> { if next < g.lo || prev > g.hi { continue; } - pts.push((g.x_of(f).clamp(g.x0, g.x1), y(sm[i]))); + pts.push((g.x_of(f).clamp(g.x0, g.x1), y(level))); } pts } diff --git a/crates/dstudio-app/src/panel_multiband.rs b/crates/dstudio-app/src/panel_multiband.rs index f4b37aaa..b3f9cadb 100644 --- a/crates/dstudio-app/src/panel_multiband.rs +++ b/crates/dstudio-app/src/panel_multiband.rs @@ -340,8 +340,7 @@ mod tests { #[test] fn meters_rise_fast_and_fall_slowly() { - let mut st = ViewState::default(); - st.last = Some(Instant::now() - std::time::Duration::from_millis(30)); + let mut st = ViewState { last: Some(Instant::now() - std::time::Duration::from_millis(30)), ..Default::default() }; assert!(st.poll(&[0.0, 0.0, -10.0, -100.0, -100.0, -6.0, 0.0, 0.0])); assert!(st.level[0] > -50.0, "one time constant up: {}", st.level[0]); assert!(st.gain[0] < -3.0); diff --git a/crates/dstudio-app/src/pianoroll.rs b/crates/dstudio-app/src/pianoroll.rs index 095bce85..2a5fb050 100644 --- a/crates/dstudio-app/src/pianoroll.rs +++ b/crates/dstudio-app/src/pianoroll.rs @@ -443,7 +443,7 @@ const BLACK: [f32; 3] = [0.0, 0.0, 0.0]; /// beat is not a multiple of twice the step) until its lines are 16 px (at 100% zoom) apart. `None` /// when that reaches a beat, then only beat and bar lines remain. pub fn sub_step(grid_beats: f64, beat_len: f64, ppb_ref: f64) -> Option { - if !(grid_beats > 0.0) { + if grid_beats.is_nan() || grid_beats <= 0.0 { return None; } let mut r = grid_beats; @@ -800,10 +800,9 @@ fn paint_velocity(notes: &mut [Note], ids: &BTreeSet, v: &PrView, a: f32, b /// Renumber `extra` notes so their ids don't collide with `existing`. fn renumber(existing: &[Note], extra: &mut [Note]) { - let mut next = existing.iter().map(|n| n.id + 1).max().unwrap_or(1); - for n in extra { - n.id = next; - next += 1; + let first = existing.iter().map(|n| n.id + 1).max().unwrap_or(1); + for (n, id) in extra.iter_mut().zip(first..) { + n.id = id; } } diff --git a/crates/dstudio-app/src/sampler_panel.rs b/crates/dstudio-app/src/sampler_panel.rs index a23732ae..47326c01 100644 --- a/crates/dstudio-app/src/sampler_panel.rs +++ b/crates/dstudio-app/src/sampler_panel.rs @@ -1479,12 +1479,8 @@ mod tests { assert_eq!(starts, [0.0, 0.25, 0.5, 0.75]); // Two hits in silence. let mut pairs = vec![[0.0f32, 0.0f32]; 3000]; - for i in 1000..1100 { - pairs[i] = [-0.8, 0.8]; - } - for i in 2000..2100 { - pairs[i] = [-0.6, 0.6]; - } + pairs[1000..1100].fill([-0.8, 0.8]); + pairs[2000..2100].fill([-0.6, 0.6]); let s = chop(&pairs, 32.0, 48_000.0, 96_000, true, 2, 50.0, 120.0); assert_eq!(s.len(), 3, "{s:?}"); assert!((s[1].start - 1000.0 * 32.0 / 96_000.0).abs() < 1e-3); diff --git a/crates/dstudio-app/src/selftest.rs b/crates/dstudio-app/src/selftest.rs index 4adcd43a..0b3dfeef 100644 --- a/crates/dstudio-app/src/selftest.rs +++ b/crates/dstudio-app/src/selftest.rs @@ -525,7 +525,6 @@ fn midi_steps() -> Vec { Box::new(|c, _| { let label = c.doc.undo_label(); label - .as_deref() .is_some_and(|l| l.starts_with("Smart Quantize") || l.starts_with("Quantize Notes")) .then_some(()) .ok_or(format!("last {label:?}")) @@ -779,9 +778,7 @@ fn midi_steps() -> Vec { before.iter().map(|n| dstudio_core::Note { start: lo + hi - n.start - n.length, ..*n }).collect(); let mut got = notes_of(c); got.sort_by_key(|n| n.id); - (got == want && c.doc.undo_label().as_deref() == Some("Reverse Notes")) - .then_some(()) - .ok_or(format!("{got:?} want {want:?}")) + (got == want && c.doc.undo_label() == Some("Reverse Notes")).then_some(()).ok_or(format!("{got:?} want {want:?}")) }), ), Do("Cmd+Z", Box::new(|a| key(a, "z", true, false))), @@ -1118,7 +1115,7 @@ fn midi_steps() -> Vec { (key.root == 5 && key.kind == 0 && !scale.highlight - && c.doc.undo_label().as_deref() == Some("Clip Scale") + && c.doc.undo_label() == Some("Clip Scale") && s.get_pr_scale_root() == "Eb" && s.get_pr_scale_type() == "Major") .then_some(()) @@ -1188,7 +1185,7 @@ fn midi_steps() -> Vec { "Space toggled Loop off (and played nothing)", Box::new(|c, _| { let l = instrument_clip(c).and_then(|m| m.clip_loop).ok_or("no loop")?; - (!l.on && !c.engine.transport().playing && c.doc.undo_label().as_deref() == Some("Clip Loop")) + (!l.on && !c.engine.transport().playing && c.doc.undo_label() == Some("Clip Loop")) .then_some(()) .ok_or(format!("{l:?} playing {}", c.engine.transport().playing)) }), @@ -1204,7 +1201,7 @@ fn midi_steps() -> Vec { "Down picked the next root (C#), one \"Clip Scale\" step", Box::new(|c, a| { let k = instrument_clip(c).and_then(|m| m.scale).and_then(|s| s.key).ok_or("no key")?; - (k.root == 1 && a.global::().get_pr_scale_root() == "C#" && c.doc.undo_label().as_deref() == Some("Clip Scale")) + (k.root == 1 && a.global::().get_pr_scale_root() == "C#" && c.doc.undo_label() == Some("Clip Scale")) .then_some(()) .ok_or(format!("{k:?}")) }), @@ -1291,9 +1288,11 @@ fn midi_steps() -> Vec { Box::new(|c, _| { let m = instrument_clip(c).ok_or("clip gone")?; let l = m.clip_loop.ok_or("no loop")?; - (l.on && l.start == 0 && l.end == m.length - PPQ && c.doc.undo_label().as_deref() == Some("Clip Loop")) - .then_some(()) - .ok_or(format!("{l:?} len {} {:?}", m.length, c.doc.undo_label())) + (l.on && l.start == 0 && l.end == m.length - PPQ && c.doc.undo_label() == Some("Clip Loop")).then_some(()).ok_or(format!( + "{l:?} len {} {:?}", + m.length, + c.doc.undo_label() + )) }), ), Do("click the footer Loop switch (off)", Box::new(|a| click(a, pr_origin().0 + 202.0 + 10.0, bottom_end() - 54.5 + 13.0 + 7.0))), @@ -3047,7 +3046,7 @@ fn steps() -> Vec { && l.end == content && l.length == content && c.project().clip_length_ticks(clip) == content - && c.doc.undo_label().as_deref() == Some("Clip Loop") + && c.doc.undo_label() == Some("Clip Loop") && a.global::().get_pr_loop_on()) .then_some(()) .ok_or(format!("{l:?} content {content} {:?}", c.doc.undo_label())) @@ -3089,7 +3088,7 @@ fn steps() -> Vec { && l.start == content / 4 && (l.end - content * 3 / 4).abs() <= g && (l.end % g == 0 || l.end == content) - && c.doc.undo_label().as_deref() == Some("Clip Loop")) + && c.doc.undo_label() == Some("Clip Loop")) .then_some(()) .ok_or(format!("{l:?} content {content}")) }), @@ -3146,7 +3145,7 @@ fn steps() -> Vec { let tpb = c.project().ticks_per_bar(); (l.start == want && a.global::().get_pr_position_text() == crate::pianoroll::fmt_pos(want, tpb) - && c.doc.undo_label().as_deref() == Some("Clip Loop")) + && c.doc.undo_label() == Some("Clip Loop")) .then_some(()) .ok_or(format!("{l:?} want start {want} content {content}")) }), @@ -3198,7 +3197,7 @@ fn steps() -> Vec { let tpb = c.project().ticks_per_bar(); let ok = (len - 2 * content).abs() <= PPQ / 2 && clip.clip_loop.is_some_and(|l| l.on && l.length == len) - && c.doc.undo_label().as_deref() == Some("Clip Loop") + && c.doc.undo_label() == Some("Clip Loop") && (c.clip_vis[i].len_beats - len as f64 / PPQ as f64).abs() < 1e-6 && (last - len as f64 / PPQ as f64).abs() < 1e-6 && segs.len() > 2 @@ -3471,7 +3470,7 @@ fn steps() -> Vec { Box::new(|c, _| { let ppb = c.view.px_per_beat; let anchor = c.view.beat_at(446.35); - let expected = 4.0 + 446.35 as f64 / crate::timeline::DEFAULT_PX_PER_BEAT; + let expected = 4.0 + 446.35_f64 / crate::timeline::DEFAULT_PX_PER_BEAT; ((ppb - crate::timeline::DEFAULT_PX_PER_BEAT).abs() > 1.0 && (anchor - expected).abs() < 0.05) .then_some(()) .ok_or(format!("ppb {ppb} anchor {anchor} vs {expected}")) @@ -6794,7 +6793,7 @@ fn limiter_family_steps() -> Vec { } c.update_ui(a); } - let mut out = vec![DoC("dynamics: select the audio track and clear its chain", Box::new(|a, ctl| clear_audio_chain(a, ctl)))]; + let mut out = vec![DoC("dynamics: select the audio track and clear its chain", Box::new(clear_audio_chain))]; for id in ["limiter", "gate", "glue-compressor", "transient-shaper", "mastering-limiter"] { let def = dstudio_core::builtin::find(id).expect("registered"); let name = def.name; @@ -6941,7 +6940,7 @@ fn limiter_family_steps() -> Vec { .ok_or(format!("history {} -> {n}, clip {:?}", u5.get(), param(c, "transient-shaper", "clip"))) }), )); - out.push(DoC("dynamics: remove the section's devices", Box::new(|a, ctl| clear_audio_chain(a, ctl)))); + out.push(DoC("dynamics: remove the section's devices", Box::new(clear_audio_chain))); out.push(Check( "dynamics: the audio track's chain is empty again", Box::new(|c, _| { @@ -8480,7 +8479,7 @@ fn modulation_device_steps() -> Vec { c.engine.builtin_readouts(d.id.0, &mut r).map_err(|e| e.to_string())?; let errors = c.engine.plugin_load_errors(); let ok = cd.field.visible - && cd.field.main != "" + && !cd.field.main.is_empty() && slint::Model::row_count(&cd.knobs) == knobs && approx(cd.width, def.layout.width() * crate::device_panel::Z, 0.01) && r.len() == 1 @@ -8894,7 +8893,7 @@ fn field_device_steps() -> Vec { Box::new(|a, _| { let Some(cd) = card_named(a, "Auto Filter") else { return }; let Some(dot) = - (0..slint::Model::row_count(&cd.canvas.dots)).filter_map(|i| slint::Model::row_data(&cd.canvas.dots, i)).last() + (0..slint::Model::row_count(&cd.canvas.dots)).filter_map(|i| slint::Model::row_data(&cd.canvas.dots, i)).next_back() else { return; }; @@ -9102,7 +9101,7 @@ fn step_sequencer_steps() -> Vec { let p = seq_clip(c).and_then(|m| m.pattern).ok_or("no pattern")?; let v = p.cell(36, 0).map(|x| x.velocity).unwrap_or(0); let nv = seq_clip(c).and_then(|m| m.notes.iter().find(|n| n.start == 0 && n.pitch == 36).map(|n| n.velocity)).unwrap_or(0); - (a.global::().get_seq_lane() == 1 && v < 60 && v >= 1 && nv == v) + (a.global::().get_seq_lane() == 1 && (1..60).contains(&v) && nv == v) .then_some(()) .ok_or(format!("lane {} velocity {v} note {nv}", a.global::().get_seq_lane())) }), @@ -10920,7 +10919,7 @@ fn devminimap_steps() -> Vec { (!c.devmm_animating() && dim == 0).then_some(()).ok_or(format!("animating {} dim tiles {dim}", c.devmm_animating())) }), ), - DoC("devices minimap: remove the effects again", Box::new(|a, ctl| clear(a, ctl))), + DoC("devices minimap: remove the effects again", Box::new(clear)), Check( "the chain is empty again and the strip is hidden", Box::new(|c, a| { diff --git a/crates/dstudio-app/src/splitters.rs b/crates/dstudio-app/src/splitters.rs index 1b46b098..c747fb95 100644 --- a/crates/dstudio-app/src/splitters.rs +++ b/crates/dstudio-app/src/splitters.rs @@ -48,7 +48,7 @@ pub fn chat_width(saved: f32, win_w: f32, sounds: bool) -> f32 { /// Widest a splitter drag can make the chat right now. pub fn chat_drag_max(win_w: f32, sounds: bool) -> f32 { - chat_room(win_w, sounds).min(CHAT_MAX_W).max(CHAT_MIN_W) + chat_room(win_w, sounds).clamp(CHAT_MIN_W, CHAT_MAX_W) } /// Whether the header hides its zoom sliders (mirrors `zoom-hidden` in ui/app.slint). diff --git a/crates/dstudio-app/src/stepseq.rs b/crates/dstudio-app/src/stepseq.rs index fc70ed0f..b09b1939 100644 --- a/crates/dstudio-app/src/stepseq.rs +++ b/crates/dstudio-app/src/stepseq.rs @@ -107,7 +107,7 @@ impl SeqGeom { let cols = steps_per_page(width); let pages = page_count(width, steps); let page = page.min(pages - 1); - let pitch = ((width - COL_X0 - 8.0) / cols as f32).min(COL_PITCH).max(6.0); + let pitch = ((width - COL_X0 - 8.0) / cols as f32).clamp(6.0, COL_PITCH); let rows = match rows { StepRows::Pads => drum_rack::PADS as u16, StepRows::Pitches => 128, @@ -278,7 +278,7 @@ pub fn build_view( let steps_per_beat = p.rate.steps_per_beat(); let every = if g.pitch >= 18.0 { 1 } else { steps_per_beat.round().max(1.0) as u16 }; let nums = (0..g.cols) - .filter(|col| (g.first + col) % every == 0) + .filter(|col| (g.first + col).is_multiple_of(every)) .map(|col| { let s = g.first + col; NumView { x: g.col_x(col), text: format!("{}", s + 1), beat: is_beat(p.rate, s), active: s < p.steps } @@ -476,7 +476,7 @@ impl Controller { 0 => { self.pr.focused = true; let Some((key, step)) = hit else { return }; - if x >= MUTE_X && x < SOLO_X + BTN_W && step.is_none() { + if (MUTE_X..SOLO_X + BTN_W).contains(&x) && step.is_none() { let solo = x >= SOLO_X; if x < MUTE_X + BTN_W || solo { self.pr.seq.drag = Some(SeqDrag::Flag); diff --git a/crates/dstudio-app/src/synth.rs b/crates/dstudio-app/src/synth.rs index f3424e1b..7d2dea95 100644 --- a/crates/dstudio-app/src/synth.rs +++ b/crates/dstudio-app/src/synth.rs @@ -2940,10 +2940,10 @@ impl Controller { sync_model(&m.maps, g.maps); } self.synth.pushed = Some(key); - } else if let Some(labels) = self.synth_pictures_changed(&v, bpm) { - if let Some(m) = &self.synth.models { - sync_model(&m.labels, labels); - } + } else if let Some(labels) = self.synth_pictures_changed(&v, bpm) + && let Some(m) = &self.synth.models + { + sync_model(&m.labels, labels); } s.set_synth_enabled(enabled); // The shared card header (and the folded strip) read the Synth as a device card. @@ -3227,7 +3227,7 @@ mod tests { fn bench_synth_panel() { let v = defaults(); let n = 300; - for p in 0..PAGES.len() { + for (p, page) in PAGES.iter().enumerate() { let t0 = std::time::Instant::now(); for _ in 0..n { std::hint::black_box(displays(&v, 120.0, p, 1)); @@ -3237,7 +3237,7 @@ mod tests { for _ in 0..n { std::hint::black_box(layout(&ctx(&v), p, 1, 0)); } - println!("{:<12} pictures {pics:8.1} us layout {:6.1} us", PAGES[p], t0.elapsed().as_secs_f64() * 1e6 / n as f64); + println!("{:<12} pictures {pics:8.1} us layout {:6.1} us", page, t0.elapsed().as_secs_f64() * 1e6 / n as f64); } } diff --git a/crates/dstudio-app/src/timeline.rs b/crates/dstudio-app/src/timeline.rs index d7f3b5fe..f52902e8 100644 --- a/crates/dstudio-app/src/timeline.rs +++ b/crates/dstudio-app/src/timeline.rs @@ -202,12 +202,11 @@ impl RulerSteps { .map(|i| cand[i]) .find(|&c| c * px_per_beat >= if c >= beats_per_bar - EPS { GRID_BAR_MIN_PX } else { GRID_MIN_PX }) .unwrap_or(cand[n - 1]); - if let Some(g) = grid { - if let Some(fixed) = Self::fixed_step(g, beats_per_bar, px_per_beat) { - if g.is_triplet() || fixed < tick_beats { - tick_beats = fixed; - } - } + if let Some(g) = grid + && let Some(fixed) = Self::fixed_step(g, beats_per_bar, px_per_beat) + && (g.is_triplet() || fixed < tick_beats) + { + tick_beats = fixed; } let line_beats = if tick_beats < beats_per_bar - EPS { tick_beats } else { tick_beats.max(tick_bars as f64 * beats_per_bar) }; From f0b68375a6d7ec8982fd3bce6ad775a8326ee8e8 Mon Sep 17 00:00:00 2001 From: Chris Laupama <42254688+chrislaupama@users.noreply.github.com> Date: Thu, 12 Nov 2026 02:58:10 +0000 Subject: [PATCH 4/4] Check Rust formatting and clippy in CI lint runs cargo fmt --all --check and tests (Linux) runs clippy over every target with warnings as errors, both on a pinned toolchain (RUST_LINT_TOOLCHAIN) so a new stable Rust can't turn CI red overnight. --- .agents/skills/dstudio-pr/SKILL.md | 2 +- .agents/skills/spec-verify/SKILL.md | 2 +- .github/workflows/ci.yml | 18 +++++++++++++++++- AGENTS.md | 2 +- CONTRIBUTING.md | 2 +- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/.agents/skills/dstudio-pr/SKILL.md b/.agents/skills/dstudio-pr/SKILL.md index d7fae577..dd6316f5 100644 --- a/.agents/skills/dstudio-pr/SKILL.md +++ b/.agents/skills/dstudio-pr/SKILL.md @@ -15,7 +15,7 @@ One change per pull request, on a branch from the latest `main`. Spec-driven wor ## 2. The local gate ```sh -cargo fmt --all --check && cargo clippy --workspace +cargo fmt --all --check && cargo clippy --workspace --all-targets -- -D warnings cargo test --workspace cd engine && cmake --preset default && cmake --build --preset default && ctest --preset default cargo run --release -p dstudio-app -- --self-test --no-audio diff --git a/.agents/skills/spec-verify/SKILL.md b/.agents/skills/spec-verify/SKILL.md index e94259d2..e3ee333c 100644 --- a/.agents/skills/spec-verify/SKILL.md +++ b/.agents/skills/spec-verify/SKILL.md @@ -24,7 +24,7 @@ through a `Command` with a working undo; old projects still load; ABI layout tes ## 3. The full local gate ```sh -cargo fmt --all --check && cargo clippy --workspace +cargo fmt --all --check && cargo clippy --workspace --all-targets -- -D warnings cargo test --workspace cd engine && cmake --preset default && cmake --build --preset default && ctest --preset default cargo run --release -p dstudio-app -- --self-test --no-audio diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b08189ec..a0026014 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ concurrency: # and ctest, then `cargo test` over the workspace (debug); # app () the app's release build and its smoke tests (a # screenshot and the scripted self-test). -# plus `lint` (workflow and script checks, seconds). The required checks are +# plus `lint` (workflow, script and Rust formatting checks, seconds). The required checks are # `build-test (macOS)`, `build-test (Windows)` and `build-test (Linux)`: each # passes only when lint and every tests and app job passed, so one failure # turns all three red (the failing job is named in the check list). @@ -62,6 +62,8 @@ env: CCACHE_BASEDIR: ${{ github.workspace }} CCACHE_NOHASHDIR: "true" CCACHE_MAXSIZE: 1G + # Toolchain for `cargo fmt --check` and clippy (builds and tests use stable). + RUST_LINT_TOOLCHAIN: "1.97.0" HOMEBREW_NO_AUTO_UPDATE: "1" HOMEBREW_NO_INSTALL_CLEANUP: "1" @@ -90,6 +92,13 @@ jobs: run: tools/ci/test-changes.sh - name: Agent skills run: python3 tools/agents/check_skills.py + # Formatting is checked with a pinned toolchain (RUST_LINT_TOOLCHAIN, + # also used for clippy in `tests (Linux)`), so a new stable Rust cannot + # turn the job red overnight. Raise the pin by hand, in its own change. + - name: Rust formatting (cargo fmt --check) + run: | + rustup toolchain install "$RUST_LINT_TOOLCHAIN" --profile minimal --component rustfmt --no-self-update + cargo "+$RUST_LINT_TOOLCHAIN" fmt --all --check tests: name: tests (${{ matrix.name }}) @@ -258,6 +267,13 @@ jobs: - name: Rust workspace — test if: steps.changes.outputs.rust == 'true' && !cancelled() run: cargo test --workspace --locked --no-fail-fast + # Clippy over every target with warnings as errors, on Linux only (the + # lints are the same on every system) and with the pinned lint toolchain. + - name: Rust workspace — clippy (Linux) + if: runner.os == 'Linux' && steps.changes.outputs.rust == 'true' && !cancelled() + run: | + rustup toolchain install "$RUST_LINT_TOOLCHAIN" --profile minimal --component clippy --no-self-update + cargo "+$RUST_LINT_TOOLCHAIN" clippy --workspace --all-targets --locked -- -D warnings - name: ccache statistics if: steps.changes.outputs.run == 'true' && !cancelled() run: ccache --show-stats diff --git a/AGENTS.md b/AGENTS.md index 62bcbb36..de0dd87a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -56,7 +56,7 @@ path a skill names still exists, so skills don't silently rot as the code moves. ## Before any pull request ```sh -cargo fmt --all && cargo clippy --workspace +cargo fmt --all && cargo clippy --workspace --all-targets -- -D warnings cargo test --workspace cd engine && cmake --preset default && cmake --build --preset default && ctest --preset default cargo run --release -p dstudio-app -- --self-test --no-audio diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 72863b2c..c3b6017a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -59,7 +59,7 @@ clang, MSVC and GCC, so please build on more than one compiler if you can, or ch ## Code style -- Rust: `cargo fmt` and `cargo clippy --workspace`. +- Rust: `cargo fmt --all` (settings in `rustfmt.toml`) and `cargo clippy --workspace --all-targets -- -D warnings`. CI checks both. - C++: C++23, follow the style of the surrounding code, no exceptions or allocation on the audio thread. - Internal names use `dstudio` (crates, namespaces, `DSTUDIO_*` options). Do not use bare `device` as an identifier prefix: it already names effects and instruments throughout the code.