]> git.mxchange.org Git - flightgear.git/blobdiff - src/ATC/ATC.cxx
Moved some of the low level scene graph construction code over to simgear.
[flightgear.git] / src / ATC / ATC.cxx
index 24c0c0d605b609cb7c45274cdb0f7ddbed9e7ac8..38af59ef5fe116dd3cd664b9dfbb9721dd1daf5b 100644 (file)
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+#include <simgear/sound/soundmgr.hxx>
+
+#include <Main/fgfs.hxx>
+#include <Main/fg_props.hxx>
+
 #include "ATC.hxx"
+#include "ATCdisplay.hxx"
 
 FGATC::~FGATC() {
 }
 
-void FGATC::Update() {
+void FGATC::Update(double dt) {
 }
 
 void FGATC::AddPlane(string pid) {
@@ -56,6 +62,60 @@ void FGATC::SetData(ATCData* d) {
        freq = d->freq;
 }
 
+// Render a transmission
+// 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) {
+#ifdef ENABLE_AUDIO_SUPPORT
+       voice = (voiceOK && fgGetBool("/sim/sound/audible")
+                 && 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);
+                       }
+               }
+               delete[] buf;
+       }
+#endif // ENABLE_AUDIO_SUPPORT
+       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; 
+}
+
+
+// Cease rendering a transmission.
+void FGATC::NoRender(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();
+               }
+               playing = false;
+       }
+}
+
 ostream& operator << (ostream& os, atc_type atc) {
     switch(atc) {
     case(INVALID):