Use normalized path for SoundManager::streamMusic

pull/3235/head
elsid 3 weeks ago
parent 40cc16046b
commit a863899eb1
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

@ -64,6 +64,7 @@
#include "mwscript/interpretercontext.hpp"
#include "mwscript/scriptmanagerimp.hpp"
#include "mwsound/constants.hpp"
#include "mwsound/soundmanagerimp.hpp"
#include "mwworld/class.hpp"
@ -987,9 +988,8 @@ void OMW::Engine::go()
// start in main menu
mWindowManager->pushGuiMode(MWGui::GM_MainMenu);
std::string titlefile = "music/special/morrowind title.mp3";
if (mVFS->exists(titlefile))
mSoundManager->streamMusic(titlefile, MWSound::MusicType::Special);
if (mVFS->exists(MWSound::titleMusic))
mSoundManager->streamMusic(MWSound::titleMusic, MWSound::MusicType::Special);
else
Log(Debug::Warning) << "Title music not found";

@ -117,7 +117,7 @@ namespace MWBase
virtual void stopMusic() = 0;
///< Stops music if it's playing
virtual void streamMusic(const std::string& filename, MWSound::MusicType type, float fade = 1.f) = 0;
virtual void streamMusic(VFS::Path::NormalizedView filename, MWSound::MusicType type, float fade = 1.f) = 0;
///< Play a soundifle
/// \param filename name of a sound file in the data directory.
/// \param type music type.

@ -22,6 +22,8 @@
#include "../mwmechanics/creaturestats.hpp"
#include "../mwmechanics/npcstats.hpp"
#include "../mwsound/constants.hpp"
#include "class.hpp"
namespace
@ -216,8 +218,7 @@ namespace MWGui
center();
// Play LevelUp Music
MWBase::Environment::get().getSoundManager()->streamMusic(
"Music/Special/MW_Triumph.mp3", MWSound::MusicType::Special);
MWBase::Environment::get().getSoundManager()->streamMusic(MWSound::triumphMusic, MWSound::MusicType::Special);
}
void LevelupDialog::onOkButtonClicked(MyGUI::Widget* sender)

@ -141,7 +141,7 @@ namespace MWLua
api["streamMusic"] = [](std::string_view fileName, const sol::optional<sol::table>& options) {
auto args = getStreamMusicArgs(options);
MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager();
sndMgr->streamMusic(std::string(fileName), MWSound::MusicType::Scripted, args.mFade);
sndMgr->streamMusic(VFS::Path::Normalized(fileName), MWSound::MusicType::Scripted, args.mFade);
};
api["say"]

