1 // fg_environmentfx.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)
32 #include "fg_environmentfx.hxx"
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>
43 static std::string _refname = "EnvironmentFX";
46 FGEnvironmentFX::FGEnvironmentFX()
48 _enabled = fgGetNode("/sim/sound/environment/enabled", true);
49 _volume = fgGetNode("/sim/sound/environment/volume", true);
50 _smgr->add(this, _refname);
53 FGEnvironmentFX::~FGEnvironmentFX()
57 void FGEnvironmentFX::unbind()
60 _smgr->remove(_refname);
64 void FGEnvironmentFX::init()
71 void FGEnvironmentFX::reinit()
76 void FGEnvironmentFX::update (double dt)
82 if ( _enabled->getBoolValue() ) {
83 set_volume( _volume->getDoubleValue() );
86 SGSampleGroup::update(dt);
93 void FGEnvironmentFX::add(std::string& path_str, const std::string& refname)
99 SGPath path = globals->resolve_resource_path(path_str);
102 SG_LOG(SG_SOUND, SG_ALERT, "File not found: '" << path_str);
105 SG_LOG(SG_SOUND, SG_INFO, "Reading sound from " << path.str());
107 SGSharedPtr<SGSoundSample> sample;
108 sample = new SGSoundSample("", path);
109 if (sample->file_path().exists()) {
110 SGSampleGroup::add( sample, refname );
114 throw sg_io_exception("Environment FX: couldn't find file: '" + path.str() + "'");
119 void FGEnvironmentFX::position(const std::string& refname, const SGVec3d& pos)
121 SGSoundSample* sample = SGSampleGroup::find(refname);
124 sample->set_position( pos );
128 void FGEnvironmentFX::pitch(const std::string& refname, float pitch)
130 SGSoundSample* sample = SGSampleGroup::find(refname);
133 sample->set_volume( pitch );
137 void FGEnvironmentFX::volume(const std::string& refname, float volume)
139 SGSoundSample* sample = SGSampleGroup::find(refname);
142 sample->set_volume( volume );
146 void FGEnvironmentFX::properties(const std::string& refname, float reference_dist, float max_dist )
148 SGSoundSample* sample = SGSampleGroup::find(refname);
151 sample->set_reference_dist( reference_dist );
153 sample->set_max_dist( max_dist );
158 // end of fg_environmentfx.cxx