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)
|
||||
{
|
||||
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,¤tItem,&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();
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user