// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+#include <Main/fgfs.hxx>
+#include <Main/fg_props.hxx>
+#include <Sound/soundmgr.hxx>
+
#include "ATC.hxx"
+#include "ATCdisplay.hxx"
FGATC::~FGATC() {
}
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):
#include STL_IOSTREAM
#include STL_STRING
+#include "ATCVoice.hxx"
+
SG_USING_STD(ostream);
SG_USING_STD(string);
SG_USING_STD(ios);
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&
# include <config.h>
#endif
-#include <plib/sl.h>
-
#include <simgear/misc/sg_path.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/sgstream.hxx>
#ifndef _FG_ATC_VOICE
#define _FG_ATC_VOICE
+#include <plib/sl.h>
+
#include <simgear/compiler.h>
#if defined( SG_HAVE_STD_INCLUDES ) || defined( __BORLANDC__ ) || (__APPLE__)
}
FGATCMgr::~FGATCMgr() {
+ delete v1;
}
void FGATCMgr::bind() {
// 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
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);
- }
- }
- 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] = ' ';
+ switch(type) {
+ case ATIS:
+ if(voiceOK) {
+ return(v1);
}
+ case TOWER:
+ return(NULL);
+ case APPROACH:
+ return(NULL);
+ case GROUND:
+ return(NULL);
+ default:
+ return(NULL);
}
- 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
#include <Main/fgfs.hxx>
#include <Main/fg_props.hxx>
-#include <Sound/soundmgr.hxx>
#include <GUI/gui.h>
#include <string>
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:
// 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]); }
refname("atis")
//type(ATIS)
{
+ vPtr = globals->get_ATC_mgr()->GetVoicePointer(ATIS);
+ voiceOK = (vPtr == NULL ? false : true);
}
// Destructor
// 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;
}
}