Homepage Demos Overview Downloads Tutorials Reference
Credits

SoundNode.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_SoundNode_h_
00003 #define INCLUDED_SoundNode_h_
00004 
00005 #include "Behaviors/StateNode.h"
00006 #include "Events/EventRouter.h"
00007 #include "SoundPlay/SoundManager.h"
00008 
00009 //! A simple StateNode that plays a sound upon startup and throws a status event on completion
00010 class SoundNode : public StateNode {
00011 protected:
00012   std::string filename;
00013   SoundManager::Play_ID curplay_id;
00014 
00015 public:
00016   //! constructor
00017   SoundNode(std::string nodename="SoundNode", std::string soundfilename="") : 
00018     StateNode("SoundNode",nodename), filename(soundfilename), curplay_id(SoundManager::invalid_Play_ID) {}
00019 
00020   //! activate the node
00021   virtual void DoStart() {
00022     curplay_id = sndman->PlayFile(filename);
00023     erouter->addListener(this,EventBase::audioEGID,curplay_id,EventBase::deactivateETID);
00024     StateNode::DoStart();  // don't activate transitions until our listener has been added
00025   }
00026 
00027   //! deactivate the node
00028   virtual void DoStop() {
00029     erouter->removeListener(this);
00030     StateNode::DoStop();
00031   }
00032 
00033   //! receive audioEGID status event and throw stateMachineEGID status event
00034   virtual void processEvent(const EventBase&) {
00035     erouter->postEvent(EventBase::stateMachineEGID,reinterpret_cast<unsigned int>(this),EventBase::statusETID,0,getName(),1);
00036   }
00037 
00038   //! interrupts playing of the current sound
00039   void StopPlay() {
00040     sndman->StopPlay(curplay_id);
00041     curplay_id = SoundManager::invalid_Play_ID;
00042   }
00043 
00044   //! returns the name of the sound file associated with this node
00045   std::string getFileName() { return filename; }
00046 
00047   //! sets the name of the sound file associated with this node
00048   void setFileName(std::string &soundfilename) { filename = soundfilename; }
00049 
00050 protected:
00051   //! constructor
00052   SoundNode(std::string &classname, std::string &nodename, std::string &soundfilename) : 
00053     StateNode(classname,nodename), filename(soundfilename), curplay_id(SoundManager::invalid_Play_ID) {}
00054 
00055 
00056 
00057 };
00058 
00059 /*! @file
00060  * @brief Defines SoundNode, a simple StateNode that plays a sound and throws a status event upon completion
00061  * @author dst (Creator)
00062  *
00063  * $Author: dst $
00064  * $Name: tekkotsu-2_2_1 $
00065  * $Revision: 1.8 $
00066  * $State: Exp $
00067  * $Date: 2004/11/17 01:31:06 $
00068  */
00069 
00070 #endif

Tekkotsu v2.2.1
Generated Tue Nov 23 16:36:40 2004 by Doxygen 1.3.9.1