00001
00002 #ifndef INCLUDED_SoundTestBehavior_h_
00003 #define INCLUDED_SoundTestBehavior_h_
00004
00005 #include "Behaviors/BehaviorBase.h"
00006 #include "SoundPlay/SoundManager.h"
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 class SoundTestBehavior : public BehaviorBase {
00019 public:
00020
00021 SoundTestBehavior()
00022 : BehaviorBase(), curplay(SoundManager::invalid_Play_ID), endtime(0),
00023 LFr(EventBase::buttonEGID,ButtonSourceID::LFrPawSID,EventBase::activateETID),
00024 RFr(EventBase::buttonEGID,ButtonSourceID::RFrPawSID,EventBase::activateETID),
00025 LBk(EventBase::buttonEGID,ButtonSourceID::LBkPawSID,EventBase::activateETID),
00026 RBk(EventBase::buttonEGID,ButtonSourceID::RBkPawSID,EventBase::activateETID),
00027 Back(EventBase::buttonEGID,ButtonSourceID::BackButSID,EventBase::activateETID)
00028 {}
00029
00030
00031
00032 virtual void DoStart() {
00033 BehaviorBase::DoStart();
00034 erouter->addListener(this,EventBase::buttonEGID);
00035 sndman->LoadFile("yap.wav");
00036 sndman->LoadFile("howl.wav");
00037 sndman->LoadFile("whimper.wav");
00038 }
00039
00040
00041 virtual void DoStop() {
00042 BehaviorBase::DoStop();
00043 erouter->removeListener(this);
00044 sndman->ReleaseFile("howl.wav");
00045 sndman->ReleaseFile("yap.wav");
00046 sndman->ReleaseFile("whimper.wav");
00047 }
00048
00049
00050 virtual void processEvent(const EventBase& event) {
00051 if(event==LFr)
00052 play("howl.wav");
00053 else if(event==RFr)
00054 play("yap.wav");
00055 else if(event==LBk)
00056 play("whimper.wav");
00057 else if(event==RBk)
00058 play("growl.wav");
00059 else if(event==Back)
00060 play("barkmed.wav");
00061 else if(event.getSourceID()==ButtonSourceID::ChinButSID)
00062 if(event.getTypeID()==EventBase::activateETID) {
00063
00064 curplay=SoundManager::invalid_Play_ID;
00065 endtime=0;
00066 } else if(pauseWhileChin)
00067 sndman->ResumePlay(curplay);
00068 }
00069
00070
00071 virtual std::string getName() const { return "SoundTestBehavior"; }
00072 static std::string getClassDescription() { return "Plays different sounds when buttons are pressed. Holding the chin button queues the sounds."; }
00073 protected:
00074
00075 void play(const char* name) {
00076 if(!state->buttons[ChinButOffset]) {
00077
00078
00079
00080 sndman->PlayFile(name);
00081
00082 } else {
00083
00084
00085 if(curplay==SoundManager::invalid_Play_ID || !pauseWhileChin && get_time()>=endtime) {
00086
00087 curplay=sndman->PlayFile(name);
00088 if(pauseWhileChin)
00089 sndman->PausePlay(curplay);
00090 } else
00091 sndman->ChainFile(curplay,name);
00092 endtime=sndman->GetRemainTime(curplay)+get_time()-SoundBufferTime;
00093
00094
00095 }
00096 }
00097 static const bool pauseWhileChin=true;
00098 SoundManager::Play_ID curplay;
00099 unsigned int endtime;
00100
00101
00102
00103 EventBase LFr,RFr,LBk,RBk,Back;
00104
00105 };
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 #endif