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:
@@ -33,6 +33,7 @@ std::filesystem::path GroovePlayerMgr::musicScanDir = "";
|
|||||||
|
|
||||||
GroovePlayerMgr::GroovePlayerMgr (std::string dbFile) : sqliteConnection(dbFile)
|
GroovePlayerMgr::GroovePlayerMgr (std::string dbFile) : sqliteConnection(dbFile)
|
||||||
{
|
{
|
||||||
|
musicScanDir = std::filesystem::current_path()/"music";
|
||||||
sqlSession.setConnection(this->sqliteConnection);
|
sqlSession.setConnection(this->sqliteConnection);
|
||||||
sqlSession.mapClass<User>("user");
|
sqlSession.mapClass<User>("user");
|
||||||
sqlSession.mapClass<AudioTrack>("tracks");
|
sqlSession.mapClass<AudioTrack>("tracks");
|
||||||
@@ -154,13 +155,26 @@ void GroovePlayerMgr::grooveEventLoop()
|
|||||||
selectedTrack = getInstance()->sqlSession.find<AudioTrack>().limit(1).offset(rand() % trackCount).resultValue().get();
|
selectedTrack = getInstance()->sqlSession.find<AudioTrack>().limit(1).offset(rand() % trackCount).resultValue().get();
|
||||||
}
|
}
|
||||||
struct GroovePlaylist* playlist = groove_playlist_create();
|
struct GroovePlaylist* playlist = groove_playlist_create();
|
||||||
|
getInstance()->currentPlaylist = playlist;
|
||||||
struct GroovePlayer* player = groove_player_create();
|
struct GroovePlayer* player = groove_player_create();
|
||||||
if(!player) {return;}
|
if(!player) {return;}
|
||||||
|
getInstance()->currentPlayer = player;
|
||||||
|
|
||||||
groove_playlist_insert(playlist, groove_file_open(selectedTrack->trackPath.c_str()),1.0,1.0,nullptr);
|
groove_playlist_insert(playlist, groove_file_open(selectedTrack->trackPath.c_str()),1.0,1.0,nullptr);
|
||||||
|
|
||||||
//Now start loop
|
//Now start loop
|
||||||
groove_player_attach(player, playlist);
|
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)
|
while(getInstance()->continueEventLoop)
|
||||||
{
|
{
|
||||||
@@ -172,6 +186,8 @@ void GroovePlayerMgr::grooveEventLoop()
|
|||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getInstance()->currentPlaylist = nullptr;
|
||||||
|
getInstance()->currentPlayer = nullptr;
|
||||||
groove_player_detach(player);
|
groove_player_detach(player);
|
||||||
groove_player_destroy(player);
|
groove_player_destroy(player);
|
||||||
groove_playlist_destroy(playlist);
|
groove_playlist_destroy(playlist);
|
||||||
@@ -190,8 +206,11 @@ GroovePlayerMgr::PlayerEvents GroovePlayerMgr::getNextPlayerEvent()
|
|||||||
|
|
||||||
Wt::Dbo::ptr<AudioTrack> GroovePlayerMgr::getCurrentTrack()
|
Wt::Dbo::ptr<AudioTrack> GroovePlayerMgr::getCurrentTrack()
|
||||||
{
|
{
|
||||||
Wt::Dbo::Transaction transaction(getInstance()->sqlSession);
|
Wt::Dbo::Transaction transaction(this->sqlSession);
|
||||||
Wt::Dbo::ptr<AudioTrack> track = getInstance()->sqlSession.find<AudioTrack>().where("path = ?").bind(currentItem->file->filename);
|
GroovePlaylistItem* currentItem;
|
||||||
|
double timeInto;
|
||||||
|
groove_player_position(this->currentPlayer,¤tItem,&timeInto);
|
||||||
|
Wt::Dbo::ptr<AudioTrack> track = this->sqlSession.find<AudioTrack>().where("path = ?").bind(currentItem->file->filename);
|
||||||
return track;
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,16 +320,3 @@ void GroovePlayerMgr::grooveAudioScannerLoop()
|
|||||||
removeOrphanedTracks();
|
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();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,13 +37,16 @@ class GroovePlayerMgr
|
|||||||
public:
|
public:
|
||||||
static std::filesystem::path musicScanDir;
|
static std::filesystem::path musicScanDir;
|
||||||
static GroovePlayerMgr* getInstance() {
|
static GroovePlayerMgr* getInstance() {
|
||||||
musicScanDir = std::filesystem::current_path()/"music";
|
|
||||||
static GroovePlayerMgr instance("music.db");
|
static GroovePlayerMgr instance("music.db");
|
||||||
return &instance;
|
return &instance;
|
||||||
};
|
};
|
||||||
GroovePlayerMgr ( GroovePlayerMgr const&) = delete;
|
GroovePlayerMgr ( GroovePlayerMgr const&) = delete;
|
||||||
void operator=( GroovePlayerMgr const&) = delete;
|
void operator=( GroovePlayerMgr const&) = delete;
|
||||||
void shutdown();
|
void shutdown();
|
||||||
|
|
||||||
|
struct GroovePlaylist* currentPlaylist;
|
||||||
|
struct GroovePlayer* currentPlayer;
|
||||||
|
std::list<const AudioTrack*> currentVoteBatch;
|
||||||
private:
|
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};
|
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<const AudioTrack*> requestQueue;
|
||||||
std::list<PlayerEvents> lastInternalEvents;
|
std::list<PlayerEvents> lastInternalEvents;
|
||||||
GroovePlaylistItem* currentItem;
|
|
||||||
|
|
||||||
|
|
||||||
std::thread* grooveEvents;
|
std::thread* grooveEvents;
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ void WebInterface::playPauseActionFromServer(User* userPausing)
|
|||||||
triggerUpdate();
|
triggerUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebInterface::songChangedFromServer(AudioTrack* nextTrack)
|
void WebInterface::songChangedFromServer(const AudioTrack* nextTrack)
|
||||||
{
|
{
|
||||||
priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"change");
|
priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"change");
|
||||||
triggerUpdate();
|
triggerUpdate();
|
||||||
@@ -81,7 +81,7 @@ void WebInterface::voteUpdateFromServer(User* userVoting, bool forSkip)
|
|||||||
triggerUpdate();
|
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");
|
priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"nextvote");
|
||||||
triggerUpdate();
|
triggerUpdate();
|
||||||
@@ -92,3 +92,9 @@ void WebInterface::voteNextPollClosedFromServer()
|
|||||||
priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"voteclosed");
|
priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"voteclosed");
|
||||||
triggerUpdate();
|
triggerUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebInterface::voteTracksUpdatedFromServer(std::list<const AudioTrack *> voteableTracks)
|
||||||
|
{
|
||||||
|
priv_int->playerUI->tempText->setText(priv_int->playerUI->tempText->text()+"votechanged");
|
||||||
|
triggerUpdate();
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,10 +32,11 @@ public:
|
|||||||
~WebInterface();
|
~WebInterface();
|
||||||
void loginCompleted();
|
void loginCompleted();
|
||||||
void playPauseActionFromServer(User* userPausing);
|
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 skipVotedFromServer(User* userRequestingToSkipCurrentTrack);
|
||||||
void voteUpdateFromServer(User* userVoting, bool forSkip);
|
void voteUpdateFromServer(User* userVoting, bool forSkip);
|
||||||
void voteNextSongFromServer(User* userVoting, AudioTrack* trackVoted);
|
void voteNextSongFromServer(User* userVoting, const AudioTrack* trackVoted);
|
||||||
void voteNextPollClosedFromServer();
|
void voteNextPollClosedFromServer();
|
||||||
private:
|
private:
|
||||||
struct internal;
|
struct internal;
|
||||||
|
|||||||
Reference in New Issue
Block a user