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