1
0
Fork 0

Add Nasal bindings

This commit is contained in:
Erik Hofman 2015-11-04 14:37:41 +01:00
parent 0f113060e9
commit 8363ee8784
3 changed files with 43 additions and 16 deletions

View file

@ -5,7 +5,7 @@ set(SOURCES
soundgenerator.cxx soundgenerator.cxx
beacon.cxx beacon.cxx
fg_fx.cxx fg_fx.cxx
fg_environmentfx.cxx environment_fx.cxx
morse.cxx morse.cxx
sample_queue.cxx sample_queue.cxx
voice.cxx voice.cxx
@ -18,7 +18,7 @@ set(HEADERS
soundgenerator.hxx soundgenerator.hxx
beacon.hxx beacon.hxx
fg_fx.hxx fg_fx.hxx
fg_environmentfx.hxx environment_fx.hxx
morse.hxx morse.hxx
sample_queue.hxx sample_queue.hxx
voice.hxx voice.hxx

View file

@ -29,18 +29,22 @@
# include <config.h> # include <config.h>
#endif #endif
#include "fg_environmentfx.hxx" #include "environment_fx.hxx"
#include <Main/fg_props.hxx> #include <Main/fg_props.hxx>
#include <Main/globals.hxx> #include <Main/globals.hxx>
// #include <simgear/props/props.hxx>
// #include <simgear/props/props_io.hxx>
#include <simgear/misc/sg_path.hxx> #include <simgear/misc/sg_path.hxx>
#include <simgear/sound/soundmgr_openal.hxx> #include <simgear/sound/soundmgr_openal.hxx>
#include <simgear/nasal/cppbind/Ghost.hxx>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
static std::string _refname = "EnvironmentFX"; static std::string _refname = "EnvironmentFX";
typedef boost::shared_ptr<SGSampleGroup> SGSampleGroupRef;
typedef boost::shared_ptr<FGEnvironmentFX> FGEnvironmentFXRef;
FGEnvironmentFX::FGEnvironmentFX() FGEnvironmentFX::FGEnvironmentFX()
@ -48,6 +52,16 @@ FGEnvironmentFX::FGEnvironmentFX()
_enabled = fgGetNode("/sim/sound/environment/enabled", true); _enabled = fgGetNode("/sim/sound/environment/enabled", true);
_volume = fgGetNode("/sim/sound/environment/volume", true); _volume = fgGetNode("/sim/sound/environment/volume", true);
_smgr->add(this, _refname); _smgr->add(this, _refname);
nasal::Ghost<FGEnvironmentFXRef>::init("sound")
.bases<SGSampleGroupRef>()
.method("add", &FGEnvironmentFX::add)
.method("position", &FGEnvironmentFX::position)
.method("pitch", &FGEnvironmentFX::pitch)
.method("volume", &FGEnvironmentFX::volume)
.method("properties", &FGEnvironmentFX::properties)
.method("play", &FGEnvironmentFX::play)
.method("stop", &FGEnvironmentFX::stop);
} }
FGEnvironmentFX::~FGEnvironmentFX() FGEnvironmentFX::~FGEnvironmentFX()
@ -90,17 +104,17 @@ void FGEnvironmentFX::update (double dt)
} }
} }
void FGEnvironmentFX::add(std::string& path_str, const std::string& refname) bool FGEnvironmentFX::add(const std::string& path_str, const std::string& refname)
{ {
if (!_smgr) { if (!_smgr) {
return; return false;
} }
SGPath path = globals->resolve_resource_path(path_str); SGPath path = globals->resolve_resource_path(path_str);
if (path.isNull()) if (path.isNull())
{ {
SG_LOG(SG_SOUND, SG_ALERT, "File not found: '" << path_str); SG_LOG(SG_SOUND, SG_ALERT, "File not found: '" << path_str);
return; return false;
} }
SG_LOG(SG_SOUND, SG_INFO, "Reading sound from " << path.str()); SG_LOG(SG_SOUND, SG_INFO, "Reading sound from " << path.str());
@ -113,15 +127,18 @@ void FGEnvironmentFX::add(std::string& path_str, const std::string& refname)
{ {
throw sg_io_exception("Environment FX: couldn't find file: '" + path.str() + "'"); throw sg_io_exception("Environment FX: couldn't find file: '" + path.str() + "'");
delete sample; delete sample;
return false;
} }
return true;
} }
void FGEnvironmentFX::position(const std::string& refname, const SGVec3d& pos) void FGEnvironmentFX::position(const std::string& refname, double lon, double lat, double elevation)
{ {
SGSoundSample* sample = SGSampleGroup::find(refname); SGSoundSample* sample = SGSampleGroup::find(refname);
if (sample) if (sample)
{ {
sample->set_position( pos ); SGGeod pos = SGGeod::fromDegFt(lon, lat, elevation);
sample->set_position( SGVec3d::fromGeod(pos) );
} }
} }
@ -155,4 +172,14 @@ void FGEnvironmentFX::properties(const std::string& refname, float reference_dis
} }
} }
void FGEnvironmentFX::play(const std::string& refname, bool looping)
{
SGSampleGroup::play( refname, looping );
}
void FGEnvironmentFX::stop(const std::string& refname)
{
SGSampleGroup::stop( refname );
}
// end of fg_environmentfx.cxx // end of fg_environmentfx.cxx

View file

@ -26,13 +26,11 @@
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <vector>
#include <simgear/structure/subsystem_mgr.hxx> #include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/props/props.hxx> #include <simgear/props/props.hxx>
#include <simgear/sound/sample_group.hxx> #include <simgear/sound/sample_group.hxx>
#include <simgear/math/SGMathFwd.hxx>
class SGXmlSound;
/** /**
@ -44,18 +42,20 @@ class FGEnvironmentFX : public SGSampleGroup
public: public:
FGEnvironmentFX(); FGEnvironmentFX();
~FGEnvironmentFX(); virtual ~FGEnvironmentFX();
void init (); void init ();
void reinit(); void reinit();
void update (double dt); void update (double dt);
void unbind(); void unbind();
void add(std::string& path_str, const std::string& refname); bool add(const std::string& path_str, const std::string& refname);
void position(const std::string& refname, const SGVec3d& pos); void position(const std::string& refname, double lon, double lat, double elevation = 0.0);
void pitch(const std::string& refname, float pitch); void pitch(const std::string& refname, float pitch);
void volume(const std::string& refname, float volume); void volume(const std::string& refname, float volume);
void properties(const std::string& refname, float reference_dist, float max_dist = -1 ); void properties(const std::string& refname, float reference_dist, float max_dist = -1 );
void play(const std::string& refname, bool looping = false);
void stop(const std::string& refname);
private: private:
SGPropertyNode_ptr _enabled; SGPropertyNode_ptr _enabled;