Portage windows + textures sur notes
authorThomas Pietrzak <thomas.pietrzak@gmail.com>
Wed, 30 Mar 2011 20:30:19 +0000 (20:30 +0000)
committerThomas Pietrzak <thomas.pietrzak@gmail.com>
Wed, 30 Mar 2011 20:30:19 +0000 (20:30 +0000)
git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@5 47cf9a05-e0a8-4ed5-9e9b-101a649bc004

14 files changed:
Haptic Metronome/Haptic Metronome.sln [new file with mode: 0644]
Haptic Metronome/Haptic Metronome.suo [new file with mode: 0644]
include/MIDIReader.hpp
include/Mixer.hpp
include/Texture.hpp
include/Track.hpp
include/Vector2D.hpp
include/Vector3D.hpp
src/MIDIReader.cpp
src/String.cpp
src/Texture.cpp
src/Tools.cpp
src/Track.cpp
src/main.cpp

diff --git a/Haptic Metronome/Haptic Metronome.sln b/Haptic Metronome/Haptic Metronome.sln
new file mode 100644 (file)
index 0000000..b695369
--- /dev/null
@@ -0,0 +1,20 @@
+\r
+Microsoft Visual Studio Solution File, Format Version 11.00\r
+# Visual Studio 2010\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Haptic Metronome", "Haptic Metronome\Haptic Metronome.vcxproj", "{46FB682E-53BE-41ED-8EF7-21FCD538023B}"\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
+               Debug|Win32 = Debug|Win32\r
+               Release|Win32 = Release|Win32\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution\r
+               {46FB682E-53BE-41ED-8EF7-21FCD538023B}.Debug|Win32.ActiveCfg = Debug|Win32\r
+               {46FB682E-53BE-41ED-8EF7-21FCD538023B}.Debug|Win32.Build.0 = Debug|Win32\r
+               {46FB682E-53BE-41ED-8EF7-21FCD538023B}.Release|Win32.ActiveCfg = Release|Win32\r
+               {46FB682E-53BE-41ED-8EF7-21FCD538023B}.Release|Win32.Build.0 = Release|Win32\r
+       EndGlobalSection\r
+       GlobalSection(SolutionProperties) = preSolution\r
+               HideSolutionNode = FALSE\r
+       EndGlobalSection\r
+EndGlobal\r
diff --git a/Haptic Metronome/Haptic Metronome.suo b/Haptic Metronome/Haptic Metronome.suo
new file mode 100644 (file)
index 0000000..66ff2c7
Binary files /dev/null and b/Haptic Metronome/Haptic Metronome.suo differ
index a09c8a7b8d15ada807692d9625205e5eba2adc88..2e620f5ee61e5de9dee8455442c5251ae4d4960d 100644 (file)
@@ -6,6 +6,7 @@
 #include "Track.hpp"
 #include "String.hpp"
 #include "Tools.hpp"
+#include <stdint.h> 
 
 
 class MIDIReader
@@ -23,13 +24,13 @@ class MIDIReader
     MIDIReader(const MIDIReader &);
 
     FILE *_file;
-    uint16 _nbtracks;
-    uint16 _timedivision;
+    uint16_t _nbtracks;
+    uint16_t _timedivision;
 //     unsigned long int _position;
-    uint8 readVariableLength(uint32 &);
-    void readBytes(void *, uint32);
-               void printBytes(uint8 *data, uint32 length);
-    uint32 _position;
+    uint8_t readVariableLength(uint32_t &);
+    void readBytes(void *, uint32_t);
+               void printBytes(uint8_t *data, uint32_t length);
+    uint32_t _position;
 };
 
 #endif
index 7725886d9eb466d956af39b2a9ecfbf50acf557a..ed219142467b463c7afb1fd0934604ad2977cffd 100644 (file)
@@ -28,6 +28,8 @@
 #include "PrefixTree.hpp"
 #ifdef __APPLE__
 #include <SDL_mixer/SDL_mixer.h>
+#elif WIN32
+#include <SDL_mixer.h>
 #else
 #include <SDL/SDL_mixer.h>
 #endif
index ee7058ab3eff446fed2b8a7a49bef0d50b2e1e74..e2a2ec321e823330752c7ff74b7034fe768b47f0 100644 (file)
 #define __TEXTURE__
 
 #include <GL/glew.h>
+#ifdef WIN32
+#include <SDL.h>
+#else
 #include <SDL/SDL.h>
+#endif
 // #include <SDL/SDL_opengl.h>
 
 #include "String.hpp"
index d9af10774729077f8a34e124aa24d003efc34885..9bfa783ca9e6c5feae46b52b177524bcd9f3b462 100644 (file)
@@ -30,7 +30,7 @@ class Track
 //     void setTempo(uint32 t) { _currenttempo = t; }
     
 //     uint32 beatsToTicks(uint32 time) { return (time * _currenttempo * 480) / 60000.0; }
-    uint32 beatsToTicks(uint32 time, uint32 tempo) { return (time * tempo * 480) / 60000.0; }
+    uint32 beatsToTicks(uint32 time, uint32 tempo) { return uint32((time * tempo * 480) / 60000.0); }
     uint32 ticksToBeats(uint32 time) { return 60000000 / time; }
 
     void displayTracks();
