state

package
v0.0.0-...-e62810a Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2022 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Playlist

type Playlist struct {
	Name   PlaylistName
	Path   string
	Tracks []*Track
	// contains filtered or unexported fields
}

func (*Playlist) Add

func (pl *Playlist) Add(ix int, before bool, paths ...string) (start, end int)

Add adds the given path to a track to the current playlist. It marks the playlist as unsaved. If before is false, then the track is appended after the index. If before is true, then the track is appended before the index. The returned integers are the positions of the inserted tracks. If len(paths) is 0, then ix is returned for both.

func (*Playlist) IsUnsaved

func (pl *Playlist) IsUnsaved() bool

IsUnsaved returns true if the playlist is unsaved. It is thread-safe.

func (*Playlist) Remove

func (pl *Playlist) Remove(ixs ...int)

Remove removes the tracks with the given indices. The function guarantees that the delete will never touch tracks that didn't have the given indices before removal; it does this by sorting the internal array of ixs.

func (*Playlist) Save

func (pl *Playlist) Save(done func(error))

Save saves the playlist. The function must not be called in another goroutine. The done callback may be called in a goroutine.

TODO: refactor this to Save() and WaitUntilSaved().

func (*Playlist) SetUnsaved

func (pl *Playlist) SetUnsaved()

SetUnsaved marks the playlist as unsaved.

type PlaylistName

type PlaylistName = string

type RepeatMode

type RepeatMode uint8
const (
	RepeatNone RepeatMode = iota
	RepeatAll
	RepeatSingle
)

func (RepeatMode) Cycle

func (m RepeatMode) Cycle() RepeatMode

Cycle returns the next mode to be activated when the repeat button is constantly pressed.

type State

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

func NewState

func NewState() *State

NewState creates an empty state.

func ReadFromFile

func ReadFromFile() (*State, error)

ReadFromFile reads the state from the user's state.

func (*State) AddPlaylist

func (s *State) AddPlaylist(p *playlist.Playlist) *Playlist

AddPlaylist adds a playlist. If a playlist with the same name is added, then the function does nothing.

func (*State) AutoNext

func (s *State) AutoNext() (int, *Track)

AutoNext returns the next track, unless we're in RepeatSingle mode, then it returns the same track. Use this to cycle across the playlist.

func (*State) DeletePlaylist

func (s *State) DeletePlaylist(name string)

DeletePlaylist deletes the playlist with the given name.

func (*State) IsMuted

func (s *State) IsMuted() bool

IsMuted returns the current muted state.

func (*State) IsShuffling

func (s *State) IsShuffling() bool

IsShuffling returns true if the list is being shuffled.

func (*State) MarkChanged

func (s *State) MarkChanged()

MarkChanged marks the state as changed (unsaved).

func (*State) MarshalJSON

func (s *State) MarshalJSON() ([]byte, error)

MarshalJSON marshals State to JSON.

func (*State) Next

func (s *State) Next() (int, *Track)

Next returns the next track from the currently playing playlist. Nil is returned if there is no next track.

func (*State) NowPlaying

func (s *State) NowPlaying() (int, *Track)

NowPlaying returns the currently playing track. If playingPl is nil, then this method returns (-1, nil).

func (*State) OnUpdate

func (s *State) OnUpdate(fn func(*State))

OnTrackUpdate adds into the call stack a callback that is triggered when the state is changed.

func (*State) Peek

func (s *State) Peek() (int, *Track)

Peek returns the next track without changing the state. It basically emulates AutoNext.

func (*State) Play

func (s *State) Play(index int) *Track

Play plays the track indexed relative to the actual playlist. This does not index relative to the actual play queue, which may be shuffled. It also does not update QueuePos if we're shuffling.

func (*State) PlayingPlaylist

func (s *State) PlayingPlaylist() *Playlist

PlayingPlaylist returns the playing playlist, or nil if none. It panics if the internal states are inconsistent, which should never happen unless the playlist pointer was illegally changed. If the path were to be changed, then SetCurrentPlaylist should be called again.

func (*State) PlayingPlaylistName

func (s *State) PlayingPlaylistName() string

PlayingPlaylistName returns the playing playlist name, or an empty string if none.

func (*State) Playlist

func (s *State) Playlist(name string) (*Playlist, bool)

Playlist returns a playlist, or nil if none. It also returns a boolean to indicate.

func (*State) PlaylistFromPath

func (s *State) PlaylistFromPath(path string) (*Playlist, bool)

PlaylistFromPath returns a playlist, or nil if none.

func (*State) PlaylistNames

func (s *State) PlaylistNames() []PlaylistName

func (*State) Previous

func (s *State) Previous() (int, *Track)

Previous returns the previous track, similarly to Next. Nil is returned if there is no previous track. If shuffling mode is on, then Prev will not return the previous track.

func (*State) RefreshQueue

func (s *State) RefreshQueue()

RefreshQueue refreshes completely the current play queue.

func (*State) ReloadPlayQueue

func (s *State) ReloadPlayQueue()

ReloadPlayQueue reloads the internal play queue for the currently playing playlist. Call this when the playlist's track slice is changed.

func (*State) RenamePlaylist

func (s *State) RenamePlaylist(p *Playlist, oldName string)

func (*State) RepeatMode

func (s *State) RepeatMode() RepeatMode

RepeatMode returns the current repeat mode.

func (*State) SaveAll

func (s *State) SaveAll()

SaveAll saves the state and all its playlists. It's asynchronous.

func (*State) SaveState

func (s *State) SaveState()

SaveState saves the state. It is non-blocking, but the JSON is marshaled in the same thread as the caller.

func (*State) SetMute

func (s *State) SetMute(muted bool)

SetMute sets the mute state.

func (*State) SetPlayingPlaylist

func (s *State) SetPlayingPlaylist(pl *Playlist)

SetPlayingPlaylist sets the playing playlist.

func (*State) SetRepeatMode

func (s *State) SetRepeatMode(mode RepeatMode)

SetRepeatMode sets the current repeat mode.

func (*State) SetShuffling

func (s *State) SetShuffling(shuffling bool)

SetShuffling sets the shuffling mode.

func (*State) SetVolume

func (s *State) SetVolume(vol float64)

SetVolume sets the volume.

func (*State) UnmarshalJSON

func (s *State) UnmarshalJSON(b []byte) error

func (*State) Volume

func (s *State) Volume() float64

Volume returns the current volume.

func (*State) WaitUntilSaved

func (s *State) WaitUntilSaved()

WaitUntilSaved waits until all the saving routines are done. This is useful for implementing a loading bar.

type Track

type Track struct {
	Filepath string
	// contains filtered or unexported fields
}

Track is a track value that keeps track of a Metadata pointer and a filepath.

func (*Track) Metadata

func (t *Track) Metadata() (track playlist.Track)

Metadata returns a copy of the current track's metadata with the filepath filled in. If the metadata is not found, then a placeholder one is returned.

func (*Track) UpdateMetadata

func (t *Track) UpdateMetadata(i playlist.Track)

UpdateMetadata updates the track's metadata in the global metadata store. If the metadata does not yet exist, it will create a new one and automatically reference it. Else, no references are taken.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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