Minor stuff
authorThomas Pietrzak <thomas.pietrzak@gmail.com>
Thu, 5 May 2011 19:28:20 +0000 (19:28 +0000)
committerThomas Pietrzak <thomas.pietrzak@gmail.com>
Thu, 5 May 2011 19:28:20 +0000 (19:28 +0000)
git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@10 47cf9a05-e0a8-4ed5-9e9b-101a649bc004

15 files changed:
Haptic Metronome/Haptic Metronome.suo
include/Metronome.hpp
include/MetronomeAudio.hpp
include/MetronomeHaptic.hpp
include/PaintGame.h
include/Tools.hpp
include/Track.hpp
include/Wiimote.hpp
src/Metronome.cpp
src/MetronomeAudio.cpp
src/MetronomeHaptic.cpp
src/PaintGame.cpp
src/Track.cpp
src/Wiimote.cpp
src/main.cpp

index 51f3482d84198a56f7e0b0ecba22a1002dbbbfb5..5f9e0c5228fb743f7479cfec77b10e20f116a48a 100644 (file)
Binary files a/Haptic Metronome/Haptic Metronome.suo and b/Haptic Metronome/Haptic Metronome.suo differ
index 1ec54d53fcf38c3741111c93b564ad3254507f7a..69a55e02e7c185f2390552de979914862f18b6ff 100644 (file)
@@ -7,7 +7,7 @@
 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
@@ -20,7 +20,7 @@ class Metronome
                uint32_t _nbbeats;\r
                uint32_t _tempo;\r
                bool _activated;\r
-               Track *_track;\r
+               const Track *_track;\r
 };\r
 \r
 #endif\r
index a652b3d5c1acbcdbcf03b57c28dbeed9b772f83c..6d6bb67b260158196377d9cabc36177601ca3ed0 100644 (file)
@@ -15,7 +15,7 @@
 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
index 92db8691b2f64b565aae80110c38612ef06c6d53..361a0053948683ca1cbac226eafc558238a2444c 100644 (file)
@@ -17,7 +17,7 @@
 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
index 1a89b5c6aaf9cafd7d1a4cba1e79600642d95f63..a223b76a00f1e15c3fe70a514d12ad445659bd30 100644 (file)
@@ -4,15 +4,15 @@
 #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
@@ -21,7 +21,8 @@ void handleKeyOff(keys k, uint32_t currenttime);
 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
 {
index 4054029ac82c264db7b618c88ecb81ba7585c904..3dde2e43ee2ce1018945dd9eb90bc60bbe4175dd 100644 (file)
 #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)
 
index 4ecfd8d23ce1a9724719b98ecc7ce2f9b3c64487..c5679f6aa86afd607628414b5b2a312cb2cd5cd6 100644 (file)
@@ -40,6 +40,8 @@ class Track
   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);
@@ -47,16 +49,16 @@ class Track
 
     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;
@@ -74,7 +76,7 @@ class Track
     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();
@@ -84,7 +86,7 @@ class Track
   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)
index 9802af538c6b42695ab245ed4791145b7fa99e9b..87b9a780f0baee071954eaef904acaadf9a32ef1 100644 (file)
@@ -16,7 +16,7 @@ class Wiimote{
        public:
                Wiimote(int nb=1);
 
-               void handleEvents(uint32_t currenttime);
+               void handleEvents();
 
                void vibration(int wiimote, int time);
 
index d4f304da46663f5251c124480db3d18405b33b1f..e07be39c5d60026f82a2c34a68a582b390ccb580 100644 (file)
@@ -1,6 +1,6 @@
 #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
index c3fcae2e424ae938ac0334816d1890b0acf72780..0f2bea0aba690efb688d09c4fa9c4d73243a69df 100644 (file)
@@ -5,14 +5,20 @@
 #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");
 }
 
@@ -43,13 +49,13 @@ int MetronomeAudio::thread_func(void *obj)
        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;
@@ -57,7 +63,7 @@ int MetronomeAudio::thread_func(void *obj)
        while(thismetronome->_activated)
        {
 #ifdef WIN32
-               t = timeGetTime ();
+               t = timeGetTime () + BIPLENGTH;
                now.tv_sec = t / 1000;
                now.tv_usec = (t % 1000) * 1000;
 #else
@@ -65,12 +71,15 @@ int MetronomeAudio::thread_func(void *obj)
 #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++;
                }
