1
0
Fork 0

Chatter-queue moved out of globals

- now lives as part of the sound-manager, yay.
This commit is contained in:
James Turner 2016-01-01 14:53:02 -06:00
parent fc9c43b48d
commit c400405b0a
6 changed files with 50 additions and 65 deletions

View file

@ -1061,46 +1061,6 @@ do_add_model (const SGPropertyNode * arg)
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/)
*/
@ -1470,7 +1430,6 @@ static struct {
{ "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 },

View file

@ -1069,7 +1069,6 @@ void fgStartNewReset()
globals->set_renderer(NULL);
globals->set_matlib(NULL);
globals->set_chatter_queue(NULL);
simgear::clearEffectCache();
simgear::SGModelLib::resetPropertyRoot();

View file

@ -54,7 +54,6 @@
#include <Navaids/navlist.hxx>
#include <Viewer/renderer.hxx>
#include <Viewer/viewmgr.hxx>
#include <Sound/sample_queue.hxx>
#include "globals.hxx"
#include "locale.hxx"
@ -160,8 +159,7 @@ FGGlobals::FGGlobals() :
channel_options_list( NULL ),
initial_waypoints( NULL ),
channellist( NULL ),
haveUserSettings(false),
_chatter_queue(NULL)
haveUserSettings(false)
{
SGPropertyNode* root = new SGPropertyNode;
props = SGPropertyNode_ptr(root);
@ -224,7 +222,6 @@ FGGlobals::~FGGlobals()
// renderer touches subsystems during its destruction
set_renderer(NULL);
_chatter_queue.clear();
delete subsystem_mgr;
subsystem_mgr = NULL; // important so ::get_subsystem returns NULL
@ -720,16 +717,6 @@ FGControls *FGGlobals::get_controls() const
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);

View file

@ -63,7 +63,6 @@ class FGTileMgr;
class FGViewMgr;
class FGViewer;
class FGRenderer;
class FGSampleQueue;
namespace simgear { namespace pkg {
class Root;
@ -140,9 +139,7 @@ private:
* helper to initialise standard properties on a new property tree
*/
void initProperties();
SGSharedPtr<FGSampleQueue> _chatter_queue;
void cleanupListeners();
typedef std::vector<SGPropertyChangeListener*> SGPropertyChangeListenerVec;
@ -341,9 +338,6 @@ public:
*/
void saveUserSettings();
FGSampleQueue* get_chatter_queue() const;
void set_chatter_queue(FGSampleQueue* queue);
void addListenerToCleanup(SGPropertyChangeListener* l);
simgear::pkg::Root* packageRoot();

View file

@ -22,10 +22,13 @@
#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"
@ -87,6 +90,9 @@ void FGSoundManager::init()
SGPropertyNode_ptr scenery_loaded = fgGetNode("sim/sceneryloaded", true);
scenery_loaded->addChangeListener(_listener.get());
globals->get_commands()->addCommand("play-audio-sample", this, &FGSoundManager::playAudioSampleCommand);
reinit();
}
@ -96,7 +102,11 @@ void FGSoundManager::shutdown()
scenery_loaded->removeChangeListener(_listener.get());
stop();
_chatterQueue.clear();
globals->get_commands()->removeCommand("play-audio-sample");
SGSoundMgr::shutdown();
}
@ -202,6 +212,37 @@ void FGSoundManager::update(double dt)
}
}
/**
* 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 )
{

View file

@ -26,6 +26,7 @@
#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/sound/soundmgr_openal.hxx>
class FGSampleQueue;
class SGSoundMgr;
class Listener;
#if defined(ENABLE_FLITE)
@ -51,7 +52,11 @@ public:
#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;