queue

package
v3.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: AGPL-3.0 Imports: 2 Imported by: 0

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

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 New

func New() *Queue

New returns an empty queue.

func (*Queue) AdvanceAuto

func (q *Queue) AdvanceAuto() bool

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

func (q *Queue) AdvanceLinear() bool

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

func (q *Queue) AlignIndex(i int)

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

func (q *Queue) Append(tracks ...deezer.Track)

Append adds tracks to the end without moving the cursor. Under shuffle the stale permutation is rebuilt lazily (see ensureOrder).

func (*Queue) Current

func (q *Queue) Current() (deezer.Track, bool)

Current returns the current track and whether one exists.

func (*Queue) CycleRepeat

func (q *Queue) CycleRepeat() Repeat

func (*Queue) Index

func (q *Queue) Index() int

Index returns the current cursor (−1 if empty).

func (*Queue) InsertAfterCurrent

func (q *Queue) InsertAfterCurrent(tracks ...deezer.Track) int

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) Len

func (q *Queue) Len() int

Len reports the number of queued tracks.

func (*Queue) Move

func (q *Queue) Move(i, j int) bool

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

func (q *Queue) Next() bool

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

func (q *Queue) PeekNext() (deezer.Track, bool)

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) Prev

func (q *Queue) Prev() bool

Prev steps back, retracing shuffle history when present.

func (*Queue) Remove

func (q *Queue) Remove(i int) bool

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) Repeat

func (q *Queue) Repeat() Repeat

func (*Queue) Set

func (q *Queue) Set(tracks []deezer.Track, start int)

Set replaces the queue contents and positions the cursor at start (clamped). History is cleared.

func (*Queue) SetIndex

func (q *Queue) SetIndex(i int)

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.

func (*Queue) SetRepeat

func (q *Queue) SetRepeat(r Repeat)

func (*Queue) SetShuffle

func (q *Queue) SetShuffle(on bool)

func (*Queue) Shuffle

func (q *Queue) Shuffle() bool

Shuffle / Repeat accessors.

func (*Queue) ToggleShuffle

func (q *Queue) ToggleShuffle() bool

func (*Queue) Tracks

func (q *Queue) Tracks() []deezer.Track

Tracks returns the underlying slice (read-only; do not mutate).

func (*Queue) Version

func (q *Queue) Version() uint64

Version returns the mutation counter for the track-list contents. See the field doc: bumped by Set/Append/Remove/Move/InsertAfterCurrent only.

type Repeat

type Repeat int

Repeat is the loop mode.

const (
	RepeatOff Repeat = iota
	RepeatAll
	RepeatOne
)

func (Repeat) String

func (r Repeat) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL