core

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// VolumeMin is the minimum volume level.
	VolumeMin = 0
	// VolumeMax is the maximum volume level.
	VolumeMax = 100
	// VolumeStep is the delta used when adjusting volume with +/-.
	VolumeStep = 5
)
View Source
const DefaultVolume = 100

DefaultVolume is the initial volume level (0-100).

Variables

View Source
var (
	// ErrAppClosed is returned when dispatching to a closed app.
	ErrAppClosed = errors.New("app is closed")
	// ErrCommandQueueFull is returned when the command queue is full.
	ErrCommandQueueFull = errors.New("command queue full")
)

Functions

This section is empty.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App owns playback and playlist state.

func New

func New(cfg config.Config) *App

New constructs a new App.

func (*App) Dispatch

func (a *App) Dispatch(cmd Command) error

Dispatch queues a command for processing.

func (*App) HandlePlayerEvent

func (a *App) HandlePlayerEvent(event player.Event)

HandlePlayerEvent updates state in response to a player event.

func (*App) Restore

func (a *App) Restore(tracks []Track, cursor int, mode QueueMode)

Restore loads playlist and queue state without starting playback.

func (*App) SetVolume

func (a *App) SetVolume(volume int)

SetVolume sets the current volume (0-100).

func (*App) Shutdown

func (a *App) Shutdown()

Shutdown shuts down the player engine and background workers.

func (*App) ShutdownAndWait

func (a *App) ShutdownAndWait()

ShutdownAndWait shuts down the player engine and waits for background workers to stop.

func (*App) State

func (a *App) State() State

State returns a snapshot of the current state.

func (*App) SubscribeLyricsEvents

func (a *App) SubscribeLyricsEvents() (<-chan LyricsEvent, func())

SubscribeLyricsEvents registers a new lyrics event subscriber. Use the returned unsubscribe func to stop receiving events.

func (*App) SubscribeMetadataEvents

func (a *App) SubscribeMetadataEvents() (<-chan MetadataEvent, func())

SubscribeMetadataEvents registers a new metadata event subscriber. Use the returned unsubscribe func to stop receiving events.

func (*App) SubscribePlayerEvents

func (a *App) SubscribePlayerEvents() (<-chan player.Event, func())

SubscribePlayerEvents registers a new player event subscriber. Use the returned unsubscribe func to stop receiving events.

func (*App) SubscribeStateEvents

func (a *App) SubscribeStateEvents() (<-chan StateEvent, func())

SubscribeStateEvents registers a new state event subscriber. Use the returned unsubscribe func to stop receiving events.

type Command

type Command struct {
	Type    CommandType
	Track   Track
	Tracks  []Track
	Index   int
	Mode    QueueMode
	Count   int
	Offset  time.Duration
	Volume  int
	TrackID uint64
	Path    string
	Scope   MetadataScope
}

Command represents a UI action to apply.

type CommandType

type CommandType int

CommandType identifies a UI command.

const (
	CmdAdd CommandType = iota
	CmdAddAll
	CmdClear
	CmdSelectUp
	CmdSelectDown
	CmdSelectTop
	CmdSelectBottom
	CmdSelectPageUp
	CmdSelectPageDown
	CmdSelectIndex
	CmdPlayFromCursor
	CmdNext
	CmdPrev
	CmdStop
	CmdTogglePause
	CmdRemoveAt
	CmdMoveUp
	CmdMoveDown
	CmdSetQueueMode
	CmdVolumeUp
	CmdVolumeDown
	CmdToggleMute
	CmdSetVolume
	CmdSeekBy
	CmdRequestMetadata
	CmdRequestLyrics
)

type LinearStrategy

type LinearStrategy struct{}

LinearStrategy advances through the playlist in order.

func (LinearStrategy) Next

func (LinearStrategy) Prev

func (LinearStrategy) Reset

func (s LinearStrategy) Reset()

type LyricsEvent

type LyricsEvent struct {
	TrackID uint64
	Path    string
	Lyrics  lyrics.Lyrics
	Err     error
}

LyricsEvent reports lyrics loaded in the background.

type MetadataEvent added in v0.9.2

type MetadataEvent struct {
	TrackID  uint64
	Path     string
	Scope    MetadataScope
	Metadata library.Metadata
	Err      error
}

MetadataEvent reports tags for a track loaded in the background.

type MetadataScope

type MetadataScope int

MetadataScope controls the amount of metadata to load.

const (
	MetadataBasic MetadataScope = iota
	MetadataExtended
)

type PlaybackState

type PlaybackState int

PlaybackState describes the current playback mode.

const (
	PlaybackStopped PlaybackState = iota
	PlaybackPlaying
	PlaybackPaused
)

