From: Thomas Pietrzak Date: Wed, 15 Jun 2011 21:20:07 +0000 (+0000) Subject: add copy constructor, and setters X-Git-Url: https://git.thomaspietrzak.com/?a=commitdiff_plain;h=3d4c02dcc9848f8992d23883b89d0c1ca76cafd2;p=tactonlibrary.git add copy constructor, and setters git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@35 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- diff --git a/TactonLibrary.suo b/TactonLibrary.suo index 4b9a884..56817b7 100644 Binary files a/TactonLibrary.suo and b/TactonLibrary.suo differ diff --git a/TactonPlayer/Tacton.cpp b/TactonPlayer/Tacton.cpp index 3e38661..bf72612 100644 --- a/TactonPlayer/Tacton.cpp +++ b/TactonPlayer/Tacton.cpp @@ -78,6 +78,15 @@ Tacton::Tacton(unsigned char pattern, unsigned int duration, unsigned int freque _amplitudes[0] = amplitude; } +Tacton::Tacton(const Tacton &t) +:_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]) +{ + memcpy(_patterns, t._patterns, t._nbframes * sizeof(unsigned char)); + memcpy(_durations, t._durations, t._nbframes * sizeof(unsigned int)); + memcpy(_frequencies, t._frequencies, t._nbframes * sizeof(unsigned int)); + memcpy(_amplitudes, t._amplitudes, t._nbframes * sizeof(unsigned char)); +} + Tacton::~Tacton() { delete []_patterns; @@ -91,6 +100,67 @@ const unsigned int Tacton::getNbFrames() const return _nbframes; } +__declspec(dllexport) void Tacton::setPattern(char pattern) +{ + setPattern(0, pattern); +} + +__declspec(dllexport) void Tacton::setPattern(unsigned int frame, char pattern) +{ + if (frame < _nbframes) + _patterns[frame] = pattern; +} + +__declspec(dllexport) void Tacton::setPattern(char *pattern) +{ + setPattern(0, pattern); +} + +__declspec(dllexport) void Tacton::setPattern(unsigned int frame, char *pattern) +{ + if (frame < _nbframes) + { + unsigned char t1 = pattern[0] == '1'; + unsigned char t2 = pattern[1] == '1'; + unsigned char t3 = pattern[2] == '1'; + unsigned char t4 = pattern[3] == '1'; + _patterns[frame] = (t1 << 3) | (t2 << 2) | (t3 << 1) | t4; + } +} + +__declspec(dllexport) void Tacton::setDuration(unsigned int duration) +{ + setDuration(0, duration); +} + +__declspec(dllexport) void Tacton::setDuration(unsigned int frame, unsigned int duration) +{ + if (frame < _nbframes) + _durations[frame] = duration; +} + +__declspec(dllexport) void Tacton::setFrequency(unsigned int frequency) +{ + setFrequency(0, frequency); +} + +__declspec(dllexport) void Tacton::setFrequency(unsigned int frame, unsigned int frequency) +{ + if (frame < _nbframes) + _frequencies[frame] = frequency; +} + +__declspec(dllexport) void Tacton::setAmplitude(unsigned int amplitude) +{ + setAmplitude(0, amplitude); +} + +__declspec(dllexport) void Tacton::setAmplitude(unsigned int frame, unsigned int amplitude) +{ + if (frame < _nbframes) + _amplitudes[frame] = amplitude; +} + void *Tacton::rawCode() const { unsigned char *res = new unsigned char[_nbframes * 6]; diff --git a/TactonPlayer/Tacton.hpp b/TactonPlayer/Tacton.hpp index b5162c4..3294764 100644 --- a/TactonPlayer/Tacton.hpp +++ b/TactonPlayer/Tacton.hpp @@ -21,7 +21,25 @@ class Tacton __declspec(dllexport) Tacton(unsigned int nbframes, unsigned char *patterns, unsigned int *durations, unsigned int *frequencies, unsigned char *amplitudes); //create a simple vibration __declspec(dllexport) Tacton(unsigned char pattern, unsigned int duration, unsigned int frequency, unsigned char amplitude); + __declspec(dllexport) Tacton(const Tacton &t); __declspec(dllexport) ~Tacton(); + + //changes the pattern using raw format + __declspec(dllexport) void setPattern(char pattern); + __declspec(dllexport) void setPattern(unsigned int frame, char pattern); + //changes the pattern using string format + __declspec(dllexport) void setPattern(char *pattern); + __declspec(dllexport) void setPattern(unsigned int frame, char *pattern); + //changes the duration + __declspec(dllexport) void setDuration(unsigned int duration); + __declspec(dllexport) void setDuration(unsigned int frame, unsigned int duration); + //changes the frequency + __declspec(dllexport) void setFrequency(unsigned int frequency); + __declspec(dllexport) void setFrequency(unsigned int frame, unsigned int frequency); + //changes the amplitude + __declspec(dllexport) void setAmplitude(unsigned int amplitude); + __declspec(dllexport) void setAmplitude(unsigned int frame, unsigned int amplitude); + //returns the number of frames __declspec(dllexport) const unsigned int getNbFrames() const;