2009-10-07 20:56:24 +00:00
|
|
|
// _samplequeue.cxx -- Sound effect management class implementation
|
|
|
|
//
|
|
|
|
// Started by David Megginson, October 2001
|
|
|
|
// (Reuses some code from main.cxx, probably by Curtis Olson)
|
|
|
|
//
|
|
|
|
// Copyright (C) 2001 Curtis L. Olson - http://www.flightgear.org/~curt
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning (disable: 4786)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "sample_queue.hxx"
|
|
|
|
|
|
|
|
#include <Main/fg_props.hxx>
|
|
|
|
|
|
|
|
#include <simgear/sound/soundmgr_openal.hxx>
|
|
|
|
#include <simgear/sound/sample_openal.hxx>
|
|
|
|
|
|
|
|
FGSampleQueue::FGSampleQueue ( SGSoundMgr *smgr, const string &refname ) :
|
2009-11-29 10:24:47 +00:00
|
|
|
last_enabled( true ),
|
2009-10-07 20:56:24 +00:00
|
|
|
last_volume( 0.0 ),
|
2009-11-29 10:24:47 +00:00
|
|
|
_enabled( fgGetNode("/sim/sound/chatter/enabled", true) ),
|
|
|
|
_volume( fgGetNode("/sim/sound/chatter/volume", true) )
|
2009-10-07 20:56:24 +00:00
|
|
|
{
|
|
|
|
SGSampleGroup::_smgr = smgr;
|
|
|
|
SGSampleGroup::_smgr->add(this, refname);
|
2009-11-23 09:35:59 +00:00
|
|
|
SGSampleGroup::_refname = refname;
|
2009-11-29 10:24:47 +00:00
|
|
|
_enabled->setBoolValue(true);
|
|
|
|
_volume->setFloatValue(1.0);
|
2009-10-07 20:56:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FGSampleQueue::~FGSampleQueue ()
|
|
|
|
{
|
|
|
|
while ( _messages.size() > 0 ) {
|
|
|
|
delete _messages.front();
|
|
|
|
_messages.pop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
FGSampleQueue::update (double dt)
|
|
|
|
{
|
|
|
|
// command sound manger
|
2009-11-29 10:24:47 +00:00
|
|
|
bool new_enabled = _enabled->getBoolValue();
|
|
|
|
if ( new_enabled != last_enabled ) {
|
|
|
|
if ( new_enabled ) {
|
2009-10-07 20:56:24 +00:00
|
|
|
resume();
|
2009-11-29 10:24:47 +00:00
|
|
|
} else {
|
|
|
|
suspend();
|
2009-10-07 20:56:24 +00:00
|
|
|
}
|
2009-11-29 10:24:47 +00:00
|
|
|
last_enabled = new_enabled;
|
2009-10-07 20:56:24 +00:00
|
|
|
}
|
|
|
|
|
2009-11-29 10:24:47 +00:00
|
|
|
if ( new_enabled ) {
|
2009-10-19 10:41:17 +00:00
|
|
|
double volume = _volume->getDoubleValue();
|
|
|
|
if ( volume != last_volume ) {
|
|
|
|
set_volume( volume );
|
|
|
|
last_volume = volume;
|
|
|
|
}
|
2009-10-07 20:56:24 +00:00
|
|
|
|
2009-10-19 10:41:17 +00:00
|
|
|
// process mesage queue
|
|
|
|
const string msgid = "Sequential Audio Message";
|
|
|
|
bool now_playing = false;
|
|
|
|
if ( exists( msgid ) ) {
|
|
|
|
now_playing = is_playing( msgid );
|
|
|
|
if ( !now_playing ) {
|
|
|
|
// current message finished, stop and remove
|
|
|
|
stop( msgid ); // removes source
|
|
|
|
remove( msgid ); // removes buffer
|
|
|
|
}
|
2009-10-07 20:56:24 +00:00
|
|
|
}
|
|
|
|
|
2009-10-19 10:41:17 +00:00
|
|
|
if ( !now_playing ) {
|
|
|
|
// message queue idle, add next sound if we have one
|
|
|
|
if ( _messages.size() > 0 ) {
|
|
|
|
SGSampleGroup::add( _messages.front(), msgid );
|
|
|
|
_messages.pop();
|
|
|
|
play_once( msgid );
|
|
|
|
}
|
2009-10-07 20:56:24 +00:00
|
|
|
}
|
|
|
|
|
2009-10-19 10:41:17 +00:00
|
|
|
SGSampleGroup::update(dt);
|
|
|
|
}
|
2009-10-07 20:56:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// end of _samplequeue.cxx
|