| 1 | // _samplequeue.cxx -- Sound effect management class implementation |
| 2 | // |
| 3 | // Started by David Megginson, October 2001 |
| 4 | // (Reuses some code from main.cxx, probably by Curtis Olson) |
| 5 | // |
| 6 | // Copyright (C) 2001 Curtis L. Olson - http://www.flightgear.org/~curt |
| 7 | // |
| 8 | // This program is free software; you can redistribute it and/or |
| 9 | // modify it under the terms of the GNU General Public License as |
| 10 | // published by the Free Software Foundation; either version 2 of the |
| 11 | // License, or (at your option) any later version. |
| 12 | // |
| 13 | // This program is distributed in the hope that it will be useful, but |
| 14 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | // General Public License for more details. |
| 17 | // |
| 18 | // You should have received a copy of the GNU General Public License |
| 19 | // along with this program; if not, write to the Free Software |
| 20 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 21 | // |
| 22 | // $Id$ |
| 23 | |
| 24 | #ifdef _MSC_VER |
| 25 | #pragma warning (disable: 4786) |
| 26 | #endif |
| 27 | |
| 28 | #ifdef HAVE_CONFIG_H |
| 29 | # include <config.h> |
| 30 | #endif |
| 31 | |
| 32 | #include "sample_queue.hxx" |
| 33 | |
| 34 | #include <Main/fg_props.hxx> |
| 35 | |
| 36 | #include <simgear/sound/soundmgr.hxx> |
| 37 | #include <simgear/sound/sample.hxx> |
| 38 | |
| 39 | FGSampleQueue::FGSampleQueue ( SGSoundMgr *smgr, const std::string &refname ) : |
| 40 | last_enabled( true ), |
| 41 | last_volume( 0.0 ), |
| 42 | _enabled( fgGetNode("/sim/sound/"+refname+"/enabled", true) ), |
| 43 | _volume( fgGetNode("/sim/sound/"+refname+"/volume", true) ) |
| 44 | { |
| 45 | SGSampleGroup::_smgr = smgr; |
| 46 | SGSampleGroup::_smgr->add(this, refname); |
| 47 | SGSampleGroup::_refname = refname; |
| 48 | } |
| 49 | |
| 50 | |
| 51 | FGSampleQueue::~FGSampleQueue () |
| 52 | { |
| 53 | } |
| 54 | |
| 55 | |
| 56 | void |
| 57 | FGSampleQueue::update (double dt) |
| 58 | { |
| 59 | // command sound manger |
| 60 | bool new_enabled = _enabled->getBoolValue(); |
| 61 | if ( new_enabled != last_enabled ) { |
| 62 | if ( new_enabled ) { |
| 63 | resume(); |
| 64 | } else { |
| 65 | suspend(); |
| 66 | } |
| 67 | last_enabled = new_enabled; |
| 68 | } |
| 69 | |
| 70 | if ( new_enabled ) { |
| 71 | double volume = _volume->getDoubleValue(); |
| 72 | if ( volume != last_volume ) { |
| 73 | set_volume( volume ); |
| 74 | last_volume = volume; |
| 75 | } |
| 76 | |
| 77 | // process message queue |
| 78 | const std::string msgid = "Sequential Audio Message"; |
| 79 | bool now_playing = false; |
| 80 | if ( exists( msgid ) ) { |
| 81 | now_playing = is_playing( msgid ); |
| 82 | if ( !now_playing ) { |
| 83 | // current message finished, stop and remove |
| 84 | stop( msgid ); // removes source |
| 85 | remove( msgid ); // removes buffer |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | if ( !now_playing ) { |
| 90 | // message queue idle, add next sound if we have one |
| 91 | if ( ! _messages.empty() ) { |
| 92 | SGSampleGroup::add( _messages.front(), msgid ); |
| 93 | _messages.pop(); |
| 94 | play_once( msgid ); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | SGSampleGroup::update(dt); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | // end of _samplequeue.cxx |