Skip to content

Commit

Permalink
now I actually implemented the shuffle button
Browse files Browse the repository at this point in the history
  • Loading branch information
Crylia committed Mar 27, 2024
1 parent 8070db4 commit 067c339
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Controller/MusicPlayer/MusicPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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( );
}

Expand Down
9 changes: 6 additions & 3 deletions src/Controller/MusicPlayer/MusicPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MusicPlayer {
}

private:
MusicPlayer( ) { }
MusicPlayer( ) : songQueue(new SongQueue( )) { }

// 0 no shuffle, 1 shuffling
int shuffle = 0;
Expand All @@ -36,7 +36,7 @@ class MusicPlayer {

Audio& audio = Audio::getInstance( );

void shuffleQueue( );
void shuffleHandler( );
void setQueueLoop( );

public:
Expand Down Expand Up @@ -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; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "ConditionalCircularLinkedList.h"

ConditionalCircularLinkedList::ConditionalCircularLinkedList( ) { }

void ConditionalCircularLinkedList::Append(Song* song) {
Node* newNode = new Node(song);
if (head == nullptr) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/core/SongQueue/SongQueue.cpp
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 067c339

Please sign in to comment.