Rework music playback (bug #7172)

7220-lua-add-a-general-purpose-lexical-parser
Alexei Kotov 1 year ago
parent f0e58d1c59
commit fd6e96576a

@ -32,6 +32,7 @@
Bug #7054: Quests aren't sorted by name
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 #7172: Current music playlist continues playing indefinitely if next playlist is empty
Feature #5492: Let rain and snow collide with statics
Feature #6447: Add LOD support to Object Paging
Feature #6922: Improve launcher appearance

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

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

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

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

Loading…
Cancel
Save