From 8363ee8784965ae103d9d6e8432220f017af28cd Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Wed, 4 Nov 2015 14:37:41 +0100 Subject: [PATCH] Add Nasal bindings --- src/Sound/CMakeLists.txt | 4 +- ...g_environmentfx.cxx => environment_fx.cxx} | 43 +++++++++++++++---- ...g_environmentfx.hxx => environment_fx.hxx} | 12 +++--- 3 files changed, 43 insertions(+), 16 deletions(-) rename src/Sound/{fg_environmentfx.cxx => environment_fx.cxx} (72%) rename src/Sound/{fg_environmentfx.hxx => environment_fx.hxx} (83%) diff --git a/src/Sound/CMakeLists.txt b/src/Sound/CMakeLists.txt index 2803dfe23..b2492b010 100644 --- a/src/Sound/CMakeLists.txt +++ b/src/Sound/CMakeLists.txt @@ -5,7 +5,7 @@ set(SOURCES soundgenerator.cxx beacon.cxx fg_fx.cxx - fg_environmentfx.cxx + environment_fx.cxx morse.cxx sample_queue.cxx voice.cxx @@ -18,7 +18,7 @@ set(HEADERS soundgenerator.hxx beacon.hxx fg_fx.hxx - fg_environmentfx.hxx + environment_fx.hxx morse.hxx sample_queue.hxx voice.hxx diff --git a/src/Sound/fg_environmentfx.cxx b/src/Sound/environment_fx.cxx similarity index 72% rename from src/Sound/fg_environmentfx.cxx rename to src/Sound/environment_fx.cxx index 12dc4aaca..964fd3b98 100644 --- a/src/Sound/fg_environmentfx.cxx +++ b/src/Sound/environment_fx.cxx @@ -29,18 +29,22 @@ # include #endif -#include "fg_environmentfx.hxx" +#include "environment_fx.hxx" #include
#include
-// #include -// #include #include #include +#include + +#include +#include static std::string _refname = "EnvironmentFX"; +typedef boost::shared_ptr SGSampleGroupRef; +typedef boost::shared_ptr FGEnvironmentFXRef; FGEnvironmentFX::FGEnvironmentFX() @@ -48,6 +52,16 @@ FGEnvironmentFX::FGEnvironmentFX() _enabled = fgGetNode("/sim/sound/environment/enabled", true); _volume = fgGetNode("/sim/sound/environment/volume", true); _smgr->add(this, _refname); + + nasal::Ghost::init("sound") + .bases() + .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() @@ -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) { - return; + return false; } SGPath path = globals->resolve_resource_path(path_str); if (path.isNull()) { 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()); @@ -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() + "'"); 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); 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 diff --git a/src/Sound/fg_environmentfx.hxx b/src/Sound/environment_fx.hxx similarity index 83% rename from src/Sound/fg_environmentfx.hxx rename to src/Sound/environment_fx.hxx index 59e1a9706..3be2d4897 100644 --- a/src/Sound/fg_environmentfx.hxx +++ b/src/Sound/environment_fx.hxx @@ -26,13 +26,11 @@ #include -#include - #include #include #include +#include -class SGXmlSound; /** @@ -44,18 +42,20 @@ class FGEnvironmentFX : public SGSampleGroup public: FGEnvironmentFX(); - ~FGEnvironmentFX(); + virtual ~FGEnvironmentFX(); void init (); void reinit(); void update (double dt); void unbind(); - void add(std::string& path_str, const std::string& refname); - void position(const std::string& refname, const SGVec3d& pos); + bool add(const std::string& path_str, const std::string& refname); + void position(const std::string& refname, double lon, double lat, double elevation = 0.0); void pitch(const std::string& refname, float pitch); void volume(const std::string& refname, float volume); 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: SGPropertyNode_ptr _enabled; -- 2.39.5