From: Thomas Pietrzak Date: Wed, 7 Mar 2012 10:44:22 +0000 (+0000) Subject: remove dirent.h, couple of tweaks X-Git-Url: https://git.thomaspietrzak.com/?a=commitdiff_plain;h=a6142e9082454013acfb9526be3b896907892b71;p=hapticmetronome.git remove dirent.h, couple of tweaks git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@54 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- diff --git a/Haptic Metronome/Haptic Metronome.suo b/Haptic Metronome/Haptic Metronome.suo index 57a05ef..27c6e50 100644 Binary files a/Haptic Metronome/Haptic Metronome.suo and b/Haptic Metronome/Haptic Metronome.suo differ diff --git a/include/MetronomeHaptic.hpp b/include/MetronomeHaptic.hpp index 35bc78f..8ae11c8 100644 --- a/include/MetronomeHaptic.hpp +++ b/include/MetronomeHaptic.hpp @@ -30,7 +30,7 @@ class MetronomeHaptic : public Metronome private: static int thread_func(void *unused); SDL_Thread *thread; - TactonPlayer _tactonPlayer; + TactonPlayer *_tactonPlayer; }; #endif diff --git a/src/MetronomeHaptic.cpp b/src/MetronomeHaptic.cpp index 2093a6a..e942d6a 100644 --- a/src/MetronomeHaptic.cpp +++ b/src/MetronomeHaptic.cpp @@ -10,15 +10,30 @@ extern Uint32 start; extern FILE *logfile; MetronomeHaptic::MetronomeHaptic(const Track &track, Uint32 nbbeats, Uint32 tempo, bool activated) -:Metronome(track, nbbeats, tempo, activated), thread(NULL), _tactonPlayer("COM3") +:Metronome(track, nbbeats, tempo, activated), thread(NULL) { + try + { + _tactonPlayer = new TactonPlayer("COM4"); + } + catch (...) + { + SDL_Log("Wristband not found"); + _tactonPlayer = NULL; + } + //load the tactons - _tactonPlayer.registFile("bips.txt"); + if (_tactonPlayer) + _tactonPlayer->registFile("bips.txt"); } MetronomeHaptic::~MetronomeHaptic() { - _tactonPlayer.stop(); + if (_tactonPlayer) + { + _tactonPlayer->stop(); + delete _tactonPlayer; + } _activated = false; SDL_WaitThread(thread, NULL); } @@ -45,10 +60,12 @@ void MetronomeHaptic::init() void MetronomeHaptic::checkAt(Uint32 timestamp) { + if (!_tactonPlayer) + return; //send first beeps in advance while (_iBips != _bips->end() && timestamp >= BIPTIMESTAMP(*_iBips)) { - _tactonPlayer.schedule(_currentbeat % 4, BIPTIMESTAMP(*_iBips)); + _tactonPlayer->schedule(_currentbeat % 4, BIPTIMESTAMP(*_iBips)); if (logfile) fprintf(logfile, "BIP;%d;%d;%d\n", BIPTICK(*_iBips), BIPTIMESTAMP(*_iBips), 0); @@ -78,7 +95,8 @@ int MetronomeHaptic::thread_func(void *obj) // SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH); - thismetronome->_tactonPlayer.start(); + if (thismetronome->_tactonPlayer) + thismetronome->_tactonPlayer->start(); while(thismetronome->_activated) { diff --git a/src/Tools.cpp b/src/Tools.cpp index bb23adc..e735657 100644 --- a/src/Tools.cpp +++ b/src/Tools.cpp @@ -25,8 +25,9 @@ #include #include #include +#include -#include +//#include using namespace std; @@ -43,13 +44,14 @@ bool fileExists(const String &f) bool dirExists(const String &d) { - DIR *dir; + return _chdir(d.c_str()) == 0; +/* DIR *dir; if ((dir = opendir(d.c_str())) != NULL) { closedir(dir); return true; } - return false; + return false;*/ } Vector2D rotatePoint(const Vector2D pos, const Vector2D center, const double &angle) diff --git a/src/main.cpp b/src/main.cpp index 1ee3801..5357327 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -115,7 +115,7 @@ int main(int argc, char *argv[]) } catch(...) { - SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Unable to load the song fil\n"); + SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Unable to load the song file\n"); exit(0); }