Documentation
¶
Overview ¶
Package queue is the playback queue model shared by the TUI and the C API (via corelib), so shuffle/repeat/prev-history behaviour is defined once instead of being re-implemented per frontend.
Index ¶
- type Queue
- func (q *Queue) AdvanceAuto() bool
- func (q *Queue) AdvanceLinear() bool
- func (q *Queue) AlignIndex(i int)
- func (q *Queue) Append(tracks ...deezer.Track)
- func (q *Queue) Current() (deezer.Track, bool)
- func (q *Queue) CycleRepeat() Repeat
- func (q *Queue) Index() int
- func (q *Queue) InsertAfterCurrent(tracks ...deezer.Track) int
- func (q *Queue) Len() int
- func (q *Queue) Move(i, j int) bool
- func (q *Queue) Next() bool
- func (q *Queue) PeekNext() (deezer.Track, bool)
- func (q *Queue) Prev() bool
- func (q *Queue) Remove(i int) bool
- func (q *Queue) Repeat() Repeat
- func (q *Queue) Set(tracks []deezer.Track, start int)
- func (q *Queue) SetIndex(i int)
- func (q *Queue) SetRepeat(r Repeat)
- func (q *Queue) SetShuffle(on bool)
- func (q *Queue) Shuffle() bool
- func (q *Queue) ToggleShuffle() bool
- func (q *Queue) Tracks() []deezer.Track
- func (q *Queue) Version() uint64
- type Repeat
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue holds an ordered track list plus a cursor, shuffle/repeat state and a visited-index history (so Prev under shuffle retraces the real path). The zero value is a valid empty queue. Not safe for concurrent use; callers serialize.
func (*Queue) AdvanceAuto ¶
AdvanceAuto is called when a track ends naturally: RepeatOne replays the current track (reports true, cursor unchanged); otherwise it behaves like Next. Returns whether playback should continue.
func (*Queue) AdvanceLinear ¶
AdvanceLinear advances the cursor to the deterministic next track (linear +1, or a RepeatAll wrap) regardless of shuffle/RepeatOne, matching exactly what PeekNext returned. Used to sync the cursor after the player gaplessly swapped in the preloaded (always deterministic) next track, so the cursor can't jump to a random shuffle pick that differs from the audio. Reports whether it moved.
func (*Queue) AlignIndex ¶
AlignIndex moves the cursor (clamped) WITHOUT recording navigation history. It exists for remote/GUI cursor synchronisation: a client that owns its own queue calls Set(tracks, 0) then AlignIndex(N) to point the engine cursor at the row it is already playing. Because the row was not "picked", pushing it onto history would make a later Prev jump to a never-played track. Genuine jumps (a queue-view pick, a remote QueueJump command) use SetIndex instead.
func (*Queue) Append ¶
Append adds tracks to the end without moving the cursor. Under shuffle the stale permutation is rebuilt lazily (see ensureOrder).
func (*Queue) CycleRepeat ¶
func (*Queue) InsertAfterCurrent ¶
InsertAfterCurrent inserts tracks immediately after the current one (at the head when the queue is empty or has no current track), without moving the cursor, and returns the insertion position. Under shuffle the new tracks are spliced directly after the current position in the cycle, so "play next" holds there too.
func (*Queue) Move ¶
Move relocates the track at i to position j, reporting whether it did. The cursor, history and shuffle cycle all follow the tracks they referenced, so reordering never changes what's playing or what Prev retraces to.
func (*Queue) Next ¶
Next advances the cursor following shuffle/repeat rules and reports whether it moved to a playable track. RepeatOne is treated as a normal advance here (the caller decides whether a natural finish should instead replay current — see AdvanceAuto).
func (*Queue) PeekNext ¶
PeekNext returns the track Next would advance to, WITHOUT mutating the queue, for the deterministic cases only (linear order, with RepeatAll wrap). Under shuffle or RepeatOne it returns ok=false, since the next track isn't fixed — callers use this to decide whether a gapless preload is safe.
func (*Queue) Remove ¶
Remove deletes the track at i and reports whether it did. The cursor keeps following the track it was on; removing the current track leaves the cursor in place (the next track slides in), clamped to the new end. History entries are remapped and references to the removed track dropped. Under shuffle the removed index is deleted from the cycle, which otherwise continues unchanged.
func (*Queue) Set ¶
Set replaces the queue contents and positions the cursor at start (clamped). History is cleared.
func (*Queue) SetIndex ¶
SetIndex moves the cursor (clamped); use when the user picks a row directly. The previous position is recorded so Prev retraces to the track that was actually playing before the pick. For a remote/GUI client that only needs to align the engine cursor to a row that is ALREADY playing (no user pick), use AlignIndex instead so no synthetic history entry is created.