void init();
void initPaint();
-void draw(Track &t, char diff);\r
+void draw(Track &t, float currenttime, char diff);\r
void drawCube(float pos, float size, float colorx, float colory, float colorz);
void drawLong(float pos, float size, float length, float colorx, float colory, float colorz);
\r
-void handleKeyOn(keys k);\r
-void handleKeyOff(keys k);\r
-void handleKeys(bool a, bool b, bool c, bool d, bool e);
-void handleStrokeOn();\r
-void handleStrokeOff();\r
-bool processEvents();
+void handleKeyOn(keys k, float currenttime);\r
+void handleKeyOff(keys k, float currenttime);\r
+void handleKeys(bool a, bool b, bool c, bool d, bool e, float currenttime);
+void handleStrokeOn(float currenttime);\r
+void handleStrokeOff(float currenttime);\r
+bool processEvents(float currenttime);
class MyWiimote: public Wiimote
{
public:
MyWiimote():Wiimote(1){}
- void handleStrumOn() { handleStrokeOn(); }
- void handleStrumOff() { handleStrokeOff(); }
- void handleButtonOn(int k) { handleKeyOn(keys(k)); }
- void handleButtonOff(int k) { handleKeyOff(keys(k)); }
- void handleButtons(bool a, bool b, bool c, bool d, bool e) { handleKeys(a, b, c, d, e); }
+ void handleStrumOn(float currenttime) { handleStrokeOn(currenttime); }
+ void handleStrumOff(float currenttime) { handleStrokeOff(currenttime); }
+ void handleButtonOn(int k, float currenttime) { handleKeyOn(keys(k), currenttime); }
+ void handleButtonOff(int k, float currenttime) { handleKeyOff(keys(k), currenttime); }
+ void handleButtons(bool a, bool b, bool c, bool d, bool e, float currenttime) { handleKeys(a, b, c, d, e, currenttime); }
};
\r
#endif\r
#define MAX(X,Y) (X)>(Y)?(X):(Y)
#define MIN(X,Y) (X)<(Y)?(X):(Y)
+#define EPSILON 0.00001f
+
bool fileExists(const String &f);
bool dirExists(const String &d);
Vector2D<int> rotatePoint(const Vector2D<int> pos, const Vector2D<int> center, const double &angle);
#include "Config.hpp"
#include "Tools.hpp"
+#include "Pair.hpp"
+//#include "Metronome.hpp"
class Track
{
void addKey(uint32_t time, uint8_t note);
void remKey(uint32_t time, uint8_t note);
- void addTempo(uint32_t pos, uint32_t t) { _tempo[pos] = t; }
- void addTimesignature(uint32_t pos, uint32_t t) { _timesignatures[pos] = t; }
-
+ void addTempo(uint32_t tick, float timestamp, uint32_t t) { _tempo[tick] = Pair<float, uint32_t>(timestamp, t); }
+ void addTimesignature(uint32_t tick, float timestamp, uint32_t t) { _timesignatures[tick] = Pair<float, uint32_t>(timestamp, t); }
+ map<uint32_t, Pair<float, uint32_t> > *getTempos() { return &_tempo; }
+ map<uint32_t, Pair<float, uint32_t> > *getTimeSignatures() { return &_timesignatures; }
+
// int getTempo() const { return _currenttempo; }
// void setTempo(uint32 t) { _currenttempo = t; }
uint32_t ticksToBeats(uint32_t time) { return 60000000 / time; }
void displayTracks();
- void drawFrets(double postime) const;
- void drawNotes(double postime, uint8_t diff) const;
+ void drawFrets(float postime) const;
+ void drawNotes(float postime, uint8_t difficulty) const;
+// void checkMetronome(float postime, Metronome *m) const;
uint32_t getNbNotes(uint32_t k) const { return _nbnotes[k]; }
uint32_t getTotalLength(uint32_t k) const { return _totallength[k]; }
Config getNote(uint32_t pos, uint8_t difficulty);
uint32_t getTempo(uint32_t pos);
- uint32_t getTimeSignatures(uint32_t pos);
+ uint32_t getTimeSignature(uint32_t pos);
+ uint32_t getTempo(float pos);
+ uint32_t getTimeSignature(float pos);
- list<Pair<uint32_t, double> > getBips() const { return _bips; }
- void addBip(uint32_t tick, double timestamp) { _bips.push_back(Pair<uint32_t, double>(tick, timestamp)); }
+ list<Pair<uint32_t, float> > * getBips() { return &_bips; }
+ void addBip(uint32_t tick, float timestamp) { _bips.push_back(Pair<uint32_t, float>(tick, timestamp)); }
//void computeBips();
private:
//notes : position ; configs
map<uint32_t, Config> _notes[NBDIFFICULTIES];
- map<uint32_t, uint32_t> _tempo;
- map<uint32_t, uint32_t> _timesignatures;
+ map<uint32_t, Pair<float, uint32_t> > _tempo;
+ map<uint32_t, Pair<float, uint32_t> > _timesignatures;
// private:
- list<Pair<uint32_t, double> > _bips;
+ list<Pair<uint32_t, float> > _bips;
Config _currentconfig[NBDIFFICULTIES];
public:
Wiimote(int nb=1);
- void handleEvents();
+ void handleEvents(float currenttime);
void vibration(int wiimote, int time);
- virtual void handleStrumOn() = 0;
- virtual void handleStrumOff() = 0;
- virtual void handleButtonOn(int k) = 0;
- virtual void handleButtonOff(int k) = 0;
- virtual void handleButtons(bool a, bool b, bool c, bool d, bool e) = 0;
+ virtual void handleStrumOn(float currenttime) = 0;
+ virtual void handleStrumOff(float currenttime) = 0;
+ virtual void handleButtonOn(int k, float currenttime) = 0;
+ virtual void handleButtonOff(int k, float currenttime) = 0;
+ virtual void handleButtons(bool a, bool b, bool c, bool d, bool e, float currenttime) = 0;
private:
- void handleKey(guitar_hero_3_t* gh3, int key, int button);
+ void handleKey(guitar_hero_3_t* gh3, int key, int button, float currenttime);
wiimote **_wiimotes;
int _nb;
bool _strumstate, _keystate[5];
float timestamp = 0;
uint32_t currenttempo = 60000000/120;
+ if (addbips)
+ tr.addBip(0, 0.0);
+
// Track example;
uint32_t delta = 0;
if (addbips)
{
uint32_t lastbiptick = 0;
- if (!tr.getBips().empty())
- lastbiptick = tr.getBips().back().getX();
+ lastbiptick = tr.getBips()->back().getX();
float temptimestamp = timestamp;
//manage 1st bip, taking into account the time elapsed since the last event
if (lastbiptick > 0 && ticks >= lastbiptick + 480)
tr.addBip(lastbiptick, temptimestamp);
}
//add bips with the current tempo
- for (uint32_t i = lastbiptick ; i < ticks ; i += 480 )
+ for (uint32_t i = lastbiptick + 480 ; i < ticks ; i += 480 )
{
- tr.addBip(i, temptimestamp);
temptimestamp += currenttempo / 1000.0f;
+ tr.addBip(i, temptimestamp);
}
}
tempo = ((int(data[2]) << 16) + (int(data[1]) << 8) + int(data[0]));
cout << "Tempo at " << ticks << " : x=" << tempo << "=" << 60000000 / tempo << "bpm" << endl;
currenttempo = tempo;
- tr.addTempo(ticks, tempo);
+ tr.addTempo(ticks, timestamp, tempo);
break;
case 0x58:
cout << "Time signature at " << ticks<< " : " << int(data[3]) << "|" << int(pow(float(2), int(data[2]))) << " " << int(data[1]) << " ticks " << int(data[0]) << "x" << endl;
- tr.addTimesignature(ticks, int(data[3]));
+ tr.addTimesignature(ticks, timestamp, int(data[3]));
break;
case 0x59:
cout << "Key signature: " << int(data[1]) << " " << int(data[0]) << endl;
if (addbips)
{
uint32_t lastbiptick = 0;
- if (!tr.getBips().empty())
- lastbiptick = tr.getBips().back().getX();
+ if (!tr.getBips()->empty())
+ lastbiptick = tr.getBips()->back().getX();
float temptimestamp = timestamp;
//manage 1st bip, taking into account the time elapsed since the last event
if (lastbiptick > 0)
#include <GL/glew.h>
#ifdef WIN32
-#include <time.h>
-#include <windows.h>
-
#include <SDL.h>
#include <SDL_mixer.h>
#include <SDL_image.h>
#else
-#include <sys/time.h>
-
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include <SDL/SDL_image.h>
Config fromKeyboard;
extern FILE*logfile;
-
-#ifdef WIN32
- struct { int tv_sec, tv_usec; } start;
- DWORD t;
-#else
- struct timeval start;
+\r
+#if SDL_VERSION_ATLEAST(1,3,0)\r
+SDL_Window *window;
+SDL_Renderer *renderer;
#endif
void init()
resolution_y = 768;
}
}
-
+ \r
+#if 0//SDL_VERSION_ATLEAST(1,3,0)\r
+ if ((window = SDL_CreateWindow("Haptic Metronome",\r
+ SDL_WINDOWPOS_CENTERED,\r
+ SDL_WINDOWPOS_CENTERED,\r
+ resolution_x, resolution_y,\r
+ SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN)) == NULL)
+ throw "Unable to create the window";
+
+ if ((renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED)) == NULL)
+ throw "unable to create the renderer";
+ /*
+ GLdouble ratio = (GLdouble) window->w / window->h;
+
+ printf("infos : %d %d %d %d\n", window->flags, window->w, window->h, window->pitch);
+ printf("Video resolution: %dx%dx%d (ratio = %3.2f)\n", window->w, window->h, window->surface->format->BitsPerPixel, ratio);*/
+ printf("OpenGL infos\n");
+ printf("------------\n");
+ printf("Vendor : %s\n", glGetString(GL_VENDOR));
+ printf("Renderer : %s\n", glGetString(GL_RENDERER));
+ printf("Version : %s\n", glGetString(GL_VERSION));
+ printf("Extensions: %s\n", glGetString(GL_EXTENSIONS));
+#else
//initializes Opengl
- if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
- throw "Couldn't initialise Video SubSystem: %s\n";
+// if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
+// throw "Couldn't initialise Video SubSystem: %s\n";
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 8);
- int flags = SDL_OPENGL | SDL_OPENGLBLIT | SDL_HWSURFACE;// | SDL_FULLSCREEN;
+ int flags = SDL_OPENGL | SDL_OPENGL | SDL_HWSURFACE;// | SDL_FULLSCREEN;
// int flags = SDL_OPENGL | SDL_OPENGLBLIT | SDL_SWSURFACE | SDL_FULLSCREEN;
SDL_Surface * screen;
printf("Renderer : %s\n", glGetString(GL_RENDERER));
printf("Version : %s\n", glGetString(GL_VERSION));
printf("Extensions: %s\n", glGetString(GL_EXTENSIONS));
+#endif
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
texturefond = new Texture("back.jpg");
texturesteel = new Texture("steel.jpg");
-
-#ifdef WIN32
- t = timeGetTime ();
- start.tv_sec = t / 1000;
- start.tv_usec = (t % 1000) * 1000;
-#else
- gettimeofday(&start, NULL);
-#endif
}
-void draw(Track &t, char diff)
+void draw(Track &t, float currenttime, char diff)
{
-#ifdef WIN32
- struct { int tv_sec, tv_usec; } now;
- DWORD tim;
-#else
- struct timeval now;
-#endif
-
-#ifdef WIN32
- tim = timeGetTime ();
- now.tv_sec = tim / 1000;
- now.tv_usec = (tim % 1000) * 1000;
-#else
- gettimeofday(&now, NULL);
-#endif
- float postime = (now.tv_sec - start.tv_sec) * 1000.0f + (now.tv_usec - start.tv_usec) / 1000.0;
- posz = -SECONDSIZE * postime;
+ posz = -SECONDSIZE * currenttime;
// cout << "draw screen" << endl;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// glColor(1.0, 1.0, 1.0, 0.0);
- //Draw the back
+ //Draw the background
glDisable(GL_LIGHTING);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
texturebois->useTexture();
glBegin(GL_QUADS);
glColor3f(1.0f, 1.0f, 1.0f); // Set The Color To Green
- glTexCoord2d(0.0f, 0.0f); glVertex3f( NECKWIDTH,0, 0);
- glTexCoord2d(0.0f, 20000); glVertex3f( NECKWIDTH,0,-1500000);
- glTexCoord2d(1.0f, 20000); glVertex3f(-NECKWIDTH,0,-1500000);
- glTexCoord2d(1.0f, 0.0f); glVertex3f(-NECKWIDTH,0, 0);
+ glTexCoord2d(0, 0); glVertex3f( NECKWIDTH,0, 0);
+ glTexCoord2d(0, 20000); glVertex3f( NECKWIDTH,0,-1500000);
+ glTexCoord2d(1, 20000); glVertex3f(-NECKWIDTH,0,-1500000);
+ glTexCoord2d(1, 0); glVertex3f(-NECKWIDTH,0, 0);
glEnd();
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
- glTranslatef(0,0,posz);
+ glTranslatef(0, 0, posz);
//draw the strings
for (int i = 0 ; i < 5 ; i++)
{
glPopMatrix();
//draw the frets
- t.drawFrets(postime);
+ t.drawFrets(currenttime);
// Draw the notes
- t.drawNotes(postime, diff);
+ t.drawNotes(currenttime, diff);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glEnd(); // Done Drawing The Quad
}
-void handleKeyOn(keys k)
+void handleKeyOn(keys k, float currenttime)
{
fromKeyboard.addKey(k);
/* switch(k)
}*/
}
-void handleKeyOff(keys k)
+void handleKeyOff(keys k, float currenttime)
{
// fromKeyboard.remKey(k);
if (fromKeyboard.getPosition() == -1)
return;
-
-#ifdef WIN32
- struct { int tv_sec, tv_usec; } now;
- DWORD t;
-#else
- struct timeval now;
-#endif
-
-#ifdef WIN32
- t = timeGetTime ();
- now.tv_sec = t / 1000;
- now.tv_usec = (t % 1000) * 1000;
-#else
- gettimeofday(&now, NULL);
-#endif
-
- double postime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000.0;
- fromKeyboard.setEnd(postime);
+ fromKeyboard.setEnd(currenttime);
cout << fromKeyboard << endl;
fromKeyboard.log("Play", logfile);
- fromKeyboard.setPosition(postime);
+ fromKeyboard.setPosition(currenttime);
fromKeyboard.setEnd(-1);
}
-void handleKeys(bool a, bool b, bool c, bool d, bool e)
+void handleKeys(bool a, bool b, bool c, bool d, bool e, float currenttime)
{
if (fromKeyboard.isNone())
fromKeyboard.setPosition(-1);
fromKeyboard.setKeys(a, b, c, d, e);
}
-void handleStrokeOn()
+void handleStrokeOn(float currenttime)
{
-#ifdef WIN32
- struct { int tv_sec, tv_usec; } now;
- DWORD t;
-#else
- struct timeval now;
-#endif
-
-#ifdef WIN32
- t = timeGetTime ();
- now.tv_sec = t / 1000;
- now.tv_usec = (t % 1000) * 1000;
-#else
- gettimeofday(&now, NULL);
-#endif
-
- double postime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000.0;
- //cout << postime << endl;
-
if (fromKeyboard.getPosition() != -1)
{
- fromKeyboard.setEnd(postime);
+ fromKeyboard.setEnd(currenttime);
cout << fromKeyboard << endl;
fromKeyboard.log("Play", logfile);
}
- fromKeyboard.setPosition(postime);
+ fromKeyboard.setPosition(currenttime);
fromKeyboard.setEnd(-1);
}
-bool processEvents()
+void handleStrokeOff(float currenttime)
+{
+}
+
+bool processEvents(float currenttime)
{
SDL_Event event;
// bool quitProgram = false;
break;
case SDL_KEYDOWN:
+#if SDL_VERSION_ATLEAST(1,3,0)\r
+ keystate = SDL_GetKeyboardState(NULL);
+ handleKeys(keystate[SDL_SCANCODE_F1], keystate[SDL_SCANCODE_F2], keystate[SDL_SCANCODE_F3], keystate[SDL_SCANCODE_F4], keystate[SDL_SCANCODE_F5], currenttime);
+#else
keystate = SDL_GetKeyState(NULL);
- handleKeys(keystate[SDLK_F1], keystate[SDLK_F2], keystate[SDLK_F3], keystate[SDLK_F4], keystate[SDLK_F5]);
+ handleKeys(keystate[SDLK_F1], keystate[SDLK_F2], keystate[SDLK_F3], keystate[SDLK_F4], keystate[SDLK_F5], currenttime);
+#endif
switch(((SDL_KeyboardEvent *)(&event))->keysym.sym)
{
case SDLK_ESCAPE:
return true;
case SDLK_UP:
- SECONDSIZE +=10;
+ SECONDSIZE += 0.01f;
break;
case SDLK_DOWN:
- SECONDSIZE -=1;
+ SECONDSIZE -= 0.01f;
break;
/* case SDLK_LEFT:
posy +=1;
handleKeyOn(KEY4);
break;*/
case SDLK_SPACE:
- handleStrokeOn();
+ handleStrokeOn(currenttime);
break;
default:
break;
switch(((SDL_KeyboardEvent *)(&event))->keysym.sym)
{
case SDLK_F1:
- handleKeyOff(KEY0);
+ handleKeyOff(KEY0, currenttime);
break;
case SDLK_F2:
- handleKeyOff(KEY1);
+ handleKeyOff(KEY1, currenttime);
break;
case SDLK_F3:
- handleKeyOff(KEY2);
+ handleKeyOff(KEY2, currenttime);
break;
case SDLK_F4:
- handleKeyOff(KEY3);
+ handleKeyOff(KEY3, currenttime);
break;
case SDLK_F5:
- handleKeyOff(KEY4);
+ handleKeyOff(KEY4, currenttime);
break;
case SDLK_SPACE:
- handleStrokeOff();
+ handleStrokeOff(currenttime);
break;
default:
break;
}
+#if SDL_VERSION_ATLEAST(1,3,0)\r
+ keystate = SDL_GetKeyboardState(NULL);
+ handleKeys(keystate[SDL_SCANCODE_F1], keystate[SDL_SCANCODE_F2], keystate[SDL_SCANCODE_F3], keystate[SDL_SCANCODE_F4], keystate[SDL_SCANCODE_F5], currenttime);
+#else
keystate = SDL_GetKeyState(NULL);
- handleKeys(keystate[SDLK_F1], keystate[SDLK_F2], keystate[SDLK_F3], keystate[SDLK_F4], keystate[SDLK_F5]);
+ handleKeys(keystate[SDLK_F1], keystate[SDLK_F2], keystate[SDLK_F3], keystate[SDLK_F4], keystate[SDLK_F5], currenttime);
+#endif
break;
default:
// lasteventtype = OTHER;
size[C_X] = surface->w;
size[C_Y] = surface->h;
SDL_Surface *temp = NULL;
+#if SDL_VERSION_ATLEAST(1,3,0)\r
+/* SDL_PixelFormat format = {
+ SDL_PIXELFORMAT_RGBA8888,
+ NULL,
+ 32,
+ 4,
+ 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000,
+ 0, 0, 0, 0,
+ 0, 8, 16, 24,
+ surface->format->refcount,
+ surface->format->next};*/
+#else
SDL_PixelFormat format = {NULL, 32, 4, 0, 0, 0, 0, 0, 8, 16, 24, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000, 0, 255};
+#endif
switch(surface->format->BitsPerPixel)
{
case 24:
//convert to 32bits
+#if SDL_VERSION_ATLEAST(1,3,0)\r
+ temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ABGR8888, SDL_SWSURFACE);
+#else
temp = SDL_ConvertSurface(surface, &format, SDL_SWSURFACE);
+#endif
SDL_FreeSurface(surface);
surface = temp;
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, surface->w, surface->h, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels);
- break;
+ break;
case 32:
//convert if it's ABGR
if (surface->format->Rshift > surface->format->Bshift)
{
+#if SDL_VERSION_ATLEAST(1,3,0)\r
+ temp = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_ABGR8888, SDL_SWSURFACE);
+#else
temp = SDL_ConvertSurface(surface, &format, SDL_SWSURFACE);
+#endif
SDL_FreeSurface(surface);
surface = temp;
}
*/
#include "Tools.hpp"
+#ifdef WIN32
+#include <SDL.h>
+#else
+#include <SDL/SDL.h>
+#endif
+
#include <cmath>
#include <cstdio>
#include <sys/types.h>
#include "Track.hpp"
-#include "Mixer.hpp"
#include "Texture.hpp"
#include <map>
+#include <windows.h>
+#include <iostream>
+#include <sstream>
+using namespace std;
+
extern Texture* texturesteel;
extern FILE *logfile;
extern float SECONDSIZE;
_currentconfig[difficulty].setTicks(time - _currentconfig[difficulty].getTime());
//compute the note duration and position
uint32_t currenttempo = 0, lasttick = 0;
- map<uint32_t, uint32_t>::iterator ti = _tempo.begin();
+ map<uint32_t, Pair<float, uint32_t> >::iterator ti = _tempo.begin();
uint32_t tickpos = _currentconfig[difficulty].getTime();
while (ti != _tempo.end() && (*ti).first <= tickpos)
{
_currentconfig[difficulty].setPosition(_currentconfig[difficulty].getPosition() + ((*ti).first - lasttick) * (currenttempo / 480000.0));
lasttick = (*ti).first;
- currenttempo = (*ti).second;
+ currenttempo = (*ti).second.getY();
ti++;
}
if (tickpos > lasttick)
{
_currentconfig[difficulty].setEnd(_currentconfig[difficulty].getPosition() + ((*ti).first - tickpos) * (currenttempo / 480000.0));
tickpos = (*ti).first;
- currenttempo = (*ti).second;
+ currenttempo = (*ti).second.getY();
ti++;
}
else
{
if (_tempo.count(pos) == 0)
throw 0;
- return _tempo[pos];
+ return _tempo[pos].getY();
}
-uint32_t Track::getTimeSignatures(uint32_t pos)
+uint32_t Track::getTimeSignature(uint32_t pos)
{
if (_timesignatures.count(pos) == 0)
throw 0;
- return _timesignatures[pos];
+ return _timesignatures[pos].getY();
+}
+
+
+uint32_t Track::getTempo(float pos)
+{
+ for( map<uint32_t, Pair<float, uint32_t> >::iterator ii=_tempo.begin(); ii!=_tempo.end(); ++ii)
+ if ((*ii).second.getX() - pos < EPSILON)
+ return (*ii).second.getY();
+ return 0;
}
+
+uint32_t Track::getTimeSignature(float pos)
+{
+ for( map<uint32_t, Pair<float, uint32_t> >::iterator ii=_timesignatures.begin(); ii!=_timesignatures.end(); ++ii)
+ if ((*ii).second.getX() - pos < EPSILON)
+ return (*ii).second.getY();
+ return 0;
+}
+
/*
void Track::computeBips()
{
void Track::debugTempo()
{
cout << "Tempo changes: " << endl;
- for( map<uint32_t,uint32_t>::iterator ii=_tempo.begin(); ii!=_tempo.end(); ++ii)
- cout << (*ii).first << ": " << (*ii).second << " (" << ticksToBeats((*ii).second) << ")" << endl;
+ for( map<uint32_t, Pair<float, uint32_t> >::iterator ii=_tempo.begin(); ii!=_tempo.end(); ++ii)
+ cout << (*ii).first << ": " << (*ii).second.getX() << " (" << (*ii).second.getY() << ")" << endl;
+ //ticksToBeats((*ii).second) << ")" << endl;
}
-void Track::drawFrets(double postime) const
+void Track::drawFrets(float postime) const
{
- static list<Pair<uint32_t, double> >::const_iterator startingbips = _bips.begin();
+ static list<Pair<uint32_t, float> >::const_iterator startingbips = _bips.begin();
// on avance tant que les bips sont dépassées
while (startingbips != _bips.end() && (*startingbips).getY() < postime)
{
- Mixer::getInstance()->playSound("bip");
+// Mixer::getInstance()->playSound("bip");
if (logfile)
fprintf(logfile, "Bip;%f;%f;%f\n", (*startingbips).getY(), postime, postime - (*startingbips).getY());
startingbips++;
}
- list<Pair<uint32_t, double> >::const_iterator b = startingbips;
+ list<Pair<uint32_t, float> >::const_iterator b = startingbips;
glMatrixMode(GL_MODELVIEW);
//on dessine les frettes jusqu'à 10s
}
}
-void Track::drawNotes(double postime, uint8_t diff) const
+void Track::drawNotes(float postime, uint8_t diff) const
{
static map<uint32_t,Config>::const_iterator startingn = _notes[diff].begin();
static double startingpos = 0.0;
n++;
}
}
+/*
+void Track::checkMetronome(float postime, Metronome *m) const
+{
+ static map<uint32_t, Pair<float, uint32_t> >::const_iterator cTempo = _tempo.begin();
+ static map<uint32_t, Pair<float, uint32_t> >::const_iterator cTimesignature = _timesignatures.begin();
+ static double startingpos = 0.0;
+
+ // on avance tant que les tempos sont dépassées
+ while (cTempo != _tempo.end() && (*cTempo).second.getX() < postime)
+ {
+ //tempo change
+ stringstream s;
+ s << "Tempo change at " << postime << " : tick=" << (*cTempo).first << " at " << (*cTempo).second.getX() << " for " << (60000000/(*cTempo).second.getY()) << " bpm " << endl;
+ OutputDebugString(s.str().c_str());
+ m->setTempo((*cTempo).second.getY());
+ cTempo++;
+ }
+
+ // on avance tant que les tempos sont dépassées
+ while (cTimesignature != _timesignatures.end() && (*cTimesignature).second.getX() < postime)
+ {
+ //tempo change
+ stringstream s;
+ s << "Time signature change at " << postime << " : tick=" << (*cTimesignature).first << " at " << (*cTimesignature).second.getX() << " for " << (*cTimesignature).second.getY() << " beats " << endl;
+ m->setNbBeats((*cTimesignature).second.getY());
+ OutputDebugString(s.str().c_str());
+ cTimesignature++;
+ }
+}*/
\ No newline at end of file
}
}
-void Wiimote::handleKey(guitar_hero_3_t* gh3, int key, int button)
+void Wiimote::handleKey(guitar_hero_3_t* gh3, int key, int button, float currenttime)
{
if (_keystate[key])
{
if (!IS_PRESSED(gh3, button))
- handleButtonOff(key);
+ handleButtonOff(key, currenttime);
_keystate[key] = false;
}
else
{
if (IS_PRESSED(gh3, button))
- handleButtonOn(key);
+ handleButtonOn(key, currenttime);
_keystate[key] = true;
}
}
-void Wiimote::handleEvents()
+void Wiimote::handleEvents(float currenttime)
{
if (!wiiuse_poll(_wiimotes, _nb))
return;
{
if (!IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_UP) && !IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_DOWN))
{
- handleStrumOff();
+ handleStrumOff(currenttime);
_strumstate = false;
}
}
{
if (IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_UP) || IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_STRUM_DOWN))
{
- handleStrumOn();
+ handleStrumOn(currenttime);
_strumstate = true;
}
}
IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_RED),
IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_YELLOW),
IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_BLUE),
- IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_ORANGE));
+ IS_PRESSED(gh3, GUITAR_HERO_3_BUTTON_ORANGE),
+ currenttime);
/* handleKey(gh3, 0, GUITAR_HERO_3_BUTTON_GREEN);
handleKey(gh3, 1, GUITAR_HERO_3_BUTTON_RED);
handleKey(gh3, 2, GUITAR_HERO_3_BUTTON_YELLOW);
#include "Track.hpp"
#include "Mixer.hpp"
#include "PaintGame.h"
+#include "Metronome.hpp"
+#include "MetronomeAudio.hpp"
#ifdef WIN32
+#include <time.h>
#include <SDL.h>
-
+#include <windows.h>
#else
+#include <sys/time.h>
+
#include <SDL/SDL.h>
#endif
cout << "Loading sounds" << endl;
- Mixer::getInstance()->addSound("guitar", songname + "/guitar.ogg");
- bool rhythm = Mixer::getInstance()->addSound("rhythm", songname + "/rhythm.ogg");
+// Mixer::getInstance()->addSound("guitar", songname + "/guitar.ogg");
+// bool rhythm = Mixer::getInstance()->addSound("rhythm", songname + "/rhythm.ogg");
- Mixer::getInstance()->addSound("bip","bip.ogg");
Mixer::getInstance()->setMusicVolume(30);
Mixer::getInstance()->setSoundVolume(30);
cout << "Init paint" << endl;
initPaint();
+ Metronome *m = new MetronomeAudio(&tr);
+
+
+#ifdef WIN32
+ struct { int tv_sec, tv_usec; } start;
+ DWORD t = timeGetTime ();
+ start.tv_sec = t / 1000;
+ start.tv_usec = (t % 1000) * 1000;
+#else
+ struct timeval start;
+ gettimeofday(&start, NULL);
+#endif
+
cout << "LET'S ROCK!" << endl;
+ //m->setActive(true);
- Mixer::getInstance()->playMusic(songname + "/song.ogg");
- Mixer::getInstance()->playSound("guitar");
+ Mixer::getInstance()->playMusic(songname + "/tout.ogg");
+ m->run();
+/* Mixer::getInstance()->playSound("guitar");
if (rhythm)
Mixer::getInstance()->playSound("rhythm");
-/*
+ */
+ /*
Sound music;
cout << "Load sounds" << endl;
music.addSound(songname + "/song.ogg");
while(!quitProgram)
{
+ //compute current time in the loop
+#ifdef WIN32
+ struct { int tv_sec, tv_usec; } now;
+ DWORD tim = timeGetTime ();
+ now.tv_sec = tim / 1000;
+ now.tv_usec = (tim % 1000) * 1000;
+#else
+ struct timeval now;
+ gettimeofday(&now, NULL);
+#endif
+ float currenttime = (now.tv_sec - start.tv_sec) * 1000.0f + (now.tv_usec - start.tv_usec) / 1000.0f;
+
+ // cout << "draw" << endl;
+ draw(tr, currenttime, NORMAL);
// cout << "events" << endl;
- quitProgram = processEvents();
+ quitProgram = processEvents(currenttime);
if (iswiimoteconnected)
- mw->handleEvents();
-// cout << "draw" << endl;
- draw(tr, NORMAL);
+ mw->handleEvents(currenttime);
// cout << "pause" << endl;
// SDL_Delay(10);
+ // check metronome events
+// tr.checkMetronome(currenttime, m);
}
- if (logfile)
- fclose(logfile);
+ delete m;
+
+ if (logfile)
+ fclose(logfile);
return 1;
}