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 ) :
44 _pause( fgGetNode("/sim/sound/pause") ),
45 _volume( fgGetNode("/sim/sound/volume") )
47 SGSampleGroup::_smgr = smgr;
48 SGSampleGroup::_refname = refname;
49 SGSampleGroup::_smgr->add(this, refname);
50 _avionics = _smgr->find("avionics", true);
51 _avionics->tie_to_listener();
57 for (unsigned int i = 0; i < _sound.size(); i++ ) {
67 SGPropertyNode *node = fgGetNode("/sim/sound", true);
69 string path_str = node->getStringValue("path");
70 SGPath path( globals->get_fg_root() );
71 if (path_str.empty()) {
72 SG_LOG(SG_GENERAL, SG_ALERT, "No path in /sim/sound/path");
76 path.append(path_str.c_str());
77 SG_LOG(SG_GENERAL, SG_INFO, "Reading sound " << node->getName()
78 << " from " << path.str());
82 readProperties(path.str(), &root);
83 } catch (const sg_exception &) {
84 SG_LOG(SG_GENERAL, SG_ALERT,
85 "Error reading file '" << path.str() << '\'');
89 node = root.getNode("fx");
91 for (int i = 0; i < node->nChildren(); ++i) {
92 SGXmlSound *sound = new SGXmlSound();
95 sound->init(globals->get_props(), node->getChild(i), this,
96 _avionics, globals->get_fg_root());
98 _sound.push_back(sound);
99 } catch ( sg_exception &e ) {
100 SG_LOG(SG_GENERAL, SG_ALERT, e.getFormattedMessage());
117 FGFX::update (double dt)
119 bool new_pause = _pause->getBoolValue();
120 if ( new_pause != last_pause ) {
126 last_pause = new_pause;
130 double volume = _volume->getDoubleValue();
131 if ( volume != last_volume ) {
132 set_volume( volume );
133 last_volume = volume;
136 // update sound effects if not paused
137 for ( unsigned int i = 0; i < _sound.size(); i++ ) {
138 _sound[i]->update(dt);
141 SGSampleGroup::update(dt);