index 8ac544c908beacc278bb219fa79674692b7a6ae6..e004b52c2026a139623622c5700ee3d37f5241ee 100644 (file)
@@ -22,8 +22,8 @@
 #define __VECTOR2D__
 
 #include "Pair.hpp"
-/*
-#include <iostream>
+
+/*#include <iostream>
 using namespace std;*/
 
 template <class T> class Vector2D;
@@ -65,19 +65,19 @@ class Vector2D: public Pair<T, T>
 //     const Vector2D & operator = (const Vector2D &s);
 //     bool operator == (const Vector2D &s) const;
 
-    friend Vector2D operator + <>(const Vector2D &p1, const Vector2D &p2);
-    friend Vector2D operator + <>(const T &a, const Vector2D &p);
-    friend Vector2D operator + <>(const Vector2D &p1, const T &a);
-    friend Vector2D operator - <>(const Vector2D &p1, const Vector2D &p2);
-    friend Vector2D operator - <>(const T &a, const Vector2D &p);
-    friend Vector2D operator - <>(const Vector2D &p1, const T &a);
+    friend Vector2D operator + (const Vector2D &p1, const Vector2D &p2);
+    friend Vector2D operator + (const T &a, const Vector2D &p);
+    friend Vector2D operator + (const Vector2D &p1, const T &a);
+    friend Vector2D operator - (const Vector2D &p1, const Vector2D &p2);
+    friend Vector2D operator - (const T &a, const Vector2D &p);
+    friend Vector2D operator - (const Vector2D &p1, const T &a);
     Vector2D operator - (void);
-    friend Vector2D operator * <>(const Vector2D &p1, const Vector2D &p2);
-    friend Vector2D operator * <>(const T &a, const Vector2D &p);
-    friend Vector2D operator * <>(const Vector2D &p1, const T &a);
-    friend Vector2D operator / <>(const Vector2D &p1, const Vector2D &p2);
-    friend Vector2D operator / <>(const T &a, const Vector2D &p);
-    friend Vector2D operator / <>(const Vector2D &p1, const T &a);
+    friend Vector2D operator * (const Vector2D &p1, const Vector2D &p2);
+    friend Vector2D operator * (const T &a, const Vector2D &p);
+    friend Vector2D operator * (const Vector2D &p1, const T &a);
+    friend Vector2D operator / (const Vector2D &p1, const Vector2D &p2);
+    friend Vector2D operator / (const T &a, const Vector2D &p);
+    friend Vector2D operator / (const Vector2D &p1, const T &a);
 //     
 //     friend ostream &operator << <>(ostream &os, const Vector2D &s);
 
index b6db366da5a9e45df40eefb205bfeee60466349c..f0de0cb471563dd3ff56c9b06d9c6a8a0439a79d 100644 (file)
@@ -54,19 +54,19 @@ class Vector3D: public Triplet<T, T, T>
     inline T &operator [] (const int &i);
     inline const T &operator [] (const int &i) const;
 
-    friend Vector3D operator + <>(const Vector3D &p1, const Vector3D &p2);
-    friend Vector3D operator + <>(const T &a, const Vector3D &p);
-    friend Vector3D operator + <>(const Vector3D &p1, const T &a);
-    friend Vector3D operator - <>(const Vector3D &p1, const Vector3D &p2);
-    friend Vector3D operator - <>(const T &a, const Vector3D &p);
-    friend Vector3D operator - <>(const Vector3D &p1, const T &a);
+    friend Vector3D operator + (const Vector3D &p1, const Vector3D &p2);
+    friend Vector3D operator + (const T &a, const Vector3D &p);
+    friend Vector3D operator + (const Vector3D &p1, const T &a);
+    friend Vector3D operator - (const Vector3D &p1, const Vector3D &p2);
+    friend Vector3D operator - (const T &a, const Vector3D &p);
+    friend Vector3D operator - (const Vector3D &p1, const T &a);
     Vector3D operator - (void);
-    friend Vector3D operator * <>(const Vector3D &p1, const Vector3D &p2);
-    friend Vector3D operator * <>(const T &a, const Vector3D &p);
-    friend Vector3D operator * <>(const Vector3D &p1, const T &a);
-    friend Vector3D operator / <>(const Vector3D &p1, const Vector3D &p2);
-    friend Vector3D operator / <>(const T &a, const Vector3D &p);
-    friend Vector3D operator / <>(const Vector3D &p1, const T &a);
+    friend Vector3D operator * (const Vector3D &p1, const Vector3D &p2);
+    friend Vector3D operator * (const T &a, const Vector3D &p);
+    friend Vector3D operator * (const Vector3D &p1, const T &a);
+    friend Vector3D operator / (const Vector3D &p1, const Vector3D &p2);
+    friend Vector3D operator / (const T &a, const Vector3D &p);
+    friend Vector3D operator / (const Vector3D &p1, const T &a);
 
   private:
 };
index 7ccb81844aae570e70445e97fe3c7a256df0857e..bc3f1c399f692a9c45e2042082a3ee7a2053c79e 100644 (file)
@@ -1,7 +1,7 @@
 // For format explanation, see http://www.sonicspot.com/guide/midifiles.html
 
 #include <MIDIReader.hpp>
-#include <arpa/inet.h>
+//#include <arpa/inet.h>
 #include <iostream>
 using namespace std;
 #include <string.h>
@@ -50,7 +50,7 @@ void MIDIReader::readHeader()
        if (!_file)
                return;
        
