]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATCDCL/ATC.cxx
Remove confusing default (missing) path from 2D panel code.
[flightgear.git] / src / ATCDCL / ATC.cxx
index 9a8d1602882b10df304608c9d55e3b3f05198989..10fb8971545d1b770ee226d835043493bfa6bf16 100644 (file)
@@ -25,7 +25,6 @@
 #include "ATC.hxx"
 
 #include <iostream>
-#include <memory>
 
 #include <simgear/sound/soundmgr_openal.hxx>
 #include <simgear/structure/exception.hxx>
@@ -36,6 +35,7 @@
 
 
 FGATC::FGATC() :
+       _playing(false),
        _voiceOK(false),
        _sgr(NULL),
        freqClear(true),
@@ -57,9 +57,14 @@ FGATC::FGATC() :
        _counter(0.0),
        _max_count(5.0)
 {
-       SGSoundMgr *smgr;
-       smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
+       SGSoundMgr *smgr = globals->get_soundmgr();
        _sgr = smgr->find("atc", true);
+        _sgr->tie_to_listener();
+
+       _volume = fgGetNode("/sim/sound/atc/volume", true);
+       _enabled = fgGetNode("/sim/sound/atc/enabled", true);
+       _atc_external = fgGetNode("/sim/sound/atc/external-view", true);
+       _internal = fgGetNode("/sim/current-view/internal", true);
 }
 
 FGATC::~FGATC() {
@@ -108,6 +113,18 @@ void FGATC::Update(double dt) {
                }
        }
 
+#ifdef ENABLE_AUDIO_SUPPORT
+       bool active = _atc_external->getBoolValue() ||
+                     _internal->getBoolValue();
+
+       if ( active && _enabled->getBoolValue() ) {
+               _sgr->set_volume( _volume->getFloatValue() );
+               _sgr->resume(); // no-op if already in resumed state
+       } else {
+               _sgr->suspend();
+       }
+#endif
+
        if(_transmit) {
                _counter = 0.0;
                _max_count = 5.0;               // FIXME - hardwired length of message - need to calculate it!
@@ -223,6 +240,8 @@ void FGATC::SetData(ATCData* d) {
 // The repeating flag indicates whether the message should be repeated continuously or played once.
 void FGATC::Render(string& msg, const float volume, 
                                   const string& refname, const bool repeating) {
+       if (volume < 0.05) return;
+
        if (repeating)
                fgSetString("/sim/messages/atis", msg.c_str());
        else
@@ -231,18 +250,15 @@ void FGATC::Render(string& msg, const float volume,
 #ifdef ENABLE_AUDIO_SUPPORT
        _voice = (_voiceOK && fgGetBool("/sim/sound/voice"));
        if(_voice) {
-               string buf = _vPtr->WriteMessage((char*)msg.c_str(), _voice);
-               if(_voice && (volume > 0.05)) {
+               size_t len;
+               void* buf = _vPtr->WriteMessage((char*)msg.c_str(), &len);
+               if(buf) {
                        NoRender(refname);
                        try {
 // >>> Beware: must pass a (new) object to the (add) method,
 // >>> because the (remove) method is going to do a (delete)
 // >>> whether that's what you want or not.
-                               std::auto_ptr<unsigned char> ptr( (unsigned char*)buf.c_str() );
-                               SGSoundSample *simple = 
-                                   new SGSoundSample(ptr,  buf.length(), 8000);
-                               // TODO - at the moment the volume can't be changed 
-                               // after the transmission has started.
+                               SGSoundSample *simple = new SGSoundSample(&buf, len, 8000);
                                simple->set_volume(volume);
                                _sgr->add(simple, refname);
                                _sgr->play(refname, repeating);
@@ -327,7 +343,7 @@ std::istream& operator >> ( std::istream& fin, ATCData& a )
        }
        
        double lat, lon, elev;
-  
+
        fin >> lat >> lon >> elev >> f >> a.range >> a.ident;
        a.geod = SGGeod::fromDegM(lon, lat, elev);
        a.name = "";