model_removed->setStringValue(props->getPath());
}
+ // refID=0 is supposedley impossible, refID=1 is the special ai_ac aircaft
+ // representing the current user, in the ATCManager. Maybe both these
+ // tests could die?
if (_fx && _refID != 0 && _refID != 1) {
SGSoundMgr *smgr = globals->get_soundmgr();
- stringstream name;
- name << "aifx:";
- name << _refID;
- smgr->remove(name.str());
+ if (smgr) {
+ stringstream name;
+ name << "aifx:";
+ name << _refID;
+ smgr->remove(name.str());
+ }
}
if (fp)
props->setStringValue("sim/sound/path", fxpath.c_str());
// initialize the sound configuration
- SGSoundMgr *smgr = globals->get_soundmgr();
stringstream name;
name << "aifx:";
name << _refID;
- _fx = new FGFX(smgr, name.str(), props);
+ _fx = new FGFX(name.str(), props);
_fx->init();
}
}
static bool
do_play_audio_sample (const SGPropertyNode * arg)
{
+ SGSoundMgr *smgr = globals->get_soundmgr();
+ if (!smgr) {
+ SG_LOG(SG_GENERAL, SG_WARN, "play-audio-sample: sound-manager not running");
+ return false;
+ }
+
string path = arg->getStringValue("path");
string file = arg->getStringValue("file");
float volume = arg->getFloatValue("volume");
try {
static FGSampleQueue *queue = 0;
if ( !queue ) {
- SGSoundMgr *smgr = globals->get_soundmgr();
queue = new FGSampleQueue(smgr, "chatter");
queue->tie_to_listener();
}
_speed_e(0),
_speed_d(0)
{
- SGSoundMgr *smgr = globals->get_soundmgr();
- _fx = new FGFX(smgr, "fx");
+ _fx = new FGFX("fx");
_fx->init();
}
#include "fg_fx.hxx"
#include <Main/fg_props.hxx>
+#include <Main/globals.hxx>
#include <simgear/props/props.hxx>
#include <simgear/props/props_io.hxx>
#include <simgear/sound/soundmgr_openal.hxx>
#include <simgear/sound/xmlsound.hxx>
-FGFX::FGFX ( SGSoundMgr *smgr, const std::string &refname, SGPropertyNode *props ) :
+FGFX::FGFX ( const std::string &refname, SGPropertyNode *props ) :
_props( props )
{
if (!props) {
_avionics_ext = _props->getNode("sim/sound/avionics/external-view", true);
_internal = _props->getNode("sim/current-view/internal", true);
+ SGSoundMgr *smgr = globals->get_soundmgr();
+ if (!smgr) {
+ return;
+ }
+
SGSampleGroup::_smgr = smgr;
SGSampleGroup::_refname = refname;
SGSampleGroup::_smgr->add(this, refname);
void
FGFX::init()
{
+ if (!_smgr) {
+ return;
+ }
+
SGPropertyNode *node = _props->getNode("sim/sound", true);
std::string path_str = node->getStringValue("path");
void
FGFX::update (double dt)
{
+ if (!_smgr) {
+ return;
+ }
+
if ( _enabled->getBoolValue() ) {
if ( _avionics_enabled->getBoolValue())
{
public:
- FGFX ( SGSoundMgr *smgr, const std::string &refname, SGPropertyNode *props = 0 );
+ FGFX ( const std::string &refname, SGPropertyNode *props = 0 );
virtual ~FGFX ();
virtual void init ();
// FGVoicePlayer::Voice::SampleElement ///////////////////////////
/////////////////////////////////////////////////////////////////////////
+FGVoicePlayer::Voice::SampleElement::SampleElement (SGSharedPtr<SGSoundSample> sample, float volume)
+: _sample(sample), _volume(volume)
+{
+ silence = false;
+}
+
void FGVoicePlayer::Voice::SampleElement::play (float volume)
{
if (_sample && (volume > 0.05)) { set_volume(volume); _sample->play_once(); }
: volume(1.0), voice(NULL), next_voice(NULL), paused(false),
dev_name(_dev_name), dir_prefix(""),
speaker(this,properties_handler)
-{}
+{
+ _sgr = NULL;
+}
FGVoicePlayer::~FGVoicePlayer ()
{
}
}
}
+
+void
+FGVoicePlayer::append (Voice *voice, const char *sample_name)
+{
+ voice->append(new Voice::SampleElement(get_sample(sample_name)));
+}
+
float _volume;
public:
- SampleElement (SGSharedPtr<SGSoundSample> sample, float volume = 1.0)
- : _sample(sample), _volume(volume) { silence = false; }
-
+ SampleElement (SGSharedPtr<SGSoundSample> sample, float volume = 1.0);
+
virtual void play (float volume);
virtual void stop ();
virtual bool is_playing ();
SGSoundSample *get_sample (const char *name);
inline void append (Voice *voice, Voice::Element *element) { voice->append(element); }
- inline void append (Voice *voice, const char *sample_name) { voice->append(new Voice::SampleElement(get_sample(sample_name))); }
+ void append (Voice *voice, const char *sample_name);
inline void append (Voice *voice, double silence) { voice->append(new Voice::SilenceElement(silence)); }
inline void make_voice (Voice **voice) { *voice = new Voice(this); _voices.push_back(*voice); }