From dff7fa145d089a44d664f67e9847dcce69115abd Mon Sep 17 00:00:00 2001 From: Kevin Whitaker Date: Sat, 4 Feb 2017 14:15:18 -0500 Subject: [PATCH] Fix music dir being set in bad place again. Update web calls that backend calls to match const requirements. Have playlist and player part of backend class now for better handling. Set up getting first vote list and sending. --- src/GroovePlayer.cpp | 36 +++++++++++++++++++++--------------- src/GroovePlayer.h | 6 ++++-- src/WebInterface.cpp | 10 ++++++++-- src/WebInterface.h | 5 +++-- 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/GroovePlayer.cpp b/src/GroovePlayer.cpp index 3bdf79b..3454a23 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 603da11..a975c15 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 c3d8a50..31904ce 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 2203e03..e9f514c 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; -- GitLab