From fe545ba3a8cee02ca85d0de8ce6bbdc2bb63499e Mon Sep 17 00:00:00 2001 From: Thomas Pietrzak Date: Thu, 2 Jun 2011 20:43:56 +0000 Subject: [PATCH] factoring metronomes, wait for haptic to begin git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@21 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- Haptic Metronome/Haptic Metronome.suo | Bin 33792 -> 47616 bytes .../Haptic Metronome/Haptic Metronome.vcxproj | 6 +- include/Metronome.hpp | 14 +- include/MetronomeAudio.hpp | 4 +- include/MetronomeHaptic.hpp | 8 +- src/Metronome.cpp | 10 +- src/MetronomeAudio.cpp | 74 ++++---- src/MetronomeHaptic.cpp | 179 ++++++------------ src/PaintGame.cpp | 32 ++-- src/main.cpp | 3 + 10 files changed, 142 insertions(+), 188 deletions(-) diff --git a/Haptic Metronome/Haptic Metronome.suo b/Haptic Metronome/Haptic Metronome.suo index 6080ca3c055c7efe7d3269a9482a23664743a295..7cdbd582c1e81d6883193690ad1663301977c76d 100644 GIT binary patch delta 3642 zcmds4dr(tX8o%dy6Os@$4~$fimuRB`M#UBcV@OivX+k8Rf&vwk$RjKUG$;_n^@%Rz zYZdFO_TkvpZjq>~<90~JPItDuwT{lVqr2BR2)X`|!jUL!TxYLh*JPT8+#K z3leNF%%Mqwo#iFZg(XQgIib2!MmeD*)Jf7!n?b`>R;EKWeb|0J+Rs@Gz6DlU1~TV{ z1q=G2AT1iqb7KO*G}Acnne;H<6dkehngVqgC^F4}`t&HW8$Qx(0DaR^t%upflp~s% zb=cQ3RZJ5QO(iUHs#JBR%HBQF>x=JB*>nBoEiwSv>nDMxBo_2q<=`SKku5@>>Eh%8 zPo|B?$xIv?M3&Ts#1jqtBdd*UftJOcFxx}CCRqy}Q(i)fh)#h1S z&F0@_jg%yz_yq`Nchi~yj~TNbg??W|@MRV<+c_;AV692^BGCk1OFmqUG(gDG+h^cN z2~;he0~xu>K+tL;WG9fA&gbeG7pBLcBHR__!1Q+M>8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pdA zL!}<)LN_a?`h}b6Y=D6rMbmhNT$6o9ZABTrlEpS*9MUOr7kP@u(5<+Mq*sNw#F7T3 zib-G5#IA0~QhBpjYE^O1Av>kJXPNJROs1T0d6rpu6-&cuM)#OijVdl3XV&ga8D5FB t9ogiJ%Ts1m_-;*Xlv-sXrm+gUTN;^9CXp#9mrT|W*DLFS8EH<4{{oZCdEEd2 diff --git a/Haptic Metronome/Haptic Metronome/Haptic Metronome.vcxproj b/Haptic Metronome/Haptic Metronome/Haptic Metronome.vcxproj index 1ec5140..861b312 100644 --- a/Haptic Metronome/Haptic Metronome/Haptic Metronome.vcxproj +++ b/Haptic Metronome/Haptic Metronome/Haptic Metronome.vcxproj @@ -50,9 +50,9 @@ - Level4 + Level3 Disabled - _MBCS;%(PreprocessorDefinitions);WIN32;FULLSCREEN + _MBCS;%(PreprocessorDefinitions);WIN32 4996 @@ -68,7 +68,7 @@ MaxSpeed true true - _MBCS;%(PreprocessorDefinitions);WIN32 + _MBCS;%(PreprocessorDefinitions);WIN32;FULLSCREEN false diff --git a/include/Metronome.hpp b/include/Metronome.hpp index cbcd7b5..1a92832 100644 --- a/include/Metronome.hpp +++ b/include/Metronome.hpp @@ -7,9 +7,13 @@ class Metronome { public: - Metronome(const Track *track, Uint32 nbbeats=4, Uint32 tempo=0, bool activated=false); + Metronome(const Track &track, Uint32 nbbeats=4, Uint32 tempo=0, bool activated=false); virtual ~Metronome(){} + virtual void init(){} + + virtual void checkAt(Uint32 timestamp)=0; + virtual void setActive(bool activated) { _activated = activated; } virtual void setTempo(Uint32 tempo) { _tempo = tempo; } virtual void setNbBeats(Uint32 nbbeats) {_nbbeats = nbbeats; } @@ -20,7 +24,13 @@ class Metronome Uint32 _nbbeats; Uint32 _tempo; bool _activated; - const Track *_track; + unsigned char _currentbeat; + const list > *_bips; + const map > *_tempos; + const map > *_timesignatures; + list >::const_iterator _iBips; + map >::const_iterator _iTempos; + map >::const_iterator _iTimesignature; }; #endif diff --git a/include/MetronomeAudio.hpp b/include/MetronomeAudio.hpp index 7134ffc..b277186 100644 --- a/include/MetronomeAudio.hpp +++ b/include/MetronomeAudio.hpp @@ -13,10 +13,12 @@ class MetronomeAudio : public Metronome { public: - MetronomeAudio(const Track *track, Uint32 nbbeats=4, Uint32 tempo=0, bool activated=true); + MetronomeAudio(const Track &track, Uint32 nbbeats=4, Uint32 tempo=0, bool activated=true); ~MetronomeAudio(); + void checkAt(Uint32 timestamp); + void run(); private: diff --git a/include/MetronomeHaptic.hpp b/include/MetronomeHaptic.hpp index a8a7a98..e402770 100644 --- a/include/MetronomeHaptic.hpp +++ b/include/MetronomeHaptic.hpp @@ -15,13 +15,17 @@ class MetronomeHaptic : public Metronome { public: - MetronomeHaptic(const Track *track, Uint32 nbbeats=4, Uint32 tempo=0, bool activated=true); + MetronomeHaptic(const Track &track, Uint32 nbbeats=4, Uint32 tempo=0, bool activated=true); ~MetronomeHaptic(); + void init(); + void setTempo(Uint32 tempo); void setNbBeats(Uint32 nbbeats); + void checkAt(Uint32 timestamp); + void run(); private: @@ -30,4 +34,4 @@ class MetronomeHaptic : public Metronome Serial *_comport; }; -#endif \ No newline at end of file +#endif diff --git a/src/Metronome.cpp b/src/Metronome.cpp index 5d8396e..52d9622 100644 --- a/src/Metronome.cpp +++ b/src/Metronome.cpp @@ -1,6 +1,10 @@ #include "Metronome.hpp" -Metronome::Metronome(const Track *track, Uint32 nbbeats, Uint32 tempo, bool activated) -:_track(track), _nbbeats(nbbeats), _tempo(tempo), _activated(activated) -{ +Metronome::Metronome(const Track &track, Uint32 nbbeats, Uint32 tempo, bool activated) +:_nbbeats(nbbeats), _tempo(tempo), _activated(activated), _currentbeat(0), + _bips(track.getBips()), _tempos(track.getTempos()), _timesignatures(track.getTimeSignatures()) +{ + _iBips = _bips->begin(); + _iTempos = _tempos->begin(); + _iTimesignature = _timesignatures->begin(); } diff --git a/src/MetronomeAudio.cpp b/src/MetronomeAudio.cpp index 4ab0fda..b785bbd 100644 --- a/src/MetronomeAudio.cpp +++ b/src/MetronomeAudio.cpp @@ -2,13 +2,12 @@ #include "Mixer.hpp" -extern Uint32 start; - #define BIPLENGTH 10 +extern Uint32 start; extern FILE*logfile; -MetronomeAudio::MetronomeAudio(const Track *track, Uint32 nbbeats, Uint32 tempo, bool activated) +MetronomeAudio::MetronomeAudio(const Track &track, Uint32 nbbeats, Uint32 tempo, bool activated) :Metronome(track, nbbeats, tempo, activated), thread(NULL) { Mixer::getInstance()->addSound("bip","bip10.wav"); @@ -26,52 +25,45 @@ void MetronomeAudio::run() thread = SDL_CreateThread(&MetronomeAudio::thread_func, this); } +void MetronomeAudio::checkAt(Uint32 timestamp) +{ + while (_iBips != _bips->end() && timestamp >= BIPTIMESTAMP(*_iBips)) + { + if (_currentbeat == 0) + Mixer::getInstance()->playSound("bip"); + else + Mixer::getInstance()->playSound("bip2"); + if (logfile) + fprintf(logfile, "BIP;%d;%d;%d\n", BIPTICK(*_iBips), BIPTIMESTAMP(*_iBips), timestamp); + SDL_Log("BipA %d at %d\n", BIPTIMESTAMP(*_iBips), timestamp); + + _currentbeat = (_currentbeat + 1) % _nbbeats; + _iBips++; + } + + // on avance tant que les tempos sont dépassées + while (_iTimesignature != _timesignatures->end() && (*_iTimesignature).second.getX() < timestamp) + { + //time signature change + SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Time signature change at %d : tick=%d at %d for %d beats\n", + timestamp, + (*_iTimesignature).first, + (*_iTimesignature).second.getX(), + (*_iTimesignature).second.getY()); + _nbbeats = (*_iTimesignature).second.getY(); + _iTimesignature++; + } +} + int MetronomeAudio::thread_func(void *obj) { MetronomeAudio *thismetronome = static_cast(obj); SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH); - const list > *bips = thismetronome->_track->getBips(); - //const map > *tempo = thismetronome->_track->getTempos(); - const map > *timesignatures = thismetronome->_track->getTimeSignatures(); - static list >::const_iterator cBips = bips->begin(); - //static map >::const_iterator cTempo = tempo->begin(); - static map >::const_iterator cTimesignature = timesignatures->begin(); - - int currentbeat = 0; - Uint32 currenttime = 0; - float lag = 0.0; - while(thismetronome->_activated) { - Uint32 currenttime = SDL_GetTicks() - start; - - while (cBips != bips->end() && currenttime >= BIPTIMESTAMP(*cBips)) - { - if (currentbeat == 0) - Mixer::getInstance()->playSound("bip"); - else - Mixer::getInstance()->playSound("bip2"); - if (logfile) - fprintf(logfile, "BIP;%d;%d;%d\n", BIPTICK(*cBips), BIPTIMESTAMP(*cBips), currenttime); - - currentbeat = (currentbeat + 1) % thismetronome->_nbbeats; - cBips++; - } - - // on avance tant que les tempos sont dépassées - while (cTimesignature != timesignatures->end() && (*cTimesignature).second.getX() < currenttime) - { - //tempo change - SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Time signature change at %d : tick=%d at %d for %d beats\n", - currenttime, - (*cTimesignature).first, - (*cTimesignature).second.getX(), - (*cTimesignature).second.getY()); - thismetronome->_nbbeats = (*cTimesignature).second.getY(); - cTimesignature++; - } + thismetronome->checkAt(SDL_GetTicks() - start); SDL_Delay(5); } diff --git a/src/MetronomeHaptic.cpp b/src/MetronomeHaptic.cpp index 70290ef..1647169 100644 --- a/src/MetronomeHaptic.cpp +++ b/src/MetronomeHaptic.cpp @@ -2,18 +2,20 @@ #include "Mixer.hpp" +#include + #ifdef WIN32 #include "SerialWindows.hpp" #else #include "SerialLinux.hpp" #endif -extern Uint32 start; #define BEFOREDELAY 2000 +extern Uint32 start; extern FILE *logfile; -MetronomeHaptic::MetronomeHaptic(const Track *track, Uint32 nbbeats, Uint32 tempo, bool activated) +MetronomeHaptic::MetronomeHaptic(const Track &track, Uint32 nbbeats, Uint32 tempo, bool activated) :Metronome(track, nbbeats, tempo, activated), thread(NULL) { try @@ -28,10 +30,10 @@ MetronomeHaptic::MetronomeHaptic(const Track *track, Uint32 nbbeats, Uint32 temp unsigned char buffer1[3]; buffer1[0] = 'N'; buffer1[1] = 0x00; buffer1[2] = 0x01; unsigned char buffer2[6]; - buffer2[0] = 0x01; //pattern - buffer2[1] = 0; buffer2[2] = 100; //duration - buffer2[3] = 0; buffer2[4] = 250; //frequency - buffer2[5] = 255; //amplitude + buffer2[0] = 0x01; //pattern + buffer2[1] = 0; buffer2[2] = 50; //duration + buffer2[3] = 0; buffer2[4] = 250; //frequency + buffer2[5] = 255; //amplitude //Tacton 1 _comport->WriteData(buffer1, 3); @@ -76,141 +78,72 @@ void MetronomeHaptic::run() thread = SDL_CreateThread(&MetronomeHaptic::thread_func, this); } -int MetronomeHaptic::thread_func(void *obj) +void MetronomeHaptic::init() { - MetronomeHaptic *thismetronome = static_cast(obj); - - SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH); - - const list > *bips = thismetronome->_track->getBips(); - //const map > *tempo = thismetronome->_track->getTempos(); - const map > *timesignatures = thismetronome->_track->getTimeSignatures(); - static list >::const_iterator cBips = bips->begin(); - //static map >::const_iterator cTempo = tempo->begin(); - static map >::const_iterator cTimesignature = timesignatures->begin(); + checkAt(BEFOREDELAY); +} - bool written = thismetronome->_comport->WriteData("S", 1); +void MetronomeHaptic::checkAt(Uint32 timestamp) +{ unsigned char outBuffer[6]; outBuffer[0] = 'P'; - unsigned char currentbeat = 0; - - while(thismetronome->_activated) + + //send first beeps in advance + while (_iBips != _bips->end() && timestamp >= BIPTIMESTAMP(*_iBips)) { - Uint32 currenttime = SDL_GetTicks() - start; - - while (cBips != bips->end() && currenttime >= BIPTIMESTAMP(*cBips)) - { -/* char outBuffer[5]; - outBuffer[0] = 'N';*/ - outBuffer[1] = currentbeat % 4; - outBuffer[2] = (BIPTIMESTAMP(*cBips) & 0xff000000) >> 24; - outBuffer[3] = (BIPTIMESTAMP(*cBips) & 0x00ff0000) >> 16; - outBuffer[4] = (BIPTIMESTAMP(*cBips) & 0x0000ff00) >> 8; - outBuffer[5] = BIPTIMESTAMP(*cBips) & 0x000000ff; - - bool written = thismetronome->_comport->WriteData(outBuffer, 6); -/* char INBUFFER[128]; - memset(INBUFFER, 0, 128); - int nbread = thismetronome->_comport->ReadData(INBUFFER, 128); - stringstream s; - s << nbread << " read:\n" << INBUFFER << endl; - OutputDebugString(s.str().c_str());*/ - - if (logfile) - fprintf(logfile, "BIP;%d;%d;%d\n", BIPTICK(*cBips), BIPTIMESTAMP(*cBips), currenttime); - - currentbeat = (currentbeat + 1) % thismetronome->_nbbeats; - cBips++; - } - - // on avance tant que les tempos sont dépassées - while (cTimesignature != timesignatures->end() && currenttime >= TIMESTAMP(*cTimesignature)) - { -/* char outBuffer[5]; - outBuffer[0] = 'B'; - outBuffer[1] = (TIMESTAMP(*cTimesignature) & 0xff000000) >> 24; - outBuffer[2] = (TIMESTAMP(*cTimesignature) & 0x00ff0000) >> 16; - outBuffer[3] = (TIMESTAMP(*cTimesignature) & 0x0000ff00) >> 8; - outBuffer[4] = TIMESTAMP(*cTimesignature) & 0x000000ff; - - bool written = thismetronome->_comport->WriteData(outBuffer, 5); - */ - //time signature change - SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Time signature change at %d : tick=%d at %d for %d beats\n", - currenttime, - (*cTimesignature).first, - (*cTimesignature).second.getX(), - (*cTimesignature).second.getY()); - thismetronome->_nbbeats = (*cTimesignature).second.getY(); - cTimesignature++; - } + outBuffer[1] = _currentbeat % 4; + outBuffer[2] = (BIPTIMESTAMP(*_iBips) & 0xff000000) >> 24; + outBuffer[3] = (BIPTIMESTAMP(*_iBips) & 0x00ff0000) >> 16; + outBuffer[4] = (BIPTIMESTAMP(*_iBips) & 0x0000ff00) >> 8; + outBuffer[5] = BIPTIMESTAMP(*_iBips) & 0x000000ff; + bool written = _comport->WriteData(outBuffer, 6); + + if (logfile) + fprintf(logfile, "BIP;%d;%d;%d\n", BIPTICK(*_iBips), BIPTIMESTAMP(*_iBips), 0); + SDL_Log("BipH %d at %d\n", timestamp, BIPTIMESTAMP(*_iBips)); + + _currentbeat = (_currentbeat + 1) % _nbbeats; + _iBips++; + } - SDL_Delay(5); + // on avance tant que les tempos sont dépassées + while (_iTimesignature != _timesignatures->end() && BEFOREDELAY >= TIMESTAMP(*_iTimesignature)) + { + //time signature change + SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Time signature change at %d : tick=%d at %d for %d beats\n", + timestamp, + (*_iTimesignature).first, + (*_iTimesignature).second.getX(), + (*_iTimesignature).second.getY()); + _nbbeats = (*_iTimesignature).second.getY(); + _iTimesignature++; } - return 0; } -/* int MetronomeHaptic::thread_func(void *obj) { MetronomeHaptic *thismetronome = static_cast(obj); - SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH); +// SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH); - const map > *tempo = thismetronome->_track->getTempos(); - const map > *timesignatures = thismetronome->_track->getTimeSignatures(); - static map >::const_iterator cTempo = tempo->begin(); - static map >::const_iterator cTimesignature = timesignatures->begin(); - -#ifdef WIN32 - struct { int tv_sec, tv_usec; } now, start; - DWORD t = timeGetTime (); - start.tv_sec = t / 1000; - start.tv_usec = (t % 1000) * 1000; -#else - struct timeval now, start; - gettimeofday(&start, NULL); -#endif - float currenttime = 0; + unsigned char outBuffer[6]; + outBuffer[0] = 'P'; + + bool written = thismetronome->_comport->WriteData("S", 1); while(thismetronome->_activated) { -#ifdef WIN32 - t = timeGetTime (); - now.tv_sec = t / 1000; - now.tv_usec = (t % 1000) * 1000; -#else - gettimeofday(&now, NULL); -#endif - float currenttime = (now.tv_sec - start.tv_sec) * 1000.0f + (now.tv_usec - start.tv_usec) / 1000.0f; - - // on avance tant que les tempos sont dépassées - while (cTempo != tempo->end() && currenttime > (*cTempo).second.getX()) - { - //tempo change - stringstream s; - s << "Tempo change at " << currenttime << " : tick=" << (*cTempo).first << " at " << (*cTempo).second.getX() << " for " << (60000000/(*cTempo).second.getY()) << " bpm" << endl; - OutputDebugString(s.str().c_str()); - - thismetronome->setTempo((*cTempo).second.getY()); - - cTempo++; - } - - // on avance tant que les tempos sont dépassées - while (cTimesignature != timesignatures->end() && (*cTimesignature).second.getX() < currenttime) - { - //time signature change - stringstream s; - s << "Time signature change at " << currenttime << " : tick=" << (*cTimesignature).first << " at " << (*cTimesignature).second.getX() << " for " << (*cTimesignature).second.getY() << " beats " << endl; - OutputDebugString(s.str().c_str()); - - thismetronome->setNbBeats((*cTimesignature).second.getY()); - - cTimesignature++; - } + // TEST + char INBUFFER[128]; + memset(INBUFFER, 0, 128); + int nbread = thismetronome->_comport->ReadData(INBUFFER, 128); + if (nbread > 0) + SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "%d read: %s\n", nbread, INBUFFER); + // + + thismetronome->checkAt(SDL_GetTicks() - start + BEFOREDELAY); + SDL_Delay(5); } return 0; } -*/ \ No newline at end of file diff --git a/src/PaintGame.cpp b/src/PaintGame.cpp index c94205b..9886a89 100644 --- a/src/PaintGame.cpp +++ b/src/PaintGame.cpp @@ -188,6 +188,10 @@ void init() glEnable(GL_LIGHT0); // SDL_EnableKeyRepeat(10, 100); +#ifdef FULLSCREEN + SDL_ShowCursor( SDL_DISABLE ); +#endif + fromKeyboard.setTimestamp(-1); fromKeyboard.setEndTimestamp(-1); } @@ -619,17 +623,18 @@ void loop(const Track &tr, const String &songname) init(); SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Create Metronome\n"); -// Metronome *m = new MetronomeAudio(&tr); - Metronome *m; + Metronome *m = NULL, *m2 = NULL; try { - m = new MetronomeHaptic(&tr); + //m = new MetronomeHaptic(tr); + m2 = new MetronomeAudio(tr); } catch (char *error) { // cout << error << endl; SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s\n", error); m = NULL; + m2 = NULL; } bool quitProgram = false; @@ -647,23 +652,23 @@ void loop(const Track &tr, const String &songname) if (gametype == REGULAR) Mixer::getInstance()->loadMusic(songname + "/tout.ogg"); -//must be done before paint and metronomes - start = SDL_GetTicks(); -/*#ifdef WIN32 - DWORD t = timeGetTime (); - start.tv_sec = t / 1000; - start.tv_usec = (t % 1000) * 1000; -#else - gettimeofday(&start, NULL); -#endif*/ - SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "LET'S ROCK!\n"); //m->setActive(true); + if (m) + m->init(); + if (m2) + m2->init(); + SDL_Delay(1000); if (gametype == REGULAR) Mixer::getInstance()->playMusic(); + //must be done before paint and metronomes + start = SDL_GetTicks(); if (m) m->run(); + if (m2) + m2->run(); + /* Mixer::getInstance()->playSound("guitar"); if (rhythm) Mixer::getInstance()->playSound("rhythm"); @@ -701,4 +706,5 @@ void loop(const Track &tr, const String &songname) } delete m; + delete m2; } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index a72c74e..1ee3801 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,6 +40,7 @@ void handleStrokeOff() int main(int argc, char *argv[]) { + srand(time((time_t *)(NULL))); if (argc < 2) { cout << "Usage : " << argv[0] << "songname [logname] [tempo] [duration] [beatsize]" << endl; @@ -130,5 +131,7 @@ int main(int argc, char *argv[]) if (logfile) fclose(logfile); + SDL_ShowCursor( SDL_ENABLE ); + return 1; } -- 2.30.2