feat(slint): immersive Album Reactive mode + mode scaffold + provisional selector

Builds the foreground layer on Codex's accepted atmosphere+player base.

- ImmersiveState.mode (int, default 0): 0 Album Reactive / 1 Static /
  2 Coverflow / 3 Spectrum. Compact 0..3 enum for the scaffold (Tauri has no
  single integer mode; it uses viewMode + activeFocusTab strings).
- ImmersiveView layer stack: atmosphere (bottom) -> mode foreground ->
  auto-hide player -> ModeBar selector. Modes 1/2/3 mount no foreground yet
  (atmosphere-only placeholder, TODO S3/S4/S5).
- Provisional ModeBar selector (top-center, auto-hides with chrome-visible),
  to be replaced by the polished segmented bar in the header session.
- New AlbumReactivePanel.slint: faithful port of AlbumReactivePanel.svelte
  (387 lines), NOT the rejected breathing-art proof. Exact maps:
  global-energy = avg(energy[0..5]); bass = avg(energy[0..2]);
  art-scale 1+global*0.25; glow-spread 15+bass*200; glow-opacity
  min(0.1+global*1.5,1); 4-bar now-playing equalizer driven by
  animation-tick() (not a Timer). Album-derived glow from the already-wired
  ImmersiveState.glow-color; energy already published by visualizer.rs.
- main.rs immersive arm sets mode=0 on open (deterministic).

Flagged minors (deferred, see overnight log): glow tint not reset on
track-change until the new cover decodes; raw energy + 100ms animate vs the
Svelte asymmetric EMA; glow drop-shadow-blur only (no spread term); explicit
badge omitted (no NowPlayingState.explicit field); clamp art-scale energy to
avoid a clip at the block boundary on loud transients.

cc
This commit is contained in:
vicrodh committed 2026-06-13 07:48:53 -06:00
1 parent 9546656734
commit 92052a3c2a
4 files changed
+377 -1

No files matched your search

