]> git.mxchange.org Git - flightgear.git/commitdiff
Split up FGFX into a dedicated effects class (FGFX) and a sample queue class. Registe...
authorehofman <ehofman>
Wed, 7 Oct 2009 20:56:24 +0000 (20:56 +0000)
committerTim Moore <timoore@redhat.com>
Thu, 8 Oct 2009 08:38:10 +0000 (10:38 +0200)
src/Main/fg_commands.cxx
src/Sound/Makefile.am
src/Sound/fg_fx.cxx
src/Sound/fg_fx.hxx
src/Sound/sample_queue.cxx [new file with mode: 0644]
src/Sound/sample_queue.hxx [new file with mode: 0644]

index ab6a15844df8542af151037960ff1efce5da0384..52b892a41d9d35991e1caf731d007e3fedc67ef1 100644 (file)
@@ -34,7 +34,7 @@
 #include <Scenery/tilemgr.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scripting/NasalSys.hxx>
-#include <Sound/fg_fx.hxx>
+#include <Sound/sample_queue.hxx>
 #include <Time/sunsolver.hxx>
 #include <Time/tmp.hxx>
 
@@ -1254,15 +1254,20 @@ do_play_audio_sample (const SGPropertyNode * arg)
 {
     string path = arg->getStringValue("path");
     string file = arg->getStringValue("file");
-    double volume = arg->getDoubleValue("volume");
+    float volume = arg->getFloatValue("volume");
     // cout << "playing " << path << " / " << file << endl;
     try {
-        static FGFX *fx = 0;
-        if ( !fx ) {
+        static FGSampleQueue *queue = 0;
+        if ( !queue ) {
            SGSoundMgr *smgr = (SGSoundMgr *)globals->get_subsystem("soundmgr");
-           fx = (FGFX *)smgr->find("fx");
+           queue = new FGSampleQueue(smgr, "queue");
+           queue->tie_to_listener();
         }
-        if (fx) fx->play_message( path, file, volume );
+
+        SGSoundSample *msg = new SGSoundSample(path.c_str(), file.c_str());
+        msg->set_volume( volume );
+        queue->add( msg );
+
         return true;
 
     } catch (const sg_io_exception&) {
index cbbb364f00f616ed4711f769751645457f8c1edb..1512dd36943dead850dcc07bd357cb83397d644c 100644 (file)
@@ -4,6 +4,7 @@ libSound_a_SOURCES = \
        beacon.cxx beacon.hxx \
        fg_fx.cxx fg_fx.hxx \
        morse.cxx morse.hxx \
-       voice.cxx voice.hxx
+       voice.cxx voice.hxx \
+       sample_queue.cxx sample_queue.hxx
 
 INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/src
index da6fcece3cca9bccbcee4cdcaedccc039610c3ae..6e06fa403830ef91b14ff2d93e903bff41a76400 100644 (file)
 
 #include "fg_fx.hxx"
 
-#include <simgear/debug/logstream.hxx>
-#include <simgear/structure/exception.hxx>
-#include <simgear/misc/sg_path.hxx>
+#include <Main/fg_props.hxx>
+
 #include <simgear/props/props.hxx>
+#include <simgear/misc/sg_path.hxx>
 #include <simgear/sound/soundmgr_openal.hxx>
 #include <simgear/sound/xmlsound.hxx>
 
-#include <Main/fg_props.hxx>
-
-#include <simgear/scene/model/placement.hxx>
-#include <Model/acmodel.hxx>
-#include <Main/viewer.hxx>
-
 FGFX::FGFX ( SGSoundMgr *smgr, const string &refname ) :
-    last_visitor_pos(SGVec3d::zeros()),
-    last_model_pos(SGVec3d::zeros()),
     last_pause( true ),
     last_volume( 0.0 ),
     _pause( fgGetNode("/sim/sound/pause") ),
@@ -60,16 +52,10 @@ FGFX::FGFX ( SGSoundMgr *smgr, const string &refname ) :
 
 FGFX::~FGFX ()
 {
-    unsigned int i;
-    for ( i = 0; i < _sound.size(); i++ ) {
+    for (unsigned int i = 0; i < _sound.size(); i++ ) {
         delete _sound[i];
     }
     _sound.clear();
-
-    while ( _samplequeue.size() > 0 ) {
-        delete _samplequeue.front();
-        _samplequeue.pop();
-    }
 }
 
 
@@ -139,28 +125,6 @@ FGFX::update (double dt)
         last_pause = new_pause;
     }
 
-    // process mesage queue
-    const string msgid = "Sequential Audio Message";
-    bool now_playing = false;
-    if ( exists( msgid ) ) {
-        if ( is_playing( msgid ) ) {
-            // still playing, do nothing
-            now_playing = true;
-        } else {
-            // current message finished, stop and remove
-            stop( msgid );   // removes source
-            remove( msgid ); // removes buffer
-        }
-    }
-    if ( !now_playing ) {
-        // message queue idle, add next sound if we have one
-        if ( _samplequeue.size() > 0 ) {
-            add( _samplequeue.front(), msgid );
-            _samplequeue.pop();
-            play_once( msgid );
-        }
-    }
-
     double volume = _volume->getDoubleValue();
     if ( volume != last_volume ) {
         set_volume( volume );        
@@ -177,21 +141,4 @@ FGFX::update (double dt)
     SGSampleGroup::update(dt);
 }
 
-/**
- * add a sound sample to the message queue which is played sequentially
- * in order.
- */
-void
-FGFX::play_message( SGSoundSample *_sample )
-{
-     _samplequeue.push( _sample );
-}
-void
-FGFX::play_message( const std::string& path, const std::string& fname, double volume )
-{
-    SGSoundSample *sample = new SGSoundSample( path.c_str(), fname.c_str() );
-    sample->set_volume( volume );
-    play_message( sample );
-}
-
 // end of fg_fx.cxx
index 76d38915f6b09ccd584145e2287a409928da6e49..62e111076ba3fb06671acc30e4ed12f4f42d900d 100644 (file)
 
 #include <simgear/compiler.h>
 
-#include <queue>
 #include <vector>
 
 #include <simgear/structure/subsystem_mgr.hxx>
 #include <simgear/sound/sample_group.hxx>
-#include <simgear/math/SGMath.hxx>
 
 class SGXmlSound;
 
@@ -39,17 +37,11 @@ class SGXmlSound;
  * Generator for FlightGear sound effects.
  *
  * This module uses a FGSampleGroup class to generate sound effects based
- * on current flight conditions.  The sound manager must be initialized
+ * on current flight conditions. The sound manager must be initialized
  * before this object is.
  *
- * Note: this module supports two separate sound mechanisms concurrently.
- *
- * 1. This module will load and play a set of sound effects defined in an
+ *    This module will load and play a set of sound effects defined in an
  *    xml file and tie them to various property states.
- * 2. This modules also maintains a queue of 'message' audio files.  These
- *    are played sequentially with no overlap until the queue is finished.
- *    This second mechanims is useful for things like tutorial messages or
- *    background atc chatter.
  */
 class FGFX : public SGSampleGroup
 {
@@ -63,22 +55,9 @@ public:
     virtual void reinit ();
     virtual void update (double dt);
 
-    /**
-     * add a sound sample to the message queue which is played sequentially
-     * in order.
-     */
-    void play_message( SGSoundSample *_sample );
-    void play_message( const std::string& path, const std::string& fname, double volume );
-
 private:
 
-    void update_pos_and_orientation(double dt);
-
-    SGVec3d last_visitor_pos;
-    SGVec3d last_model_pos;
-
     std::vector<SGXmlSound *> _sound;
-    std::queue<SGSoundSample *> _samplequeue;
 
     bool last_pause;
     double last_volume;
diff --git a/src/Sound/sample_queue.cxx b/src/Sound/sample_queue.cxx
new file mode 100644 (file)
index 0000000..30adf60
--- /dev/null
@@ -0,0 +1,104 @@
+// _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 ) :
+    last_pause( true ),
+    last_volume( 0.0 ),
+    _pause( fgGetNode("/sim/sound/pause") ),
+    _volume( fgGetNode("/sim/sound/volume") )
+{
+    SGSampleGroup::_smgr = smgr;
+    SGSampleGroup::_smgr->add(this, refname);
+    SGSampleGroup::_active = _smgr->is_working();
+}
+
+
+FGSampleQueue::~FGSampleQueue ()
+{
+    while ( _messages.size() > 0 ) {
+        delete _messages.front();
+        _messages.pop();
+    }
+}
+
+
+void
+FGSampleQueue::update (double dt)
+{
+    // command sound manger
+    bool new_pause = _pause->getBoolValue();
+    if ( new_pause != last_pause ) {
+        if ( new_pause ) {
+            suspend();
+        } else {
+            resume();
+        }
+        last_pause = new_pause;
+    }
+
+    double volume = _volume->getDoubleValue();
+    if ( volume != last_volume ) {
+        set_volume( volume );
+        last_volume = volume;
+    }
+
+    // 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
+        }
+    }
+
+    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 );
+        }
+    }
+
+    SGSampleGroup::update(dt);
+}
+
+// end of _samplequeue.cxx
diff --git a/src/Sound/sample_queue.hxx b/src/Sound/sample_queue.hxx
new file mode 100644 (file)
index 0000000..c874ae3
--- /dev/null
@@ -0,0 +1,70 @@
+// sample_queue.hxx -- sample queue management class
+//
+// 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$
+
+#ifndef __FGSAMPLE_QUEUE_HXX
+#define __FGSAMPLE_QUEUE_HXX 1
+
+#include <simgear/compiler.h>
+
+#include <queue>
+
+#include <simgear/structure/subsystem_mgr.hxx>
+#include <simgear/sound/sample_group.hxx>
+
+class SGSoundSample;
+
+/**
+ * FlightGear sample queue class
+ *
+ *    This modules maintains a queue of 'message' audio files.  These
+ *    are played sequentially with no overlap until the queue is finished.
+ *    This second mechanims is useful for things like tutorial messages or
+ *    background atc chatter.
+ */
+class FGSampleQueue : public SGSampleGroup
+{
+
+public:
+
+    FGSampleQueue ( SGSoundMgr *smgr, const string &refname );
+    virtual ~FGSampleQueue ();
+
+    virtual void update (double dt);
+
+    inline void add (SGSoundSample *msg) { _messages.push(msg); }
+
+private:
+
+    std::queue<SGSoundSample *> _messages;
+
+    bool last_pause;
+    double last_volume;
+
+    SGPropertyNode_ptr _pause;
+    SGPropertyNode_ptr _volume;
+};
+
+
+#endif
+
+// end of fg_fx.hxx