From dcec8063373f2c009b0e45eec206c364bb8913ec Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Tue, 29 May 2018 09:31:01 +0200 Subject: [PATCH] Allow for multiple named chatter queue's --- src/Sound/sample_queue.cxx | 4 ++-- src/Sound/soundmanager.cxx | 12 +++++++----- src/Sound/soundmanager.hxx | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/Sound/sample_queue.cxx b/src/Sound/sample_queue.cxx index 267bee3c9..a55fd6399 100644 --- a/src/Sound/sample_queue.cxx +++ b/src/Sound/sample_queue.cxx @@ -39,8 +39,8 @@ FGSampleQueue::FGSampleQueue ( SGSoundMgr *smgr, const std::string &refname ) : last_enabled( true ), last_volume( 0.0 ), - _enabled( fgGetNode("/sim/sound/chatter/enabled", true) ), - _volume( fgGetNode("/sim/sound/chatter/volume", true) ) + _enabled( fgGetNode("/sim/sound/"+refname+"/enabled", true) ), + _volume( fgGetNode("/sim/sound/"+refname+"/volume", true) ) { SGSampleGroup::_smgr = smgr; SGSampleGroup::_smgr->add(this, refname); diff --git a/src/Sound/soundmanager.cxx b/src/Sound/soundmanager.cxx index 45a921ac0..29bda3849 100644 --- a/src/Sound/soundmanager.cxx +++ b/src/Sound/soundmanager.cxx @@ -97,7 +97,7 @@ void FGSoundManager::shutdown() stop(); - _chatterQueue.clear(); + _queue.clear(); globals->get_commands()->removeCommand("play-audio-sample"); @@ -210,19 +210,21 @@ void FGSoundManager::update(double dt) */ bool FGSoundManager::playAudioSampleCommand(const SGPropertyNode * arg, SGPropertyNode * root) { + const char *qname = arg->getStringValue("queue"); + string name = qname ? qname : "chatter"; 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(); + if ( !_queue[name] ) { + _queue[name] = new FGSampleQueue(this, name); + _queue[name]->tie_to_listener(); } SGSoundSample *msg = new SGSoundSample(file.c_str(), path); msg->set_volume( volume ); - _chatterQueue->add( msg ); + _queue[name]->add( msg ); return true; diff --git a/src/Sound/soundmanager.hxx b/src/Sound/soundmanager.hxx index a200e21df..24e337dfa 100644 --- a/src/Sound/soundmanager.hxx +++ b/src/Sound/soundmanager.hxx @@ -55,7 +55,7 @@ private: bool playAudioSampleCommand(const SGPropertyNode * arg, SGPropertyNode * root); - SGSharedPtr _chatterQueue; + std::map> _queue; double _active_dt; bool _is_initialized, _enabled;