@@ -0,0 +1,253 @@
// 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.)
//
// 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 { QualityBadgeFull } from "../primitives/QualityBadgeFull.slint";
import { NowPlayingState, VisualizerState, ImmersiveState } from "../state.slint";
// Four-bar "now playing" equalizer. A continuous loop driven by the global
// animation-tick() (pull-based) — NOT a Timer (a Timer does not reliably drive
// continuous animation). Each bar phase-offset mirrors the Svelte
// animation-delay / per-bar base height (lines 311-314).
component EqualizerBars inherits Rectangle {
in property <color> tint: #7c3aed;
width: 18px;
height: 14px;
// 0.8s loop (Svelte `equalize 0.8s`): tick ms -> phase 0..1.
property <float> t: Math.mod(animation-tick() / 1ms, 800.0) / 800.0;
// scaleY 0.3..1.0 sweep (Svelte keyframes 0/100% -> 0.3, 50% -> 1.0).
function wave(phase: float) -> float {
// triangle-ish sweep peaking at the half-phase, like ease-in-out.
return 0.3 + 0.7 * (0.5 - 0.5 * Math.cos((Math.mod(self.t + phase, 1.0)) * 6.283185 * 1rad));
}
HorizontalLayout {
alignment: start;
spacing: 2px;
// bar 1: delay 0.0, base 60%
Rectangle {
width: 3px;
y: parent.height - self.height;
height: parent.height * 0.6 * root.wave(0.0);
border-radius: 1px;
background: root.tint;
}
// bar 2: delay 0.2, base 100%
Rectangle {
width: 3px;
y: parent.height - self.height;
height: parent.height * 1.0 * root.wave(0.25);
border-radius: 1px;
background: root.tint;
}
// bar 3: delay 0.1, base 40%
Rectangle {
width: 3px;
y: parent.height - self.height;
height: parent.height * 0.4 * root.wave(0.125);
border-radius: 1px;
background: root.tint;
}
// bar 4: delay 0.3, base 80%
Rectangle {
width: 3px;
y: parent.height - self.height;
height: parent.height * 0.8 * root.wave(0.375);
border-radius: 1px;
background: root.tint;
}
}
}
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: Svelte `min(52vh, 460px)`. viewport-height is the vh basis.
property <length> base-art: Math.min(root.viewport-height * 0.52, 460px);
// 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 the Svelte top/bottom padding (52px / 88px) so the group does
// not collide with the ModeBar (top) or the player bar (bottom).
padding-top: 52px;
padding-bottom: 88px;
alignment: center;
spacing: 60px;
// --- 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;
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, x, y { 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). Static drop shadows mirror
// the Svelte .artwork-container box-shadow.
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;
drop-shadow-blur: 32px;
drop-shadow-color: #00000080;
drop-shadow-offset-y: 8px;
animate width, height, x, y { 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 ----------------------------------------------------
info-block := VerticalLayout {
alignment: center;
spacing: 6px;
// "Now Playing" indicator: equalizer bars + label. Shown only while
// playing (Svelte {#if isPlaying}).
if NowPlayingState.playing: HorizontalLayout {
alignment: center;
spacing: 8px;
padding-bottom: 8px;
VerticalLayout {
alignment: center;
EqualizerBars {
tint: #7c3aed;
}
}
Text {
text: @tr("Now Playing");
color: #7c3aed;
font-size: 12px;
font-weight: 600;
letter-spacing: 0.5px;
vertical-alignment: center;
}
}
// Track title.
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 (Svelte {#if album}).
if NowPlayingState.album != "": Text {
text: NowPlayingState.album;
color: #ffffff80;
font-size: 14px;
font-italic: true;
horizontal-alignment: center;
overflow: elide;
}
// Quality badge (Svelte QualityBadgeStatic). Centered under the text.
HorizontalLayout {
alignment: center;
padding-top: 12px;
QualityBadgeFull {
tier: NowPlayingState.quality-tier;
detail: NowPlayingState.quality-detail;
}
}
}
}
}
@@ -6,6 +6,7 @@ import { Radius } from "../foundation/radius.slint";
import { QbzIcon } from "../primitives/QbzIcon.slint";
import { NowPlayingState, VisualizerState, ImmersiveState, SettingsState } from "../state.slint";
import { ImmersiveAtmosphere } from "ImmersiveAtmosphere.slint";
import { AlbumReactivePanel } from "AlbumReactivePanel.slint";
component GhostButton inherits Rectangle {
in property <image> icon;
@@ -413,6 +414,83 @@ component ImmersivePlayerBar inherits Rectangle {
}
}
// PROVISIONAL mode selector (top-center). A deliberately plain segmented bar to
// be replaced by the polished header in a later session (S6). Four tabs map tab
// position -> ImmersiveState.mode (0 Album Reactive, 1 Static, 2 Coverflow,
// 3 Spectrum). Each tab has its own TouchArea (pointer cursor); no `changed
// x/y/width/height` watchers (Recursion-detected risk). Fixed container height,
// tabs sized to content via HorizontalLayout. Clicking sets the mode and wakes
// the chrome so the bar resets its hide timer with the player.
component ModeTab inherits Rectangle {
in property <string> label;
in property <int> idx;
callback clicked();
property <bool> active: ImmersiveState.mode == root.idx;
height: 28px;
border-radius: 8px;
background: root.active ? #ffffff33 : (ta.has-hover ? #ffffff1f : transparent);
HorizontalLayout {
padding-left: 14px;
padding-right: 14px;
VerticalLayout {
alignment: center;
Text {
text: root.label;
color: root.active ? #ffffff : #ffffffb3;
font-size: 13px;
font-weight: root.active ? 600 : 400;
vertical-alignment: center;
}
}
}
ta := TouchArea {
mouse-cursor: pointer;
clicked => { root.clicked(); }
}
}
component ModeBar inherits Rectangle {
callback select(int);
height: 36px;
width: bar.preferred-width + 8px;
border-radius: 12px;
background: #00000080;
border-width: 1px;
border-color: #ffffff2e;
bar := HorizontalLayout {
x: 4px;
y: 4px;
height: 28px;
spacing: 4px;
ModeTab {
label: @tr("Album Reactive");
idx: 0;
clicked => { root.select(0); }
}
ModeTab {
label: @tr("Static");
idx: 1;
clicked => { root.select(1); }
}
ModeTab {
label: @tr("Coverflow");
idx: 2;
clicked => { root.select(2); }
}
ModeTab {
label: @tr("Spectrum");
idx: 3;
clicked => { root.select(3); }
}
}
}
export component ImmersiveView inherits Rectangle {
callback media-action(string, string, string);
@@ -461,6 +539,7 @@ export component ImmersiveView inherits Rectangle {
changed mouse-y => { root.wake(); }
}
// (1) Bottom: moving blurred-art atmosphere.
ImmersiveAtmosphere {
source-image: ImmersiveState.bg-image;
fallback-image: NowPlayingState.artwork-large.width > 0
@@ -469,6 +548,21 @@ export component ImmersiveView inherits Rectangle {
dim: 0.15;
}
// (2) Foreground: switches on ImmersiveState.mode via conditional mount
// (ADR-010). Mode 0 = Album Reactive (the only real foreground this
// session). Modes 1/2/3 mount NO foreground — the atmosphere is the
// explicit placeholder until those sessions land.
if ImmersiveState.mode == 0: AlbumReactivePanel {
x: 0px;
y: 0px;
viewport-width: root.width;
viewport-height: root.height;
}
// TODO(S3): Static mode foreground (mode == 1) — atmosphere-only for now.
// TODO(S4): Coverflow mode foreground (mode == 2) — atmosphere-only for now.
// TODO(S5): Spectrum mode foreground (mode == 3) — atmosphere-only for now.
// (3) Auto-hide compact player.
ImmersivePlayerBar {
viewport-width: root.width;
x: Math.round((root.width - self.width) / 2 / 1px) * 1px;
@@ -478,4 +572,18 @@ export component ImmersiveView inherits Rectangle {
wake => { root.wake(); }
media-action(kind, id, action) => { root.media-action(kind, id, action); }
}
// (4) Top-center mode selector. Shares the same chrome-visible flag so it
// auto-hides/wakes with the player (no second timer). Horizontally
// centered, pinned near the window top so it never overlaps the player.
ModeBar {
x: Math.round((root.width - self.width) / 2 / 1px) * 1px;
y: 16px;
opacity: root.chrome-visible ? 1.0 : 0.0;
animate opacity { duration: 300ms; }
select(idx) => {
ImmersiveState.mode = idx;
root.wake();
}
}
}