feat(visualizer): add stereo scopes
Add a theme-aware goniometer and pitch-locked oscilloscope to the large dock and immersive focus modes. Gate scope DSP and scenegraph updates by actual panel visibility so hidden modes remain idle, including while shader scenes cover immersive panels. cx
This commit is contained in:
26 files changed
+1009
-53
No files matched your search
@@ -12,10 +12,12 @@
|
|||||||
|
|
||||||
mod processor;
|
mod processor;
|
||||||
mod ring_buffer;
|
mod ring_buffer;
|
||||||
|
mod scope;
|
||||||
mod tapped_source;
|
mod tapped_source;
|
||||||
|
|
||||||
pub use processor::{spawn_visualizer_thread, VizFrame, VizSink};
|
pub use processor::{spawn_visualizer_thread, VizFrame, VizSink};
|
||||||
pub use ring_buffer::RingBuffer;
|
pub use ring_buffer::RingBuffer;
|
||||||
|
pub use scope::{GONIOMETER_BIT, OSCILLOSCOPE_BIT};
|
||||||
pub use tapped_source::TappedSource;
|
pub use tapped_source::TappedSource;
|
||||||
|
|
||||||
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
|
use std::sync::atomic::{AtomicBool, AtomicU32, Ordering};
|
||||||
@@ -47,6 +49,9 @@ pub struct VisualizerTap {
|
|||||||
pub paused: Arc<AtomicBool>,
|
pub paused: Arc<AtomicBool>,
|
||||||
/// Current sample rate
|
/// Current sample rate
|
||||||
pub sample_rate: Arc<AtomicU32>,
|
pub sample_rate: Arc<AtomicU32>,
|
||||||
|
/// Requested real-time scope producers. Frontends update this off the
|
||||||
|
/// audio thread; zero keeps the added DSP completely idle.
|
||||||
|
pub scope_mask: Arc<AtomicU32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VisualizerTap {
|
impl VisualizerTap {
|
||||||
@@ -57,6 +62,7 @@ impl VisualizerTap {
|
|||||||
enabled: Arc::new(AtomicBool::new(false)),
|
enabled: Arc::new(AtomicBool::new(false)),
|
||||||
paused: Arc::new(AtomicBool::new(false)),
|
paused: Arc::new(AtomicBool::new(false)),
|
||||||
sample_rate: Arc::new(AtomicU32::new(44100)),
|
sample_rate: Arc::new(AtomicU32::new(44100)),
|
||||||
|
scope_mask: Arc::new(AtomicU32::new(0)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,6 +103,11 @@ impl VisualizerTap {
|
|||||||
pub fn set_sample_rate(&self, rate: u32) {
|
pub fn set_sample_rate(&self, rate: u32) {
|
||||||
self.sample_rate.store(rate, Ordering::Relaxed);
|
self.sample_rate.store(rate, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Select the scope DSP that the visible frontend surfaces consume.
|
||||||
|
pub fn set_scope_mask(&self, mask: u32) {
|
||||||
|
self.scope_mask.store(mask, Ordering::Relaxed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for VisualizerTap {
|
impl Default for VisualizerTap {
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ use spectrum_analyzer::{samples_fft_to_spectrum, FrequencyLimit};
|
|||||||
|
|
||||||
use crate::SpectralAnalyzer;
|
use crate::SpectralAnalyzer;
|
||||||
|
|
||||||
|
use super::scope::{ScopeProcessor, GONIOMETER_BIT, OSCILLOSCOPE_BIT};
|
||||||
use super::{VisualizerTap, FFT_SIZE, NUM_BARS, TARGET_FPS};
|
use super::{VisualizerTap, FFT_SIZE, NUM_BARS, TARGET_FPS};
|
||||||
|
|
||||||
/// Number of energy bands for the Energy Bands visualizer
|
/// Number of energy bands for the Energy Bands visualizer
|
||||||
@@ -56,6 +57,13 @@ pub enum VizFrame {
|
|||||||
Energy5([f32; 5]),
|
Energy5([f32; 5]),
|
||||||
/// A single transient intensity, submitted only on detection (`viz:transient`).
|
/// A single transient intensity, submitted only on detection (`viz:transient`).
|
||||||
Transient1(f32),
|
Transient1(f32),
|
||||||
|
/// 256 packed mid/side points plus the stereo correlation coefficient.
|
||||||
|
Goniometer {
|
||||||
|
points: Box<[f32; 512]>,
|
||||||
|
correlation: f32,
|
||||||
|
},
|
||||||
|
/// 512 pitch-locked mono samples.
|
||||||
|
Oscilloscope(Box<[f32; 512]>),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Frontend-agnostic consumer of visualization frames. Implemented by the Tauri
|
/// Frontend-agnostic consumer of visualization frames. Implemented by the Tauri
|
||||||
@@ -113,6 +121,7 @@ fn run_fft_loop(tap: VisualizerTap, sink: Arc<dyn VizSink>) {
|
|||||||
SPECTRAL_UPDATE_RATE_HZ,
|
SPECTRAL_UPDATE_RATE_HZ,
|
||||||
SPECTRAL_SMOOTHING,
|
SPECTRAL_SMOOTHING,
|
||||||
);
|
);
|
||||||
|
let mut scopes = ScopeProcessor::default();
|
||||||
|
|
||||||
// Transient detection state
|
// Transient detection state
|
||||||
let mut prev_rms = 0.0f32;
|
let mut prev_rms = 0.0f32;
|
||||||
@@ -146,6 +155,23 @@ fn run_fft_loop(tap: VisualizerTap, sink: Arc<dyn VizSink>) {
|
|||||||
// Get samples from ring buffer
|
// Get samples from ring buffer
|
||||||
tap.ring_buffer.snapshot(&mut samples);
|
tap.ring_buffer.snapshot(&mut samples);
|
||||||
|
|
||||||
|
// The scope pipeline is explicitly requested by the visible
|
||||||
|
// frontend destination. Its FIR and pitch FFT remain completely
|
||||||
|
// idle for the existing bars/waveform/energy modes.
|
||||||
|
let scope_mask = tap.scope_mask.load(Ordering::Relaxed);
|
||||||
|
if scope_mask & GONIOMETER_BIT != 0 {
|
||||||
|
let (points, correlation) = scopes.goniometer(&samples, sample_rate);
|
||||||
|
sink.submit(VizFrame::Goniometer {
|
||||||
|
points,
|
||||||
|
correlation,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if scope_mask & OSCILLOSCOPE_BIT != 0 {
|
||||||
|
sink.submit(VizFrame::Oscilloscope(
|
||||||
|
scopes.oscilloscope(&samples, sample_rate),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
// Compact, progressive spectrogram bands for the Spectral Ribbon,
|
// Compact, progressive spectrogram bands for the Spectral Ribbon,
|
||||||
// gated on the analyzer's own update cadence.
|
// gated on the analyzer's own update cadence.
|
||||||
if spectral_analyzer.process_audio_frame(&samples, sample_rate) {
|
if spectral_analyzer.process_audio_frame(&samples, sample_rate) {
|
||||||
|
|||||||
@@ -0,0 +1,375 @@
|
|||||||
|
//! Real-time scope DSP fed by the visualizer ring-buffer snapshot.
|
||||||
|
//!
|
||||||
|
//! The processor is downstream of the passive audio tap. It never changes the
|
||||||
|
//! playback stream and runs only when a frontend requests one of the scope bits.
|
||||||
|
|
||||||
|
use spectrum_analyzer::scaling::divide_by_N_sqrt;
|
||||||
|
use spectrum_analyzer::windows::hann_window;
|
||||||
|
use spectrum_analyzer::{samples_fft_to_spectrum, FrequencyLimit};
|
||||||
|
|
||||||
|
pub const GONIOMETER_BIT: u32 = 0b01;
|
||||||
|
pub const OSCILLOSCOPE_BIT: u32 = 0b10;
|
||||||
|
pub const GONIOMETER_POINTS: usize = 256;
|
||||||
|
pub const OSCILLOSCOPE_POINTS: usize = 512;
|
||||||
|
|
||||||
|
const INV_SQRT_2: f32 = std::f32::consts::FRAC_1_SQRT_2;
|
||||||
|
const PITCH_MIN_HZ: f32 = 40.0;
|
||||||
|
const PITCH_MAX_HZ: f32 = 1_000.0;
|
||||||
|
const FIR_TAPS: usize = 257;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Default)]
|
||||||
|
struct Biquad {
|
||||||
|
b0: f32,
|
||||||
|
b1: f32,
|
||||||
|
b2: f32,
|
||||||
|
a1: f32,
|
||||||
|
a2: f32,
|
||||||
|
z1: f32,
|
||||||
|
z2: f32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Biquad {
|
||||||
|
fn lowpass(sample_rate: u32, cutoff_hz: f32) -> Self {
|
||||||
|
let sample_rate = sample_rate.max(1) as f32;
|
||||||
|
let cutoff = cutoff_hz.clamp(1.0, sample_rate * 0.49);
|
||||||
|
let omega = std::f32::consts::TAU * cutoff / sample_rate;
|
||||||
|
let sin = omega.sin();
|
||||||
|
let cos = omega.cos();
|
||||||
|
let alpha = sin * INV_SQRT_2;
|
||||||
|
let a0 = 1.0 + alpha;
|
||||||
|
Self {
|
||||||
|
b0: ((1.0 - cos) * 0.5) / a0,
|
||||||
|
b1: (1.0 - cos) / a0,
|
||||||
|
b2: ((1.0 - cos) * 0.5) / a0,
|
||||||
|
a1: (-2.0 * cos) / a0,
|
||||||
|
a2: (1.0 - alpha) / a0,
|
||||||
|
z1: 0.0,
|
||||||
|
z2: 0.0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn process(&mut self, sample: f32) -> f32 {
|
||||||
|
let out = self.b0 * sample + self.z1;
|
||||||
|
self.z1 = self.b1 * sample - self.a1 * out + self.z2;
|
||||||
|
self.z2 = self.b2 * sample - self.a2 * out;
|
||||||
|
out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct ScopeProcessor {
|
||||||
|
raw: Vec<f32>,
|
||||||
|
conditioned: Vec<f32>,
|
||||||
|
trigger: Vec<f32>,
|
||||||
|
draw: Vec<f32>,
|
||||||
|
fir: Vec<f32>,
|
||||||
|
pitch_hz: f32,
|
||||||
|
fir_center_hz: f32,
|
||||||
|
fir_sample_rate: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for ScopeProcessor {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
raw: Vec::new(),
|
||||||
|
conditioned: Vec::new(),
|
||||||
|
trigger: Vec::new(),
|
||||||
|
draw: Vec::new(),
|
||||||
|
fir: Vec::new(),
|
||||||
|
pitch_hz: 0.0,
|
||||||
|
fir_center_hz: 0.0,
|
||||||
|
fir_sample_rate: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ScopeProcessor {
|
||||||
|
/// Mid/side points after two cascaded 8 kHz Butterworth low-pass stages,
|
||||||
|
/// plus the correlation of the same full-rate stereo window.
|
||||||
|
pub fn goniometer(&mut self, interleaved: &[f32], sample_rate: u32) -> (Box<[f32; 512]>, f32) {
|
||||||
|
let frames = interleaved.len() / 2;
|
||||||
|
let mut points = Box::new([0.0; GONIOMETER_POINTS * 2]);
|
||||||
|
if frames == 0 {
|
||||||
|
return (points, 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut ll1 = Biquad::lowpass(sample_rate, 8_000.0);
|
||||||
|
let mut ll2 = Biquad::lowpass(sample_rate, 8_000.0);
|
||||||
|
let mut rr1 = Biquad::lowpass(sample_rate, 8_000.0);
|
||||||
|
let mut rr2 = Biquad::lowpass(sample_rate, 8_000.0);
|
||||||
|
let step = (frames / GONIOMETER_POINTS).max(1);
|
||||||
|
let first = frames.saturating_sub(step * GONIOMETER_POINTS);
|
||||||
|
let mut next = first;
|
||||||
|
let mut point = 0usize;
|
||||||
|
let mut sum_lr = 0.0f64;
|
||||||
|
let mut sum_l2 = 0.0f64;
|
||||||
|
let mut sum_r2 = 0.0f64;
|
||||||
|
|
||||||
|
for frame in 0..frames {
|
||||||
|
let left = interleaved[frame * 2];
|
||||||
|
let right = interleaved[frame * 2 + 1];
|
||||||
|
sum_lr += (left * right) as f64;
|
||||||
|
sum_l2 += (left * left) as f64;
|
||||||
|
sum_r2 += (right * right) as f64;
|
||||||
|
let left = ll2.process(ll1.process(left));
|
||||||
|
let right = rr2.process(rr1.process(right));
|
||||||
|
if frame >= next && point < GONIOMETER_POINTS {
|
||||||
|
points[point * 2] = ((right - left) * INV_SQRT_2).clamp(-1.0, 1.0);
|
||||||
|
points[point * 2 + 1] = ((right + left) * INV_SQRT_2).clamp(-1.0, 1.0);
|
||||||
|
point += 1;
|
||||||
|
next = next.saturating_add(step);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let denom = (sum_l2 * sum_r2).sqrt();
|
||||||
|
let correlation = if denom > f64::EPSILON {
|
||||||
|
(sum_lr / denom).clamp(-1.0, 1.0) as f32
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
};
|
||||||
|
(points, correlation)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Pitch-locked mono oscilloscope. Pitch estimation and drawing use
|
||||||
|
/// separate conditioned buffers; the narrow FIR is only redesigned after
|
||||||
|
/// a material pitch change.
|
||||||
|
pub fn oscilloscope(&mut self, interleaved: &[f32], sample_rate: u32) -> Box<[f32; 512]> {
|
||||||
|
let frames = interleaved.len() / 2;
|
||||||
|
let mut output = Box::new([0.0; OSCILLOSCOPE_POINTS]);
|
||||||
|
if frames < 64 {
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
self.resize(frames);
|
||||||
|
for frame in 0..frames {
|
||||||
|
self.raw[frame] = (interleaved[frame * 2] + interleaved[frame * 2 + 1]) * 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.condition_for_pitch(sample_rate);
|
||||||
|
let target_pitch = estimate_pitch(&self.conditioned, sample_rate);
|
||||||
|
if let Some(target) = target_pitch {
|
||||||
|
self.pitch_hz = if self.pitch_hz <= 0.0
|
||||||
|
|| (target / self.pitch_hz).max(self.pitch_hz / target) > 1.8
|
||||||
|
{
|
||||||
|
target
|
||||||
|
} else {
|
||||||
|
self.pitch_hz * 0.82 + target * 0.18
|
||||||
|
};
|
||||||
|
}
|
||||||
|
let pitch = self.pitch_hz.clamp(PITCH_MIN_HZ, PITCH_MAX_HZ);
|
||||||
|
if self.fir.is_empty()
|
||||||
|
|| self.fir_sample_rate != sample_rate
|
||||||
|
|| relative_change(pitch, self.fir_center_hz) > 0.05
|
||||||
|
{
|
||||||
|
self.fir = design_bandpass(pitch, sample_rate, FIR_TAPS);
|
||||||
|
self.fir_center_hz = pitch;
|
||||||
|
self.fir_sample_rate = sample_rate;
|
||||||
|
}
|
||||||
|
|
||||||
|
convolve(&self.conditioned, &self.fir, &mut self.trigger);
|
||||||
|
lowpass_draw(&self.raw, sample_rate, &mut self.draw);
|
||||||
|
|
||||||
|
let period = (sample_rate.max(1) as f32 / pitch).clamp(2.0, frames as f32);
|
||||||
|
let span = (period * 2.0).clamp(96.0, (frames.saturating_sub(4)) as f32);
|
||||||
|
let required = span.ceil() as usize + 2;
|
||||||
|
let latest = frames.saturating_sub(required).max(1);
|
||||||
|
let trigger_rms = rms(&self.trigger);
|
||||||
|
let quarter = (period * 0.25).round().max(1.0) as usize;
|
||||||
|
let threshold = (trigger_rms * 0.18).max(0.0005);
|
||||||
|
let trigger = rising_trigger(&self.trigger, latest, quarter, threshold)
|
||||||
|
.unwrap_or_else(|| frames.saturating_sub(required) as f32);
|
||||||
|
let gain = (0.22 / rms(&self.draw).max(0.015)).clamp(0.5, 6.0);
|
||||||
|
|
||||||
|
for (index, sample) in output.iter_mut().enumerate() {
|
||||||
|
let position = trigger + span * index as f32 / (OSCILLOSCOPE_POINTS - 1) as f32;
|
||||||
|
*sample = (interpolate(&self.draw, position) * gain).clamp(-1.0, 1.0);
|
||||||
|
}
|
||||||
|
output
|
||||||
|
}
|
||||||
|
|
||||||
|
fn resize(&mut self, frames: usize) {
|
||||||
|
self.raw.resize(frames, 0.0);
|
||||||
|
self.conditioned.resize(frames, 0.0);
|
||||||
|
self.trigger.resize(frames, 0.0);
|
||||||
|
self.draw.resize(frames, 0.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn condition_for_pitch(&mut self, sample_rate: u32) {
|
||||||
|
let rate = sample_rate.max(1) as f32;
|
||||||
|
let low_alpha = (-std::f32::consts::TAU * 400.0 / rate).exp();
|
||||||
|
let mut shelf_low = 0.0f32;
|
||||||
|
let mut lp1 = Biquad::lowpass(sample_rate, 18_000.0);
|
||||||
|
let mut lp2 = Biquad::lowpass(sample_rate, 18_000.0);
|
||||||
|
for (input, output) in self.raw.iter().zip(self.conditioned.iter_mut()) {
|
||||||
|
shelf_low = shelf_low * low_alpha + *input * (1.0 - low_alpha);
|
||||||
|
let high = *input - shelf_low;
|
||||||
|
*output = lp2.process(lp1.process(shelf_low + high * 0.707_106_77));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn estimate_pitch(samples: &[f32], sample_rate: u32) -> Option<f32> {
|
||||||
|
if samples.len() < 64 || rms(samples) < 0.002 {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let windowed = hann_window(samples);
|
||||||
|
let spectrum = samples_fft_to_spectrum(
|
||||||
|
&windowed,
|
||||||
|
sample_rate.max(1),
|
||||||
|
FrequencyLimit::Range(PITCH_MIN_HZ, PITCH_MAX_HZ),
|
||||||
|
Some(÷_by_N_sqrt),
|
||||||
|
)
|
||||||
|
.ok()?;
|
||||||
|
spectrum
|
||||||
|
.data()
|
||||||
|
.iter()
|
||||||
|
.max_by(|(fa, ma), (fb, mb)| {
|
||||||
|
let a = ma.val() / fa.val().max(PITCH_MIN_HZ).sqrt();
|
||||||
|
let b = mb.val() / fb.val().max(PITCH_MIN_HZ).sqrt();
|
||||||
|
a.total_cmp(&b)
|
||||||
|
})
|
||||||
|
.map(|(frequency, _)| frequency.val())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn relative_change(a: f32, b: f32) -> f32 {
|
||||||
|
if a <= 0.0 || b <= 0.0 {
|
||||||
|
return f32::INFINITY;
|
||||||
|
}
|
||||||
|
(a - b).abs() / b
|
||||||
|
}
|
||||||
|
|
||||||
|
fn design_bandpass(center_hz: f32, sample_rate: u32, taps: usize) -> Vec<f32> {
|
||||||
|
let rate = sample_rate.max(1) as f32;
|
||||||
|
let half_width = (center_hz * 0.05).max(rate / taps as f32);
|
||||||
|
let low = (center_hz - half_width).max(PITCH_MIN_HZ * 0.5) / rate;
|
||||||
|
let high = (center_hz + half_width).min(rate * 0.48) / rate;
|
||||||
|
let middle = (taps - 1) as f32 * 0.5;
|
||||||
|
let mut kernel = Vec::with_capacity(taps);
|
||||||
|
for index in 0..taps {
|
||||||
|
let m = index as f32 - middle;
|
||||||
|
let ideal = if m.abs() < f32::EPSILON {
|
||||||
|
2.0 * (high - low)
|
||||||
|
} else {
|
||||||
|
((std::f32::consts::TAU * high * m).sin() - (std::f32::consts::TAU * low * m).sin())
|
||||||
|
/ (std::f32::consts::PI * m)
|
||||||
|
};
|
||||||
|
let window = 0.5 - 0.5 * (std::f32::consts::TAU * index as f32 / (taps - 1) as f32).cos();
|
||||||
|
kernel.push(ideal * window);
|
||||||
|
}
|
||||||
|
let omega = std::f32::consts::TAU * center_hz / rate;
|
||||||
|
let (real, imag) = kernel
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.fold((0.0, 0.0), |(real, imag), (i, tap)| {
|
||||||
|
let phase = omega * i as f32;
|
||||||
|
(real + tap * phase.cos(), imag - tap * phase.sin())
|
||||||
|
});
|
||||||
|
let gain = (real * real + imag * imag).sqrt().max(1.0e-6);
|
||||||
|
for tap in &mut kernel {
|
||||||
|
*tap /= gain;
|
||||||
|
}
|
||||||
|
kernel
|
||||||
|
}
|
||||||
|
|
||||||
|
fn convolve(input: &[f32], kernel: &[f32], output: &mut [f32]) {
|
||||||
|
for (index, out) in output.iter_mut().enumerate() {
|
||||||
|
let count = kernel.len().min(index + 1);
|
||||||
|
let mut sum = 0.0;
|
||||||
|
for tap in 0..count {
|
||||||
|
sum += input[index - tap] * kernel[tap];
|
||||||
|
}
|
||||||
|
*out = sum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lowpass_draw(input: &[f32], sample_rate: u32, output: &mut [f32]) {
|
||||||
|
let mut filter = Biquad::lowpass(sample_rate, 12_000.0);
|
||||||
|
for (input, output) in input.iter().zip(output.iter_mut()) {
|
||||||
|
*output = filter.process(*input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn rising_trigger(signal: &[f32], latest: usize, quarter: usize, threshold: f32) -> Option<f32> {
|
||||||
|
for index in (1..=latest.min(signal.len().saturating_sub(2))).rev() {
|
||||||
|
let before = signal[index - 1];
|
||||||
|
let after = signal[index];
|
||||||
|
let validation = index.saturating_add(quarter).min(signal.len() - 1);
|
||||||
|
if before <= 0.0 && after > 0.0 && signal[validation].abs() >= threshold {
|
||||||
|
let fraction = (-before / (after - before).max(f32::EPSILON)).clamp(0.0, 1.0);
|
||||||
|
return Some(index as f32 - 1.0 + fraction);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn interpolate(samples: &[f32], position: f32) -> f32 {
|
||||||
|
let base = position.floor().max(0.0) as usize;
|
||||||
|
let next = (base + 1).min(samples.len().saturating_sub(1));
|
||||||
|
let fraction = position - base as f32;
|
||||||
|
samples.get(base).copied().unwrap_or(0.0) * (1.0 - fraction)
|
||||||
|
+ samples.get(next).copied().unwrap_or(0.0) * fraction
|
||||||
|
}
|
||||||
|
|
||||||
|
fn rms(samples: &[f32]) -> f32 {
|
||||||
|
if samples.is_empty() {
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
(samples.iter().map(|sample| sample * sample).sum::<f32>() / samples.len() as f32).sqrt()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
fn stereo_sine(sample_rate: u32, frequency: f32, phase: f32, inverted: bool) -> Vec<f32> {
|
||||||
|
let mut samples = Vec::with_capacity(4096);
|
||||||
|
for frame in 0..2048 {
|
||||||
|
let value = (std::f32::consts::TAU * frequency * frame as f32 / sample_rate as f32
|
||||||
|
+ phase)
|
||||||
|
.sin()
|
||||||
|
* 0.5;
|
||||||
|
samples.push(value);
|
||||||
|
samples.push(if inverted { -value } else { value });
|
||||||
|
}
|
||||||
|
samples
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn goniometer_maps_mono_vertical_and_reports_positive_correlation() {
|
||||||
|
let mut scope = ScopeProcessor::default();
|
||||||
|
let (points, correlation) =
|
||||||
|
scope.goniometer(&stereo_sine(48_000, 440.0, 0.0, false), 48_000);
|
||||||
|
let max_side = points
|
||||||
|
.iter()
|
||||||
|
.step_by(2)
|
||||||
|
.fold(0.0f32, |peak, value| peak.max(value.abs()));
|
||||||
|
assert!(max_side < 0.001);
|
||||||
|
assert!(correlation > 0.999);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn goniometer_maps_inverted_stereo_horizontal_and_reports_negative_correlation() {
|
||||||
|
let mut scope = ScopeProcessor::default();
|
||||||
|
let (points, correlation) =
|
||||||
|
scope.goniometer(&stereo_sine(48_000, 440.0, 0.0, true), 48_000);
|
||||||
|
let max_mid = points
|
||||||
|
.iter()
|
||||||
|
.skip(1)
|
||||||
|
.step_by(2)
|
||||||
|
.fold(0.0f32, |peak, value| peak.max(value.abs()));
|
||||||
|
assert!(max_mid < 0.001);
|
||||||
|
assert!(correlation < -0.999);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn oscilloscope_locks_a_tone_to_a_rising_crossing() {
|
||||||
|
let mut scope = ScopeProcessor::default();
|
||||||
|
let output = scope.oscilloscope(&stereo_sine(48_000, 440.0, 1.7, false), 48_000);
|
||||||
|
assert!(
|
||||||
|
scope.pitch_hz > 400.0 && scope.pitch_hz < 500.0,
|
||||||
|
"pitch {}",
|
||||||
|
scope.pitch_hz
|
||||||
|
);
|
||||||
|
assert!(output.iter().all(|value| value.is_finite()));
|
||||||
|
assert!(output.iter().any(|value| value.abs() > 0.1));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5970,3 +5970,9 @@ msgstr "Das ausgewählte Cover hat nicht unterstützte Abmessungen."
|
|||||||
|
|
||||||
msgid "The selected file is not a supported image."
|
msgid "The selected file is not a supported image."
|
||||||
msgstr "Die ausgewählte Datei ist kein unterstütztes Bild."
|
msgstr "Die ausgewählte Datei ist kein unterstütztes Bild."
|
||||||
|
|
||||||
|
msgid "Goniometer"
|
||||||
|
msgstr "Goniometer"
|
||||||
|
|
||||||
|
msgid "Oscilloscope"
|
||||||
|
msgstr "Oszilloskop"
|
||||||
@@ -1566,3 +1566,9 @@ msgstr "The selected file is not a supported image."
|
|||||||
|
|
||||||
msgid "Title"
|
msgid "Title"
|
||||||
msgstr "Title"
|
msgstr "Title"
|
||||||
|
|
||||||
|
msgid "Goniometer"
|
||||||
|
msgstr "Goniometer"
|
||||||
|
|
||||||
|
msgid "Oscilloscope"
|
||||||
|
msgstr "Oscilloscope"
|
||||||
@@ -5976,3 +5976,9 @@ msgstr "La portada seleccionada tiene dimensiones no compatibles."
|
|||||||
|
|
||||||
msgid "The selected file is not a supported image."
|
msgid "The selected file is not a supported image."
|
||||||
msgstr "El archivo seleccionado no es una imagen compatible."
|
msgstr "El archivo seleccionado no es una imagen compatible."
|
||||||
|
|
||||||
|
msgid "Goniometer"
|
||||||
|
msgstr "Goniómetro"
|
||||||
|
|
||||||
|
msgid "Oscilloscope"
|
||||||
|
msgstr "Osciloscopio"
|
||||||
@@ -5968,3 +5968,9 @@ msgstr "La pochette sélectionnée a des dimensions non prises en charge."
|
|||||||
|
|
||||||
msgid "The selected file is not a supported image."
|
msgid "The selected file is not a supported image."
|
||||||
msgstr "Le fichier sélectionné n’est pas une image prise en charge."
|
msgstr "Le fichier sélectionné n’est pas une image prise en charge."
|
||||||
|
|
||||||
|
msgid "Goniometer"
|
||||||
|
msgstr "Goniomètre"
|
||||||
|
|
||||||
|
msgid "Oscilloscope"
|
||||||
|
msgstr "Oscilloscope"
|
||||||
@@ -5952,3 +5952,9 @@ msgstr "選択したアートワークの寸法はサポートされていませ
|
|||||||
|
|
||||||
msgid "The selected file is not a supported image."
|
msgid "The selected file is not a supported image."
|
||||||
msgstr "選択したファイルはサポートされている画像ではありません。"
|
msgstr "選択したファイルはサポートされている画像ではありません。"
|
||||||
|
|
||||||
|
msgid "Goniometer"
|
||||||
|
msgstr "ゴニオメーター"
|
||||||
|
|
||||||
|
msgid "Oscilloscope"
|
||||||
|
msgstr "オシロスコープ"
|
||||||
@@ -5958,3 +5958,9 @@ msgstr "De geselecteerde albumafbeelding heeft niet-ondersteunde afmetingen."
|
|||||||
|
|
||||||
msgid "The selected file is not a supported image."
|
msgid "The selected file is not a supported image."
|
||||||
msgstr "Het geselecteerde bestand is geen ondersteunde afbeelding."
|
msgstr "Het geselecteerde bestand is geen ondersteunde afbeelding."
|
||||||
|
|
||||||
|
msgid "Goniometer"
|
||||||
|
msgstr "Goniometer"
|
||||||
|
|
||||||
|
msgid "Oscilloscope"
|
||||||
|
msgstr "Oscilloscoop"
|
||||||
@@ -5968,3 +5968,9 @@ msgstr "A capa selecionada tem dimensões incompatíveis."
|
|||||||
|
|
||||||
msgid "The selected file is not a supported image."
|
msgid "The selected file is not a supported image."
|
||||||
msgstr "O arquivo selecionado não é uma imagem compatível."
|
msgstr "O arquivo selecionado não é uma imagem compatível."
|
||||||
|
|
||||||
|
msgid "Goniometer"
|
||||||
|
msgstr "Goniômetro"
|
||||||
|
|
||||||
|
msgid "Oscilloscope"
|
||||||
|
msgstr "Osciloscópio"
|
||||||
@@ -5988,3 +5988,9 @@ msgstr "Размеры выбранной обложки не поддержив
|
|||||||
|
|
||||||
msgid "The selected file is not a supported image."
|
msgid "The selected file is not a supported image."
|
||||||
msgstr "Выбранный файл не является поддерживаемым изображением."
|
msgstr "Выбранный файл не является поддерживаемым изображением."
|
||||||
|
|
||||||
|
msgid "Goniometer"
|
||||||
|
msgstr "Гониометр"
|
||||||
|
|
||||||
|
msgid "Oscilloscope"
|
||||||
|
msgstr "Осциллограф"
|
||||||
@@ -302,6 +302,7 @@ fn build_rhi_items() {
|
|||||||
"plasma_item",
|
"plasma_item",
|
||||||
"ribbon_item",
|
"ribbon_item",
|
||||||
"tunnelflow_item",
|
"tunnelflow_item",
|
||||||
|
"scope_trace_item",
|
||||||
"local_tracks_model",
|
"local_tracks_model",
|
||||||
"local_albums_model",
|
"local_albums_model",
|
||||||
"local_artists_model",
|
"local_artists_model",
|
||||||
@@ -445,6 +446,7 @@ fn main() {
|
|||||||
// Per-page scroll memory for the back/forward stack; mounted
|
// Per-page scroll memory for the back/forward stack; mounted
|
||||||
// beside each view's scroll container.
|
// beside each view's scroll container.
|
||||||
"qml/controls/ScrollMemory.qml",
|
"qml/controls/ScrollMemory.qml",
|
||||||
|
"qml/controls/ScopePanel.qml",
|
||||||
"qml/controls/QbzSegToggle.qml",
|
"qml/controls/QbzSegToggle.qml",
|
||||||
"qml/controls/QbzSelect.qml",
|
"qml/controls/QbzSelect.qml",
|
||||||
"qml/controls/QbzSlider.qml",
|
"qml/controls/QbzSlider.qml",
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
#include "scope_trace_item.h"
|
||||||
|
|
||||||
|
#include <QtCore/QCoreApplication>
|
||||||
|
#include <QtQml/qqml.h>
|
||||||
|
#include <QtQuick/QSGFlatColorMaterial>
|
||||||
|
#include <QtQuick/QSGGeometryNode>
|
||||||
|
|
||||||
|
ScopeTraceItem::ScopeTraceItem(QQuickItem *parent)
|
||||||
|
: QQuickItem(parent)
|
||||||
|
{
|
||||||
|
setFlag(ItemHasContents, true);
|
||||||
|
setAntialiasing(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScopeTraceItem::setPoints(const QVariantList &points)
|
||||||
|
{
|
||||||
|
m_points = points;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScopeTraceItem::setTraceColor(const QColor &color)
|
||||||
|
{
|
||||||
|
if (m_traceColor == color)
|
||||||
|
return;
|
||||||
|
m_traceColor = color;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScopeTraceItem::setMode(int mode)
|
||||||
|
{
|
||||||
|
mode = mode == 1 ? 1 : 0;
|
||||||
|
if (m_mode == mode)
|
||||||
|
return;
|
||||||
|
m_mode = mode;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScopeTraceItem::setLineWidth(qreal width)
|
||||||
|
{
|
||||||
|
width = qMax<qreal>(1.0, width);
|
||||||
|
if (qFuzzyCompare(m_lineWidth, width))
|
||||||
|
return;
|
||||||
|
m_lineWidth = width;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
QSGNode *ScopeTraceItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
|
||||||
|
{
|
||||||
|
const int count = m_mode == 0 ? m_points.size() / 2 : m_points.size();
|
||||||
|
if (count < 2 || width() <= 0.0 || height() <= 0.0) {
|
||||||
|
delete oldNode;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto *node = static_cast<QSGGeometryNode *>(oldNode);
|
||||||
|
if (!node) {
|
||||||
|
node = new QSGGeometryNode;
|
||||||
|
auto *geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), count);
|
||||||
|
geometry->setDrawingMode(QSGGeometry::DrawLineStrip);
|
||||||
|
geometry->setLineWidth(static_cast<float>(m_lineWidth));
|
||||||
|
node->setGeometry(geometry);
|
||||||
|
node->setFlag(QSGNode::OwnsGeometry);
|
||||||
|
auto *material = new QSGFlatColorMaterial;
|
||||||
|
material->setColor(m_traceColor);
|
||||||
|
node->setMaterial(material);
|
||||||
|
node->setFlag(QSGNode::OwnsMaterial);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto *geometry = node->geometry();
|
||||||
|
if (geometry->vertexCount() != count)
|
||||||
|
geometry->allocate(count);
|
||||||
|
geometry->setDrawingMode(QSGGeometry::DrawLineStrip);
|
||||||
|
geometry->setLineWidth(static_cast<float>(m_lineWidth));
|
||||||
|
auto *vertices = geometry->vertexDataAsPoint2D();
|
||||||
|
const float pad = 4.0f;
|
||||||
|
const float drawWidth = qMax(1.0f, static_cast<float>(width()) - pad * 2.0f);
|
||||||
|
const float drawHeight = qMax(1.0f, static_cast<float>(height()) - pad * 2.0f);
|
||||||
|
|
||||||
|
for (int index = 0; index < count; ++index) {
|
||||||
|
float x;
|
||||||
|
float y;
|
||||||
|
if (m_mode == 0) {
|
||||||
|
const float side = qBound(-1.0f, m_points[index * 2].toFloat(), 1.0f);
|
||||||
|
const float mid = qBound(-1.0f, m_points[index * 2 + 1].toFloat(), 1.0f);
|
||||||
|
x = pad + (0.5f + side * 0.46f) * drawWidth;
|
||||||
|
y = pad + (0.5f - mid * 0.46f) * drawHeight;
|
||||||
|
} else {
|
||||||
|
const float value = qBound(-1.0f, m_points[index].toFloat(), 1.0f);
|
||||||
|
x = pad + index * drawWidth / qMax(1, count - 1);
|
||||||
|
y = pad + (0.5f - value * 0.46f) * drawHeight;
|
||||||
|
}
|
||||||
|
vertices[index].set(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
static_cast<QSGFlatColorMaterial *>(node->material())->setColor(m_traceColor);
|
||||||
|
node->markDirty(QSGNode::DirtyGeometry | QSGNode::DirtyMaterial);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool g_scopeTraceRegistered = false;
|
||||||
|
|
||||||
|
extern "C" void qbz_scope_trace_register_qml_type()
|
||||||
|
{
|
||||||
|
if (g_scopeTraceRegistered)
|
||||||
|
return;
|
||||||
|
g_scopeTraceRegistered = true;
|
||||||
|
qmlRegisterType<ScopeTraceItem>("com.blitzfc.qbz", 1, 0, "ScopeTraceItem");
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_COREAPP_STARTUP_FUNCTION(qbz_scope_trace_register_qml_type)
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#ifndef QBZ_SCOPE_TRACE_ITEM_H
|
||||||
|
#define QBZ_SCOPE_TRACE_ITEM_H
|
||||||
|
|
||||||
|
#include <QtCore/QVariantList>
|
||||||
|
#include <QtGui/QColor>
|
||||||
|
#include <QtQuick/QQuickItem>
|
||||||
|
|
||||||
|
class ScopeTraceItem : public QQuickItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QVariantList points READ points WRITE setPoints)
|
||||||
|
Q_PROPERTY(QColor traceColor READ traceColor WRITE setTraceColor)
|
||||||
|
Q_PROPERTY(int mode READ mode WRITE setMode)
|
||||||
|
Q_PROPERTY(qreal lineWidth READ lineWidth WRITE setLineWidth)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ScopeTraceItem(QQuickItem *parent = nullptr);
|
||||||
|
|
||||||
|
QVariantList points() const { return m_points; }
|
||||||
|
void setPoints(const QVariantList &points);
|
||||||
|
QColor traceColor() const { return m_traceColor; }
|
||||||
|
void setTraceColor(const QColor &color);
|
||||||
|
int mode() const { return m_mode; }
|
||||||
|
void setMode(int mode);
|
||||||
|
qreal lineWidth() const { return m_lineWidth; }
|
||||||
|
void setLineWidth(qreal width);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QSGNode *updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QVariantList m_points;
|
||||||
|
QColor m_traceColor{ 63, 217, 200 };
|
||||||
|
int m_mode = 0;
|
||||||
|
qreal m_lineWidth = 1.5;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern "C" void qbz_scope_trace_register_qml_type();
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import QtQuick
|
||||||
|
import com.blitzfc.qbz
|
||||||
|
import "../theme"
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
QbzTheme { id: theme }
|
||||||
|
|
||||||
|
// 0 = goniometer, 1 = pitch-locked oscilloscope.
|
||||||
|
property int scopeMode: 0
|
||||||
|
property color traceColor: theme.accent
|
||||||
|
property bool compact: false
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
anchors.fill: parent
|
||||||
|
color: "transparent"
|
||||||
|
border.width: 1
|
||||||
|
border.color: theme.borderSubtle
|
||||||
|
radius: theme.radiusMd
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
y: 8
|
||||||
|
width: 1
|
||||||
|
height: parent.height - 16
|
||||||
|
color: theme.borderSubtle
|
||||||
|
}
|
||||||
|
Rectangle {
|
||||||
|
x: 8
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
width: parent.width - 16
|
||||||
|
height: 1
|
||||||
|
color: theme.borderSubtle
|
||||||
|
}
|
||||||
|
Rectangle {
|
||||||
|
visible: root.scopeMode === 0
|
||||||
|
anchors.centerIn: parent
|
||||||
|
width: parent.width * 0.5
|
||||||
|
height: parent.height * 0.5
|
||||||
|
color: "transparent"
|
||||||
|
border.width: 1
|
||||||
|
border.color: theme.borderSubtle
|
||||||
|
radius: width / 2
|
||||||
|
}
|
||||||
|
|
||||||
|
ScopeTraceItem {
|
||||||
|
anchors.fill: parent
|
||||||
|
anchors.margins: root.compact ? 3 : 8
|
||||||
|
mode: root.scopeMode
|
||||||
|
points: root.scopeMode === 0 ? QbzViz.goniometer : QbzViz.oscilloscope
|
||||||
|
traceColor: root.traceColor
|
||||||
|
lineWidth: root.compact ? 1.0 : 1.5
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
visible: root.scopeMode === 0 && !root.compact
|
||||||
|
anchors.right: parent.right
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.margins: 12
|
||||||
|
text: QbzViz.stereoCorrelation.toFixed(2)
|
||||||
|
color: theme.textMuted
|
||||||
|
font.pixelSize: 11
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -207,8 +207,8 @@ Item {
|
|||||||
}
|
}
|
||||||
Repeater {
|
Repeater {
|
||||||
// FOCUS rows IN SLINT ORDER (:586-650): Album Reactive(0),
|
// FOCUS rows IN SLINT ORDER (:586-650): Album Reactive(0),
|
||||||
// Static(1), Coverflow(2), Spectrum(3), Wave Bed(6), Lyrics(4),
|
// Static(1), Coverflow(2), Spectrum(3), Wave Bed(6),
|
||||||
// Queue(5).
|
// Goniometer(7), Oscilloscope(8), Lyrics(4), Queue(5).
|
||||||
model: [
|
model: [
|
||||||
{ "vm": 0, "m": 0, "sp": -1, "entry": "",
|
{ "vm": 0, "m": 0, "sp": -1, "entry": "",
|
||||||
"label": QbzSession.tr("Album Reactive", QbzSession.trRev) },
|
"label": QbzSession.tr("Album Reactive", QbzSession.trRev) },
|
||||||
@@ -220,6 +220,10 @@ Item {
|
|||||||
"label": QbzSession.tr("Spectrum", QbzSession.trRev) },
|
"label": QbzSession.tr("Spectrum", QbzSession.trRev) },
|
||||||
{ "vm": 0, "m": 6, "sp": -1, "entry": "",
|
{ "vm": 0, "m": 6, "sp": -1, "entry": "",
|
||||||
"label": QbzSession.tr("Wave Bed", QbzSession.trRev) },
|
"label": QbzSession.tr("Wave Bed", QbzSession.trRev) },
|
||||||
|
{ "vm": 0, "m": 7, "sp": -1, "entry": "",
|
||||||
|
"label": QbzSession.tr("Goniometer", QbzSession.trRev) },
|
||||||
|
{ "vm": 0, "m": 8, "sp": -1, "entry": "",
|
||||||
|
"label": QbzSession.tr("Oscilloscope", QbzSession.trRev) },
|
||||||
{ "vm": 0, "m": 4, "sp": -1, "entry": "",
|
{ "vm": 0, "m": 4, "sp": -1, "entry": "",
|
||||||
"label": QbzSession.tr("Lyrics", QbzSession.trRev) },
|
"label": QbzSession.tr("Lyrics", QbzSession.trRev) },
|
||||||
{ "vm": 0, "m": 5, "sp": -1, "entry": "queue",
|
{ "vm": 0, "m": 5, "sp": -1, "entry": "queue",
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ import "../theme"
|
|||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
|
QbzTheme { id: theme }
|
||||||
|
|
||||||
// Self-gated on the bridge open flag (§5.1: closed = invisible,
|
// Self-gated on the bridge open flag (§5.1: closed = invisible,
|
||||||
// non-interactive, zero-cost). Every open/close transition funnels
|
// non-interactive, zero-cost). Every open/close transition funnels
|
||||||
// through QbzImmersive's open setter (§3/D3) — this item only reacts.
|
// through QbzImmersive's open setter (§3/D3) — this item only reacts.
|
||||||
@@ -300,6 +302,40 @@ Item {
|
|||||||
visible: QbzShaderScene.scene === 0
|
visible: QbzShaderScene.scene === 0
|
||||||
&& QbzImmersive.viewMode === 0 && QbzImmersive.mode === 6
|
&& QbzImmersive.viewMode === 0 && QbzImmersive.mode === 6
|
||||||
}
|
}
|
||||||
|
Loader {
|
||||||
|
anchors.fill: parent
|
||||||
|
active: QbzShaderScene.scene === 0
|
||||||
|
&& QbzImmersive.viewMode === 0 && QbzImmersive.mode === 7
|
||||||
|
visible: active
|
||||||
|
sourceComponent: Item {
|
||||||
|
ScopePanel {
|
||||||
|
width: Math.max(1, Math.min(parent.width - 96, parent.height - 196))
|
||||||
|
height: width
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.bottomMargin: 132
|
||||||
|
scopeMode: 0
|
||||||
|
traceColor: theme.accent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loader {
|
||||||
|
anchors.fill: parent
|
||||||
|
active: QbzShaderScene.scene === 0
|
||||||
|
&& QbzImmersive.viewMode === 0 && QbzImmersive.mode === 8
|
||||||
|
visible: active
|
||||||
|
sourceComponent: Item {
|
||||||
|
ScopePanel {
|
||||||
|
width: Math.max(1, Math.min(parent.width - 96, parent.height - 196))
|
||||||
|
height: width
|
||||||
|
anchors.horizontalCenter: parent.horizontalCenter
|
||||||
|
anchors.bottom: parent.bottom
|
||||||
|
anchors.bottomMargin: 132
|
||||||
|
scopeMode: 1
|
||||||
|
traceColor: theme.accent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// FOCUS Lyrics (mode 4, B4 §6.6): the giant-line variant. It shares the
|
// FOCUS Lyrics (mode 4, B4 §6.6): the giant-line variant. It shares the
|
||||||
// immersive LyricsSyncEngine with the split lyrics mount (trap 22 — the
|
// immersive LyricsSyncEngine with the split lyrics mount (trap 22 — the
|
||||||
// gate covers BOTH lyric surfaces and nothing else). No entry load: Qt
|
// gate covers BOTH lyric surfaces and nothing else). No entry load: Qt
|
||||||
|
|||||||
@@ -4,14 +4,13 @@
|
|||||||
// Mounted as a ROOT overlay by AppShell, pinned flush to the window
|
// Mounted as a ROOT overlay by AppShell, pinned flush to the window
|
||||||
// bottom-left (NOT inside the sidebar — that floated it above the bar).
|
// bottom-left (NOT inside the sidebar — that floated it above the bar).
|
||||||
// Layout, bottom-up: a square album cover (= the fed width) at the very
|
// Layout, bottom-up: a square album cover (= the fed width) at the very
|
||||||
// bottom; ABOVE it a compact spectrum band the user can hide with the
|
// bottom; ABOVE it either the compact spectrum band or a square scope the
|
||||||
// top-right eye button on the cover.
|
// user can hide with the top-right eye button on the cover.
|
||||||
//
|
//
|
||||||
// HEIGHT IS LOAD-BEARING. `QbzShell.largeDockHeight` (shell_bridge.rs) is the
|
// HEIGHT IS LOAD-BEARING. `QbzShell.largeDockHeight` (shell_bridge.rs) is the
|
||||||
// single source of truth and the layout below is derived from the SAME
|
// single source of truth and the layout below is derived from the SAME
|
||||||
// constants:
|
// constants and the persisted render mode: legacy modes are 42px high;
|
||||||
// ON = 9 top pad + 42 band + 10 gap + 208 art + 4 bottom gap = 273
|
// scope modes use the same square size as the artwork and grow upward.
|
||||||
// OFF = 9 top pad + 208 art + 4 bottom gap = 221
|
|
||||||
// Sidebar.qml reserves `largeDockHeight - npb height` so the playlist list
|
// Sidebar.qml reserves `largeDockHeight - npb height` so the playlist list
|
||||||
// stops ABOVE the cover, and AppShell pins this overlay at
|
// stops ABOVE the cover, and AppShell pins this overlay at
|
||||||
// `height - largeDockHeight`. Change the arithmetic in one place and the
|
// `height - largeDockHeight`. Change the arithmetic in one place and the
|
||||||
@@ -42,7 +41,8 @@ Item {
|
|||||||
property bool ambientOn: false
|
property bool ambientOn: false
|
||||||
|
|
||||||
readonly property bool bandOn: QbzShell.largeVisualizerOn
|
readonly property bool bandOn: QbzShell.largeVisualizerOn
|
||||||
readonly property int bandHeight: 42
|
readonly property int bandHeight: QbzShell.largeSpectrumMode >= 3
|
||||||
|
? Math.round(root.width) : 42
|
||||||
readonly property int padTop: 9
|
readonly property int padTop: 9
|
||||||
readonly property int bandGap: 10
|
readonly property int bandGap: 10
|
||||||
// The cover's top edge: below the band when it is shown.
|
// The cover's top edge: below the band when it is shown.
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
// SpectrumBand — the compact 42px spectrum strip above the Large-NPB cover.
|
// SpectrumBand — the compact 42px spectrum strip above the Large-NPB cover.
|
||||||
// Split out of SidebarNowPlayingDock.qml: the dock owns the layout arithmetic
|
// Split out of SidebarNowPlayingDock.qml: the dock owns the layout arithmetic
|
||||||
// and the cover, this file owns the three render modes and their motion.
|
// and the cover, this file owns the five render modes and their motion.
|
||||||
// QML port of the `spectrum := Rectangle` block in
|
// QML port of the `spectrum := Rectangle` block in
|
||||||
// crates/qbz-ui/ui/shell/SidebarNowPlayingDock.slint:122-183 (VBar / WaveCol).
|
// crates/qbz-ui/ui/shell/SidebarNowPlayingDock.slint:122-183 (VBar / WaveCol).
|
||||||
//
|
//
|
||||||
@@ -88,6 +88,7 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Window
|
import QtQuick.Window
|
||||||
import com.blitzfc.qbz
|
import com.blitzfc.qbz
|
||||||
|
import "../controls"
|
||||||
import "../theme"
|
import "../theme"
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
@@ -436,7 +437,29 @@ Rectangle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Click the band → cycle Bars -> Waveform -> Energy (persisted).
|
// Modes 3/4 — real-time scopes. Each Loader owns a single scene-graph
|
||||||
|
// line strip; when inactive the item does not exist and Rust also disables
|
||||||
|
// that scope's DSP bit.
|
||||||
|
Loader {
|
||||||
|
anchors.fill: parent
|
||||||
|
active: band.shown && QbzShell.largeSpectrumMode === 3
|
||||||
|
sourceComponent: ScopePanel {
|
||||||
|
compact: true
|
||||||
|
scopeMode: 0
|
||||||
|
traceColor: theme.accent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loader {
|
||||||
|
anchors.fill: parent
|
||||||
|
active: band.shown && QbzShell.largeSpectrumMode === 4
|
||||||
|
sourceComponent: ScopePanel {
|
||||||
|
compact: true
|
||||||
|
scopeMode: 1
|
||||||
|
traceColor: theme.accent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Click the band → cycle all five modes (persisted).
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
//! (`qbz-nix-docs/qt-frontend/2026-08-02-immersive-port/00-CONTRACT.md` §3).
|
//! (`qbz-nix-docs/qt-frontend/2026-08-02-immersive-port/00-CONTRACT.md` §3).
|
||||||
//! All enums are `i32` with the Slint numbering verbatim
|
//! All enums are `i32` with the Slint numbering verbatim
|
||||||
//! (`state.slint:4238,4249,4254`): view_mode 0 FOCUS / 1 SPLIT; mode 0 Album
|
//! (`state.slint:4238,4249,4254`): view_mode 0 FOCUS / 1 SPLIT; mode 0 Album
|
||||||
//! Reactive, 1 Static, 2 Coverflow, 3 Spectrum, 4 Lyrics, 5 Queue, 6 WaveBed;
|
//! Reactive, 1 Static, 2 Coverflow, 3 Spectrum, 4 Lyrics, 5 Queue, 6 WaveBed,
|
||||||
|
//! 7 Goniometer, 8 Oscilloscope;
|
||||||
//! split_panel 0 Lyrics, 1 TrackInfo, 2 Suggestions, 3 Queue.
|
//! split_panel 0 Lyrics, 1 TrackInfo, 2 Suggestions, 3 Queue.
|
||||||
//!
|
//!
|
||||||
//! The `open` property uses a CUSTOM WRITE (`set_open`) so EVERY write — the
|
//! The `open` property uses a CUSTOM WRITE (`set_open`) so EVERY write — the
|
||||||
@@ -61,7 +62,8 @@ pub mod qbz_immersive {
|
|||||||
// restore — QML never writes these directly (§3.2).
|
// restore — QML never writes these directly (§3.2).
|
||||||
#[qproperty(i32, view_mode)]
|
#[qproperty(i32, view_mode)]
|
||||||
// FOCUS foreground: 0 AlbumReactive, 1 Static, 2 Coverflow, 3
|
// FOCUS foreground: 0 AlbumReactive, 1 Static, 2 Coverflow, 3
|
||||||
// Spectrum, 4 Lyrics, 5 Queue, 6 WaveBed.
|
// Spectrum, 4 Lyrics, 5 Queue, 6 WaveBed, 7 Goniometer,
|
||||||
|
// 8 Oscilloscope.
|
||||||
#[qproperty(i32, mode)]
|
#[qproperty(i32, mode)]
|
||||||
// SPLIT active panel: 0 Lyrics, 1 TrackInfo, 2 Suggestions, 3 Queue.
|
// SPLIT active panel: 0 Lyrics, 1 TrackInfo, 2 Suggestions, 3 Queue.
|
||||||
#[qproperty(i32, split_panel)]
|
#[qproperty(i32, split_panel)]
|
||||||
@@ -297,6 +299,7 @@ fn apply_open(mut this: Pin<&mut QbzImmersive>, value: bool) {
|
|||||||
}
|
}
|
||||||
// Unknown key: Slint's `_ => {}` — leave the current view alone.
|
// Unknown key: Slint's `_ => {}` — leave the current view alone.
|
||||||
crate::viz_qt::immersive_opened();
|
crate::viz_qt::immersive_opened();
|
||||||
|
crate::viz_qt::set_immersive_view(this.view_mode, this.mode);
|
||||||
// Shader scenes (block A1): the open edge decides the scene. Under
|
// Shader scenes (block A1): the open edge decides the scene. Under
|
||||||
// "remember" it restores the last one (2026-08-19 — the triple above
|
// "remember" it restores the last one (2026-08-19 — the triple above
|
||||||
// never covered the scenes, so Plasma / Ribbon / Line Bed / Tunnel
|
// never covered the scenes, so Plasma / Ribbon / Line Bed / Tunnel
|
||||||
@@ -356,6 +359,7 @@ impl qbz_immersive::QbzImmersive {
|
|||||||
self.as_mut().set_view_mode(view_mode);
|
self.as_mut().set_view_mode(view_mode);
|
||||||
self.as_mut().set_mode(mode);
|
self.as_mut().set_mode(mode);
|
||||||
self.as_mut().set_split_panel(split_panel);
|
self.as_mut().set_split_panel(split_panel);
|
||||||
|
crate::viz_qt::set_immersive_view(view_mode, mode);
|
||||||
if crate::settings_qt::pref_str("immersive_default_view", "remember") == "remember" {
|
if crate::settings_qt::pref_str("immersive_default_view", "remember") == "remember" {
|
||||||
// JSON numbers — co-owned file, Slint declares the keys i32 (see
|
// JSON numbers — co-owned file, Slint declares the keys i32 (see
|
||||||
// apply_open's comment).
|
// apply_open's comment).
|
||||||
|
|||||||
@@ -1997,14 +1997,19 @@ pub(crate) fn large_toggle_visualizer() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Large dock, band click: cycle Bars -> Waveform -> Energy.
|
/// Large dock, band click: cycle Bars -> Waveform -> Energy -> Goniometer ->
|
||||||
|
/// Oscilloscope.
|
||||||
pub(crate) fn large_cycle_spectrum() {
|
pub(crate) fn large_cycle_spectrum() {
|
||||||
let mode = settings_qt::set_large_spectrum_mode((settings_qt::large_spectrum_mode() + 1) % 3);
|
let mode = settings_qt::set_large_spectrum_mode((settings_qt::large_spectrum_mode() + 1) % 5);
|
||||||
|
let height = shell_bridge::large_dock_height(settings_qt::large_visualizer_on());
|
||||||
log::info!("[qbz-qt] large spectrum mode -> {mode}");
|
log::info!("[qbz-qt] large spectrum mode -> {mode}");
|
||||||
// Point the drain at the new stream BEFORE the UI switches, so the first
|
// Point the drain at the new stream BEFORE the UI switches, so the first
|
||||||
// frame the new mode renders already has data.
|
// frame the new mode renders already has data.
|
||||||
viz_qt::set_mode(mode);
|
viz_qt::set_mode(mode);
|
||||||
shell_bridge::ui(move |mut b| b.as_mut().set_large_spectrum_mode(mode));
|
shell_bridge::ui(move |mut b| {
|
||||||
|
b.as_mut().set_large_spectrum_mode(mode);
|
||||||
|
b.as_mut().set_large_dock_height(height);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Artist-network row click: resolve a musician NAME and open the right
|
/// Artist-network row click: resolve a musician NAME and open the right
|
||||||
|
|||||||
@@ -840,7 +840,8 @@ pub fn set_large_visualizer_on(on: bool) -> bool {
|
|||||||
on
|
on
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The band's render mode: 0 Bars / 1 Waveform / 2 Energy.
|
/// The band's render mode: 0 Bars / 1 Waveform / 2 Energy / 3 Goniometer /
|
||||||
|
/// 4 Oscilloscope.
|
||||||
pub fn large_spectrum_mode() -> i32 {
|
pub fn large_spectrum_mode() -> i32 {
|
||||||
let Some(path) = prefs_path() else {
|
let Some(path) = prefs_path() else {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -848,14 +849,17 @@ pub fn large_spectrum_mode() -> i32 {
|
|||||||
std::fs::read_to_string(path)
|
std::fs::read_to_string(path)
|
||||||
.ok()
|
.ok()
|
||||||
.and_then(|text| serde_json::from_str::<serde_json::Value>(&text).ok())
|
.and_then(|text| serde_json::from_str::<serde_json::Value>(&text).ok())
|
||||||
.and_then(|v| v.get("large_spectrum_mode").and_then(serde_json::Value::as_i64))
|
.and_then(|v| {
|
||||||
.map(|m| (m as i32).clamp(0, 2))
|
v.get("large_spectrum_mode")
|
||||||
|
.and_then(serde_json::Value::as_i64)
|
||||||
|
})
|
||||||
|
.map(|m| (m as i32).clamp(0, 4))
|
||||||
.unwrap_or(0)
|
.unwrap_or(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Persist the band mode (clamped 0-2); returns the stored index.
|
/// Persist the band mode (clamped 0-4); returns the stored index.
|
||||||
pub fn set_large_spectrum_mode(mode: i32) -> i32 {
|
pub fn set_large_spectrum_mode(mode: i32) -> i32 {
|
||||||
let mode = mode.clamp(0, 2);
|
let mode = mode.clamp(0, 4);
|
||||||
save_pref(
|
save_pref(
|
||||||
"large_spectrum_mode",
|
"large_spectrum_mode",
|
||||||
serde_json::Value::Number(mode.into()),
|
serde_json::Value::Number(mode.into()),
|
||||||
|
|||||||
@@ -352,6 +352,7 @@ fn is_shipped(scene: i32) -> bool {
|
|||||||
/// notify.
|
/// notify.
|
||||||
pub(crate) fn apply_on_immersive_open() {
|
pub(crate) fn apply_on_immersive_open() {
|
||||||
let target = remembered_scene();
|
let target = remembered_scene();
|
||||||
|
crate::viz_qt::set_immersive_scene_active(target != 0);
|
||||||
ui(move |mut s| {
|
ui(move |mut s| {
|
||||||
if s.scene == target {
|
if s.scene == target {
|
||||||
return;
|
return;
|
||||||
@@ -477,6 +478,7 @@ impl qbz_shader_scene::QbzShaderScene {
|
|||||||
}
|
}
|
||||||
self.as_mut().rust_mut().scene = value;
|
self.as_mut().rust_mut().scene = value;
|
||||||
self.as_mut().scene_changed();
|
self.as_mut().scene_changed();
|
||||||
|
crate::viz_qt::set_immersive_scene_active(value != 0);
|
||||||
if RESTORING.load(Ordering::SeqCst) {
|
if RESTORING.load(Ordering::SeqCst) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -944,13 +944,11 @@ impl Default for QbzShellRust {
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// Large-NPB dock geometry
|
// Large-NPB dock geometry
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// SidebarNowPlayingDock.slint's height formula, verbatim. The cover is square
|
// The cover is square and as wide as the sidebar's content column (240
|
||||||
// and as wide as the sidebar's content column (240 sidebar - 16 left - 16
|
// sidebar - 16 left - 16 right gutters = 208). Legacy spectrum modes use a
|
||||||
// right gutters = 208), so the totals are constants:
|
// compact 42px band; scope modes use the same 208px square as the artwork and
|
||||||
// ON = 9 top pad + 42 band + 10 gap + 208 art + 4 bottom gap = 273
|
// grow upward from their bottom edge. SidebarNowPlayingDock.qml derives its
|
||||||
// OFF = 9 top pad + 208 art + 4 bottom gap = 221
|
// band height from the same mode boundary.
|
||||||
// SidebarNowPlayingDock.qml lays itself out from these SAME numbers — if you
|
|
||||||
// change one, change both, or the cover shifts off the window bottom edge.
|
|
||||||
pub(crate) const DOCK_ART_SIZE: f32 = 208.0;
|
pub(crate) const DOCK_ART_SIZE: f32 = 208.0;
|
||||||
pub(crate) const DOCK_BAND_HEIGHT: f32 = 42.0;
|
pub(crate) const DOCK_BAND_HEIGHT: f32 = 42.0;
|
||||||
pub(crate) const DOCK_PAD_TOP: f32 = 9.0;
|
pub(crate) const DOCK_PAD_TOP: f32 = 9.0;
|
||||||
@@ -961,7 +959,12 @@ pub(crate) const DOCK_BAND_GAP: f32 = 10.0;
|
|||||||
pub(crate) fn large_dock_height(visualizer_on: bool) -> f32 {
|
pub(crate) fn large_dock_height(visualizer_on: bool) -> f32 {
|
||||||
let base = DOCK_PAD_TOP + DOCK_ART_SIZE + DOCK_PAD_BOTTOM;
|
let base = DOCK_PAD_TOP + DOCK_ART_SIZE + DOCK_PAD_BOTTOM;
|
||||||
if visualizer_on {
|
if visualizer_on {
|
||||||
base + DOCK_BAND_HEIGHT + DOCK_BAND_GAP
|
let band_height = if crate::settings_qt::large_spectrum_mode() >= 3 {
|
||||||
|
DOCK_ART_SIZE
|
||||||
|
} else {
|
||||||
|
DOCK_BAND_HEIGHT
|
||||||
|
};
|
||||||
|
base + band_height + DOCK_BAND_GAP
|
||||||
} else {
|
} else {
|
||||||
base
|
base
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,11 @@ pub mod qbz_viz {
|
|||||||
// 256 L samples followed by 256 R (VizFrame::Wave256x2). The dock's
|
// 256 L samples followed by 256 R (VizFrame::Wave256x2). The dock's
|
||||||
// Waveform mode downsamples the L half (indices 0..235 step 5).
|
// Waveform mode downsamples the L half (indices 0..235 step 5).
|
||||||
#[qproperty(QList_f32, waveform)]
|
#[qproperty(QList_f32, waveform)]
|
||||||
|
// Packed x/y mid-side points for the goniometer.
|
||||||
|
#[qproperty(QList_f32, goniometer)]
|
||||||
|
// Pitch-locked mono scope samples.
|
||||||
|
#[qproperty(QList_f32, oscilloscope)]
|
||||||
|
#[qproperty(f32, stereo_correlation)]
|
||||||
type QbzViz = super::QbzVizRust;
|
type QbzViz = super::QbzVizRust;
|
||||||
|
|
||||||
/// Registers this object's Qt-thread hop (Main.qml boots EVERY
|
/// Registers this object's Qt-thread hop (Main.qml boots EVERY
|
||||||
@@ -87,6 +91,7 @@ type QListF32 = QList<f32>;
|
|||||||
pub(crate) const BARS_LEN: usize = 16;
|
pub(crate) const BARS_LEN: usize = 16;
|
||||||
pub(crate) const ENERGY_LEN: usize = 5;
|
pub(crate) const ENERGY_LEN: usize = 5;
|
||||||
pub(crate) const WAVEFORM_LEN: usize = 512;
|
pub(crate) const WAVEFORM_LEN: usize = 512;
|
||||||
|
pub(crate) const SCOPE_LEN: usize = 512;
|
||||||
|
|
||||||
fn zeros(n: usize) -> QListF32 {
|
fn zeros(n: usize) -> QListF32 {
|
||||||
let mut list = QListF32::default();
|
let mut list = QListF32::default();
|
||||||
@@ -101,6 +106,9 @@ pub struct QbzVizRust {
|
|||||||
bars: QListF32,
|
bars: QListF32,
|
||||||
energy: QListF32,
|
energy: QListF32,
|
||||||
waveform: QListF32,
|
waveform: QListF32,
|
||||||
|
goniometer: QListF32,
|
||||||
|
oscilloscope: QListF32,
|
||||||
|
stereo_correlation: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for QbzVizRust {
|
impl Default for QbzVizRust {
|
||||||
@@ -109,6 +117,9 @@ impl Default for QbzVizRust {
|
|||||||
bars: zeros(BARS_LEN),
|
bars: zeros(BARS_LEN),
|
||||||
energy: zeros(ENERGY_LEN),
|
energy: zeros(ENERGY_LEN),
|
||||||
waveform: zeros(WAVEFORM_LEN),
|
waveform: zeros(WAVEFORM_LEN),
|
||||||
|
goniometer: zeros(SCOPE_LEN),
|
||||||
|
oscilloscope: zeros(SCOPE_LEN),
|
||||||
|
stereo_correlation: 0.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+210
-24
@@ -15,7 +15,7 @@
|
|||||||
//! aliasing, and zero idle wakeups (cheaper than the old poll, not just
|
//! aliasing, and zero idle wakeups (cheaper than the old poll, not just
|
||||||
//! smoother).
|
//! smoother).
|
||||||
//!
|
//!
|
||||||
//! Cost controls (the Slint install() has the same three, and they are why the
|
//! Cost controls (the frozen reference install() has the same three, and they are why the
|
||||||
//! ambient field sits under 3% CPU during playback):
|
//! ambient field sits under 3% CPU during playback):
|
||||||
//! 1. The tap starts DISABLED — nothing is captured and the producer idles
|
//! 1. The tap starts DISABLED — nothing is captured and the producer idles
|
||||||
//! until the dock's eye toggle calls `set_enabled(true)`.
|
//! until the dock's eye toggle calls `set_enabled(true)`.
|
||||||
@@ -26,8 +26,10 @@
|
|||||||
//! Plus the mode gate: only the ONE stream the visible mode renders is
|
//! Plus the mode gate: only the ONE stream the visible mode renders is
|
||||||
//! marshalled into a `QList` (in Bars mode the 512-float waveform is latched
|
//! marshalled into a `QList` (in Bars mode the 512-float waveform is latched
|
||||||
//! for an instant mode switch but never published) — UNLESS the immersive
|
//! for an instant mode switch but never published) — UNLESS the immersive
|
||||||
//! overlay is open, which owns the marshalling set and publishes all three
|
//! overlay is open, which owns the legacy marshalling set and publishes bars,
|
||||||
//! streams every frame (§4.2 of the immersive-port contract). Block A1
|
//! energy and waveform every frame (§4.2 of the immersive-port contract).
|
||||||
|
//! The two scope streams are requested independently and only while their
|
||||||
|
//! panel is visible. Block A1
|
||||||
//! (2026-08-15 immersive-completion) extends the immersive set: `Spectral512`
|
//! (2026-08-15 immersive-completion) extends the immersive set: `Spectral512`
|
||||||
//! and `Transient1` are LATCHED too (still never dock-marshalled), and the
|
//! and `Transient1` are LATCHED too (still never dock-marshalled), and the
|
||||||
//! drain derives the shader-scenes uniform pack from them HOST-SIDE
|
//! drain derives the shader-scenes uniform pack from them HOST-SIDE
|
||||||
@@ -49,7 +51,9 @@ use std::sync::{Arc, Mutex, OnceLock};
|
|||||||
use std::thread::Thread;
|
use std::thread::Thread;
|
||||||
|
|
||||||
use cxx_qt_lib::QList;
|
use cxx_qt_lib::QList;
|
||||||
use qbz_audio::visualizer::{spawn_visualizer_thread, VizFrame, VizSink};
|
use qbz_audio::visualizer::{
|
||||||
|
spawn_visualizer_thread, VizFrame, VizSink, GONIOMETER_BIT, OSCILLOSCOPE_BIT,
|
||||||
|
};
|
||||||
use qbz_audio::VisualizerTap;
|
use qbz_audio::VisualizerTap;
|
||||||
|
|
||||||
use crate::viz_bridge;
|
use crate::viz_bridge;
|
||||||
@@ -83,6 +87,8 @@ struct VizCells {
|
|||||||
// (visualizer.rs:146-178).
|
// (visualizer.rs:146-178).
|
||||||
spectral: Mutex<Option<Vec<f32>>>,
|
spectral: Mutex<Option<Vec<f32>>>,
|
||||||
transient: Mutex<Option<f32>>,
|
transient: Mutex<Option<f32>>,
|
||||||
|
goniometer: Mutex<Option<(Box<[f32; 512]>, f32)>>,
|
||||||
|
oscilloscope: Mutex<Option<Box<[f32; 512]>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Producer-side sink: latches frames into the shared cells and signals the
|
/// Producer-side sink: latches frames into the shared cells and signals the
|
||||||
@@ -135,6 +141,17 @@ impl VizSink for QtVizSink {
|
|||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
VizFrame::Goniometer {
|
||||||
|
points,
|
||||||
|
correlation,
|
||||||
|
} => {
|
||||||
|
*self.cells.goniometer.lock().unwrap() = Some((points, correlation));
|
||||||
|
stream_wakes(mode, all, Stream::Goniometer)
|
||||||
|
}
|
||||||
|
VizFrame::Oscilloscope(points) => {
|
||||||
|
*self.cells.oscilloscope.lock().unwrap() = Some(points);
|
||||||
|
stream_wakes(mode, all, Stream::Oscilloscope)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
if wake {
|
if wake {
|
||||||
wake_drain();
|
wake_drain();
|
||||||
@@ -155,7 +172,8 @@ static DRAIN_THREAD: OnceLock<Thread> = OnceLock::new();
|
|||||||
/// This is the EFFECTIVE enable — the OR of the per-source bits in
|
/// This is the EFFECTIVE enable — the OR of the per-source bits in
|
||||||
/// `ENABLED_MASK` (§4.2a); nothing writes it except `apply_effective_enabled`.
|
/// `ENABLED_MASK` (§4.2a); nothing writes it except `apply_effective_enabled`.
|
||||||
static ENABLED: AtomicBool = AtomicBool::new(false);
|
static ENABLED: AtomicBool = AtomicBool::new(false);
|
||||||
/// The band's render mode (0 Bars / 1 Waveform / 2 Energy). The drain only
|
/// The band's render mode (0 Bars / 1 Waveform / 2 Energy / 3 Goniometer /
|
||||||
|
/// 4 Oscilloscope). The drain only
|
||||||
/// publishes the ONE stream that mode consumes: in Bars mode, marshalling the
|
/// publishes the ONE stream that mode consumes: in Bars mode, marshalling the
|
||||||
/// 512-float waveform into a QList 30 times a second would be pure waste.
|
/// 512-float waveform into a QList 30 times a second would be pure waste.
|
||||||
static ACTIVE_MODE: AtomicI32 = AtomicI32::new(0);
|
static ACTIVE_MODE: AtomicI32 = AtomicI32::new(0);
|
||||||
@@ -176,8 +194,13 @@ static ENABLED_MASK: AtomicU32 = AtomicU32::new(0);
|
|||||||
/// bars AND energy AND waveform publish every frame, regardless of
|
/// bars AND energy AND waveform publish every frame, regardless of
|
||||||
/// `ACTIVE_MODE`. Dock mode-cycle writes while it is set still record
|
/// `ACTIVE_MODE`. Dock mode-cycle writes while it is set still record
|
||||||
/// `ACTIVE_MODE` (and the dock's pref) but have no effect on the marshalled
|
/// `ACTIVE_MODE` (and the dock's pref) but have no effect on the marshalled
|
||||||
/// set; the close edge restores `ACTIVE_MODE` from the pref anyway.
|
/// legacy set; the close edge restores `ACTIVE_MODE` from the pref anyway.
|
||||||
|
/// Scope DSP remains visibility-gated by the two scope masks below.
|
||||||
static MARSHAL_ALL: AtomicBool = AtomicBool::new(false);
|
static MARSHAL_ALL: AtomicBool = AtomicBool::new(false);
|
||||||
|
static DOCK_SCOPE_MASK: AtomicU32 = AtomicU32::new(0);
|
||||||
|
static IMMERSIVE_PANEL_SCOPE_MASK: AtomicU32 = AtomicU32::new(0);
|
||||||
|
static IMMERSIVE_SCOPE_MASK: AtomicU32 = AtomicU32::new(0);
|
||||||
|
static IMMERSIVE_SCENE_ACTIVE: AtomicBool = AtomicBool::new(false);
|
||||||
|
|
||||||
/// A consumer of the FFT tap (§4.2a).
|
/// A consumer of the FFT tap (§4.2a).
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
@@ -196,31 +219,73 @@ impl VizSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn mask_with(mask: u32, bit: u32, on: bool) -> u32 {
|
fn mask_with(mask: u32, bit: u32, on: bool) -> u32 {
|
||||||
if on { mask | bit } else { mask & !bit }
|
if on {
|
||||||
|
mask | bit
|
||||||
|
} else {
|
||||||
|
mask & !bit
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mask_enabled(mask: u32) -> bool {
|
fn mask_enabled(mask: u32) -> bool {
|
||||||
mask != 0
|
mask != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The three marshalled streams (the wake table's rows).
|
/// The five dock render streams (the wake table's rows).
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
enum Stream {
|
enum Stream {
|
||||||
Bars,
|
Bars,
|
||||||
Waveform,
|
Waveform,
|
||||||
Energy,
|
Energy,
|
||||||
|
Goniometer,
|
||||||
|
Oscilloscope,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Wake table for the drain signal: marshal-all wakes on EVERY stream;
|
/// Wake table for the drain signal: immersive marshal-all wakes on every
|
||||||
/// otherwise exactly the ONE stream the dock's active mode renders.
|
/// legacy stream; scope frames hitchhike on that cadence. Otherwise exactly
|
||||||
|
/// the ONE stream the dock's active mode renders wakes the drain.
|
||||||
fn stream_wakes(mode: i32, marshal_all: bool, stream: Stream) -> bool {
|
fn stream_wakes(mode: i32, marshal_all: bool, stream: Stream) -> bool {
|
||||||
if marshal_all {
|
if marshal_all && matches!(stream, Stream::Bars | Stream::Waveform | Stream::Energy) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
match stream {
|
match stream {
|
||||||
Stream::Bars => !matches!(mode, 1 | 2),
|
Stream::Bars => mode == 0,
|
||||||
Stream::Waveform => mode == 1,
|
Stream::Waveform => mode == 1,
|
||||||
Stream::Energy => mode == 2,
|
Stream::Energy => mode == 2,
|
||||||
|
Stream::Goniometer => !marshal_all && mode == 3,
|
||||||
|
Stream::Oscilloscope => !marshal_all && mode == 4,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn scope_mask_for_mode(mode: i32) -> u32 {
|
||||||
|
match mode {
|
||||||
|
3 | 7 => GONIOMETER_BIT,
|
||||||
|
4 | 8 => OSCILLOSCOPE_BIT,
|
||||||
|
_ => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn visible_scope_mask(requested: u32, scene_active: bool) -> u32 {
|
||||||
|
if scene_active {
|
||||||
|
0
|
||||||
|
} else {
|
||||||
|
requested
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn apply_immersive_scope_mask() {
|
||||||
|
let mask = visible_scope_mask(
|
||||||
|
IMMERSIVE_PANEL_SCOPE_MASK.load(Ordering::Relaxed),
|
||||||
|
IMMERSIVE_SCENE_ACTIVE.load(Ordering::Relaxed),
|
||||||
|
);
|
||||||
|
IMMERSIVE_SCOPE_MASK.store(mask, Ordering::Relaxed);
|
||||||
|
apply_scope_mask();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn apply_scope_mask() {
|
||||||
|
if let Some(handles) = HANDLES.get() {
|
||||||
|
handles.tap.set_scope_mask(
|
||||||
|
DOCK_SCOPE_MASK.load(Ordering::Relaxed) | IMMERSIVE_SCOPE_MASK.load(Ordering::Relaxed),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -418,13 +483,24 @@ fn publish_active(cells: &VizCells, pack: &mut ShaderPackState, linebed: &mut li
|
|||||||
if let Some(b) = waveform {
|
if let Some(b) = waveform {
|
||||||
viz_bridge::ui(move |mut v| v.as_mut().set_waveform(to_qlist(b.as_ref())));
|
viz_bridge::ui(move |mut v| v.as_mut().set_waveform(to_qlist(b.as_ref())));
|
||||||
}
|
}
|
||||||
|
let goniometer = cells.goniometer.lock().unwrap().take();
|
||||||
|
if let Some((points, correlation)) = goniometer {
|
||||||
|
viz_bridge::ui(move |mut v| {
|
||||||
|
v.as_mut().set_goniometer(to_qlist(points.as_ref()));
|
||||||
|
v.as_mut().set_stereo_correlation(correlation);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let oscilloscope = cells.oscilloscope.lock().unwrap().take();
|
||||||
|
if let Some(points) = oscilloscope {
|
||||||
|
viz_bridge::ui(move |mut v| {
|
||||||
|
v.as_mut().set_oscilloscope(to_qlist(points.as_ref()));
|
||||||
|
});
|
||||||
|
}
|
||||||
// A1: the scene-only streams, latched by the sink without waking.
|
// A1: the scene-only streams, latched by the sink without waking.
|
||||||
let spectral = cells.spectral.lock().unwrap().take();
|
let spectral = cells.spectral.lock().unwrap().take();
|
||||||
let transient = cells.transient.lock().unwrap().take();
|
let transient = cells.transient.lock().unwrap().take();
|
||||||
if fresh_frame {
|
if fresh_frame {
|
||||||
crate::shader_scene_bridge::publish_pack(
|
crate::shader_scene_bridge::publish_pack(pack.tick(transient, spectral.as_deref()));
|
||||||
pack.tick(transient, spectral.as_deref()),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// A4 (Line Bed, mode 5): push the SAME latched Spectral512 frame
|
// A4 (Line Bed, mode 5): push the SAME latched Spectral512 frame
|
||||||
// into the depth ring (fresh frames only, like the reference's
|
// into the depth ring (fresh frames only, like the reference's
|
||||||
@@ -471,6 +547,23 @@ fn publish_active(cells: &VizCells, pack: &mut ShaderPackState, linebed: &mut li
|
|||||||
viz_bridge::ui(move |mut v| v.as_mut().set_energy(to_qlist(&b)));
|
viz_bridge::ui(move |mut v| v.as_mut().set_energy(to_qlist(&b)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3 => {
|
||||||
|
let frame = cells.goniometer.lock().unwrap().take();
|
||||||
|
if let Some((points, correlation)) = frame {
|
||||||
|
viz_bridge::ui(move |mut v| {
|
||||||
|
v.as_mut().set_goniometer(to_qlist(points.as_ref()));
|
||||||
|
v.as_mut().set_stereo_correlation(correlation);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
4 => {
|
||||||
|
let frame = cells.oscilloscope.lock().unwrap().take();
|
||||||
|
if let Some(points) = frame {
|
||||||
|
viz_bridge::ui(move |mut v| {
|
||||||
|
v.as_mut().set_oscilloscope(to_qlist(points.as_ref()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let frame = cells.bars.lock().unwrap().take();
|
let frame = cells.bars.lock().unwrap().take();
|
||||||
if let Some(b) = frame {
|
if let Some(b) = frame {
|
||||||
@@ -489,6 +582,11 @@ pub fn install(tap: VisualizerTap) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The startup macro is normally sufficient, but the explicit symbol
|
||||||
|
// reference keeps the custom item linked from static archives on every
|
||||||
|
// platform and guarantees registration before the QML module loads.
|
||||||
|
register_scope_qml_item();
|
||||||
|
|
||||||
let cells = Arc::new(VizCells::default());
|
let cells = Arc::new(VizCells::default());
|
||||||
|
|
||||||
// The drain: park until the sink says a frame of the visible stream is
|
// The drain: park until the sink says a frame of the visible stream is
|
||||||
@@ -543,6 +641,13 @@ pub fn install(tap: VisualizerTap) {
|
|||||||
/// a tap the other consumer still needs.
|
/// a tap the other consumer still needs.
|
||||||
pub fn set_enabled(on: bool) {
|
pub fn set_enabled(on: bool) {
|
||||||
set_enabled_source(VizSource::Dock, on);
|
set_enabled_source(VizSource::Dock, on);
|
||||||
|
let mask = if on {
|
||||||
|
scope_mask_for_mode(ACTIVE_MODE.load(Ordering::Relaxed))
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
DOCK_SCOPE_MASK.store(mask, Ordering::Relaxed);
|
||||||
|
apply_scope_mask();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// §4.2a two-source enable: set one consumer's bit; the EFFECTIVE enable is
|
/// §4.2a two-source enable: set one consumer's bit; the EFFECTIVE enable is
|
||||||
@@ -604,6 +709,9 @@ pub(crate) fn immersive_opened() {
|
|||||||
/// while immersive was open already updated it via
|
/// while immersive was open already updated it via
|
||||||
/// `settings_qt::set_large_spectrum_mode`).
|
/// `settings_qt::set_large_spectrum_mode`).
|
||||||
pub(crate) fn immersive_closed() {
|
pub(crate) fn immersive_closed() {
|
||||||
|
IMMERSIVE_PANEL_SCOPE_MASK.store(0, Ordering::Relaxed);
|
||||||
|
IMMERSIVE_SCOPE_MASK.store(0, Ordering::Relaxed);
|
||||||
|
apply_scope_mask();
|
||||||
set_enabled_source(VizSource::Immersive, false);
|
set_enabled_source(VizSource::Immersive, false);
|
||||||
MARSHAL_ALL.store(false, Ordering::Relaxed);
|
MARSHAL_ALL.store(false, Ordering::Relaxed);
|
||||||
set_mode(crate::settings_qt::large_spectrum_mode());
|
set_mode(crate::settings_qt::large_spectrum_mode());
|
||||||
@@ -612,7 +720,18 @@ pub(crate) fn immersive_closed() {
|
|||||||
/// Point the drain at the stream the band is actually rendering. Called at
|
/// Point the drain at the stream the band is actually rendering. Called at
|
||||||
/// install time (from the persisted pref) and on every mode cycle.
|
/// install time (from the persisted pref) and on every mode cycle.
|
||||||
pub fn set_mode(mode: i32) {
|
pub fn set_mode(mode: i32) {
|
||||||
ACTIVE_MODE.store(mode.clamp(0, 2), Ordering::Relaxed);
|
let mode = mode.clamp(0, 4);
|
||||||
|
ACTIVE_MODE.store(mode, Ordering::Relaxed);
|
||||||
|
let dock_visible = ENABLED_MASK.load(Ordering::Relaxed) & DOCK_BIT != 0;
|
||||||
|
DOCK_SCOPE_MASK.store(
|
||||||
|
if dock_visible {
|
||||||
|
scope_mask_for_mode(mode)
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
},
|
||||||
|
Ordering::Relaxed,
|
||||||
|
);
|
||||||
|
apply_scope_mask();
|
||||||
// The new stream may already have a frame latched from before the switch;
|
// The new stream may already have a frame latched from before the switch;
|
||||||
// publish it now instead of showing the old mode's last frame until the
|
// publish it now instead of showing the old mode's last frame until the
|
||||||
// producer's next tick (and it is what unblocks a switch made while the
|
// producer's next tick (and it is what unblocks a switch made while the
|
||||||
@@ -622,6 +741,36 @@ pub fn set_mode(mode: i32) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update the scope requested by the active immersive FOCUS panel. Split
|
||||||
|
/// layouts and every existing FOCUS mode leave both scope producers idle.
|
||||||
|
pub(crate) fn set_immersive_view(view_mode: i32, mode: i32) {
|
||||||
|
let mask = if MARSHAL_ALL.load(Ordering::Relaxed) && view_mode == 0 {
|
||||||
|
scope_mask_for_mode(mode)
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
IMMERSIVE_PANEL_SCOPE_MASK.store(mask, Ordering::Relaxed);
|
||||||
|
apply_immersive_scope_mask();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A shader scene replaces every FOCUS panel. Keep the desired scope mode so
|
||||||
|
/// returning to the panel is instant, but disable its DSP and Qt publishes
|
||||||
|
/// while the scene is covering it.
|
||||||
|
pub(crate) fn set_immersive_scene_active(active: bool) {
|
||||||
|
IMMERSIVE_SCENE_ACTIVE.store(active, Ordering::Relaxed);
|
||||||
|
apply_immersive_scope_mask();
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
fn qbz_scope_trace_register_qml_type();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn register_scope_qml_item() {
|
||||||
|
// SAFETY: no arguments; registration is guarded and occurs before QML is
|
||||||
|
// loaded. The explicit reference also keeps the static-library object.
|
||||||
|
unsafe { qbz_scope_trace_register_qml_type() };
|
||||||
|
}
|
||||||
|
|
||||||
/// Mirror the transport onto the tap so a paused player parks the producer.
|
/// Mirror the transport onto the tap so a paused player parks the producer.
|
||||||
/// Called from the playback path on every playing-state flip (the Slint side
|
/// Called from the playback path on every playing-state flip (the Slint side
|
||||||
/// does this from playback.rs).
|
/// does this from playback.rs).
|
||||||
@@ -668,11 +817,18 @@ mod tests {
|
|||||||
assert!(!mask_enabled(none));
|
assert!(!mask_enabled(none));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The pre-immersive wake table: exactly ONE stream per dock mode.
|
/// The dock wake table: exactly ONE stream per render mode.
|
||||||
#[test]
|
#[test]
|
||||||
fn single_stream_wake_table() {
|
fn single_stream_wake_table() {
|
||||||
for mode in 0..=2 {
|
let streams = [
|
||||||
let wakes: Vec<bool> = [Stream::Bars, Stream::Waveform, Stream::Energy]
|
Stream::Bars,
|
||||||
|
Stream::Waveform,
|
||||||
|
Stream::Energy,
|
||||||
|
Stream::Goniometer,
|
||||||
|
Stream::Oscilloscope,
|
||||||
|
];
|
||||||
|
for mode in 0..=4 {
|
||||||
|
let wakes: Vec<bool> = streams
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|s| stream_wakes(mode, false, s))
|
.map(|s| stream_wakes(mode, false, s))
|
||||||
.collect();
|
.collect();
|
||||||
@@ -681,20 +837,35 @@ mod tests {
|
|||||||
assert!(stream_wakes(0, false, Stream::Bars));
|
assert!(stream_wakes(0, false, Stream::Bars));
|
||||||
assert!(stream_wakes(1, false, Stream::Waveform));
|
assert!(stream_wakes(1, false, Stream::Waveform));
|
||||||
assert!(stream_wakes(2, false, Stream::Energy));
|
assert!(stream_wakes(2, false, Stream::Energy));
|
||||||
|
assert!(stream_wakes(3, false, Stream::Goniometer));
|
||||||
|
assert!(stream_wakes(4, false, Stream::Oscilloscope));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// §4.2b: marshal-all wakes on EVERY stream regardless of ACTIVE_MODE —
|
/// §4.2b: marshal-all wakes on every legacy stream regardless of
|
||||||
/// which is also why dock mode-cycle writes while immersive is open have
|
/// ACTIVE_MODE. Scope frames hitchhike on that fixed cadence, avoiding
|
||||||
/// no effect on the marshalled set.
|
/// extra drain wakeups while immersive is open.
|
||||||
#[test]
|
#[test]
|
||||||
fn marshal_all_wakes_every_stream() {
|
fn marshal_all_wakes_every_stream() {
|
||||||
for mode in 0..=2 {
|
for mode in 0..=2 {
|
||||||
for s in [Stream::Bars, Stream::Waveform, Stream::Energy] {
|
for s in [Stream::Bars, Stream::Waveform, Stream::Energy] {
|
||||||
assert!(stream_wakes(mode, true, s), "mode {mode} stream {s:?}");
|
assert!(stream_wakes(mode, true, s), "mode {mode} stream {s:?}");
|
||||||
}
|
}
|
||||||
|
assert!(!stream_wakes(mode, true, Stream::Goniometer));
|
||||||
|
assert!(!stream_wakes(mode, true, Stream::Oscilloscope));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn shader_scene_suppresses_hidden_scope() {
|
||||||
|
assert_eq!(visible_scope_mask(GONIOMETER_BIT, false), GONIOMETER_BIT);
|
||||||
|
assert_eq!(
|
||||||
|
visible_scope_mask(OSCILLOSCOPE_BIT, false),
|
||||||
|
OSCILLOSCOPE_BIT
|
||||||
|
);
|
||||||
|
assert_eq!(visible_scope_mask(GONIOMETER_BIT, true), 0);
|
||||||
|
assert_eq!(visible_scope_mask(OSCILLOSCOPE_BIT, true), 0);
|
||||||
|
}
|
||||||
|
|
||||||
/// The hooks against the REAL statics (kept in ONE test so parallel test
|
/// The hooks against the REAL statics (kept in ONE test so parallel test
|
||||||
/// threads cannot race the shared atomics): open sets the immersive bit +
|
/// threads cannot race the shared atomics): open sets the immersive bit +
|
||||||
/// marshal-all; close clears both and restores ACTIVE_MODE from the
|
/// marshal-all; close clears both and restores ACTIVE_MODE from the
|
||||||
@@ -702,19 +873,33 @@ mod tests {
|
|||||||
/// application is a no-op and only the masks/flags move.
|
/// application is a no-op and only the masks/flags move.
|
||||||
#[test]
|
#[test]
|
||||||
fn immersive_hooks_switch_and_restore() {
|
fn immersive_hooks_switch_and_restore() {
|
||||||
|
// Selecting a scope while the dock is hidden only records the mode;
|
||||||
|
// its DSP request stays off until the dock becomes visible.
|
||||||
|
set_mode(3);
|
||||||
|
assert_eq!(DOCK_SCOPE_MASK.load(Ordering::Relaxed), 0);
|
||||||
|
|
||||||
// Dock was on (the common case: dock drives the tap, then immersive
|
// Dock was on (the common case: dock drives the tap, then immersive
|
||||||
// opens on top).
|
// opens on top).
|
||||||
set_enabled(true);
|
set_enabled(true);
|
||||||
assert_eq!(ENABLED_MASK.load(Ordering::Relaxed), DOCK_BIT);
|
assert_eq!(ENABLED_MASK.load(Ordering::Relaxed), DOCK_BIT);
|
||||||
|
assert_eq!(DOCK_SCOPE_MASK.load(Ordering::Relaxed), GONIOMETER_BIT);
|
||||||
|
|
||||||
immersive_opened();
|
immersive_opened();
|
||||||
assert!(MARSHAL_ALL.load(Ordering::Relaxed));
|
assert!(MARSHAL_ALL.load(Ordering::Relaxed));
|
||||||
assert_eq!(ENABLED_MASK.load(Ordering::Relaxed), DOCK_BIT | IMMERSIVE_BIT);
|
assert_eq!(
|
||||||
|
ENABLED_MASK.load(Ordering::Relaxed),
|
||||||
|
DOCK_BIT | IMMERSIVE_BIT
|
||||||
|
);
|
||||||
|
|
||||||
// A dock mode-cycle while immersive is open records ACTIVE_MODE but
|
// A dock mode-cycle while immersive is open records ACTIVE_MODE but
|
||||||
// the wake table stays all-three (marshal-all short-circuits it).
|
// the wake table stays all-three (marshal-all short-circuits it).
|
||||||
set_mode(2);
|
set_mode(2);
|
||||||
assert!(stream_wakes(2, MARSHAL_ALL.load(Ordering::Relaxed), Stream::Bars));
|
assert_eq!(DOCK_SCOPE_MASK.load(Ordering::Relaxed), 0);
|
||||||
|
assert!(stream_wakes(
|
||||||
|
2,
|
||||||
|
MARSHAL_ALL.load(Ordering::Relaxed),
|
||||||
|
Stream::Bars
|
||||||
|
));
|
||||||
|
|
||||||
immersive_closed();
|
immersive_closed();
|
||||||
assert!(!MARSHAL_ALL.load(Ordering::Relaxed));
|
assert!(!MARSHAL_ALL.load(Ordering::Relaxed));
|
||||||
@@ -729,6 +914,7 @@ mod tests {
|
|||||||
// Leave the statics as found for any later test in the process.
|
// Leave the statics as found for any later test in the process.
|
||||||
set_enabled(false);
|
set_enabled(false);
|
||||||
assert_eq!(ENABLED_MASK.load(Ordering::Relaxed), 0);
|
assert_eq!(ENABLED_MASK.load(Ordering::Relaxed), 0);
|
||||||
|
assert_eq!(DOCK_SCOPE_MASK.load(Ordering::Relaxed), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- A1: the shader-pack derivation (visualizer.rs:203-269 parity) -----
|
// --- A1: the shader-pack derivation (visualizer.rs:203-269 parity) -----
|
||||||
|
|||||||
Reference in new issue
Block a user