From 29e0ac75f7ec3b2a9bdd60b194c87ad392fd7c7b Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Sat, 13 Jun 2026 09:07:20 -0600 Subject: [PATCH] feat(slint): immersive Spectrum Visualizer mode (mode 3) - 16-bar mirrored cube spectrum New SpectrumPanel.slint: faithful port of VisualizerPanel.svelte (the 16-bar spectrum, not SpectralRibbon/Oscilloscope/LineBed). - 16 source bars, bins {1,15} excluded -> 14 active -> 28 mirrored columns. Geometry exact to source: bar-gap 4, total-bar-width W/28, baseY 0.85H, maxBarHeight 0.7H, xLeft/xRight per spec. - Discrete 6px+2px cubelets with per-cubelet gradient (gradientRatio min(c/20,1), primary->secondary). GPU path (ADR-011); CPU flat fallback not ported (Slint is GPU by default). - Heights driven by VisualizerState.bars (bounds-safe clamp, 30fps len-16 VecModel) + a short animate settle - NO Timer. Bars already smoothed+clamped in qbz-audio (no double-EMA). Now-playing card reuses the sibling pattern. - Mounted on mode==3; modes 0/1/2 untouched. Logged minors: MAX_CUBES=80 clips full-amplitude bars on very tall / 4K windows (raise as a cheap follow-up); two-color gradient ships the Svelte default cyan->purple (no album-derived secondary color wired yet); smoothing is the Rust asymmetric EMA, not the Svelte symmetric 0.6 (deliberate, shared pipeline). cc --- .../ui/immersive/ImmersiveView.slint | 15 +- .../ui/immersive/SpectrumPanel.slint | 279 ++++++++++++++++++ 2 files changed, 293 insertions(+), 1 deletion(-) create mode 100644 crates/qbz-slint/ui/immersive/SpectrumPanel.slint diff --git a/crates/qbz-slint/ui/immersive/ImmersiveView.slint b/crates/qbz-slint/ui/immersive/ImmersiveView.slint index c34caa3f5..1c8dce641 100644 --- a/crates/qbz-slint/ui/immersive/ImmersiveView.slint +++ b/crates/qbz-slint/ui/immersive/ImmersiveView.slint @@ -9,6 +9,7 @@ import { ImmersiveAtmosphere } from "ImmersiveAtmosphere.slint"; import { AlbumReactivePanel } from "AlbumReactivePanel.slint"; import { StaticPanel } from "StaticPanel.slint"; import { CoverflowPanel } from "CoverflowPanel.slint"; +import { SpectrumPanel } from "SpectrumPanel.slint"; component GhostButton inherits Rectangle { in property icon; @@ -580,7 +581,19 @@ export component ImmersiveView inherits Rectangle { viewport-width: root.width; viewport-height: root.height; } - // TODO(S5): Spectrum mode foreground (mode == 3) — atmosphere-only for now. + // (2d) Spectrum mode foreground (mode == 3) — faithful 16-bar mirrored cube + // spectrum (14 active bins x 2 mirror = 28 columns) over a solid-black + // canvas, with the same centered now-playing card as the siblings. Reads + // VisualizerState.bars (pre-smoothed + clamped in Rust). set-enabled is + // ALREADY driven on open (the mode-0 AlbumReactivePanel reads + // VisualizerState.energy from the same enabled tap). Same conditional-mount + + // viewport-prop contract as the siblings (ADR-010). + if ImmersiveState.mode == 3: SpectrumPanel { + x: 0px; + y: 0px; + viewport-width: root.width; + viewport-height: root.height; + } // (3) Auto-hide compact player. ImmersivePlayerBar { diff --git a/crates/qbz-slint/ui/immersive/SpectrumPanel.slint b/crates/qbz-slint/ui/immersive/SpectrumPanel.slint new file mode 100644 index 000000000..2a29d20a5 --- /dev/null +++ b/crates/qbz-slint/ui/immersive/SpectrumPanel.slint @@ -0,0 +1,279 @@ +// Spectrum foreground (Immersive mode 3) — a faithful port of the Tauri +// `src/lib/components/immersive/panels/VisualizerPanel.svelte` (the 16-bar +// "Spectrum" panel; modeList maps Spectrum -> that file). +// +// THE 16-BAR MIRRORED CUBE SPECTRUM. Backend publishes NUM_BARS=16 to +// VisualizerState.bars. The Svelte panel EXCLUDES bins {1, 15}, leaving +// ACTIVE_BIN_INDICES = [0,2,3,4,5,6,7,8,9,10,11,12,13,14] (14 active bins). +// The layout is MIRRORED about the vertical center: visualBars = 14*2 = 28 +// columns. Each active bin i draws TWO stacks — a LEFT column at index i and a +// RIGHT (mirror) column at (28-1-i) — both reading the SAME source bin. The +// stale in-code Svelte comment says "32 visual bars"; the real post-exclusion +// count is 28 (recon visualizers.md:101-103). Use 28. +// +// GEOMETRY (Svelte 197-209): barGap=4px, totalBarWidth = canvasW/28, +// barWidth = totalBarWidth-4. xLeft(i) = i*totalBarWidth + barGap/2. +// xRight(i) = canvasW - (i+1)*totalBarWidth + barGap/2. baseY = 0.85*H (bars +// grow UP), maxBarHeight = 0.7*H. Bars are STACKS OF DISCRETE CUBELETS: +// cubeHeight=6px (GPU/hwaccel — Slint is GPU by default, ADR-011), cubeGap=2px, +// no corner radius. cube j (0-based) top Y = baseY - (j+1)*(cubeH+cubeGap). +// numCubes = floor(barHeight / (cubeH+cubeGap)). +// +// COLORS (Svelte 68-119, 210-254): GPU path = per-cubelet vertical gradient. +// gradientRatio(j) = min(j/20, 1). channel = primary + ratio*(secondary-primary) +// — fades from PRIMARY at the base to SECONDARY at j>=20, identical left/right. +// The album-derived two-color extraction is NOT published to Slint (only a +// single ImmersiveState.glow-color exists), so v1 ships the Svelte DEFAULTS: +// primary = cyan rgb(0,220,200), secondary = purple rgb(150,50,255). Full +// album-color parity is a flagged Rust follow-up (publish primary/secondary), +// NOT a blocker. +// +// NO PEAK CAPS (peak-hold belongs to SpectralRibbon, out of scope — do NOT add). +// +// SMOOTHING (CRITICAL parity note): the Svelte panel applies a symmetric 0.6 +// EMA in JS, but the Slint pipeline ALREADY smooths in Rust — qbz-audio +// processor.rs:150-161 runs an ASYMMETRIC EMA (fast attack 0.7 rising / slow +// decay 0.6 falling) on the 16 bars and clamps 0..1 (processor.rs:321) BEFORE +// publishing. So VisualizerState.bars arrive pre-smoothed AND pre-clamped. We +// bind them RAW (no second EMA — that would double-smooth) and add only a short +// `animate height`/`animate threshold` for inter-frame settle. This is a +// documented parity deviation (Slint Rust attack/decay != Svelte symmetric 0.6) +// — it is the EXISTING shared pipeline AlbumReactivePanel already depends on and +// must NOT be touched here. +// +// OPAQUE BLACK: unlike Static/AlbumReactive (transparent over the atmosphere), +// the Svelte .visualizer-panel paints solid #000000, so mode 3 HIDES the +// atmosphere (intended faithful behavior). The root background is #000000. +// +// `parent` is NEVER read in the root binding (Slint gotcha); viewport dims are +// passed in. `opacity:` is NEVER set on the root or on any container holding the +// hand-positioned cubelets (it corrupts absolute positioning) — the chrome fade +// lives on the player/ModeBar. Cube count/visibility is driven ONLY from the +// bound model value (never a `changed x/y/width/height` handler) to avoid the +// "Recursion detected" panic. + +import { QualityBadgeFull } from "../primitives/QualityBadgeFull.slint"; +import { NowPlayingState, VisualizerState } from "../state.slint"; + +// One mirrored pair of cube stacks for a single active source bin. Draws the +// LEFT column at `x-left` and the RIGHT (mirror) column at `x-right`, both from +// the same amplitude. Hand-positioned cubelets; a fixed MAX_CUBES with +// `visible: idx < num-cubes` (no model churn, no geometry watchers). +component BarPair inherits Rectangle { + // Geometry passed in from the panel (computed from viewport-width). + in property x-left; + in property x-right; + in property bar-width; + in property base-y; + in property max-bar-height; + // 0..1 amplitude for this bin (already smoothed + clamped in Rust). + in property amp; + // Fixed index array [0..MAX_CUBES-1] supplied once by the panel; iterated + // with `visible: c < shown-cubes` so the model never churns. + in property <[int]> cube-indices; + + // Cube metrics (GPU/hwaccel path): 6px cube + 2px gap = 8px unit. + property cube-h: 6px; + property cube-gap: 2px; + property cube-unit: 8px; // cube-h + cube-gap + + // barHeight = amp * maxBarHeight; numCubes = floor(barHeight / cubeUnit). + property bar-height: root.amp * root.max-bar-height; + // Animated cube threshold for an inter-frame settle (NOT a re-smooth — the + // Rust EMA already smoothed the data; this only eases the discrete step). + property shown-cubes: Math.floor(root.bar-height / root.cube-unit); + animate shown-cubes { duration: 90ms; easing: ease; } + + // Default-color gradient (Svelte defaults): cyan primary -> purple secondary. + // gradientRatio(c) = min(c/20, 1). channel = primary + ratio*(secondary-primary). + // primary = rgb(0,220,200) secondary = rgb(150,50,255). + pure function cube-color(c: int) -> color { + return rgb( + 0 + Math.min(c / 20.0, 1.0) * (150 - 0), + 220 + Math.min(c / 20.0, 1.0) * (50 - 220), + 200 + Math.min(c / 20.0, 1.0) * (255 - 200)); + } + + width: 0px; // purely a positioning host; children are absolute. + height: 0px; + + // LEFT column. + for c in root.cube-indices: Rectangle { + x: root.x-left; + // cube top-left Y = baseY - (c+1)*(cubeH+cubeGap). + y: root.base-y - (c + 1) * root.cube-unit; + width: root.bar-width; + height: root.cube-h; + background: root.cube-color(c); + visible: c < root.shown-cubes; + } + + // RIGHT (mirror) column — same source bin, same per-cube color. + for c in root.cube-indices: Rectangle { + x: root.x-right; + y: root.base-y - (c + 1) * root.cube-unit; + width: root.bar-width; + height: root.cube-h; + background: root.cube-color(c); + visible: c < root.shown-cubes; + } +} + +export component SpectrumPanel inherits Rectangle { + in property viewport-width: 1280px; + in property viewport-height: 720px; + + width: root.viewport-width; + height: root.viewport-height; + // Solid black — the Svelte .visualizer-panel is opaque #000000 (hides the + // atmosphere behind it; intended faithful behavior). + background: #000000; + + // --- Bars geometry (Svelte 197-209) ----------------------------------- + // 28 visual columns = 14 active bins x 2 (mirror). + property visual-bars: 28; + property bar-gap: 4px; + property total-bar-width: root.viewport-width / 28; + property bar-width: root.total-bar-width - 4px; + property base-y: root.viewport-height * 0.85; + property max-bar-height: root.viewport-height * 0.7; + + // Active SOURCE bins after excluding {1, 15} (length 14). for src[i] iterates + // these; the LEFT column sits at visual index i, the RIGHT at (28-1-i). + property <[int]> active-bins: [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]; + + // Fixed cube-index array (length MAX_CUBES). MAX_CUBES = 80 covers + // maxBarHeight up to ~640px (viewport-height ~915px) with the 8px unit; + // beyond that the tallest cubes simply don't render (visible:false), no + // panic, no churn. NEVER drive cube count from a geometry-changed handler. + property <[int]> cube-indices: [ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, + 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, + 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, + 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, + 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, + 70, 71, 72, 73, 74, 75, 76, 77, 78, 79 + ]; + + // --- Bars (drawn FIRST, behind the song card) -------------------------- + // One BarPair per active bin; each draws its own left + mirrored-right + // stack. The amplitude is read with a SAFE bounds check (bars may be the + // initial all-zeros len-16 model, or ever swapped) — fallback 0.0 = flat + // baseline, no index-out-of-range. + for src[i] in root.active-bins: BarPair { + x: 0px; + y: 0px; + x-left: i * root.total-bar-width + root.bar-gap / 2; + x-right: root.viewport-width - (i + 1) * root.total-bar-width + root.bar-gap / 2; + bar-width: root.bar-width; + base-y: root.base-y; + max-bar-height: root.max-bar-height; + cube-indices: root.cube-indices; + amp: VisualizerState.bars.length > src + ? Math.max(0.0, Math.min(1.0, VisualizerState.bars[src])) + : 0.0; + } + + // --- Song card (drawn SECOND, in front of the bars) -------------------- + // Same now-playing pattern as StaticPanel.slint / AlbumReactivePanel.slint + // (artwork + title + artist + album-if-present + QualityBadgeFull), centered + // over the black bars canvas. No atmosphere blur here — the bars fill the + // whole panel behind the card. Player clearance (132px padding-bottom) is + // KEPT IDENTICAL to the siblings so the quality badge never clips under the + // floating ImmersivePlayerBar. + // + // Artwork is smaller than the Static/Album card (the Spectrum card is + // secondary to the bars): max(160px, min(min(0.45*H, 0.5*W), 360px)). + property art-size: Math.max(160px, + Math.min(Math.min(root.viewport-height * 0.45, root.viewport-width * 0.5), 360px)); + + VerticalLayout { + x: 0px; + y: 0px; + width: root.viewport-width; + height: root.viewport-height; + padding-top: 70px; + padding-bottom: 132px; + alignment: center; + spacing: 20px; + + // --- Artwork ------------------------------------------------------ + artwork-block := Rectangle { + height: root.art-size; + horizontal-stretch: 1; + + art := Rectangle { + width: root.art-size; + height: root.art-size; + x: (parent.width - self.width) / 2; + y: (parent.height - self.height) / 2; + border-radius: 8px; + clip: true; + // Halo box-shadow (Svelte .now-playing-card artwork). The two- + // layer CSS shadow collapses to one blur in Slint (same accepted + // gap as the siblings). + drop-shadow-blur: 36px; + drop-shadow-color: #00000099; + drop-shadow-offset-y: 8px; + + Image { + source: NowPlayingState.artwork-large.width > 0 + ? NowPlayingState.artwork-large + : NowPlayingState.artwork; + image-fit: cover; + width: parent.width; + height: parent.height; + } + } + } + + // --- Track info --------------------------------------------------- + info-block := VerticalLayout { + alignment: center; + spacing: 6px; + + // Track title. (Explicit badge OMITTED — NowPlayingState has no + // `explicit` field; consistent with the sibling panels.) + Text { + text: NowPlayingState.title; + color: #ffffff; + font-size: 28px; + font-weight: 700; + horizontal-alignment: center; + overflow: elide; + } + + // Artist. + Text { + text: NowPlayingState.artist; + color: #ffffffb3; + font-size: 18px; + horizontal-alignment: center; + overflow: elide; + } + + // Album (italic, dimmer). Shown only when present. + if NowPlayingState.album != "": Text { + text: NowPlayingState.album; + color: #ffffff80; + font-size: 14px; + font-italic: true; + horizontal-alignment: center; + overflow: elide; + } + + // Quality badge (Svelte QualityBadgeStatic full). Self-hides when + // tier == "". Centered under the text. + HorizontalLayout { + alignment: center; + padding-top: 12px; + QualityBadgeFull { + tier: NowPlayingState.quality-tier; + detail: NowPlayingState.quality-detail; + } + } + } + } +}