NLSOUND::CBackgroundSound Class Reference

#include <background_sound.h>

Inheritance diagram for NLSOUND::CBackgroundSound:

NLSOUND::CSound

Detailed Description

A background sound static properties
Author:
Boris Boucher

Nevrax France

Date:
2002

Definition at line 46 of file background_sound.h.

Public Types

enum  TSOUND_TYPE { SOUND_SIMPLE, SOUND_COMPLEX, SOUND_BACKGROUND, SOUND_CONTEXT }

Public Member Functions

 CBackgroundSound ()
 Constructor.

float getConeInnerAngle () const
 Return the inner angle of the cone.

float getConeOuterAngle () const
 Return the outer angle of the cone.

float getConeOuterGain () const
 Return the outer gain of the cone.

const NLMISC::CVectorgetDirectionVector () const
 Return the direction vector.

virtual uint32 getDuration ()
 Return the length of the sound in ms.

float getGain () const
 Return the gain.

bool getLooping () const
 Return the looping state.

virtual float getMaxDistance () const
 Return the max distance (if detailed()).

const NLMISC::TStringIdgetName () const
 Return the name (must be unique).

float getPitch () const
 Return the pitch.

TSoundPriority getPriority () const
 Return the initial priority.

const std::vector< TSoundInfo > & getSounds () const
TSOUND_TYPE getSoundType ()
 Get the type of the sound.

virtual void getSubSoundList (std::vector< std::pair< std::string, CSound * > > &subsounds) const
 Return the name (must be unique) Used by the george sound plugin to check sound recursion (ie sound 'toto' use sound 'titi' witch also use sound 'toto' ...).

NLMISC::TStringId getUserVarControler ()
virtual void importForm (const std::string &filename, NLGEORGES::UFormElm &formRoot)
 Load the sound parameters from georges' form.

bool isDetailed () const
 Return true if cone is meaningful.

bool operator< (const CSound &otherSound) const
void serial (NLMISC::IStream &s)
void setLooping (bool looping)
 Set looping.

 ~CBackgroundSound ()
 Destructor.


Static Public Member Functions

CSoundcreateSound (const std::string &filename, NLGEORGES::UFormElm &formRoot)
 Factory for specialized sound.


Protected Attributes

float _ConeInnerAngle
float _ConeOuterAngle
float _ConeOuterGain
NLMISC::CVector _Direction
float _Gain
bool _Looping
float _MaxDist
 Clipping distance for complex or backgound sound.

NLMISC::TStringId _Name
float _Pitch
TSoundPriority _Priority
NLMISC::TStringId _UserVarControler
 An optional user var controler.


Private Attributes

uint32 _Duration
bool _DurationValid
std::vector< TSoundInfo_Sounds
 The list of sound composing the background sound with there repective filter.


Member Enumeration Documentation

enum NLSOUND::CSound::TSOUND_TYPE [inherited]
 

Enumeration values:
SOUND_SIMPLE 
SOUND_COMPLEX 
SOUND_BACKGROUND 
SOUND_CONTEXT 

Definition at line 67 of file sound.h.

00068         {
00069                 SOUND_SIMPLE,
00070                 SOUND_COMPLEX,
00071                 SOUND_BACKGROUND,
00072                 SOUND_CONTEXT
00073         };


Constructor & Destructor Documentation

NLSOUND::CBackgroundSound::CBackgroundSound  ) 
 

Constructor.

Definition at line 43 of file background_sound.cpp.

00044 : _Duration(0), _DurationValid(false)
00045 {
00046 }

NLSOUND::CBackgroundSound::~CBackgroundSound  ) 
 

Destructor.

Definition at line 48 of file background_sound.cpp.

00049 {
00050 }


Member Function Documentation

CSound * NLSOUND::CSound::createSound const std::string &  filename,
NLGEORGES::UFormElm formRoot
[static, inherited]
 

Factory for specialized sound.

Definition at line 43 of file sound.cpp.

