From 763df2eab533ad364e9fda83bedfa4c3275cdc93 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Sat, 13 Jun 2026 11:34:35 -0600 Subject: [PATCH] perf+feat(slint): immersive Coverflow jukebox pyramid + kill the per-click CPU spike Owner rebuild: cheap "rocola" of flat scaled cards, and eliminate the CPU spike on every navigation click. CPU spike (root cause): each queue navigation re-ran refresh_async, whose to_item reset EVERY rebuilt row's artwork to Image::default(), discarding the already-decoded handles for the 6-of-7 on-screen covers; each was then re-decoded (the disk cache stored only compressed bytes, so even a hit ran a full image::load + thumbnail). Dozens of full JPEG/PNG decodes per click. Fix: (A) artwork.rs decoded-pixel cache (DECODED_PIXEL_CACHE keyed by url+size; fetch_and_decode_ref consults it before any disk read/decode); (B) queue.rs to_item_reuse + per-list prior-art id-diff carries unchanged decoded handles across the model rebuild (no blank, no re-decode); load_artwork short-circuits on a decoded-cache hit. Net: at most the one newly-revealed cover decodes. Pyramid (CoverflowPanel.slint rebuilt): 7 flat cards (3 history left + center + 3 upcoming right), center declared last (paints on top), step-down scale (1.00/0.80/0.64/0.50) + per-depth black-overlay attenuation on an inner Rectangle (0/0.22/0.40/0.55). NO rotateY/skew/perspective, NO reflection, NO far-edge gradient, NO root transparency. Removed the 500ms x/width/height reflow (it re-laid-out clipped images every frame); only a 120ms GPU opacity cross-fade on the dim overlay remains. Center drop-shadow static. 132px player clearance kept. Correctness fix (review blocker): the coverflow upcoming cards index the UNFILTERED next-3 (coverflow-upcoming), so routing their click through the paged/filtered play-upcoming played the wrong track on a paged/searched sidebar. Added QueueState.play-coverflow-upcoming -> queue.play_coverflow_upcoming, which plays the queue-wide upcoming index directly via play_upcoming_at. History already indexes queue-wide via play-history. cc --- crates/qbz-slint/src/artwork.rs | 96 +++++- crates/qbz-slint/src/main.rs | 6 + crates/qbz-slint/src/queue.rs | 218 ++++++++++++-- .../ui/immersive/CoverflowPanel.slint | 275 +++++++++--------- .../ui/immersive/ImmersiveView.slint | 12 +- crates/qbz-slint/ui/state.slint | 13 + 6 files changed, 442 insertions(+), 178 deletions(-) diff --git a/crates/qbz-slint/src/artwork.rs b/crates/qbz-slint/src/artwork.rs index 0e7eab068..cf24f0678 100644 --- a/crates/qbz-slint/src/artwork.rs +++ b/crates/qbz-slint/src/artwork.rs @@ -6,7 +6,8 @@ //! cover is applied to its own `AlbumCardItem` row on the Slint event //! loop, so artwork arriving never resets a list (POC ADR 16 and 18). -use std::sync::{Arc, Mutex}; +use std::collections::HashMap; +use std::sync::{Arc, LazyLock, Mutex}; use qbz_cache::ImageCacheService; use qbz_models::ArtworkRef; @@ -422,6 +423,69 @@ fn decode_rgba(bytes: &[u8], decode_size: u32) -> Option<(Vec, u32, u32)> { Some((rgba.into_raw(), width, height)) } +/// A decoded cover, ready for `pixels_to_image`. `slint::Image` is `!Send`, so +/// the cache stores the RGBA tuple (which IS `Send`) and the event loop builds +/// the `slint::Image` on demand. `Arc`-wrapped so cache hits clone a pointer, +/// not the ~36KB buffer. +pub type DecodedPixels = (Arc>, u32, u32); + +/// Decoded-pixel LRU. Repeat decodes of the same `(url, size)` — exactly what +/// the coverflow / queue refresh hammered every click — become a HashMap hit + +/// a cheap pixel upload instead of a full `image::load_from_memory().thumbnail()`. +/// Capped to keep a long session from leaking; insertion order approximates LRU +/// (re-insert on hit moves the entry to the back). +const DECODED_CACHE_CAP: usize = 256; + +struct DecodedCache { + /// `(url, size)` -> decoded pixels. Insertion order = eviction order. + map: HashMap<(String, u32), DecodedPixels>, + /// Keys in insertion order; the front is the eviction candidate. + order: Vec<(String, u32)>, +} + +static DECODED_PIXEL_CACHE: LazyLock> = LazyLock::new(|| { + Mutex::new(DecodedCache { + map: HashMap::new(), + order: Vec::new(), + }) +}); + +/// Decoded-pixel cache lookup for `(url, size)`. A hit returns the shared RGBA +/// tuple — callers build the `slint::Image` via [`pixels_to_image`] on the event +/// loop and SKIP the expensive decode entirely. +pub fn decoded_pixels(url: &str, size: u32) -> Option { + let mut cache = DECODED_PIXEL_CACHE.lock().ok()?; + let key = (url.to_string(), size); + let hit = cache.map.get(&key).cloned(); + if hit.is_some() { + // Move to the back (most-recently-used). + if let Some(pos) = cache.order.iter().position(|k| k == &key) { + cache.order.remove(pos); + } + cache.order.push(key); + } + hit +} + +/// Store decoded pixels for `(url, size)`, evicting the oldest entry past the cap. +fn store_decoded(url: &str, size: u32, pixels: &DecodedPixels) { + let Ok(mut cache) = DECODED_PIXEL_CACHE.lock() else { + return; + }; + let key = (url.to_string(), size); + if cache.map.insert(key.clone(), pixels.clone()).is_none() { + cache.order.push(key); + } else if let Some(pos) = cache.order.iter().position(|k| k == &key) { + // Refresh recency on an overwrite. + cache.order.remove(pos); + cache.order.push(key); + } + while cache.order.len() > DECODED_CACHE_CAP { + let oldest = cache.order.remove(0); + cache.map.remove(&oldest); + } +} + /// Resolve an [`ArtworkRef`] to raw RGBA8 pixels, downscaled to /// `decode_size`, regardless of origin. This is the source-aware entry /// point that fixes local/Plex artwork never reaching the UI: HTTP and Plex @@ -436,6 +500,30 @@ pub async fn fetch_and_decode_ref( if art.is_empty() { return None; } + + // Decoded-pixel cache key: the stable resolved location for this art at this + // decode size. A hit returns the already-decoded RGBA tuple and skips both + // the disk read AND the `image::load_from_memory().thumbnail()` decode — this + // is what makes a one-position queue/coverflow shift near-free (the 6 covers + // still on screen reuse their decoded pixels instead of being re-decoded). + // `Embedded` has no stable URL, so it is never decode-cached. + let cache_key: Option = match art { + ArtworkRef::None | ArtworkRef::Embedded(_) => None, + ArtworkRef::LocalFile(path) => Some(path.clone()), + ArtworkRef::Remote(url) => Some(url.clone()), + ArtworkRef::PlexThumb { + base_url, + token, + path, + size, + } => Some(qbz_models::plex_thumb_url(base_url, token, path, *size)), + }; + if let Some(key) = cache_key.as_deref() { + if let Some((pixels, w, h)) = decoded_pixels(key, decode_size) { + return Some(((*pixels).clone(), w, h)); + } + } + let bytes: Vec = match art { ArtworkRef::None => return None, ArtworkRef::Embedded(b) => b.clone(), @@ -457,7 +545,11 @@ pub async fn fetch_and_decode_ref( fetch_cached_http(&url, cache, false).await? } }; - decode_rgba(&bytes, decode_size) + let (pixels, w, h) = decode_rgba(&bytes, decode_size)?; + if let Some(key) = cache_key { + store_decoded(&key, decode_size, &(Arc::new(pixels.clone()), w, h)); + } + Some((pixels, w, h)) } /// Resolve one cover image (by remote URL) to raw RGBA8 pixels. Kept for the diff --git a/crates/qbz-slint/src/main.rs b/crates/qbz-slint/src/main.rs index 8af5dae36..382a418dc 100644 --- a/crates/qbz-slint/src/main.rs +++ b/crates/qbz-slint/src/main.rs @@ -6597,6 +6597,12 @@ fn main() -> Result<(), Box> { let c = controller.clone(); qs.on_play_upcoming(move |index| c.play_upcoming(index.max(0) as usize)); } + { + let c = controller.clone(); + qs.on_play_coverflow_upcoming(move |index| { + c.play_coverflow_upcoming(index.max(0) as usize) + }); + } { let c = controller.clone(); qs.on_play_history(move |index| c.play_history(index.max(0) as usize)); diff --git a/crates/qbz-slint/src/queue.rs b/crates/qbz-slint/src/queue.rs index 17d777102..c359e8774 100644 --- a/crates/qbz-slint/src/queue.rs +++ b/crates/qbz-slint/src/queue.rs @@ -261,6 +261,22 @@ impl QueueController { let history_rows: Vec = state.history.iter().map(|t| row_from(t, false)).collect(); + // --- COVERFLOW (unfiltered next-3 / prev-3) ----------------------- + // Built from the UNFILTERED queue so the immersive pyramid is correct + // regardless of sidebar page/search. Index 0 = next / most-recent. + let coverflow_up_rows: Vec = state + .upcoming + .iter() + .take(3) + .map(|t| row_from(t, false)) + .collect(); + let coverflow_hist_rows: Vec = state + .history + .iter() + .take(3) + .map(|t| row_from(t, false)) + .collect(); + // --- Infinite-play flag ------------------------------------------ let infinite = self .playback @@ -286,20 +302,49 @@ impl QueueController { art_jobs.push((ArtTarget::History(idx), row.artwork_url.clone())); } } + for (idx, row) in coverflow_up_rows.iter().enumerate() { + if !row.artwork_url.is_empty() { + art_jobs.push((ArtTarget::CoverflowUpcoming(idx), row.artwork_url.clone())); + } + } + for (idx, row) in coverflow_hist_rows.iter().enumerate() { + if !row.artwork_url.is_empty() { + art_jobs.push((ArtTarget::CoverflowHistory(idx), row.artwork_url.clone())); + } + } let weak = self.weak.clone(); let _ = weak.upgrade_in_event_loop(move |w| { let qs = w.global::(); + // Snapshot prior decoded handles per list BEFORE replacing the + // models, so unchanged tracks keep their decoded artwork instead of + // blanking to the default (which forced a full re-decode + blink on + // every click). Diffed per-list so a track present in both history + // and upcoming can't cross-map. + let prior_page = prior_art_map(&qs.get_upcoming_page()); + let prior_history = prior_art_map(&qs.get_history()); + let prior_cf_up = prior_art_map(&qs.get_coverflow_upcoming()); + let prior_cf_hist = prior_art_map(&qs.get_coverflow_history()); + let np_item = now_playing .as_ref() - .map(|r| to_item(r)) + .map(|r| { + // Reuse the prior now-playing cover only if the same track. + let prior = qs.get_now_playing(); + let mut map = std::collections::HashMap::new(); + if prior.artwork.size().width > 0 { + map.insert(prior.id.clone(), prior.artwork.clone()); + } + to_item_reuse(r, &map) + }) .unwrap_or_default(); qs.set_has_current(now_playing.is_some()); qs.set_now_playing(np_item); qs.set_now_playing_favorite(now_playing_favorite); - let page_items: Vec = page_rows.iter().map(to_item).collect(); + let page_items: Vec = + page_rows.iter().map(|r| to_item_reuse(r, &prior_page)).collect(); qs.set_upcoming_page(slint::ModelRc::new(slint::VecModel::from(page_items))); qs.set_upcoming_total(upcoming_total as i32); qs.set_upcoming_remaining(remaining as i32); @@ -308,9 +353,22 @@ impl QueueController { qs.set_page_start(page_start as i32); qs.set_page_end(page_end as i32); - let history_items: Vec = history_rows.iter().map(to_item).collect(); + let history_items: Vec = + history_rows.iter().map(|r| to_item_reuse(r, &prior_history)).collect(); qs.set_history(slint::ModelRc::new(slint::VecModel::from(history_items))); + // Coverflow lists (unfiltered next-3 / prev-3), reusing handles. + let cf_up_items: Vec = coverflow_up_rows + .iter() + .map(|r| to_item_reuse(r, &prior_cf_up)) + .collect(); + qs.set_coverflow_upcoming(slint::ModelRc::new(slint::VecModel::from(cf_up_items))); + let cf_hist_items: Vec = coverflow_hist_rows + .iter() + .map(|r| to_item_reuse(r, &prior_cf_hist)) + .collect(); + qs.set_coverflow_history(slint::ModelRc::new(slint::VecModel::from(cf_hist_items))); + qs.set_infinite_play(infinite); // Keep the Slint tab property in sync with the view state so the // Queue/History body always matches the selected tab. @@ -350,6 +408,25 @@ impl QueueController { }); } + /// Play an upcoming track by its QUEUE-WIDE (unfiltered) index. The immersive + /// coverflow lists `state.upcoming.take(3)` regardless of the sidebar's page + /// or search, so its cards must NOT go through `play_upcoming`'s page-local + /// `resolve_upcoming_index` (that would play the wrong track when the sidebar + /// is paged/filtered). History is already queue-wide via `play_history`. + pub fn play_coverflow_upcoming(&self, upcoming_index: usize) { + let this = self.clone(); + self.handle.spawn(async move { + let Some(track) = this.runtime.core().play_upcoming_at(upcoming_index).await else { + log::warn!( + "[qbz-slint] queue: play_coverflow_upcoming {upcoming_index} miss" + ); + return; + }; + crate::playback::after_track_change(&this.runtime, &this.weak, track.id).await; + this.refresh_async().await; + }); + } + /// Remove the upcoming entry at `page_index` within the current page. pub fn remove_upcoming(&self, page_index: usize) { let this = self.clone(); @@ -633,16 +710,30 @@ enum ArtTarget { NowPlaying, Upcoming(usize), History(usize), + CoverflowUpcoming(usize), + CoverflowHistory(usize), } -/// Build a `QueueItem` from plain row data (no artwork — that resolves -/// asynchronously and is set onto the row afterward). -fn to_item(row: &RowData) -> QueueItem { +/// Build a `QueueItem` from plain row data, REUSING a prior decoded artwork +/// handle when the same track id was already on screen. This is the core of the +/// CPU-spike fix: a one-position queue shift keeps the decoded `slint::Image` +/// for every unchanged row instead of resetting it to `Image::default()` and +/// forcing a full re-decode (which also caused the empty-then-fill blink). +/// +/// `prior` maps track id -> the decoded image from the model being replaced. +/// Unchanged rows reuse their handle; only genuinely-new rows fall back to the +/// default placeholder (their cover is decoded once by the artwork pipeline). +fn to_item_reuse( + row: &RowData, + prior: &std::collections::HashMap, +) -> QueueItem { + let id: slint::SharedString = row.id.clone().into(); + let artwork = prior.get(&id).cloned().unwrap_or_default(); QueueItem { - id: row.id.clone().into(), + id: id.clone(), title: row.title.clone().into(), artist: row.artist.clone().into(), - artwork: slint::Image::default(), + artwork, playing: row.playing, duration: row.duration.clone().into(), explicit: row.explicit, @@ -650,6 +741,23 @@ fn to_item(row: &RowData) -> QueueItem { } } +/// Snapshot the current id -> decoded-artwork map for a Slint model, so the +/// rebuilt rows can reuse handles for tracks that did not change. Only rows +/// whose artwork is actually resolved (`width > 0`) are recorded. +fn prior_art_map( + model: &slint::ModelRc, +) -> std::collections::HashMap { + let mut map = std::collections::HashMap::new(); + for i in 0..model.row_count() { + if let Some(item) = model.row_data(i) { + if item.artwork.size().width > 0 { + map.insert(item.id.clone(), item.artwork.clone()); + } + } + } + map +} + #[cfg(test)] mod tests { use super::*; @@ -759,6 +867,9 @@ fn load_artwork( plex_base_url: String, plex_token: String, ) { + /// Decode size for all queue/coverflow covers (matches the artwork pipeline). + const QUEUE_DECODE: u32 = 96; + let Some(cache) = crate::artwork::shared_cache() else { return; }; @@ -783,42 +894,85 @@ fn load_artwork( path: url, // Queue rows + now-playing item render small; request a // 96px server-side transcode (the decode size used below). - size: Some(96), + size: Some(QUEUE_DECODE), } } else { qbz_models::ArtworkRef::LocalFile(url) }; + + // Decoded-pixel fast path: if this exact cover was already decoded at + // this size (true for the covers still on screen after a one-position + // shift), upload the cached pixels on the event loop and SKIP the tokio + // decode entirely. This is the bulk of the per-click CPU-spike fix. + let cache_key = match &art { + qbz_models::ArtworkRef::Remote(u) => Some(u.clone()), + qbz_models::ArtworkRef::LocalFile(p) => Some(p.clone()), + qbz_models::ArtworkRef::PlexThumb { base_url, token, path, size } => { + Some(qbz_models::plex_thumb_url(base_url, token, path, *size)) + } + _ => None, + }; + if let Some(key) = cache_key.as_deref() { + if let Some((pixels, w, h)) = crate::artwork::decoded_pixels(key, QUEUE_DECODE) { + let weak = weak.clone(); + let _ = weak.upgrade_in_event_loop(move |win| { + let img = crate::artwork::pixels_to_image(&pixels, w, h); + apply_queue_art(&win, target, img); + }); + continue; + } + } + tokio::spawn(async move { let Some((pixels, w, h)) = - crate::artwork::fetch_and_decode_ref(&art, &cache, 96).await + crate::artwork::fetch_and_decode_ref(&art, &cache, QUEUE_DECODE).await else { return; }; let _ = weak.upgrade_in_event_loop(move |win| { let img = crate::artwork::pixels_to_image(&pixels, w, h); - let qs = win.global::(); - match target { - ArtTarget::NowPlaying => { - let mut item = qs.get_now_playing(); - item.artwork = img; - qs.set_now_playing(item); - } - ArtTarget::Upcoming(idx) => { - let items = qs.get_upcoming_page(); - if let Some(mut item) = items.row_data(idx) { - item.artwork = img; - items.set_row_data(idx, item); - } - } - ArtTarget::History(idx) => { - let items = qs.get_history(); - if let Some(mut item) = items.row_data(idx) { - item.artwork = img; - items.set_row_data(idx, item); - } - } - } + apply_queue_art(&win, target, img); }); }); } } + +/// Apply a resolved cover onto its queue/coverflow row. Runs on the event loop. +fn apply_queue_art(win: &AppWindow, target: ArtTarget, img: slint::Image) { + let qs = win.global::(); + match target { + ArtTarget::NowPlaying => { + let mut item = qs.get_now_playing(); + item.artwork = img; + qs.set_now_playing(item); + } + ArtTarget::Upcoming(idx) => { + let items = qs.get_upcoming_page(); + if let Some(mut item) = items.row_data(idx) { + item.artwork = img; + items.set_row_data(idx, item); + } + } + ArtTarget::History(idx) => { + let items = qs.get_history(); + if let Some(mut item) = items.row_data(idx) { + item.artwork = img; + items.set_row_data(idx, item); + } + } + ArtTarget::CoverflowUpcoming(idx) => { + let items = qs.get_coverflow_upcoming(); + if let Some(mut item) = items.row_data(idx) { + item.artwork = img; + items.set_row_data(idx, item); + } + } + ArtTarget::CoverflowHistory(idx) => { + let items = qs.get_coverflow_history(); + if let Some(mut item) = items.row_data(idx) { + item.artwork = img; + items.set_row_data(idx, item); + } + } + } +} diff --git a/crates/qbz-slint/ui/immersive/CoverflowPanel.slint b/crates/qbz-slint/ui/immersive/CoverflowPanel.slint index cefffc2be..fed75ac12 100644 --- a/crates/qbz-slint/ui/immersive/CoverflowPanel.slint +++ b/crates/qbz-slint/ui/immersive/CoverflowPanel.slint @@ -1,35 +1,40 @@ -// Coverflow foreground (Immersive mode 2) — a faithful PURE-SLINT 2D port of -// the Tauri `src/lib/components/immersive/panels/CoverflowPanel.svelte`. +// Coverflow foreground (Immersive mode 2) — a CHEAP "rocola" (jukebox) +// PYRAMID of flat scaled cards. // -// OWNER DECISION (binding): Tauri's coverflow uses true CSS 3D — perspective:1400px -// + rotateY(45/55deg) on the side covers + a hover micro-turn. Declarative Slint -// has NO perspective / 3D / shear, so the true-3D rotateY foreshortening, the -// 1400px perspective, and the hover micro-turn are DROPPED and DEFERRED to a -// future wgpu/Skia session. This is the FAITHFUL-POSSIBLE 2D version: -// - a clean scaled fan: now-playing cover CENTERED + on top; played covers -// (QueueState.history) fanned LEFT; upcoming covers (QueueState.upcoming-page) -// fanned RIGHT. -// - depth via SCALE + per-depth drop-shadow + a far-edge shade gradient + -// dimming-by-distance. NO rotateY, NO skew, NO perspective, NO fake tilt -// (a fake 2D tilt is exactly the approximation trap the owner rejected). -// - a ~500ms reflow on track change via `animate x, width, height` on the -// data-derived slot bindings + `animate opacity` on the INNER dim Rectangle -// (never on the slot root — root opacity corrupts absolute positioning). +// OWNER DECISION (binding, REPLACES the old true-3D-aspiring fan): NO rotateY / +// skew / perspective / reflection, NO far-edge shade gradient, NO transparency +// on the card root. Just flat scaled cards. Depth reads from (a) a step-down +// SCALE so the silhouette is a pyramid (center tallest) and (b) a per-depth +// semi-transparent BLACK overlay on an INNER rectangle (attenuation, darker +// the further out). A real blur is too expensive and is NOT used — the owner +// said "un blur o atenuación... basta", so attenuation + scale is the depth cue. +// +// LAYOUT: 7 cards = 3 past (left, history) + center + 3 upcoming (right). The +// now-playing cover is ALWAYS centered and ALWAYS on top in Z (declared LAST = +// paints last). Cards may overlap toward the center (jukebox stack). +// +// PERF: the old version animated x / width / height over 500ms on every slot, +// re-laying-out clipped images each frame on every click. That is DROPPED — the +// cards snap to their new depth on a click (Option A). Combined with the Rust +// decoded-handle reuse (queue.rs) the covers no longer blink, so the snap is +// clean. A single 120ms opacity cross-fade on the INNER dim overlay (Option B) +// is the only motion — GPU-only, no relayout, no texture re-upload. // // SLINT GOTCHAS honored: `parent` is never read in any root binding (viewport -// dims passed as props; CoverSlot dims passed as props). No Repeater for the -// slots (hand-placed 5 fixed instances) and NO `changed x/y/width/height` -// watchers -> avoids the "Recursion detected" panic. Slot painting order is -// declaration order, so the center slot is declared LAST (paints on top). +// dims passed as props; CoverSlot dims passed as props). Hand-placed fixed +// instances (no Repeater) and NO `changed x/y/width/height` watchers -> avoids +// the "Recursion detected" panic. `dim` is applied on an INNER Rectangle, never +// the slot root opacity (root opacity corrupts absolute positioning). The +// off-clamp uses Math.min (max-width is ignored on hand-positioned Rectangles). // -// DATA MAPPING (QueueState is host-split, not Tauri's flat queue+index): -// center (offset 0) <- NowPlayingState (unified source, also feeds card) -// right-1 (offset +1) <- QueueState.upcoming-page[0] (idx 0 = next track) -// right-2 (offset +2) <- QueueState.upcoming-page[1] -// left-1 (offset -1) <- QueueState.history[0] (recent-first = prev) -// left-2 (offset -2) <- QueueState.history[1] -// Side covers navigate DIRECTLY via QueueState.play-upcoming / play-history -// (QueueState is a global; no ImmersiveView plumbing needed). +// DATA MAPPING (unfiltered coverflow lists, correct regardless of sidebar +// page/search — populated in queue.rs refresh_async from state.upcoming[..3] / +// state.history[..3] with decoded-handle reuse): +// center (depth 0) <- NowPlayingState (unified source, also feeds the card) +// right-n (depth n) <- QueueState.coverflow-upcoming[n-1] (next tracks) +// left-n (depth n) <- QueueState.coverflow-history[n-1] (recent-first) +// Side covers navigate via QueueState.play-upcoming / play-history (index n-1); +// the center is non-interactive. import { QualityBadgeFull } from "../primitives/QualityBadgeFull.slint"; import { NowPlayingState, QueueState } from "../state.slint"; @@ -82,22 +87,18 @@ component EqualizerBars inherits Rectangle { } } -// One fanned cover. Dims passed as props (NEVER `parent` in the root binding). -// `dim` is the distance darkening (0 center .. 0.45 outermost); applied on an -// INNER Rectangle, never the root opacity. The far-edge shade gradient is the -// only honest nod to the Tauri turn — `side` selects which edge darkens -// (-1 = left covers darken their LEFT/far edge, +1 = right covers darken their -// RIGHT/far edge, 0 = center, no shade). `has-art` true when the cover image is -// resolved; when an item exists but its art is not yet decoded we show a neutral -// placeholder instead of a 0-size collapse. The 500ms reflow lives on the -// animatable x / size / dim bindings. +// One flat card in the pyramid. Dims passed as props (NEVER `parent` in the +// root binding). `dim` is the per-depth attenuation (0 center .. 0.55 outermost) +// applied on an INNER Rectangle, never the root opacity. `has-art` is true when +// the cover image is resolved; otherwise a neutral placeholder shows instead of +// a 0-size collapse. NO animated geometry — the card snaps to its depth on a +// click; only the dim overlay cross-fades (120ms, GPU-only). component CoverSlot inherits Rectangle { in property art; in property slot-size; in property center-x; // window-x of the cover CENTER in property stage-height; - in property dim: 0.0; // 0..1 extra darken - in property side: 0; // -1 left, 0 center, +1 right + in property dim: 0.0; // 0..1 per-depth black-overlay opacity in property has-art: false; // art image resolved (width > 0) in property interactive: false; callback navigate(); @@ -105,20 +106,17 @@ component CoverSlot inherits Rectangle { width: root.slot-size; height: root.slot-size; x: root.center-x - root.slot-size / 2; - // Vertical center of the stage, small upward bias to leave room for the card. + // Shared center band; the larger center card naturally rises. Small upward + // bias to leave room for the song card below. y: (root.stage-height - root.slot-size) / 2 - 12px; border-radius: 8px; clip: true; - // Per-depth drop-shadow: center 32px @ 0.4, sides 16px @ 0.25 (spec :246/:288). - drop-shadow-blur: root.side == 0 ? 32px : 16px; - drop-shadow-color: root.side == 0 ? #00000066 : #00000040; - drop-shadow-offset-y: root.side == 0 ? 8px : 4px; - - // 500ms reflow on track change — bindings recompute when the data reshuffles. - animate x { duration: 500ms; easing: cubic-bezier(0.4, 0, 0.2, 1); } - animate width { duration: 500ms; easing: cubic-bezier(0.4, 0, 0.2, 1); } - animate height { duration: 500ms; easing: cubic-bezier(0.4, 0, 0.2, 1); } + // Static drop-shadow on the center card only (never animated, never on the + // side cards — the attenuation carries their depth). + drop-shadow-blur: root.dim == 0.0 ? 28px : 0px; + drop-shadow-color: #00000066; + drop-shadow-offset-y: root.dim == 0.0 ? 8px : 0px; // Neutral placeholder when the item exists but its art is unresolved. Rectangle { @@ -137,35 +135,20 @@ component CoverSlot inherits Rectangle { visible: root.has-art; } - // Far-edge shade gradient — the only honest nod to the Tauri turn (NOT a - // tilt). Left covers darken their LEFT edge; right covers their RIGHT edge. - if root.side == -1: Rectangle { - width: parent.width; - height: parent.height; - border-radius: 8px; - background: @linear-gradient(90deg, #00000050 0%, transparent 35%); - } - if root.side == 1: Rectangle { - width: parent.width; - height: parent.height; - border-radius: 8px; - background: @linear-gradient(90deg, transparent 65%, #00000050 100%); - } - - // Distance dimming — on an INNER Rectangle (never the slot root opacity, - // which corrupts absolute positioning). Animated so the dim cross-fades - // during the 500ms reflow. - dim-overlay := Rectangle { + // Per-depth attenuation — a semi-transparent BLACK overlay on an INNER + // Rectangle (never the slot root opacity). The ONLY animation: a short + // opacity cross-fade so the attenuation eases as a card changes depth. + // GPU-only (no relayout, no clipped-image re-raster) -> no CPU spike. + Rectangle { width: parent.width; height: parent.height; border-radius: 8px; background: #000000; opacity: root.dim; - animate opacity { duration: 500ms; easing: cubic-bezier(0.4, 0, 0.2, 1); } + animate opacity { duration: 120ms; easing: ease-out; } } - // Side covers navigate; the center is non-interactive (like the disabled - // Tauri center button). + // Side cards navigate; the center is non-interactive. if root.interactive: TouchArea { mouse-cursor: pointer; clicked => { root.navigate(); } @@ -180,28 +163,29 @@ export component CoverflowPanel inherits Rectangle { height: root.viewport-height; background: transparent; - // --- Geometry (faithful, scaled from the spec) ----------------------- - // Center cover edge. Reserve = pad-top(52) + fan + info(~160) + - // player-clearance(132) = 364px (same budget as StaticPanel). Width cap 0.42 - // keeps both side fans inside the window (covers must not clip at narrow - // widths). Clamped 180..460px. - property base-art: Math.max(180px, - Math.min(Math.min(root.viewport-height - 364px, root.viewport-width * 0.42), 460px)); - // Side cover edges from the spec scale ratios (0.82/0.65 against the 380 side - // base relative to the 460 center): side1 = base*0.68, side2 = base*0.54. - property side1-size: root.base-art * 0.68; - property side2-size: root.base-art * 0.54; + // --- Geometry -------------------------------------------------------- + // Center cover edge (base-art = depth-0 scale). Honors the 132px player + // clearance: reserve = pad-top(52) + info + clearance(132) = 364px. + property base-art: Math.max(160px, + Math.min(Math.min(root.viewport-height - 364px, root.viewport-width * 0.42), 440px)); - // X offsets scaled to base-art (spec ±200/±340 against a 460 center): - // off1 = base*0.435, off2 = base*0.739. Clamp so off2 + side2/2 stays inside - // the half-window with a 24px margin (narrow-width clip guard; max-width is - // ignored on hand-positioned Rectangles, so use Math.min). + // Step-down SCALE (center tallest): depth0 1.00, depth1 0.80, depth2 0.64, + // depth3 0.50. + property size1: root.base-art * 0.80; + property size2: root.base-art * 0.64; + property size3: root.base-art * 0.50; + + // X offsets (center-anchored, overlapping inward). Spec ratios off1 0.42, + // off2 0.74, off3 1.02. Each clamped so the card stays inside the half-window + // with a 16px margin (Math.min — max-width is ignored on hand-positioned + // rects). Chain off1 < off2 < off3 so the order never crosses. property half-w: root.viewport-width / 2; - property off2-max: Math.max(0px, root.half-w - root.side2-size / 2 - 24px); - property off2: Math.min(root.base-art * 0.739, root.off2-max); - // Keep off1 strictly inside off2 (never overlap the order) while honoring - // the spec ratio; clamp to off2 minus a small gap. - property off1: Math.min(root.base-art * 0.435, Math.max(0px, root.off2 - root.side2-size / 4)); + property off3: Math.min(root.base-art * 1.02, + Math.max(0px, root.half-w - root.size3 / 2 - 16px)); + property off2: Math.min(root.base-art * 0.74, + Math.max(0px, root.off3 - root.size3 / 4)); + property off1: Math.min(root.base-art * 0.42, + Math.max(0px, root.off2 - root.size2 / 4)); // --- Center artwork source (unified NowPlayingState, like the siblings) -- property center-art: NowPlayingState.artwork-large.width > 0 @@ -209,98 +193,113 @@ export component CoverflowPanel inherits Rectangle { : NowPlayingState.artwork; property center-has-art: root.center-art.width > 0; - // --- Side item presence + art (async-decoded; guard with .width > 0) ---- - property has-up1: QueueState.upcoming-page.length > 0; - property has-up2: QueueState.upcoming-page.length > 1; - property has-hist1: QueueState.history.length > 0; - property has-hist2: QueueState.history.length > 1; + // --- Side item presence (unfiltered coverflow lists) ---------------- + property has-up1: QueueState.coverflow-upcoming.length > 0; + property has-up2: QueueState.coverflow-upcoming.length > 1; + property has-up3: QueueState.coverflow-upcoming.length > 2; + property has-hist1: QueueState.coverflow-history.length > 0; + property has-hist2: QueueState.coverflow-history.length > 1; + property has-hist3: QueueState.coverflow-history.length > 2; - // --- Fan stage ------------------------------------------------------- - // A content stage centered horizontally, leaving the pad-top/clearance to - // the surrounding card layout. The stage height drives the slots' vertical - // center. + // --- Pyramid stage --------------------------------------------------- fan := Rectangle { x: 0px; - // pad-top 52 (true visual center offset, matches the siblings). - y: 52px; + y: 52px; // pad-top, matches the siblings width: root.viewport-width; - // The fan occupies the area above the song card; the card is pinned at - // the bottom with the 132px player clearance via the VerticalLayout. height: root.base-art + 56px; property cx: root.viewport-width / 2; - // Declaration order = paint order: far -> near, CENTER LAST (on top). - // left-2 (offset -2) <- history[1] + // Declaration order = paint order: depth3 -> depth1 outward-to-inward, + // CENTER LAST (on top). Left/right of each depth interleaved. + // depth3 LEFT <- history[2] CoverSlot { - slot-size: root.side2-size; + slot-size: root.size3; + center-x: parent.cx - root.off3; + stage-height: parent.height; + dim: 0.55; + art: root.has-hist3 ? QueueState.coverflow-history[2].artwork : root.center-art; + has-art: root.has-hist3 && QueueState.coverflow-history[2].artwork.width > 0; + interactive: root.has-hist3; + visible: root.has-hist3; + navigate => { QueueState.play-history(2); } + } + // depth3 RIGHT <- upcoming[2] + CoverSlot { + slot-size: root.size3; + center-x: parent.cx + root.off3; + stage-height: parent.height; + dim: 0.55; + art: root.has-up3 ? QueueState.coverflow-upcoming[2].artwork : root.center-art; + has-art: root.has-up3 && QueueState.coverflow-upcoming[2].artwork.width > 0; + interactive: root.has-up3; + visible: root.has-up3; + navigate => { QueueState.play-coverflow-upcoming(2); } + } + // depth2 LEFT <- history[1] + CoverSlot { + slot-size: root.size2; center-x: parent.cx - root.off2; stage-height: parent.height; - dim: 0.45; - side: -1; - art: root.has-hist2 ? QueueState.history[1].artwork : root.center-art; - has-art: root.has-hist2 && QueueState.history[1].artwork.width > 0; + dim: 0.40; + art: root.has-hist2 ? QueueState.coverflow-history[1].artwork : root.center-art; + has-art: root.has-hist2 && QueueState.coverflow-history[1].artwork.width > 0; interactive: root.has-hist2; visible: root.has-hist2; navigate => { QueueState.play-history(1); } } - // right-2 (offset +2) <- upcoming-page[1] + // depth2 RIGHT <- upcoming[1] CoverSlot { - slot-size: root.side2-size; + slot-size: root.size2; center-x: parent.cx + root.off2; stage-height: parent.height; - dim: 0.45; - side: 1; - art: root.has-up2 ? QueueState.upcoming-page[1].artwork : root.center-art; - has-art: root.has-up2 && QueueState.upcoming-page[1].artwork.width > 0; + dim: 0.40; + art: root.has-up2 ? QueueState.coverflow-upcoming[1].artwork : root.center-art; + has-art: root.has-up2 && QueueState.coverflow-upcoming[1].artwork.width > 0; interactive: root.has-up2; visible: root.has-up2; - navigate => { QueueState.play-upcoming(1); } + navigate => { QueueState.play-coverflow-upcoming(1); } } - // left-1 (offset -1) <- history[0] + // depth1 LEFT <- history[0] CoverSlot { - slot-size: root.side1-size; + slot-size: root.size1; center-x: parent.cx - root.off1; stage-height: parent.height; - dim: 0.15; - side: -1; - art: root.has-hist1 ? QueueState.history[0].artwork : root.center-art; - has-art: root.has-hist1 && QueueState.history[0].artwork.width > 0; + dim: 0.22; + art: root.has-hist1 ? QueueState.coverflow-history[0].artwork : root.center-art; + has-art: root.has-hist1 && QueueState.coverflow-history[0].artwork.width > 0; interactive: root.has-hist1; visible: root.has-hist1; navigate => { QueueState.play-history(0); } } - // right-1 (offset +1) <- upcoming-page[0] + // depth1 RIGHT <- upcoming[0] CoverSlot { - slot-size: root.side1-size; + slot-size: root.size1; center-x: parent.cx + root.off1; stage-height: parent.height; - dim: 0.15; - side: 1; - art: root.has-up1 ? QueueState.upcoming-page[0].artwork : root.center-art; - has-art: root.has-up1 && QueueState.upcoming-page[0].artwork.width > 0; + dim: 0.22; + art: root.has-up1 ? QueueState.coverflow-upcoming[0].artwork : root.center-art; + has-art: root.has-up1 && QueueState.coverflow-upcoming[0].artwork.width > 0; interactive: root.has-up1; visible: root.has-up1; - navigate => { QueueState.play-upcoming(0); } + navigate => { QueueState.play-coverflow-upcoming(0); } } - // CENTER (offset 0) <- NowPlayingState. Declared LAST = paints on top. - // Non-interactive (no TouchArea), like the disabled Tauri center button. + // CENTER (depth 0) <- NowPlayingState. Declared LAST = paints on top. + // Non-interactive, like the disabled Tauri center button. CoverSlot { slot-size: root.base-art; center-x: parent.cx; stage-height: parent.height; dim: 0.0; - side: 0; art: root.center-art; has-art: root.center-has-art; interactive: false; } } - // --- Song card below the fan ---------------------------------------- - // Reuses the StaticPanel pattern verbatim, fed by NowPlayingState (unifies - // the Tauri dual-source). Pinned under the fan, respecting the 132px player - // clearance. + // --- Song card below the pyramid ------------------------------------ + // Reuses the StaticPanel pattern verbatim, fed by NowPlayingState. Pinned + // under the pyramid, respecting the 132px player clearance. VerticalLayout { x: 0px; y: 0px; diff --git a/crates/qbz-slint/ui/immersive/ImmersiveView.slint b/crates/qbz-slint/ui/immersive/ImmersiveView.slint index 3197ed34d..b5e081ee2 100644 --- a/crates/qbz-slint/ui/immersive/ImmersiveView.slint +++ b/crates/qbz-slint/ui/immersive/ImmersiveView.slint @@ -620,12 +620,12 @@ export component ImmersiveView inherits Rectangle { viewport-width: root.width; viewport-height: root.height; } - // (2c) Coverflow mode foreground (mode == 2) — a faithful PURE-SLINT 2D fan - // (now-playing centered + on top, history fanned left, upcoming right; - // scale-by-depth + far-edge shade + per-depth shadow + distance dimming; - // ~500ms reflow on track change). True-3D rotateY/perspective DROPPED - // (deferred to a wgpu/Skia session). Same conditional-mount + viewport-prop - // contract as the siblings (ADR-010). + // (2c) Coverflow mode foreground (mode == 2) — a CHEAP jukebox PYRAMID of + // flat scaled cards (now-playing centered + on top, 3 past left + 3 upcoming + // right; step-down scale + per-depth black-overlay attenuation; cards snap on + // click, no 3D / reflection / gradient / 500ms reflow). True-3D rotateY/ + // perspective remains deferred to a wgpu/Skia session. Same conditional-mount + // + viewport-prop contract as the siblings (ADR-010). if ImmersiveState.mode == 2: CoverflowPanel { x: 0px; y: 0px; diff --git a/crates/qbz-slint/ui/state.slint b/crates/qbz-slint/ui/state.slint index 2448ff5d3..c5bb9af6e 100644 --- a/crates/qbz-slint/ui/state.slint +++ b/crates/qbz-slint/ui/state.slint @@ -3247,6 +3247,15 @@ export global QueueState { // --- History tab ----------------------------------------------------- in property <[QueueItem]> history: []; + // --- Immersive coverflow (mode 2) ------------------------------------ + // The next 3 / previous 3 tracks, taken from the UNFILTERED queue so the + // coverflow pyramid is correct regardless of the sidebar's page or search + // filter. Index 0 = next / most-recent. Decoded artwork handles are reused + // across refreshes (id-diff) so a one-position shift never re-decodes the + // covers still on screen. + in property <[QueueItem]> coverflow-upcoming: []; + in property <[QueueItem]> coverflow-history: []; + // --- Shared ---------------------------------------------------------- // Active tab: 0 = Queue, 1 = History. in-out property tab: 0; @@ -3256,6 +3265,10 @@ export global QueueState { // --- Callbacks (wired to the Rust queue controller) ------------------ // Play the upcoming entry at `index` within the current page slice. callback play-upcoming(int); + // Play an upcoming entry by its QUEUE-WIDE (unfiltered) index. Used by the + // immersive coverflow, whose cards index `coverflow-upcoming` (= the real + // next-3, page/search-independent) — NOT the paged play-upcoming. + callback play-coverflow-upcoming(int); // Play a history entry by its `index` in the `history` list. callback play-history(int); // Remove the upcoming entry at `index` within the current page slice.