Files
qbz/crates/qbz-slint/ui/immersive/AlbumReactivePanel.slint
T
vicrodh 85b02417be feat(slint): immersive views polish — 50/50 split, no glass, sharp art, default-view
Split layout is a true 50/50 (explicit half-widths; the horizontal-stretch weights skewed it because the left's intrinsic content out-measured the right). Removed the glass backing plates from the split panel and the song-data metadata block — both sit directly on the atmosphere now.

Cover art no longer upscales blurry on large windows: the now-playing large cover decodes at 1000px (was 300, the hover-preview size) so the full Qobuz source resolution comes through, and the split / Static / Album-Reactive panels cap the art at its native size so it grows sharply instead of stretching.

New Settings > Appearance 'Immersive default view': 'Remember last' restores the last view, or pin Album Reactive / Static / Coverflow / Spectrum / Lyrics / Queue. Persisted via ui_prefs + ImmersiveActions opened/view-changed hooks.

cc
2026-06-20 19:45:16 -06:00

179 lines
9.4 KiB
Plaintext

// Album Reactive foreground — a faithful port of the Tauri
// `src/lib/components/immersive/panels/AlbumReactivePanel.svelte` (387 lines).
//
// Every reactive element maps 1:1 to the Svelte source:
// globalEnergy = avg(energy[0..5]) (Svelte init() line 116)
// bassEnergy = avg(energy[0], energy[1]) (Svelte init() line 117)
// artScale = 1 + globalEnergy * 0.25 (Svelte $derived line 165)
// glowSpread = 15 + bassEnergy * 200 (px) (Svelte $derived line 166)
// glowOpacity = min(0.1 + globalEnergy*1.5,1)(Svelte $derived line 167)
// glowColor = ImmersiveState.glow-color (Svelte extractGlowColor;
// the Rust crate::immersive::glow_color is the SAME algorithm,
// published to ImmersiveState.glow-color from playback.rs)
//
// Energy smoothing: the Svelte panel runs an asymmetric EMA (fast attack 0.9,
// slower decay 0.4) on the raw bands. The raw averaged bands are bound here and
// the visual settle is reproduced by 100ms property `animate`s — matching the
// Svelte CSS `transition: transform/box-shadow/opacity 100ms ease`. (Exact EMA
// parity is a Rust-side follow-up, flagged in the handoff risks; it must NOT
// touch the audio path.)
//
// Speaker-cone pulse (NO lateral movement): Tauri scales the art with
// `transform: scale(artScale)`, which is intrinsically center-anchored — the
// art grows/shrinks in place like a vibrating loudspeaker cone, never sliding
// sideways. Slint has no `transform: scale` on a clipped Image, so we animate
// width/height instead and recompute the centering x/y from the live size.
// CRITICAL: x/y are NOT animated. Animating x/y put the centering offset on its
// own 100ms easing timeline, desynced from the width/height timeline, so the box
// drifted off-center mid-pulse (the reported lateral movement). Leaving x/y as
// plain bindings makes them recompute in exact lockstep with the animated size
// → pure centered pulse, zero translate, matching Tauri.
//
// Glow fidelity gap (known, flagged): CSS box-shadow has blur AND spread; Slint
// drop-shadow has blur only. We use glowSpread as the blur radius — the halo
// reads slightly tighter than Tauri but blur+opacity dominate the look.
//
// `parent` is NEVER read in the root binding (Slint gotcha); viewport dims are
// passed in as properties. `opacity:` is NEVER set on the root (it corrupts
// absolute positioning); the fade lives on the player/ModeBar chrome instead.
import { NowPlayingState, VisualizerState, ImmersiveState } from "../state.slint";
import { ImmersiveTrackInfo } from "ImmersiveTrackInfo.slint";
export component AlbumReactivePanel inherits Rectangle {
in property <length> viewport-width: 1280px;
in property <length> viewport-height: 720px;
// --- Reactive scalars (faithful to AlbumReactivePanel.svelte) ----------
// Raw averaged energy bands (5 = sub-bass..air). VisualizerState.energy is
// published by the Rust 30fps drain while Immersive is open.
property <float> global-energy:
(VisualizerState.energy.length >= 5
? (VisualizerState.energy[0] + VisualizerState.energy[1]
+ VisualizerState.energy[2] + VisualizerState.energy[3]
+ VisualizerState.energy[4]) / 5.0
: 0.0);
property <float> bass-energy:
(VisualizerState.energy.length >= 2
? (VisualizerState.energy[0] + VisualizerState.energy[1]) / 2.0
: 0.0);
// artScale = 1 + globalEnergy * 0.25 (Svelte line 165)
property <float> art-scale: 1.0 + root.global-energy * 0.25;
// glowSpread = 15 + bassEnergy * 200 (px) (Svelte line 166) -> blur radius
property <length> glow-spread: (15.0 + root.bass-energy * 200.0) * 1px;
// glowOpacity = min(0.1 + globalEnergy * 1.5, 1) (Svelte line 167)
property <float> glow-opacity: Math.min(0.1 + root.global-energy * 1.5, 1.0);
// Base art box. The group must leave room for the metadata block + the
// floating player, or the quality badge gets clipped under the bar. So size
// the art so the WHOLE group (art*1.25 growth + spacing + info) fits the
// viewport height, with a width cap. Reserve = pad-top(52) + spacing(40) +
// info(~160) + player clearance(132) = 384px.
//
// RESPONSIVE: on large/tall windows the art should GROW to fill the space
// (people love big covers; the bg particles were removed, so a small art
// reads empty). The height budget `(vh-384)/1.25` already scales with the
// window; we raise the hard cap from 460 -> 660px and the width fraction
// 0.55 -> 0.62 so the art keeps growing on a big screen instead of stalling.
// The 180px floor keeps small windows safe (small was confirmed good).
// Native source resolution — cap the RESTING art so it is never upscaled
// beyond its own size on a large window (owner: oversized blurry art looked
// nefasto). The audio breathing (art-scale) still grows it momentarily — that
// is the intended reactive effect, not the static oversizing being fixed.
property <length> src-native:
(NowPlayingState.artwork-large.width > 0
? NowPlayingState.artwork-large.width
: NowPlayingState.artwork.width) * 1px;
property <length> base-art: Math.max(180px,
Math.min(Math.min(Math.min((root.viewport-height - 384px) / 1.25, root.viewport-width * 0.62), 660px), root.src-native));
// Reactive size = base * artScale. The glow layer and the art share this
// exact size/position so the halo stays glued to the art edge (per risk).
property <length> art-size: root.base-art * root.art-scale;
width: root.viewport-width;
height: root.viewport-height;
background: transparent;
// Vertical stack: artwork block, then the track-info block. Matches the
// Svelte column (.album-reactive-panel: flex column, centered, gap 20px,
// track-info margin-top 40px). Centered as a group in the viewport.
VerticalLayout {
x: 0px;
y: 0px;
width: root.viewport-width;
height: root.viewport-height;
// Reserve top for the ModeBar and bottom for the floating player bar
// (90px + 24px margin + gap). base-art's reserve constant (384px) is kept
// in sync with these (pad-top 52 + spacing 40 + info ~160 + pad-bottom 132).
padding-top: 52px;
padding-bottom: 132px;
alignment: center;
spacing: 40px;
// --- Artwork + glow ------------------------------------------------
artwork-block := Rectangle {
// Sized to the largest reactive footprint so growth doesn't clip.
height: root.base-art * 1.25;
horizontal-stretch: 1;
// Glow halo: a same-size, same-position Rectangle behind the art,
// tinted with the album-derived glow color and a reactive
// drop-shadow blur. (CSS box-shadow blur+spread -> blur only.)
glow := Rectangle {
width: root.art-size;
height: root.art-size;
// Center anchor. NOT animated: it recomputes in exact lockstep
// with the animated width/height each frame, so the box grows
// symmetrically from its center (like Tauri's `transform:
// scale()`) with ZERO lateral drift. Animating x/y on their own
// 100ms timeline desyncs from the size and makes the art slide.
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
border-radius: 8px;
background: ImmersiveState.glow-color;
opacity: root.glow-opacity;
drop-shadow-blur: root.glow-spread;
drop-shadow-color: ImmersiveState.glow-color;
animate width, height { duration: 100ms; easing: ease; }
animate opacity, drop-shadow-blur { duration: 100ms; easing: ease; }
}
// Artwork. Grows from center via reactive width/height (Slint has no
// transform:scale on a clipped Image). This is the SPEAKER-CONE
// pulse: a centered scale driven by audio energy, exactly like
// Tauri's `transform: scale({artScale})`. Static drop shadows mirror
// the Svelte .artwork-container box-shadow.
art := Rectangle {
width: root.art-size;
height: root.art-size;
// Center anchor. NOT animated (see glow note): recomputes in
// lockstep with the animated size so the art pulses in place
// with NO lateral/sideways movement.
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
border-radius: 8px;
clip: true;
drop-shadow-blur: 32px;
drop-shadow-color: #00000080;
drop-shadow-offset-y: 8px;
animate width, height { duration: 100ms; easing: ease; }
Image {
source: NowPlayingState.artwork-large.width > 0
? NowPlayingState.artwork-large
: NowPlayingState.artwork;
image-fit: cover;
width: parent.width;
height: parent.height;
}
}
}
// --- Track info (shared, homologated across all 3 panels) ----------
ImmersiveTrackInfo {
equalizer-tint: #7c3aed;
}
}
}