class Metronome\r
{\r
public:\r
- Metronome(Track *track, uint32_t nbbeats=4, uint32_t tempo=0, bool activated=false);\r
+ Metronome(const Track *track, uint32_t nbbeats=4, uint32_t tempo=0, bool activated=false);\r
virtual ~Metronome(){}\r
\r
virtual void setActive(bool activated) { _activated = activated; }\r
uint32_t _nbbeats;\r
uint32_t _tempo;\r
bool _activated;\r
- Track *_track;\r
+ const Track *_track;\r
};\r
\r
#endif\r
class MetronomeAudio : public Metronome\r
{ \r
public:\r
- MetronomeAudio(Track *track, uint32_t nbbeats=4, uint32_t tempo=0, bool activated=true);\r
+ MetronomeAudio(const Track *track, uint32_t nbbeats=4, uint32_t tempo=0, bool activated=true);\r
\r
~MetronomeAudio();\r
\r
class MetronomeHaptic : public Metronome\r
{ \r
public:\r
- MetronomeHaptic(Track *track, uint32_t nbbeats=4, uint32_t tempo=0, bool activated=true);\r
+ MetronomeHaptic(const Track *track, uint32_t nbbeats=4, uint32_t tempo=0, bool activated=true);\r
\r
~MetronomeHaptic();\r
\r
#define POSITION_HEIGHT 35
#define POSITION_EYE 45
#define POSITION_CENTER (-70)
-#define VIEWLENGTH 250
#include "Track.hpp"
+#include "String.hpp"
#include "Wiimote.hpp"
void init();
void initPaint();
-void draw(Track &t, uint32_t currenttime, char diff);\r
+void draw(const Track &t, 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 handleKeys(bool a, bool b, bool c, bool d, bool e, uint32_t currenttime);
void handleStrokeOn(uint32_t currenttime);\r
void handleStrokeOff(uint32_t currenttime);\r
-bool processEvents(uint32_t currenttime);
+bool processEvents();
+void loop(const Track &tr, const String &songname);
class MyWiimote: public Wiimote
{
#include "Vector2D.hpp"
#include <cmath>
+#include <string>\r
+#include <sstream>\r
+#include <iostream>\r
+using namespace std;\r
+
#define MAX(X,Y) (X)>(Y)?(X):(Y)
#define MIN(X,Y) (X)<(Y)?(X):(Y)
public:
Track();
Track(const Track &);
+ //create an empty track with the specified tempo and specified duration
+ Track(uint32_t tempo, uint32_t duration);
~Track();
void addKey(uint32_t time, uint8_t note);
void addTempo(uint32_t tick, uint32_t timestamp, uint32_t t) { _tempo[tick] = Pair<uint32_t, uint32_t>(timestamp, t); }
void addTimesignature(uint32_t tick, uint32_t timestamp, uint32_t t) { _timesignatures[tick] = Pair<uint32_t, uint32_t>(timestamp, t); }
- map<uint32_t, Pair<uint32_t, uint32_t> > *getTempos() { return &_tempo; }
- map<uint32_t, Pair<uint32_t, uint32_t> > *getTimeSignatures() { return &_timesignatures; }
+ const map<uint32_t, Pair<uint32_t, uint32_t> > *getTempos() const { return &_tempo; }
+ const map<uint32_t, Pair<uint32_t, uint32_t> > *getTimeSignatures() const { return &_timesignatures; }
// int getTempo() const { return _currenttempo; }
// void setTempo(uint32 t) { _currenttempo = t; }
// uint32 beatsToTicks(uint32 time) { return (time * _currenttempo * 480) / 60000.0; }
- uint32_t beatsToTicks(uint32_t time, uint32_t tempo) { return (time * tempo * 480) / 60000; }
- uint32_t ticksToBeats(uint32_t time) { return 60000000 / time; }
+// uint32_t beatsToTicks(uint32_t time, uint32_t tempo) { return (time * tempo * 480) / 60000; }
+// uint32_t ticksToBeats(uint32_t time) { return 60000000 / time; }
void displayTracks();
void drawFrets(uint32_t postime) const;
uint32_t getTempo(uint32_t tick);
uint32_t getTimeSignature(uint32_t tick);
- list<Pair<uint32_t, uint32_t> > * getBips() { return &_bips; }
+ const list<Pair<uint32_t, uint32_t> > * getBips() const { return &_bips; }
void addBip(uint32_t tick, uint32_t timestamp) { _bips.push_back(Pair<uint32_t, uint32_t>(tick, timestamp)); }
//void computeBips();
private:
//notes : position ; configs
map<uint32_t, Config> _notes[NBDIFFICULTIES];
- map<uint32_t, Pair<uint32_t, uint32_t> > _tempo;
+ map<uint32_t, Pair<uint32_t, uint32_t> > _tempo; //microseconds per quarter-note
map<uint32_t, Pair<uint32_t, uint32_t> > _timesignatures;
// (beat, timestamp)
public:
Wiimote(int nb=1);
- void handleEvents(uint32_t currenttime);
+ void handleEvents();
void vibration(int wiimote, int time);
#include "Metronome.hpp"\r
\r
-Metronome::Metronome(Track *track, uint32_t nbbeats, uint32_t tempo, bool activated)\r
+Metronome::Metronome(const Track *track, uint32_t nbbeats, uint32_t tempo, bool activated)\r
:_track(track), _nbbeats(nbbeats), _tempo(tempo), _activated(activated)\r
{\r
}\r
#ifdef WIN32
#include <time.h>
#include <windows.h>
+ extern struct { int tv_sec, tv_usec; } start;
#else
#include <sys/time.h>
+ extern struct timeval start;
#endif
-MetronomeAudio::MetronomeAudio(Track *track, uint32_t nbbeats, uint32_t tempo, bool activated)
+#define BIPLENGTH 10
+
+extern FILE*logfile;
+
+MetronomeAudio::MetronomeAudio(const Track *track, uint32_t nbbeats, uint32_t tempo, bool activated)
:Metronome(track, nbbeats, tempo, activated), thread(NULL)
{
- Mixer::getInstance()->addSound("bip","bip.ogg");
+ Mixer::getInstance()->addSound("bip","bip10.ogg");
Mixer::getInstance()->addSound("bip2","bip2.ogg");
}
int currentbeat = 0;
#ifdef WIN32
- struct { int tv_sec, tv_usec; } now, start;
+ struct { int tv_sec, tv_usec; } now;//, start;
DWORD t = timeGetTime ();
- start.tv_sec = t / 1000;
- start.tv_usec = (t % 1000) * 1000;
+/* start.tv_sec = t / 1000;
+ start.tv_usec = (t % 1000) * 1000;*/
#else
- struct timeval now, start;
- gettimeofday(&start, NULL);
+ struct timeval now;/*, start;
+ gettimeofday(&start, NULL);*/
#endif
uint32_t currenttime = 0;
float lag = 0.0;
while(thismetronome->_activated)
{
#ifdef WIN32
- t = timeGetTime ();
+ t = timeGetTime () + BIPLENGTH;
now.tv_sec = t / 1000;
now.tv_usec = (t % 1000) * 1000;
#else
#endif
uint32_t currenttime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000;
- while (cBips != bips->end() && currenttime >= (*cBips).getY())
+ 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++;
}
#include <time.h>
#include <windows.h>
#include "SerialWindows.hpp"
+ extern struct { int tv_sec, tv_usec; } start;
#else
#include <sys/time.h>
#include "SerialLinux.hpp"
+ extern struct timeval start;
#endif
-#define BEFOREDELAY 20
+#define BEFOREDELAY 150
-MetronomeHaptic::MetronomeHaptic(Track *track, uint32_t nbbeats, uint32_t tempo, bool activated)
+extern FILE *logfile;
+
+MetronomeHaptic::MetronomeHaptic(const Track *track, uint32_t nbbeats, uint32_t tempo, bool activated)
:Metronome(track, nbbeats, tempo, activated), thread(NULL), _comport(new SerialWindows("COM5"))
{
}
static list<Pair<uint32_t, uint32_t> >::const_iterator cBips = bips->begin();
//static map<uint32_t, Pair<float, uint32_t> >::const_iterator cTempo = tempo->begin();
static map<uint32_t, Pair<uint32_t, uint32_t> >::const_iterator cTimesignature = timesignatures->begin();
-
+
#ifdef WIN32
- struct { int tv_sec, tv_usec; } now, start;
+ struct { int tv_sec, tv_usec; } now;//, start
DWORD t = timeGetTime () - BEFOREDELAY;
- start.tv_sec = t / 1000;
- start.tv_usec = (t % 1000) * 1000;
+/* start.tv_sec = t / 1000;
+ start.tv_usec = (t % 1000) * 1000;*/
#else
- struct timeval now, start;
- gettimeofday(&start, NULL);
-#endif
+ struct timeval now;/*, start;
+ gettimeofday(&start, NULL);*/
+#endif*/
//float currenttime = 0;
char outBuffer[5];\r
while(thismetronome->_activated)
{
#ifdef WIN32
- t = timeGetTime ();
+ t = timeGetTime () + BEFOREDELAY;
now.tv_sec = t / 1000;
now.tv_usec = (t % 1000) * 1000;
#else
{
char outBuffer[5];\r
outBuffer[0] = 'N';\r
- outBuffer[1] = ((*cBips).getY() & 0xff000000) >> 24;\r
- outBuffer[2] = ((*cBips).getY() & 0x00ff0000) >> 16;\r
- outBuffer[3] = ((*cBips).getY() & 0x0000ff00) >> 8;\r
- outBuffer[4] = (*cBips).getY() & 0x000000ff;\r
+ outBuffer[1] = (BIPTIMESTAMP(*cBips) & 0xff000000) >> 24;\r
+ outBuffer[2] = (BIPTIMESTAMP(*cBips) & 0x00ff0000) >> 16;\r
+ outBuffer[3] = (BIPTIMESTAMP(*cBips) & 0x0000ff00) >> 8;\r
+ outBuffer[4] = BIPTIMESTAMP(*cBips) & 0x000000ff;\r
\r
bool written = thismetronome->_comport->WriteData(outBuffer, 5);\r
+ if (logfile)
+ fprintf(logfile, "BIP;%d;%d;%d\n", BIPTICK(*cBips), BIPTIMESTAMP(*cBips), currenttime);
cBips++;
}
// on avance tant que les tempos sont dépassées
- while (cTimesignature != timesignatures->end() && TIMESTAMP(*cTimesignature) < currenttime - BEFOREDELAY)
+ while (cTimesignature != timesignatures->end() && currenttime >= TIMESTAMP(*cTimesignature))
{
char outBuffer[5];\r
- outBuffer[0] = 'T';\r
- outBuffer[1] = ((*cTimesignature).second.getY() & 0xff000000) >> 24;\r
- outBuffer[2] = ((*cTimesignature).second.getY() & 0x00ff0000) >> 16;\r
- outBuffer[3] = ((*cTimesignature).second.getY() & 0x0000ff00) >> 8;\r
- outBuffer[4] = (*cTimesignature).second.getY() & 0x000000ff;\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
#include "Texture.hpp"
#include "Mixer.hpp"
+#include "Metronome.hpp"
+#include "MetronomeAudio.hpp"
+#include "MetronomeHaptic.hpp"
#include <GL/glew.h>
#include <SDL.h>
#include <SDL_mixer.h>
#include <SDL_image.h>
+ struct { int tv_sec, tv_usec; } start;
#else
+ struct timeval start;
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include <SDL/SDL_image.h>
#include <iostream>
using namespace std;
-float SECONDSIZE = 0.050f;
+int VIEWLENGTH = 250;
+extern float SECONDSIZE;
float posz = 0;
-Texture *texturebois, *texturefond, *texturesteel;
+Texture *texturebois, *texturefond, *texturesteel, *texturefrett;
int resolution_x, resolution_y;
Config fromKeyboard;
void init()
{
- //initializes SDL
- cout << "init SDL" << endl;
- const SDL_VideoInfo* info = NULL;
+ //initializes SDL
+ cout << "init SDL" << endl;
+ const SDL_VideoInfo* info = NULL;
- atexit(SDL_Quit);
+ atexit(SDL_Quit);
- if( SDL_Init(SDL_INIT_EVERYTHING) <0 )
- throw "Error while loading SDL";
+ if( SDL_Init(SDL_INIT_EVERYTHING) <0 )
+ throw "Error while loading SDL";
- //Initialize SDL_mixer
- if (Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 1024 ) == -1 )
- throw String("Can't initialize sound");
+ //Initialize SDL_mixer
+ if (Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 1024 ) == -1 )
+ throw String("Can't initialize sound");
- cout << "get video info" << endl;
- info = SDL_GetVideoInfo();
- if(!info)
- throw "Impossible to get information from SDL";
+ cout << "get video info" << endl;
+ info = SDL_GetVideoInfo();
+ if(!info)
+ throw "Impossible to get information from SDL";
- SDL_EnableUNICODE(1);
+ SDL_EnableUNICODE(1);
-// int width, height;
- // we search for the available screen sizes
- int searchflags = SDL_HWSURFACE;// | SDL_FULLSCREEN;
- SDL_Rect **modes = SDL_ListModes(NULL, searchflags);
- if (modes == NULL)
- throw "Impossible to get the screen resolution !";
- else if (modes == (SDL_Rect **)-1)
- {
- resolution_x = 1280;
- resolution_y = 1024;
- }
- else
- {
- int i;
- for (i=0 ; modes[i] ; i++)
- {
- cout << "Resolution available: " << modes[i]->w << "x" << modes[i]->h << endl;
- if (modes[i]->w == 1280 && modes[i]->h == 1024)
- {
- resolution_x = modes[i]->w;
- resolution_y = modes[i]->h;
- break;
- }
- }
- if (!modes[i])
- {
- cout << "Resolution wanted not available" << endl;
- resolution_x = 1024;
- resolution_y = 768;
- }
- }
+ // int width, height;
+ // we search for the available screen sizes
+ int searchflags = SDL_HWSURFACE;// | SDL_FULLSCREEN;
+ SDL_Rect **modes = SDL_ListModes(NULL, searchflags);
+ if (modes == NULL)
+ throw "Impossible to get the screen resolution !";
+ else if (modes == (SDL_Rect **)-1)
+ {
+ resolution_x = 1280;
+ resolution_y = 1024;
+ }
+ else
+ {
+ int i;
+ for (i=0 ; modes[i] ; i++)
+ {
+ cout << "Resolution available: " << modes[i]->w << "x" << modes[i]->h << endl;
+ if (modes[i]->w == 1280 && modes[i]->h == 1024)
+ {
+ resolution_x = modes[i]->w;
+ resolution_y = modes[i]->h;
+ break;
+ }
+ }
+ if (!modes[i])
+ {
+ cout << "Resolution wanted not available" << endl;
+ resolution_x = 1024;
+ resolution_y = 768;
+ }
+ }
\r
#if 0//SDL_VERSION_ATLEAST(1,3,0)\r
if ((window = SDL_CreateWindow("Haptic Metronome",\r
SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 8);
int flags = SDL_OPENGL | SDL_OPENGL | SDL_HWSURFACE;// | SDL_FULLSCREEN;
-
-// int flags = SDL_OPENGL | SDL_OPENGLBLIT | SDL_SWSURFACE | SDL_FULLSCREEN;
- SDL_Surface * screen;
- if (!(screen = SDL_SetVideoMode(resolution_x, resolution_y, 0, flags)))
- throw "Impossible to change the video mode";
+
+ glEnable(GL_MULTISAMPLE);
// Utilisation de l'anti-aliasing possible ?
if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1) == -1)
throw "Impossible to initialize SDL_GL_MULTISAMPLEBUFFERS";
// Nombre de tampons utilisés pour l'anti-aliasing (la valeur utilisée dépend de la carte graphique)
- if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 6) == -1)
+ if (SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 8) == -1)
throw "Impossible to initialize SDL_GL_MULTISAMPLESAMPLES";
+// int flags = SDL_OPENGL | SDL_OPENGLBLIT | SDL_SWSURFACE | SDL_FULLSCREEN;
+ SDL_Surface * screen;
+ if (!(screen = SDL_SetVideoMode(resolution_x, resolution_y, 0, flags)))
+ throw "Impossible to change the video mode";
+
GLdouble ratio = (GLdouble) screen->w / screen->h;
printf("infos : %d %d %d %d\n", screen->flags, screen->w, screen->h, screen->pitch);
#endif
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glClear(GL_COLOR_BUFFER_BIT);// | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, resolution_x, resolution_y);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
- glShadeModel(GL_SMOOTH);
+// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glDisable(GL_BLEND);
+// glShadeModel(GL_SMOOTH);
glEnable(GL_NORMALIZE);
+ //glDisable(GL_DEPTH_TEST);
+ glDepthMask(GL_TRUE);
+ glDepthFunc(GL_ALWAYS);
+ //glDepthFunc(GL_LEQUAL);
// glEnable(GL_POLYGON_SMOOTH);
GLfloat light_ambient[] = { 0.8f, 0.7f, 0.9f, 1.0f };
texturebois = new Texture("wood.jpg", true);
texturefond = new Texture("back.jpg");
texturesteel = new Texture("steel.jpg");
-
+ texturefrett = new Texture("frett.png");
}
-void draw(Track &t, uint32_t currenttime, char diff)
+void draw(const Track &t, char diff)
{
+#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
+ uint32_t currenttime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000;
+
posz = -SECONDSIZE * currenttime;
// cout << "draw screen" << endl;
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glClear(GL_COLOR_BUFFER_BIT);// | GL_DEPTH_BUFFER_BIT);
// glColor(1.0, 1.0, 1.0, 0.0);
//Draw the background
glTexCoord2f(1.0, 0.0); glVertex2f(float(resolution_x), 0.0f);
glEnd();
glDisable(GL_TEXTURE_2D);
-
+
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective( 45.0f, double(resolution_x) / double(resolution_y), 1/*POSITION_EYE+3*/, VIEWLENGTH );
// cout << "End: " << t.getEndOfTrack() << endl;
//glEnable(GL_LIGHTING);
- glPolygonOffset(1.0f, 4.0f);
+// glPolygonOffset(1.0f, 4.0f);
// Draw the guitar neck
- glEnable(GL_POLYGON_OFFSET_FILL);
+// glEnable(GL_POLYGON_OFFSET_FILL);
glEnable(GL_TEXTURE_2D);
texturebois->useTexture();
glBegin(GL_QUADS);
glTexCoord2f(1.0, 0.0); glVertex3f(-NECKWIDTH, 0.0, 0.0);
glEnd();
glDisable(GL_TEXTURE_2D);
- glDisable(GL_POLYGON_OFFSET_FILL);
+// glDisable(GL_POLYGON_OFFSET_FILL);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
{
}
-bool processEvents(uint32_t currenttime)
+bool processEvents()
{
+#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
+ uint32_t currenttime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000;
+
SDL_Event event;
// bool quitProgram = false;
case SDLK_SPACE:
handleStrokeOn(currenttime);
break;
+ case SDLK_RCTRL:
+ if (logfile)
+ fprintf(logfile, "PRESS;%d\n", currenttime);
+ break;
default:
break;
}
}
return false;
}
+
+void loop(const Track &tr, const String &songname)
+{
+ bool iswiimoteconnected = false;
+ Wiimote *mw;
+ try
+ {
+ mw = new MyWiimote();
+ iswiimoteconnected = true;
+ }
+ catch(...){}
+
+ init();
+ cout << "Create Metronome" << endl;
+ Metronome *m = new MetronomeAudio(&tr);
+// Metronome *m = new MetronomeHaptic(&tr);
+
+ bool quitProgram = false;
+
+ cout << "Loading sounds" << endl;
+
+// Mixer::getInstance()->addSound("guitar", songname + "/guitar.ogg");
+// bool rhythm = Mixer::getInstance()->addSound("rhythm", songname + "/rhythm.ogg");
+
+ Mixer::getInstance()->setMusicVolume(30);
+ Mixer::getInstance()->setSoundVolume(30);
+
+ cout << "Init paint" << endl;
+ initPaint();
+
+//must be done before paint and metronomes
+#ifdef WIN32
+ DWORD t = timeGetTime ();
+ start.tv_sec = t / 1000;
+ start.tv_usec = (t % 1000) * 1000;
+#else
+ gettimeofday(&start, NULL);
+#endif
+
+ cout << "LET'S ROCK!" << endl;
+ //m->setActive(true);
+
+ 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");
+ music.addSound(songname + "/guitar.ogg");
+ music.addSound(songname + "/rhythm.ogg");
+ cout << "Mixing sounds" << endl;
+ Mix_Chunk *m_chunk = music.mix();
+ cout << "Play music" << endl;
+ Mix_PlayChannel(-1, m_chunk, 1);
+*/
+/*
+ Mix_Chunk *Mix_LoadWAV(char *file) x2/3
+ for(...)
+ a/3+b/3+c/3;
+ int Mix_SetPanning(int channel, Uint8 left, Uint8 right) left + right
+ int Mix_PlayChannel(int channel, Mix_Chunk *chunk, int loops)
+*/
+
+ 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
+ uint32_t currenttime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000;
+ */
+ // cout << "draw" << endl;
+ draw(tr, NORMAL);
+// cout << "events" << endl;
+ quitProgram = processEvents();
+ if (iswiimoteconnected)
+ mw->handleEvents();
+// cout << "pause" << endl;
+// SDL_Delay(10);
+ // check metronome events
+// tr.checkMetronome(currenttime, m);
+ }
+
+ delete m;
+}
\ No newline at end of file
#include <sstream>
using namespace std;
-extern Texture* texturesteel;
+extern Texture* texturesteel, *texturefrett;
extern FILE *logfile;
extern float SECONDSIZE;
+extern int VIEWLENGTH;
Track::Track()
:/*_currenttempo(120)*,_currentpos(0),*/ _trackSize(0), _active(true)
}
}
+/**
+ Click track
+ tempo: beats per minute
+ duration: track length in ms
+*/
+Track::Track(uint32_t tempo, uint32_t duration)
+{
+ uint32_t t = 60000000 / tempo;
+ addTempo(0, 0, tempo);
+ addTimesignature(0, 0, 1);
+
+ for (uint32_t i = 0 ; i < (duration * 1000) / t ; i++)
+ _bips.push_back(Pair<uint32_t, uint32_t>(i, i * t / 1000 + 2000));
+}
+
Track::~Track()
{
}
list<Pair<uint32_t, uint32_t> >::const_iterator b = startingbips;
glMatrixMode(GL_MODELVIEW);
+ //glDisable(GL_DEPTH_TEST);
//on dessine les frettes jusqu'à 10s
- while (b != _bips.end() && BIPTIMESTAMP(*b) < postime + 10000)
+ while (b != _bips.end() && BIPTIMESTAMP(*b) < postime + VIEWLENGTH / SECONDSIZE)
{
glPushMatrix();
glTranslatef(0, 0, static_cast<float>(- SECONDSIZE * BIPTIMESTAMP(*b)));
- glEnable(GL_POLYGON_OFFSET_FILL);
- glPolygonOffset(-2.0f, -20.0f);
+ //glEnable(GL_POLYGON_OFFSET_FILL);
+ //glPolygonOffset(-2.0f, -20.0f);
+ glEnable(GL_TEXTURE_2D);
+ texturefrett->useTexture();
glBegin(GL_QUADS);
glColor3f(0.8f, 0.8f, 0.0f); // Set The Color To Green
glNormal3f(0, 1.0f, 0);
- glVertex3f( NECKWIDTH, 0.0f, 0.2f);
- glVertex3f( NECKWIDTH, 0.0f, -0.2f);
- glVertex3f(-NECKWIDTH, 0.0f, -0.2f);
- glVertex3f(-NECKWIDTH, 0.0f, 0.2f);
+ glTexCoord2f(0.0, 0.0); glVertex3f(-NECKWIDTH, 0.0f, .2f);
+ glTexCoord2f(1.0, 0.0); glVertex3f( NECKWIDTH, 0.0f, .2f);
+ glTexCoord2f(1.0, 1.0); glVertex3f( NECKWIDTH, 0.02f, -.2f);
+ glTexCoord2f(0.0, 1.0); glVertex3f(-NECKWIDTH, 0.02f, -.2f);
/* glVertex3f( NECKWIDTH,0, 0.1f);
glVertex3f( NECKWIDTH,0.1f, 0);
glVertex3f(-NECKWIDTH,0.1f, 0);
glVertex3f(-NECKWIDTH,0, -0.1f);
glVertex3f(-NECKWIDTH,0.1f, 0);*/
glEnd();
- glDisable(GL_POLYGON_OFFSET_FILL);
+ glDisable(GL_TEXTURE_2D);
+ //glDisable(GL_POLYGON_OFFSET_FILL);
glPopMatrix();
b++;
}
glMatrixMode(GL_MODELVIEW);
//on dessine les notes jusqu'à 10s
- while (n != _notes[diff].end() && NOTEENDTIMESTAMP(*n) < postime + 10000)
+ while (n != _notes[diff].end() && NOTEENDTIMESTAMP(*n) < postime + VIEWLENGTH / SECONDSIZE)
{
glPushMatrix();
glTranslatef(0, 0, static_cast<float>(- SECONDSIZE * NOTETIMESTAMP(*n)));
#define MAX(X,Y) (((X)>(Y))?(X):(Y))
#define MIN(X,Y) (((X)<(Y))?(X):(Y))
+#ifdef WIN32
+ extern struct { int tv_sec, tv_usec; } start;
+#else
+ extern struct timeval start;
+#endif
+
Wiimote::Wiimote(int nb)
:_wiimotes(wiiuse_init(nb)), _nb(nb), _strumstate(false)
{
}
}
-void Wiimote::handleEvents(uint32_t currenttime)
+void Wiimote::handleEvents()
{
+#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
+ uint32_t currenttime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000;
+
if (!wiiuse_poll(_wiimotes, _nb))
return;
for (int i = 0 ; i < _nb ; i++)
#include "Track.hpp"
#include "Mixer.hpp"
#include "PaintGame.h"
-#include "Metronome.hpp"
-#include "MetronomeAudio.hpp"
-#include "MetronomeHaptic.hpp"
#ifdef WIN32
#include <time.h>
#include <SDL/SDL_mixer.h>
#endif*/
+float SECONDSIZE = 0.050f;
FILE *logfile = NULL;
//list<double> bips;
//list<double>::iterator cb;
int main(int argc, char *argv[])
{
- bool iswiimoteconnected = false;
- Wiimote *mw;
- try
- {
- mw = new MyWiimote();
- iswiimoteconnected = true;
- }
- catch(...){}
-
if (argc < 2)
{
- cout << "Usage : " << argv[0] << "songname" << endl;
+ cout << "Usage : " << argv[0] << "songname [logname] [tempo] [duration] [beatsize]" << endl;
exit(0);
}
String songname(argv[1]);
- if (argc >= 3)
- {
- time_t tim = time(NULL);
- struct tm *t = gmtime(&tim);
- String logfilename = String(argv[2]) + "-" + String(1900 + t->tm_year) + "-" + String(t->tm_mon) + "-" + String(t->tm_mday) + "-" + String(t->tm_hour) + "-" + String(t->tm_min) + "-" + String(t->tm_sec) + "-" + String(argv[1]);
- logfile = fopen(logfilename.c_str(), "w");
- }
+ time_t tim = time(NULL);
+ struct tm *t = gmtime(&tim);
cout << "Loading song" << endl;
- MIDIReader *test;
- try
+ if (argc >= 6)
{
- test = new MIDIReader(songname + "/notes.mid");
+ Track tr(atoi(argv[3]), atoi(argv[4]));
+ SECONDSIZE = atof(argv[5]);
+
+ String logfilename = String(argv[1]) + "-" + String(argv[2]) + "-" + \
+ String(1900 + t->tm_year) + "-" + String(t->tm_mon) + "-" + String(t->tm_mday) + "-" + \
+ String(t->tm_hour) + "-" + String(t->tm_min) + "-" + String(t->tm_sec) + "-" + \
+ String(int(floor(SECONDSIZE * 1000 + 0.5))) + "-" + argv[3];
+ logfile = fopen(logfilename.c_str(), "w");
+ //run the game with a click track
+ loop(tr, songname);
}
- catch(...)
+ else
{
- cerr << "Unable to load the song file" << endl;
- exit(0);
+ if (argc >= 3)
+ {
+ String logfilename = String(argv[1]) + "-" + String(argv[2]) + "-" + String(1900 + t->tm_year) + "-" + String(t->tm_mon) + "-" + String(t->tm_mday) + "-" + String(t->tm_hour) + "-" + String(t->tm_min) + "-" + String(t->tm_sec) + "-" + String(argv[1]);
+ logfile = fopen(logfilename.c_str(), "w");
+ }
+
+ Track tr;
+ MIDIReader *test;
+ try
+ {
+ test = new MIDIReader(songname + "/notes.mid");
+ }
+ catch(...)
+ {
+ cerr << "Unable to load the song file" << endl;
+ exit(0);
+ }
+
+ cout << "Loading notes" << endl;
+ test->readHeader();
+ cout << "Reading tracks" << endl;
+ test->readTracks(tr);
+
+ //run the game with a song
+ loop(tr, songname);
}
- Track tr;
-
- cout << "Loading notes" << endl;
- test->readHeader();
- cout << "Reading tracks" << endl;
- test->readTracks(tr);
-
- init();
- cout << "Create Metronome" << endl;
-// Metronome *m = new MetronomeAudio(&tr);
- Metronome *m = new MetronomeHaptic(&tr);
-
- bool quitProgram = false;
+ if (logfile)
+ fclose(logfile);
- cout << "Loading sounds" << endl;
-
-// Mixer::getInstance()->addSound("guitar", songname + "/guitar.ogg");
-// bool rhythm = Mixer::getInstance()->addSound("rhythm", songname + "/rhythm.ogg");
-
- Mixer::getInstance()->setMusicVolume(30);
- Mixer::getInstance()->setSoundVolume(30);
-
-
- cout << "Init paint" << endl;
- initPaint();
-
-
-#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 + "/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");
- music.addSound(songname + "/guitar.ogg");
- music.addSound(songname + "/rhythm.ogg");
- cout << "Mixing sounds" << endl;
- Mix_Chunk *m_chunk = music.mix();
- cout << "Play music" << endl;
- Mix_PlayChannel(-1, m_chunk, 1);
-*/
-/*
- Mix_Chunk *Mix_LoadWAV(char *file) x2/3
- for(...)
- a/3+b/3+c/3;
- int Mix_SetPanning(int channel, Uint8 left, Uint8 right) left + right
- int Mix_PlayChannel(int channel, Mix_Chunk *chunk, int loops)
-*/
-
- 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
- uint32_t currenttime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000;
-
- // cout << "draw" << endl;
- draw(tr, currenttime, NORMAL);
-// cout << "events" << endl;
- quitProgram = processEvents(currenttime);
- if (iswiimoteconnected)
- mw->handleEvents(currenttime);
-// cout << "pause" << endl;
-// SDL_Delay(10);
- // check metronome events
-// tr.checkMetronome(currenttime, m);
- }
-
- delete m;
-
- if (logfile)
- fclose(logfile);
-
- return 1;
+ return 1;
}