checkpoint 3: base shuffle works, but very bad code

This commit is contained in:
Siiiiinth
2026-02-15 09:28:38 -08:00
committed by Drew Weymouth
parent 6a5ec33799
commit f010ef0272
+8 -10
View File
@@ -255,7 +255,7 @@ func (p *playbackEngine) insertItemsIntoPlayQueueAt(items []mediaprovider.MediaI
} }
func (p *playbackEngine) GetPlayQueueDeepCopy() []mediaprovider.MediaItem { func (p *playbackEngine) GetPlayQueueDeepCopy() []mediaprovider.MediaItem {
return deepCopyMediaItemSlice(p.playQueue) // TODO_SHUFFLE: does this also need the shuffled play queue? return deepCopyMediaItemSlice(p.getPlayQueue())
} }
// ======================== END PLAY QUEUE FUNCS ============================= // ======================== END PLAY QUEUE FUNCS =============================
@@ -306,20 +306,20 @@ func (p *playbackEngine) GetLoopMode() LoopMode {
} }
func (p *playbackEngine) SetShuffle(shuffle bool) { func (p *playbackEngine) SetShuffle(shuffle bool) {
//TODO_SHUFFLE: fix very bad code
if p.shuffle == shuffle { if p.shuffle == shuffle {
return return
} }
if shuffle { if shuffle {
fmt.Println("shuffling") fmt.Println("shuffling")
newQueue := deepCopyMediaItemSlice(p.playQueue) shuffledQueue := deepCopyMediaItemSlice(p.playQueue)
rand.Shuffle(len(newQueue), func(i, j int) { rand.Shuffle(len(shuffledQueue), func(i, j int) {
newQueue[i], newQueue[j] = newQueue[j], newQueue[i] shuffledQueue[i], shuffledQueue[j] = shuffledQueue[j], shuffledQueue[i]
}) })
fmt.Println(p.playQueue[0].Metadata().ID)
newNowPlayingIdx := -1 newNowPlayingIdx := -1
if p.nowPlayingIdx >= 0 { if p.nowPlayingIdx >= 0 {
nowPlayingID := p.getPlayQueueItemAt(p.nowPlayingIdx).Metadata().ID nowPlayingID := p.getPlayQueueItemAt(p.nowPlayingIdx).Metadata().ID
for i, tr := range newQueue { for i, tr := range shuffledQueue {
if tr.Metadata().ID == nowPlayingID { if tr.Metadata().ID == nowPlayingID {
newNowPlayingIdx = i newNowPlayingIdx = i
break break
@@ -327,7 +327,7 @@ func (p *playbackEngine) SetShuffle(shuffle bool) {
} }
} }
p.shuffle = shuffle p.shuffle = shuffle
p.setPlayQueue(newQueue) p.shuffledPlayQueue = shuffledQueue
if p.nowPlayingIdx >= 0 && newNowPlayingIdx == -1 { if p.nowPlayingIdx >= 0 && newNowPlayingIdx == -1 {
return return
} }
@@ -339,7 +339,6 @@ func (p *playbackEngine) SetShuffle(shuffle bool) {
p.invokeNoArgCallbacks(p.onQueueChange) p.invokeNoArgCallbacks(p.onQueueChange)
} else { } else {
fmt.Println("deshuffling") fmt.Println("deshuffling")
fmt.Println(p.playQueue[0].Metadata().ID)
newQueue := deepCopyMediaItemSlice(p.playQueue) newQueue := deepCopyMediaItemSlice(p.playQueue)
newNowPlayingIdx := -1 newNowPlayingIdx := -1
if p.nowPlayingIdx >= 0 { if p.nowPlayingIdx >= 0 {
@@ -352,7 +351,7 @@ func (p *playbackEngine) SetShuffle(shuffle bool) {
} }
} }
p.shuffle = shuffle p.shuffle = shuffle
p.setPlayQueue(newQueue) p.playQueue = newQueue
if p.nowPlayingIdx >= 0 && newNowPlayingIdx == -1 { if p.nowPlayingIdx >= 0 && newNowPlayingIdx == -1 {
return return
} }
@@ -363,7 +362,6 @@ func (p *playbackEngine) SetShuffle(shuffle bool) {
p.invokeNoArgCallbacks(p.onQueueChange) p.invokeNoArgCallbacks(p.onQueueChange)
} }
} }
func (p *playbackEngine) GetShuffle() bool { func (p *playbackEngine) GetShuffle() bool {