References NLGEORGES::UFormElm::getDfnName(), NLGEORGES::UFormElm::getNodeByName(), NLSOUND::CSound::importForm(), nlassertex, and nlwarning.

00044 {
00045         NL_ALLOC_CONTEXT(NLSOUND_CSound);
00046         CSound *ret = NULL;
00047         string  soundType;
00048 
00049         NLGEORGES::UFormElm *psoundType;
00050 
00051         if (!formRoot.getNodeByName(&psoundType, ".SoundType"))
00052         {
00053                 nlwarning("No SoundType in : %s", filename.c_str());
00054                 return 0;
00055         }
00056 
00057         if (psoundType != NULL)
00058         {
00059                 std::string dfnName;
00060                 psoundType->getDfnName(dfnName);
00061 
00062                 if (dfnName == "simple_sound.dfn")
00063                 {
00064                         ret = new CSimpleSound();
00065                         ret->importForm(filename, formRoot);
00066                 }
00067                 else if (dfnName == "complex_sound.dfn")
00068                 {
00069                         ret = new CComplexSound();
00070                         ret->importForm(filename, formRoot);
00071                 }
00072                 else if (dfnName == "background_sound.dfn")
00073                 {
00074                         ret = new CBackgroundSound();
00075                         ret->importForm(filename, formRoot);
00076                 }
00077                 else if (dfnName == "context_sound.dfn")
00078                 {
00079                         ret = new CContextSound();
00080                         ret->importForm(filename, formRoot);
00081                 }
00082                 else
00083                 {
00084                         nlassertex(false, ("SoundType unsuported : %s", dfnName.c_str()));
00085                 }
00086                         
00087         }
00088 
00089         return ret;
00090 }

float NLSOUND::CSound::getConeInnerAngle  )  const [inline, inherited]
 

Return the inner angle of the cone.

Definition at line 98 of file sound.h.

References NLSOUND::CSound::_ConeInnerAngle.

Referenced by NLSOUND::CSimpleSource::setDirection().

00098 { return _ConeInnerAngle; }

float NLSOUND::CSound::getConeOuterAngle  )  const [inline, inherited]
 

Return the outer angle of the cone.

Definition at line 100 of file sound.h.

References NLSOUND::CSound::_ConeOuterAngle.

Referenced by NLSOUND::CSimpleSource::setDirection().

00100 { return _ConeOuterAngle; }

float NLSOUND::CSound::getConeOuterGain  )  const [inline, inherited]
 

Return the outer gain of the cone.

Definition at line 102 of file sound.h.

References NLSOUND::CSound::_ConeOuterGain.

Referenced by NLSOUND::CSimpleSource::setDirection().

00102 { return _ConeOuterGain; }

const NLMISC::CVector& NLSOUND::CSound::getDirectionVector  )  const [inline, inherited]
 

Return the direction vector.

Definition at line 104 of file sound.h.

00104 { return _Direction;}

uint32 NLSOUND::CBackgroundSound::getDuration  )  [virtual]
 

Return the length of the sound in ms.

Implements NLSOUND::CSound.

Definition at line 121 of file background_sound.cpp.

References _Duration, _DurationValid, NLSOUND::CSound::getDuration(), NLSOUND::CAudioMixerUser::getSoundId(), and uint32.

00122 {
00123         if (_DurationValid)
00124                 return _Duration;
00125 
00126         vector<sint32>  durations;
00127         CAudioMixerUser *mixer = CAudioMixerUser::instance();
00128         std::vector<TSoundInfo>::const_iterator first(_Sounds.begin()), last(_Sounds.end());
00129         for (; first != last; ++first)
00130         {
00131                 CSound *sound = mixer->getSoundId(first->SoundName);
00132                 if (sound != NULL)
00133                         durations.push_back(sound->getDuration());
00134         }
00135         if (durations.empty())
00136                 return 0;
00137         _Duration = *(std::max_element(durations.begin(), durations.end()));
00138         _DurationValid = true;
00139 
00140         return _Duration;
00141 }