index c1086b8145f7c6a1fd780277a3e2aaad72200d1e..91af41dead35aee67d0a934ae6ee545c3a04f0c2 100644 (file)
@@ -6,14 +6,18 @@
 #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"))
 {
 }
@@ -89,16 +93,16 @@ int MetronomeHaptic::thread_func(void *obj)
        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
@@ -112,7 +116,7 @@ int MetronomeHaptic::thread_func(void *obj)
        while(thismetronome->_activated)
        {
 #ifdef WIN32
-               t = timeGetTime ();
+               t = timeGetTime () + BEFOREDELAY;
                now.tv_sec = t / 1000;
                now.tv_usec = (t % 1000) * 1000;
 #else
@@ -124,25 +128,27 @@ int MetronomeHaptic::thread_func(void *obj)
                {
                        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
                                
index 206b7e9bf08530ffaf157fcba92063106f92ddbc..a64f16758b9ec839218b4b3a13d723e9251ac55d 100644 (file)
@@ -2,6 +2,9 @@
 
 #include "Texture.hpp"
 #include "Mixer.hpp"
+#include "Metronome.hpp"
+#include "MetronomeAudio.hpp"
+#include "MetronomeHaptic.hpp"
 
 #include <GL/glew.h>
 
@@ -9,7 +12,9 @@
 #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;
@@ -34,57 +40,57 @@ SDL_Renderer *renderer;
 
 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
@@ -124,20 +130,22 @@ void init()
   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);
@@ -151,13 +159,17 @@ void init()
 #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 };
@@ -182,15 +194,26 @@ void initPaint()
        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
@@ -211,7 +234,7 @@ void draw(Track &t, uint32_t currenttime, char diff)
                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 );
@@ -226,10 +249,10 @@ void draw(Track &t, uint32_t currenttime, char diff)
 //     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);
@@ -240,7 +263,7 @@ void draw(Track &t, uint32_t currenttime, char diff)
                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();
@@ -472,8 +495,19 @@ void handleStrokeOff(uint32_t currenttime)
 {
 }
 
-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;
 
@@ -536,6 +570,10 @@ bool processEvents(uint32_t currenttime)
                                        case SDLK_SPACE:
                                                handleStrokeOn(currenttime);
                                                break;
+                                       case SDLK_RCTRL:
+                                               if (logfile)
+                                                       fprintf(logfile, "PRESS;%d\n", currenttime);
+                                               break;
                                        default:
                                                break;
                                }
@@ -580,3 +618,98 @@ bool processEvents(uint32_t currenttime)
        }
   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
index 925885d6496fbd12b6f39066a7962b1d2f1a7cfe..8b709b86e94bc4f0d65bb058e086445bcd5659bb 100644 (file)
@@ -9,9 +9,10 @@
 #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)
@@ -38,6 +39,21 @@ Track::Track(const Track &tr)
   }
 }
 
+/**
+       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()
 {
 }
@@ -325,20 +341,23 @@ void Track::drawFrets(uint32_t postime) const
        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);
@@ -349,7 +368,8 @@ void Track::drawFrets(uint32_t postime) const
                                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++;
        }
@@ -379,7 +399,7 @@ void Track::drawNotes(uint32_t postime, uint8_t diff) const
        
        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)));
index 962c40b6ef1ed15f4c46b22b573055065cdf0e5b..eb500d915906db32e1f57ef1e09c58c874fb3aa6 100644 (file)
@@ -6,6 +6,12 @@ using namespace std;
 #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)
 {
@@ -54,8 +60,19 @@ void Wiimote::handleKey(guitar_hero_3_t* gh3, int key, int button, uint32_t curr
        }
 }
 
-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++)
index 167f656e5d13b242263c50177b0d3cc56140b5dd..5df6946ab8ae05af6c50765c4add518455139669 100644 (file)
@@ -4,9 +4,6 @@
 #include "Track.hpp"
 #include "Mixer.hpp"
 #include "PaintGame.h"
-#include "Metronome.hpp"
-#include "MetronomeAudio.hpp"
-#include "MetronomeHaptic.hpp"
 
 #ifdef WIN32
 #include <time.h>
@@ -32,6 +29,7 @@
 #include <SDL/SDL_mixer.h>
 #endif*/
 
+float SECONDSIZE = 0.050f;
 FILE *logfile = NULL;
 //list<double> bips;
 //list<double>::iterator cb;
@@ -42,137 +40,61 @@ void handleStrokeOff()
 
 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;
 }