-       uint8 temp[4];
+       uint8_t temp[4];
        
        //read the chunk ID
        fread((void *)(temp), 1, 4, _file);
@@ -61,12 +61,12 @@ void MIDIReader::readHeader()
        }
 
        //read the chunk size
-       uint32 chunksize;
+       uint32_t chunksize;
        readBytes(&chunksize, 4);
        cout << "Header size: " << chunksize << endl;
 
        //read the format
-       uint16 format;
+       uint16_t format;
        readBytes(&format, 2);
        cout << "Format type: " << format << endl;
        
@@ -85,7 +85,7 @@ void MIDIReader::readHeader()
 
 void MIDIReader::skipTrack()
 {
-       uint8 temp[4];
+       uint8_t temp[4];
        //read the chunk ID
        fread((void *)(temp), 4, 1, _file);
 //      cerr << temp << endl;
@@ -96,7 +96,7 @@ void MIDIReader::skipTrack()
        }
 
        //read the chunk size
-       uint32 chunksize;
+       uint32_t chunksize;
        readBytes(&chunksize, 4);
        cout << "Chunk size: " << chunksize << endl;
                fseek(_file, chunksize, SEEK_CUR);
@@ -105,7 +105,7 @@ void MIDIReader::skipTrack()
 
 void MIDIReader::readTrack(Track &tr)
 {
-       uint8 temp[4];
+       uint8_t temp[4];
        //read the chunk ID
        fread((void *)(temp), 4, 1, _file);
 //      cerr << temp << endl;
@@ -116,7 +116,7 @@ void MIDIReader::readTrack(Track &tr)
        }
 
        //read the chunk size
-       uint32 chunksize;
+       uint32_t chunksize;
        readBytes(&chunksize, 4);
        cout << "Chunk size: " << chunksize << endl;
 
@@ -129,21 +129,21 @@ void MIDIReader::readTrack(Track &tr)
 //              readBytes((char *)(&temp2),4);
 //              printf("TEMP : %0x %0x %0x %0x\n", temp2[0], temp2[1], temp2[2], temp2[3]);
        bool end = false;