type QueueDecision

type QueueDecision struct {
	// Index is the track index to play next. If negative, no track should be played.
	Index int
	// Stop indicates playback should clear the current playing index when Index is negative.
	Stop bool
}

QueueDecision describes the outcome of a queue step.

func QueueNoop

func QueueNoop() QueueDecision

QueueNoop returns a decision indicating no next/previous track.

func QueuePlay

func QueuePlay(index int) QueueDecision

QueuePlay returns a decision to play the provided index.

func QueueStop

func QueueStop() QueueDecision

QueueStop returns a decision indicating playback should stop.

type QueueInput

type QueueInput struct {
	PlaylistLen int
	Playing     int
}

QueueInput is the immutable input provided to queue strategies.

type QueueMode

type QueueMode int

QueueMode identifies the playback ordering strategy.

const (
	QueueModeLinear QueueMode = iota
	QueueModeShuffle
	QueueModeRepeatOne
	QueueModeRepeatAll
	QueueModeStopAfterCurrent
)

type QueueStrategy

type QueueStrategy interface {
	// Next returns the next index to play, based on the intention to advance forward.
	Next(in QueueInput) QueueDecision
	// Prev returns the next index to play, based on the intention to advance backward.
	Prev(in QueueInput) QueueDecision
	// Reset resets the strategy's internal state, if any.
	Reset()
}

QueueStrategy selects next/previous indices based on state.

type RepeatAllStrategy

type RepeatAllStrategy struct{}

RepeatAllStrategy loops through the playlist in order.

func (RepeatAllStrategy) Next

func (RepeatAllStrategy) Prev

func (RepeatAllStrategy) Reset

func (s RepeatAllStrategy) Reset()

type RepeatOneStrategy

type RepeatOneStrategy struct{}

RepeatOneStrategy keeps playback on the current track.

func (RepeatOneStrategy) Next

func (RepeatOneStrategy) Prev

func (RepeatOneStrategy) Reset

func (s RepeatOneStrategy) Reset()

type ShuffleStrategy

type ShuffleStrategy struct {
	// contains filtered or unexported fields
}

ShuffleStrategy advances through a shuffled deck of all tracks before reshuffling, so every track is heard exactly once per cycle. History is tracked independently for backward navigation via Prev.

func NewShuffleStrategy

func NewShuffleStrategy() *ShuffleStrategy

NewShuffleStrategy constructs a new ShuffleStrategy.

func (*ShuffleStrategy) Next

func (*ShuffleStrategy) Prev

func (*ShuffleStrategy) Reset

func (s *ShuffleStrategy) Reset()

type State

type State struct {
	Playlist     []Track
	PlaylistErr  error
	Playing      int
	Cursor       int
	QueueMode    QueueMode
	PlayState    PlaybackState
	PlayTrack    string
	PlayStart    time.Time
	PlayDuration time.Duration
	PausedAt     time.Time
	PausedFor    time.Duration
	Volume       int
}

State is the shared application state for the UI.

func (*State) Elapsed

func (s *State) Elapsed() time.Duration

Elapsed returns the playback time elapsed for the current track.

type StateChange

type StateChange uint32

StateChange identifies which parts of the app state changed.

const (
	StateChangeNone     StateChange = 0
	StateChangePlaylist StateChange = 1 << iota
	StateChangeSelection
	StateChangePlaying
	StateChangePlayback
	StateChangeQueue
	StateChangeVolume
	StateChangeMetadata
	StateChangeError
)

func DiffState

func DiffState(prev, next State) StateChange

DiffState compares two state snapshots and returns the changes.

type StateEvent

type StateEvent struct {
	Source  StateEventSource
	Command Command
	Changes StateChange
}

StateEvent signals that the app state was updated after a command or event.

type StateEventSource

type StateEventSource int

StateEventSource indicates the origin of a state change.

const (
	StateEventCommand StateEventSource = iota
	StateEventPlayer
	StateEventMetadata
)

type StopAfterCurrentStrategy

type StopAfterCurrentStrategy struct {
	// contains filtered or unexported fields
}

func (StopAfterCurrentStrategy) Next

func (StopAfterCurrentStrategy) Prev

func (StopAfterCurrentStrategy) Reset

func (s StopAfterCurrentStrategy) Reset()

type Track

type Track struct {
	ID       uint64
	Name     string
	Path     string
	Artist   string
	Title    string
	Album    string
	Duration time.Duration
}

Track represents a playable file.

func (Track) DisplayName

func (t Track) DisplayName() string

DisplayName returns the most user-friendly track name available.

Jump to

Keyboard shortcuts

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