From 067c339fc96840fe6e3e4c7644186c51d668b33b Mon Sep 17 00:00:00 2001 From: Crylia Date: Wed, 27 Mar 2024 02:42:29 +0100 Subject: [PATCH] now I actually implemented the shuffle button --- src/Controller/MusicPlayer/MusicPlayer.cpp | 2 +- src/Controller/MusicPlayer/MusicPlayer.h | 9 ++++++--- .../ConditionalCircularLinkedList.cpp | 2 -- .../ConditionalCircularLinkedList.h | 4 ++-- src/core/SongQueue/SongQueue.cpp | 3 ++- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/Controller/MusicPlayer/MusicPlayer.cpp b/src/Controller/MusicPlayer/MusicPlayer.cpp index 80e0508..ba142bf 100644 --- a/src/Controller/MusicPlayer/MusicPlayer.cpp +++ b/src/Controller/MusicPlayer/MusicPlayer.cpp @@ -70,7 +70,7 @@ void MusicPlayer::MoveSongInQueue(Song* songToMove, Song* otherSong, bool before songQueue->MoveSongInPriorityQueue(songToMove, otherSong, beforeElseAfter); } -void MusicPlayer::shuffleQueue( ) { +void MusicPlayer::shuffleHandler( ) { shuffle ? songQueue->ShufflePlaylist( ) : songQueue->RestorePlaylist( ); } diff --git a/src/Controller/MusicPlayer/MusicPlayer.h b/src/Controller/MusicPlayer/MusicPlayer.h index b784456..1a89c2f 100644 --- a/src/Controller/MusicPlayer/MusicPlayer.h +++ b/src/Controller/MusicPlayer/MusicPlayer.h @@ -19,7 +19,7 @@ class MusicPlayer { } private: - MusicPlayer( ) { } + MusicPlayer( ) : songQueue(new SongQueue( )) { } // 0 no shuffle, 1 shuffling int shuffle = 0; @@ -36,7 +36,7 @@ class MusicPlayer { Audio& audio = Audio::getInstance( ); - void shuffleQueue( ); + void shuffleHandler( ); void setQueueLoop( ); public: @@ -95,7 +95,10 @@ class MusicPlayer { */ Song* GetCurrentlyPlaying( ); - void SetShuffle(bool shuffle) { this->shuffle = shuffle; } + void SetShuffle(bool shuffle) { + this->shuffle = shuffle; + shuffleHandler( ); + } bool GetShuffle( ) { return shuffle; } void SetLoop(Loop loop) { this->loop = loop; } Loop GetLoop( ) { return loop; } diff --git a/src/core/SongQueue/ConditionalCircularLinkedList/ConditionalCircularLinkedList.cpp b/src/core/SongQueue/ConditionalCircularLinkedList/ConditionalCircularLinkedList.cpp index 61ecffb..af468c0 100644 --- a/src/core/SongQueue/ConditionalCircularLinkedList/ConditionalCircularLinkedList.cpp +++ b/src/core/SongQueue/ConditionalCircularLinkedList/ConditionalCircularLinkedList.cpp @@ -1,7 +1,5 @@ #include "ConditionalCircularLinkedList.h" -ConditionalCircularLinkedList::ConditionalCircularLinkedList( ) { } - void ConditionalCircularLinkedList::Append(Song* song) { Node* newNode = new Node(song); if (head == nullptr) { diff --git a/src/core/SongQueue/ConditionalCircularLinkedList/ConditionalCircularLinkedList.h b/src/core/SongQueue/ConditionalCircularLinkedList/ConditionalCircularLinkedList.h index 98ba4d4..0ee8244 100644 --- a/src/core/SongQueue/ConditionalCircularLinkedList/ConditionalCircularLinkedList.h +++ b/src/core/SongQueue/ConditionalCircularLinkedList/ConditionalCircularLinkedList.h @@ -22,8 +22,8 @@ class ConditionalCircularLinkedList { // Variable to either link or unlink the list bool isLinked; public: - ConditionalCircularLinkedList( ); - ConditionalCircularLinkedList(bool isLinked) : head(nullptr), isLinked(isLinked) { } + ConditionalCircularLinkedList( ) : head(nullptr), isLinked(false), current(nullptr) { } + ConditionalCircularLinkedList(bool isLinked) : head(nullptr), isLinked(isLinked), current(nullptr) { } /** * @brief Append a new song to the queue diff --git a/src/core/SongQueue/SongQueue.cpp b/src/core/SongQueue/SongQueue.cpp index 1f0a0e9..6cb6887 100644 --- a/src/core/SongQueue/SongQueue.cpp +++ b/src/core/SongQueue/SongQueue.cpp @@ -1,7 +1,7 @@ #include "SongQueue.h" SongQueue::SongQueue( ) { - queue = new ConditionalCircularLinkedList( ); + queue = new ConditionalCircularLinkedList(false); // Its never going to be linked, I'm just too lazy to make a new implementation thats almost the same priorityQueue = new ConditionalCircularLinkedList(false); @@ -77,6 +77,7 @@ void SongQueue::MoveSongInPriorityQueue(Song* songToMove, Song* otherSong, bool } void SongQueue::ShufflePlaylist( ) { + if (queue && queue->IsEmpty( )) return; //First backup the original list state queue_original = new ConditionalCircularLinkedList(queue);