Skip to content

Commit

Permalink
Part of a larger restructure, added MusicPlayer which is the main con…
Browse files Browse the repository at this point in the history
…troller and a structure for the song queue
  • Loading branch information
Crylia committed Mar 26, 2024
1 parent a2872f6 commit 9023766
Show file tree
Hide file tree
Showing 67 changed files with 1,218 additions and 262 deletions.
8 changes: 4 additions & 4 deletions build/CMakeLists.txt → CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET
)
PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)

file(GLOB_RECURSE PROJECT_SOURCES ../src/*.cpp)
file(GLOB_RECURSE PROJECT_HEADERS ../src/*.h)
file(GLOB_RECURSE PROJECT_RESOURCES ../assets/resources.qrc)
file(GLOB_RECURSE PROJECT_SOURCES src/*.cpp)
file(GLOB_RECURSE PROJECT_HEADERS src/*.h)
file(GLOB_RECURSE PROJECT_RESOURCES assets/resources.qrc)

add_executable(CryliaPlayer
${PROJECT_SOURCES}
Expand Down Expand Up @@ -61,4 +61,4 @@ set(DESKTOP_FILE ${CMAKE_CURRENT_BINARY_DIR}/CryliaPlayer.desktop)
configure_file(${DESKTOP_FILE_IN} ${DESKTOP_FILE} @ONLY)

install(FILES ${DESKTOP_FILE} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
install(FILES ../assets/aqua.jpg DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons)
install(FILES assets/aqua.jpg DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons)
File renamed without changes.
File renamed without changes
1 change: 1 addition & 0 deletions assets/icons/folder-outline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/home-outline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
1 change: 1 addition & 0 deletions assets/icons/playlist-edit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/playlist-music-outline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icons/playlist-plus.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
16 changes: 1 addition & 15 deletions assets/resources.qrc
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
<RCC>
<qresource prefix="/">
<file>aqua.jpg</file>
<file>icons/songControl/shuffle.svg</file>
<file>icons/songControl/prevSong.svg</file>
<file>icons/songControl/nextSong.svg</file>
<file>icons/songControl/play.svg</file>
<file>icons/songControl/pause.svg</file>
<file>icons/songControl/songRepeat.svg</file>
<file>icons/songControl/repeat-once.svg</file>
<file>icons/songControl/volume-high.svg</file>
<file>icons/songControl/volume-low.svg</file>
<file>icons/songControl/volume-mute.svg</file>
<file>icons/songControl/volume-off.svg</file>
<file>icons/songControl/volume-medium.svg</file>
<file>icons/songControl/arrow-expand.svg</file>
<file>icons/home.svg</file>
<file>icons/songControl/magnify.svg</file>
<file>icons/</file>
</qresource>
</RCC>
79 changes: 79 additions & 0 deletions src/Controller/MusicPlayer/MusicPlayer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include "MusicPlayer.h"

MusicPlayer::~MusicPlayer( ) { }

void MusicPlayer::PlaySong(Song* song) {
songHistory->push(songQueue->Top( ));
songQueue->SetTop(song);

audio.PlaySong(songQueue->Top( )->GetPath( ));
}

void MusicPlayer::NextSong( ) {
if (songQueue->IsEmpty( )) {
audio.StopMusic( );
return;
}

songHistory->push(songQueue->Top( ));
songQueue->Next( );

audio.PlaySong(songQueue->Top( )->GetPath( ));
}

void MusicPlayer::NextSong(Song* song, bool isPrioQueue) {
if (songQueue->IsEmpty( )) {
audio.StopMusic( );
return;
}

songHistory->push(songQueue->Top( ));
songQueue->JumpToSong(song, isPrioQueue);

audio.PlaySong(songQueue->Top( )->GetPath( ));
}

void MusicPlayer::PreviousSong( ) {
if (songHistory->isEmpty( ))
return;

songQueue->SetTop(songHistory->top( ));
songHistory->pop( );

audio.PlaySong(songQueue->Top( )->GetPath( ));
}

void MusicPlayer::SkipToTimestamp(unsigned const int& skipTo) {
if (audio.IsMusicPlaying( ) == 0) return;

audio.SetMusicPos(skipTo);
}

int MusicPlayer::GetSongProgression( ) {
return audio.IsMusicPlaying( ) == 1 ? audio.GetMusicPos( ) : 0;
}

Song* MusicPlayer::GetCurrentlyPlaying( ) {
return songQueue->Top( );
}

//For the PriorityQueue
void MusicPlayer::AddSongToQueue(Song* song) {
songQueue->AddToPriorityQueue(song);
}

void MusicPlayer::RemoveSongFromQueue(Song* song) {
songQueue->RemoveSongFromPriorityQueue(song);
}

void MusicPlayer::MoveSongInQueue(Song* songToMove, Song* otherSong, bool beforeElseAfter) {
songQueue->MoveSongInPriorityQueue(songToMove, otherSong, beforeElseAfter);
}

void MusicPlayer::shuffleQueue( ) {
shuffle ? songQueue->ShufflePlaylist( ) : songQueue->RestorePlaylist( );
}

void MusicPlayer::setQueueLoop( ) {
loop == All ? songQueue->LinkQueue(true) : songQueue->LinkQueue(false);
}
104 changes: 104 additions & 0 deletions src/Controller/MusicPlayer/MusicPlayer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#pragma once

#include "../../core/audio/audio.h"
#include "../../core/SongHistory/SongHistory.hpp"
#include "../../core/SongQueue/SongQueue.h"
#include "../../core/song/song.h"

enum Loop {
None,
Once,
All
};

class MusicPlayer {
public:
static MusicPlayer& getInstance( ) {
static MusicPlayer instance;
return instance;
}

private:
MusicPlayer( );

// 0 no shuffle, 1 shuffling
int shuffle = 0;
// None, Once, All
Loop loop = None;
// 0 stopped, 1 playing
bool playing = 0;

// Song queue, will be filled with the entire playlist by default
SongQueue* songQueue;

// Contain all played songs
SongHistory<Song*>* songHistory;

Audio& audio = Audio::getInstance( );

void shuffleQueue( );
void setQueueLoop( );

public:
~MusicPlayer( );

MusicPlayer(MusicPlayer const&) = delete;
void operator=(MusicPlayer const&) = delete;

/**
* @brief Will start playing the given song and put itself at the queue top.
*
* @param song Song that will start playing
*/
void PlaySong(Song* song);

/**
* @brief Skip the current song and play the next in queue,
* if nothing is in queue it will stop playing anything.
*
*/
void NextSong( );

/**
* @brief Jumps the queue to the given song keeping the non altered queue intact
*
* @param song
* @param isPrioQueue If the song is in the prio queue or normal queue
*/
void NextSong(Song* song, bool isPrioQueue);

/**
* @brief Rewind the currently playing song to the beginning if playtime >= 5 seconds.
* Otherwise play the top song in the history stack
*
*/
void PreviousSong( );

/**
* @brief Skip the song to the given timestamp
*
* @param skipTo time as positive integer
*/
void SkipToTimestamp(unsigned const int& skipTo);

/**
* @brief Get the current Song progression as an positive integer
*
* @return int current timestamp
*/
int GetSongProgression( );

/**
* @brief Get the Currently Playing Song
*
* @return Song& Song thats currently playing
*/
Song* GetCurrentlyPlaying( );

void SetShuffle(bool shuffle) { this->shuffle = shuffle; }
void SetLoop(Loop loop) { this->loop = loop; }

void AddSongToQueue(Song* song);
void RemoveSongFromQueue(Song* song);
void MoveSongInQueue(Song* songToMove, Song* otherSong, bool beforeElseAfter);
};
Empty file.
46 changes: 0 additions & 46 deletions src/Public/MainWindow.cpp

This file was deleted.

27 changes: 0 additions & 27 deletions src/Public/Modules/PageNavigator/pages.cpp

This file was deleted.

17 changes: 0 additions & 17 deletions src/Public/Modules/PageNavigator/pages.h

This file was deleted.

18 changes: 0 additions & 18 deletions src/Public/Pages/Playlist/PlaylistPage.cpp

This file was deleted.

16 changes: 0 additions & 16 deletions src/Public/Tools/SvgToPixmap.hpp

This file was deleted.

Loading

0 comments on commit 9023766

Please sign in to comment.