1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-21 07:09:42 +00:00

Merge branch '24-7lofibeatstoachievechimto' into 'master'

Rework music playback (bug #7172)

Closes #7172

See merge request OpenMW/openmw!2640
This commit is contained in:
psi29a 2023-01-21 23:07:25 +00:00
commit 7be20301af
5 changed files with 37 additions and 47 deletions

View file

@ -32,6 +32,7 @@
Bug #7054: Quests aren't sorted by name Bug #7054: Quests aren't sorted by name
Bug #7084: Resurrecting an actor doesn't take into account base record changes Bug #7084: Resurrecting an actor doesn't take into account base record changes
Bug #7088: Deleting last save game of last character doesn't clear character name/details Bug #7088: Deleting last save game of last character doesn't clear character name/details
Bug #7172: Current music playlist continues playing indefinitely if next playlist is empty
Feature #5492: Let rain and snow collide with statics Feature #5492: Let rain and snow collide with statics
Feature #6447: Add LOD support to Object Paging Feature #6447: Add LOD support to Object Paging
Feature #6922: Improve launcher appearance Feature #6922: Improve launcher appearance

View file

@ -897,7 +897,7 @@ void OMW::Engine::go()
{ {
// start in main menu // start in main menu
mWindowManager->pushGuiMode(MWGui::GM_MainMenu); mWindowManager->pushGuiMode(MWGui::GM_MainMenu);
mSoundManager->playTitleMusic(); mSoundManager->playPlaylist("Title");
std::string_view logo = Fallback::Map::getString("Movies_Morrowind_Logo"); std::string_view logo = Fallback::Map::getString("Movies_Morrowind_Logo");
if (!logo.empty()) if (!logo.empty())
mWindowManager->playVideo(logo, /*allowSkipping*/ true, /*overrideSounds*/ false); mWindowManager->playVideo(logo, /*allowSkipping*/ true, /*overrideSounds*/ false);

View file

@ -113,9 +113,7 @@ namespace MWBase
virtual void playPlaylist(const std::string& playlist) = 0; virtual void playPlaylist(const std::string& playlist) = 0;
///< Start playing music from the selected folder ///< Start playing music from the selected folder
/// \param name of the folder that contains the playlist /// \param name of the folder that contains the playlist
/// Title music playlist is predefined
virtual void playTitleMusic() = 0;
///< Start playing title music
virtual void say(const MWWorld::ConstPtr& reference, const std::string& filename) = 0; virtual void say(const MWWorld::ConstPtr& reference, const std::string& filename) = 0;
///< Make an actor say some text. ///< Make an actor say some text.

View file

@ -129,6 +129,15 @@ namespace MWSound
Log(Debug::Info) << stream.str(); Log(Debug::Info) << stream.str();
} }
// TODO: dehardcode this
std::vector<std::string> titleMusic;
std::string_view titlefile = "music/special/morrowind title.mp3";
if (mVFS->exists(titlefile))
titleMusic.emplace_back(titlefile);
else
Log(Debug::Warning) << "Title music not found";
mMusicFiles["Title"] = titleMusic;
} }
SoundManager::~SoundManager() SoundManager::~SoundManager()
@ -234,10 +243,13 @@ namespace MWSound
{ {
if (!mOutput->isInitialized()) if (!mOutput->isInitialized())
return; return;
Log(Debug::Info) << "Playing " << filename;
mLastPlayedMusic = filename;
stopMusic(); stopMusic();
if (filename.empty())
return;
Log(Debug::Info) << "Playing " << filename;
mLastPlayedMusic = filename;
DecoderPtr decoder = getDecoder(); DecoderPtr decoder = getDecoder();
try try
@ -276,6 +288,12 @@ namespace MWSound
void SoundManager::startRandomTitle() void SoundManager::startRandomTitle()
{ {
const std::vector<std::string>& filelist = mMusicFiles[mCurrentPlaylist]; const std::vector<std::string>& filelist = mMusicFiles[mCurrentPlaylist];
if (filelist.empty())
{
advanceMusic(std::string());
return;
}
auto& tracklist = mMusicToPlay[mCurrentPlaylist]; auto& tracklist = mMusicToPlay[mCurrentPlaylist];
// Do a Fisher-Yates shuffle // Do a Fisher-Yates shuffle
@ -317,46 +335,20 @@ namespace MWSound
if (mMusicFiles.find(playlist) == mMusicFiles.end()) if (mMusicFiles.find(playlist) == mMusicFiles.end())
{ {
std::vector<std::string> filelist; std::vector<std::string> filelist;
for (const auto& name : mVFS->getRecursiveDirectoryIterator("Music/" + playlist + '/'))
for (const auto& name : mVFS->getRecursiveDirectoryIterator("Music/" + playlist))
filelist.push_back(name); filelist.push_back(name);
mMusicFiles[playlist] = filelist; mMusicFiles[playlist] = filelist;
} }
if (mMusicFiles[playlist].empty()) // No Battle music? Use Explore playlist
return; if (playlist == "Battle" && mMusicFiles[playlist].empty())
mCurrentPlaylist = playlist;
startRandomTitle();
}
void SoundManager::playTitleMusic()
{
if (mCurrentPlaylist == "Title")
return;
if (mMusicFiles.find("Title") == mMusicFiles.end())
{ {
std::vector<std::string> filelist; playPlaylist("Explore");
// Is there an ini setting for this filename or something? return;
std::string_view filename = "music/special/morrowind title.mp3";
if (mVFS->exists(filename))
{
filelist.emplace_back(filename);
mMusicFiles["Title"] = filelist;
}
else
{
Log(Debug::Warning) << "Title music not found";
return;
}
} }
if (mMusicFiles["Title"].empty()) mCurrentPlaylist = playlist;
return;
mCurrentPlaylist = "Title";
startRandomTitle(); startRandomTitle();
} }
@ -1013,18 +1005,19 @@ namespace MWSound
void SoundManager::updateMusic(float duration) void SoundManager::updateMusic(float duration)
{ {
if (!mNextMusic.empty()) if (!mMusic || !mMusic->updateFade(duration) || !mOutput->isStreamPlaying(mMusic.get()))
{ {
mMusic->updateFade(duration); stopMusic();
if (!mNextMusic.empty())
mOutput->updateStream(mMusic.get());
if (mMusic->getRealVolume() <= 0.f)
{ {
streamMusicFull(mNextMusic); streamMusicFull(mNextMusic);
mNextMusic.clear(); mNextMusic.clear();
} }
} }
else
{
mOutput->updateStream(mMusic.get());
}
} }
void SoundManager::update(float duration) void SoundManager::update(float duration)

View file

@ -174,9 +174,7 @@ namespace MWSound
void playPlaylist(const std::string& playlist) override; void playPlaylist(const std::string& playlist) override;
///< Start playing music from the selected folder ///< Start playing music from the selected folder
/// \param name of the folder that contains the playlist /// \param name of the folder that contains the playlist
/// Title music playlist is predefined
void playTitleMusic() override;
///< Start playing title music
void say(const MWWorld::ConstPtr& reference, const std::string& filename) override; void say(const MWWorld::ConstPtr& reference, const std::string& filename) override;
///< Make an actor say some text. ///< Make an actor say some text.