// 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 viewport-width: 1280px; in property 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 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 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 art-scale: 1.0 + root.global-energy * 0.25; // glowSpread = 15 + bassEnergy * 200 (px) (Svelte line 166) -> blur radius property glow-spread: (15.0 + root.bass-energy * 200.0) * 1px; // glowOpacity = min(0.1 + globalEnergy * 1.5, 1) (Svelte line 167) property 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). property base-art: Math.max(180px, Math.min(Math.min((root.viewport-height - 384px) / 1.25, root.viewport-width * 0.62), 660px)); // 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 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; } } }