#include <cstring>\r
#include <cstdlib>\r
\r
+Tacton::Tacton()\r
+:_nbframes(0), _patterns(NULL), _durations(NULL), _frequencies(NULL), _amplitudes(NULL)\r
+{\r
+}\r
+\r
Tacton::Tacton(unsigned int nbframes, unsigned char *desc)\r
:_nbframes(nbframes), _patterns(new unsigned char[nbframes]), _durations(new unsigned int[nbframes]), _frequencies(new unsigned int[nbframes]), _amplitudes(new unsigned char[nbframes])\r
{\r
}\r
\r
Tacton::Tacton(const Tacton &t)\r
-:_nbframes(t._nbframes), _patterns(new unsigned char[t._nbframes]), _durations(new unsigned int[t._nbframes]), _frequencies(new unsigned int[t._nbframes]), _amplitudes(new unsigned char[t._nbframes])\r
+:_nbframes(t._nbframes)\r
{\r
- memcpy(_patterns, t._patterns, t._nbframes * sizeof(unsigned char));\r
- memcpy(_durations, t._durations, t._nbframes * sizeof(unsigned int));\r
- memcpy(_frequencies, t._frequencies, t._nbframes * sizeof(unsigned int));\r
- memcpy(_amplitudes, t._amplitudes, t._nbframes * sizeof(unsigned char));\r
+ if (_nbframes > 0)\r
+ {\r
+ _patterns = new unsigned char[t._nbframes];\r
+ memcpy(_patterns, t._patterns, t._nbframes * sizeof(unsigned char));\r
+ _durations = new unsigned int[t._nbframes];\r
+ memcpy(_durations, t._durations, t._nbframes * sizeof(unsigned int));\r
+ _frequencies = new unsigned int[t._nbframes];\r
+ memcpy(_frequencies, t._frequencies, t._nbframes * sizeof(unsigned int));\r
+ _amplitudes = new unsigned char[t._nbframes];\r
+ memcpy(_amplitudes, t._amplitudes, t._nbframes * sizeof(unsigned char));\r
+ }\r
+ else\r
+ {\r
+ _patterns = NULL;\r
+ _durations = NULL;\r
+ _frequencies = NULL;\r
+ _amplitudes = NULL;\r
+ }\r
}\r
\r
Tacton::~Tacton()\r
{\r
- delete []_patterns;\r
- delete []_durations;\r
- delete []_frequencies;\r
- delete []_amplitudes;\r
+ if (_nbframes > 0)\r
+ {\r
+ delete []_patterns;\r
+ delete []_durations;\r
+ delete []_frequencies;\r
+ delete []_amplitudes;\r
+ }\r
+}\r
+\r
+Tacton &Tacton::operator = (const Tacton &t)\r
+{\r
+ if (&t == this)\r
+ return *this;\r
+\r
+ if (_nbframes > 0)\r
+ {\r
+ delete []_patterns;\r
+ delete []_durations;\r
+ delete []_frequencies;\r
+ delete []_amplitudes;\r
+ }\r
+\r
+ _nbframes = t.getNbFrames();\r
+\r
+ if (_nbframes > 0)\r
+ {\r
+ _patterns = new unsigned char[t._nbframes];\r
+ memcpy(_patterns, t._patterns, t._nbframes * sizeof(unsigned char));\r
+ _durations = new unsigned int[t._nbframes];\r
+ memcpy(_durations, t._durations, t._nbframes * sizeof(unsigned int));\r
+ _frequencies = new unsigned int[t._nbframes];\r
+ memcpy(_frequencies, t._frequencies, t._nbframes * sizeof(unsigned int));\r
+ _amplitudes = new unsigned char[t._nbframes];\r
+ memcpy(_amplitudes, t._amplitudes, t._nbframes * sizeof(unsigned char));\r
+ }\r
+ else\r
+ {\r
+ _patterns = NULL;\r
+ _durations = NULL;\r
+ _frequencies = NULL;\r
+ _amplitudes = NULL;\r
+ }\r
+\r
+ return *this;\r
}\r
\r
const unsigned int Tacton::getNbFrames() const\r