#include <sound_animation.h>
Public Types | |
enum | { NoId = -1 } |
Public Member Functions | |
virtual void | addMarker (CSoundAnimMarker *marker) |
virtual uint32 | countMarkers () |
CSoundAnimation (std::string &name, TSoundAnimId id) | |
virtual std::string & | getFilename () |
virtual CSoundAnimMarker * | getMarker (uint32 i) |
virtual std::string & | getName () |
virtual bool | isDirty () |
virtual void | load () |
virtual void | play (UAudioMixer *mixer, float lastTime, float curTime, NL3D::CCluster *cluster, CSoundContext &context) |
virtual void | removeMarker (CSoundAnimMarker *marker) |
virtual void | save () |
virtual void | setDirty (bool b) |
virtual void | setFilename (std::string &name) |
virtual | ~CSoundAnimation () |
Protected Member Functions | |
virtual void | sort () |
Sort all the markers according to their time. | |
Protected Attributes | |
bool | _Dirty |
std::string | _Filename |
TSoundAnimId | _Id |
TMarkerVector | _Markers |
std::string | _Name |
|
Definition at line 49 of file sound_animation.h.
00050 { 00051 NoId = -1 00052 }; |
|
Definition at line 54 of file sound_animation.h. References id, and NLSOUND::TSoundAnimId.
|
|
Definition at line 56 of file sound_animation.h.
00056 {} |
|
Add a new marker Definition at line 43 of file sound_animation.cpp. References _Markers, and sort(). Referenced by load().
|
|
Return the number of markers in this track Definition at line 66 of file sound_animation.h. References _Markers, and uint32.
00066 { return _Markers.size(); } |
|
Return the filename of the animation Definition at line 82 of file sound_animation.h.
00082 { return _Filename; } |
|
Return a marker of this track given its index Definition at line 69 of file sound_animation.h. References _Markers, and uint32.
00069 { return _Markers[i]; } |
|
Return the name of the animation Definition at line 72 of file sound_animation.h. Referenced by NLSOUND::CSoundAnimManager::createAnimation().
00072 { return _Name; } |
|
Returns whether the sound animation changed since the last save. (Editing support) Definition at line 89 of file sound_animation.h.
00089 { return _Dirty; } |
|
Load from an xml file Definition at line 159 of file sound_animation.cpp. References addMarker(), NLSOUND::CSoundAnimMarker::addSound(), file, and NLSOUND::CSoundAnimMarker::setTime(). Referenced by NLSOUND::CSoundAnimManager::loadAnimation().
00160 { 00161 NL_ALLOC_CONTEXT(NLSOUND_CSoundAnimation); 00162 CIFile file; 00163 00164 // Open the file 00165 if (!file.open(_Filename.c_str())) 00166 { 00167 throw exception("Can't open the file for reading"); 00168 } 00169 00170 // Create the XML stream 00171 CIXml input; 00172 00173 // Init 00174 if (input.init (file)) 00175 { 00176 xmlNodePtr animNode = input.getRootNode (); 00177 xmlNodePtr markerNode = input.getFirstChildNode(animNode, "MARKER"); 00178 00179 while (markerNode != 0) 00180 { 00181 CSoundAnimMarker* marker = new CSoundAnimMarker(); 00182 00183 const char *time = (const char*) xmlGetProp(markerNode, (xmlChar*) "time"); 00184 if (time == 0) 00185 { 00186 throw exception("Invalid sound animation marker"); 00187 } 00188 00189 marker->setTime((float) atof(time)); 00190 xmlFree ((void*)time); 00191 00192 00193 xmlNodePtr soundNode = input.getFirstChildNode(markerNode, "SOUND"); 00194 00195 while (soundNode != 0) 00196 { 00197 char *name = (char*) xmlGetProp(soundNode, (xmlChar*) "name"); 00198 if (name == 0) 00199 { 00200 throw exception("Invalid sound animation marker"); 00201 } 00202 00203 marker->addSound(CStringMapper::map(string(name))); 00204 00205 xmlFree ((void*)name); 00206 00207 soundNode = input.getNextChildNode(soundNode, "SOUND"); 00208 } 00209 00210 addMarker(marker); 00211 00212 markerNode = input.getNextChildNode(markerNode, "MARKER"); 00213 } 00214 } 00215 00216 // Close the file 00217 file.close (); 00218 _Dirty = false; 00219 } |
|
Play the sounds of the markers that fall within the specified time interval. Definition at line 142 of file sound_animation.cpp. References _Markers, NLSOUND::CSoundAnimMarker::getTime(), nlassert, and NLSOUND::CSoundAnimMarker::play(). Referenced by NLSOUND::CSoundAnimManager::playAnimation().
00143 { 00144 vector<CSoundAnimMarker*>::iterator iter; 00145 for (iter = _Markers.begin(); iter != _Markers.end(); iter++) 00146 { 00147 CSoundAnimMarker* marker = *iter; 00148 nlassert(marker); 00149 00150 if ((lastTime <= marker->getTime()) && (marker->getTime() < curTime)) 00151 { 00152 marker->play(mixer, cluster, context); 00153 } 00154 } 00155 } |
|
Remove a marker Definition at line 55 of file sound_animation.cpp. References _Markers.
|
|
Save to an xml document Definition at line 81 of file sound_animation.cpp. References _Markers, file, NLMISC::COXml::flush(), NLMISC::COXml::getDocument(), NLSOUND::CSoundAnimMarker::getSounds(), NLSOUND::CSoundAnimMarker::getTime(), NLMISC::COXml::init(), s, and NLMISC::smprintf(). Referenced by NLSOUND::CSoundAnimManager::saveAnimation().
00082 { 00083 // File stream 00084 COFile file; 00085 vector<NLMISC::TStringId> sounds; 00086 00087 // Open the file 00088 if (!file.open(_Filename.c_str())) 00089 { 00090 throw exception("Can't open the file for writing"); 00091 } 00092 00093 // Create the XML stream 00094 COXml output; 00095 00096 // Init 00097 if (output.init (&file, "1.0")) 00098 { 00099 xmlDocPtr xmlDoc = output.getDocument(); 00100 00101 // Create the first node 00102 xmlNodePtr root = xmlNewDocNode (xmlDoc, NULL, (const xmlChar*)"SOUNDANIMATION", NULL); 00103 xmlDocSetRootElement (xmlDoc, root); 00104 00105 vector<CSoundAnimMarker*>::iterator iter; 00106 for (iter = _Markers.begin(); iter != _Markers.end(); iter++) 00107 { 00108 CSoundAnimMarker* marker = (*iter); 00109 00110 set<string>::iterator iter; 00111 00112 char s[64]; 00113 smprintf(s, 64, "%f", marker->getTime()); 00114 00115 xmlNodePtr markerNode = xmlNewChild (root, NULL, (const xmlChar*)"MARKER", NULL); 00116 xmlSetProp (markerNode, (const xmlChar*) "time", (const xmlChar*) s); 00117 00118 marker->getSounds(sounds); 00119 00120 vector<NLMISC::TStringId>::iterator iter2; 00121 for (iter2 = sounds.begin(); iter2 != sounds.end(); iter2++) 00122 { 00123 xmlNodePtr soundNode = xmlNewChild ( markerNode, NULL, (const xmlChar*)"SOUND", NULL ); 00124 xmlSetProp (soundNode, (const xmlChar*)"name", (const xmlChar*) CStringMapper::unmap(*iter2).c_str()); 00125 } 00126 00127 sounds.clear(); 00128 } 00129 00130 // Flush the stream, write all the output file 00131 output.flush (); 00132 } 00133 00134 // Close the file 00135 file.close (); 00136 00137 _Dirty = false; 00138 } |
|
Set the dirty flag (Editing support) Definition at line 92 of file sound_animation.h.
00092 { _Dirty = b; } |
|
Set the filename of the animation Definition at line 86 of file sound_animation.h. Referenced by NLSOUND::CSoundAnimManager::loadAnimation(), and NLSOUND::CSoundAnimManager::saveAnimation().
00086 { _Filename = name; } |
|
Sort all the markers according to their time.
Definition at line 74 of file sound_animation.cpp. Referenced by addMarker().
00075 {
00076 //std::sort<CSoundAnimMarker*, eqmarker>(_Markers.begin(), _Markers.end(), eqmarker());
00077 }
|
|
Has the sound animation changed since the last save? (Editing support) Definition at line 115 of file sound_animation.h. |
|
The filename Definition at line 112 of file sound_animation.h. |
|
The unique ID of the animation Definition at line 103 of file sound_animation.h. |
|
The set of markers Definition at line 109 of file sound_animation.h. Referenced by addMarker(), countMarkers(), getMarker(), play(), removeMarker(), and save(). |
|
The name of the animation Definition at line 106 of file sound_animation.h. |