mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-29 16:06:44 +00:00
Music Player
This commit is contained in:
parent
13d8ea09b0
commit
74aba13053
3 changed files with 67 additions and 14 deletions
|
@ -57,8 +57,42 @@ void OMW::Engine::executeLocalScripts()
|
||||||
mIgnoreLocalPtr = MWWorld::Ptr();
|
mIgnoreLocalPtr = MWWorld::Ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OMW::Engine::startRandomTitle()
|
||||||
|
{
|
||||||
|
char number[100];
|
||||||
|
/* initialize random seed: */
|
||||||
|
srand ( time(NULL) );
|
||||||
|
|
||||||
|
/* generate secret number: */
|
||||||
|
int r = rand() % 7 + 1;
|
||||||
|
|
||||||
|
sprintf(number, "Music/Explore/mx_explore_%d.mp3", r);
|
||||||
|
//std::string music = (mDataDir / "Music/Explore/mx_explore_5.mp3").file_string();
|
||||||
|
std::string music = (mDataDir / number).file_string();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::cout << "Playing " << music << "\n";
|
||||||
|
mEnvironment.mSoundManager->streamMusic(music);
|
||||||
|
}
|
||||||
|
catch(std::exception &e)
|
||||||
|
{
|
||||||
|
std::cout << " Music Error: " << e.what() << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt)
|
bool OMW::Engine::frameStarted(const Ogre::FrameEvent& evt)
|
||||||
{
|
{
|
||||||
|
//
|
||||||
|
MWWorld::Environment test = mEnvironment;
|
||||||
|
if(! (test.mSoundManager->isMusicPlaying()))
|
||||||
|
{
|
||||||
|
// Play some good 'ol tunes
|
||||||
|
startRandomTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
//tesprintf("HERE");t.mSoundManager.
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
mEnvironment.mFrameDuration = evt.timeSinceLastFrame;
|
mEnvironment.mFrameDuration = evt.timeSinceLastFrame;
|
||||||
|
@ -216,6 +250,8 @@ void OMW::Engine::go()
|
||||||
assert (!mCellName.empty());
|
assert (!mCellName.empty());
|
||||||
assert (!mMaster.empty());
|
assert (!mMaster.empty());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::cout << "Data directory: " << mDataDir << "\n";
|
std::cout << "Data directory: " << mDataDir << "\n";
|
||||||
|
|
||||||
const char* plugCfg = "plugins.cfg";
|
const char* plugCfg = "plugins.cfg";
|
||||||
|
@ -293,16 +329,7 @@ void OMW::Engine::go()
|
||||||
mOgre.getRoot()->addFrameListener (this);
|
mOgre.getRoot()->addFrameListener (this);
|
||||||
|
|
||||||
// Play some good 'ol tunes
|
// Play some good 'ol tunes
|
||||||
std::string music = (mDataDir / "Music/Explore/mx_explore_5.mp3").file_string();
|
startRandomTitle();
|
||||||
try
|
|
||||||
{
|
|
||||||
std::cout << "Playing " << music << "\n";
|
|
||||||
mEnvironment.mSoundManager->streamMusic(music);
|
|
||||||
}
|
|
||||||
catch(std::exception &e)
|
|
||||||
{
|
|
||||||
std::cout << " Music Error: " << e.what() << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start the main rendering loop
|
// Start the main rendering loop
|
||||||
mOgre.start();
|
mOgre.start();
|
||||||
|
|
|
@ -62,6 +62,7 @@ namespace MWSound
|
||||||
sounds based on the sound factory it is given.
|
sounds based on the sound factory it is given.
|
||||||
*/
|
*/
|
||||||
OEManagerPtr mgr;
|
OEManagerPtr mgr;
|
||||||
|
SoundPtr music;
|
||||||
|
|
||||||
/* This class calls update() on the sound manager each frame
|
/* This class calls update() on the sound manager each frame
|
||||||
using and Ogre::FrameListener
|
using and Ogre::FrameListener
|
||||||
|
@ -319,6 +320,20 @@ namespace MWSound
|
||||||
delete mData;
|
delete mData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SoundManager::isMusicPlaying()
|
||||||
|
{
|
||||||
|
bool test = mData->music->isPlaying();
|
||||||
|
return test;
|
||||||
|
}
|
||||||
|
|
||||||
|
SoundManager::SoundImpl SoundManager::getMData()
|
||||||
|
{
|
||||||
|
// bool test = mData->music->isPlaying();
|
||||||
|
return *mData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void SoundManager::say (MWWorld::Ptr ptr, const std::string& filename)
|
void SoundManager::say (MWWorld::Ptr ptr, const std::string& filename)
|
||||||
{
|
{
|
||||||
// The range values are not tested
|
// The range values are not tested
|
||||||
|
@ -342,10 +357,13 @@ namespace MWSound
|
||||||
// Play the sound and tell it to stream, if possible. TODO:
|
// Play the sound and tell it to stream, if possible. TODO:
|
||||||
// Store the reference, the jukebox will need to check status,
|
// Store the reference, the jukebox will need to check status,
|
||||||
// control volume etc.
|
// control volume etc.
|
||||||
SoundPtr music = mData->mgr->load(filename);
|
if (mData->music)
|
||||||
music->setStreaming(true);
|
mData->music->stop();
|
||||||
music->setVolume(0.4);
|
mData->music = mData->mgr->load(filename);
|
||||||
music->play();
|
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)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
#include "../mwworld/ptr.hpp"
|
#include "../mwworld/ptr.hpp"
|
||||||
|
#include <openengine/sound/sndmanager.hpp>
|
||||||
|
|
||||||
namespace Ogre
|
namespace Ogre
|
||||||
{
|
{
|
||||||
|
@ -19,17 +20,24 @@ namespace ESMS
|
||||||
|
|
||||||
namespace MWSound
|
namespace MWSound
|
||||||
{
|
{
|
||||||
|
//SoundPtr *music;
|
||||||
class SoundManager
|
class SoundManager
|
||||||
{
|
{
|
||||||
// Hide implementation details - engine.cpp is compiling
|
// Hide implementation details - engine.cpp is compiling
|
||||||
// enough as it is.
|
// enough as it is.
|
||||||
struct SoundImpl;
|
struct SoundImpl;
|
||||||
|
|
||||||
SoundImpl *mData;
|
SoundImpl *mData;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SoundManager(Ogre::Root*, Ogre::Camera*, const ESMS::ESMStore &store,
|
SoundManager(Ogre::Root*, Ogre::Camera*, const ESMS::ESMStore &store,
|
||||||
const std::string &soundDir, bool useSound);
|
const std::string &soundDir, bool useSound);
|
||||||
~SoundManager();
|
~SoundManager();
|
||||||
|
//struct SoundImpl;
|
||||||
|
bool isMusicPlaying();
|
||||||
|
|
||||||
|
SoundImpl getMData();
|
||||||
|
|
||||||
void say (MWWorld::Ptr reference, const std::string& filename);
|
void say (MWWorld::Ptr reference, const std::string& filename);
|
||||||
///< Make an actor say some text.
|
///< Make an actor say some text.
|
||||||
|
|
Loading…
Reference in a new issue