]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/ATC.cxx
Daniyar ATADJANOV:
[flightgear.git] / src / ATC / ATC.cxx
index d76ba74cf2ca9294508904708331653c847f9068..2bc321805619481bed8f0698fdeb42cdfd700693 100644 (file)
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
 
-#include <simgear/sound/soundmgr.hxx>
+#include <simgear/sound/soundmgr_openal.hxx>
+#include <simgear/structure/exception.hxx>
 
 #include <Main/globals.hxx>
 #include <Main/fg_props.hxx>
 
 #include "ATC.hxx"
-#include "ATCdisplay.hxx"
 
 FGATC::FGATC() {
        freqClear = true;
@@ -51,6 +51,8 @@ FGATC::FGATC() {
        _transmitting = false;
        _counter = 0.0;
        _max_count = 5.0;
+       
+       _voiceOK = false;
 }
 
 FGATC::~FGATC() {
@@ -105,8 +107,7 @@ void FGATC::Update(double dt) {
                //cout << "Transmission = " << pending_transmission << '\n';
                if(_display) {
                        //Render(pending_transmission, ident, false);
-                       // At the moment Render only works for ATIS
-                       globals->get_ATC_display()->RegisterSingleMessage(pending_transmission);
+                       Render(pending_transmission);
                }
                // Run the callback regardless of whether on same freq as user or not.
                //cout << "_callback_code = " << _callback_code << '\n';
@@ -122,6 +123,10 @@ void FGATC::Update(double dt) {
                        _transmitting = false;
                        //if(tuned_station) tuned_station->NotifyTransmissionFinished(plane.callsign);
                        // TODO - need to let the plane the transmission is aimed at that it's finished.
+                       // However, for now we'll just release the frequency since if we don't it all goes pear-shaped
+                       _releaseCounter = 0.0;
+                       _releaseTime = 0.9;
+                       _runReleaseCounter = true;
                }
                _counter += dt;
        }
@@ -131,7 +136,7 @@ void FGATC::ReceiveUserCallback(int code) {
        SG_LOG(SG_ATC, SG_WARN, "WARNING - whichever ATC class was intended to receive callback code " << code << " didn't get it!!!");
 }
 
-void FGATC::SetResponseReqd(string rid) {
+void FGATC::SetResponseReqd(const string& rid) {
        receiving = false;
        responseReqd = true;
        respond = false;        // TODO - this ignores the fact that more than one plane could call this before response
@@ -142,7 +147,7 @@ void FGATC::SetResponseReqd(string rid) {
        responseTime = 1.8;             // TODO - randomize this slightly.
 }
 
-void FGATC::NotifyTransmissionFinished(string rid) {
+void FGATC::NotifyTransmissionFinished(const string& rid) {
        //cout << "Transmission finished, callsign = " << rid << '\n';
        receiving = false;
        responseID = rid;
@@ -175,8 +180,8 @@ 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
-               globals->get_ATC_display()->RegisterSingleMessage(pending_transmission);
        }
        if(callback_code) {
                ProcessCallback(callback_code);
@@ -187,7 +192,7 @@ void FGATC::ImmediateTransmit(int callback_code) {
 void FGATC::ProcessCallback(int code) {
 }
 
-void FGATC::AddPlane(string pid) {
+void FGATC::AddPlane(const string& pid) {
 }
 
 int FGATC::RemovePlane() {
@@ -211,53 +216,59 @@ void FGATC::SetData(ATCData* d) {
 // Outputs the transmission either on screen or as audio depending on user preference
 // The refname is a string to identify this sample to the sound manager
 // The repeating flag indicates whether the message should be repeated continuously or played once.
-void FGATC::Render(string msg, string refname, bool repeating) {
+void FGATC::Render(string& msg, const string& refname, bool repeating) {
+       if (repeating)
+               fgSetString("/sim/messages/atis", msg.c_str());
+       else
+               fgSetString("/sim/messages/atc", msg.c_str());
+
        #ifdef ENABLE_AUDIO_SUPPORT
-       voice = (voiceOK && fgGetBool("/sim/sound/audible")
-       && fgGetBool("/sim/sound/voice"));
-       if(voice) {
+       _voice = (_voiceOK && fgGetBool("/sim/sound/voice"));
+       if(_voice) {
                int len;
-               unsigned char* buf = vPtr->WriteMessage((char*)msg.c_str(), len, voice);
-               if(voice) {
-                       SGSimpleSound* simple = new SGSimpleSound(buf, len);
-                       // TODO - at the moment the volume is always set off comm1 
-                       // and can't be changed after the transmission has started.
-                       simple->set_volume(5.0 * fgGetDouble("/radios/comm[0]/volume"));
-                       globals->get_soundmgr()->add(simple, refname);
-                       if(repeating) {
-                               globals->get_soundmgr()->play_looped(refname);
-                       } else {
-                               globals->get_soundmgr()->play_once(refname);
+               unsigned char* buf = _vPtr->WriteMessage((char*)msg.c_str(), len, _voice);
+               if(_voice) {
+                       try {
+                               SGSoundSample *simple
+                                                               = new SGSoundSample(buf, len, 8000);
+                               // TODO - at the moment the volume is always set off comm1 
+                               // and can't be changed after the transmission has started.
+                               simple->set_volume(5.0 * fgGetDouble("/instrumentation/comm[0]/volume"));
+                               globals->get_soundmgr()->add(simple, refname);
+                               if(repeating) {
+                                       globals->get_soundmgr()->play_looped(refname);
+                               } else {
+                                       globals->get_soundmgr()->play_once(refname);
+                               }
+                       } catch ( sg_io_exception &e ) {
+                               SG_LOG(SG_GENERAL, SG_ALERT, e.getFormattedMessage());
                        }
                }
                delete[] buf;
        }
        #endif  // ENABLE_AUDIO_SUPPORT
-       if(!voice) {
+       if(!_voice) {
                // first rip the underscores and the pause hints out of the string - these are for the convienience of the voice parser
                for(unsigned int i = 0; i < msg.length(); ++i) {
                        if((msg.substr(i,1) == "_") || (msg.substr(i,1) == "/")) {
                                msg[i] = ' ';
                        }
                }
-               globals->get_ATC_display()->RegisterRepeatingMessage(msg);
        }
-       playing = true; 
+       _playing = true;        
 }
 
 
 // Cease rendering a transmission.
-void FGATC::NoRender(string refname) {
-       if(playing) {
-               if(voice) {
-                       #ifdef ENABLE_AUDIO_SUPPORT             
+void FGATC::NoRender(const string& refname) {
+       if(_playing) {
+               if(_voice) {
+#ifdef ENABLE_AUDIO_SUPPORT            
                        globals->get_soundmgr()->stop(refname);
                        globals->get_soundmgr()->remove(refname);
-                       #endif
-               } else {
-                       globals->get_ATC_display()->CancelRepeatingMessage();
+#endif
                }
-               playing = false;
+               _playing = false;
        }
 }