fixed various bugs with inserting and adding tracks
This commit is contained in:
+15
-16
@@ -46,19 +46,19 @@ var (
|
||||
)
|
||||
|
||||
type App struct {
|
||||
Config *Config
|
||||
ServerManager *ServerManager
|
||||
LyricsManager *LyricsManager
|
||||
ImageManager *ImageManager
|
||||
AudioCache *AudioCache
|
||||
AutoEQManager *AutoEQManager
|
||||
EQPresetManager *EQPresetManager
|
||||
PlaybackManager *PlaybackManager
|
||||
LocalPlayer *mpv.Player
|
||||
UpdateChecker UpdateChecker
|
||||
MPRISHandler *MPRISHandler
|
||||
WinSMTC *windows.SMTC
|
||||
ipcServer ipc.IPCServer
|
||||
Config *Config
|
||||
ServerManager *ServerManager
|
||||
LyricsManager *LyricsManager
|
||||
ImageManager *ImageManager
|
||||
AudioCache *AudioCache
|
||||
AutoEQManager *AutoEQManager
|
||||
EQPresetManager *EQPresetManager
|
||||
PlaybackManager *PlaybackManager
|
||||
LocalPlayer *mpv.Player
|
||||
UpdateChecker UpdateChecker
|
||||
MPRISHandler *MPRISHandler
|
||||
WinSMTC *windows.SMTC
|
||||
ipcServer ipc.IPCServer
|
||||
|
||||
// UI callbacks to be set in main
|
||||
OnReactivate func()
|
||||
@@ -653,7 +653,7 @@ func (a *App) LoadSavedPlayQueue() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
a.PlaybackManager.LoadTracks(playQueue.Tracks, Replace, Both, false)
|
||||
a.PlaybackManager.LoadTracks(playQueue.Tracks, Replace, false)
|
||||
if playQueue.TrackIndex >= 0 && playQueue.TrackIndex < len(playQueue.Tracks) {
|
||||
// TODO: This isn't ideal but doesn't seem to cause an audible play-for-a-split-second artifact
|
||||
a.PlaybackManager.PlayTrackAt(playQueue.TrackIndex)
|
||||
@@ -673,8 +673,7 @@ func (a *App) LoadSavedPlayQueue() error {
|
||||
|
||||
if slices.Equal(serverStatePlayQueue, clientStatePlayQueue) {
|
||||
fmt.Println("Loading unshuffled items into playQueue")
|
||||
a.PlaybackManager.SetShuffle(true)
|
||||
a.PlaybackManager.LoadTracks(unshuffledPlayQueue.Tracks, Replace, PlayQueue, false)
|
||||
a.PlaybackManager.LoadTracks(unshuffledPlayQueue.Tracks, Replace, false)
|
||||
} else {
|
||||
a.PlaybackManager.SetShuffle(false)
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ type playbackCommand struct {
|
||||
Arg any
|
||||
Arg2 any
|
||||
Arg3 any
|
||||
Arg4 any
|
||||
OnDone func()
|
||||
}
|
||||
|
||||
@@ -149,14 +148,13 @@ func (c *playbackCommandQueue) LoadRadioStation(radio *mediaprovider.RadioStatio
|
||||
c.cmdAvailable.Signal()
|
||||
}
|
||||
|
||||
func (c *playbackCommandQueue) LoadItems(items []mediaprovider.MediaItem, insertQueueMode InsertQueueMode, queueType QueueType, shuffle bool) {
|
||||
func (c *playbackCommandQueue) LoadItems(items []mediaprovider.MediaItem, insertQueueMode InsertQueueMode, shuffle bool) {
|
||||
c.mutex.Lock()
|
||||
c.queue = append(c.queue, playbackCommand{
|
||||
Type: cmdLoadItems,
|
||||
Arg: items,
|
||||
Arg2: insertQueueMode,
|
||||
Arg3: queueType,
|
||||
Arg4: shuffle,
|
||||
Arg3: shuffle,
|
||||
})
|
||||
c.mutex.Unlock()
|
||||
c.cmdAvailable.Signal()
|
||||
|
||||
+29
-14
@@ -7,7 +7,6 @@ import (
|
||||
"log"
|
||||
"math/rand"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -272,7 +271,6 @@ func (p *playbackEngine) insertItemsIntoPlayQueueAt(items []mediaprovider.MediaI
|
||||
p.playQueue = append(p.playQueue[:idx], append(items, p.playQueue[idx:]...)...)
|
||||
p.shuffledPlayQueue = append(p.shuffledPlayQueue[:idx], append(items, p.shuffledPlayQueue[idx:]...)...)
|
||||
case PlayQueue:
|
||||
fmt.Println("Inserting into playQueue at: " + strconv.Itoa(idx))
|
||||
p.playQueue = append(p.playQueue[:idx], append(items, p.playQueue[idx:]...)...)
|
||||
case ShuffledPlayQueue:
|
||||
p.shuffledPlayQueue = append(p.shuffledPlayQueue[:idx], append(items, p.shuffledPlayQueue[idx:]...)...)
|
||||
@@ -475,19 +473,21 @@ func (p *playbackEngine) Continue() error {
|
||||
|
||||
// Load items into the play queue.
|
||||
// If replacing the current queue (!appendToQueue), playback will be stopped.
|
||||
func (p *playbackEngine) LoadItems(items []mediaprovider.MediaItem, insertQueueMode InsertQueueMode, queueType QueueType, shuffle bool) error {
|
||||
func (p *playbackEngine) LoadItems(items []mediaprovider.MediaItem, insertQueueMode InsertQueueMode, shuffle bool) error {
|
||||
newItems := deepCopyMediaItemSlice(items)
|
||||
return p.doLoaditems(newItems, insertQueueMode, queueType, shuffle)
|
||||
return p.doLoaditems(newItems, insertQueueMode, shuffle)
|
||||
}
|
||||
|
||||
// Load tracks into the play queue.
|
||||
// If replacing the current queue (!appendToQueue), playback will be stopped.
|
||||
func (p *playbackEngine) LoadTracks(tracks []*mediaprovider.Track, insertQueueMode InsertQueueMode, queueType QueueType, shuffle bool) error {
|
||||
func (p *playbackEngine) LoadTracks(tracks []*mediaprovider.Track, insertQueueMode InsertQueueMode, shuffle bool) error {
|
||||
newTracks := sharedutil.CopyTrackSliceToMediaItemSlice(tracks)
|
||||
return p.doLoaditems(newTracks, insertQueueMode, queueType, shuffle)
|
||||
return p.doLoaditems(newTracks, insertQueueMode, shuffle)
|
||||
}
|
||||
|
||||
func (p *playbackEngine) doLoaditems(items []mediaprovider.MediaItem, insertQueueMode InsertQueueMode, queueType QueueType, shuffle bool) error {
|
||||
func (p *playbackEngine) doLoaditems(items []mediaprovider.MediaItem, insertQueueMode InsertQueueMode, shuffle bool) error {
|
||||
queueType := PlayQueue
|
||||
|
||||
if insertQueueMode == Replace {
|
||||
p.player.Stop(false)
|
||||
p.nowPlayingIdx = -1
|
||||
@@ -497,16 +497,31 @@ func (p *playbackEngine) doLoaditems(items []mediaprovider.MediaItem, insertQueu
|
||||
defer p.handleNextTrackUpdated()
|
||||
}
|
||||
|
||||
if shuffle || p.shuffle {
|
||||
rand.Shuffle(len(items), func(i, j int) { items[i], items[j] = items[j], items[i] })
|
||||
}
|
||||
|
||||
insertIdx := p.getPlayQueueLength()
|
||||
if insertQueueMode == InsertNext {
|
||||
insertIdx = p.nowPlayingIdx + 1
|
||||
|
||||
if insertQueueMode == Replace {
|
||||
if shuffle || p.shuffle {
|
||||
shuffledItems := deepCopyMediaItemSlice(items)
|
||||
rand.Shuffle(len(shuffledItems), func(i, j int) { shuffledItems[i], shuffledItems[j] = shuffledItems[j], shuffledItems[i] })
|
||||
|
||||
p.insertItemsIntoPlayQueueAt(items, insertIdx, PlayQueue)
|
||||
p.insertItemsIntoPlayQueueAt(shuffledItems, insertIdx, ShuffledPlayQueue)
|
||||
} else {
|
||||
p.insertItemsIntoPlayQueueAt(items, insertIdx, queueType)
|
||||
}
|
||||
} else {
|
||||
if shuffle {
|
||||
rand.Shuffle(len(items), func(i, j int) { items[i], items[j] = items[j], items[i] })
|
||||
}
|
||||
if insertQueueMode == InsertNext {
|
||||
insertIdx = p.nowPlayingIdx + 1
|
||||
}
|
||||
if p.shuffle {
|
||||
queueType = Both
|
||||
}
|
||||
p.insertItemsIntoPlayQueueAt(items, insertIdx, queueType)
|
||||
}
|
||||
|
||||
p.insertItemsIntoPlayQueueAt(items, insertIdx, queueType)
|
||||
p.invokeNoArgCallbacks(p.onQueueChange)
|
||||
return nil
|
||||
}
|
||||
|
||||
+12
-13
@@ -369,7 +369,7 @@ func (p *PlaybackManager) LoadAlbum(albumID string, insertQueueMode InsertQueueM
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.LoadTracks(album.Tracks, insertQueueMode, Both, shuffle)
|
||||
p.LoadTracks(album.Tracks, insertQueueMode, shuffle)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -383,21 +383,21 @@ func (p *PlaybackManager) LoadPlaylist(playlistID string, insertQueueMode Insert
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.LoadTracks(playlist.Tracks, insertQueueMode, Both, shuffle)
|
||||
p.LoadTracks(playlist.Tracks, insertQueueMode, shuffle)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Load tracks into the play queue.
|
||||
// If replacing the current queue (!appendToQueue), playback will be stopped.
|
||||
func (p *PlaybackManager) LoadTracks(tracks []*mediaprovider.Track, insertQueueMode InsertQueueMode, queueType QueueType, shuffle bool) {
|
||||
func (p *PlaybackManager) LoadTracks(tracks []*mediaprovider.Track, insertQueueMode InsertQueueMode, shuffle bool) {
|
||||
items := sharedutil.CopyTrackSliceToMediaItemSlice(tracks)
|
||||
p.cmdQueue.LoadItems(items, insertQueueMode, queueType, shuffle)
|
||||
p.cmdQueue.LoadItems(items, insertQueueMode, shuffle)
|
||||
}
|
||||
|
||||
// Load items into the currently active queue. (shuffledPlayQueue/playQueue)
|
||||
// If replacing the current queue (!appendToQueue), playback will be stopped.
|
||||
func (p *PlaybackManager) LoadItems(items []mediaprovider.MediaItem, insertQueueMode InsertQueueMode, queueType QueueType, shuffle bool) {
|
||||
p.cmdQueue.LoadItems(items, insertQueueMode, queueType, shuffle)
|
||||
func (p *PlaybackManager) LoadItems(items []mediaprovider.MediaItem, insertQueueMode InsertQueueMode, shuffle bool) {
|
||||
p.cmdQueue.LoadItems(items, insertQueueMode, shuffle)
|
||||
}
|
||||
|
||||
// Replaces the play queue with the given set of tracks.
|
||||
@@ -434,7 +434,7 @@ func (p *PlaybackManager) PlayTrack(trackID string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.LoadTracks([]*mediaprovider.Track{tr}, Replace, Both, false)
|
||||
p.LoadTracks([]*mediaprovider.Track{tr}, Replace, false)
|
||||
if p.engine.replayGainCfg.Mode == ReplayGainAuto {
|
||||
p.SetReplayGainMode(player.ReplayGainTrack)
|
||||
}
|
||||
@@ -472,7 +472,7 @@ func (p *PlaybackManager) PlayArtistDiscography(artistID string, shuffleTracks b
|
||||
log.Printf("failed to get artist tracks: %v\n", err)
|
||||
return
|
||||
}
|
||||
p.LoadTracks(tr, Replace, Both, shuffleTracks)
|
||||
p.LoadTracks(tr, Replace, shuffleTracks)
|
||||
if p.engine.replayGainCfg.Mode == ReplayGainAuto {
|
||||
if shuffleTracks {
|
||||
p.SetReplayGainMode(player.ReplayGainTrack)
|
||||
@@ -537,7 +537,7 @@ func (p *PlaybackManager) PlayRandomAlbums(genreName string) error {
|
||||
break
|
||||
}
|
||||
if al, err := mp.GetAlbum(al.ID); err == nil {
|
||||
p.LoadTracks(al.Tracks, insertMode, Both, false)
|
||||
p.LoadTracks(al.Tracks, insertMode, false)
|
||||
if i == 0 {
|
||||
p.PlayFromBeginning()
|
||||
insertMode = Append
|
||||
@@ -561,7 +561,7 @@ func (p *PlaybackManager) fetchAndPlayTracks(fetchFn func() ([]*mediaprovider.Tr
|
||||
if songs, err := fetchFn(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
p.LoadTracks(songs, Replace, Both, false)
|
||||
p.LoadTracks(songs, Replace, false)
|
||||
if p.engine.replayGainCfg.Mode == ReplayGainAuto {
|
||||
p.SetReplayGainMode(player.ReplayGainTrack)
|
||||
}
|
||||
@@ -811,7 +811,7 @@ func (p *PlaybackManager) enqueueAutoplayTracks() {
|
||||
}
|
||||
|
||||
if len(tracks) > 0 {
|
||||
p.LoadTracks(tracks, Append, Both, false /*no need to shuffle, already random*/)
|
||||
p.LoadTracks(tracks, Append, false /*no need to shuffle, already random*/)
|
||||
}
|
||||
}()
|
||||
}
|
||||
@@ -855,8 +855,7 @@ func (p *PlaybackManager) runCmdQueue(ctx context.Context) {
|
||||
err := p.engine.LoadItems(
|
||||
c.Arg.([]mediaprovider.MediaItem),
|
||||
c.Arg2.(InsertQueueMode),
|
||||
c.Arg3.(QueueType),
|
||||
c.Arg4.(bool),
|
||||
c.Arg3.(bool),
|
||||
)
|
||||
logIfErr("LoadItems", err)
|
||||
case cmdLoadRadioStation:
|
||||
|
||||
Reference in New Issue
Block a user