Chatter-queue moved out of globals
- now lives as part of the sound-manager, yay.
This commit is contained in:
parent
fc9c43b48d
commit
c400405b0a
6 changed files with 50 additions and 65 deletions
|
@ -1061,46 +1061,6 @@ do_add_model (const SGPropertyNode * arg)
|
||||||
return true;
|
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/)
|
* Built-in command: commit presets (read from in /sim/presets/)
|
||||||
*/
|
*/
|
||||||
|
@ -1470,7 +1430,6 @@ static struct {
|
||||||
{ "open-browser", do_open_browser },
|
{ "open-browser", do_open_browser },
|
||||||
{ "gui-redraw", do_gui_redraw },
|
{ "gui-redraw", do_gui_redraw },
|
||||||
{ "add-model", do_add_model },
|
{ "add-model", do_add_model },
|
||||||
{ "play-audio-sample", do_play_audio_sample },
|
|
||||||
{ "presets-commit", do_presets_commit },
|
{ "presets-commit", do_presets_commit },
|
||||||
{ "log-level", do_log_level },
|
{ "log-level", do_log_level },
|
||||||
{ "replay", do_replay },
|
{ "replay", do_replay },
|
||||||
|
|
|
@ -1069,7 +1069,6 @@ void fgStartNewReset()
|
||||||
|
|
||||||
globals->set_renderer(NULL);
|
globals->set_renderer(NULL);
|
||||||
globals->set_matlib(NULL);
|
globals->set_matlib(NULL);
|
||||||
globals->set_chatter_queue(NULL);
|
|
||||||
|
|
||||||
simgear::clearEffectCache();
|
simgear::clearEffectCache();
|
||||||
simgear::SGModelLib::resetPropertyRoot();
|
simgear::SGModelLib::resetPropertyRoot();
|
||||||
|
|
|
@ -54,7 +54,6 @@
|
||||||
#include <Navaids/navlist.hxx>
|
#include <Navaids/navlist.hxx>
|
||||||
#include <Viewer/renderer.hxx>
|
#include <Viewer/renderer.hxx>
|
||||||
#include <Viewer/viewmgr.hxx>
|
#include <Viewer/viewmgr.hxx>
|
||||||
#include <Sound/sample_queue.hxx>
|
|
||||||
|
|
||||||
#include "globals.hxx"
|
#include "globals.hxx"
|
||||||
#include "locale.hxx"
|
#include "locale.hxx"
|
||||||
|
@ -160,8 +159,7 @@ FGGlobals::FGGlobals() :
|
||||||
channel_options_list( NULL ),
|
channel_options_list( NULL ),
|
||||||
initial_waypoints( NULL ),
|
initial_waypoints( NULL ),
|
||||||
channellist( NULL ),
|
channellist( NULL ),
|
||||||
haveUserSettings(false),
|
haveUserSettings(false)
|
||||||
_chatter_queue(NULL)
|
|
||||||
{
|
{
|
||||||
SGPropertyNode* root = new SGPropertyNode;
|
SGPropertyNode* root = new SGPropertyNode;
|
||||||
props = SGPropertyNode_ptr(root);
|
props = SGPropertyNode_ptr(root);
|
||||||
|
@ -224,7 +222,6 @@ FGGlobals::~FGGlobals()
|
||||||
|
|
||||||
// renderer touches subsystems during its destruction
|
// renderer touches subsystems during its destruction
|
||||||
set_renderer(NULL);
|
set_renderer(NULL);
|
||||||
_chatter_queue.clear();
|
|
||||||
|
|
||||||
delete subsystem_mgr;
|
delete subsystem_mgr;
|
||||||
subsystem_mgr = NULL; // important so ::get_subsystem returns NULL
|
subsystem_mgr = NULL; // important so ::get_subsystem returns NULL
|
||||||
|
@ -720,16 +717,6 @@ FGControls *FGGlobals::get_controls() const
|
||||||
return get_subsystem<FGControls>();
|
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)
|
void FGGlobals::addListenerToCleanup(SGPropertyChangeListener* l)
|
||||||
{
|
{
|
||||||
_listeners_to_cleanup.push_back(l);
|
_listeners_to_cleanup.push_back(l);
|
||||||
|
|
|
@ -63,7 +63,6 @@ class FGTileMgr;
|
||||||
class FGViewMgr;
|
class FGViewMgr;
|
||||||
class FGViewer;
|
class FGViewer;
|
||||||
class FGRenderer;
|
class FGRenderer;
|
||||||
class FGSampleQueue;
|
|
||||||
|
|
||||||
namespace simgear { namespace pkg {
|
namespace simgear { namespace pkg {
|
||||||
class Root;
|
class Root;
|
||||||
|
@ -140,9 +139,7 @@ private:
|
||||||
* helper to initialise standard properties on a new property tree
|
* helper to initialise standard properties on a new property tree
|
||||||
*/
|
*/
|
||||||
void initProperties();
|
void initProperties();
|
||||||
|
|
||||||
SGSharedPtr<FGSampleQueue> _chatter_queue;
|
|
||||||
|
|
||||||
void cleanupListeners();
|
void cleanupListeners();
|
||||||
|
|
||||||
typedef std::vector<SGPropertyChangeListener*> SGPropertyChangeListenerVec;
|
typedef std::vector<SGPropertyChangeListener*> SGPropertyChangeListenerVec;
|
||||||
|
@ -341,9 +338,6 @@ public:
|
||||||
*/
|
*/
|
||||||
void saveUserSettings();
|
void saveUserSettings();
|
||||||
|
|
||||||
FGSampleQueue* get_chatter_queue() const;
|
|
||||||
void set_chatter_queue(FGSampleQueue* queue);
|
|
||||||
|
|
||||||
void addListenerToCleanup(SGPropertyChangeListener* l);
|
void addListenerToCleanup(SGPropertyChangeListener* l);
|
||||||
|
|
||||||
simgear::pkg::Root* packageRoot();
|
simgear::pkg::Root* packageRoot();
|
||||||
|
|
|
@ -22,10 +22,13 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <simgear/sound/soundmgr_openal.hxx>
|
#include <simgear/sound/soundmgr_openal.hxx>
|
||||||
|
#include <simgear/structure/commands.hxx>
|
||||||
|
|
||||||
#if defined(ENABLE_FLITE)
|
#if defined(ENABLE_FLITE)
|
||||||
#include "VoiceSynthesizer.hxx"
|
#include "VoiceSynthesizer.hxx"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "sample_queue.hxx"
|
||||||
#include "soundmanager.hxx"
|
#include "soundmanager.hxx"
|
||||||
#include "Main/globals.hxx"
|
#include "Main/globals.hxx"
|
||||||
#include "Main/fg_props.hxx"
|
#include "Main/fg_props.hxx"
|
||||||
|
@ -87,6 +90,9 @@ void FGSoundManager::init()
|
||||||
SGPropertyNode_ptr scenery_loaded = fgGetNode("sim/sceneryloaded", true);
|
SGPropertyNode_ptr scenery_loaded = fgGetNode("sim/sceneryloaded", true);
|
||||||
scenery_loaded->addChangeListener(_listener.get());
|
scenery_loaded->addChangeListener(_listener.get());
|
||||||
|
|
||||||
|
globals->get_commands()->addCommand("play-audio-sample", this, &FGSoundManager::playAudioSampleCommand);
|
||||||
|
|
||||||
|
|
||||||
reinit();
|
reinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +102,11 @@ void FGSoundManager::shutdown()
|
||||||
scenery_loaded->removeChangeListener(_listener.get());
|
scenery_loaded->removeChangeListener(_listener.get());
|
||||||
|
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
|
_chatterQueue.clear();
|
||||||
|
globals->get_commands()->removeCommand("play-audio-sample");
|
||||||
|
|
||||||
|
|
||||||
SGSoundMgr::shutdown();
|
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)
|
#if defined(ENABLE_FLITE)
|
||||||
VoiceSynthesizer * FGSoundManager::getSynthesizer( const std::string & voice )
|
VoiceSynthesizer * FGSoundManager::getSynthesizer( const std::string & voice )
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <simgear/structure/subsystem_mgr.hxx>
|
#include <simgear/structure/subsystem_mgr.hxx>
|
||||||
#include <simgear/sound/soundmgr_openal.hxx>
|
#include <simgear/sound/soundmgr_openal.hxx>
|
||||||
|
|
||||||
|
class FGSampleQueue;
|
||||||
class SGSoundMgr;
|
class SGSoundMgr;
|
||||||
class Listener;
|
class Listener;
|
||||||
#if defined(ENABLE_FLITE)
|
#if defined(ENABLE_FLITE)
|
||||||
|
@ -51,7 +52,11 @@ public:
|
||||||
#endif
|
#endif
|
||||||
private:
|
private:
|
||||||
bool stationaryView() const;
|
bool stationaryView() const;
|
||||||
|
|
||||||
|
bool playAudioSampleCommand(const SGPropertyNode * arg);
|
||||||
|
|
||||||
|
SGSharedPtr<FGSampleQueue> _chatterQueue;
|
||||||
|
|
||||||
bool _is_initialized, _enabled;
|
bool _is_initialized, _enabled;
|
||||||
SGPropertyNode_ptr _sound_working, _sound_enabled, _volume, _device_name;
|
SGPropertyNode_ptr _sound_working, _sound_enabled, _volume, _device_name;
|
||||||
SGPropertyNode_ptr _currentView;
|
SGPropertyNode_ptr _currentView;
|
||||||
|
|
Loading…
Add table
Reference in a new issue