Compare commits

..
Author SHA1 Message Date
rootandClaude Opus 5.5 29cc9a03d4 Random Album Radio: every new song adds another album, continuous queue (build 61)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 10:35:06 -08:00
2 changed files with 25 additions and 7 deletions

No files matched your search

+24 -6
View File
@@ -219,11 +219,19 @@ final class PlaybackManager: StemEngineListener, @unchecked Sendable {
@ObservationIgnored private var stationGen = 0
@ObservationIgnored private var stationBusy = false
private static let radioAlbumsAhead = 8
private static let radioAlbumsLow = 3
/// Each new song adds an album, up to this many ahead (keeps the queue from growing without end).
private static let radioAlbumsMax = 40
/// Album radio: the song the last top-up saw, and songs started since that haven't added their album yet.
@ObservationIgnored private var radioSeenUid: Int64?
@ObservationIgnored private var radioOwed = 0
private static let radioSongsBatch = 100
private static let radioSongsLow = 25
private func setStation(_ s: Station?) { station = s; stationGen += 1; stationBusy = false }
private func setStation(_ s: Station?) {
station = s; stationGen += 1; stationBusy = false
radioSeenUid = queue.indices.contains(index) ? queue[index].uid : nil
radioOwed = 0
}
private func albumDeck() async throws -> [String] {
var deck = (try? await plex.albums().map(\.ratingKey)) ?? []
@@ -268,18 +276,28 @@ final class PlaybackManager: StemEngineListener, @unchecked Sendable {
let gen = stationGen
switch st {
case .albums(let saved):
// Every song that starts (the next track, a skip, a jump to another album) owes one more album,
// so the queue always runs on past what's playing.
let uid = queue[index].uid
if uid != radioSeenUid { radioSeenUid = uid; radioOwed += 1 }
let ahead = Set(queue[index...].map { $0.track.albumKey ?? $0.track.album }).count
guard ahead <= Self.radioAlbumsLow else { return }
let want = min(max(Self.radioAlbumsAhead + 1 - ahead, radioOwed), Self.radioAlbumsMax - ahead)
guard want > 0 else { radioOwed = 0; return }
stationBusy = true
let owed = radioOwed
Task { @MainActor in
defer { if gen == stationGen { stationBusy = false } }
var got = false
// Checks again once the albums are in, unless nothing came back (server down: don't spin).
defer { if gen == stationGen { stationBusy = false; if got { topUpStation() } } }
var deck = saved
if deck.isEmpty { deck = (try? await albumDeck()) ?? [] }
let take = Array(deck.prefix(Self.radioAlbumsAhead + 1 - ahead))
if deck.count < want { deck += (try? await albumDeck()) ?? [] }
let take = Array(deck.prefix(want))
deck.removeFirst(take.count)
let tracks = await albumTracks(take)
guard gen == stationGen else { return }
station = .albums(deck)
radioOwed = max(radioOwed - owed, 0)
got = !tracks.isEmpty
addToQueue(tracks)
}
case .songs:
+1 -1
View File
@@ -9,7 +9,7 @@ settings:
# iOS needs a plain number for the bundle version; the label is what the app and releases show.
MARKETING_VERSION: "0.10.1"
VERSION_LABEL: "0.10.1"
CURRENT_PROJECT_VERSION: "60"
CURRENT_PROJECT_VERSION: "61"
# Dev builds override these (build-ipa.sh dev) so they install next to the release app.
APP_ID: org.cdnutter.stemify
APP_NAME: Stemify