forked from mirror/openmw-tes3mp
streammusic strict
This commit is contained in:
parent
9eefee7168
commit
2fe66319fe
2 changed files with 85 additions and 43 deletions
|
@ -87,15 +87,18 @@ namespace MWSound
|
||||||
bool FSstrict;
|
bool FSstrict;
|
||||||
FileFinder::FileFinder files;
|
FileFinder::FileFinder files;
|
||||||
FileFinder::FileFinderStrict strict;
|
FileFinder::FileFinderStrict strict;
|
||||||
|
FileFinder::FileFinder musicpath;
|
||||||
|
FileFinder::FileFinderStrict musicpathStrict;
|
||||||
|
|
||||||
SoundImpl(Ogre::Root *root, Ogre::Camera *camera,
|
SoundImpl(Ogre::Root *root, Ogre::Camera *camera,
|
||||||
const ESMS::ESMStore &str,
|
const ESMS::ESMStore &str,
|
||||||
const std::string &soundDir, bool fsstrict)
|
const std::string &soundDir, const std::string &musicDir, bool fsstrict)
|
||||||
: mgr(new OEManager(SoundFactoryPtr(new SOUND_FACTORY)))
|
: mgr(new OEManager(SoundFactoryPtr(new SOUND_FACTORY)))
|
||||||
, updater(mgr)
|
, updater(mgr)
|
||||||
, cameraTracker(mgr)
|
, cameraTracker(mgr)
|
||||||
, store(str)
|
, store(str)
|
||||||
, files(soundDir), strict(soundDir)
|
, files(soundDir), strict(soundDir)
|
||||||
|
,musicpath(musicDir), musicpathStrict(musicDir)
|
||||||
{
|
{
|
||||||
FSstrict = fsstrict;
|
FSstrict = fsstrict;
|
||||||
cout << "Sound output: " << SOUND_OUT << endl;
|
cout << "Sound output: " << SOUND_OUT << endl;
|
||||||
|
@ -113,6 +116,8 @@ namespace MWSound
|
||||||
cameraTracker.unfollowCamera();
|
cameraTracker.unfollowCamera();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static std::string toMp3(std::string str)
|
static std::string toMp3(std::string str)
|
||||||
{
|
{
|
||||||
std::string::size_type i = str.rfind('.');
|
std::string::size_type i = str.rfind('.');
|
||||||
|
@ -124,44 +129,70 @@ namespace MWSound
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasFile(const std::string &str)
|
bool hasFile(const std::string &str, bool music = false)
|
||||||
{
|
{
|
||||||
if(FSstrict == false){
|
if(FSstrict == false){
|
||||||
if(files.has(str)) return true;
|
if(music){
|
||||||
// Not found? Try with .mp3
|
if(musicpath.has(str)) return true;
|
||||||
return files.has(toMp3(str));
|
// Not found? Try with .mp3
|
||||||
|
return musicpath.has(toMp3(str));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(files.has(str)) return true;
|
||||||
|
return files.has(toMp3(str));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(music){
|
||||||
|
if(musicpathStrict.has(str)) return true;
|
||||||
|
// Not found? Try with .mp3
|
||||||
|
return musicpathStrict.has(toMp3(str));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(strict.has(str)) return true;
|
||||||
|
return strict.has(toMp3(str));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
|
||||||
if(strict.has(str)) return true;
|
|
||||||
// Not found? Try with .mp3
|
|
||||||
return files.has(toMp3(str));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert a Morrowind sound path (eg. Fx\funny.wav) to full path
|
// Convert a Morrowind sound path (eg. Fx\funny.wav) to full path
|
||||||
// with proper slash conversion (eg. datadir/Sound/Fx/funny.wav)
|
// with proper slash conversion (eg. datadir/Sound/Fx/funny.wav)
|
||||||
std::string convertPath(const std::string &str)
|
std::string convertPath(const std::string &str, bool music = false)
|
||||||
{
|
{
|
||||||
if(FSstrict == false){
|
if(FSstrict == false){
|
||||||
// Search and return
|
// Search and return
|
||||||
if(files.has(str))
|
if(music && musicpath.has(str))
|
||||||
return files.lookup(str);
|
return musicpath.lookup(str);
|
||||||
|
else if(files.has(str))
|
||||||
|
return files.lookup(str);
|
||||||
|
|
||||||
|
|
||||||
// Try mp3 if the wav wasn't found
|
// Try mp3 if the wav wasn't found
|
||||||
std::string mp3 = toMp3(str);
|
std::string mp3 = toMp3(str);
|
||||||
if(files.has(mp3))
|
if(music && musicpath.has(mp3))
|
||||||
return files.lookup(mp3);
|
return musicpath.lookup(mp3);
|
||||||
|
else if(files.has(mp3))
|
||||||
|
return files.lookup(mp3);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(files.has(str))
|
if(music && musicpathStrict.has(str))
|
||||||
return files.lookup(str);
|
return musicpathStrict.lookup(str);
|
||||||
|
else if(strict.has(str))
|
||||||
|
return strict.lookup(str);
|
||||||
|
|
||||||
// Try mp3 if the wav wasn't found
|
|
||||||
std::string mp3 = toMp3(str);
|
// Try mp3 if the wav wasn't found
|
||||||
if(files.has(mp3))
|
std::string mp3 = toMp3(str);
|
||||||
return files.lookup(mp3);
|
if(music && musicpathStrict.has(mp3))
|
||||||
|
return musicpathStrict.lookup(mp3);
|
||||||
|
else if(strict.has(str))
|
||||||
|
return strict.lookup(mp3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Give up
|
// Give up
|
||||||
|
@ -326,6 +357,22 @@ namespace MWSound
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void SoundManager::streamMusicFull (const std::string& filename)
|
||||||
|
{
|
||||||
|
if(!mData) return;
|
||||||
|
|
||||||
|
// Play the sound and tell it to stream, if possible. TODO:
|
||||||
|
// Store the reference, the jukebox will need to check status,
|
||||||
|
// control volume etc.
|
||||||
|
if (mData->music)
|
||||||
|
mData->music->stop();
|
||||||
|
mData->music = mData->mgr->load(filename);
|
||||||
|
mData->music->setStreaming(true);
|
||||||
|
mData->music->setVolume(0.4);
|
||||||
|
mData->music->play();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
SoundManager::SoundManager(Ogre::Root *root, Ogre::Camera *camera,
|
SoundManager::SoundManager(Ogre::Root *root, Ogre::Camera *camera,
|
||||||
const ESMS::ESMStore &store,
|
const ESMS::ESMStore &store,
|
||||||
boost::filesystem::path dataDir,
|
boost::filesystem::path dataDir,
|
||||||
|
@ -335,7 +382,7 @@ namespace MWSound
|
||||||
fsStrict = fsstrict;
|
fsStrict = fsstrict;
|
||||||
MP3Lookup(dataDir / "Music/Explore/");
|
MP3Lookup(dataDir / "Music/Explore/");
|
||||||
if(useSound)
|
if(useSound)
|
||||||
mData = new SoundImpl(root, camera, store, (dataDir / "Sound").string(), fsstrict);
|
mData = new SoundImpl(root, camera, store, (dataDir / "Sound").string(), (dataDir / "Music").string(), fsstrict);
|
||||||
}
|
}
|
||||||
|
|
||||||
SoundManager::~SoundManager()
|
SoundManager::~SoundManager()
|
||||||
|
@ -344,6 +391,15 @@ namespace MWSound
|
||||||
delete mData;
|
delete mData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SoundManager::streamMusic(const std::string& filename){
|
||||||
|
if(mData->hasFile(filename, true))
|
||||||
|
{
|
||||||
|
std::string fullpath = mData->convertPath(filename, true);
|
||||||
|
streamMusicFull(fullpath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SoundManager::MP3Lookup(boost::filesystem::path dir)
|
void SoundManager::MP3Lookup(boost::filesystem::path dir)
|
||||||
{
|
{
|
||||||
boost::filesystem::directory_iterator dir_iter(dir), dir_end;
|
boost::filesystem::directory_iterator dir_iter(dir), dir_end;
|
||||||
|
@ -376,7 +432,7 @@ namespace MWSound
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
std::cout << "Playing " << music << "\n";
|
std::cout << "Playing " << music << "\n";
|
||||||
streamMusic(music);
|
streamMusicFull(music);
|
||||||
}
|
}
|
||||||
catch(std::exception &e)
|
catch(std::exception &e)
|
||||||
{
|
{
|
||||||
|
@ -420,22 +476,7 @@ namespace MWSound
|
||||||
return !mData->isPlaying(ptr, "_say_sound");
|
return !mData->isPlaying(ptr, "_say_sound");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundManager::streamMusic (const std::string& filename)
|
|
||||||
{
|
|
||||||
if(!mData) return;
|
|
||||||
|
|
||||||
// Play the sound and tell it to stream, if possible. TODO:
|
|
||||||
// Store the reference, the jukebox will need to check status,
|
|
||||||
// control volume etc.
|
|
||||||
if (mData->music)
|
|
||||||
mData->music->stop();
|
|
||||||
mData->music = mData->mgr->load(filename);
|
|
||||||
mData->music->setStreaming(true);
|
|
||||||
mData->music->setVolume(0.4);
|
|
||||||
mData->music->play();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void SoundManager::playSound (const std::string& soundId, float volume, float pitch)
|
void SoundManager::playSound (const std::string& soundId, float volume, float pitch)
|
||||||
{
|
{
|
||||||
if(!mData) return;
|
if(!mData) return;
|
||||||
|
|
|
@ -31,6 +31,9 @@ namespace MWSound
|
||||||
SoundImpl *mData;
|
SoundImpl *mData;
|
||||||
std::vector<boost::filesystem::path> files;
|
std::vector<boost::filesystem::path> files;
|
||||||
bool fsStrict;
|
bool fsStrict;
|
||||||
|
void streamMusicFull (const std::string& filename);
|
||||||
|
///< Play a soundifle
|
||||||
|
/// \param filename name of a sound file in "Music/" in the data directory.
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -39,7 +42,7 @@ namespace MWSound
|
||||||
boost::filesystem::path dataDir, bool useSound, bool fsstrict);
|
boost::filesystem::path dataDir, bool useSound, bool fsstrict);
|
||||||
~SoundManager();
|
~SoundManager();
|
||||||
|
|
||||||
|
void streamMusic(const std::string& filename);
|
||||||
void startRandomTitle();
|
void startRandomTitle();
|
||||||
void MP3Lookup(boost::filesystem::path dir);
|
void MP3Lookup(boost::filesystem::path dir);
|
||||||
//struct SoundImpl;
|
//struct SoundImpl;
|
||||||
|
@ -54,9 +57,7 @@ namespace MWSound
|
||||||
bool sayDone (MWWorld::Ptr reference) const;
|
bool sayDone (MWWorld::Ptr reference) const;
|
||||||
///< Is actor not speaking?
|
///< Is actor not speaking?
|
||||||
|
|
||||||
void streamMusic (const std::string& filename);
|
|
||||||
///< Play a soundifle
|
|
||||||
/// \param filename name of a sound file in "Music/" in the data directory.
|
|
||||||
|
|
||||||
void playSound (const std::string& soundId, float volume, float pitch);
|
void playSound (const std::string& soundId, float volume, float pitch);
|
||||||
///< Play a sound, independently of 3D-position
|
///< Play a sound, independently of 3D-position
|
||||||
|
|
Loading…
Reference in a new issue