#include <context_sound.h>
Inheritance diagram for NLSOUND::CContextSound:

Public Types | |
| enum | TSOUND_TYPE { SOUND_SIMPLE, SOUND_COMPLEX, SOUND_BACKGROUND, SOUND_CONTEXT } |
Public Member Functions | |
| CContextSound () | |
| 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. | |
| CSound * | getContextSound (CSoundContext &context) |
| const NLMISC::CVector & | getDirectionVector () 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. | |
| float | getMaxDistance () const |
| Return the max distance (if detailed()). | |
| const NLMISC::TStringId & | getName () const |
| Return the name (must be unique). | |
| float | getPitch () const |
| Return the pitch. | |
| TSoundPriority | getPriority () const |
| Return the initial priority. | |
| TSOUND_TYPE | getSoundType () |
| Get the type of the sound. | |
| virtual void | getSubSoundList (std::vector< std::pair< std::string, CSound * > > &subsounds) const |
| 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. | |
| void | init () |
| virtual 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. | |
| ~CContextSound () | |
| Destructor. | |
Static Public Member Functions | |
| CSound * | createSound (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 | |
| std::string | _BaseName |
| The base name, that is the constante part of the name (before the first joker). | |
| IContextSoundContainer * | _ContextSounds |
| container for all the candidate sounds | |
| std::string | _PatternName |
| The context sound pattern name. | |
| uint32 | _Random |
| The random lenght (0 mean no random). | |
|
|
Definition at line 67 of file sound.h.
00068 {
00069 SOUND_SIMPLE,
00070 SOUND_COMPLEX,
00071 SOUND_BACKGROUND,
00072 SOUND_CONTEXT
00073 };
|
|
|
Constructor.
Definition at line 42 of file context_sound.cpp.
00043 : _ContextSounds(0) 00044 { 00045 } |
|
|
Destructor.
Definition at line 47 of file context_sound.cpp.
00048 {
00049 if (_ContextSounds != 0)
00050 delete _ContextSounds;
00051 }
|
|
||||||||||||
|
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 }
|
|
|
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; }
|
|
|
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; }
|
|
|
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; }
|
|
|
Definition at line 135 of file context_sound.cpp. References NLSOUND::IContextSoundContainer::getSound(), init(), NLSOUND::CSoundContext::PreviousRandom, r, and uint32. Referenced by NLSOUND::CAudioMixerUser::createSource().
00136 {
00137 if (_ContextSounds == 0)
00138 {
00139 // need to init the sound container.
00140 init();
00141
00142 if (_ContextSounds == 0)
00143 return 0;
00144 }
00145
00146 if (_Random > 1)
00147 {
00148 // compute the random value.
00149 uint32 r;
00150 do
00151 {
00152 r = rand()%_Random;
00153 } while (r == context.PreviousRandom);
00154
00155 context.PreviousRandom = r;
00156
00157 return _ContextSounds->getSound(context, r);
00158 }
00159 else
00160 return _ContextSounds->getSound(context, 0);
00161
00162
00163 }
|
|
|
Return the direction vector.
Definition at line 104 of file sound.h.
00104 { return _Direction;}
|
|
|
Return the length of the sound in ms.
Implements NLSOUND::CSound. Definition at line 106 of file context_sound.cpp. References getSubSoundList(), and uint32.
00107 {
00108 std::vector<std::pair<std::string, CSound*> > sounds;
00109 getSubSoundList(sounds);
00110
00111 uint32 duration = 0;
00112
00113 std::vector<std::pair<std::string, CSound*> >::iterator first(sounds.begin()), last(sounds.end());
00114 for (; first != last; ++first)
00115 {
00116 duration = std::max(duration, first->second->getDuration());
00117 }
00118 return duration;
00119 }
|
|
|
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; }
|
|
|
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; }
|
|
|
Return the max distance (if detailed()).
Reimplemented from NLSOUND::CSound. Definition at line 91 of file context_sound.cpp. References NLSOUND::IContextSoundContainer::getMaxDistance().
00092 {
00093 if (_ContextSounds == 0)
00094 {
00095 const_cast<CContextSound*>(this)->init();
00096 if (_ContextSounds == 0)
00097 {
00098 // invalid state
00099 return 0;
00100 }
00101 }
00102 return _ContextSounds->getMaxDistance();;
00103 }
|
|
|
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; }
|
|
|
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; }
|
|
|
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; }
|
|
|
Get the type of the sound.
Implements NLSOUND::CSound. Definition at line 287 of file context_sound.h.
00287 { return CSound::SOUND_CONTEXT; };
|
|
|
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 122 of file context_sound.cpp. References NLSOUND::IContextSoundContainer::getSoundList(). Referenced by getDuration().
00123 {
00124 if (_ContextSounds == 0)
00125 {
00126 const_cast<CContextSound*>(this)->init();
00127 }
00128
00129 if (_ContextSounds)
00130 {
00131 _ContextSounds->getSoundList(subsounds);
00132 }
00133 }
|
|
|
Definition at line 121 of file sound.h. References NLSOUND::CSound::_UserVarControler.
00121 { return _UserVarControler; }
|
|
||||||||||||
|
Load the sound parameters from georges' form.
Reimplemented from NLSOUND::CSound. Definition at line 67 of file context_sound.cpp. References _PatternName, NLGEORGES::UFormElm::getDfnName(), NLGEORGES::UFormElm::getNodeByName(), NLGEORGES::UFormElm::getValueByName(), and nlassert.
00068 {
00069 NLGEORGES::UFormElm *psoundType;
00070 std::string dfnName;
00071
00072 // some basic checking.
00073 formRoot.getNodeByName(&psoundType, ".SoundType");
00074 nlassert(psoundType != NULL);
00075 psoundType->getDfnName(dfnName);
00076 nlassert(dfnName == "context_sound.dfn");
00077
00078 // Call the base class
00079 CSound::importForm(filename, formRoot);
00080
00081 // Read the pattern name
00082 formRoot.getValueByName(_PatternName, ".SoundType.PatternName");
00083 }
|
|
|
Definition at line 165 of file context_sound.cpp. References _BaseName, _PatternName, NLSOUND::IContextSoundContainer::addSound(), index, NLSOUND::IContextSoundContainer::init(), LM_CASE_CONTAINER_CREATOR, nlassert, nldebug, nlwarning, and uint. Referenced by getContextSound().
00166 {
00167 NL_ALLOC_CONTEXT(NLSOUND_CContextSound);
00168 uint nbJoker = 0;
00169 uint contextArgIndex[SoundContextNbArgs];
00170 bool useRandom = false;
00171 bool parseArg = false;
00172 _BaseName = "";
00173
00174 nldebug("Init the context sound %s", _PatternName.c_str());
00175
00176 string::iterator first(_PatternName.begin()), last(_PatternName.end());
00177 // 1st loop until the first joker
00178 for(; first != last && *first != '%'; ++first)
00179 _BaseName += *first;
00180
00181 // 2nd loop, now we read the context arg index for each joker.
00182 std::string index;
00183 for (; first != last; ++first)
00184 {
00185 if (parseArg)
00186 {
00187 if (isdigit(int(*first)))
00188 {
00189 index += *first;
00190 }
00191 else if (!index.empty())
00192 {
00193 if (useRandom)
00194 {
00195 _Random = atoi(index.c_str());
00196 }
00197 else
00198 {
00199 nlassert(nbJoker < SoundContextNbArgs);
00200 contextArgIndex[nbJoker++] = atoi(index.c_str());
00201 parseArg = false;
00202 index = "";
00203 }
00204 }
00205 else if (*first == 'r')
00206 {
00207 nlassert(useRandom == false);
00208 useRandom = true;
00209 }
00210 }
00211 else if (*first == '%')
00212 {
00213 nlassert(useRandom == false);
00214 parseArg = true;
00215 }
00216 }
00217
00218 // read the last char...
00219 if (!index.empty())
00220 {
00221 if (useRandom)
00222 {
00223 _Random = atoi(index.c_str());
00224 }
00225 else
00226 {
00227 nlassert(nbJoker < SoundContextNbArgs);
00228 contextArgIndex[nbJoker++] = atoi(index.c_str());
00229 parseArg = false;
00230 }
00231 }
00232
00233 if (_ContextSounds != 0)
00234 delete _ContextSounds;
00235
00236 // A little macro to make life easier (LM stand for Local Macro)
00237 #define LM_CASE_CONTAINER_CREATOR(size) case (size):\
00238 if (useRandom)\
00239 _ContextSounds = new CContextSoundContainer<(size), true>;\
00240 else\
00241 _ContextSounds = new CContextSoundContainer<(size), false>;\
00242 break;
00243
00244 // ok, now instantiate the correct container
00245 switch (nbJoker)
00246 {
00247 LM_CASE_CONTAINER_CREATOR(0)
00248 LM_CASE_CONTAINER_CREATOR(1)
00249 LM_CASE_CONTAINER_CREATOR(2)
00250 LM_CASE_CONTAINER_CREATOR(3)
00251 LM_CASE_CONTAINER_CREATOR(4)
00252 LM_CASE_CONTAINER_CREATOR(5)
00253 LM_CASE_CONTAINER_CREATOR(6)
00254 LM_CASE_CONTAINER_CREATOR(7)
00255 LM_CASE_CONTAINER_CREATOR(8)
00256 LM_CASE_CONTAINER_CREATOR(9)
00257 LM_CASE_CONTAINER_CREATOR(10)
00258 default:
00259 nlwarning("Unsuported number of context argument !");
00260 return;
00261 }
00262 // cleanup macro
00263 #undef LM_CASE_CONTAINER_CREATOR
00264
00265 _ContextSounds->init(contextArgIndex);
00266
00267 // ok, we have the container, now fill it with the sound
00268 {
00269 std::vector<NLMISC::TStringId> allSounds;
00270 // CSoundBank::getSoundNames(allSounds);
00271 CAudioMixerUser::instance()->getSoundNames(allSounds);
00272
00273 std::vector<NLMISC::TStringId>::iterator first(allSounds.begin()), last(allSounds.end());
00274 for (; first != last; ++first)
00275 {
00276 const std::string &soundName = CStringMapper::unmap(*first);
00277 if (soundName.size() > _BaseName.size())
00278 {
00279 uint i;
00280 for (i=0; i<_BaseName.size(); ++i)
00281 {
00282 if (soundName[i] != _BaseName[i])
00283 break;
00284 }
00285 if (i == _BaseName.size())
00286 {
00287 // The base name is ok, check that the next char is a digit (avoid conflit if some
00288 // sound have a longeur base name with same begining)
00289 if (soundName[i] >= '0' && soundName[i] <= '9')
00290 _ContextSounds->addSound(CAudioMixerUser::instance()->getSoundId(*first), _BaseName);
00291 }
00292 }
00293 }
00294 }
00295 }
|
|
|
Return true if cone is meaningful.
Implements NLSOUND::CSound. Definition at line 86 of file context_sound.cpp.
00087 {
00088 return false;
00089 }
|
|
|
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 }
|
|
|
Reimplemented from NLSOUND::CSound. Definition at line 53 of file context_sound.cpp. References _PatternName, and s.
00054 {
00055 CSound::serial(s);
00056 s.serial(_PatternName);
00057
00058 if (s.isReading())
00059 {
00060 if (_ContextSounds)
00061 delete _ContextSounds;
00062 }
00063 }
|
|
|
Set looping.
Definition at line 113 of file sound.h. References NLSOUND::CSound::_Looping.
00113 { _Looping = looping; }
|
|
|
The base name, that is the constante part of the name (before the first joker).
Definition at line 315 of file context_sound.h. Referenced by init(). |
|
|
Definition at line 134 of file sound.h. Referenced by NLSOUND::CSound::getConeInnerAngle(), NLSOUND::CSound::importForm(), and NLSOUND::CSound::serial(). |
|
|
Definition at line 134 of file sound.h. Referenced by NLSOUND::CSound::getConeOuterAngle(), NLSOUND::CSound::importForm(), and NLSOUND::CSound::serial(). |
|
|
Definition at line 134 of file sound.h. Referenced by NLSOUND::CSound::getConeOuterGain(), NLSOUND::CSound::importForm(), and NLSOUND::CSound::serial(). |
|
|
container for all the candidate sounds
Definition at line 323 of file context_sound.h. |
|
|
|
|
|
|
|
|
Definition at line 137 of file sound.h. Referenced by NLSOUND::CSound::getLooping(), NLSOUND::CSound::importForm(), NLSOUND::CSound::serial(), and NLSOUND::CSound::setLooping(). |
|
|
Clipping distance for complex or backgound sound.
Definition at line 140 of file sound.h. Referenced by NLSOUND::CComplexSound::getMaxDistance(). |
|
|
Definition at line 143 of file sound.h. Referenced by NLSOUND::CSound::operator<(). |
|
|
The context sound pattern name.
Definition at line 313 of file context_sound.h. Referenced by importForm(), init(), and serial(). |
|
|
|
|
|
Definition at line 133 of file sound.h. Referenced by NLSOUND::CSound::getPriority(), NLSOUND::CSound::importForm(), and NLSOUND::CSound::serial(). |
|
|
The random lenght (0 mean no random).
Definition at line 318 of file context_sound.h. |
|
|
An optional user var controler.
Definition at line 145 of file sound.h. Referenced by NLSOUND::CSound::getUserVarControler(), and NLSOUND::CAudioMixerUser::initUserVar(). |
1.3.6