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.

This commit is contained in:
Kevin Whitaker
2017-02-04 14:15:18 -05:00
parent 9b2783238e
commit dff7fa145d
4 changed files with 36 additions and 21 deletions

View File

@@ -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>("user");
sqlSession.mapClass<AudioTrack>("tracks");
@@ -154,13 +155,26 @@ void GroovePlayerMgr::grooveEventLoop()
selectedTrack = getInstance()->sqlSession.find<AudioTrack>().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<WebInterface*>(app)->songChangedFromServer(getInstance()->getCurrentTrack().get());
static_cast<WebInterface*>(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<AudioTrack> GroovePlayerMgr::getCurrentTrack()
{
Wt::Dbo::Transaction transaction(getInstance()->sqlSession);
Wt::Dbo::ptr<AudioTrack> track = getInstance()->sqlSession.find<AudioTrack>().where("path = ?").bind(currentItem->file->filename);
Wt::Dbo::Transaction transaction(this->sqlSession);
GroovePlaylistItem* currentItem;
double timeInto;
groove_player_position(this->currentPlayer,&currentItem,&timeInto);
Wt::Dbo::ptr<AudioTrack> track = this->sqlSession.find<AudioTrack>().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<WebInterface*>(app)->updateUIFromServer();
// }
// }
// );

View File

@@ -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<const AudioTrack*> 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<const AudioTrack*> requestQueue;
std::list<PlayerEvents> lastInternalEvents;
GroovePlaylistItem* currentItem;
std::thread* grooveEvents;

View File

@@ -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<const AudioTrack *> voteableTracks)
{
priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"votechanged");
triggerUpdate();
}

View File

@@ -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<const AudioTrack*> 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;