1 // ATISmgr.cxx - Implementation of FGATISMgr - a global Flightgear ATIS manager.
3 // Written by David Luff, started February 2002.
5 // Copyright (C) 2002 David C Luff - david.luff@nottingham.ac.uk
6 // Copyright (C) 2012 Thorsten Brehm
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License as
10 // published by the Free Software Foundation; either version 2 of the
11 // License, or (at your option) any later version.
13 // This program is distributed in the hope that it will be useful, but
14 // WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 #include <simgear/misc/sg_path.hxx>
27 #include <simgear/debug/logstream.hxx>
28 #include <simgear/structure/exception.hxx>
30 #include <Main/fg_props.hxx>
32 #include "ATISmgr.hxx"
35 FGATISMgr::FGATISMgr() :
38 #ifdef ENABLE_AUDIO_SUPPORT
43 globals->set_ATIS_mgr(this);
46 FGATISMgr::~FGATISMgr()
48 globals->set_ATIS_mgr(NULL);
50 for (unsigned int unit = 0;unit < radios.size(); ++unit) {
54 #ifdef ENABLE_AUDIO_SUPPORT
59 void FGATISMgr::init()
61 for (unsigned int unit = 0;unit < _maxCommRadios; ++unit)
63 if (unit < _maxCommRadios/2)
64 radios.push_back(new FGATIS("comm", unit));
66 radios.push_back(new FGATIS("nav", unit - _maxCommRadios/2));
70 void FGATISMgr::reinit()
72 #ifdef ENABLE_AUDIO_SUPPORT
73 if ((voiceName != "")&&
74 (voiceName != fgGetString("/sim/atis/voice", "default")))
76 voiceName = fgGetString("/sim/atis/voice", "default");
84 void FGATISMgr::update(double dt)
86 // update only runs every now and then (1-2 per second)
87 if (++_currentUnit >= _maxCommRadios)
90 FGATC* commRadio = radios[_currentUnit];
92 commRadio->update(dt * _maxCommRadios);
95 // Return a pointer to an appropriate voice for a given type of ATC
96 // creating the voice if necessary - i.e. make sure exactly one copy
97 // of every voice in use exists in memory.
99 // TODO - in the future this will get more complex and dole out country/airport
100 // specific voices, and possible make sure that the same voice doesn't get used
101 // at different airports in quick succession if a large enough selection are available.
102 FGATCVoice* FGATISMgr::GetVoicePointer(const atc_type& type)
104 #ifdef ENABLE_AUDIO_SUPPORT
105 // TODO - implement me better - maintain a list of loaded voices and other voices!!
110 case ATIS: case AWOS:
111 // Delayed loading for all available voices, needed because the
112 // sound manager might not be initialized (at all) at this point.
113 // For now we'll do one hard-wired one
115 /* I've loaded the voice even if /sim/sound/pause is true
116 * since I know no way of forcing load of the voice if the user
117 * subsequently switches /sim/sound/audible to true.
118 * (which is the right thing to do -- CLO) :-)
120 if (!voice && fgGetBool("/sim/sound/working")) {
121 voice = new FGATCVoice;
122 voiceName = fgGetString("/sim/atis/voice", "default");
124 useVoice = voice->LoadVoice(voiceName);
125 } catch ( sg_io_exception & e) {
126 SG_LOG(SG_ATC, SG_ALERT, "Unable to load voice '" << voiceName << "': "
127 << e.getFormattedMessage().c_str());