Documentation
¶
Index ¶
- Constants
- Variables
- type App
- func (a *App) Dispatch(cmd Command) error
- func (a *App) HandlePlayerEvent(event player.Event)
- func (a *App) Restore(tracks []Track, cursor int, mode QueueMode)
- func (a *App) SetVolume(volume int)
- func (a *App) Shutdown()
- func (a *App) ShutdownAndWait()
- func (a *App) State() State
- func (a *App) SubscribeLyricsEvents() (<-chan LyricsEvent, func())
- func (a *App) SubscribeMetadataEvents() (<-chan MetadataEvent, func())
- func (a *App) SubscribePlayerEvents() (<-chan player.Event, func())
- func (a *App) SubscribeStateEvents() (<-chan StateEvent, func())
- type Command
- type CommandType
- type LinearStrategy
- type LyricsEvent
- type MetadataEvent
- type MetadataScope
- type PlaybackState
- type QueueDecision
- type QueueInput
- type QueueMode
- type QueueStrategy
- type RepeatAllStrategy
- type RepeatOneStrategy
- type ShuffleStrategy
- type State
- type StateChange
- type StateEvent
- type StateEventSource
- type StopAfterCurrentStrategy
- type Track
Constants ¶
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 )
const DefaultVolume = 100
DefaultVolume is the initial volume level (0-100).
Variables ¶
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 (*App) HandlePlayerEvent ¶
HandlePlayerEvent updates state in response to a player event.
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) 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 ¶
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 (s LinearStrategy) Next(in QueueInput) QueueDecision
func (LinearStrategy) Prev ¶
func (s LinearStrategy) Prev(in QueueInput) QueueDecision
func (LinearStrategy) Reset ¶
func (s LinearStrategy) Reset()
type LyricsEvent ¶
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 ¶
QueueInput is the immutable input provided to queue strategies.
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 (s RepeatAllStrategy) Next(in QueueInput) QueueDecision
func (RepeatAllStrategy) Prev ¶
func (s RepeatAllStrategy) Prev(in QueueInput) QueueDecision
func (RepeatAllStrategy) Reset ¶
func (s RepeatAllStrategy) Reset()
type RepeatOneStrategy ¶
type RepeatOneStrategy struct{}
RepeatOneStrategy keeps playback on the current track.
func (RepeatOneStrategy) Next ¶
func (s RepeatOneStrategy) Next(in QueueInput) QueueDecision
func (RepeatOneStrategy) Prev ¶
func (s RepeatOneStrategy) Prev(in QueueInput) QueueDecision
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 (s *ShuffleStrategy) Next(in QueueInput) QueueDecision
func (*ShuffleStrategy) Prev ¶
func (s *ShuffleStrategy) Prev(in QueueInput) QueueDecision
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.
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 (s StopAfterCurrentStrategy) Next(in QueueInput) QueueDecision
func (StopAfterCurrentStrategy) Prev ¶
func (s StopAfterCurrentStrategy) Prev(in QueueInput) QueueDecision
func (StopAfterCurrentStrategy) Reset ¶
func (s StopAfterCurrentStrategy) Reset()