From: James Turner Date: Mon, 1 Oct 2012 09:10:34 +0000 (+0100) Subject: Make the sound-manager optional in a few places. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=bcea720db3e29a62626b361f2149a7147e149f3b;p=flightgear.git Make the sound-manager optional in a few places. --- diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index a17b9e476..7cfcfcb0a 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -143,12 +143,17 @@ FGAIBase::~FGAIBase() { model_removed->setStringValue(props->getPath()); } + // refID=0 is supposedley impossible, refID=1 is the special ai_ac aircaft + // representing the current user, in the ATCManager. Maybe both these + // tests could die? if (_fx && _refID != 0 && _refID != 1) { SGSoundMgr *smgr = globals->get_soundmgr(); - stringstream name; - name << "aifx:"; - name << _refID; - smgr->remove(name.str()); + if (smgr) { + stringstream name; + name << "aifx:"; + name << _refID; + smgr->remove(name.str()); + } } if (fp) @@ -245,11 +250,10 @@ void FGAIBase::update(double dt) { props->setStringValue("sim/sound/path", fxpath.c_str()); // initialize the sound configuration - SGSoundMgr *smgr = globals->get_soundmgr(); stringstream name; name << "aifx:"; name << _refID; - _fx = new FGFX(smgr, name.str(), props); + _fx = new FGFX(name.str(), props); _fx->init(); } } diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 92bdea7c0..e5d72f8a9 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -1106,6 +1106,12 @@ do_set_cursor (const SGPropertyNode * arg) static bool do_play_audio_sample (const SGPropertyNode * arg) { + SGSoundMgr *smgr = globals->get_soundmgr(); + if (!smgr) { + SG_LOG(SG_GENERAL, SG_WARN, "play-audio-sample: sound-manager not running"); + return false; + } + string path = arg->getStringValue("path"); string file = arg->getStringValue("file"); float volume = arg->getFloatValue("volume"); @@ -1113,7 +1119,6 @@ do_play_audio_sample (const SGPropertyNode * arg) try { static FGSampleQueue *queue = 0; if ( !queue ) { - SGSoundMgr *smgr = globals->get_soundmgr(); queue = new FGSampleQueue(smgr, "chatter"); queue->tie_to_listener(); } diff --git a/src/Model/acmodel.cxx b/src/Model/acmodel.cxx index af75fd8be..41967c6da 100644 --- a/src/Model/acmodel.cxx +++ b/src/Model/acmodel.cxx @@ -48,8 +48,7 @@ FGAircraftModel::FGAircraftModel () _speed_e(0), _speed_d(0) { - SGSoundMgr *smgr = globals->get_soundmgr(); - _fx = new FGFX(smgr, "fx"); + _fx = new FGFX("fx"); _fx->init(); } diff --git a/src/Sound/fg_fx.cxx b/src/Sound/fg_fx.cxx index be9378c73..42b622108 100644 --- a/src/Sound/fg_fx.cxx +++ b/src/Sound/fg_fx.cxx @@ -32,6 +32,7 @@ #include "fg_fx.hxx" #include
+#include
#include #include @@ -39,7 +40,7 @@ #include #include -FGFX::FGFX ( SGSoundMgr *smgr, const std::string &refname, SGPropertyNode *props ) : +FGFX::FGFX ( const std::string &refname, SGPropertyNode *props ) : _props( props ) { if (!props) { @@ -60,6 +61,11 @@ FGFX::FGFX ( SGSoundMgr *smgr, const std::string &refname, SGPropertyNode *props _avionics_ext = _props->getNode("sim/sound/avionics/external-view", true); _internal = _props->getNode("sim/current-view/internal", true); + SGSoundMgr *smgr = globals->get_soundmgr(); + if (!smgr) { + return; + } + SGSampleGroup::_smgr = smgr; SGSampleGroup::_refname = refname; SGSampleGroup::_smgr->add(this, refname); @@ -84,6 +90,10 @@ FGFX::~FGFX () void FGFX::init() { + if (!_smgr) { + return; + } + SGPropertyNode *node = _props->getNode("sim/sound", true); std::string path_str = node->getStringValue("path"); @@ -143,6 +153,10 @@ FGFX::reinit() void FGFX::update (double dt) { + if (!_smgr) { + return; + } + if ( _enabled->getBoolValue() ) { if ( _avionics_enabled->getBoolValue()) { diff --git a/src/Sound/fg_fx.hxx b/src/Sound/fg_fx.hxx index 81fac4f72..7d5132dd9 100644 --- a/src/Sound/fg_fx.hxx +++ b/src/Sound/fg_fx.hxx @@ -49,7 +49,7 @@ class FGFX : public SGSampleGroup public: - FGFX ( SGSoundMgr *smgr, const std::string &refname, SGPropertyNode *props = 0 ); + FGFX ( const std::string &refname, SGPropertyNode *props = 0 ); virtual ~FGFX (); virtual void init (); diff --git a/src/Sound/voiceplayer.cxx b/src/Sound/voiceplayer.cxx index de178b70e..6e12b083d 100644 --- a/src/Sound/voiceplayer.cxx +++ b/src/Sound/voiceplayer.cxx @@ -65,6 +65,12 @@ using std::vector; // FGVoicePlayer::Voice::SampleElement /////////////////////////// ///////////////////////////////////////////////////////////////////////// +FGVoicePlayer::Voice::SampleElement::SampleElement (SGSharedPtr sample, float volume) +: _sample(sample), _volume(volume) +{ + silence = false; +} + void FGVoicePlayer::Voice::SampleElement::play (float volume) { if (_sample && (volume > 0.05)) { set_volume(volume); _sample->play_once(); } @@ -179,7 +185,9 @@ FGVoicePlayer::FGVoicePlayer (PropertiesHandler* properties_handler, string _dev : volume(1.0), voice(NULL), next_voice(NULL), paused(false), dev_name(_dev_name), dir_prefix(""), speaker(this,properties_handler) -{} +{ + _sgr = NULL; +} FGVoicePlayer::~FGVoicePlayer () { @@ -339,3 +347,10 @@ FGVoicePlayer::update () } } } + +void +FGVoicePlayer::append (Voice *voice, const char *sample_name) +{ + voice->append(new Voice::SampleElement(get_sample(sample_name))); +} + diff --git a/src/Sound/voiceplayer.hxx b/src/Sound/voiceplayer.hxx index be5e7765b..90e3cbac9 100644 --- a/src/Sound/voiceplayer.hxx +++ b/src/Sound/voiceplayer.hxx @@ -149,9 +149,8 @@ public: float _volume; public: - SampleElement (SGSharedPtr sample, float volume = 1.0) - : _sample(sample), _volume(volume) { silence = false; } - + SampleElement (SGSharedPtr sample, float volume = 1.0); + virtual void play (float volume); virtual void stop (); virtual bool is_playing (); @@ -311,7 +310,7 @@ protected: SGSoundSample *get_sample (const char *name); inline void append (Voice *voice, Voice::Element *element) { voice->append(element); } - inline void append (Voice *voice, const char *sample_name) { voice->append(new Voice::SampleElement(get_sample(sample_name))); } + void append (Voice *voice, const char *sample_name); inline void append (Voice *voice, double silence) { voice->append(new Voice::SilenceElement(silence)); } inline void make_voice (Voice **voice) { *voice = new Voice(this); _voices.push_back(*voice); }