diff --git a/src/ATC/ATC.cxx b/src/ATC/ATC.cxx index 24c0c0d60..2f4d944fb 100644 --- a/src/ATC/ATC.cxx +++ b/src/ATC/ATC.cxx @@ -18,7 +18,12 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#include
+#include
+#include + #include "ATC.hxx" +#include "ATCdisplay.hxx" FGATC::~FGATC() { } @@ -56,6 +61,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) { + FGSimpleSound* simple = new FGSimpleSound(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): diff --git a/src/ATC/ATC.hxx b/src/ATC/ATC.hxx index 1babf06f7..2dda84e0b 100644 --- a/src/ATC/ATC.hxx +++ b/src/ATC/ATC.hxx @@ -30,6 +30,8 @@ #include STL_IOSTREAM #include STL_STRING +#include "ATCVoice.hxx" + SG_USING_STD(ostream); SG_USING_STD(string); SG_USING_STD(ios); @@ -111,12 +113,28 @@ public: protected: + // 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 Render(string msg, string refname, bool repeating); + + // Cease rendering a transmission. + // Requires the sound manager refname if audio, else "". + void NoRender(string refname); + double lon, lat, elev; double x, y, z; int freq; int range; string ident; // Code of the airport its at. string name; // Name transmitted in the broadcast. + + // Rendering related stuff + bool voice; // Flag - true if we are using voice + bool playing; // Indicates a message in progress + bool voiceOK; // Flag - true if at least one voice has loaded OK + FGATCVoice* vPtr; }; inline istream& diff --git a/src/ATC/ATCVoice.cxx b/src/ATC/ATCVoice.cxx index 0ebc217fb..3a7c427a6 100644 --- a/src/ATC/ATCVoice.cxx +++ b/src/ATC/ATCVoice.cxx @@ -23,8 +23,6 @@ # include #endif -#include - #include #include #include diff --git a/src/ATC/ATCVoice.hxx b/src/ATC/ATCVoice.hxx index 8edd8953e..657e5ecb2 100644 --- a/src/ATC/ATCVoice.hxx +++ b/src/ATC/ATCVoice.hxx @@ -21,6 +21,8 @@ #ifndef _FG_ATC_VOICE #define _FG_ATC_VOICE +#include + #include #if defined( SG_HAVE_STD_INCLUDES ) || defined( __BORLANDC__ ) || (__APPLE__) diff --git a/src/ATC/ATCmgr.cxx b/src/ATC/ATCmgr.cxx index 838de9c7f..412664aee 100644 --- a/src/ATC/ATCmgr.cxx +++ b/src/ATC/ATCmgr.cxx @@ -53,6 +53,7 @@ FGATCMgr::FGATCMgr() { } FGATCMgr::~FGATCMgr() { + delete v1; } void FGATCMgr::bind() { @@ -99,7 +100,9 @@ void FGATCMgr::init() { // Load all available voices. // For now we'll do one hardwired one - voiceOK = v1.LoadVoice("default"); + v1 = new FGATCVoice; + voiceOK = v1->LoadVoice("default"); + voice = true; /* I've loaded the voice even if /sim/sound/audible is false * since I know no way of forcing load of the voice if the user @@ -284,62 +287,36 @@ FGATC* FGATCMgr::GetATCPointer(string icao, atc_type type) { return(NULL); } - -// 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 FGATCMgr::Render(string msg, string refname, bool repeating) { -#ifdef ENABLE_AUDIO_SUPPORT - voice = (voiceOK && fgGetBool("/sim/sound/audible") - && fgGetBool("/sim/sound/voice")); +// Return a pointer to an appropriate voice for a given type of ATC +// creating the voice if necessary - ie. make sure exactly one copy +// of every voice in use exists in memory. +// +// TODO - in the future this will get more complex and dole out country/airport +// specific voices, and possible make sure that the same voice doesn't get used +// at different airports in quick succession if a large enough selection are available. +FGATCVoice* FGATCMgr::GetVoicePointer(atc_type type) { + // TODO - implement me better - maintain a list of loaded voices and other voices!! if(voice) { - int len; - unsigned char* buf = v1.WriteMessage((char*)msg.c_str(), len, voice); - if(voice) { - FGSimpleSound* simple = new FGSimpleSound(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); + switch(type) { + case ATIS: + if(voiceOK) { + return(v1); } + case TOWER: + return(NULL); + case APPROACH: + return(NULL); + case GROUND: + return(NULL); + default: + return(NULL); } - 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 FGATCMgr::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; + return(NULL); + } else { + return(NULL); } } - // Display a dialog box with options relevant to the currently tuned ATC service. void FGATCMgr::doPopupDialog() { ATCDoDialog(comm_type[0]); // FIXME - currently hardwired to comm1 diff --git a/src/ATC/ATCmgr.hxx b/src/ATC/ATCmgr.hxx index 284d31211..992e87f3c 100644 --- a/src/ATC/ATCmgr.hxx +++ b/src/ATC/ATCmgr.hxx @@ -24,7 +24,6 @@ #include
#include
-#include #include #include @@ -131,13 +130,12 @@ private: FGTower tower; FGApproach approach; //FGDeparture departure; - - // Rendering related stuff + + // Voice related stuff bool voice; // Flag - true if we are using voice - bool playing; // Indicates a message in progress #ifdef ENABLE_AUDIO_SUPPORT bool voiceOK; // Flag - true if at least one voice has loaded OK - FGATCVoice v1; + FGATCVoice* v1; #endif public: @@ -159,19 +157,18 @@ public: // Return a pointer to a given sort of ATC at a given airport and activate if necessary FGATC* GetATCPointer(string icao, atc_type type); - // 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 Render(string msg, string refname, bool repeating); - - // Cease rendering a transmission. - // Requires the sound manager refname if audio, else "". - void NoRender(string refname); - // Display a dialog box with options relevant to the currently tuned ATC service. void doPopupDialog(); + // Return a pointer to an appropriate voice for a given type of ATC + // creating the voice if necessary - ie. make sure exactly one copy + // of every voice in use exists in memory. + // + // TODO - in the future this will get more complex and dole out country/airport + // specific voices, and possible make sure that the same voice doesn't get used + // at different airports in quick succession if a large enough selection are available. + FGATCVoice* GetVoicePointer(atc_type type); + atc_type GetComm1ATCType() { return(comm_type[0]); } FGATC* GetComm1ATCPointer() { return(comm_atc_ptr[0]); } atc_type GetComm2ATCType() { return(comm_type[1]); } diff --git a/src/ATC/atis.cxx b/src/ATC/atis.cxx index 344a3bc2e..cc4f1618a 100644 --- a/src/ATC/atis.cxx +++ b/src/ATC/atis.cxx @@ -66,6 +66,8 @@ atis_failed(false), refname("atis") //type(ATIS) { + vPtr = globals->get_ATC_mgr()->GetVoicePointer(ATIS); + voiceOK = (vPtr == NULL ? false : true); } // Destructor @@ -83,14 +85,14 @@ void FGATIS::Update() { // We need to get and display the message UpdateTransmission(); //cout << "ATIS.CXX - calling ATCMgr to render transmission..." << endl; - globals->get_ATC_mgr()->Render(transmission, refname, true); + Render(transmission, refname, true); displaying = true; } } else { // We shouldn't be displaying if(displaying) { //cout << "ATIS.CXX - calling NoRender()..." << endl; - globals->get_ATC_mgr()->NoRender(refname); + NoRender(refname); displaying = false; } }