float NLSOUND::CSound::getGain void   )  const [inline, inherited]
 

Return the gain.

Definition at line 90 of file sound.h.

Referenced by NLSOUND::CAudioMixerUser::addUserControledSource(), NLSOUND::CComplexSource::CComplexSource(), NLSOUND::CAudioMixerUser::createSource(), and NLSOUND::CBackgroundSource::updateFilterValues().

00090 { return _Gain; }

bool NLSOUND::CSound::getLooping  )  const [inline, inherited]
 

Return the looping state.

Definition at line 88 of file sound.h.

References NLSOUND::CSound::_Looping.

Referenced by NLSOUND::CComplexSource::CComplexSource(), and NLSOUND::CComplexSource::checkup().

00088 { return _Looping; }

float NLSOUND::CBackgroundSound::getMaxDistance  )  const [virtual]
 

Return the max distance (if detailed()).

Reimplemented from NLSOUND::CSound.

Definition at line 154 of file background_sound.cpp.

References NLSOUND::CSound::getMaxDistance(), and NLSOUND::CAudioMixerUser::getSoundId().

00155 {
00156         CAudioMixerUser *mixer = CAudioMixerUser::instance();
00157         float ret = 0.0f;
00158         std::vector<TSoundInfo>::const_iterator first(_Sounds.begin()), last(_Sounds.end());
00159         for (; first != last; ++first)
00160         {
00161                 CSound *sound = mixer->getSoundId(first->SoundName);
00162                 if (sound != 0)
00163                 {
00164                         ret = max(ret, sound->getMaxDistance());
00165                 }
00166         }
00167         if (ret == 0)
00168                 ret  = 1;
00169 
00170         return ret;
00171 }

const NLMISC::TStringId& NLSOUND::CSound::getName void   )  const [inline, inherited]
 

Return the name (must be unique).

Definition at line 108 of file sound.h.

Referenced by NLSOUND::CSoundBank::addSound(), NLSOUND::CContextSoundContainer< NbJoker, UseRandom, Shift >::addSound(), and NLSOUND::CComplexSource::onUpdate().

00108 { return _Name; }

float NLSOUND::CSound::getPitch void   )  const [inline, inherited]
 

Return the pitch.

Definition at line 92 of file sound.h.

Referenced by NLSOUND::CComplexSource::CComplexSource(), NLSOUND::CAudioMixerUser::createSource(), NLSOUND::CComplexSource::onEvent(), NLSOUND::CComplexSource::playStuf(), and NLSOUND::CBackgroundSource::updateFilterValues().

00092 { return _Pitch; }

TSoundPriority NLSOUND::CSound::getPriority void   )  const [inline, inherited]
 

Return the initial priority.

Definition at line 94 of file sound.h.

References NLSOUND::CSound::_Priority, and NLSOUND::TSoundPriority.

Referenced by NLSOUND::CComplexSource::CComplexSource().

00094 { return _Priority; }

const std::vector<TSoundInfo>& NLSOUND::CBackgroundSound::getSounds  )  const [inline]
 

Definition at line 95 of file background_sound.h.

Referenced by NLSOUND::CBackgroundSource::play().

00095 { return _Sounds;}

TSOUND_TYPE NLSOUND::CBackgroundSound::getSoundType  )  [inline, virtual]
 

Get the type of the sound.

Implements NLSOUND::CSound.

Definition at line 54 of file background_sound.h.

00054 { return SOUND_BACKGROUND;}

void NLSOUND::CBackgroundSound::getSubSoundList std::vector< std::pair< std::string, CSound * > > &  subsounds  )  const [virtual]
 

Return the name (must be unique) Used by the george sound plugin to check sound recursion (ie sound 'toto' use sound 'titi' witch also use sound 'toto' ...).

Implements NLSOUND::CSound.

Definition at line 143 of file background_sound.cpp.

