- now lives as part of the sound-manager, yay.
return true;
}
-/**
- * Built-in command: play an audio message (i.e. a wav file) This is
- * fire and forget. Call this once per message and it will get dumped
- * into a queue. Messages are played sequentially so they do not
- * overlap.
- */
-static bool
-do_play_audio_sample (const SGPropertyNode * arg)
-{
- SGSoundMgr *smgr = globals->get_subsystem<SGSoundMgr>();
- 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");
- // cout << "playing " << path << " / " << file << endl;
- try {
- FGSampleQueue *queue = globals->get_chatter_queue();
- if ( !queue ) {
- queue = new FGSampleQueue(smgr, "chatter");
- queue->tie_to_listener();
- globals->set_chatter_queue(queue);
- }
-
- SGSoundSample *msg = new SGSoundSample(file.c_str(), path);
- msg->set_volume( volume );
- queue->add( msg );
-
- return true;
-
- } catch (const sg_io_exception&) {
- SG_LOG(SG_GENERAL, SG_ALERT, "play-audio-sample: "
- "failed to load" << path << '/' << file);
- return false;
- }
-}
-
/**
* Built-in command: commit presets (read from in /sim/presets/)
*/
{ "open-browser", do_open_browser },
{ "gui-redraw", do_gui_redraw },
{ "add-model", do_add_model },
- { "play-audio-sample", do_play_audio_sample },
{ "presets-commit", do_presets_commit },
{ "log-level", do_log_level },
{ "replay", do_replay },
globals->set_renderer(NULL);
globals->set_matlib(NULL);
- globals->set_chatter_queue(NULL);
simgear::clearEffectCache();
simgear::SGModelLib::resetPropertyRoot();
#include <Navaids/navlist.hxx>
#include <Viewer/renderer.hxx>
#include <Viewer/viewmgr.hxx>
-#include <Sound/sample_queue.hxx>
#include "globals.hxx"
#include "locale.hxx"
channel_options_list( NULL ),
initial_waypoints( NULL ),
channellist( NULL ),
- haveUserSettings(false),
- _chatter_queue(NULL)
+ haveUserSettings(false)
{
SGPropertyNode* root = new SGPropertyNode;
props = SGPropertyNode_ptr(root);
// renderer touches subsystems during its destruction
set_renderer(NULL);
- _chatter_queue.clear();
delete subsystem_mgr;
subsystem_mgr = NULL; // important so ::get_subsystem returns NULL
return get_subsystem<FGControls>();
}
-FGSampleQueue* FGGlobals::get_chatter_queue() const
-{
- return _chatter_queue;
-}
-
-void FGGlobals::set_chatter_queue(FGSampleQueue* queue)
-{
- _chatter_queue = queue;
-}
-
void FGGlobals::addListenerToCleanup(SGPropertyChangeListener* l)
{
_listeners_to_cleanup.push_back(l);
class FGViewMgr;
class FGViewer;
class FGRenderer;
-class FGSampleQueue;
namespace simgear { namespace pkg {
class Root;
* helper to initialise standard properties on a new property tree
*/
void initProperties();
-
- SGSharedPtr<FGSampleQueue> _chatter_queue;
-
+
void cleanupListeners();
typedef std::vector<SGPropertyChangeListener*> SGPropertyChangeListenerVec;
*/
void saveUserSettings();
- FGSampleQueue* get_chatter_queue() const;
- void set_chatter_queue(FGSampleQueue* queue);
-
void addListenerToCleanup(SGPropertyChangeListener* l);
simgear::pkg::Root* packageRoot();
#endif
#include <simgear/sound/soundmgr_openal.hxx>
+#include <simgear/structure/commands.hxx>
#if defined(ENABLE_FLITE)
#include "VoiceSynthesizer.hxx"
#endif
+
+#include "sample_queue.hxx"
#include "soundmanager.hxx"
#include "Main/globals.hxx"
#include "Main/fg_props.hxx"
SGPropertyNode_ptr scenery_loaded = fgGetNode("sim/sceneryloaded", true);
scenery_loaded->addChangeListener(_listener.get());
+ globals->get_commands()->addCommand("play-audio-sample", this, &FGSoundManager::playAudioSampleCommand);
+
+
reinit();
}
scenery_loaded->removeChangeListener(_listener.get());
stop();
-
+
+ _chatterQueue.clear();
+ globals->get_commands()->removeCommand("play-audio-sample");
+
+
SGSoundMgr::shutdown();
}
}
}
+/**
+ * Built-in command: play an audio message (i.e. a wav file) This is
+ * fire and forget. Call this once per message and it will get dumped
+ * into a queue. Messages are played sequentially so they do not
+ * overlap.
+ */
+bool FGSoundManager::playAudioSampleCommand(const SGPropertyNode * arg)
+{
+ string path = arg->getStringValue("path");
+ string file = arg->getStringValue("file");
+ float volume = arg->getFloatValue("volume");
+ // cout << "playing " << path << " / " << file << endl;
+ try {
+ if ( !_chatterQueue ) {
+ _chatterQueue = new FGSampleQueue(this, "chatter");
+ _chatterQueue->tie_to_listener();
+ }
+
+ SGSoundSample *msg = new SGSoundSample(file.c_str(), path);
+ msg->set_volume( volume );
+ _chatterQueue->add( msg );
+
+ return true;
+
+ } catch (const sg_io_exception&) {
+ SG_LOG(SG_GENERAL, SG_ALERT, "play-audio-sample: "
+ "failed to load" << path << '/' << file);
+ return false;
+ }
+}
+
#if defined(ENABLE_FLITE)
VoiceSynthesizer * FGSoundManager::getSynthesizer( const std::string & voice )
{
#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/sound/soundmgr_openal.hxx>
+class FGSampleQueue;
class SGSoundMgr;
class Listener;
#if defined(ENABLE_FLITE)
#endif
private:
bool stationaryView() const;
-
+
+ bool playAudioSampleCommand(const SGPropertyNode * arg);
+
+ SGSharedPtr<FGSampleQueue> _chatterQueue;
+
bool _is_initialized, _enabled;
SGPropertyNode_ptr _sound_working, _sound_enabled, _volume, _device_name;
SGPropertyNode_ptr _currentView;