SoundNode.h
Go to the documentation of this file.00001
00002 #ifndef INCLUDED_SoundNode_h_
00003 #define INCLUDED_SoundNode_h_
00004
00005 #include "Behaviors/StateNode.h"
00006 #include "Events/EventRouter.h"
00007 #include "Sound/SoundManager.h"
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 class SoundNode : public StateNode {
00018 public:
00019
00020 SoundNode(const std::string& soundfilename="") :
00021 StateNode(), filename(soundfilename), curplay_id(SoundManager::invalid_Play_ID), autostop(false) {}
00022
00023
00024 SoundNode(const std::string& nodename, const std::string& soundfilename) :
00025 StateNode(nodename), filename(soundfilename), curplay_id(SoundManager::invalid_Play_ID), autostop(false) {}
00026
00027
00028 virtual void preStart() {
00029 StateNode::preStart();
00030 if(event!=NULL) {
00031 const DataEvent<std::string>* ev = dynamic_cast<const DataEvent<std::string>*>(event);
00032 if ( ev != NULL )
00033 filename = ev->getData();
00034 }
00035 }
00036
00037 virtual void postStart() {
00038 StateNode::postStart();
00039 startPlaying();
00040 }
00041
00042
00043 virtual void stop() {
00044 if(autostop)
00045 stopPlay();
00046 StateNode::stop();
00047 }
00048
00049
00050 virtual void doEvent() {
00051 curplay_id = SoundManager::invalid_Play_ID;
00052 postStateCompletion();
00053 }
00054
00055
00056 void stopPlay() {
00057 sndman->stopPlay(curplay_id);
00058 curplay_id = SoundManager::invalid_Play_ID;
00059 }
00060
00061
00062 std::string getFileName() { return filename; }
00063
00064
00065 void setFileName(std::string &soundfilename) { filename = soundfilename; }
00066
00067
00068 bool getAutoStop() { return autostop; }
00069
00070
00071 void setAutoStop(bool astop) { autostop=astop; }
00072
00073 protected:
00074 virtual void startPlaying() {
00075 if(filename.size()>0) {
00076 curplay_id = sndman->playFile(filename);
00077 erouter->addListener(this,EventBase::audioEGID,curplay_id,EventBase::deactivateETID);
00078 }
00079 }
00080
00081 std::string filename;
00082 SoundManager::Play_ID curplay_id;
00083 bool autostop;
00084
00085 };
00086
00087
00088
00089
00090
00091
00092 #endif