@ -39,6 +39,8 @@
#include "../mwrender/vismask.hpp"
#include "../mwsound/constants.hpp"
#include "actor.hpp"
#include "actorutil.hpp"
#include "aicombataction.hpp"
@ -1798,7 +1800,7 @@ namespace MWMechanics
MWBase::Environment::get().getStateManager()->askLoadRecent();
// Play Death Music if it was the player dying
MWBase::Environment::get().getSoundManager()->streamMusic(
"Music/Special/MW_Death.mp3", MWSound::MusicType::Special);
MWSound::deathMusic, MWSound::MusicType::Special);
}
else
{

@ -63,7 +63,7 @@ namespace MWScript
public:
void execute(Interpreter::Runtime& runtime) override
{
std::string music{ runtime.getStringLiteral(runtime[0].mInteger) };
const VFS::Path::Normalized music(runtime.getStringLiteral(runtime[0].mInteger));
runtime.pop();
MWBase::Environment::get().getSoundManager()->streamMusic(

@ -7,6 +7,9 @@ namespace MWSound
{
constexpr VFS::Path::NormalizedView battlePlaylist("battle");
constexpr VFS::Path::NormalizedView explorePlaylist("explore");
constexpr VFS::Path::NormalizedView titleMusic("music/special/morrowind title.mp3");
constexpr VFS::Path::NormalizedView triumphMusic("music/special/mw_triumph.mp3");
constexpr VFS::Path::NormalizedView deathMusic("music/special/mw_death.mp3");
}
#endif

@ -252,13 +252,13 @@ namespace MWSound
}
}
void SoundManager::streamMusicFull(const std::string& filename)
void SoundManager::streamMusicFull(VFS::Path::NormalizedView filename)
{
if (!mOutput->isInitialized())
return;
stopMusic();
if (filename.empty())
if (filename.value().empty())
return;
Log(Debug::Info) << "Playing \"" << filename << "\"";
@ -267,9 +267,9 @@ namespace MWSound
DecoderPtr decoder = getDecoder();
try
{
decoder->open(VFS::Path::Normalized(filename));
decoder->open(filename);
}
catch (std::exception& e)
catch (const std::exception& e)
{
Log(Debug::Error) << "Failed to load audio from \"" << filename << "\": " << e.what();
return;
@ -285,7 +285,7 @@ namespace MWSound
mOutput->streamSound(std::move(decoder), mMusic.get());
}
void SoundManager::advanceMusic(const std::string& filename, float fadeOut)
void SoundManager::advanceMusic(VFS::Path::NormalizedView filename, float fadeOut)
{
if (!isMusicPlaying())
{
@ -304,7 +304,7 @@ namespace MWSound
if (playlist == mMusicFiles.end() || playlist->second.empty())
{
advanceMusic(std::string());
advanceMusic(VFS::Path::NormalizedView());
return;
}
@ -338,7 +338,7 @@ namespace MWSound
return mMusic && mOutput->isStreamPlaying(mMusic.get());
}
void SoundManager::streamMusic(const std::string& filename, MusicType type, float fade)
void SoundManager::streamMusic(VFS::Path::NormalizedView filename, MusicType type, float fade)
{
const auto mechanicsManager = MWBase::Environment::get().getMechanicsManager();
@ -347,10 +347,8 @@ namespace MWSound
&& type != MusicType::Special)
return;
std::string normalizedName = VFS::Path::normalizeFilename(filename);
mechanicsManager->setMusicType(type);
advanceMusic(normalizedName, fade);
advanceMusic(filename, fade);
if (type == MWSound::MusicType::Battle)
mCurrentPlaylist = battlePlaylist;
else if (type == MWSound::MusicType::Explore)
@ -367,8 +365,8 @@ namespace MWSound
if (it == mMusicFiles.end())
{
std::vector<VFS::Path::Normalized> filelist;
constexpr VFS::Path::NormalizedView music("music");
const VFS::Path::Normalized playlistPath = music / playlist / VFS::Path::NormalizedView();
const VFS::Path::Normalized playlistPath
= Misc::ResourceHelpers::correctMusicPath(playlist) / VFS::Path::NormalizedView();
for (const auto& name : mVFS->getRecursiveDirectoryIterator(VFS::Path::NormalizedView(playlistPath)))
filelist.push_back(name);
@ -1143,10 +1141,10 @@ namespace MWSound
if (!mMusic || !mMusic->updateFade(duration) || !mOutput->isStreamPlaying(mMusic.get()))
{
stopMusic();
if (!mNextMusic.empty())
if (!mNextMusic.value().empty())
{
streamMusicFull(mNextMusic);
mNextMusic.clear();
mNextMusic = VFS::Path::Normalized();
}
}
else
@ -1166,9 +1164,8 @@ namespace MWSound
if (isMainMenu && !isMusicPlaying())
{
std::string titlefile = "music/special/morrowind title.mp3";
if (mVFS->exists(titlefile))
streamMusic(titlefile, MWSound::MusicType::Special);
if (mVFS->exists(MWSound::titleMusic))
streamMusic(MWSound::titleMusic, MWSound::MusicType::Special);
}
updateSounds(duration);

@ -56,7 +56,7 @@ namespace MWSound
std::unordered_map<VFS::Path::Normalized, std::vector<VFS::Path::Normalized>, VFS::Path::Hash, std::equal_to<>>
mMusicFiles;
std::unordered_map<std::string, std::vector<int>> mMusicToPlay; // A list with music files not yet played
std::string mLastPlayedMusic; // The music file that was last played
VFS::Path::Normalized mLastPlayedMusic; // The music file that was last played
WaterSoundUpdater mWaterSoundUpdater;
@ -104,7 +104,7 @@ namespace MWSound
Sound* mUnderwaterSound;
Sound* mNearWaterSound;
std::string mNextMusic;
VFS::Path::Normalized mNextMusic;
bool mPlaybackPaused;
RegionSoundSelector mRegionSoundSelector;
@ -125,8 +125,8 @@ namespace MWSound
StreamPtr playVoice(DecoderPtr decoder, const osg::Vec3f& pos, bool playlocal);
void streamMusicFull(const std::string& filename);
void advanceMusic(const std::string& filename, float fadeOut = 1.f);
void streamMusicFull(VFS::Path::NormalizedView filename);
void advanceMusic(VFS::Path::NormalizedView filename, float fadeOut = 1.f);
void startRandomTitle();
void cull3DSound(SoundBase* sound);
@ -176,7 +176,7 @@ namespace MWSound
void stopMusic() override;
///< Stops music if it's playing
void streamMusic(const std::string& filename, MWSound::MusicType type, float fade = 1.f) override;
void streamMusic(VFS::Path::NormalizedView filename, MWSound::MusicType type, float fade = 1.f) override;
///< Play a soundifle
/// \param filename name of a sound file in the data directory.
/// \param type music type.

@ -186,11 +186,10 @@ VFS::Path::Normalized Misc::ResourceHelpers::correctSoundPath(VFS::Path::Normali
return prefix / resPath;
}
std::string Misc::ResourceHelpers::correctMusicPath(std::string_view resPath)
VFS::Path::Normalized Misc::ResourceHelpers::correctMusicPath(VFS::Path::NormalizedView resPath)
{
std::string result("music/");
result += resPath;
return result;
static constexpr VFS::Path::NormalizedView prefix("music");
return prefix / resPath;
}
std::string_view Misc::ResourceHelpers::meshPathForESM3(std::string_view resPath)

@ -38,11 +38,11 @@ namespace Misc
// Adds "meshes\\".
std::string correctMeshPath(std::string_view resPath);
// Adds "sound\\".
// Prepends "sound/".
VFS::Path::Normalized correctSoundPath(VFS::Path::NormalizedView resPath);
// Adds "music\\".
std::string correctMusicPath(std::string_view resPath);
// Prepends "music/".
VFS::Path::Normalized correctMusicPath(VFS::Path::NormalizedView resPath);
// Removes "meshes\\".
std::string_view meshPathForESM3(std::string_view resPath);

Loading…
Cancel
Save