diff --git a/CHANGELOG.md b/CHANGELOG.md index f51554c..0eed1fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ One section per version, newest first. +## v0.6.3 (2026-11-04) + +### Features + +- On the now-playing screen the cover flips around when the next track has a different picture, and settles with a small bounce. Tracks that share a picture do not flip, even on servers such as Navidrome that give every track its own cover id. + ## v0.6.2 (2026-11-04) ### Bug fixes diff --git a/Cargo.lock b/Cargo.lock index 813724c..a369aee 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4385,7 +4385,7 @@ checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" [[package]] name = "remus" -version = "0.6.2" +version = "0.6.3" dependencies = [ "anyhow", "directories", diff --git a/Cargo.toml b/Cargo.toml index 362a0c7..f7db2be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "remus" -version = "0.6.2" +version = "0.6.3" edition = "2024" license = "MIT" diff --git a/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml b/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml index 0083013..a430109 100644 --- a/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml +++ b/flatpak/me.anshorei.Fettleshed.Remus.metainfo.xml @@ -20,6 +20,7 @@ + diff --git a/src/app.rs b/src/app.rs index 96cdd6d..3fb22ad 100644 --- a/src/app.rs +++ b/src/app.rs @@ -128,6 +128,9 @@ enum Setting { /// How long the UI takes to change from one palette to the next. const FADE: Duration = Duration::from_millis(800); +/// How long the now-playing cover takes to turn edge-on, the `in` animation +/// of the `turned` state in NowPlayingView. The turn back is in the .slint. +const FLIP_OUT: Duration = Duration::from_millis(170); /// The palette on screen and the one it is fading towards. struct Fade { @@ -199,6 +202,8 @@ struct Covers { /// Per cover id, whatever size it was decoded at. None for a cover with /// too little colour to base a palette on. tones: LruCache>, + /// Hash of each decoded cover's pixels, to tell two ids with one picture. + prints: LruCache, pending: HashSet, failed: HashSet, limit: Arc, @@ -247,6 +252,20 @@ pub struct App { icons: RefCell>>, settings: Settings, fade: Fade, + /// The now-playing art on screen, `None` when nothing is playing. + art_shown: Option, + /// Runs while the cover turns away; the new art goes up when it fires. + flip_timer: Timer, +} + +/// What the now-playing art shows, to decide whether a track change flips it. +/// Compared by picture, not by id: Navidrome gives every track its own cover +/// id even when the whole album shares one image. +struct ShownArt { + /// Cover id of the track the art belongs to. + id: Option, + /// Hash of the decoded cover, `None` for the letter placeholder. + print: Option, } impl App { @@ -282,6 +301,7 @@ impl App { covers: Covers { images: LruCache::new(NonZeroUsize::new(400).unwrap()), tones: LruCache::new(NonZeroUsize::new(400).unwrap()), + prints: LruCache::new(NonZeroUsize::new(400).unwrap()), pending: HashSet::new(), failed: HashSet::new(), limit: Arc::new(Semaphore::new(6)), @@ -302,6 +322,8 @@ impl App { last_save: Instant::now(), login_focus: 0, toast_timer: Timer::default(), + art_shown: None, + flip_timer: Timer::default(), prompts: Prompts::Keyboard, icons: RefCell::default(), settings: config::load_settings(), @@ -1449,11 +1471,12 @@ impl App { None } - fn cover_loaded(&mut self, key: CoverKey, result: Result<(SharedPixelBuffer, Option)>) { + fn cover_loaded(&mut self, key: CoverKey, result: Result<(SharedPixelBuffer, Option, u64)>) { self.covers.pending.remove(&key); match result { - Ok((buf, tone)) => { + Ok((buf, tone, print)) => { self.covers.images.put(key.clone(), Image::from_rgb8(buf)); + self.covers.prints.put(key.clone(), print); // The first size decoded decides: other sizes give a tone that // differs in the last digits, which would restart the fade. if !self.covers.tones.contains(&key.0) { @@ -1463,7 +1486,16 @@ impl App { } Err(e) => { log::debug!("cover {} failed: {e:#}", key.0); + // The playing track's art may be waiting on this to flip. + let playing = self + .current + .and_then(|i| self.queue.get(i)) + .and_then(|s| s.cover_art.as_deref()) + == Some(key.0.as_str()); self.covers.failed.insert(key); + if playing { + self.render_player(); + } // The playing track's cover failing means the brand palette. self.update_theme(); return; @@ -1773,18 +1805,16 @@ impl App { self.ui.set_np_paused(self.paused); match song { Some(s) => { - let px = self.now_playing_px(); - let cover = s.cover_art.as_deref().and_then(|id| self.cover(id, px)); - self.ui - .set_np_letter(initial(s.album.as_deref().unwrap_or(&s.title)).into()); - self.ui.set_np_tint(tint(s.album.as_deref().unwrap_or(&s.title))); - self.ui.set_np_has_cover(cover.is_some()); - self.ui.set_np_cover(cover.unwrap_or_default()); + self.update_art(&s); + self.prefetch_next_cover(); self.ui.set_np_title(s.title.into()); self.ui.set_np_artist(s.artist.unwrap_or_default().into()); self.ui.set_np_album(s.album.unwrap_or_default().into()); } None => { + self.flip_timer.stop(); + self.ui.set_np_flip_out(false); + self.art_shown = None; self.ui.set_np_has_cover(false); self.ui.set_np_cover(Image::default()); self.ui.set_np_letter("".into()); @@ -1797,6 +1827,94 @@ impl App { self.update_theme(); } + /// Shows the song's art, flipping the cover if it is a different picture + /// from the one on screen. While a changed track's cover loads, the old one + /// stays up: the load ends in a render either way, and decides then. + fn update_art(&mut self, s: &Song) { + if self.flip_timer.running() { + // Mid-turn: the midpoint puts up whatever is current then. + return; + } + let Some(shown) = &self.art_shown else { + // From nothing playing: no flip, the cover fades in when it loads. + self.render_art(s); + return; + }; + if shown.id == s.cover_art || self.screen != Screen::NowPlaying { + self.render_art(s); + return; + } + let Some(print) = self.art_print(s) else { return }; + if Some(print) == self.art_shown.as_ref().map(|a| a.print) { + log::debug!("same cover picture under a new id, no flip"); + self.render_art(s); + } else { + log::debug!("cover picture changed, flipping"); + self.ui.set_np_flip_out(true); + self.flip_timer + .start(slint::TimerMode::SingleShot, FLIP_OUT, || with_app(|app| app.flip_in())); + } + } + + /// The picture the song's art will show: `Some(None)` for the placeholder, + /// `None` while its cover is still loading. + fn art_print(&mut self, s: &Song) -> Option> { + let Some(id) = s.cover_art.as_deref() else { + return Some(None); + }; + let key: CoverKey = (id.to_string(), self.now_playing_px()); + if let Some(p) = self.covers.prints.get(&key) { + return Some(Some(*p)); + } + if self.covers.failed.contains(&key) { + return Some(None); + } + // Starts the load if it is not under way. + self.cover(id, key.1); + None + } + + /// Loads the next track's cover at the now-playing size, so a skip can + /// tell at once whether the picture changes. + fn prefetch_next_cover(&mut self) { + if self.screen != Screen::NowPlaying { + return; + } + let next = self.current.and_then(|i| self.queue.get(i + 1)); + if let Some(id) = next.and_then(|s| s.cover_art.clone()) { + let px = self.now_playing_px(); + self.cover(&id, px); + } + } + + /// Puts the song's cover, or its letter placeholder, on screen. + fn render_art(&mut self, s: &Song) { + let px = self.now_playing_px(); + let cover = s.cover_art.as_deref().and_then(|id| self.cover(id, px)); + let print = s + .cover_art + .as_ref() + .and_then(|id| self.covers.prints.get(&(id.clone(), px)).copied()) + .filter(|_| cover.is_some()); + let name = s.album.as_deref().unwrap_or(&s.title); + self.ui.set_np_letter(initial(name).into()); + self.ui.set_np_tint(tint(name)); + self.ui.set_np_has_cover(cover.is_some()); + self.ui.set_np_cover(cover.unwrap_or_default()); + self.art_shown = Some(ShownArt { + id: s.cover_art.clone(), + print, + }); + } + + /// The cover is edge-on: swap in the current track's art and turn it back. + fn flip_in(&mut self) { + if let Some(s) = self.current.and_then(|i| self.queue.get(i)).cloned() { + self.render_art(&s); + } + self.ui.set_np_flip_out(false); + } + // ---------------------------------------------------------------- now playing fn open_now_playing(&mut self) { @@ -2033,7 +2151,7 @@ fn bucket(px: f32) -> u32 { } /// Decodes a cover at `px` and works out its tone for the album art palette. -fn decode_cover(bytes: &[u8], px: u32) -> Result<(SharedPixelBuffer, Option)> { +fn decode_cover(bytes: &[u8], px: u32) -> Result<(SharedPixelBuffer, Option, u64)> { let img = image::load_from_memory(bytes)?; let img = if img.width() > px || img.height() > px { img.resize(px, px, image::imageops::FilterType::Triangle) @@ -2046,8 +2164,11 @@ fn decode_cover(bytes: &[u8], px: u32) -> Result<(SharedPixelBuffer, .to_rgb8(); let tone = crate::palette::tone(small.as_raw()); let rgb = img.to_rgb8(); + let mut hasher = std::hash::DefaultHasher::new(); + std::hash::Hash::hash(rgb.as_raw(), &mut hasher); + let print = std::hash::Hasher::finish(&hasher); let buf = SharedPixelBuffer::clone_from_slice(rgb.as_raw(), rgb.width(), rgb.height()); - Ok((buf, tone)) + Ok((buf, tone, print)) } fn color(lab: Lab) -> Color { @@ -2156,6 +2277,22 @@ fn join_dot>>(parts: I) -> String { mod tests { use super::*; + fn png(pixel: [u8; 3]) -> Vec { + let img = image::RgbImage::from_pixel(8, 8, image::Rgb(pixel)); + let mut out = std::io::Cursor::new(Vec::new()); + img.write_to(&mut out, image::ImageFormat::Png).unwrap(); + out.into_inner() + } + + #[test] + fn one_picture_under_two_ids_has_one_print() { + let (_, _, a) = decode_cover(&png([120, 20, 30]), 64).unwrap(); + let (_, _, b) = decode_cover(&png([120, 20, 30]), 64).unwrap(); + let (_, _, c) = decode_cover(&png([20, 120, 30]), 64).unwrap(); + assert_eq!(a, b); + assert_ne!(a, c); + } + #[test] fn grid_window_is_row_aligned() { assert_eq!(window(1000, 0, 5, false), (0, 55)); diff --git a/ui/app.slint b/ui/app.slint index 5628ce3..0ceae40 100644 --- a/ui/app.slint +++ b/ui/app.slint @@ -756,6 +756,9 @@ component NowPlayingView inherits Rectangle { in property duration; in property paused; in property has-track; + // True while the cover turns away; the app swaps the cover at edge-on and + // sets it back to false to turn the new one in. + in property flip-out; in property <[Item]> queue; in property queue-count; in property queue-selected; @@ -786,9 +789,11 @@ component NowPlayingView inherits Rectangle { spacing: 10px * Theme.s; width: root.art-size; - Art { + art := Art { width: root.art-size; height: root.art-size; + // Set here so the turned state below has a value to return to. + transform-scale-x: 100%; source: root.cover; has-image: root.has-cover; tint: root.tint; @@ -873,6 +878,20 @@ component NowPlayingView inherits Rectangle { } } } + + // A flip around the vertical axis, faked by squashing the width: Slint has + // no perspective. The turn back overshoots a little and settles. + states [ + turned when root.flip-out: { + art.transform-scale-x: 0%; + in { + animate art.transform-scale-x { duration: 170ms; easing: ease-in; } + } + out { + animate art.transform-scale-x { duration: 380ms; easing: cubic-bezier(0.34, 1.5, 0.64, 1); } + } + } + ] } export component AppWindow inherits Window { @@ -936,6 +955,7 @@ export component AppWindow inherits Window { in property np-position; in property np-duration; in property np-paused; + in property np-flip-out; in property <[Item]> queue-items; in property queue-count; in property queue-selected; @@ -1097,6 +1117,7 @@ export component AppWindow inherits Window { duration: root.np-duration; paused: root.np-paused; has-track: root.np-has-track; + flip-out: root.np-flip-out; queue: root.queue-items; queue-count: root.queue-count; queue-selected: root.queue-selected;