now I actually implemented the shuffle button

This commit is contained in:
Crylia
2024-03-27 02:42:29 +01:00
parent 8070db4d5f
commit 067c339fc9
5 changed files with 11 additions and 9 deletions

View File

@@ -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( );
}

View File

@@ -19,7 +19,7 @@ public:
}
private:
MusicPlayer( ) { }
MusicPlayer( ) : songQueue(new SongQueue( )) { }
// 0 no shuffle, 1 shuffling
int shuffle = 0;
@@ -36,7 +36,7 @@ private:
Audio& audio = Audio::getInstance( );
void shuffleQueue( );
void shuffleHandler( );
void setQueueLoop( );
public:
@@ -95,7 +95,10 @@ public:
*/
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; }

View File

@@ -1,7 +1,5 @@
#include "ConditionalCircularLinkedList.h"
ConditionalCircularLinkedList::ConditionalCircularLinkedList( ) { }
void ConditionalCircularLinkedList::Append(Song* song) {
Node* newNode = new Node(song);
if (head == nullptr) {

View File

@@ -22,8 +22,8 @@ private:
// 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

View File

@@ -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);