Music Player

actorid
Jason Hooks 14 years ago
parent 13d8ea09b0
commit 74aba13053

@ -57,8 +57,42 @@ void OMW::Engine::executeLocalScripts()
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)
{
//
MWWorld::Environment test = mEnvironment;
if(! (test.mSoundManager->isMusicPlaying()))
{
// Play some good 'ol tunes
startRandomTitle();
}
//tesprintf("HERE");t.mSoundManager.
try
{
mEnvironment.mFrameDuration = evt.timeSinceLastFrame;
@ -216,6 +250,8 @@ void OMW::Engine::go()
assert (!mCellName.empty());
assert (!mMaster.empty());
std::cout << "Data directory: " << mDataDir << "\n";
const char* plugCfg = "plugins.cfg";
@ -293,16 +329,7 @@ void OMW::Engine::go()
mOgre.getRoot()->addFrameListener (this);
// Play some good 'ol tunes
std::string music = (mDataDir / "Music/Explore/mx_explore_5.mp3").file_string();
try
{
std::cout << "Playing " << music << "\n";
mEnvironment.mSoundManager->streamMusic(music);
}
catch(std::exception &e)
{
std::cout << " Music Error: " << e.what() << "\n";
}
startRandomTitle();
// Start the main rendering loop
mOgre.start();

@ -62,6 +62,7 @@ namespace MWSound
sounds based on the sound factory it is given.
*/
OEManagerPtr mgr;
SoundPtr music;
/* This class calls update() on the sound manager each frame
using and Ogre::FrameListener
@ -319,6 +320,20 @@ namespace MWSound
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)
{
// The range values are not tested
@ -342,10 +357,13 @@ namespace MWSound
// Play the sound and tell it to stream, if possible. TODO:
// Store the reference, the jukebox will need to check status,
// control volume etc.
SoundPtr music = mData->mgr->load(filename);
music->setStreaming(true);
music->setVolume(0.4);
music->play();
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)

@ -5,6 +5,7 @@
#include <map>
#include "../mwworld/ptr.hpp"
#include <openengine/sound/sndmanager.hpp>
namespace Ogre
{
@ -19,17 +20,24 @@ namespace ESMS
namespace MWSound
{
//SoundPtr *music;
class SoundManager
{
// Hide implementation details - engine.cpp is compiling
// enough as it is.
struct SoundImpl;
SoundImpl *mData;
public:
SoundManager(Ogre::Root*, Ogre::Camera*, const ESMS::ESMStore &store,
const std::string &soundDir, bool useSound);
~SoundManager();
//struct SoundImpl;
bool isMusicPlaying();
SoundImpl getMData();
void say (MWWorld::Ptr reference, const std::string& filename);
///< Make an actor say some text.

Loading…
Cancel
Save