]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATCDCL/ATC.cxx
Merge branch 'next' into navaids-radio
[flightgear.git] / src / ATCDCL / ATC.cxx
index 7e17f1da79775f0fd936eb614af0eaa8661c16ad..776ec34419e1a433d1aba6fbf8e6def7c0ebec3d 100644 (file)
 
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
-
-
+#include <ATC/CommStation.hxx>
+#include <Airports/simple.hxx>
 
 FGATC::FGATC() :
+       _playing(false),
        _voiceOK(false),
        _sgr(NULL),
        freqClear(true),
@@ -50,7 +51,6 @@ FGATC::FGATC() :
        pending_transmission(""),
        _timeout(0),
        _pending(false),
-       _callback_code(0),
        _transmit(false),
        _transmitting(false),
        _counter(0.0),
@@ -58,6 +58,12 @@ FGATC::FGATC() :
 {
        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() {
@@ -106,6 +112,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!
@@ -115,11 +133,6 @@ void FGATC::Update(double dt) {
                        //Render(pending_transmission, ident, false);
                        Render(pending_transmission);
                }
-               // Run the callback regardless of whether on same freq as user or not.
-               //cout << "_callback_code = " << _callback_code << '\n';
-               if(_callback_code) {
-                       ProcessCallback(_callback_code);
-               }
                _transmit = false;
                _transmitting = true;
        } else if(_transmitting) {
@@ -168,51 +181,20 @@ void FGATC::NotifyTransmissionFinished(const string& rid) {
        }
 }
 
-void FGATC::Transmit(int callback_code) {
-       SG_LOG(SG_ATC, SG_INFO, "Transmit called by " << ident << " " << _type << ", msg = " << pending_transmission);
-       _pending = true;
-       _callback_code = callback_code;
-       _timeout = 0.0;
-}
-
-void FGATC::ConditionalTransmit(double timeout, int callback_code) {
-       SG_LOG(SG_ATC, SG_INFO, "Timed transmit called by " << ident << " " << _type << ", msg = " << pending_transmission);
-       _pending = true;
-       _callback_code = callback_code;
-       _timeout = timeout;
-}
-
-void FGATC::ImmediateTransmit(int callback_code) {
-       SG_LOG(SG_ATC, SG_INFO, "Immediate transmit called by " << ident << " " << _type << ", msg = " << pending_transmission);
-       if(_display) {
-               //Render(pending_transmission, ident, false);
-               Render(pending_transmission);
-               // At the moment Render doesn't work except for ATIS
-       }
-       if(callback_code) {
-               ProcessCallback(callback_code);
-       }
-}
-
-// Derived classes should override this.
-void FGATC::ProcessCallback(int code) {
-}
-
-void FGATC::AddPlane(const string& pid) {
-}
-
-int FGATC::RemovePlane() {
-       return 0;
-}
-
-void FGATC::SetData(ATCData* d) {
-       _type = d->type;
-       _geod = d->geod;
-       _cart = d->cart;
-       range = d->range;
-       ident = d->ident;
-       name = d->name;
-       freq = d->freq;
+void FGATC::SetStation(flightgear::CommStation* sta) {
+    switch (sta->type()) {
+        case FGPositioned::FREQ_ATIS:   _type = ATIS; break;
+        case FGPositioned::FREQ_AWOS:   _type = AWOS; break;
+        default:
+        throw sg_exception("unsupported comm station type");
+    }
+    
+    _geod = sta->geod();
+    _cart = sta->cart();
+    range = sta->rangeNm();
+    ident = sta->airport()->ident();
+    name = sta->airport()->name();
+    freq = sta->freqKHz();
 }
 
 // Render a transmission
@@ -221,6 +203,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
@@ -229,9 +213,9 @@ void FGATC::Render(string& msg, const float volume,
 #ifdef ENABLE_AUDIO_SUPPORT
        _voice = (_voiceOK && fgGetBool("/sim/sound/voice"));
        if(_voice) {
-                size_t len;
+               size_t len;
                void* buf = _vPtr->WriteMessage((char*)msg.c_str(), &len);
-               if(buf && (volume > 0.05)) {
+               if(buf) {
                        NoRender(refname);
                        try {
 // >>> Beware: must pass a (new) object to the (add) method,
@@ -242,7 +226,7 @@ void FGATC::Render(string& msg, const float volume,
                                _sgr->add(simple, refname);
                                _sgr->play(refname, repeating);
                        } catch ( sg_io_exception &e ) {
-                               SG_LOG(SG_GENERAL, SG_ALERT, e.getFormattedMessage());
+                               SG_LOG(SG_ATC, SG_ALERT, e.getFormattedMessage());
                        }
                }
        }
@@ -316,13 +300,13 @@ std::istream& operator >> ( std::istream& fin, ATCData& a )
                a.type = INVALID;
                return fin >> skipeol;
        default:
-               SG_LOG(SG_GENERAL, SG_ALERT, "Warning - unknown type \'" << tp << "\' found whilst reading ATC frequency data!\n");
+               SG_LOG(SG_ATC, SG_ALERT, "Warning - unknown type \'" << tp << "\' found whilst reading ATC frequency data!\n");
                a.type = INVALID;
                return fin >> skipeol;
        }
        
        double lat, lon, elev;
-  
+
        fin >> lat >> lon >> elev >> f >> a.range >> a.ident;
        a.geod = SGGeod::fromDegM(lon, lat, elev);
        a.name = "";