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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .agents/skills/dstudio-pr/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .agents/skills/spec-verify/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Commits that only reformat code. GitHub's blame view skips them, and so does
# `git blame --ignore-revs-file .git-blame-ignore-revs`.

# Format the Rust workspace with rustfmt
8e5a7c536e2952b7b6819c6ec2435f0b6d0e0241
18 changes: 17 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ concurrency:
# and ctest, then `cargo test` over the workspace (debug);
# app (<system>) 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).
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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
- name: Engine pin checker (offline self-test)
run: tools/ci/engine_pins.py --self-test

Expand Down Expand Up @@ -260,6 +269,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
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion crates/dstudio-app/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/dstudio-app/src/device_canvas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/dstudio-app/src/device_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
78 changes: 39 additions & 39 deletions crates/dstudio-app/src/device_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
}
}
91 changes: 44 additions & 47 deletions crates/dstudio-app/src/device_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
}
}

Expand Down Expand Up @@ -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;
}
_ => {}
}
Expand Down Expand Up @@ -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::*;
Expand Down Expand Up @@ -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 });
}
}
2 changes: 1 addition & 1 deletion crates/dstudio-app/src/devminimap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion crates/dstudio-app/src/dialogs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
10 changes: 4 additions & 6 deletions crates/dstudio-app/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/dstudio-app/src/gain_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions crates/dstudio-app/src/live_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ fn span(c: roxmltree::Node) -> Result<Span, String> {
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("?")));
}
Expand Down
Loading
Loading