References NLSOUND::CAudioMixerUser::getSoundId().

00144 {
00145         CAudioMixerUser *mixer = CAudioMixerUser::instance();
00146         std::vector<TSoundInfo>::const_iterator first(_Sounds.begin()), last(_Sounds.end());
00147         for (; first != last; ++first)
00148         {
00149                 CSound *sound = mixer->getSoundId(first->SoundName);
00150                 subsounds.push_back(make_pair(CStringMapper::unmap(first->SoundName), sound));
00151         }
00152 }

NLMISC::TStringId NLSOUND::CSound::getUserVarControler  )  [inline, inherited]
 

Definition at line 121 of file sound.h.

References NLSOUND::CSound::_UserVarControler.

00121 { return _UserVarControler; }

void NLSOUND::CBackgroundSound::importForm const std::string &  filename,
NLGEORGES::UFormElm formRoot
[virtual]
 

Load the sound parameters from georges' form.

Reimplemented from NLSOUND::CSound.

Definition at line 62 of file background_sound.cpp.

References _DurationValid, NLSOUND::CBackgroundSound::TSoundInfo::Filter, NLSOUND::UAudioMixer::TBackgroundFlags::Flags, NLGEORGES::UFormElm::getArrayNode(), NLGEORGES::UFormElm::getArraySize(), NLGEORGES::UFormElm::getDfnName(), NLGEORGES::UFormElm::getNodeByName(), NLGEORGES::UFormElm::getValueByName(), NLGEORGES::UFormElm::isArray(), nlassert, size, NLSOUND::CBackgroundSound::TSoundInfo::SoundName, and uint.

00063 {
00064         NLGEORGES::UFormElm *psoundType;
00065         std::string dfnName;
00066 
00067         // some basic checking.
00068         formRoot.getNodeByName(&psoundType, ".SoundType");
00069         nlassert(psoundType != NULL);
00070         psoundType->getDfnName(dfnName);
00071         nlassert(dfnName == "background_sound.dfn");
00072 
00073         // Call the base class
00074         CSound::importForm(filename, formRoot);
00075 
00076         // Read the array of sound with there respective filter.
00077         {
00078                 _Sounds.clear();
00079 
00080                 NLGEORGES::UFormElm *psoundList;
00081 
00082                 formRoot.getNodeByName(&psoundList, ".SoundType.Sounds");
00083 
00084                 if (psoundList != 0 && psoundList->isArray())
00085                 {
00086                         uint size;
00087                         psoundList->getArraySize(size);
00088 
00089                         for (uint i=0; i<size; ++i)
00090                         {
00091                                 TSoundInfo      sound;
00092                                 NLGEORGES::UFormElm     *psoundItem;
00093 
00094                                 psoundList->getArrayNode(&psoundItem, i);
00095 
00096                                 if (psoundItem != NULL)
00097                                 {
00098                                         // Read the sound name.
00099                                         std::string soundName;
00100                                         psoundItem->getValueByName(soundName, "Sound");
00101                                         sound.SoundName = CStringMapper::map(CFile::getFilenameWithoutExtension(soundName));
00102 
00103 
00104                                         // Read the environnement flag.
00105                                         for (uint j=0; j<UAudioMixer::TBackgroundFlags::NB_BACKGROUND_FLAGS; j++)
00106                                         {
00107                                                 char tmp[200];
00108                                                 sprintf(tmp, "Filter%2.2u", j);
00109                                                 psoundItem->getValueByName(sound.Filter.Flags[j], tmp);
00110                                         }
00111                                 }
00112 
00113                                 _Sounds.push_back(sound);
00114                         }
00115                 }
00116         }
00117 
00118         _DurationValid = false;
00119 }

bool NLSOUND::CBackgroundSound::isDetailed  )  const [inline, virtual]
 

Return true if cone is meaningful.

Implements NLSOUND::CSound.

Definition at line 60 of file background_sound.h.

00060 { return false;}

