</PropertyGroup>\r
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
<ClCompile>\r
- <WarningLevel>Level4</WarningLevel>\r
+ <WarningLevel>Level3</WarningLevel>\r
<Optimization>Disabled</Optimization>\r
- <PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);WIN32;FULLSCREEN</PreprocessorDefinitions>\r
+ <PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);WIN32</PreprocessorDefinitions>\r
<DisableSpecificWarnings>4996</DisableSpecificWarnings>\r
</ClCompile>\r
<Link>\r
<Optimization>MaxSpeed</Optimization>\r
<FunctionLevelLinking>true</FunctionLevelLinking>\r
<IntrinsicFunctions>true</IntrinsicFunctions>\r
- <PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);WIN32</PreprocessorDefinitions>\r
+ <PreprocessorDefinitions>_MBCS;%(PreprocessorDefinitions);WIN32;FULLSCREEN</PreprocessorDefinitions>\r
</ClCompile>\r
<Link>\r
<GenerateDebugInformation>false</GenerateDebugInformation>\r
class Metronome\r
{\r
public:\r
- Metronome(const Track *track, Uint32 nbbeats=4, Uint32 tempo=0, bool activated=false);\r
+ Metronome(const Track &track, Uint32 nbbeats=4, Uint32 tempo=0, bool activated=false);\r
virtual ~Metronome(){}\r
\r
+ virtual void init(){}\r
+\r
+ virtual void checkAt(Uint32 timestamp)=0;\r
+\r
virtual void setActive(bool activated) { _activated = activated; }\r
virtual void setTempo(Uint32 tempo) { _tempo = tempo; }\r
virtual void setNbBeats(Uint32 nbbeats) {_nbbeats = nbbeats; }\r
Uint32 _nbbeats;\r
Uint32 _tempo;\r
bool _activated;\r
- const Track *_track;\r
+ unsigned char _currentbeat;\r
+ const list<Pair<Uint32, Uint32> > *_bips;
+ const map<Uint32, Pair<Uint32, Uint32> > *_tempos;
+ const map<Uint32, Pair<Uint32, Uint32> > *_timesignatures;
+ list<Pair<Uint32, Uint32> >::const_iterator _iBips;
+ map<Uint32, Pair<Uint32, Uint32> >::const_iterator _iTempos;
+ map<Uint32, Pair<Uint32, Uint32> >::const_iterator _iTimesignature;
};\r
\r
#endif\r
class MetronomeAudio : public Metronome\r
{ \r
public:\r
- MetronomeAudio(const Track *track, Uint32 nbbeats=4, Uint32 tempo=0, bool activated=true);\r
+ MetronomeAudio(const Track &track, Uint32 nbbeats=4, Uint32 tempo=0, bool activated=true);\r
\r
~MetronomeAudio();\r
\r
+ void checkAt(Uint32 timestamp);\r
+\r
void run();\r
\r
private:\r
class MetronomeHaptic : public Metronome\r
{ \r
public:\r
- MetronomeHaptic(const Track *track, Uint32 nbbeats=4, Uint32 tempo=0, bool activated=true);\r
+ MetronomeHaptic(const Track &track, Uint32 nbbeats=4, Uint32 tempo=0, bool activated=true);\r
\r
~MetronomeHaptic();\r
\r
+ void init();\r
+\r
void setTempo(Uint32 tempo);\r
void setNbBeats(Uint32 nbbeats);\r
\r
+ void checkAt(Uint32 timestamp);\r
+\r
void run();\r
\r
private:\r
Serial *_comport;\r
};\r
\r
-#endif
\ No newline at end of file
+#endif\r
#include "Metronome.hpp"\r
\r
-Metronome::Metronome(const Track *track, Uint32 nbbeats, Uint32 tempo, bool activated)\r
-:_track(track), _nbbeats(nbbeats), _tempo(tempo), _activated(activated)\r
-{\r
+Metronome::Metronome(const Track &track, Uint32 nbbeats, Uint32 tempo, bool activated)\r
+:_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();\r
}\r
#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");
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<MetronomeAudio *>(obj);
SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
- const list<Pair<Uint32, Uint32> > *bips = thismetronome->_track->getBips();
- //const map<Uint32, Pair<float, Uint32> > *tempo = thismetronome->_track->getTempos();
- const map<Uint32, Pair<Uint32, Uint32> > *timesignatures = thismetronome->_track->getTimeSignatures();
- static list<Pair<Uint32, Uint32> >::const_iterator cBips = bips->begin();
- //static map<Uint32, Pair<float, Uint32> >::const_iterator cTempo = tempo->begin();
- static map<Uint32, Pair<Uint32, Uint32> >::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);
}
#include "Mixer.hpp"
+#include <SDL/SDL_mutex.h>
+
#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
unsigned char buffer1[3];\r
buffer1[0] = 'N'; buffer1[1] = 0x00; buffer1[2] = 0x01;\r
unsigned char buffer2[6];\r
- buffer2[0] = 0x01; //pattern\r
- buffer2[1] = 0; buffer2[2] = 100; //duration\r
- buffer2[3] = 0; buffer2[4] = 250; //frequency\r
- buffer2[5] = 255; //amplitude\r
+ buffer2[0] = 0x01; //pattern\r
+ buffer2[1] = 0; buffer2[2] = 50; //duration\r
+ buffer2[3] = 0; buffer2[4] = 250; //frequency\r
+ buffer2[5] = 255; //amplitude\r
\r
//Tacton 1\r
_comport->WriteData(buffer1, 3);
thread = SDL_CreateThread(&MetronomeHaptic::thread_func, this);
}
-int MetronomeHaptic::thread_func(void *obj)
+void MetronomeHaptic::init()
{
- MetronomeHaptic *thismetronome = static_cast<MetronomeHaptic *>(obj);
-
- SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
-
- const list<Pair<Uint32, Uint32> > *bips = thismetronome->_track->getBips();
- //const map<Uint32, Pair<float, Uint32> > *tempo = thismetronome->_track->getTempos();
- const map<Uint32, Pair<Uint32, Uint32> > *timesignatures = thismetronome->_track->getTimeSignatures();
- static list<Pair<Uint32, Uint32> >::const_iterator cBips = bips->begin();
- //static map<Uint32, Pair<float, Uint32> >::const_iterator cTempo = tempo->begin();
- static map<Uint32, Pair<Uint32, Uint32> >::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];\r
- outBuffer[0] = 'N';*/\r
- outBuffer[1] = currentbeat % 4;\r
- outBuffer[2] = (BIPTIMESTAMP(*cBips) & 0xff000000) >> 24;\r
- outBuffer[3] = (BIPTIMESTAMP(*cBips) & 0x00ff0000) >> 16;\r
- outBuffer[4] = (BIPTIMESTAMP(*cBips) & 0x0000ff00) >> 8;\r
- outBuffer[5] = BIPTIMESTAMP(*cBips) & 0x000000ff;\r
-\r
- bool written = thismetronome->_comport->WriteData(outBuffer, 6);\r
-/* char INBUFFER[128];\r
- memset(INBUFFER, 0, 128);
- int nbread = thismetronome->_comport->ReadData(INBUFFER, 128);
- stringstream s;
- s << nbread << " read:\n" << INBUFFER << endl;
- OutputDebugString(s.str().c_str());*/\r
-
- 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];\r
- outBuffer[0] = 'B';\r
- outBuffer[1] = (TIMESTAMP(*cTimesignature) & 0xff000000) >> 24;\r
- outBuffer[2] = (TIMESTAMP(*cTimesignature) & 0x00ff0000) >> 16;\r
- outBuffer[3] = (TIMESTAMP(*cTimesignature) & 0x0000ff00) >> 8;\r
- outBuffer[4] = TIMESTAMP(*cTimesignature) & 0x000000ff;\r
- \r
- bool written = thismetronome->_comport->WriteData(outBuffer, 5);\r
- */
- //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;\r
+ outBuffer[2] = (BIPTIMESTAMP(*_iBips) & 0xff000000) >> 24;\r
+ outBuffer[3] = (BIPTIMESTAMP(*_iBips) & 0x00ff0000) >> 16;\r
+ outBuffer[4] = (BIPTIMESTAMP(*_iBips) & 0x0000ff00) >> 8;\r
+ outBuffer[5] = BIPTIMESTAMP(*_iBips) & 0x000000ff;\r
+ bool written = _comport->WriteData(outBuffer, 6);\r
+
+ 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<MetronomeHaptic *>(obj);
- SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
+// SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
- const map<Uint32, Pair<float, Uint32> > *tempo = thismetronome->_track->getTempos();
- const map<Uint32, Pair<float, Uint32> > *timesignatures = thismetronome->_track->getTimeSignatures();
- static map<Uint32, Pair<float, Uint32> >::const_iterator cTempo = tempo->begin();
- static map<Uint32, Pair<float, Uint32> >::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];\r
+ 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);
+ //\r
+\r
+ thismetronome->checkAt(SDL_GetTicks() - start + BEFOREDELAY);\r
+\r
SDL_Delay(5);
}
return 0;
}
-*/
\ No newline at end of file
glEnable(GL_LIGHT0);
// SDL_EnableKeyRepeat(10, 100);
+#ifdef FULLSCREEN
+ SDL_ShowCursor( SDL_DISABLE );
+#endif
+
fromKeyboard.setTimestamp(-1);
fromKeyboard.setEndTimestamp(-1);
}
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;
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");
}
delete m;
+ delete m2;
}
\ No newline at end of file
int main(int argc, char *argv[])
{
+ srand(time((time_t *)(NULL)));
if (argc < 2)
{
cout << "Usage : " << argv[0] << "songname [logname] [tempo] [duration] [beatsize]" << endl;
if (logfile)
fclose(logfile);
+ SDL_ShowCursor( SDL_ENABLE );
+
return 1;
}