1 // fg_fx.cxx -- Sound effect management class implementation
3 // Started by David Megginson, October 2001
4 // (Reuses some code from main.cxx, probably by Curtis Olson)
6 // Copyright (C) 2001 Curtis L. Olson - http://www.flightgear.org/~curt
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.
25 #pragma warning (disable: 4786)
34 #include <Main/fg_props.hxx>
36 #include <simgear/props/props.hxx>
37 #include <simgear/misc/sg_path.hxx>
38 #include <simgear/sound/soundmgr_openal.hxx>
39 #include <simgear/sound/xmlsound.hxx>
41 FGFX::FGFX ( SGSoundMgr *smgr, const string &refname ) :
42 _enabled( fgGetNode("/sim/sound/effects/enabled", true) ),
43 _volume( fgGetNode("/sim/sound/effects/volume", true) ),
44 _avionics_enabled( fgGetNode("/sim/sound/avionics/enabled", true) ),
45 _avionics_volume( fgGetNode("/sim/sound/avionics/volume", true) ),
46 _avionics_external( fgGetNode("/sim/sound/avionics/external-view", true) ),
47 _internal( fgGetNode("/sim/current-view/internal", true) )
49 SGSampleGroup::_smgr = smgr;
50 SGSampleGroup::_refname = refname;
51 SGSampleGroup::_smgr->add(this, refname);
52 _avionics = _smgr->find("avionics", true);
53 _avionics->tie_to_listener();
59 for (unsigned int i = 0; i < _sound.size(); i++ ) {
69 SGPropertyNode *node = fgGetNode("/sim/sound", true);
71 string path_str = node->getStringValue("path");
72 SGPath path( globals->get_fg_root() );
73 if (path_str.empty()) {
74 SG_LOG(SG_GENERAL, SG_ALERT, "No path in /sim/sound/path");
78 path.append(path_str.c_str());
79 SG_LOG(SG_GENERAL, SG_INFO, "Reading sound " << node->getName()
80 << " from " << path.str());
84 readProperties(path.str(), &root);
85 } catch (const sg_exception &) {
86 SG_LOG(SG_GENERAL, SG_ALERT,
87 "Error reading file '" << path.str() << '\'');
91 node = root.getNode("fx");
93 for (int i = 0; i < node->nChildren(); ++i) {
94 SGXmlSound *sound = new SGXmlSound();
97 sound->init(globals->get_props(), node->getChild(i), this,
98 _avionics, globals->get_fg_root());
100 _sound.push_back(sound);
101 } catch ( sg_exception &e ) {
102 SG_LOG(SG_GENERAL, SG_ALERT, e.getFormattedMessage());
119 FGFX::update (double dt)
121 bool active = _avionics_external->getBoolValue() ||
122 _internal->getBoolValue();
124 if ( active && _avionics_enabled->getBoolValue() )
125 _avionics->resume(); // no-op if already in resumed state
127 _avionics->suspend();
128 _avionics->set_volume( _avionics_volume->getFloatValue() );
130 if ( _enabled->getBoolValue() ) {
131 set_volume( _volume->getDoubleValue() );
134 // update sound effects if not paused
135 for ( unsigned int i = 0; i < _sound.size(); i++ ) {
136 _sound[i]->update(dt);
139 SGSampleGroup::update(dt);