bool NLSOUND::CSound::operator< const CSound otherSound  )  const [inline, inherited]
 

Definition at line 123 of file sound.h.

References NLSOUND::CSound::_Name, and NLMISC::CStringMapper::unmap().

00124         {
00125                 return NLMISC::CStringMapper::unmap(_Name) < NLMISC::CStringMapper::unmap(otherSound._Name);
00126         }

void NLSOUND::CBackgroundSound::serial NLMISC::IStream s  )  [virtual]
 

Reimplemented from NLSOUND::CSound.

Definition at line 52 of file background_sound.cpp.

References _DurationValid, and s.

00053 {
00054         CSound::serial(s);
00055 
00056         s.serialCont(_Sounds);
00057 
00058         if (s.isReading())
00059                 _DurationValid = false;
00060 }

void NLSOUND::CSound::setLooping bool  looping  )  [inline, inherited]
 

Set looping.

Definition at line 113 of file sound.h.

References NLSOUND::CSound::_Looping.

00113 { _Looping = looping; }


Field Documentation

float NLSOUND::CSound::_ConeInnerAngle [protected, inherited]
 

Definition at line 134 of file sound.h.

Referenced by NLSOUND::CSound::getConeInnerAngle(), NLSOUND::CSound::importForm(), and NLSOUND::CSound::serial().

float NLSOUND::CSound::_ConeOuterAngle [protected, inherited]
 

Definition at line 134 of file sound.h.

Referenced by NLSOUND::CSound::getConeOuterAngle(), NLSOUND::CSound::importForm(), and NLSOUND::CSound::serial().

float NLSOUND::CSound::_ConeOuterGain [protected, inherited]
 

Definition at line 134 of file sound.h.

Referenced by NLSOUND::CSound::getConeOuterGain(), NLSOUND::CSound::importForm(), and NLSOUND::CSound::serial().

NLMISC::CVector NLSOUND::CSound::_Direction [protected, inherited]
 

Definition at line 135 of file sound.h.

uint32 NLSOUND::CBackgroundSound::_Duration [private]
 

Definition at line 105 of file background_sound.h.

Referenced by getDuration().

bool NLSOUND::CBackgroundSound::_DurationValid [private]
 

Definition at line 107 of file background_sound.h.

Referenced by getDuration(), importForm(), and serial().

float NLSOUND::CSound::_Gain [protected, inherited]
 

Definition at line 131 of file sound.h.

bool NLSOUND::CSound::_Looping [protected, inherited]
 

Definition at line 137 of file sound.h.

Referenced by NLSOUND::CSound::getLooping(), NLSOUND::CSound::importForm(), NLSOUND::CSound::serial(), and NLSOUND::CSound::setLooping().

float NLSOUND::CSound::_MaxDist [protected, inherited]
 

Clipping distance for complex or backgound sound.

Definition at line 140 of file sound.h.

Referenced by NLSOUND::CComplexSound::getMaxDistance().

NLMISC::TStringId NLSOUND::CSound::_Name [protected, inherited]
 

Definition at line 143 of file sound.h.

Referenced by NLSOUND::CSound::operator<().

float NLSOUND::CSound::_Pitch [protected, inherited]
 

Definition at line 132 of file sound.h.

TSoundPriority NLSOUND::CSound::_Priority [protected, inherited]
 

Definition at line 133 of file sound.h.

Referenced by NLSOUND::CSound::getPriority(), NLSOUND::CSound::importForm(), and NLSOUND::CSound::serial().

std::vector<TSoundInfo> NLSOUND::CBackgroundSound::_Sounds [private]
 

The list of sound composing the background sound with there repective filter.

Definition at line 101 of file background_sound.h.

NLMISC::TStringId NLSOUND::CSound::_UserVarControler [protected, inherited]
 

An optional user var controler.

Definition at line 145 of file sound.h.

Referenced by NLSOUND::CSound::getUserVarControler(), and NLSOUND::CAudioMixerUser::initUserVar().


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