NLSOUND::CSoundAnimManager Class Reference

#include <sound_anim_manager.h>


Detailed Description

The set of players.

Definition at line 76 of file sound_anim_manager.h.

Public Member Functions

virtual TSoundAnimId createAnimation (std::string &name)
 CSoundAnimManager (UAudioMixer *mixer)
virtual CSoundAnimationfindAnimation (std::string &name)
virtual TSoundAnimId getAnimationFromName (std::string &name)
virtual std::string idToName (TSoundAnimId id)
virtual bool isPlaying (TSoundAnimPlayId playbackId)
virtual TSoundAnimId loadAnimation (std::string &name)
virtual void playAnimation (TSoundAnimId id, float lastTime, float curTime, NL3D::CCluster *cluster, CSoundContext &context)
virtual TSoundAnimPlayId playAnimation (std::string &name, float time, NL3D::CCluster *cluster, CSoundContext &context)
virtual TSoundAnimPlayId playAnimation (TSoundAnimId id, float time, NL3D::CCluster *cluster, CSoundContext &context)
virtual void saveAnimation (CSoundAnimation *anim, std::string &filname)
virtual void stopAnimation (TSoundAnimPlayId playbackId)
virtual void update (float lastTime, float curTime)
virtual ~CSoundAnimManager ()

Static Public Member Functions

CSoundAnimManagerinstance ()
void release ()

Protected Attributes

TSoundAnimVector _Animations
TSoundAnimMap _IdMap
UAudioMixer_Mixer

Static Protected Attributes

CSoundAnimManager_Instance = 0


Constructor & Destructor Documentation

NLSOUND::CSoundAnimManager::CSoundAnimManager UAudioMixer mixer  ) 
 

Definition at line 44 of file sound_anim_manager.cpp.

00044                                                               : _Mixer(mixer) 
00045 {
00046         if (_Instance != 0)
00047         {
00048                 throw Exception("Duplicate instanciation of CSoundAnimManager singleton");
00049         }
00050 
00051         _Instance = this;
00052         //_PlayerId = 0;
00053 }

NLSOUND::CSoundAnimManager::~CSoundAnimManager  )  [virtual]
 

Definition at line 57 of file sound_anim_manager.cpp.

00058 {
00059         if (_Instance == NULL)
00060                 return;
00061         /*
00062         set<CSoundAnimPlayer*>::iterator iter;
00063 
00064         for (iter = _Players.begin(); iter != _Players.end(); iter++)
00065         {
00066                 CSoundAnimPlayer* player = *iter; 
00067                 delete player;
00068         }
00069 
00070         _Players.clear();
00071         */
00072 
00073         _Instance = NULL;
00074 }


Member Function Documentation

TSoundAnimId NLSOUND::CSoundAnimManager::createAnimation std::string &  name  )  [virtual]
 

Create a new sound animation with the specified name. Returns CSoundAnimation::NoId if the creation fails (duplicate name).

Parameters:
name The name of the animation to load.

Definition at line 120 of file sound_anim_manager.cpp.

References NLSOUND::CSoundAnimationNoId, NLSOUND::CSoundAnimation::getName(), nlassert, nlwarning, and NLSOUND::TSoundAnimId.

Referenced by loadAnimation().

00121 {
00122         NL_ALLOC_CONTEXT(NLSOUND_CSoundAnimManager);
00123         nlassert(!name.empty());
00124 
00125         // create and insert animations
00126         TSoundAnimId id = _Animations.size();
00127         CSoundAnimation* anim = new CSoundAnimation(name, id);
00128         _Animations.push_back(anim);
00129 
00130         // insert the name and id in the id table
00131         pair<TSoundAnimMap::iterator, bool> inserted;
00132         inserted =_IdMap.insert(make_pair(anim->getName().c_str(), id));
00133         if (!inserted.second) 
00134         {
00135                 nlwarning("Duplicate sound animation \"%s\"", name.c_str());
00136                 delete anim;
00137                 return CSoundAnimationNoId;
00138         }
00139 
00140         return id;
00141 }

CSoundAnimation * NLSOUND::CSoundAnimManager::findAnimation std::string &  name  )  [virtual]
 

Returns the animation corresponding to a name.

Parameters:
name The name of the animation to load.

Definition at line 145 of file sound_anim_manager.cpp.

00146 {
00147         TSoundAnimMap::iterator iter = _IdMap.find(name.c_str());
00148         return (iter == _IdMap.end())? 0 : _Animations[(*iter).second]; 
00149 }

TSoundAnimId NLSOUND::CSoundAnimManager::getAnimationFromName std::string &  name  )  [virtual]
 

