Add code to try and make sure second votable track is different from first. Implement code to handle skip requests in player.

This commit is contained in:
Kevin Whitaker
2017-02-13 21:47:52 -05:00
parent 41fa567f82
commit 7668a923d8
2 changed files with 64 additions and 17 deletions

View File

@@ -128,10 +128,10 @@ std::list<AudioTrack> GroovePlayerMgr::getNextVoteBatch(Wt::Dbo::Session* sessio
{
//Pick item from genre
Wt::Dbo::ptr<AudioTrack> eligibleTrack = session->find<AudioTrack>().where("genre = ?").limit(1).offset(rand() % trackGenreCount).bind(currentTrack.trackGenre);
//Try to make sure same track isn't up to vote again
if((*eligibleTrack).trackFingerprint == currentTrack.trackFingerprint && trackGenreCount > 1)
//Try to make sure same track isn't up to vote again and isn't the same as first votable track.
if(((*eligibleTrack).trackFingerprint == currentTrack.trackFingerprint || (*eligibleTrack).trackFingerprint == selectedTracks.front().trackFingerprint) && trackGenreCount > 2)
{
while((*eligibleTrack).trackFingerprint == currentTrack.trackFingerprint)
while((*eligibleTrack).trackFingerprint == currentTrack.trackFingerprint || (*eligibleTrack).trackFingerprint == selectedTracks.front().trackFingerprint)
{
eligibleTrack = session->find<AudioTrack>().where("genre = ?").limit(1).offset(rand() % trackGenreCount).bind(currentTrack.trackGenre);
}
@@ -241,6 +241,7 @@ void GroovePlayerMgr::grooveEventLoop()
}
else if(event.eventType == GROOVE_NOWPLAYING)
{
currentSkipRequester.clear();
currentTrack = getCurrentTrackDB(&sqlSession);
//Pick new batch of tracks to vote on and inform UI of update.
currentVoteBatch = getNextVoteBatch(&sqlSession);
@@ -403,8 +404,8 @@ void GroovePlayerMgr::grooveEventLoop()
//Update vote display on all clients.
Wt::WServer::instance()->postAll([event]() {
Wt::WApplication* app = Wt::WApplication::instance();
if(app != nullptr)
Wt::WApplication* app = Wt::WApplication::instance();
if(app != nullptr)
{
static_cast<WebInterface*>(app)->playPauseActionFromServer(event.userInvolved, true);
}
@@ -427,8 +428,8 @@ void GroovePlayerMgr::grooveEventLoop()
//Update vote display on all clients.
Wt::WServer::instance()->postAll([event]() {
Wt::WApplication* app = Wt::WApplication::instance();
if(app != nullptr)
Wt::WApplication* app = Wt::WApplication::instance();
if(app != nullptr)
{
static_cast<WebInterface*>(app)->playPauseActionFromServer(event.userInvolved, false);
}
@@ -437,23 +438,55 @@ void GroovePlayerMgr::grooveEventLoop()
}
else if(event.eventType == SKIP_REQUESTED)
{
//TODO
if(!voteEndedButNotNextTrackYet)
{
currentSkipRequester.push_back(event.userInvolved);
skipRequestedAt = std::chrono::steady_clock::now();
Wt::Dbo::Transaction skipTransaction(sqlSession);
UserAction* action = new UserAction();
action->action = UserAction::UAction::RequestSkip;
action->user = Wt::Dbo::ptr<User>(&event.userInvolved);
action->trackInvolved = Wt::Dbo::ptr<AudioTrack>(&event.tracksInvolved.front());
action->datetime = Wt::WDateTime::currentDateTime();
sqlSession.add(action);
skipTransaction.commit();
//Display skip request on all clients.
Wt::WServer::instance()->postAll([event]() {
Wt::WApplication* app = Wt::WApplication::instance();
if(app != nullptr)
{
static_cast<WebInterface*>(app)->skipVotedFromServer(event.userInvolved);
}
}
);
}
}
else if(event.eventType == SKIP_VOTE_CAST_AGAINST)
{
//TODO
if(!voteEndedButNotNextTrackYet)
{
currentSkipRequester.clear();
//Display skip request on all clients.
Wt::WServer::instance()->postAll([event]() {
Wt::WApplication* app = Wt::WApplication::instance();
if(app != nullptr)
{
static_cast<WebInterface*>(app)->skipVoteUpdateFromServer(event.userInvolved, false);
}
}
);
}
}
else if(event.eventType == SKIP_VOTING_ENDED)
{
//TODO
}
else if(event.eventType == ADMIN_FORCE_SKIP)
{
//Don't skip without first determining next track
if(!voteEndedButNotNextTrackYet)
{
voteEndedButNotNextTrackYet = true;
lastInternalEvents.push_front(PlayerEvent() = {PlayerEventType::ADMIN_FORCE_SKIP});
lastInternalEvents.push_front(PlayerEvent() = {PlayerEventType::SKIP_VOTING_ENDED});
lastInternalEvents.push_front(PlayerEvent() = {PlayerEventType::VOTING_ENDED});
}
else
@@ -463,6 +496,13 @@ void GroovePlayerMgr::grooveEventLoop()
groove_playlist_seek(currentPlaylist, item->next, 0.0);
}
}
else if(event.eventType == ADMIN_FORCE_SKIP)
{
if(!voteEndedButNotNextTrackYet)
{
lastInternalEvents.push_front(PlayerEvent() = {PlayerEventType::SKIP_VOTING_ENDED});
}
}
}
currentPlaylist = nullptr;
@@ -495,6 +535,11 @@ GroovePlayerMgr::PlayerEvent GroovePlayerMgr::getNextPlayerEvent(Wt::Dbo::Sessio
return PlayerEvent() = {PlayerEventType::GROOVE_NOWPLAYING};
}
}
if(!voteEndedButNotNextTrackYet && currentSkipRequester.size() > 0 && skipRequestedAt+std::chrono::seconds(5) < std::chrono::steady_clock::now())
{
//Skip succeeded. Time to skip song.
lastInternalEvents.push_front(PlayerEvent() = {PlayerEventType::SKIP_VOTING_ENDED});
}
if(lastInternalEvents.size() > 0)
{
PlayerEvent event = lastInternalEvents.front();