-       uint8 oldeventandchannel = 0;
-       uint32 timestamp = 0;
+       uint8_t oldeventandchannel = 0;
+       uint32_t timestamp = 0;
 
 //      Track example;
        
        //Read the events
        while (_position < chunksize)
        {
-               uint32 delta;
+               uint32_t delta;
                //The delta is a variable-length stuff
                /*uint8 nblus = */readVariableLength(delta);
 
                timestamp += delta;
        
-               uint8 eventandchannel, tempevt;
+               uint8_t eventandchannel, tempevt;
                // 4 bits for event type, and 4 others for the channel
                readBytes(&tempevt, 1);
                fseek(_file, -1, SEEK_CUR);
@@ -165,15 +165,15 @@ void MIDIReader::readTrack(Track &tr)
                {
                        if (end)
                                cerr << "EXTRA EVT ";
-                       uint8 type;
+                       uint8_t type;
                        readBytes(&type, 1);
 
-                       uint32 length;
-                       /*uint8 nblus = */readVariableLength(length);
+                       uint32_t length;
+                       /*uint8_t nblus = */readVariableLength(length);
        
-                       uint8 *data = new uint8[length];
+                       uint8_t *data = new uint8_t[length];
                        readBytes(data, length);
-                       uint32 tempo = 0;
+                       uint32_t tempo = 0;
        
                        switch(type)
                        {
@@ -240,9 +240,9 @@ void MIDIReader::readTrack(Track &tr)
                else if ((eventandchannel & 0xf0) == 0xf0)// || (eventandchannel & 0xff) == 0xf7)
                {
                        //May be something else
-                       uint32 length;
+                       uint32_t length;
                        readVariableLength(length);
-                       uint8 *data = new uint8[length];
+                       uint8_t *data = new uint8_t[length];
                        readBytes(data, length);
                        printf("System data\n");
                        delete []data;
@@ -251,7 +251,7 @@ void MIDIReader::readTrack(Track &tr)
                else
                {
 //                      printf("Evt : %x %x %x\n", eventandchannel & 0xf0, eventandchannel & 0x0f, eventandchannel);
-                       uint8 par1, par2;
+                       uint8_t par1, par2;
 //                      position += 2;
 //                      char *notenames[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
                        switch(eventandchannel & 0xf0)
@@ -354,11 +354,11 @@ void MIDIReader::readTracks(Track &t)//, int &nb)
        cout << endl << "Total : " << total << endl;
 }
 
-uint8 MIDIReader::readVariableLength(uint32 &nb)
+uint8_t MIDIReader::readVariableLength(uint32_t &nb)
 {
-       uint8 nblus = 0;
+       uint8_t nblus = 0;
        nb = 0;
-       uint8 temp;
+       uint8_t temp;
        do
        {
                fread((void *)(&temp), 1, 1, _file);
@@ -370,18 +370,19 @@ uint8 MIDIReader::readVariableLength(uint32 &nb)
        return nblus;
 }
 
-void MIDIReader::readBytes(void *data, uint32 nb)
+void MIDIReader::readBytes(void *data, uint32_t nb)
 {
-       uint8 temp[nb];
-       fread((void *)(&temp), nb, 1, _file);
-               for (uint32 i=0 ; i<nb ; i++)
-                       ((uint8 *)data)[i] = temp[nb - i - 1];
+       uint8_t *temp = new uint8_t[nb];
+       fread((void *)(temp), nb, 1, _file);
+       for (uint32_t i=0 ; i<nb ; i++)
+               ((uint8_t *)data)[i] = temp[nb - i - 1];
+       delete []temp;
        _position += nb;
 }
 
-void MIDIReader::printBytes(uint8 *data, uint32 length)
+void MIDIReader::printBytes(uint8_t *data, uint32_t length)
 {
-       for (uint32 i=0 ; i < length ; i++)
+       for (uint32_t i=0 ; i < length ; i++)
                cout << data[length - i - 1];
        cout << endl;
 }
index 1d105ae299bfd8424dfeb2343cc1420570e96366..fcb9f3f32c8c90e405dfba53c868a6cd3ea5243c 100644 (file)
 #include <iostream>
 using namespace std;
 
+#ifdef WIN32
+#define snprintf _snprintf
+#endif
+
 String::String(const String &s)
 :string(strdup(s.string))
 {
@@ -38,9 +42,9 @@ String::String(const int &a)
   if (a == 0)
     string = (char *)malloc(2 * sizeof(char));
   else if (a < 0)
-    string = (char *)malloc(int(log10(-a) + 3) * sizeof(char));
+    string = (char *)malloc(int(log10(static_cast<double>(-a)) + 3) * sizeof(char));
   else
-    string = (char *)malloc(int(log10(a) + 2) * sizeof(char));
+    string = (char *)malloc(int(log10(static_cast<double>(a)) + 2) * sizeof(char));
   sprintf(string, "%d", a);
 }
 
index e3f9913d85d19d5af216207ce6d7f75013828c96..00d8cbefb55cd3854bb0a34fe13cdbbda953c088 100644 (file)
@@ -24,6 +24,8 @@
 // #include <SDL/SDL.h>
 #ifdef __APPLE__
 #include <SDL_image/SDL_image.h>
+#elif WIN32
+#include <SDL_image.h>
 #else
 #include <SDL/SDL_image.h>
 #endif
index 79ce0595e09ab912dd5dbad30ec708ea14d34b57..4b674a4c7fd1a5bdee3a9e5dac382d71355c113c 100644 (file)
@@ -23,7 +23,9 @@
 #include <cmath>
 #include <cstdio>
 #include <sys/types.h>
+
 #include <dirent.h>
+
 using namespace std;
 
 bool fileExists(const String &f)
index e9173c5d6e7c5e8ee0486ddf538c48bd3617983c..a8405d1ee648d7f3938333410c3335f89ccb46ea 100644 (file)
@@ -1,15 +1,18 @@
 #include "Track.hpp"
 
 #include "Mixer.hpp"
+#include "Texture.hpp"
 
 #include <map>
 
 double SECONDSIZE = 0.050;
-
+extern Texture* texturesteel;
 extern FILE *logfile;
 
 void drawCube(double pos, double size, double colorx, double colory, double colorz)
 {
+       glEnable(GL_TEXTURE_2D);
+       texturesteel->useTexture();
        glBegin(GL_QUADS);
                glColor3f(colorx, colory, colorz);                      // Set The Color To Green
 /*
@@ -20,29 +23,32 @@ void drawCube(double pos, double size, double colorx, double colory, double colo
                glVertex3f( size+pos,0,-size);                  // Bottom Right Of The Quad (Bottom)
 */
                glNormal3f(0, 0.5, 0.5);
-               glVertex3f( size/2+pos, size/3, size/2);                        // Top Right Of The Quad (Front)
-               glVertex3f(-size/2+pos, size/3, size/2);                        // Top Left Of The Quad (Front)
-               glVertex3f(-size+pos,0, size);                  // Bottom Left Of The Quad (Front)
-               glVertex3f( size+pos,0, size);                  // Bottom Right Of The Quad (Front)
+               glTexCoord2d(1.0, 0.0); glVertex3f( size/2+pos, size/3, size/2);                        // Top Right Of The Quad (Front)
+               glTexCoord2d(0.0, 0.0); glVertex3f(-size/2+pos, size/3, size/2);                        // Top Left Of The Quad (Front)
+               glTexCoord2d(0.0, 1.0); glVertex3f(-size+pos,0, size);                  // Bottom Left Of The Quad (Front)
+               glTexCoord2d(1.0, 1.0); glVertex3f( size+pos,0, size);                  // Bottom Right Of The Quad (Front)
 
                glNormal3f(0, 0.5, -0.5);
-               glVertex3f( size+pos,0,-size);                  // Bottom Left Of The Quad (Back)
-               glVertex3f(-size+pos,0,-size);                  // Bottom Right Of The Quad (Back)
-               glVertex3f(-size/2+pos, size/3,-size/2);                        // Top Right Of The Quad (Back)
-               glVertex3f( size/2+pos, size/3,-size/2);                        // Top Left Of The Quad (Back)
+               glTexCoord2d(1.0, 0.0); glVertex3f( size+pos,0,-size);                  // Bottom Left Of The Quad (Back)
+               glTexCoord2d(0.0, 0.0); glVertex3f(-size+pos,0,-size);                  // Bottom Right Of The Quad (Back)
+               glTexCoord2d(0.0, 1.0); glVertex3f(-size/2+pos, size/3,-size/2);                        // Top Right Of The Quad (Back)
+               glTexCoord2d(1.0, 1.0); glVertex3f( size/2+pos, size/3,-size/2);                        // Top Left Of The Quad (Back)
 
                glNormal3f(-0.5, 0.5, 0);
-               glVertex3f(-size/2+pos, size/3, size/2);                        // Top Right Of The Quad (Left)
-               glVertex3f(-size/2+pos, size/3,-size/2);                        // Top Left Of The Quad (Left)
-               glVertex3f(-size+pos,0,-size);                  // Bottom Left Of The Quad (Left)
-               glVertex3f(-size+pos,0, size);                  // Bottom Right Of The Quad (Left)
+               glTexCoord2d(1.0, 0.0); glVertex3f(-size/2+pos, size/3, size/2);                        // Top Right Of The Quad (Left)
+               glTexCoord2d(0.0, 0.0); glVertex3f(-size/2+pos, size/3,-size/2);                        // Top Left Of The Quad (Left)
+               glTexCoord2d(0.0, 1.0); glVertex3f(-size+pos,0,-size);                  // Bottom Left Of The Quad (Left)
+               glTexCoord2d(1.0, 1.0); glVertex3f(-size+pos,0, size);                  // Bottom Right Of The Quad (Left)
 
                glNormal3f(0.5, 0.5, 0);
-               glVertex3f( size/2+pos, size/3,-size/2l);                       // Top Right Of The Quad (Right)
-               glVertex3f( size/2+pos, size/3, size/2);                        // Top Left Of The Quad (Right)
-               glVertex3f( size+pos,0, size);                  // Bottom Left Of The Quad (Right)
-               glVertex3f( size+pos,0,-size);                  // Bottom Right Of The Quad (Right)
+               glTexCoord2d(1.0, 0.0); glVertex3f( size/2+pos, size/3,-size/2l);                       // Top Right Of The Quad (Right)
+               glTexCoord2d(0.0, 0.0); glVertex3f( size/2+pos, size/3, size/2);                        // Top Left Of The Quad (Right)
+               glTexCoord2d(0.0, 1.0); glVertex3f( size+pos,0, size);                  // Bottom Left Of The Quad (Right)
+               glTexCoord2d(1.0, 1.0); glVertex3f( size+pos,0,-size);                  // Bottom Right Of The Quad (Right)
+       glEnd();
+       glDisable(GL_TEXTURE_2D);
 
+       glBegin(GL_QUADS);
                glColor3f(1.0, 1.0, 1.0);                       // Set The Color To White
                glNormal3f(0, 1, 0);
                glVertex3f( size/2+pos, size/3,-size/2);                        // Top Right Of The Quad (Top)
@@ -57,6 +63,8 @@ void drawCube(double pos, double size, double colorx, double colory, double colo
 void drawLong(double pos, double size, double length, double colorx, double colory, double colorz)
 {
        double l = length*SECONDSIZE;
+       glEnable(GL_TEXTURE_2D);
+       texturesteel->useTexture();
        glBegin(GL_QUADS);
                glColor3f(colorx, colory, colorz);                      // Set The Color
 /*
@@ -67,34 +75,34 @@ void drawLong(double pos, double size, double length, double colorx, double colo
                glVertex3f( size+pos,0,-size-l);                        // Bottom Right Of The Quad (Bottom)
 */
                glNormal3f(0, 0.5, 0.5);
-               glVertex3f( size/2+pos, size/3, size/2);                        // Top Right Of The Quad (Front)
-               glVertex3f(-size/2+pos, size/3, size/2);                        // Top Left Of The Quad (Front)
-               glVertex3f(-size+pos,0, size);                  // Bottom Left Of The Quad (Front)
-               glVertex3f( size+pos,0, size);                  // Bottom Right Of The Quad (Front)
+               glTexCoord2d(1.0, 0.0); glVertex3f( size/2+pos, size/3, size/2);                        // Top Right Of The Quad (Front)
+               glTexCoord2d(0.0, 0.0); glVertex3f(-size/2+pos, size/3, size/2);                        // Top Left Of The Quad (Front)
+               glTexCoord2d(0.0, 1.0); glVertex3f(-size+pos,0, size);                  // Bottom Left Of The Quad (Front)
+               glTexCoord2d(1.0, 1.0); glVertex3f( size+pos,0, size);                  // Bottom Right Of The Quad (Front)
 
                glNormal3f(0, 0.5, -0.5);
-               glVertex3f( size+pos,0,-size);                  // Bottom Left Of The Quad (Back)
-               glVertex3f(-size+pos,0,-size);                  // Bottom Right Of The Quad (Back)
-               glVertex3f(-size/2+pos, size/3,-size/2-l);                      // Top Right Of The Quad (Back)
-               glVertex3f( size/2+pos, size/3,-size/2-l);                      // Top Left Of The Quad (Back)
+               glTexCoord2d(1.0, 0.0); glVertex3f( size+pos,0,-size);                  // Bottom Left Of The Quad (Back)
+               glTexCoord2d(0.0, 0.0); glVertex3f(-size+pos,0,-size);                  // Bottom Right Of The Quad (Back)
+               glTexCoord2d(0.0, 1.0); glVertex3f(-size/2+pos, size/3,-size/2-l);                      // Top Right Of The Quad (Back)
+               glTexCoord2d(1.0, 1.0); glVertex3f( size/2+pos, size/3,-size/2-l);                      // Top Left Of The Quad (Back)
 
                glNormal3f(-0.5, 0.5, 0);
-               glVertex3f(-size/2+pos, size/3, size/2);                        // Top Right Of The Quad (Left)
-               glVertex3f(-size/2+pos, size/3,-size/2-l);                      // Top Left Of The Quad (Left)
-               glVertex3f(-size+pos,0,-size-l);                        // Bottom Left Of The Quad (Left)
-               glVertex3f(-size+pos,0, size);                  // Bottom Right Of The Quad (Left)
+               glTexCoord2d(1.0, 0.0); glVertex3f(-size/2+pos, size/3, size/2);                        // Top Right Of The Quad (Left)
+               glTexCoord2d(0.0, 0.0); glVertex3f(-size/2+pos, size/3,-size/2-l);                      // Top Left Of The Quad (Left)
+               glTexCoord2d(0.0, 1.0); glVertex3f(-size+pos,0,-size-l);                        // Bottom Left Of The Quad (Left)
+               glTexCoord2d(1.0, 1.0); glVertex3f(-size+pos,0, size);                  // Bottom Right Of The Quad (Left)
 
                glNormal3f(0.5, 0.5, 0);
-               glVertex3f( size/2+pos, size/3,-size/2-l);                      // Top Right Of The Quad (Right)
-               glVertex3f( size/2+pos, size/3, size/2);                        // Top Left Of The Quad (Right)
-               glVertex3f( size+pos,0, size);                  // Bottom Left Of The Quad (Right)
-               glVertex3f( size+pos,0,-size-l);                        // Bottom Right Of The Quad (Right)
+               glTexCoord2d(1.0, 0.0); glVertex3f( size/2+pos, size/3,-size/2-l);                      // Top Right Of The Quad (Right)
+               glTexCoord2d(0.0, 0.0); glVertex3f( size/2+pos, size/3, size/2);                        // Top Left Of The Quad (Right)
+               glTexCoord2d(0.0, 1.0); glVertex3f( size+pos,0, size);                  // Bottom Left Of The Quad (Right)
+               glTexCoord2d(1.0, 1.0); glVertex3f( size+pos,0,-size-l);                        // Bottom Right Of The Quad (Right)
 
                glNormal3f(0, 1, 0);
-               glVertex3f( size/2+pos, size/3,-size/2-l);                      // Top Right Of The Quad (Top)
-               glVertex3f(-size/2+pos, size/3,-size/2-l);                      // Top Left Of The Quad (Top)
-               glVertex3f(-size/2+pos, size/3, size/2);                        // Bottom Left Of The Quad (Top)
-               glVertex3f( size/2+pos, size/3, size/2);                        // Bottom Right Of The Quad (Top)
+               glTexCoord2d(1.0, 1.0); glVertex3f( size/2+pos, size/3,-size/2-l);                      // Top Right Of The Quad (Top)
+               glTexCoord2d(0.0, 1.0); glVertex3f(-size/2+pos, size/3,-size/2-l);                      // Top Left Of The Quad (Top)
+               glTexCoord2d(0.0, 1.0); glVertex3f(-size/2+pos, size/3, size/2);                        // Bottom Left Of The Quad (Top)
+               glTexCoord2d(1.0, 1.0); glVertex3f( size/2+pos, size/3, size/2);                        // Bottom Right Of The Quad (Top)
        glEnd();                                                // Done Drawing The Quad
 }
 
index f353f6b443cbddff30f3cf73822e47fcce3e2d2c..0bf677cd6c0339731485cce2dcccf4f17efb87d0 100644 (file)
@@ -5,7 +5,23 @@
 #include "Texture.hpp"
 #include "Mixer.hpp"
 
+
+#include <GL/glew.h>
+
+#ifdef WIN32
+#include <time.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>
+#endif
+
 #include <list>
 /*#ifdef __APPLE__
 #include <SDL_mixer/SDL_mixer.h>
 #include <SDL/SDL_mixer.h>
 #endif*/
 
-#include <GL/glew.h>
-#include <SDL/SDL.h>
-#include <SDL/SDL_mixer.h>
-#include <SDL/SDL_image.h>
 extern double SECONDSIZE;
 
 #include "Wiimote.hpp"
 
-double posx, posy, posz;
-struct timeval start;
-Texture *texturebois, *texturefond;
+double posz=0.0;
+\r
+#ifdef WIN32\r
+    struct { int tv_sec, tv_usec; } start;\r
+    DWORD t;\r
+#else\r
+    struct timeval start;\r
+#endif\r
+
+Texture *texturebois, *texturefond, *texturesteel;
 int resolution_x, resolution_y;
 Config fromKeyboard;
 
@@ -45,8 +64,8 @@ void init()
     throw "Error while loading SDL";
 
   //Initialize SDL_mixer
-  if (Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 1024 ) == -1 );
-//    throw String("Can't initialize sound");
+  if (Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 1024 ) == -1 )
+    throw String("Can't initialize sound");
 
   cout << "get video info" << endl;
   info = SDL_GetVideoInfo();
@@ -152,24 +171,34 @@ void init()
 
        texturebois = new Texture("wood.jpg", true);
        texturefond = new Texture("back.jpg");
-
-       posx=0.0;
-       posy=25.0;
-       posz=0.0;
+       texturesteel = new Texture("steel.jpg");
 
        fromKeyboard.setPosition(-1);
        fromKeyboard.setEnd(-1);
 }
 
+#define POSITION_HEIGHT 35
 #define POSITION_EYE    45
-#define POSITION_CENTER (-80)
-#define VIEWLENGTH 250
+#define POSITION_CENTER (-70)
+#define VIEWLENGTH             250
 
 
 void draw(Track &t, uint8 diff)
 {
-       struct timeval now;
-       gettimeofday(&now, NULL);
+#ifdef WIN32\r
+    struct { int tv_sec, tv_usec; } now;\r
+    DWORD tim;\r
+#else\r
+    struct timeval now;\r
+#endif\r
+\r
+#ifdef WIN32\r
+    tim = timeGetTime ();\r
+    now.tv_sec = tim / 1000;\r
+    now.tv_usec = (tim % 1000) * 1000;\r
+#else\r
+     gettimeofday(&now, NULL);\r
+#endif
        double postime = (now.tv_sec - start.tv_sec) * 1000. + (now.tv_usec - start.tv_usec) / 1000.0;
        posz = -SECONDSIZE * postime;
 
@@ -198,11 +227,11 @@ void draw(Track &t, uint8 diff)
                
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
-       gluPerspective( 45.0f, double(resolution_x) / double(resolution_y), POSITION_EYE+3, VIEWLENGTH );
+  gluPerspective( 45.0f, double(resolution_x) / double(resolution_y), 1/*POSITION_EYE+3*/, VIEWLENGTH );
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
        //cout << "posz=" << posz << endl;
-       gluLookAt(posx, posy, posz + POSITION_EYE, 0, 0, posz + POSITION_CENTER, 0.0,1.0,0.0);
+       gluLookAt(0, POSITION_HEIGHT, posz + POSITION_EYE, 0, 0, posz + POSITION_CENTER, 0.0,1.0,0.0);
 //     gluLookAt(posx-50, posy, posz-POSITION, 0, 0,posz-POSITION, 0.0,1.0,0.0);
        GLfloat light_position[] = { 0.0, 10.0 , posz, 1.0 };
   glLightfv(GL_LIGHT1, GL_POSITION, light_position);
@@ -223,22 +252,26 @@ void draw(Track &t, uint8 diff)
        glEnd();
   glDisable(GL_TEXTURE_2D);
        
-       //Draw the position bar
-  glMatrixMode(GL_MODELVIEW);
+       glMatrixMode(GL_MODELVIEW);
        glPushMatrix();
        glTranslatef(0,0,posz);
-       glBegin(GL_QUADS);
-               glColor3f(0.8, 0.8, 0.8);
-               glNormal3f(0, 1, 0);
-               glVertex3f( NECKWIDTH,0, 1);
-               glVertex3f( NECKWIDTH,0.2, 0);
-               glVertex3f(-NECKWIDTH,0.2, 0);
-               glVertex3f(-NECKWIDTH,0, 1);
-               glVertex3f( NECKWIDTH,0.2, 0);
-               glVertex3f( NECKWIDTH,0, -1);
-               glVertex3f(-NECKWIDTH,0, -1);
-               glVertex3f(-NECKWIDTH,0.2, 0);
-       glEnd();
+       //draw the strings
+       for (int i = 0 ; i < 5 ; i++)
+       {
+               glBegin(GL_QUADS);
+                       glColor3f(0.2, 0.2, 0.2);
+                       glNormal3f(0, 1, 0);
+                       glVertex3f(NOTEDIST*(i-2), 0, 1);
+                       glVertex3f(NOTEDIST*(i-2)+.1,0.2, 1);
+                       glVertex3f(NOTEDIST*(i-2)+.1,0.2,-VIEWLENGTH);
+                       glVertex3f(NOTEDIST*(i-2),0, -VIEWLENGTH);
+                       glVertex3f(NOTEDIST*(i-2)+.1, 0.2, 1);
+                       glVertex3f(NOTEDIST*(i-2)+.2,0, 1);
+                       glVertex3f(NOTEDIST*(i-2)+.2,0,-VIEWLENGTH);
+                       glVertex3f(NOTEDIST*(i-2)+.1,0.2, -VIEWLENGTH);
+               glEnd();
+       }
+       //Draw the sides
        glBegin(GL_QUADS);
                glColor3f(0.8, 0.8, 0.8);
                glNormal3f(0, 1, 0);
@@ -263,15 +296,33 @@ void draw(Track &t, uint8 diff)
                glVertex3f(-NECKWIDTH-.2,0,-VIEWLENGTH);
                glVertex3f(-NECKWIDTH-.1,0.2, -VIEWLENGTH);
        glEnd();
-       fromKeyboard.display();
        glPopMatrix();
-
+       
        //draw the frets
        t.drawFrets(postime);
 
        // Draw the notes
        t.drawNotes(postime, diff);
 
+       glMatrixMode(GL_MODELVIEW);
+       glPushMatrix();
+       glTranslatef(0,0,posz);
+       //Draw the position bar
+       glBegin(GL_QUADS);
+               glColor3f(0.8, 0.8, 0.8);
+               glNormal3f(0, 1, 0);
+               glVertex3f( NECKWIDTH,0.5, 10);
+               glVertex3f( NECKWIDTH,0.5, 0);
+               glVertex3f(-NECKWIDTH,0.5, 0);
+               glVertex3f(-NECKWIDTH,0.5, 10);
+               glVertex3f( NECKWIDTH,0.5, 0);
+               glVertex3f( NECKWIDTH,0, -1);
+               glVertex3f(-NECKWIDTH,0, -1);
+               glVertex3f(-NECKWIDTH,0.5, 0);
+       glEnd();
+       fromKeyboard.display();
+       glPopMatrix();
+
        SDL_GL_SwapBuffers();
 }
 
@@ -304,8 +355,21 @@ void handleKeyOff(keys k)
        if (fromKeyboard.getPosition() == -1)
                return;
                
-       struct timeval now;
-       gettimeofday(&now, NULL);
+#ifdef WIN32\r
+    struct { int tv_sec, tv_usec; } now;\r
+    DWORD t;\r
+#else\r
+    struct timeval now;\r
+#endif\r
+\r
+#ifdef WIN32\r
+    t = timeGetTime ();\r
+    now.tv_sec = t / 1000;\r
+    now.tv_usec = (t % 1000) * 1000;\r
+#else\r
+     gettimeofday(&now, NULL);\r
+#endif
+
        double postime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000.0;
        fromKeyboard.setEnd(postime);
        cout << fromKeyboard << endl;
@@ -324,8 +388,21 @@ void handleKeys(bool a, bool b, bool c, bool d, bool e)
 
 void handleStrokeOn()
 {
-       struct timeval now;
-       gettimeofday(&now, NULL);
+#ifdef WIN32\r
+    struct { int tv_sec, tv_usec; } now;\r
+    DWORD t;\r
+#else\r
+    struct timeval now;\r
+#endif\r
+\r
+#ifdef WIN32\r
+    t = timeGetTime ();\r
+    now.tv_sec = t / 1000;\r
+    now.tv_usec = (t % 1000) * 1000;\r
+#else\r
+     gettimeofday(&now, NULL);\r
+#endif
+
        double postime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000.0;
        //cout << postime << endl;
 
@@ -371,7 +448,7 @@ bool processEvents()
 
                        case SDL_KEYDOWN:
                                keystate = SDL_GetKeyState(NULL);
-                               handleKeys(keystate[SDLK_a], keystate[SDLK_z], keystate[SDLK_e], keystate[SDLK_r], keystate[SDLK_t]);
+                               handleKeys(keystate[SDLK_F1], keystate[SDLK_F2], keystate[SDLK_F3], keystate[SDLK_F4], keystate[SDLK_F5]);
                                switch(((SDL_KeyboardEvent *)(&event))->keysym.sym)
                                {
                                        case SDLK_ESCAPE:
@@ -382,12 +459,12 @@ bool processEvents()
                                        case SDLK_DOWN:
                                                SECONDSIZE -=1;
                                                break;
-                                       case SDLK_LEFT:
+/*                                     case SDLK_LEFT:
                                                posy +=1;
                                                break;
                                        case SDLK_RIGHT:
                                                posy -=1;
-                                               break;
+                                               break;*/
                                        case SDLK_KP_PLUS:
                                                Mixer::getInstance()->setMusicVolume(Mixer::getInstance()->getMusicVolume() + 10);
                                                Mixer::getInstance()->setSoundVolume(Mixer::getInstance()->getSoundVolume() + 10);
@@ -422,19 +499,19 @@ bool processEvents()
                        case SDL_KEYUP:
                                switch(((SDL_KeyboardEvent *)(&event))->keysym.sym)
                                {
-                                       case SDLK_a:
+                                       case SDLK_F1:
                                                handleKeyOff(KEY0);
                                                break;
-                                       case SDLK_z:
+                                       case SDLK_F2:
                                                handleKeyOff(KEY1);
                                                break;
-                                       case SDLK_e:
+                                       case SDLK_F3:
                                                handleKeyOff(KEY2);
                                                break;
-                                       case SDLK_r:
+                                       case SDLK_F4:
                                                handleKeyOff(KEY3);
                                                break;
-                                       case SDLK_t:
+                                       case SDLK_F5:
                                                handleKeyOff(KEY4);
                                                break;
                                        case SDLK_SPACE:
@@ -444,7 +521,7 @@ bool processEvents()
                                                break;
                                }
                                keystate = SDL_GetKeyState(NULL);
-                               handleKeys(keystate[SDLK_a], keystate[SDLK_z], keystate[SDLK_e], keystate[SDLK_r], keystate[SDLK_t]);
+                               handleKeys(keystate[SDLK_F1], keystate[SDLK_F2], keystate[SDLK_F3], keystate[SDLK_F4], keystate[SDLK_F5]);
                                break;
                        default:
        //       lasteventtype = OTHER;
@@ -522,7 +599,14 @@ int main(int argc, char *argv[])
        Mixer::getInstance()->playSound("guitar");
        if (rhythm)
                Mixer::getInstance()->playSound("rhythm");
-       gettimeofday(&start, NULL);
+\r
+#ifdef WIN32\r
+    t = timeGetTime ();\r
+    start.tv_sec = t / 1000;\r
+    start.tv_usec = (t % 1000) * 1000;\r
+#else\r
+     gettimeofday(&start, NULL);\r
+#endif
 /*
        Sound music;
        cout << "Load sounds" << endl;