From 831f81d97cd1a3383b866ca4e7ee5b7577466ef5 Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Sat, 3 Dec 2011 14:40:48 +0100 Subject: [PATCH 1/3] Properly construct a string from another string and an integer, use a relative path for sound construction, allow enable/disable aimodel sounds using /sim/sound/aimodels/enabled --- src/AIModel/AIBase.cxx | 13 ++++++++++--- src/Sound/fg_fx.cxx | 20 ++++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index d2e2fe25d..95d023296 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -147,7 +147,10 @@ FGAIBase::~FGAIBase() { if (_refID != 0 && _refID != 1) { SGSoundMgr *smgr = globals->get_soundmgr(); - smgr->remove("aifx:"+_refID); + stringstream name; + name << "aifx:"; + name << _refID; + smgr->remove(name.str()); } delete fp; @@ -221,7 +224,8 @@ void FGAIBase::update(double dt) { _fx->set_orientation( orient ); SGVec3d velocity; - velocity = SGVec3d( speed_north_deg_sec, speed_east_deg_sec, pitch*speed ); + velocity = SGVec3d( speed_north_deg_sec, speed_east_deg_sec, + pitch*speed ); _fx->set_velocity( velocity ); } else if (_aimodel) @@ -234,7 +238,10 @@ void FGAIBase::update(double dt) { // initialize the sound configuration SGSoundMgr *smgr = globals->get_soundmgr(); - _fx = new FGFX(smgr, "aifx:"+_refID, props); + stringstream name; + name << "aifx:"; + name << _refID; + _fx = new FGFX(smgr, name.str(), props); _fx->init(); } } diff --git a/src/Sound/fg_fx.cxx b/src/Sound/fg_fx.cxx index c8c6b49f3..2df20387d 100644 --- a/src/Sound/fg_fx.cxx +++ b/src/Sound/fg_fx.cxx @@ -40,11 +40,19 @@ #include FGFX::FGFX ( SGSoundMgr *smgr, const string &refname, SGPropertyNode *props ) : - _props( props ), - _enabled( fgGetNode("/sim/sound/effects/enabled", true) ), - _volume( fgGetNode("/sim/sound/effects/volume", true) ) + _props( props ) { - if (!props) _props = globals->get_props(); + if (!props) { + _props = globals->get_props(); + _enabled = fgGetNode("/sim/sound/effects/enabled", true); + _volume = fgGetNode("/sim/sound/effects/volume", true); + } else { + _enabled = _props->getNode("/sim/sound/aimodels/enabled", true); + _enabled->setBoolValue(fgGetBool("/sim/sound/effects/enabled")); + _volume = _props->getNode("/sim/sound/aimodels/volume", true); + _volume->setFloatValue(fgGetFloat("/sim/sound/effects/volume")); +_volume->setFloatValue(0.1f); + } _avionics_enabled = _props->getNode("sim/sound/avionics/enabled", true); _avionics_volume = _props->getNode("sim/sound/avionics/volume", true); @@ -102,9 +110,9 @@ FGFX::init() SGXmlSound *sound = new SGXmlSound(); try { - sound->init(globals->get_props(), node->getChild(i), this, +// sound->init(globals->get_props(), node->getChild(i), this, + sound->init(_props, node->getChild(i), this, _avionics, path.dir()); - _sound.push_back(sound); } catch ( sg_exception &e ) { SG_LOG(SG_SOUND, SG_ALERT, e.getFormattedMessage()); From 61e60484c8918a019d0b30e884c07cca79513fb1 Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Sat, 3 Dec 2011 15:29:04 +0100 Subject: [PATCH 2/3] make the sound of the base model work again. this also gives an indication where things start to go wrong. --- src/Sound/fg_fx.cxx | 15 ++++++++------- src/Sound/fg_fx.hxx | 1 + 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Sound/fg_fx.cxx b/src/Sound/fg_fx.cxx index 2df20387d..390609567 100644 --- a/src/Sound/fg_fx.cxx +++ b/src/Sound/fg_fx.cxx @@ -43,10 +43,12 @@ FGFX::FGFX ( SGSoundMgr *smgr, const string &refname, SGPropertyNode *props ) : _props( props ) { if (!props) { + _is_aimodel = false; _props = globals->get_props(); _enabled = fgGetNode("/sim/sound/effects/enabled", true); _volume = fgGetNode("/sim/sound/effects/volume", true); } else { + _is_aimodel = true; _enabled = _props->getNode("/sim/sound/aimodels/enabled", true); _enabled->setBoolValue(fgGetBool("/sim/sound/effects/enabled")); _volume = _props->getNode("/sim/sound/aimodels/volume", true); @@ -105,18 +107,17 @@ FGFX::init() } node = root.getNode("fx"); - if(node) { + if(node && !_is_aimodel) { for (int i = 0; i < node->nChildren(); ++i) { - SGXmlSound *sound = new SGXmlSound(); + SGXmlSound *soundfx = new SGXmlSound(); try { -// sound->init(globals->get_props(), node->getChild(i), this, - sound->init(_props, node->getChild(i), this, - _avionics, path.dir()); - _sound.push_back(sound); + soundfx->init( _props, node->getChild(i), this, _avionics, + path.dir() ); + _sound.push_back( soundfx ); } catch ( sg_exception &e ) { SG_LOG(SG_SOUND, SG_ALERT, e.getFormattedMessage()); - delete sound; + delete soundfx; } } } diff --git a/src/Sound/fg_fx.hxx b/src/Sound/fg_fx.hxx index a46d8583c..3803f5bc6 100644 --- a/src/Sound/fg_fx.hxx +++ b/src/Sound/fg_fx.hxx @@ -58,6 +58,7 @@ public: private: + bool _is_aimodel; SGSharedPtr _avionics; std::vector _sound; From ded106fe31a47eee387fdf37bb7be39c03c1b97c Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Sat, 3 Dec 2011 22:59:20 +0100 Subject: [PATCH 3/3] event input for Linux: substitude dbus+hal by udev --- src/Input/FGLinuxEventInput.cxx | 100 ++++++++------------------------ src/Input/FGLinuxEventInput.hxx | 4 -- 2 files changed, 23 insertions(+), 81 deletions(-) diff --git a/src/Input/FGLinuxEventInput.cxx b/src/Input/FGLinuxEventInput.cxx index e41f6e195..a5e825b10 100644 --- a/src/Input/FGLinuxEventInput.cxx +++ b/src/Input/FGLinuxEventInput.cxx @@ -25,15 +25,11 @@ #include #include #include -#include -#include -#include -#include #include "FGLinuxEventInput.hxx" +#include #include #include -#include #include #include @@ -445,92 +441,42 @@ void FGLinuxInputDevice::SetDevname( std::string name ) this->devname = name; } -FGLinuxEventInput::FGLinuxEventInput() : - halcontext(NULL) +FGLinuxEventInput::FGLinuxEventInput() { } FGLinuxEventInput::~FGLinuxEventInput() { - if( halcontext != NULL ) { - libhal_ctx_shutdown( halcontext, NULL); - libhal_ctx_free( halcontext ); - halcontext = NULL; - } } -#if 0 -//TODO: enable hotplug support -static void DeviceAddedCallback (LibHalContext *ctx, const char *udi) -{ - FGLinuxEventInput * linuxEventInput = (FGLinuxEventInput*)libhal_ctx_get_user_data (ctx); - linuxEventInput->AddHalDevice( udi ); -} - -static void DeviceRemovedCallback (LibHalContext *ctx, const char *udi) -{ -} -#endif - void FGLinuxEventInput::postinit() { FGEventInput::postinit(); - DBusConnection * connection; - DBusError dbus_error; + struct udev * udev = udev_new(); - dbus_error_init(&dbus_error); - connection = dbus_bus_get (DBUS_BUS_SYSTEM, &dbus_error); - if (dbus_error_is_set(&dbus_error)) { - SG_LOG( SG_INPUT, SG_ALERT, "Can't connect to system bus " << dbus_error.message); - dbus_error_free (&dbus_error); - return; + struct udev_enumerate *enumerate = udev_enumerate_new(udev); + udev_enumerate_add_match_subsystem(enumerate, "input"); + udev_enumerate_scan_devices(enumerate); + struct udev_list_entry *devices = udev_enumerate_get_list_entry(enumerate); + struct udev_list_entry *dev_list_entry; + + udev_list_entry_foreach(dev_list_entry, devices) { + const char * path = udev_list_entry_get_name(dev_list_entry); + struct udev_device *dev = udev_device_new_from_syspath(udev, path); + const char * node = udev_device_get_devnode(dev); + + dev = udev_device_get_parent( dev ); + const char * name = udev_device_get_sysattr_value(dev,"name"); + + SG_LOG(SG_INPUT,SG_ALERT, "name=" << (name?name:"") << ", node=" << (node?node:"")); + if( name && node ) + AddDevice( new FGLinuxInputDevice(name, node) ); + + udev_device_unref(dev); } - halcontext = libhal_ctx_new(); - - libhal_ctx_set_dbus_connection (halcontext, connection ); - dbus_error_init (&dbus_error); - - if( libhal_ctx_init( halcontext, &dbus_error )) { - - int num_devices = 0; - char ** devices = libhal_find_device_by_capability(halcontext, "input", &num_devices, NULL); - - for ( int i = 0; i < num_devices; i++) - AddHalDevice( devices[i] ); - - libhal_free_string_array (devices); - -//TODO: enable hotplug support -// libhal_ctx_set_user_data( halcontext, this ); -// libhal_ctx_set_device_added( halcontext, DeviceAddedCallback ); -// libhal_ctx_set_device_removed( halcontext, DeviceRemovedCallback ); - } else { - if(dbus_error_is_set (&dbus_error) ) { - SG_LOG( SG_INPUT, SG_ALERT, "Can't connect to hald: " << dbus_error.message); - dbus_error_free (&dbus_error); - } else { - SG_LOG( SG_INPUT, SG_ALERT, "Can't connect to hald." ); - } - - libhal_ctx_free (halcontext); - halcontext = NULL; - } -} - -void FGLinuxEventInput::AddHalDevice( const char * udi ) -{ - char * device = libhal_device_get_property_string( halcontext, udi, "input.device", NULL); - char * product = libhal_device_get_property_string( halcontext, udi, "input.product", NULL); - - if( product != NULL && device != NULL ) - AddDevice( new FGLinuxInputDevice(product, device) ); - else - SG_LOG( SG_INPUT, SG_ALERT, "Can't get device or product property of " << udi ); - - if( device != NULL ) libhal_free_string( device ); - if( product != NULL ) libhal_free_string( product ); + udev_unref(udev); } diff --git a/src/Input/FGLinuxEventInput.hxx b/src/Input/FGLinuxEventInput.hxx index f3bfa044f..5fcd81e24 100644 --- a/src/Input/FGLinuxEventInput.hxx +++ b/src/Input/FGLinuxEventInput.hxx @@ -25,7 +25,6 @@ #include "FGEventInput.hxx" #include -#include struct FGLinuxEventData : public FGEventData { FGLinuxEventData( struct input_event & event, double dt, int modifiers ) : @@ -71,10 +70,7 @@ public: virtual void update (double dt); virtual void postinit(); - void AddHalDevice( const char * udi ); protected: - LibHalContext *halcontext; - }; #endif