From 97fd942aa0d578f6ca3152d77f2f9154ddb6055b Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Tue, 16 Jun 2026 10:42:18 -0600 Subject: [PATCH] =?UTF-8?q?fix(slint):=20HiFi=20wizard=20test=20step=20?= =?UTF-8?q?=E2=80=94=20audio,=20bit-perfect=20read-back,=20track=20jump,?= =?UTF-8?q?=20UX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes from owner testing of the Slice 9 playback test: - No audio: removed the incomplete reinit_device(node) that routed output to the selected DAC (the proper switch is set_output_device -> reload_settings -> reinit; doing it half-way broke playback). The test now plays through the current output; route QBZ to the DAC under test in Settings > Audio. - Bit-perfect read-back: dropped the pw-top panel (batch snapshot never reflected the live nodes) and enriched the N6 read-back to show the DAC's real /proc/asound hw_params — rate + ALSA container format (S32_LE etc.) + channels. That container format is the bit-perfect proof. Probe scans for the actively playing card, so it's DAC-agnostic (answers the multi-DAC case: one output at a time). - Track jump: clicking a test row now re-sets the queue at that index via the working play_tracks path (play_index alone only moved the pointer). Resolved tracks are stashed for this. - "Use my own music" button: starts the read-back + resumes the user's own queue for those who don't want the curated tracks. - Row hover no longer changes the row height (fixed-size glyph slot; the ♪->▶ swap can't reflow what's below). cc --- crates/qbz-audio/src/dac_probe.rs | 16 +++++ crates/qbz-audio/src/lib.rs | 2 +- crates/qbz-slint/src/dac_wizard.rs | 53 ++++++--------- crates/qbz-slint/src/main.rs | 46 +++++++++++-- .../ui/primitives/DacWizardModal.slint | 65 ++++++++++++++----- crates/qbz-slint/ui/state.slint | 2 + 6 files changed, 129 insertions(+), 55 deletions(-) diff --git a/crates/qbz-audio/src/dac_probe.rs b/crates/qbz-audio/src/dac_probe.rs index ecb3b7df4..7d6f2fc1e 100644 --- a/crates/qbz-audio/src/dac_probe.rs +++ b/crates/qbz-audio/src/dac_probe.rs @@ -125,6 +125,22 @@ pub fn negotiated_stream_rate(node_name: &str) -> Option { read_hw_params_for_card(card) } +/// The negotiated rate of whichever ALSA card is ACTIVELY playing right now. +/// +/// Scans every card's playback substream and returns the first one that is +/// open (not `closed`). This is DAC-agnostic — it reports the rate of whatever +/// QBZ is currently outputting to, so it works no matter which (or how many) +/// DACs the user selected; you can only play through one output at a time. +/// `None` = nothing is playing. Read-only; safe to poll. +pub fn negotiated_active_rate() -> Option { + for card in 0..16 { + if let Some(nr) = read_hw_params_for_card(card) { + return Some(nr); + } + } + None +} + #[cfg(test)] mod tests { use super::*; diff --git a/crates/qbz-audio/src/lib.rs b/crates/qbz-audio/src/lib.rs index 3c3cc3eb4..0cda5e3c8 100644 --- a/crates/qbz-audio/src/lib.rs +++ b/crates/qbz-audio/src/lib.rs @@ -73,7 +73,7 @@ pub use backend::{ }; pub use coreaudio_direct::CoreAudioExclusiveGuard; pub use dac_capabilities::{query_dac_capabilities, DacCapabilities}; -pub use dac_probe::{negotiated_stream_rate, NegotiatedRate}; +pub use dac_probe::{negotiated_active_rate, negotiated_stream_rate, NegotiatedRate}; pub use health::{ audio_stack_health, detect_distro, detect_init, detect_sandbox, AudioStackHealth, Distro, InitSystem, Sandbox, diff --git a/crates/qbz-slint/src/dac_wizard.rs b/crates/qbz-slint/src/dac_wizard.rs index 6a465552e..1d85e6a8e 100644 --- a/crates/qbz-slint/src/dac_wizard.rs +++ b/crates/qbz-slint/src/dac_wizard.rs @@ -479,9 +479,6 @@ pub const TEST_SEEDS: [TestSeed; 4] = [ TestSeed { depth: 24, rate: 192000.0, id_hint: 52265, artist: "Toto", title: "Africa" }, ]; -/// The DAC node.name the test is currently watching (N6 probe target). -static TEST_NODE: Mutex> = Mutex::new(None); - /// True if a resolved track matches this seed's family (rate + bit depth — the /// two 44.1 seeds only differ by depth). pub fn track_matches_seed(track: &qbz_models::Track, seed: &TestSeed) -> bool { @@ -493,29 +490,21 @@ pub fn track_matches_seed(track: &qbz_models::Track, seed: &TestSeed) -> bool { rate_ok && depth_ok } -/// The node.name of the first checked candidate (the DAC being configured), or -/// the manual node.name from the escape hatch. -pub fn first_selected_node(window: &AppWindow) -> Option { - let st = window.global::(); - let model = st.get_candidates(); - for i in 0..model.row_count() { - if let Some(r) = model.row_data(i) { - if r.checked { - return Some(r.id.to_string()); - } - } - } - let manual = st.get_manual_node_name().to_string(); - if !manual.trim().is_empty() && st.get_manual_valid() { - Some(manual) - } else { - None - } +/// Resolved test tracks, kept so the user can jump straight to any of them +/// (re-set the queue at the chosen index via the working play path). +static TEST_TRACKS: Mutex> = Mutex::new(Vec::new()); + +pub fn stash_test_tracks(tracks: Vec) { + *TEST_TRACKS.lock().unwrap() = tracks; } -/// Start the test: stash the watched node + show the "playing" state. -pub fn begin_test(window: &AppWindow, node: Option) { - *TEST_NODE.lock().unwrap() = node; +pub fn test_tracks() -> Vec { + TEST_TRACKS.lock().unwrap().clone() +} + +/// Start the test: show the "playing" state. The read-back probes whichever +/// DAC is actively playing (scan), so no node needs to be stashed. +pub fn begin_test(window: &AppWindow) { let st = window.global::(); st.set_test_playing(true); st.set_test_rate_matched(false); @@ -527,11 +516,6 @@ pub fn end_test(window: &AppWindow) { window.global::().set_test_playing(false); } -/// The node the poll loop should probe (read on a worker thread). -pub fn test_node() -> Option { - TEST_NODE.lock().unwrap().clone() -} - /// Apply one poll: the rate QBZ requested vs the DAC's real negotiated rate (N6). pub fn apply_poll( window: &AppWindow, @@ -552,12 +536,17 @@ pub fn apply_poll( }); match negotiated { Some(n) => { - st.set_test_negotiated_label(format!("DAC running at {}", khz(n.sample_rate)).into()); - // Truth signal (N6): the DAC's real clock matches what QBZ asked for. + // The DAC's REAL hardware params (N6): rate + ALSA container format + // (e.g. S32_LE = 24-bit in a 32-bit frame) + channels. This is the + // bit-perfect proof — exactly what the hardware is clocked at. + st.set_test_negotiated_label( + format!("DAC: {} · {} · {} ch", khz(n.sample_rate), n.format, n.channels).into(), + ); + // Truth signal: the DAC's real clock matches what QBZ asked for. st.set_test_rate_matched(requested_rate > 0 && n.sample_rate == requested_rate); } None => { - st.set_test_negotiated_label("DAC idle — set QBZ output to this DAC".into()); + st.set_test_negotiated_label("Waiting for the DAC to start playing…".into()); st.set_test_rate_matched(false); } } diff --git a/crates/qbz-slint/src/main.rs b/crates/qbz-slint/src/main.rs index 378323b04..06c9ca0b7 100644 --- a/crates/qbz-slint/src/main.rs +++ b/crates/qbz-slint/src/main.rs @@ -11393,8 +11393,7 @@ fn main() -> Result<(), Box> { let Some(w) = weak.upgrade() else { return; }; - let node = dac_wizard::first_selected_node(&w); - dac_wizard::begin_test(&w, node.clone()); + dac_wizard::begin_test(&w); let runtime = runtime.clone(); let weak2 = w.as_weak(); let play_handle = handle.clone(); @@ -11418,9 +11417,8 @@ fn main() -> Result<(), Box> { tracks.push(t); } } - if let Some(n) = node.clone() { - let _ = runtime.core().player().reinit_device(Some(n)); - } + // Keep the resolved tracks so the user can jump between them. + dac_wizard::stash_test_tracks(tracks.clone()); let runtime2 = runtime.clone(); let _ = weak2.upgrade_in_event_loop(move |w| { if tracks.is_empty() { @@ -11448,8 +11446,7 @@ fn main() -> Result<(), Box> { let player = runtime.core().player(); let req_rate = player.state.get_sample_rate(); let req_bits = player.state.get_bit_depth(); - let negotiated = dac_wizard::test_node() - .and_then(|n| qbz_audio::negotiated_stream_rate(&n)); + let negotiated = qbz_audio::negotiated_active_rate(); let _ = weak2.upgrade_in_event_loop(move |w| { dac_wizard::apply_poll(&w, req_rate, req_bits, negotiated); }); @@ -11466,6 +11463,41 @@ fn main() -> Result<(), Box> { } }); } + { + // Jump straight to one of the test tracks (skip the long waits) by + // re-setting the queue at that index via the working play path. + let runtime = app_runtime.clone(); + let weak = window.as_weak(); + let handle = tokio_rt.handle().clone(); + window + .global::() + .on_test_play_index(move |i| { + let tracks = dac_wizard::test_tracks(); + if tracks.is_empty() { + return; + } + let start = (i.max(0) as usize).min(tracks.len().saturating_sub(1)); + crate::playback::play_tracks( + runtime.clone(), + weak.clone(), + handle.clone(), + tracks, + start, + ); + }); + } + { + // "Use my own music": start the read-back without queuing the test + // tracks — the user plays whatever they want; the poll reads the rate. + let runtime = app_runtime.clone(); + let weak = window.as_weak(); + window.global::().on_verify_own(move || { + if let Some(w) = weak.upgrade() { + dac_wizard::begin_test(&w); + } + let _ = runtime.core().resume(); + }); + } { window .global::() diff --git a/crates/qbz-slint/ui/primitives/DacWizardModal.slint b/crates/qbz-slint/ui/primitives/DacWizardModal.slint index cd682931e..c220bf136 100644 --- a/crates/qbz-slint/ui/primitives/DacWizardModal.slint +++ b/crates/qbz-slint/ui/primitives/DacWizardModal.slint @@ -478,28 +478,55 @@ export component DacWizardModal inherits Rectangle { font-size: Typography.body; wrap: word-wrap; } - // The four tracks that will play. + // The four tracks — click one to jump straight to it + // while testing (no need to wait for each to finish). VerticalLayout { - spacing: 6px; - for line in root.test-tracks: HorizontalLayout { - spacing: 8px; - alignment: start; - Text { - text: "♪"; - color: Theme.text-muted; - font-size: Typography.legal; + spacing: 4px; + for line[idx] in root.test-tracks: Rectangle { + height: 26px; + border-radius: Radius.sm; + background: (trow.has-hover && DacWizardState.test-playing) + ? Theme.surface-hover : transparent; + HorizontalLayout { + padding-left: 6px; + padding-right: 6px; + spacing: 8px; + alignment: start; + // Fixed glyph slot (width + height) so the + // ♪→▶ hover swap can never reflow the row. + Text { + width: 14px; + height: 26px; + horizontal-alignment: center; + vertical-alignment: center; + text: (trow.has-hover && DacWizardState.test-playing) ? "▶" : "♪"; + color: (trow.has-hover && DacWizardState.test-playing) + ? Theme.accent : Theme.text-muted; + font-size: Typography.legal; + } + Text { + text: line; + color: Theme.text-secondary; + font-size: Typography.legal; + vertical-alignment: center; + overflow: elide; + horizontal-stretch: 1; + } } - Text { - text: line; - color: Theme.text-secondary; - font-size: Typography.legal; - overflow: elide; + trow := TouchArea { + mouse-cursor: DacWizardState.test-playing ? pointer : default; + clicked => { + if (DacWizardState.test-playing) { + DacWizardActions.test-play-index(idx); + } + } } } } - // Play / Stop. + // Play / Stop + the "use my own music" escape. HorizontalLayout { alignment: start; + spacing: 10px; QbzPrimaryButton { height: 34px; label: DacWizardState.test-playing ? @tr("Stop") : @tr("Play test"); @@ -511,6 +538,14 @@ export component DacWizardModal inherits Rectangle { } } } + // For users who'd rather verify with their own + // queue than the curated tracks. + if !DacWizardState.test-playing: SecondaryButton { + label: @tr("Use my own music"); + clicked => { + DacWizardActions.verify-own(); + } + } } // Live read-back: requested (honest) + DAC negotiated (N6). if DacWizardState.test-playing || DacWizardState.test-requested-label != "": Rectangle { diff --git a/crates/qbz-slint/ui/state.slint b/crates/qbz-slint/ui/state.slint index e4731cd3b..22e743043 100644 --- a/crates/qbz-slint/ui/state.slint +++ b/crates/qbz-slint/ui/state.slint @@ -3925,6 +3925,8 @@ export global DacWizardActions { callback toggle-dac(int); // flip one candidate's checked state callback validate-manual(string);// validate a pasted node.name (escape hatch) callback start-test(); // queue + play the 4 test tracks (Slice 9) + callback verify-own(); // start the read-back using the user's own music callback poll-test(); // refresh the requested-vs-negotiated read-back + callback test-play-index(int); // jump straight to one of the 4 test tracks callback stop-test(); }