feat(album): multi-disc "Disc N" headers with per-disc context menu

Album and local-album track lists render a "Disc N" header above the
first track of each disc when the album spans more than one disc
(media_number-driven; single-disc albums render flat), matching Tauri.
Each header carries a context menu (new — Tauri has none) with Play all /
Shuffle / Add to queue / Play next scoped to that disc's tracks only; the
whole-album header buttons are unchanged.

The menu lives in a DiscHeaderMenu wrapper because Slint rejects a
PopupWindow placed directly under a for/if delegate — wrapping it makes
the popup a non-root child (same pattern as TrackRow + TrackContextMenu).
Every TrackItem constructor gains disc-header-number: 0; artist
top-tracks (a flat cross-album list) default the disc to 1.

cc
This commit is contained in:
vicrodh committed 2026-06-15 19:19:21 -06:00
1 parent 2e337f6039
commit 30bd959bf7
16 files changed
+506 -40

No files matched your search

+55 -1
View File
@@ -80,6 +80,10 @@ pub struct TrackData {
pub quality_tier: String,
pub quality_detail: String,
pub explicit: bool,
/// Disc/media number (Qobuz `media_number`, defaulting to 1 when absent).
/// Used after mapping to decide where the "Disc N" headers fall when the
/// album spans more than one disc.
pub disc: u32,
}
/// Fetch and map a full album by id.
@@ -260,6 +264,8 @@ fn map_track(track: Track) -> TrackData {
track.maximum_sampling_rate,
),
explicit: track.parental_warning,
// Tauri: `disc = track.media_number ?? 1`.
disc: track.media_number.unwrap_or(1),
}
}
@@ -294,10 +300,41 @@ pub fn apply_album(window: &AppWindow, data: AlbumData) {
// album link target is this album's own id (the album column is not
// shown here, but album-id keeps the row model complete).
let album_id: slint::SharedString = data.id.clone().into();
// Multi-disc grouping (Tauri PurchaseAlbumDetailView: groupByDisc +
// isMultiDisc). The album is "multi-disc" when its tracks span more than
// one distinct disc number; only then do we emit "Disc N" headers. The
// header is stamped on the first track of each disc run, and tracks stay
// in their delivered order (Qobuz returns them disc-then-track ordered).
let is_multi_disc = {
let mut seen: Option<u32> = None;
let mut multi = false;
for track in &data.tracks {
match seen {
Some(d) if d != track.disc => {
multi = true;
break;
}
_ => seen = Some(track.disc),
}
}
multi
};
let mut prev_disc: Option<u32> = None;
let tracks: Vec<TrackItem> = data
.tracks
.into_iter()
.map(|track| TrackItem {
.map(|track| {
// Stamp the disc number on the first row of each disc run, but
// only for multi-disc albums (single-disc renders flat → 0). The
// delegate renders `@tr("Disc") <n>` above the row when this is
// > 0, matching the Tauri `{$t('album.disc')} {discNum}` markup.
let disc_header_number = if is_multi_disc && prev_disc != Some(track.disc) {
track.disc as i32
} else {
0
};
prev_disc = Some(track.disc);
TrackItem {
id: track.id.clone().into(),
number: track.number.into(),
title: track.title.into(),
@@ -319,6 +356,8 @@ pub fn apply_album(window: &AppWindow, data: AlbumData) {
// Qobuz album-detail rows; local albums override via map_local_track.
source: "qobuz".into(),
unlocking: false,
disc_header_number,
}
})
.collect();
@@ -489,6 +528,21 @@ pub fn selected_play_tracks(window: &AppWindow) -> Vec<Track> {
})
}
/// The full catalog Track objects for one disc of the open album (for the
/// per-disc "Disc N" header menu), resolved from the stashed raw album tracks.
/// `disc` matches `media_number` (defaulting to 1, exactly as `map_track`
/// stamps `TrackData.disc`), so it lines up with the rendered "Disc N" header.
/// Preserves the delivered (disc-then-track) order.
pub fn disc_play_tracks(disc: i32) -> Vec<Track> {
PLAY_TRACKS.with(|cell| {
cell.borrow()
.iter()
.filter(|t| t.media_number.unwrap_or(1) as i32 == disc)
.cloned()
.collect()
})
}
/// Apply decoded header artwork pixels. Runs on the Slint event loop.
pub fn apply_artwork(window: &AppWindow, pixels: &[u8], width: u32, height: u32) {
let mut buffer = slint::SharedPixelBuffer::<slint::Rgba8Pixel>::new(width, height);
+5
View File
@@ -376,6 +376,9 @@ fn map_track(index: usize, track: PageArtistTrack) -> TrackData {
quality_tier: tier(bit_depth).to_string(),
quality_detail: crate::quality::detail(bit_depth, sample_rate),
explicit: track.parental_warning.unwrap_or(false),
// Artist top-tracks are a flat cross-album list and never render
// "Disc N" headers, so the disc value is unused here — default to 1.
disc: 1,
}
}
@@ -511,6 +514,8 @@ pub fn apply_artist(window: &AppWindow, data: ArtistData) {
cache_progress: 0.0,
source: "qobuz".into(),
unlocking: false,
// Disc grouping is album-detail only; flat lists carry none.
disc_header_number: 0,
})
.collect();
let release_sections: Vec<DiscoverSection> = data
+2
View File
@@ -486,6 +486,8 @@ pub fn apply_favorites(window: &AppWindow, data: FavData) {
cache_progress: 0.0,
source: "qobuz".into(),
unlocking: false,
// Disc grouping is album-detail only; flat lists carry none.
disc_header_number: 0,
})
.collect();
// `tracks` is the full set the artwork pipeline targets;
+8
View File
@@ -776,6 +776,8 @@ fn top_track_to_item(t: &TopTrack) -> TrackItem {
cache_progress: 0.0,
source: "qobuz".into(),
unlocking: false,
// Disc grouping is album-detail only; flat lists carry none.
disc_header_number: 0,
}
}
@@ -793,6 +795,12 @@ fn playlist_to_item(p: &PlaylistSlim) -> SearchPlaylistItem {
cover2: slint::Image::default(),
cover3: slint::Image::default(),
cover4: slint::Image::default(),
// Label-landing playlist cards carry no category subtag, and a
// transparent dominant-colour is the sentinel for "no letterbox":
// the collage keeps the legacy cover-fit (the contain + dominant-
// colour treatment is Discover-only).
category: "".into(),
dominant_color: slint::Color::from_argb_u8(0, 0, 0, 0),
}
}
+52 -3
View File
@@ -783,6 +783,10 @@ fn map_local_track(t: qbz_library::LocalTrack) -> TrackItem {
}
.into(),
unlocking: false,
// Default: no disc header. The flat Library Tracks tab never groups by
// disc; the local-album DETAIL view stamps this afterwards (see
// apply_album_version) for multi-disc local albums.
disc_header_number: 0,
}
}
@@ -1336,17 +1340,48 @@ pub fn apply_album_version(window: &AppWindow, index: i32) {
// Client-side filter (Qobuz album view parity): match title/artist; the
// header badge/info stay album-level (computed from the full version above).
let q = album_query().to_lowercase();
let items: Vec<TrackItem> = tracks
let shown: Vec<&qbz_library::LocalTrack> = tracks
.iter()
.filter(|t| {
q.is_empty()
|| t.title.to_lowercase().contains(&q)
|| t.artist.to_lowercase().contains(&q)
})
.cloned()
.collect();
// Multi-disc grouping (mirrors the Qobuz album view): the album is
// multi-disc when its shown tracks span more than one distinct disc
// number, and only then do we stamp "Disc N" headers on the first row of
// each disc run. Local tracks are already disc-then-track sorted upstream
// (album_versions sorts by (disc_number, track_number)).
let is_multi_disc = {
let mut seen: Option<u32> = None;
let mut multi = false;
for t in &shown {
let disc = t.disc_number.unwrap_or(1);
match seen {
Some(d) if d != disc => {
multi = true;
break;
}
_ => seen = Some(disc),
}
}
multi
};
let mut prev_disc: Option<u32> = None;
let items: Vec<TrackItem> = shown
.into_iter()
.map(|t| {
let mut it = map_local_track(t);
let disc = t.disc_number.unwrap_or(1);
let disc_header_number = if is_multi_disc && prev_disc != Some(disc) {
disc as i32
} else {
0
};
prev_disc = Some(disc);
let mut it = map_local_track(t.clone());
it.album_id = group_key.clone().into();
it.disc_header_number = disc_header_number;
it
})
.collect();
@@ -1676,6 +1711,20 @@ pub fn current_album_version_tracks(window: &AppWindow) -> Vec<qbz_library::Loca
.unwrap_or_default()
}
/// The current version's tracks for one disc (for the per-disc "Disc N" header
/// menu), filtered by `disc_number` (defaulting to 1 — exactly as
/// `apply_album_version` stamps the "Disc N" header). Preserves the upstream
/// (disc, track) order.
pub fn current_album_disc_tracks(
window: &AppWindow,
disc: i32,
) -> Vec<qbz_library::LocalTrack> {
current_album_version_tracks(window)
.into_iter()
.filter(|t| t.disc_number.unwrap_or(1) as i32 == disc)
.collect()
}
// ============================ Folders (flat) ==============================
//
// The Folders tab (flat mode) is the album grid grouped by directory rather
+8
View File
@@ -885,6 +885,8 @@ fn row_item(item: &RowItem, queue: Option<&QueueTrack>) -> TrackItem {
cache_progress: 0.0,
source: "qobuz".into(),
unlocking: false,
// Disc grouping is album-detail only; playlist rows carry none.
disc_header_number: 0,
},
RowItem::Local(track) | RowItem::Plex(track) => {
let (tier, quality_detail, _) = crate::quality::badge(
@@ -924,6 +926,8 @@ fn row_item(item: &RowItem, queue: Option<&QueueTrack>) -> TrackItem {
}
.into(),
unlocking: false,
// Disc grouping is album-detail only; playlist rows carry none.
disc_header_number: 0,
}
}
RowItem::LocalFile { path } => {
@@ -952,6 +956,8 @@ fn row_item(item: &RowItem, queue: Option<&QueueTrack>) -> TrackItem {
cache_progress: 0.0,
source: "local".into(),
unlocking: false,
// Disc grouping is album-detail only; playlist rows carry none.
disc_header_number: 0,
}
}
// Honest unavailable row: distinct title + the raw stored ref in
@@ -991,6 +997,8 @@ fn row_item(item: &RowItem, queue: Option<&QueueTrack>) -> TrackItem {
cache_progress: 0.0,
source: if *kind == "plex" { "plex" } else { "" }.into(),
unlocking: false,
// Disc grouping is album-detail only; playlist rows carry none.
disc_header_number: 0,
},
}
}
+125
View File
@@ -6916,6 +6916,79 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
});
}
// Per-disc "Disc N" header ⋯ menu (Qobuz album) — each action is scoped to
// that disc's tracks only, resolved from the album's stashed raw catalog
// tracks. Reuses the SAME queue ops as the album-header buttons (play_tracks
// / play_album_shuffled's xorshift / enqueue_tracks), just over the disc
// subset rather than the whole album.
{
let runtime = app_runtime.clone();
let weak = window.as_weak();
let handle = tokio_rt.handle().clone();
window
.global::<AlbumActions>()
.on_disc_action(move |disc, action| {
let mut tracks = album::disc_play_tracks(disc);
if tracks.is_empty() {
return;
}
match action.as_str() {
"play" => {
playback::play_tracks(
runtime.clone(),
weak.clone(),
handle.clone(),
tracks,
0,
);
}
"shuffle" => {
// Same SystemTime-seeded xorshift Fisher-Yates as the
// album-header Shuffle (playback::play_album_shuffled),
// applied to the disc subset before play_tracks.
let mut seed = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_nanos() as u64)
.unwrap_or(1)
| 1;
for i in (1..tracks.len()).rev() {
seed ^= seed << 13;
seed ^= seed >> 7;
seed ^= seed << 17;
let j = (seed % (i as u64 + 1)) as usize;
tracks.swap(i, j);
}
playback::play_tracks(
runtime.clone(),
weak.clone(),
handle.clone(),
tracks,
0,
);
}
"queue" => {
playback::enqueue_tracks(
runtime.clone(),
handle.clone(),
tracks,
false,
);
}
"play-next" => {
playback::enqueue_tracks(
runtime.clone(),
handle.clone(),
tracks,
true,
);
}
other => {
log::warn!("[qbz-slint] album disc-action: unknown action {other}");
}
}
});
}
// Artist in-page search — client-side filter over Popular Tracks
// and every release-section album.
{
@@ -8885,6 +8958,58 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
local_library::search_album(weak.clone(), q.to_string());
});
}
{
// Per-disc "Disc N" header ⋯ menu (local album) — scoped to that disc's
// tracks only, resolved from the open version's track cache. Reuses the
// SAME local queue ops as the header play-all / shuffle buttons
// (play_local_tracks, shuffle flag) and the per-row menu's
// enqueue_local_tracks, just over the disc subset.
let runtime = app_runtime.clone();
let weak = window.as_weak();
let handle = tokio_rt.handle().clone();
window
.global::<LocalAlbumActions>()
.on_disc_action(move |disc, action| {
let Some(w) = weak.upgrade() else { return };
let tracks = local_library::current_album_disc_tracks(&w, disc);
if tracks.is_empty() {
return;
}
match action.as_str() {
"play" => playback::play_local_tracks(
runtime.clone(),
weak.clone(),
handle.clone(),
tracks,
0,
false,
),
"shuffle" => playback::play_local_tracks(
runtime.clone(),
weak.clone(),
handle.clone(),
tracks,
0,
true,
),
"queue" => playback::enqueue_local_tracks(
runtime.clone(),
handle.clone(),
tracks,
false,
),
"play-next" => playback::enqueue_local_tracks(
runtime.clone(),
handle.clone(),
tracks,
true,
),
other => {
log::warn!("[qbz-slint] local disc-action: unknown action {other}");
}
}
});
}
// Local Library — Albums tab controls (search / sort re-query page 1;
// load-more pages on scroll; retry) + the shared AlbumCollectionView's
+2
View File
@@ -295,6 +295,8 @@ fn to_item(track: &Track) -> TrackItem {
cache_progress: 0.0,
source: "qobuz".into(),
unlocking: false,
// Disc grouping is album-detail only; flat lists carry none.
disc_header_number: 0,
}
}
+2
View File
@@ -706,6 +706,8 @@ fn track_to_item(track: &qbz_models::QueueTrack, resolver_index: usize) -> Track
cache_status: 0,
cache_progress: 0.0,
unlocking: false,
// Disc grouping is album-detail only; flat lists carry no header.
disc_header_number: 0,
}
}
+2
View File
@@ -550,6 +550,8 @@ pub(crate) fn to_item(track: &Track) -> TrackItem {
cache_progress: 0.0,
source: "qobuz".into(),
unlocking: false,
// Disc grouping is album-detail only; flat lists carry none.
disc_header_number: 0,
}
}
+8
View File
@@ -385,6 +385,8 @@ fn track_item(row: TrackRowData) -> TrackItem {
cache_progress: 0.0,
source: "qobuz".into(),
unlocking: false,
// Disc grouping is album-detail only; flat lists carry none.
disc_header_number: 0,
}
}
@@ -417,6 +419,12 @@ pub(crate) fn playlist_item(row: PlaylistRow) -> SearchPlaylistItem {
cover2: slint::Image::default(),
cover3: slint::Image::default(),
cover4: slint::Image::default(),
// Search playlist results carry no category subtag, and a transparent
// dominant-colour is the sentinel for "no letterbox" — the collage
// keeps the legacy cover-fit (contain + dominant colour is Discover-
// only).
category: "".into(),
dominant_color: slint::Color::from_argb_u8(0, 0, 0, 0),
}
}