Start playing a sound animation. Returns true is the animation was found and is playing.

Parameters:
name The name of the animation to load.

Definition at line 153 of file sound_anim_manager.cpp.

References NLSOUND::CSoundAnimationNoId, and NLSOUND::TSoundAnimId.

00154 {
00155         TSoundAnimMap::iterator iter = _IdMap.find(name.c_str());
00156         return (iter == _IdMap.end())? CSoundAnimationNoId : (*iter).second;    
00157 }

std::string NLSOUND::CSoundAnimManager::idToName TSoundAnimId  id  )  [virtual]
 

Convert back from an anim ID to the anim name.

Definition at line 206 of file sound_anim_manager.cpp.

References NLSOUND::TSoundAnimId.

00207 {
00208         static string empty;
00209         TSoundAnimMap::iterator it(std::find_if(_IdMap.begin(), _IdMap.end(), TFindId(id)));
00210 
00211         if (it != _IdMap.end())
00212                 return it->first;
00213         else
00214                 return empty;
00215 }

CSoundAnimManager* NLSOUND::CSoundAnimManager::instance  )  [inline, static]
 

Definition at line 80 of file sound_anim_manager.h.

00080 { return _Instance; }

bool NLSOUND::CSoundAnimManager::isPlaying TSoundAnimPlayId  playbackId  )  [virtual]
 

Returns true is the animation with the specified playback ID is playing

Parameters:
name The playback id that was returned by playAnimation.

Definition at line 273 of file sound_anim_manager.cpp.

References NLSOUND::TSoundAnimPlayId.

00274 {
00275         /*nlassert(playbackId >= 0);
00276 
00277         set<CSoundAnimPlayer*>::iterator iter;
00278 
00279         for (iter = _Players.begin(); iter != _Players.end(); )
00280         {
00281                 CSoundAnimPlayer* player = *iter; 
00282                 if (player->getId() == playbackId)
00283                 {
00284                         return player->isPlaying();
00285                 }
00286         }*/
00287 
00288         return false;
00289 }

TSoundAnimId NLSOUND::CSoundAnimManager::loadAnimation std::string &  name  )  [virtual]
 

Load the sound animation with the specified name. Returns the id of the new animation, or CSoundAnimationNoId is the file could not be found.

Parameters:
name The name of the animation to load.

Definition at line 78 of file sound_anim_manager.cpp.

References createAnimation(), NLSOUND::CSoundAnimationNoId, NLSOUND::CSoundAnimation::load(), nlassert, NLSOUND::CSoundAnimation::setFilename(), and NLSOUND::TSoundAnimId.

00079 {
00080         nlassert(!name.empty());
00081 
00082         string filename;
00083         if (name.find(".anim") != name.npos)
00084         {
00085                 filename = CFile::getFilenameWithoutExtension(name);
00086                 filename.append(".sound_anim");
00087         }
00088         else
00089         {
00090                 filename = name;
00091                 filename.append(".sound_anim");
00092         }
00093 
00094         // throws exception if file not found
00095         filename = CPath::lookup(filename, false, false, true);
00096         if (filename.empty())
00097         {
00098                 return CSoundAnimationNoId;
00099         }
00100 
00101         TSoundAnimId id = createAnimation(name);
00102         if (id == CSoundAnimationNoId)
00103         {
00104                 return CSoundAnimationNoId;
00105         }
00106 
00107         CSoundAnimation* anim = _Animations[id];
00108         
00109         if (anim == NULL)
00110                 return CSoundAnimationNoId;
00111 
00112         anim->setFilename(filename);
00113         anim->load();
00114 
00115         return id;
00116 }

void NLSOUND::CSoundAnimManager::playAnimation TSoundAnimId  id,
float  lastTime,
float  curTime,
NL3D::CCluster cluster,
CSoundContext context
[virtual]
 

Play all the events of an animation in the interval between lastTime and curTime. Both lastTime and curTime are measured relatively from the beginning of the animation.

Definition at line 218 of file sound_anim_manager.cpp.

References _Mixer, NLSOUND::CSoundAnimationNoId, nlassert, NLSOUND::CSoundAnimation::play(), NLSOUND::TSoundAnimId, and uint32.

00219 {
00220         //nlassert(id != CSoundAnimationNoId);
00221         if (id == CSoundAnimationNoId) 
00222         {
00223                 return;
00224         }
00225 
00226         if ((uint32) id >= _Animations.size())
00227                 return;
00228         nlassert((uint32) id < _Animations.size());
00229 
00230         CSoundAnimation* anim = _Animations[id];
00231         nlassert(anim);
00232 
00233         anim->play(_Mixer, lastTime, curTime, cluster, context);
00234 }

