From 3aa0493570bd989eeea407f52ec7fc56633789bd Mon Sep 17 00:00:00 2001 From: Nimetu Date: Fri, 17 Apr 2020 13:29:27 +0300 Subject: [PATCH 1/4] Fixed: Clear song info when all songs are done playing. --- .../client/src/interface_v3/music_player.cpp | 60 +++++++++++++------ ryzom/client/src/interface_v3/music_player.h | 6 ++ 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/ryzom/client/src/interface_v3/music_player.cpp b/ryzom/client/src/interface_v3/music_player.cpp index 2f02352fb..98bbd5299 100644 --- a/ryzom/client/src/interface_v3/music_player.cpp +++ b/ryzom/client/src/interface_v3/music_player.cpp @@ -174,28 +174,30 @@ void CMusicPlayer::playSongs (const std::vector &filenames) // If pause, stop, else play will resume if (_State == Paused || _Songs.empty()) - _State = Stopped; + stop(); // get song title/duration using worker thread MusicPlayerWorker.getSongsInfo(filenames); } // *************************************************************************** -void CMusicPlayer::updatePlaylist(sint prevIndex) +void CMusicPlayer::updatePlaylist(uint index, bool state) { - CInterfaceElement *pIE; - std::string rowId; + if (index >= _Songs.size()) return; + + std::string rowId = toString("%s:s%d:bg", MP3_PLAYER_PLAYLIST_LIST, index); + CInterfaceElement *pIE = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(rowId)); + if (pIE) pIE->setActive(state); +} +void CMusicPlayer::updatePlaylist(sint prevIndex) +{ if (prevIndex >= 0 && prevIndex < _Songs.size()) { - rowId = toString("%s:s%d:bg", MP3_PLAYER_PLAYLIST_LIST, prevIndex); - pIE = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(rowId)); - if (pIE) pIE->setActive(false); + updatePlaylist(prevIndex, false); } - rowId = toString("%s:s%d:bg", MP3_PLAYER_PLAYLIST_LIST, _CurrentSongIndex); - pIE = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(rowId)); - if (pIE) pIE->setActive(true); + updatePlaylist(_CurrentSongIndex, true); } // *************************************************************************** @@ -361,7 +363,7 @@ void CMusicPlayer::play (sint index) if (_Songs.empty()) { - _State = Stopped; + stop(); return; } @@ -437,6 +439,8 @@ void CMusicPlayer::stop () _PlayStart = 0; _PauseTime = 0; + clearPlayingInfo(); + NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:MP3_PLAYING")->setValueBool(false); } @@ -472,12 +476,31 @@ void CMusicPlayer::next () } // *************************************************************************** +void CMusicPlayer::updatePlayingInfo(const std::string info) +{ + CViewText *pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:mp3_player:screen:text")); + if (pVT) + { + pVT->setText(ucstring::makeFromUtf8(info)); + } +} + +// *************************************************************************** +void CMusicPlayer::clearPlayingInfo() +{ + updatePlayingInfo(""); +} +// *************************************************************************** void CMusicPlayer::update () { if(!SoundMngr) { - _State = Stopped; + if (_State != Stopped) + { + _State = Stopped; + clearPlayingInfo(); + } return; } @@ -488,8 +511,6 @@ void CMusicPlayer::update () if (_State == Playing) { - CViewText *pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:mp3_player:screen:text")); - if (pVT) { TTime dur = (CTime::getLocalTime() - _PlayStart) / 1000; uint min = (dur / 60) % 60; @@ -499,7 +520,7 @@ void CMusicPlayer::update () std::string title(toString("%02d:%02d", min, sec)); if (hour > 0) title = toString("%02d:", hour) + title; title += " " + _CurrentSong.Title; - pVT->setText(ucstring::makeFromUtf8(title)); + updatePlayingInfo(title); } if (SoundMngr->isMusicEnded ()) @@ -520,8 +541,13 @@ void CMusicPlayer::update () } else { - SoundMngr->stopMusic(0); - _State = Stopped; + // remove active highlight from playlist + updatePlaylist(_CurrentSongIndex, false); + + stop(); + + // restart from top on next 'play' + _CurrentSongIndex = 0; } } } diff --git a/ryzom/client/src/interface_v3/music_player.h b/ryzom/client/src/interface_v3/music_player.h index 1932591e3..febfde719 100644 --- a/ryzom/client/src/interface_v3/music_player.h +++ b/ryzom/client/src/interface_v3/music_player.h @@ -62,6 +62,10 @@ public: void update (); + // update currently playing song info/duration on main gui + void updatePlayingInfo(const std::string info); + void clearPlayingInfo(); + bool isRepeatEnabled() const; bool isShuffleEnabled() const; @@ -71,6 +75,8 @@ public: void shuffleAndRebuildPlaylist(); // Update playlist active row void updatePlaylist(sint prevIndex = -1); + // set/remove playlist highlight + void updatePlaylist(uint index, bool state); // Update single song title/duration on _Songs and on playlist void updateSong(const CSongs &song); From 334d1d2af1c04edb21031000b7ffbbf388f153aa Mon Sep 17 00:00:00 2001 From: Nimetu Date: Sat, 18 Apr 2020 09:31:29 +0300 Subject: [PATCH 2/4] Changed: SHow no-files text if there is no songs in playlist --- ryzom/client/src/interface_v3/music_player.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ryzom/client/src/interface_v3/music_player.cpp b/ryzom/client/src/interface_v3/music_player.cpp index 98bbd5299..6c94fa2cf 100644 --- a/ryzom/client/src/interface_v3/music_player.cpp +++ b/ryzom/client/src/interface_v3/music_player.cpp @@ -488,7 +488,14 @@ void CMusicPlayer::updatePlayingInfo(const std::string info) // *************************************************************************** void CMusicPlayer::clearPlayingInfo() { - updatePlayingInfo(""); + if (_Songs.empty()) + { + updatePlayingInfo(CI18N::get("uiNoFiles").toUtf8()); + } + else + { + updatePlayingInfo(""); + } } // *************************************************************************** From e9f63f2556fc59c0ea12298bc974b3b2e48628bf Mon Sep 17 00:00:00 2001 From: Nimetu Date: Sat, 18 Apr 2020 11:47:28 +0300 Subject: [PATCH 3/4] Merge "Fixed: Restore playlist after charselect" --- ryzom/client/src/interface_v3/interface_manager.cpp | 4 ++++ ryzom/client/src/release.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ryzom/client/src/interface_v3/interface_manager.cpp b/ryzom/client/src/interface_v3/interface_manager.cpp index 50acc2308..23440218e 100644 --- a/ryzom/client/src/interface_v3/interface_manager.cpp +++ b/ryzom/client/src/interface_v3/interface_manager.cpp @@ -1044,6 +1044,10 @@ void CInterfaceManager::initInGame() gc->setTarget(gc->getSavedTarget()); } + // rebuild mp3 player playlist if user reselected a char (songs are already scanned) + CAHManager::getInstance()->runActionHandler("music_player", NULL, "update_playlist"); + CAHManager::getInstance()->runActionHandler("music_player", NULL, "stop"); + CCDBNodeLeaf *node = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:CHATLOG_STATE", false); if (node) { diff --git a/ryzom/client/src/release.cpp b/ryzom/client/src/release.cpp index 0477acce9..889bcee11 100644 --- a/ryzom/client/src/release.cpp +++ b/ryzom/client/src/release.cpp @@ -240,8 +240,8 @@ void releaseMainLoopReselect() // alredy called from farTPMainLoop() // --R2::getEditor().autoConfigRelease(IsInRingSession); - // Pause any user played music - MusicPlayer.pause(); + // stop any user played music + MusicPlayer.stop(); // only really needed at exit // --STRING_MANAGER::CStringManagerClient::instance()->flushStringCache(); @@ -390,8 +390,8 @@ void releaseMainLoop(bool closeConnection) // Release R2 editor if applicable R2::getEditor().autoConfigRelease(IsInRingSession); - // Pause any user played music - MusicPlayer.pause(); + // stop any user played music + MusicPlayer.stop(); // flush the server string cache STRING_MANAGER::CStringManagerClient::instance()->flushStringCache(); From c09736a08ae8aae85ab6aac84a2b4df9fdcae2b8 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Wed, 6 May 2020 17:43:51 +0300 Subject: [PATCH 4/4] Fixed: Calling stop on music player should not affect background music. --- ryzom/client/src/interface_v3/music_player.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ryzom/client/src/interface_v3/music_player.cpp b/ryzom/client/src/interface_v3/music_player.cpp index 6c94fa2cf..56f97b554 100644 --- a/ryzom/client/src/interface_v3/music_player.cpp +++ b/ryzom/client/src/interface_v3/music_player.cpp @@ -434,7 +434,9 @@ void CMusicPlayer::stop () return; // stop the music only if we are really playing (else risk to stop a background music!) - SoundMngr->stopMusic(0); + if (_State != Stopped) + SoundMngr->stopMusic(0); + _State = Stopped; _PlayStart = 0; _PauseTime = 0;