diff --git a/src/GroovePlayer.cpp b/src/GroovePlayer.cpp index 3bdf79bd2bf462b705d2fa1c437c8259bbdd3ee9..3454a2301e274291030b55e8ca22f5d1ea82c997 100644 --- a/src/GroovePlayer.cpp +++ b/src/GroovePlayer.cpp @@ -33,6 +33,7 @@ std::filesystem::path GroovePlayerMgr::musicScanDir = ""; GroovePlayerMgr::GroovePlayerMgr (std::string dbFile) : sqliteConnection(dbFile) { + musicScanDir = std::filesystem::current_path()/"music"; sqlSession.setConnection(this->sqliteConnection); sqlSession.mapClass("user"); sqlSession.mapClass("tracks"); @@ -154,13 +155,26 @@ void GroovePlayerMgr::grooveEventLoop() selectedTrack = getInstance()->sqlSession.find().limit(1).offset(rand() % trackCount).resultValue().get(); } struct GroovePlaylist* playlist = groove_playlist_create(); + getInstance()->currentPlaylist = playlist; struct GroovePlayer* player = groove_player_create(); if(!player) {return;} + getInstance()->currentPlayer = player; groove_playlist_insert(playlist, groove_file_open(selectedTrack->trackPath.c_str()),1.0,1.0,nullptr); //Now start loop groove_player_attach(player, playlist); + getInstance()->currentVoteBatch = getInstance()->getNextVoteBatch(); + groove_playlist_play(playlist); + Wt::WServer::instance()->postAll([]() { + Wt::WApplication* app = Wt::WApplication::instance(); + if(app != nullptr) + { + static_cast(app)->songChangedFromServer(getInstance()->getCurrentTrack().get()); + static_cast(app)->voteTracksUpdatedFromServer(getInstance()->currentVoteBatch); + } + } + ); while(getInstance()->continueEventLoop) { @@ -172,6 +186,8 @@ void GroovePlayerMgr::grooveEventLoop() //TODO } + getInstance()->currentPlaylist = nullptr; + getInstance()->currentPlayer = nullptr; groove_player_detach(player); groove_player_destroy(player); groove_playlist_destroy(playlist); @@ -190,8 +206,11 @@ GroovePlayerMgr::PlayerEvents GroovePlayerMgr::getNextPlayerEvent() Wt::Dbo::ptr GroovePlayerMgr::getCurrentTrack() { - Wt::Dbo::Transaction transaction(getInstance()->sqlSession); - Wt::Dbo::ptr track = getInstance()->sqlSession.find().where("path = ?").bind(currentItem->file->filename); + Wt::Dbo::Transaction transaction(this->sqlSession); + GroovePlaylistItem* currentItem; + double timeInto; + groove_player_position(this->currentPlayer,¤tItem,&timeInto); + Wt::Dbo::ptr track = this->sqlSession.find().where("path = ?").bind(currentItem->file->filename); return track; } @@ -301,16 +320,3 @@ void GroovePlayerMgr::grooveAudioScannerLoop() removeOrphanedTracks(); } - - - - //TODO:use this code when sending to UI. -// Wt::WServer::instance()->postAll([]() { -// Wt::WApplication* app = Wt::WApplication::instance(); -// if(app != nullptr) -// { -// static_cast(app)->updateUIFromServer(); -// } -// } -// ); - diff --git a/src/GroovePlayer.h b/src/GroovePlayer.h index 603da112e49e753da70b80eabf9934c7218705c7..a975c150758b8647811fb4e625da725d01067ae5 100644 --- a/src/GroovePlayer.h +++ b/src/GroovePlayer.h @@ -37,13 +37,16 @@ class GroovePlayerMgr public: static std::filesystem::path musicScanDir; static GroovePlayerMgr* getInstance() { - musicScanDir = std::filesystem::current_path()/"music"; static GroovePlayerMgr instance("music.db"); return &instance; }; GroovePlayerMgr ( GroovePlayerMgr const&) = delete; void operator=( GroovePlayerMgr const&) = delete; void shutdown(); + + struct GroovePlaylist* currentPlaylist; + struct GroovePlayer* currentPlayer; + std::list currentVoteBatch; private: enum PlayerEvents {NOTHING, GROOVE_NOWPLAYING, VOTING_ENDED, VOTE_CAST, PLAYING_PAUSED, PLAYING_RESUMED, SKIP_REQUESTED, SKIP_VOTE_CAST, SKIP_VOTING_ENDED, ADMIN_FORCE_SKIP}; @@ -54,7 +57,6 @@ private: std::list requestQueue; std::list lastInternalEvents; - GroovePlaylistItem* currentItem; std::thread* grooveEvents; diff --git a/src/WebInterface.cpp b/src/WebInterface.cpp index c3d8a50228ab4e0be3f1848e8d6bb6518477c1aa..31904ce0d198f5472bd1bf0c6b5fe9019dbfef54 100644 --- a/src/WebInterface.cpp +++ b/src/WebInterface.cpp @@ -63,7 +63,7 @@ void WebInterface::playPauseActionFromServer(User* userPausing) triggerUpdate(); } -void WebInterface::songChangedFromServer(AudioTrack* nextTrack) +void WebInterface::songChangedFromServer(const AudioTrack* nextTrack) { priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"change"); triggerUpdate(); @@ -81,7 +81,7 @@ void WebInterface::voteUpdateFromServer(User* userVoting, bool forSkip) triggerUpdate(); } -void WebInterface::voteNextSongFromServer(User* userVoting, AudioTrack* trackVoted) +void WebInterface::voteNextSongFromServer(User* userVoting, const AudioTrack* trackVoted) { priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"nextvote"); triggerUpdate(); @@ -92,3 +92,9 @@ void WebInterface::voteNextPollClosedFromServer() priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"voteclosed"); triggerUpdate(); } + +void WebInterface::voteTracksUpdatedFromServer(std::list voteableTracks) +{ + priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"votechanged"); + triggerUpdate(); +} diff --git a/src/WebInterface.h b/src/WebInterface.h index 2203e0303f5e5ffb8ebedd36782962e195f7d517..e9f514c47669d15405e92ce66dec01971906583d 100644 --- a/src/WebInterface.h +++ b/src/WebInterface.h @@ -32,10 +32,11 @@ public: ~WebInterface(); void loginCompleted(); void playPauseActionFromServer(User* userPausing); - void songChangedFromServer(AudioTrack* nextTrack); + void songChangedFromServer(const AudioTrack* nextTrack); + void voteTracksUpdatedFromServer(std::list voteableTracks); void skipVotedFromServer(User* userRequestingToSkipCurrentTrack); void voteUpdateFromServer(User* userVoting, bool forSkip); - void voteNextSongFromServer(User* userVoting, AudioTrack* trackVoted); + void voteNextSongFromServer(User* userVoting, const AudioTrack* trackVoted); void voteNextPollClosedFromServer(); private: struct internal;