virtual void valueChanged (SGPropertyNode * node);
private:
- FGSoundManager * _wrapper;
+ FGSoundManager* _wrapper;
};
void Listener::valueChanged(SGPropertyNode * node)
{
}
-
-void FGSoundManager::setNewSoundDevice(const char *device)
-{
- SGSoundMgr *smgr = globals->get_soundmgr();
- smgr->suspend();
- smgr->stop();
- smgr->init(device);
- smgr->resume();
-}
-
void FGSoundManager::init()
-{
- globals->get_props()->tie("/sim/sound/devices/name",
- SGRawValueFunctions<const char *>(0, FGSoundManager::setNewSoundDevice), false);
-}
-
-void FGSoundManager::bind()
{
_sound_working = fgGetNode("/sim/sound/working");
_sound_enabled = fgGetNode("/sim/sound/enabled");
_volume = fgGetNode("/sim/sound/volume");
+ _device_name = fgGetNode("/sim/sound/device-name");
+
+ reinit();
+}
+
+void FGSoundManager::reinit()
+{
+ _is_initialized = false;
+
+ if (_is_initialized && !_sound_working->getBoolValue())
+ {
+ // shutdown sound support
+ stop();
+ return;
+ }
+
+ if (!_sound_working->getBoolValue())
+ {
+ return;
+ }
- // we intentionally do _not_ call SGSoundMgr::bind here, we'll do this later
+ update_device_list();
+
+ select_device(_device_name->getStringValue());
+ SGSoundMgr::reinit();
+ _is_initialized = true;
+
+ activate(fgGetBool("sim/sceneryloaded", true));
}
void FGSoundManager::activate(bool State)
{
- if (_is_initialized &&
- fgGetBool("/sim/sound/working"))
+ if (_is_initialized)
{
if (State)
+ {
SGSoundMgr::activate();
+ }
}
}
-void FGSoundManager::runtime_init()
+void FGSoundManager::update_device_list()
{
- SGSoundMgr::bind();
- SGSoundMgr::init(fgGetString("/sim/sound/device-name", NULL));
-
std::vector <const char*>devices = get_available_devices();
for (unsigned int i=0; i<devices.size(); i++) {
SGPropertyNode *p = fgGetNode("/sim/sound/devices/device", i, true);
// Actual sound update is triggered by the subsystem manager.
void FGSoundManager::update(double dt)
{
- if (!_is_initialized) {
- if (_sound_working->getBoolValue()) {
- runtime_init();
- _is_initialized = true;
- }
- } else {
- if (!_sound_working->getBoolValue()) { // request to reinit
- SGSoundMgr::reinit();
- _sound_working->setBoolValue(true);
- }
-
- if (_sound_enabled->getBoolValue()) {
- set_volume(_volume->getFloatValue());
- SGSoundMgr::update(dt);
- }
+ if (_is_initialized && _sound_working->getBoolValue() && _sound_enabled->getBoolValue())
+ {
+ set_volume(_volume->getFloatValue());
+ SGSoundMgr::update(dt);
}
}
~FGSoundManager();
void init(void);
- void bind(void);
void update(double dt);
+ void reinit(void);
- void runtime_init(void);
void activate(bool State);
-
- static void setNewSoundDevice(const char *device);
+ void update_device_list();
private:
bool _is_initialized;
- SGPropertyNode_ptr _sound_working, _sound_enabled, _volume;
+ SGPropertyNode_ptr _sound_working, _sound_enabled, _volume, _device_name;
Listener* _listener;
};
#else
+#include "Main/fg_props.hxx"
// provide a dummy sound class
class FGSoundManager : public SGSubsystem
{
public:
- FGSoundManager() {}
+ FGSoundManager() { fgSetBool("/sim/sound/working", false);}
~FGSoundManager() {}
void update(double dt) {}