]> git.mxchange.org Git - flightgear.git/commitdiff
Make the sound-manager optional in a few places.
authorJames Turner <zakalawe@mac.com>
Mon, 1 Oct 2012 09:10:34 +0000 (10:10 +0100)
committerJames Turner <zakalawe@mac.com>
Mon, 1 Oct 2012 09:10:34 +0000 (10:10 +0100)
src/AIModel/AIBase.cxx
src/Main/fg_commands.cxx
src/Model/acmodel.cxx
src/Sound/fg_fx.cxx
src/Sound/fg_fx.hxx
src/Sound/voiceplayer.cxx
src/Sound/voiceplayer.hxx

index a17b9e47602b7ec8d1979f0bbf805d8e2360d448..7cfcfcb0a33418517ff24f767da13d599e186191 100644 (file)
@@ -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();
             }
         }
index 92bdea7c041c1dc65b6d31f3c4b0e778d48b8423..e5d72f8a923fa5ef0cf1b6082cc96291280b6d11 100644 (file)
@@ -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();
         }
index af75fd8be8992441f55f3f06d97fdf466c074ac3..41967c6da06adad56c61ff11ebad6bb8151b0e02 100644 (file)
@@ -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();
 }
 
index be9378c73d19441d60eb5acd876b3d0ce3c3391e..42b622108aa4f060c09130e78a66304ded142c96 100644 (file)
@@ -32,6 +32,7 @@
 #include "fg_fx.hxx"
 
 #include <Main/fg_props.hxx>
+#include <Main/globals.hxx>
 
 #include <simgear/props/props.hxx>
 #include <simgear/props/props_io.hxx>
@@ -39,7 +40,7 @@
 #include <simgear/sound/soundmgr_openal.hxx>
 #include <simgear/sound/xmlsound.hxx>
 
-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())
         {
index 81fac4f72b6f9fdb8ff443c79125f72d68fed867..7d5132dd9e2a9c85a80fc4ba97f423b03ddab104 100644 (file)
@@ -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 ();
index de178b70e7fdf04e8c1a13444fc7598ea99fe07e..6e12b083dab3eeebf320346a1b80349e418a4ca8 100644 (file)
@@ -65,6 +65,12 @@ using std::vector;
 // FGVoicePlayer::Voice::SampleElement ///////////////////////////
 /////////////////////////////////////////////////////////////////////////
 
+FGVoicePlayer::Voice::SampleElement::SampleElement (SGSharedPtr<SGSoundSample> 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)));
+}
+
index be5e7765b00f73aeab8f0cde0991e4819aa2e5ed..90e3cbac9b04bb3a39e3ce9224f1904cfae8558f 100644 (file)
@@ -149,9 +149,8 @@ public:
         float               _volume;
 
     public:
-        SampleElement (SGSharedPtr<SGSoundSample> sample, float volume = 1.0)
-          : _sample(sample), _volume(volume) { silence = false; }
-
+        SampleElement (SGSharedPtr<SGSoundSample> 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); }