TSoundAnimPlayId NLSOUND::CSoundAnimManager::playAnimation std::string &  name,
float  time,
NL3D::CCluster cluster,
CSoundContext context
[virtual]
 

Start playing a sound animation. Returns an id number of this playback instance or -1 if the animation was not found.

Parameters:
name The name of the animation to play.

Definition at line 244 of file sound_anim_manager.cpp.

References NLSOUND::TSoundAnimPlayId.

00245 {
00246 /*      nlassert(position);
00247 
00248         TSoundAnimId id = getAnimationFromName(name);
00249         return (id == CSoundAnimation::NoId)? -1 : _PlayerId;*/
00250         return 0; 
00251 }

TSoundAnimPlayId NLSOUND::CSoundAnimManager::playAnimation TSoundAnimId  id,
float  time,
NL3D::CCluster cluster,
CSoundContext context
[virtual]
 

Start playing a sound animation. Returns an id number of this playback instance or -1 if the animation was not found.

Parameters:
name The id of the animation to play.

Definition at line 238 of file sound_anim_manager.cpp.

References NLSOUND::TSoundAnimId, and NLSOUND::TSoundAnimPlayId.

00239 {
00240         return 0;
00241 }

void NLSOUND::CSoundAnimManager::release void   )  [inline, static]
 

Definition at line 81 of file sound_anim_manager.h.

00081 { delete _Instance; }

void NLSOUND::CSoundAnimManager::saveAnimation CSoundAnimation anim,
std::string &  filname
[virtual]
 

Save the sound animation in the specified file.

Parameters:
filename The name of the file to save the animation in.

Definition at line 161 of file sound_anim_manager.cpp.

References nlassert, NLSOUND::CSoundAnimation::save(), and NLSOUND::CSoundAnimation::setFilename().

00162 {
00163         nlassert(anim);
00164         nlassert(!filename.empty());
00165 
00166         anim->setFilename(filename);
00167         anim->save ();
00168 }

void NLSOUND::CSoundAnimManager::stopAnimation TSoundAnimPlayId  playbackId  )  [virtual]
 

Stop the playing of a sound animation.

Parameters:
name The playback id that was returned by playAnimation.

Definition at line 255 of file sound_anim_manager.cpp.

References NLSOUND::TSoundAnimPlayId.

00256 {
00257 /*      nlassert(playbackId >= 0);
00258 
00259         set<CSoundAnimPlayer*>::iterator iter;
00260 
00261         for (iter = _Players.begin(); iter != _Players.end(); )
00262         {
00263                 CSoundAnimPlayer* player = *iter; 
00264                 if (player->getId() == playbackId)
00265                 {
00266                         _Players.erase(iter);
00267                         break;
00268                 }
00269         }*/
00270 }

void NLSOUND::CSoundAnimManager::update float  lastTime,
float  curTime
[virtual]
 

Update all the sound animations during playback.

Definition at line 292 of file sound_anim_manager.cpp.

00293 {
00294 /*      set<CSoundAnimPlayer*>::iterator iter;
00295 
00296         _Garbage.clear();
00297 
00298         for (iter = _Players.begin(); iter != _Players.end(); iter++)
00299         {
00300                 CSoundAnimPlayer* player = *iter; 
00301                 if (player->isPlaying())
00302                 {
00303                         player->update(lastTime, curTime);
00304                 }
00305                 else
00306                 {
00307                         _Garbage.push_back(player);
00308                 }
00309         }
00310 
00311         vector<CSoundAnimPlayer*>::iterator iter2;
00312 
00313         for (iter2 = _Garbage.begin(); iter2 != _Garbage.end(); iter2++)
00314         {
00315                 iter = _Players.find(*iter2);
00316                 if (iter != _Players.end())
00317                 {
00318                         _Players.erase(iter);
00319                 }
00320         }*/
00321 }


Field Documentation

TSoundAnimVector NLSOUND::CSoundAnimManager::_Animations [protected]
 

The vector of all defined animations

Definition at line 163 of file sound_anim_manager.h.

TSoundAnimMap NLSOUND::CSoundAnimManager::_IdMap [protected]
 

The conversion table from animation name to id

Definition at line 160 of file sound_anim_manager.h.

CSoundAnimManager * NLSOUND::CSoundAnimManager::_Instance = 0 [static, protected]
 

The one and only singleton instance

Definition at line 40 of file sound_anim_manager.cpp.

UAudioMixer* NLSOUND::CSoundAnimManager::_Mixer [protected]
 

The mixer

Definition at line 157 of file sound_anim_manager.h.

Referenced by playAnimation().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 14:42:49 2004 for NeL by doxygen 1.3.6