mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-19 10:41:36 +00:00
Use normalized path for SoundManager::streamMusic
This commit is contained in:
parent
40cc16046b
commit
a863899eb1
11 changed files with 40 additions and 38 deletions
|
@ -64,6 +64,7 @@
|
||||||
#include "mwscript/interpretercontext.hpp"
|
#include "mwscript/interpretercontext.hpp"
|
||||||
#include "mwscript/scriptmanagerimp.hpp"
|
#include "mwscript/scriptmanagerimp.hpp"
|
||||||
|
|
||||||
|
#include "mwsound/constants.hpp"
|
||||||
#include "mwsound/soundmanagerimp.hpp"
|
#include "mwsound/soundmanagerimp.hpp"
|
||||||
|
|
||||||
#include "mwworld/class.hpp"
|
#include "mwworld/class.hpp"
|
||||||
|
@ -987,9 +988,8 @@ void OMW::Engine::go()
|
||||||
// start in main menu
|
// start in main menu
|
||||||
mWindowManager->pushGuiMode(MWGui::GM_MainMenu);
|
mWindowManager->pushGuiMode(MWGui::GM_MainMenu);
|
||||||
|
|
||||||
std::string titlefile = "music/special/morrowind title.mp3";
|
if (mVFS->exists(MWSound::titleMusic))
|
||||||
if (mVFS->exists(titlefile))
|
mSoundManager->streamMusic(MWSound::titleMusic, MWSound::MusicType::Special);
|
||||||
mSoundManager->streamMusic(titlefile, MWSound::MusicType::Special);
|
|
||||||
else
|
else
|
||||||
Log(Debug::Warning) << "Title music not found";
|
Log(Debug::Warning) << "Title music not found";
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ namespace MWBase
|
||||||
virtual void stopMusic() = 0;
|
virtual void stopMusic() = 0;
|
||||||
///< Stops music if it's playing
|
///< 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
|
///< Play a soundifle
|
||||||
/// \param filename name of a sound file in the data directory.
|
/// \param filename name of a sound file in the data directory.
|
||||||
/// \param type music type.
|
/// \param type music type.
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#include "../mwmechanics/creaturestats.hpp"
|
#include "../mwmechanics/creaturestats.hpp"
|
||||||
#include "../mwmechanics/npcstats.hpp"
|
#include "../mwmechanics/npcstats.hpp"
|
||||||
|
|
||||||
|
#include "../mwsound/constants.hpp"
|
||||||
|
|
||||||
#include "class.hpp"
|
#include "class.hpp"
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
@ -216,8 +218,7 @@ namespace MWGui
|
||||||
center();
|
center();
|
||||||
|
|
||||||
// Play LevelUp Music
|
// Play LevelUp Music
|
||||||
MWBase::Environment::get().getSoundManager()->streamMusic(
|
MWBase::Environment::get().getSoundManager()->streamMusic(MWSound::triumphMusic, MWSound::MusicType::Special);
|
||||||
"Music/Special/MW_Triumph.mp3", MWSound::MusicType::Special);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LevelupDialog::onOkButtonClicked(MyGUI::Widget* sender)
|
void LevelupDialog::onOkButtonClicked(MyGUI::Widget* sender)
|
||||||
|
|
|
@ -141,7 +141,7 @@ namespace MWLua
|
||||||
api["streamMusic"] = [](std::string_view fileName, const sol::optional<sol::table>& options) {
|
api["streamMusic"] = [](std::string_view fileName, const sol::optional<sol::table>& options) {
|
||||||
auto args = getStreamMusicArgs(options);
|
auto args = getStreamMusicArgs(options);
|
||||||
MWBase::SoundManager* sndMgr = MWBase::Environment::get().getSoundManager();
|
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"]
|
api["say"]
|
||||||
|
|
|
@ -39,6 +39,8 @@
|
||||||
|
|
||||||
#include "../mwrender/vismask.hpp"
|
#include "../mwrender/vismask.hpp"
|
||||||
|
|
||||||
|
#include "../mwsound/constants.hpp"
|
||||||
|
|
||||||
#include "actor.hpp"
|
#include "actor.hpp"
|
||||||
#include "actorutil.hpp"
|
#include "actorutil.hpp"
|
||||||
#include "aicombataction.hpp"
|
#include "aicombataction.hpp"
|
||||||
|
@ -1798,7 +1800,7 @@ namespace MWMechanics
|
||||||
MWBase::Environment::get().getStateManager()->askLoadRecent();
|
MWBase::Environment::get().getStateManager()->askLoadRecent();
|
||||||
// Play Death Music if it was the player dying
|
// Play Death Music if it was the player dying
|
||||||
MWBase::Environment::get().getSoundManager()->streamMusic(
|
MWBase::Environment::get().getSoundManager()->streamMusic(
|
||||||
"Music/Special/MW_Death.mp3", MWSound::MusicType::Special);
|
MWSound::deathMusic, MWSound::MusicType::Special);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -63,7 +63,7 @@ namespace MWScript
|
||||||
public:
|
public:
|
||||||
void execute(Interpreter::Runtime& runtime) override
|
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();
|
runtime.pop();
|
||||||
|
|
||||||
MWBase::Environment::get().getSoundManager()->streamMusic(
|
MWBase::Environment::get().getSoundManager()->streamMusic(
|
||||||
|
|
|
@ -7,6 +7,9 @@ namespace MWSound
|
||||||
{
|
{
|
||||||
constexpr VFS::Path::NormalizedView battlePlaylist("battle");
|
constexpr VFS::Path::NormalizedView battlePlaylist("battle");
|
||||||
constexpr VFS::Path::NormalizedView explorePlaylist("explore");
|
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
|
#endif
|
||||||
|
|
|
@ -252,13 +252,13 @@ namespace MWSound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::streamMusicFull(const std::string& filename)
|
void SoundManager::streamMusicFull(VFS::Path::NormalizedView filename)
|
||||||
{
|
{
|
||||||
if (!mOutput->isInitialized())
|
if (!mOutput->isInitialized())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
stopMusic();
|
stopMusic();
|
||||||
if (filename.empty())
|
if (filename.value().empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Log(Debug::Info) << "Playing \"" << filename << "\"";
|
Log(Debug::Info) << "Playing \"" << filename << "\"";
|
||||||
|
@ -267,9 +267,9 @@ namespace MWSound
|
||||||
DecoderPtr decoder = getDecoder();
|
DecoderPtr decoder = getDecoder();
|
||||||
try
|
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();
|
Log(Debug::Error) << "Failed to load audio from \"" << filename << "\": " << e.what();
|
||||||
return;
|
return;
|
||||||
|
@ -285,7 +285,7 @@ namespace MWSound
|
||||||
mOutput->streamSound(std::move(decoder), mMusic.get());
|
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())
|
if (!isMusicPlaying())
|
||||||
{
|
{
|
||||||
|
@ -304,7 +304,7 @@ namespace MWSound
|
||||||
|
|
||||||
if (playlist == mMusicFiles.end() || playlist->second.empty())
|
if (playlist == mMusicFiles.end() || playlist->second.empty())
|
||||||
{
|
{
|
||||||
advanceMusic(std::string());
|
advanceMusic(VFS::Path::NormalizedView());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,7 +338,7 @@ namespace MWSound
|
||||||
return mMusic && mOutput->isStreamPlaying(mMusic.get());
|
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();
|
const auto mechanicsManager = MWBase::Environment::get().getMechanicsManager();
|
||||||
|
|
||||||
|
@ -347,10 +347,8 @@ namespace MWSound
|
||||||
&& type != MusicType::Special)
|
&& type != MusicType::Special)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
std::string normalizedName = VFS::Path::normalizeFilename(filename);
|
|
||||||
|
|
||||||
mechanicsManager->setMusicType(type);
|
mechanicsManager->setMusicType(type);
|
||||||
advanceMusic(normalizedName, fade);
|
advanceMusic(filename, fade);
|
||||||
if (type == MWSound::MusicType::Battle)
|
if (type == MWSound::MusicType::Battle)
|
||||||
mCurrentPlaylist = battlePlaylist;
|
mCurrentPlaylist = battlePlaylist;
|
||||||
else if (type == MWSound::MusicType::Explore)
|
else if (type == MWSound::MusicType::Explore)
|
||||||
|
@ -367,8 +365,8 @@ namespace MWSound
|
||||||
if (it == mMusicFiles.end())
|
if (it == mMusicFiles.end())
|
||||||
{
|
{
|
||||||
std::vector<VFS::Path::Normalized> filelist;
|
std::vector<VFS::Path::Normalized> filelist;
|
||||||
constexpr VFS::Path::NormalizedView music("music");
|
const VFS::Path::Normalized playlistPath
|
||||||
const VFS::Path::Normalized playlistPath = music / playlist / VFS::Path::NormalizedView();
|
= Misc::ResourceHelpers::correctMusicPath(playlist) / VFS::Path::NormalizedView();
|
||||||
for (const auto& name : mVFS->getRecursiveDirectoryIterator(VFS::Path::NormalizedView(playlistPath)))
|
for (const auto& name : mVFS->getRecursiveDirectoryIterator(VFS::Path::NormalizedView(playlistPath)))
|
||||||
filelist.push_back(name);
|
filelist.push_back(name);
|
||||||
|
|
||||||
|
@ -1143,10 +1141,10 @@ namespace MWSound
|
||||||
if (!mMusic || !mMusic->updateFade(duration) || !mOutput->isStreamPlaying(mMusic.get()))
|
if (!mMusic || !mMusic->updateFade(duration) || !mOutput->isStreamPlaying(mMusic.get()))
|
||||||
{
|
{
|
||||||
stopMusic();
|
stopMusic();
|
||||||
if (!mNextMusic.empty())
|
if (!mNextMusic.value().empty())
|
||||||
{
|
{
|
||||||
streamMusicFull(mNextMusic);
|
streamMusicFull(mNextMusic);
|
||||||
mNextMusic.clear();
|
mNextMusic = VFS::Path::Normalized();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1166,9 +1164,8 @@ namespace MWSound
|
||||||
|
|
||||||
if (isMainMenu && !isMusicPlaying())
|
if (isMainMenu && !isMusicPlaying())
|
||||||
{
|
{
|
||||||
std::string titlefile = "music/special/morrowind title.mp3";
|
if (mVFS->exists(MWSound::titleMusic))
|
||||||
if (mVFS->exists(titlefile))
|
streamMusic(MWSound::titleMusic, MWSound::MusicType::Special);
|
||||||
streamMusic(titlefile, MWSound::MusicType::Special);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSounds(duration);
|
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<>>
|
std::unordered_map<VFS::Path::Normalized, std::vector<VFS::Path::Normalized>, VFS::Path::Hash, std::equal_to<>>
|
||||||
mMusicFiles;
|
mMusicFiles;
|
||||||
std::unordered_map<std::string, std::vector<int>> mMusicToPlay; // A list with music files not yet played
|
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;
|
WaterSoundUpdater mWaterSoundUpdater;
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ namespace MWSound
|
||||||
Sound* mUnderwaterSound;
|
Sound* mUnderwaterSound;
|
||||||
Sound* mNearWaterSound;
|
Sound* mNearWaterSound;
|
||||||
|
|
||||||
std::string mNextMusic;
|
VFS::Path::Normalized mNextMusic;
|
||||||
bool mPlaybackPaused;
|
bool mPlaybackPaused;
|
||||||
|
|
||||||
RegionSoundSelector mRegionSoundSelector;
|
RegionSoundSelector mRegionSoundSelector;
|
||||||
|
@ -125,8 +125,8 @@ namespace MWSound
|
||||||
|
|
||||||
StreamPtr playVoice(DecoderPtr decoder, const osg::Vec3f& pos, bool playlocal);
|
StreamPtr playVoice(DecoderPtr decoder, const osg::Vec3f& pos, bool playlocal);
|
||||||
|
|
||||||
void streamMusicFull(const std::string& filename);
|
void streamMusicFull(VFS::Path::NormalizedView filename);
|
||||||
void advanceMusic(const std::string& filename, float fadeOut = 1.f);
|
void advanceMusic(VFS::Path::NormalizedView filename, float fadeOut = 1.f);
|
||||||
void startRandomTitle();
|
void startRandomTitle();
|
||||||
|
|
||||||
void cull3DSound(SoundBase* sound);
|
void cull3DSound(SoundBase* sound);
|
||||||
|
@ -176,7 +176,7 @@ namespace MWSound
|
||||||
void stopMusic() override;
|
void stopMusic() override;
|
||||||
///< Stops music if it's playing
|
///< 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
|
///< Play a soundifle
|
||||||
/// \param filename name of a sound file in the data directory.
|
/// \param filename name of a sound file in the data directory.
|
||||||
/// \param type music type.
|
/// \param type music type.
|
||||||
|
|
|
@ -186,11 +186,10 @@ VFS::Path::Normalized Misc::ResourceHelpers::correctSoundPath(VFS::Path::Normali
|
||||||
return prefix / resPath;
|
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/");
|
static constexpr VFS::Path::NormalizedView prefix("music");
|
||||||
result += resPath;
|
return prefix / resPath;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view Misc::ResourceHelpers::meshPathForESM3(std::string_view resPath)
|
std::string_view Misc::ResourceHelpers::meshPathForESM3(std::string_view resPath)
|
||||||
|
|
|
@ -38,11 +38,11 @@ namespace Misc
|
||||||
// Adds "meshes\\".
|
// Adds "meshes\\".
|
||||||
std::string correctMeshPath(std::string_view resPath);
|
std::string correctMeshPath(std::string_view resPath);
|
||||||
|
|
||||||
// Adds "sound\\".
|
// Prepends "sound/".
|
||||||
VFS::Path::Normalized correctSoundPath(VFS::Path::NormalizedView resPath);
|
VFS::Path::Normalized correctSoundPath(VFS::Path::NormalizedView resPath);
|
||||||
|
|
||||||
// Adds "music\\".
|
// Prepends "music/".
|
||||||
std::string correctMusicPath(std::string_view resPath);
|
VFS::Path::Normalized correctMusicPath(VFS::Path::NormalizedView resPath);
|
||||||
|
|
||||||
// Removes "meshes\\".
|
// Removes "meshes\\".
|
||||||
std::string_view meshPathForESM3(std::string_view resPath);
|
std::string_view meshPathForESM3(std::string_view resPath);
|
||||||
|
|
Loading…
Reference in a new issue