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>
35 #include <Main/globals.hxx>
37 #include <simgear/props/props.hxx>
38 #include <simgear/props/props_io.hxx>
39 #include <simgear/misc/sg_path.hxx>
40 #include <simgear/sound/soundmgr_openal.hxx>
41 #include <simgear/sound/xmlsound.hxx>
43 FGFX::FGFX ( const std::string &refname, SGPropertyNode *props ) :
48 _props = globals->get_props();
49 _enabled = fgGetNode("/sim/sound/effects/enabled", true);
50 _volume = fgGetNode("/sim/sound/effects/volume", true);
53 _enabled = _props->getNode("/sim/sound/aimodels/enabled", true);
54 _enabled->setBoolValue(fgGetBool("/sim/sound/effects/enabled"));
55 _volume = _props->getNode("/sim/sound/aimodels/volume", true);
56 _volume->setFloatValue(fgGetFloat("/sim/sound/effects/volume"));
59 _avionics_enabled = _props->getNode("sim/sound/avionics/enabled", true);
60 _avionics_volume = _props->getNode("sim/sound/avionics/volume", true);
61 _avionics_ext = _props->getNode("sim/sound/avionics/external-view", true);
62 _internal = _props->getNode("sim/current-view/internal", true);
64 _smgr = globals->get_soundmgr();
70 _smgr->add(this, refname);
74 _avionics = _smgr->find("avionics", true);
75 _avionics->tie_to_listener();
83 _smgr->remove(_refname);
89 for (unsigned int i = 0; i < _sound.size(); i++ ) {
103 SGPropertyNode *node = _props->getNode("sim/sound", true);
105 std::string path_str = node->getStringValue("path");
106 if (path_str.empty()) {
107 SG_LOG(SG_SOUND, SG_ALERT, "No path in sim/sound/path");
111 SGPath path = globals->resolve_aircraft_path(path_str);
114 SG_LOG(SG_SOUND, SG_ALERT,
115 "File not found: '" << path_str);
118 SG_LOG(SG_SOUND, SG_INFO, "Reading sound " << node->getName()
119 << " from " << path.str());
123 readProperties(path.str(), &root);
124 } catch (const sg_exception &) {
125 SG_LOG(SG_SOUND, SG_ALERT,
126 "Error reading file '" << path.str() << '\'');
130 node = root.getNode("fx");
132 for (int i = 0; i < node->nChildren(); ++i) {
133 SGXmlSound *soundfx = new SGXmlSound();
136 soundfx->init( _props, node->getChild(i), this, _avionics,
138 _sound.push_back( soundfx );
139 } catch ( sg_exception &e ) {
140 SG_LOG(SG_SOUND, SG_ALERT, e.getFormattedMessage());
151 for ( unsigned int i = 0; i < _sound.size(); i++ ) {
160 FGFX::update (double dt)
166 if ( _enabled->getBoolValue() ) {
167 if ( _avionics_enabled->getBoolValue())
169 if (_avionics_ext->getBoolValue() || _internal->getBoolValue()) {
170 // avionics sound is enabled
171 _avionics->resume(); // no-op if already in resumed state
172 _avionics->set_volume( _avionics_volume->getFloatValue() );
175 _avionics->suspend();
178 set_volume( _volume->getDoubleValue() );
181 // update sound effects if not paused
182 for ( unsigned int i = 0; i < _sound.size(); i++ ) {
183 _sound[i]->update(dt);
186 SGSampleGroup::update(dt);