#define NECKWIDTH 12
#define NOTEDIST 5
-void drawCube(double pos, double size, double colorx, double colory, double colorz);
-void drawLong(double pos, double size, double length, double colorx, double colory, double colorz);
-
#include <GL/glew.h>
+#include <stdint.h>
#include <iostream>
using namespace std;
class Config
{
public:
- Config(double position=0, double end=0, uint32 time=0, uint32 ticks=0,bool a=false, bool b=false, bool c=false, bool d=false, bool e=false)
+ Config(double position=0, double end=0, uint32_t time=0, uint32_t ticks=0,bool a=false, bool b=false, bool c=false, bool d=false, bool e=false)
:_position(position), _end(end), _time(time), _ticks(ticks), _a(a), _b(b), _c(c), _d(d), _e(e){}
Config(const Config &cf):_position(cf._position), _end(cf._end), _time(cf._time), _ticks(cf._ticks), _a(cf._a), _b(cf._b), _c(cf._c), _d(cf._d), _e(cf._e){}
void setEnd(double d) { _end = d; }
double getEnd() const { return _end; }
- void setTime(uint32 t) { _time = t; }
- uint32 getTime() const { return _time; }
+ void setTime(uint32_t t) { _time = t; }
+ uint32_t getTime() const { return _time; }
- void setTicks(uint32 t) { _ticks = t; }
- uint32 getTicks() const { return _ticks; }
+ void setTicks(uint32_t t) { _ticks = t; }
+ uint32_t getTicks() const { return _ticks; }
void display() const;
void log(const String &type, FILE *file) const;
private:
double _position, _end;
- uint32 _time, _ticks;
+ uint32_t _time, _ticks;
bool _a, _b, _c, _d, _e;
};
void readHeader();
void skipTrack();
- void readTrack(Track &);
+ void readTrack(Track &, bool addbips);
void readTracks(Track &t);
private:
MIDIReader();
#include "String.hpp"
#include "PrefixTree.hpp"
+#include "Sound.hpp"
+
#ifdef __APPLE__
#include <SDL_mixer/SDL_mixer.h>
#elif WIN32
#include <SDL/SDL_mixer.h>
#endif
-class Sound
-{
- public:
- Sound();
- Sound(const String &);
- ~Sound();
-
- bool addSound(const String &filename);
- bool addChunk(Mix_Chunk *c);
- Mix_Chunk *mix();
-
- Mix_Chunk *getChunk();
-
- private:
- Sound(const Sound &);
- int nbrchunks;
- Mix_Chunk **_chunks;
-};
-
class Mixer
{
public:
--- /dev/null
+#ifndef _PAINTGAME_\r
+#define _PAINTGAME_\r
+
+#define POSITION_HEIGHT 35
+#define POSITION_EYE 45
+#define POSITION_CENTER (-70)
+#define VIEWLENGTH 250
+
+#include "Track.hpp"
+
+#include "Wiimote.hpp"
+
+void init();
+void initPaint();
+void draw(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 handleKeyOn(keys k);\r
+void handleKeyOff(keys k);\r
+void handleKeys(bool a, bool b, bool c, bool d, bool e);
+void handleStrokeOn();\r
+void handleStrokeOff();\r
+bool processEvents();
+
+class MyWiimote: public Wiimote
+{
+ public:
+ MyWiimote():Wiimote(1){}
+
+ void handleStrumOn() { handleStrokeOn(); }
+ void handleStrumOff() { handleStrokeOff(); }
+ void handleButtonOn(int k) { handleKeyOn(keys(k)); }
+ void handleButtonOff(int k) { handleKeyOff(keys(k)); }
+ void handleButtons(bool a, bool b, bool c, bool d, bool e) { handleKeys(a, b, c, d, e); }
+};
+\r
+#endif\r
--- /dev/null
+/*
+ * This source file is part of Haptic Metronome
+ *
+ * Copyright (C) 2011 Thomas Pietrzak
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __SOUND__
+#define __SOUND__
+
+#include "String.hpp"
+
+#ifdef __APPLE__
+#include <SDL_mixer/SDL_mixer.h>
+#elif WIN32
+#include <SDL_mixer.h>
+#else
+#include <SDL/SDL_mixer.h>
+#endif
+
+class Sound
+{
+ public:
+ Sound();
+ Sound(const String &);
+ ~Sound();
+
+ bool addSound(const String &filename);
+ bool addChunk(Mix_Chunk *c);
+ Mix_Chunk *mix();
+
+ Mix_Chunk *getChunk();
+
+ private:
+ Sound(const Sound &);
+ int nbrchunks;
+ Mix_Chunk **_chunks;
+};
+
+#endif
#ifndef __MYTOOLS__
#define __MYTOOLS__
-typedef unsigned char uint8;
-typedef unsigned short uint16;
-typedef unsigned int uint32;
-
#include "String.hpp"
#include "Vector2D.hpp"
#include <cmath>
#include <list>
#include <map>
-/*#include <iostream>
+#include <stdint.h>
+
+//temp
+#include <iostream>
+#include <sstream>
using namespace std;
-*/
+
+#include <windows.h>
+//temp
+
#include "Config.hpp"
#include "Tools.hpp"
Track(const Track &);
~Track();
- void addKey(uint32 time, uint8 note);
- void remKey(uint32 time, uint8 note);
+ void addKey(uint32_t time, uint8_t note);
+ void remKey(uint32_t time, uint8_t note);
- void addTempo(uint32 pos, uint32 t) { _tempo[pos] = t; }
+ void addTempo(uint32_t pos, uint32_t t) { _tempo[pos] = t; }
+ void addTimesignature(uint32_t pos, uint32_t t) { _timesignatures[pos] = t; }
// int getTempo() const { return _currenttempo; }
// void setTempo(uint32 t) { _currenttempo = t; }
// uint32 beatsToTicks(uint32 time) { return (time * _currenttempo * 480) / 60000.0; }
- uint32 beatsToTicks(uint32 time, uint32 tempo) { return uint32((time * tempo * 480) / 60000.0); }
- uint32 ticksToBeats(uint32 time) { return 60000000 / time; }
+ uint32_t beatsToTicks(uint32_t time, uint32_t tempo) { return uint32_t((time * tempo * 480) / 60000.0); }
+ uint32_t ticksToBeats(uint32_t time) { return 60000000 / time; }
void displayTracks();
- void drawFrets(double postime) const;
- void drawNotes(double postime, uint8 diff) const;
+ void drawFrets(double postime) const;
+ void drawNotes(double postime, uint8_t diff) const;
+
+ uint32_t getNbNotes(uint32_t k) const { return _nbnotes[k]; }
+ uint32_t getTotalLength(uint32_t k) const { return _totallength[k]; }
+ uint32_t getTotalNotes(uint32_t k) const { return _totalnotes[k]; }
- uint32 getNbNotes(uint32 k) const { return _nbnotes[k]; }
- uint32 getTotalLength(uint32 k) const { return _totallength[k]; }
- uint32 getTotalNotes(uint32 k) const { return _totalnotes[k]; }
+ void setEndOfTrack(uint32_t length) { if (length > _trackSize) _trackSize = length; }
+ uint32_t getEndOfTrack() const { return _trackSize; }
- void setEndOfTrack(uint32 length) { if (length > _trackSize) _trackSize = length; }
- uint32 getEndOfTrack() const { return _trackSize; }
+ Config getNote(uint32_t pos, uint8_t difficulty);
+ uint32_t getTempo(uint32_t pos);
+ uint32_t getTimeSignatures(uint32_t pos);
- Config getNote(uint32 pos, uint8 difficulty);
- uint32 getTempo(uint32 pos);
+ list<Pair<uint32_t, double> > getBips() const { return _bips; }
+ void addBip(uint32_t tick, double timestamp) {
+ stringstream strs;\r
+ strs << "Bip at " << tick << ":" << timestamp << endl;\r
+ OutputDebugString( strs.str().c_str() ) ;
+ _bips.push_back(Pair<uint32_t, double>(tick, timestamp)); }
- void computeBips();
+ //void computeBips();
void debugTempo();
- private:
+ private:
//notes : position ; configs
- map<uint32, Config> _notes[NBDIFFICULTIES];
- map<uint32, uint32> _tempo;
+ map<uint32_t, Config> _notes[NBDIFFICULTIES];
+ map<uint32_t, uint32_t> _tempo;
+ map<uint32_t, uint32_t> _timesignatures;
// private:
- list<double> _bips;
+ list<Pair<uint32_t, double> > _bips;
Config _currentconfig[NBDIFFICULTIES];
- uint32 _nbnotes[NBDIFFICULTIES];
- uint32 _totallength[NBDIFFICULTIES];
- uint32 _totalnotes[128];
- uint32 _trackSize;
+ uint32_t _nbnotes[NBDIFFICULTIES];
+ uint32_t _totallength[NBDIFFICULTIES];
+ uint32_t _totalnotes[128];
+ uint32_t _trackSize;
bool _active;
};
#include "Config.hpp"
#include <stdio.h>
+#include "PaintGame.h"
+
void Config::addKey(keys k)
{
switch(k)
{
if (_ticks > 240)
{
+ float notelength = static_cast<float>(_end - _position);
if (_a)
- drawLong(-2*NOTEDIST, LONGSIZE, _end - _position, COLOR_GREEN);
+ drawLong(-2*NOTEDIST, LONGSIZE, notelength, COLOR_GREEN);
if (_b)
- drawLong(-NOTEDIST, LONGSIZE, _end - _position, COLOR_RED);
+ drawLong(-NOTEDIST, LONGSIZE, notelength, COLOR_RED);
if (_c)
- drawLong(0, LONGSIZE, _end - _position, COLOR_YELLOW);
+ drawLong(0, LONGSIZE, notelength, COLOR_YELLOW);
if (_d)
- drawLong(NOTEDIST, LONGSIZE, _end - _position, COLOR_BLUE);
+ drawLong(NOTEDIST, LONGSIZE, notelength, COLOR_BLUE);
if (_e)
- drawLong(2*NOTEDIST, LONGSIZE, _end - _position, COLOR_ORANGE);
+ drawLong(2*NOTEDIST, LONGSIZE, notelength, COLOR_ORANGE);
}
if (_a)
cout << "Track Skipped" << endl;
}
-void MIDIReader::readTrack(Track &tr)
+void MIDIReader::readTrack(Track &tr, bool addbips)
{
uint8_t temp[4];
//read the chunk ID
// printf("TEMP : %0x %0x %0x %0x\n", temp2[0], temp2[1], temp2[2], temp2[3]);
bool end = false;
uint8_t oldeventandchannel = 0;
- uint32_t timestamp = 0;
+ uint32_t ticks = 0;
+ float timestamp = 0;
+ uint32_t currenttempo = 60000000/120;
// Track example;
+ uint32_t delta = 0;
//Read the events
while (_position < chunksize)
{
- uint32_t delta;
//The delta is a variable-length stuff
/*uint8 nblus = */readVariableLength(delta);
- timestamp += delta;
-
+ ticks += delta;
+
+ //add bips
+ if (addbips)
+ {
+ uint32_t lastbiptick = 0;
+ if (!tr.getBips().empty())
+ lastbiptick = tr.getBips().back().getX();
+ float temptimestamp = timestamp;
+ //manage 1st bip, taking into account the time elapsed since the last event
+ if (lastbiptick > 0 && ticks >= lastbiptick + 480)
+ {
+ lastbiptick += 480;
+ temptimestamp = timestamp + (lastbiptick - ticks + delta) * (currenttempo / 480000.0f);
+ tr.addBip(lastbiptick, temptimestamp);
+ }
+ //add bips with the current tempo
+ for (uint32_t i = lastbiptick ; i < ticks ; i += 480 )
+ {
+ tr.addBip(i, temptimestamp);
+ temptimestamp += currenttempo / 1000.0f;
+ }
+ }
+
+ timestamp += delta * (currenttempo / 480000.0f);
+
uint8_t eventandchannel, tempevt;
// 4 bits for event type, and 4 others for the channel
readBytes(&tempevt, 1);
cout << "MIDI Channel prefix: " << data << endl;
break;
case 0x2F:
- cout << "End of track at " << timestamp << endl;
- tr.setEndOfTrack(timestamp);
+ cout << "End of track at " << ticks << endl;
+ tr.setEndOfTrack(ticks);
end = true;
break;
case 0x51:
tempo = ((int(data[2]) << 16) + (int(data[1]) << 8) + int(data[0]));
- cout << "Tempo at " << timestamp << " : x=" << tempo << "=" << 60000000 / tempo << "bpm" << endl;
- tr.addTempo(timestamp, tempo);
+ cout << "Tempo at " << ticks << " : x=" << tempo << "=" << 60000000 / tempo << "bpm" << endl;
+ currenttempo = tempo;
+ tr.addTempo(ticks, tempo);
break;
case 0x58:
- cout << "Time signature: " << int(data[3]) << "|" << int(data[2]) << " " << int(data[1]) << " ticks " << int(data[0]) << "x" << endl;
+ cout << "Time signature at " << ticks<< " : " << int(data[3]) << "|" << int(pow(float(2), int(data[2]))) << " " << int(data[1]) << " ticks " << int(data[0]) << "x" << endl;
+ tr.addTimesignature(ticks, int(data[3]));
break;
case 0x59:
cout << "Key signature: " << int(data[1]) << " " << int(data[0]) << endl;
readBytes(&par1, 1);
readBytes(&par2, 1);
// printf("- Delta : %4d ; Note %s%d (%02x) off, velocity=%d, channel=%d\n", delta, notenames[par1 % 12], par1 / 12, par1+0, par2+0, eventandchannel & 0x0f);
- tr.remKey(timestamp, par1);
+ tr.remKey(ticks, par1);
// tr.addKey(delta, par1);
// cout << "Note " << notenames[int(par1) % 12] << (int(par1) / 12) << " (" << << ") off, velocity=" << int(par2) << " channel " << (eventandchannel & 0x0f) << endl;
break;
readBytes(&par2, 1);
// printf("+ Delta : %4d ; Note %s%d (%02x) on, velocity=%d, channel=%d\n", delta, notenames[par1 % 12], par1 / 12, par1+0, par2+0, eventandchannel & 0x0f);
if (par2 > 0)
- tr.addKey(timestamp, par1);
+ tr.addKey(ticks, par1);
else
- tr.remKey(timestamp, par1);
+ tr.remKey(ticks, par1);
// printf("Delta : %4ld ; ", delta);
// cout << "Note " << notenames[int(par1) % 12] << (int(par1) / 12 )<< " on, velocity=" << int(par2) << " channel " << (eventandchannel & 0x0f) << endl;
break;
}
// printf("Delta : %d, Event %4x on channel %d, par1 = %d, par2 = %d\n", delta, eventandchannel >> 4, eventandchannel & 0x0f, par1, par2);
}
+ //add final bips
+ //these are needed if the notes track is longer than the time events track
+ if (addbips)
+ {
+ uint32_t lastbiptick = 0;
+ if (!tr.getBips().empty())
+ lastbiptick = tr.getBips().back().getX();
+ float temptimestamp = timestamp;
+ //manage 1st bip, taking into account the time elapsed since the last event
+ if (lastbiptick > 0)
+ {
+ lastbiptick += 480;
+ temptimestamp = timestamp + (lastbiptick - ticks) * (currenttempo / 480000.0f);
+ tr.addBip(lastbiptick, temptimestamp);
+ }
+ //add 1000 bips with the current tempo
+ for (uint32_t i = lastbiptick ; i < lastbiptick + 480000 ; i += 480 )
+ {
+ tr.addBip(i, temptimestamp);
+ temptimestamp += currenttempo / 1000.0f;
+ }
+ }
// tr.displayTracks();
}
// Track t;
//read tempos
- readTrack(t);
+ readTrack(t, true);
//read notes
- readTrack(t);
+ readTrack(t, false);
//skip other tracks
for (int i = 2 ; i < _nbtracks ; i++)
{
#include "Tools.hpp"
//#include "log.hpp"
-Sound::Sound()
-:nbrchunks(0), _chunks(NULL)
-{
-}
-
-Sound::Sound(const Sound &s)
-:nbrchunks(s.nbrchunks), _chunks(s._chunks)
-{
-}
-
-Sound::Sound(const String &filename)
-:nbrchunks(0), _chunks(NULL)
-{
- addSound(filename);
-}
-
-bool Sound::addSound(const String &filename)
-{
- String buffer;
- if (fileExists(filename))
- buffer = filename;
- else if (fileExists("data/sounds/" + filename))
- buffer = "data/sounds/" + filename;
- else if (fileExists("../data/sounds/" + filename))
- buffer = "../data/sounds/" + filename;
- else if (fileExists("data/songs/" + filename))
- buffer = "data/songs/" + filename;
- else if (fileExists("../data/songs/" + filename))
- buffer = "../data/songs/" + filename;
-
- //_debug_(stderr, "Sound(%s)\n",buffer.c_str());
-
- if (buffer != "")
- {
- Mix_Chunk *c = Mix_LoadWAV(buffer.c_str());
- if(c)
- return addChunk(c);
- else
- fprintf(stderr, "cannot load sound %s ; %s\n",buffer.c_str(), SDL_GetError());
- }
- else
- fprintf(stderr, "sound file %s not found\n",filename.c_str());
-
- return false;
-}
-
-bool Sound::addChunk(Mix_Chunk *c)
-{
- if(c == NULL)
- return false;
-
- if(_chunks == NULL)
- {
- _chunks=new Mix_Chunk*[1];
- nbrchunks=1;
- _chunks[0]=c;
- }
- else
- {
- nbrchunks++;
- Mix_Chunk **t=new Mix_Chunk*[nbrchunks];
- for (int i = 0 ; i < nbrchunks - 1 ; i++)
- t[i] = _chunks[i];
- t[nbrchunks-1] = c;
- delete [] _chunks;
- _chunks=t;
- }
-
- return true;
-}
-
-Sound::~Sound()
-{
- if (_chunks)
- {
- // TODO FIX: if we copy the sound (with the copy constructor)
- // the destructor doesn't have to destroy the chunk !
- for(int i = 0 ; i < nbrchunks ; i++)
- Mix_FreeChunk(_chunks[i]);
- delete [] _chunks;
- }
-}
-
-Mix_Chunk *Sound::getChunk()
-{
- if(!_chunks)
- return NULL;
- int i = rand() % nbrchunks;
- return _chunks[i];
-}
-
-Mix_Chunk *Sound::mix()
-{
- if (nbrchunks <= 0)
- return NULL;
- Mix_Chunk *m = new(Mix_Chunk);
- m->allocated = _chunks[0]->allocated;
- m->alen = _chunks[0]->alen;
- m->abuf = new Uint8[m->alen];
- m->volume = _chunks[0]->volume;
- for (Uint32 i = 0 ; i < m->alen ; i++)
- {
- printf("%d/%d\r",i, m->alen);
- m->abuf[i] = 0;
- for (int j = 0 ; j < nbrchunks ; j++)
- m->abuf[i] += _chunks[j]->abuf[i] / nbrchunks;
- }
- return m;
-}
-
Mix_Music *Mixer::_music = NULL;
Mixer *Mixer::_minstance = NULL;
int *Mixer::_soundChannels = NULL;
--- /dev/null
+#include "PaintGame.h"
+
+#include "Texture.hpp"
+#include "Mixer.hpp"
+
+#include <GL/glew.h>
+
+#ifdef WIN32
+#include <time.h>
+#include <windows.h>
+
+#include <SDL.h>
+#include <SDL_mixer.h>
+#include <SDL_image.h>
+#else
+#include <sys/time.h>
+
+#include <SDL/SDL.h>
+#include <SDL/SDL_mixer.h>
+#include <SDL/SDL_image.h>
+#endif
+
+#include <iostream>
+using namespace std;
+
+float SECONDSIZE = 0.050f;
+float posz = 0;
+Texture *texturebois, *texturefond, *texturesteel;
+
+int resolution_x, resolution_y;
+Config fromKeyboard;
+
+extern FILE*logfile;
+
+#ifdef WIN32
+ struct { int tv_sec, tv_usec; } start;
+ DWORD t;
+#else
+ struct timeval start;
+#endif
+
+void init()
+{
+ //initializes SDL
+ cout << "init SDL" << endl;
+ const SDL_VideoInfo* info = NULL;
+
+ atexit(SDL_Quit);
+
+ 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");
+
+ cout << "get video info" << endl;
+ info = SDL_GetVideoInfo();
+ if(!info)
+ throw "Impossible to get information from SDL";
+
+ 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;
+ }
+ }
+
+ //initializes Opengl
+ if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
+ throw "Couldn't initialise Video SubSystem: %s\n";
+
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 8);
+
+ int flags = SDL_OPENGL | SDL_OPENGLBLIT | SDL_HWSURFACE;// | SDL_FULLSCREEN;
+
+// int flags = SDL_OPENGL | SDL_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";
+
+ // 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)
+ throw "Impossible to initialize SDL_GL_MULTISAMPLESAMPLES";
+
+ GLdouble ratio = (GLdouble) screen->w / screen->h;
+
+ printf("infos : %d %d %d %d\n", screen->flags, screen->w, screen->h, screen->pitch);
+ printf("Video resolution: %dx%dx%d (ratio = %3.2f)\n", screen->w, screen->h, screen->format->BitsPerPixel, ratio);
+ printf("OpenGL infos\n");
+ printf("------------\n");
+ printf("Vendor : %s\n", glGetString(GL_VENDOR));
+ printf("Renderer : %s\n", glGetString(GL_RENDERER));
+ printf("Version : %s\n", glGetString(GL_VERSION));
+ printf("Extensions: %s\n", glGetString(GL_EXTENSIONS));
+
+ glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
+ 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);
+ glEnable(GL_NORMALIZE);
+
+ GLfloat light_ambient[] = { 0.8f, 0.7f, 0.9f, 1.0f };
+ GLfloat light_diffuse[] = { 1.0f, 0.9f, 0.8f, 1.0f };
+ GLfloat light_specular[] = { 1.0f, 0.9f, 0.7f, 1.0f };
+ glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
+ glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
+// glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 0.5);
+ glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.01f);
+ glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.01f);
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+// SDL_EnableKeyRepeat(10, 100);
+
+ fromKeyboard.setPosition(-1);
+ fromKeyboard.setEnd(-1);
+}
+
+void initPaint()
+{
+ texturebois = new Texture("wood.jpg", true);
+ texturefond = new Texture("back.jpg");
+ texturesteel = new Texture("steel.jpg");
+
+
+#ifdef WIN32
+ t = timeGetTime ();
+ start.tv_sec = t / 1000;
+ start.tv_usec = (t % 1000) * 1000;
+#else
+ gettimeofday(&start, NULL);
+#endif
+}
+
+void draw(Track &t, char diff)
+{
+#ifdef WIN32
+ struct { int tv_sec, tv_usec; } now;
+ DWORD tim;
+#else
+ struct timeval now;
+#endif
+
+#ifdef WIN32
+ tim = timeGetTime ();
+ now.tv_sec = tim / 1000;
+ now.tv_usec = (tim % 1000) * 1000;
+#else
+ gettimeofday(&now, NULL);
+#endif
+ float postime = (now.tv_sec - start.tv_sec) * 1000.0f + (now.tv_usec - start.tv_usec) / 1000.0;
+ posz = -SECONDSIZE * postime;
+
+// cout << "draw screen" << endl;
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+// glColor(1.0, 1.0, 1.0, 0.0);
+
+ //Draw the back
+ glDisable(GL_LIGHTING);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ gluOrtho2D(0, resolution_x, resolution_y, 0);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ glEnable(GL_TEXTURE_2D);
+ texturefond->useTexture();
+ glBegin(GL_QUADS);
+ glColor3f(1.0f, 1.0f, 1.0f);
+ glTexCoord2d(0, 0); glVertex2f(0.0f, 0.0f);
+ glTexCoord2d(0, 1); glVertex2f(0.0f, float(resolution_y));
+ glTexCoord2d(1, 1); glVertex2f(float(resolution_x), float(resolution_y));
+ glTexCoord2d(1, 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 );
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+ //cout << "posz=" << posz << endl;
+ gluLookAt(0, POSITION_HEIGHT, posz + POSITION_EYE, 0, 0, posz + POSITION_CENTER, 0.0f, 1.0f, 0.0f);
+// gluLookAt(posx-50, posy, posz-POSITION, 0, 0,posz-POSITION, 0.0,1.0,0.0);
+ GLfloat light_position[] = { 0.0, 10.0f , posz, 1.0f };
+ glLightfv(GL_LIGHT1, GL_POSITION, light_position);
+
+// cout << "End: " << t.getEndOfTrack() << endl;
+
+//glEnable(GL_LIGHTING);
+
+ // Draw the guitar neck
+ glEnable(GL_TEXTURE_2D);
+ texturebois->useTexture();
+ glBegin(GL_QUADS);
+ glColor3f(1.0f, 1.0f, 1.0f); // Set The Color To Green
+ glTexCoord2d(0.0f, 0.0f); glVertex3f( NECKWIDTH,0, 0);
+ glTexCoord2d(0.0f, 20000); glVertex3f( NECKWIDTH,0,-1500000);
+ glTexCoord2d(1.0f, 20000); glVertex3f(-NECKWIDTH,0,-1500000);
+ glTexCoord2d(1.0f, 0.0f); glVertex3f(-NECKWIDTH,0, 0);
+ glEnd();
+ glDisable(GL_TEXTURE_2D);
+
+ glMatrixMode(GL_MODELVIEW);
+ glPushMatrix();
+ glTranslatef(0,0,posz);
+ //draw the strings
+ for (int i = 0 ; i < 5 ; i++)
+ {
+ glBegin(GL_QUADS);
+ glColor3f(0.2f, 0.2f, 0.2f);
+ glNormal3f(0, 1, 0);
+ glVertex3f(NOTEDIST*(i-2), 0, 1);
+ glVertex3f(NOTEDIST*(i-2)+.1f, 0.2f, 1);
+ glVertex3f(NOTEDIST*(i-2)+.1f, 0.2f,-VIEWLENGTH);
+ glVertex3f(NOTEDIST*(i-2), 0, -VIEWLENGTH);
+ glVertex3f(NOTEDIST*(i-2)+.1f, 0.2f, 1);
+ glVertex3f(NOTEDIST*(i-2)+.2f, 0, 1);
+ glVertex3f(NOTEDIST*(i-2)+.2f, 0,-VIEWLENGTH);
+ glVertex3f(NOTEDIST*(i-2)+.1f, 0.2f, -VIEWLENGTH);
+ glEnd();
+ }
+ //Draw the sides
+ glBegin(GL_QUADS);
+ glColor3f(0.8f, 0.8f, 0.8f);
+ glNormal3f(0, 1, 0);
+ glVertex3f(NECKWIDTH, 0, 1);
+ glVertex3f(NECKWIDTH+.1f, 0.2f, 1);
+ glVertex3f(NECKWIDTH+.1f, 0.2f,-VIEWLENGTH);
+ glVertex3f(NECKWIDTH,0, -VIEWLENGTH);
+ glVertex3f(NECKWIDTH+.1f, 0.2f, 1);
+ glVertex3f(NECKWIDTH+.2f, 0, 1);
+ glVertex3f(NECKWIDTH+.2f, 0,-VIEWLENGTH);
+ glVertex3f(NECKWIDTH+.1f, 0.2f, -VIEWLENGTH);
+ glEnd();
+ glBegin(GL_QUADS);
+ glColor3f(0.8f, 0.8f, 0.8f);
+ glNormal3f(0, 1, 0);
+ glVertex3f(-NECKWIDTH, 0, 1);
+ glVertex3f(-NECKWIDTH-.1f, 0.2f, 1);
+ glVertex3f(-NECKWIDTH-.1f, 0.2f, -VIEWLENGTH);
+ glVertex3f(-NECKWIDTH, 0, -VIEWLENGTH);
+ glVertex3f(-NECKWIDTH-.1f, 0.2f, 1);
+ glVertex3f(-NECKWIDTH-.2f, 0, 1);
+ glVertex3f(-NECKWIDTH-.2f, 0, -VIEWLENGTH);
+ glVertex3f(-NECKWIDTH-.1f, 0.2f, -VIEWLENGTH);
+ glEnd();
+ 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.8f, 0.8f, 0.8f);
+ glNormal3f(0, 1, 0);
+ glVertex3f( NECKWIDTH, 0.5f, 10);
+ glVertex3f( NECKWIDTH, 0.5f, 0);
+ glVertex3f(-NECKWIDTH, 0.5f, 0);
+ glVertex3f(-NECKWIDTH, 0.5f, 10);
+ glVertex3f( NECKWIDTH, 0.5f, 0);
+ glVertex3f( NECKWIDTH, 0, -1);
+ glVertex3f(-NECKWIDTH, 0, -1);
+ glVertex3f(-NECKWIDTH, 0.5f, 0);
+ glEnd();
+ fromKeyboard.display();
+ glPopMatrix();
+
+ SDL_GL_SwapBuffers();
+}
+
+void drawCube(float pos, float size, float colorx, float colory, float colorz)
+{
+ glEnable(GL_TEXTURE_2D);
+ texturesteel->useTexture();
+ glBegin(GL_QUADS);
+ glColor3f(colorx, colory, colorz); // Set The Color To Green
+/*
+ glNormal3f(0, -1, 0);
+ glVertex3f( size+pos,0, size); // Top Right Of The Quad (Bottom)
+ glVertex3f(-size+pos,0, size); // Top Left Of The Quad (Bottom)
+ glVertex3f(-size+pos,0,-size); // Bottom Left Of The Quad (Bottom)
+ glVertex3f( size+pos,0,-size); // Bottom Right Of The Quad (Bottom)
+*/
+ glNormal3f(0, 0.5, 0.5);
+ 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);
+ 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);
+ 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);
+ 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)
+ glVertex3f( size/2+pos, size/3, size/2); // Bottom Right 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); // Top Left Of The Quad (Top)
+/*
+*/
+ glEnd(); // Done Drawing The Quad
+}
+
+void drawLong(float pos, float size, float length, float colorx, float colory, float colorz)
+{
+ float l = length*SECONDSIZE;
+ glEnable(GL_TEXTURE_2D);
+ texturesteel->useTexture();
+ glBegin(GL_QUADS);
+ glColor3f(colorx, colory, colorz); // Set The Color
+/*
+ glNormal3f(0, -1, 0);
+ glVertex3f( size+pos,0, size); // Top Right Of The Quad (Bottom)
+ glVertex3f(-size+pos,0, size); // Top Left Of The Quad (Bottom)
+ glVertex3f(-size+pos,0,-size-l); // Bottom Left Of The Quad (Bottom)
+ glVertex3f( size+pos,0,-size-l); // Bottom Right Of The Quad (Bottom)
+*/
+ glNormal3f(0, 0.5, 0.5);
+ 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);
+ 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);
+ 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);
+ 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);
+ 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
+}
+
+void handleKeyOn(keys k)
+{
+ fromKeyboard.addKey(k);
+/* switch(k)
+ {
+ case KEY0:
+ cout << "\033[1;32mGREEN\033[0m" << endl;
+ break;
+ case KEY1:
+ cout << "\033[0;31mRED\033[0m" << endl;
+ break;
+ case KEY2:
+ cout << "\033[1;33mYELLOW\033[0m" << endl;
+ break;
+ case KEY3:
+ cout << "\033[1;34mBLUE\033[0m" << endl;
+ break;
+ case KEY4:
+ cout << "\033[0;33mORANGE\033[0m" << endl;
+ break;
+ }*/
+}
+
+void handleKeyOff(keys k)
+{
+// fromKeyboard.remKey(k);
+ if (fromKeyboard.getPosition() == -1)
+ return;
+
+#ifdef WIN32
+ struct { int tv_sec, tv_usec; } now;
+ DWORD t;
+#else
+ struct timeval now;
+#endif
+
+#ifdef WIN32
+ t = timeGetTime ();
+ now.tv_sec = t / 1000;
+ now.tv_usec = (t % 1000) * 1000;
+#else
+ gettimeofday(&now, NULL);
+#endif
+
+ double postime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000.0;
+ fromKeyboard.setEnd(postime);
+ cout << fromKeyboard << endl;
+ fromKeyboard.log("Play", logfile);
+
+ fromKeyboard.setPosition(postime);
+ fromKeyboard.setEnd(-1);
+}
+
+void handleKeys(bool a, bool b, bool c, bool d, bool e)
+{
+ if (fromKeyboard.isNone())
+ fromKeyboard.setPosition(-1);
+ fromKeyboard.setKeys(a, b, c, d, e);
+}
+
+void handleStrokeOn()
+{
+#ifdef WIN32
+ struct { int tv_sec, tv_usec; } now;
+ DWORD t;
+#else
+ struct timeval now;
+#endif
+
+#ifdef WIN32
+ t = timeGetTime ();
+ now.tv_sec = t / 1000;
+ now.tv_usec = (t % 1000) * 1000;
+#else
+ gettimeofday(&now, NULL);
+#endif
+
+ double postime = (now.tv_sec - start.tv_sec) * 1000 + (now.tv_usec - start.tv_usec) / 1000.0;
+ //cout << postime << endl;
+
+ if (fromKeyboard.getPosition() != -1)
+ {
+ fromKeyboard.setEnd(postime);
+ cout << fromKeyboard << endl;
+ fromKeyboard.log("Play", logfile);
+ }
+ fromKeyboard.setPosition(postime);
+ fromKeyboard.setEnd(-1);
+}
+
+bool processEvents()
+{
+ SDL_Event event;
+// bool quitProgram = false;
+
+ while (SDL_PollEvent (&event))
+ {
+ Uint8 *keystate;
+ switch (event.type)
+ {
+ case SDL_QUIT:
+ return true;
+ break;
+
+ case SDL_KEYDOWN:
+ keystate = SDL_GetKeyState(NULL);
+ 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:
+ return true;
+ case SDLK_UP:
+ SECONDSIZE +=10;
+ break;
+ case SDLK_DOWN:
+ SECONDSIZE -=1;
+ break;
+/* case SDLK_LEFT:
+ posy +=1;
+ break;
+ case SDLK_RIGHT:
+ posy -=1;
+ break;*/
+ case SDLK_KP_PLUS:
+ Mixer::getInstance()->setMusicVolume(Mixer::getInstance()->getMusicVolume() + 10);
+ Mixer::getInstance()->setSoundVolume(Mixer::getInstance()->getSoundVolume() + 10);
+ break;
+ case SDLK_KP_MINUS:
+ Mixer::getInstance()->setMusicVolume(Mixer::getInstance()->getMusicVolume() - 10);
+ Mixer::getInstance()->setSoundVolume(Mixer::getInstance()->getSoundVolume() - 10);
+ break;
+/* case SDLK_a:
+ handleKeyOn(KEY0);
+ break;
+ case SDLK_z:
+ handleKeyOn(KEY1);
+ break;
+ case SDLK_e:
+ handleKeyOn(KEY2);
+ break;
+ case SDLK_r:
+ handleKeyOn(KEY3);
+ break;
+ case SDLK_t:
+ handleKeyOn(KEY4);
+ break;*/
+ case SDLK_SPACE:
+ handleStrokeOn();
+ break;
+ default:
+ break;
+ }
+ break;
+
+ case SDL_KEYUP:
+ switch(((SDL_KeyboardEvent *)(&event))->keysym.sym)
+ {
+ case SDLK_F1:
+ handleKeyOff(KEY0);
+ break;
+ case SDLK_F2:
+ handleKeyOff(KEY1);
+ break;
+ case SDLK_F3:
+ handleKeyOff(KEY2);
+ break;
+ case SDLK_F4:
+ handleKeyOff(KEY3);
+ break;
+ case SDLK_F5:
+ handleKeyOff(KEY4);
+ break;
+ case SDLK_SPACE:
+ handleStrokeOff();
+ break;
+ default:
+ break;
+ }
+ keystate = SDL_GetKeyState(NULL);
+ handleKeys(keystate[SDLK_F1], keystate[SDLK_F2], keystate[SDLK_F3], keystate[SDLK_F4], keystate[SDLK_F5]);
+ break;
+ default:
+ // lasteventtype = OTHER;
+ break;
+ }
+ }
+ return false;
+}
--- /dev/null
+/*
+ * This source file is part of Haptic Metronome
+ *
+ * Copyright (C) 2011 Thomas Pietrzak
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "Sound.hpp"
+#include "Tools.hpp"
+
+Sound::Sound()
+:nbrchunks(0), _chunks(NULL)
+{
+}
+
+Sound::Sound(const Sound &s)
+:nbrchunks(s.nbrchunks), _chunks(s._chunks)
+{
+}
+
+Sound::Sound(const String &filename)
+:nbrchunks(0), _chunks(NULL)
+{
+ addSound(filename);
+}
+
+bool Sound::addSound(const String &filename)
+{
+ String buffer;
+ if (fileExists(filename))
+ buffer = filename;
+ else if (fileExists("data/sounds/" + filename))
+ buffer = "data/sounds/" + filename;
+ else if (fileExists("../data/sounds/" + filename))
+ buffer = "../data/sounds/" + filename;
+ else if (fileExists("data/songs/" + filename))
+ buffer = "data/songs/" + filename;
+ else if (fileExists("../data/songs/" + filename))
+ buffer = "../data/songs/" + filename;
+
+ //_debug_(stderr, "Sound(%s)\n",buffer.c_str());
+
+ if (buffer != "")
+ {
+ Mix_Chunk *c = Mix_LoadWAV(buffer.c_str());
+ if(c)
+ return addChunk(c);
+ else
+ fprintf(stderr, "cannot load sound %s ; %s\n",buffer.c_str(), SDL_GetError());
+ }
+ else
+ fprintf(stderr, "sound file %s not found\n",filename.c_str());
+
+ return false;
+}
+
+bool Sound::addChunk(Mix_Chunk *c)
+{
+ if(c == NULL)
+ return false;
+
+ if(_chunks == NULL)
+ {
+ _chunks=new Mix_Chunk*[1];
+ nbrchunks=1;
+ _chunks[0]=c;
+ }
+ else
+ {
+ nbrchunks++;
+ Mix_Chunk **t=new Mix_Chunk*[nbrchunks];
+ for (int i = 0 ; i < nbrchunks - 1 ; i++)
+ t[i] = _chunks[i];
+ t[nbrchunks-1] = c;
+ delete [] _chunks;
+ _chunks=t;
+ }
+
+ return true;
+}
+
+Sound::~Sound()
+{
+ if (_chunks)
+ {
+ // TODO FIX: if we copy the sound (with the copy constructor)
+ // the destructor doesn't have to destroy the chunk !
+ for(int i = 0 ; i < nbrchunks ; i++)
+ Mix_FreeChunk(_chunks[i]);
+ delete [] _chunks;
+ }
+}
+
+Mix_Chunk *Sound::getChunk()
+{
+ if(!_chunks)
+ return NULL;
+ int i = rand() % nbrchunks;
+ return _chunks[i];
+}
+
+Mix_Chunk *Sound::mix()
+{
+ if (nbrchunks <= 0)
+ return NULL;
+ Mix_Chunk *m = new(Mix_Chunk);
+ m->allocated = _chunks[0]->allocated;
+ m->alen = _chunks[0]->alen;
+ m->abuf = new Uint8[m->alen];
+ m->volume = _chunks[0]->volume;
+ for (Uint32 i = 0 ; i < m->alen ; i++)
+ {
+ printf("%d/%d\r",i, m->alen);
+ m->abuf[i] = 0;
+ for (int j = 0 ; j < nbrchunks ; j++)
+ m->abuf[i] += _chunks[j]->abuf[i] / nbrchunks;
+ }
+ return m;
+}
#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
-/*
- glNormal3f(0, -1, 0);
- glVertex3f( size+pos,0, size); // Top Right Of The Quad (Bottom)
- glVertex3f(-size+pos,0, size); // Top Left Of The Quad (Bottom)
- glVertex3f(-size+pos,0,-size); // Bottom Left Of The Quad (Bottom)
- glVertex3f( size+pos,0,-size); // Bottom Right Of The Quad (Bottom)
-*/
- glNormal3f(0, 0.5, 0.5);
- 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);
- 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);
- 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);
- 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)
- glVertex3f( size/2+pos, size/3, size/2); // Bottom Right 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); // Top Left Of The Quad (Top)
-/*
-*/
- glEnd(); // Done Drawing The Quad
-}
-
-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
-/*
- glNormal3f(0, -1, 0);
- glVertex3f( size+pos,0, size); // Top Right Of The Quad (Bottom)
- glVertex3f(-size+pos,0, size); // Top Left Of The Quad (Bottom)
- glVertex3f(-size+pos,0,-size-l); // Bottom Left Of The Quad (Bottom)
- glVertex3f( size+pos,0,-size-l); // Bottom Right Of The Quad (Bottom)
-*/
- glNormal3f(0, 0.5, 0.5);
- 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);
- 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);
- 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);
- 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);
- 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
-}
+extern float SECONDSIZE;
Track::Track()
:/*_currenttempo(120)*,_currentpos(0),*/ _trackSize(0), _active(true)
{
- for (uint8 i = 0 ; i < NBDIFFICULTIES ; i++)
+ for (uint8_t i = 0 ; i < NBDIFFICULTIES ; i++)
{
_currentconfig[i] = 0;
_nbnotes[i] = 0;
_totallength[i] = 0;
}
- for (uint8 i = 0 ; i < 128 ; i++)
+ for (uint8_t i = 0 ; i < 128 ; i++)
_totalnotes[i] = 0;
}
Track::Track(const Track &tr)
{
cerr << "WARNING: COPYING THE TRACK!" << endl;
- for (uint8 i = 0 ; i < NBDIFFICULTIES ; i++)
+ for (uint8_t i = 0 ; i < NBDIFFICULTIES ; i++)
{
_notes[i] = tr._notes[i];
_currentconfig[i] = tr._currentconfig[i];
108: vocal track (C)
*/
-void Track::addKey(uint32 time, uint8 note)
+void Track::addKey(uint32_t time, uint8_t note)
{
// _totalnotes[note]++;
// cout << "addkey begin" << endl;
- uint8 difficulty = note / 12 - 5;
- uint8 key = note % 12;
+ uint8_t difficulty = note / 12 - 5;
+ uint8_t key = note % 12;
// cout << "+ diff=" << difficulty+0 << " key=" << key+0 << " note=" << note+0 << endl; //could be note 108 for singer
if (difficulty >= NBDIFFICULTIES || difficulty < 0)
{
// cout << "addkey end" << endl;
}
-void Track::remKey(uint32 time, uint8 note)
+void Track::remKey(uint32_t time, uint8_t note)
{
_totalnotes[note]++;
// cout << "remkey begin" << endl;
- uint8 difficulty = note / 12 - 5;
- uint8 key = note % 12;
+ uint8_t difficulty = note / 12 - 5;
+ uint8_t key = note % 12;
// cout << "- diff=" << difficulty+0 << " key=" << key+0 << " note=" << note+0 << endl;
if (difficulty >= NBDIFFICULTIES || difficulty+0 < 0)
{
{
_currentconfig[difficulty].setTicks(time - _currentconfig[difficulty].getTime());
//compute the note duration and position
- uint32 currenttempo = 0, lasttick = 0;
- map<uint32, uint32>::iterator ti = _tempo.begin();
- uint32 tickpos = _currentconfig[difficulty].getTime();
+ uint32_t currenttempo = 0, lasttick = 0;
+ map<uint32_t, uint32_t>::iterator ti = _tempo.begin();
+ uint32_t tickpos = _currentconfig[difficulty].getTime();
while (ti != _tempo.end() && (*ti).first <= tickpos)
{
_currentconfig[difficulty].setPosition(_currentconfig[difficulty].getPosition() + ((*ti).first - lasttick) * (currenttempo / 480000.0));
// cout << "remkey end" << endl;
}
-Config Track::getNote(uint32 pos, uint8 difficulty)
+Config Track::getNote(uint32_t pos, uint8_t difficulty)
{
if (_notes[difficulty].count(pos) == 0)
throw 0;
return _notes[difficulty][pos];
}
-uint32 Track::getTempo(uint32 pos)
+uint32_t Track::getTempo(uint32_t pos)
{
if (_tempo.count(pos) == 0)
throw 0;
return _tempo[pos];
}
+uint32_t Track::getTimeSignatures(uint32_t pos)
+{
+ if (_timesignatures.count(pos) == 0)
+ throw 0;
+ return _timesignatures[pos];
+}
+/*
void Track::computeBips()
{
double pos = 0;
- uint32 currenttempo = 120;
- map<uint32,uint32>::iterator p = _tempo.begin();
- for (uint32 i = 0 ; i < getEndOfTrack() ; i += 480)
+ uint32_t currenttempo = 120;
+ map<uint32_t,uint32_t>::iterator p = _tempo.begin();
+ for (uint32_t i = 0 ; i < getEndOfTrack() ; i += 480)
{
//cout << "Bip @ " << pos << endl;
_bips.push_back(pos);
else
pos += currenttempo / 1000.0;
}
-}
+}*/
void Track::displayTracks()
{
cout << "TRACK:" << endl;
- for (uint8 k=0 ; k < NBDIFFICULTIES ; k++)
+ for (uint8_t k=0 ; k < NBDIFFICULTIES ; k++)
{
cout << "Difficulty " << (k+0) << ":" << endl;
- for(map<uint32,Config>::iterator i = _notes[k].begin(); i != _notes[k].end(); ++i)
+ for(map<uint32_t,Config>::iterator i = _notes[k].begin(); i != _notes[k].end(); ++i)
cout << (*i).first << ": " << (*i).second << endl;
}
}
void Track::debugTempo()
{
cout << "Tempo changes: " << endl;
- for( map<uint32,uint32>::iterator ii=_tempo.begin(); ii!=_tempo.end(); ++ii)
+ for( map<uint32_t,uint32_t>::iterator ii=_tempo.begin(); ii!=_tempo.end(); ++ii)
cout << (*ii).first << ": " << (*ii).second << " (" << ticksToBeats((*ii).second) << ")" << endl;
}
void Track::drawFrets(double postime) const
{
- static list<double>::const_iterator startingbips = _bips.begin();
+ static list<Pair<uint32_t, double> >::const_iterator startingbips = _bips.begin();
// on avance tant que les bips sont dépassées
- while (startingbips != _bips.end() && *startingbips < postime)
+ while (startingbips != _bips.end() && (*startingbips).getY() < postime)
{
Mixer::getInstance()->playSound("bip");
if (logfile)
- fprintf(logfile, "Bip;%f;%f;%f\n", *startingbips, postime, postime - *startingbips);
+ fprintf(logfile, "Bip;%f;%f;%f\n", (*startingbips).getY(), postime, postime - (*startingbips).getY());
startingbips++;
}
- list<double>::const_iterator b = startingbips;
+ list<Pair<uint32_t, double> >::const_iterator b = startingbips;
glMatrixMode(GL_MODELVIEW);
//on dessine les frettes jusqu'Ã 10s
- while (b != _bips.end() && *b < postime + 10000)
+ while (b != _bips.end() && (*b).getY() < postime + 10000)
{
glPushMatrix();
- glTranslatef(0, 0, - SECONDSIZE * *b);
+ glTranslatef(0, 0, static_cast<float>(- SECONDSIZE * (*b).getY()));
glBegin(GL_QUADS);
- glColor3f(0.8, 0.8, 0.0); // Set The Color To Green
- glNormal3f(0, 0.5, 0.5);
- glVertex3f( NECKWIDTH,0, 0.1);
- glVertex3f( NECKWIDTH,0.1, 0);
- glVertex3f(-NECKWIDTH,0.1, 0);
- glVertex3f(-NECKWIDTH,0, 0.1);
- glNormal3f(0, 0.5, -0.5);
- glVertex3f( NECKWIDTH,0.1, 0);
- glVertex3f( NECKWIDTH,0, -0.1);
- glVertex3f(-NECKWIDTH,0, -0.1);
- glVertex3f(-NECKWIDTH,0.1, 0);
+ glColor3f(0.8f, 0.8f, 0.0f); // Set The Color To Green
+ glNormal3f(0, 0.5f, 0.5f);
+ glVertex3f( NECKWIDTH,0, 0.1f);
+ glVertex3f( NECKWIDTH,0.1f, 0);
+ glVertex3f(-NECKWIDTH,0.1f, 0);
+ glVertex3f(-NECKWIDTH,0, 0.1f);
+ glNormal3f(0, 0.5f, -0.5f);
+ glVertex3f( NECKWIDTH,0.1f, 0);
+ glVertex3f( NECKWIDTH,0, -0.1f);
+ glVertex3f(-NECKWIDTH,0, -0.1f);
+ glVertex3f(-NECKWIDTH,0.1f, 0);
glEnd();
glPopMatrix();
b++;
}
}
-void Track::drawNotes(double postime, uint8 diff) const
+void Track::drawNotes(double postime, uint8_t diff) const
{
- static map<uint32,Config>::const_iterator startingn = _notes[diff].begin();
+ static map<uint32_t,Config>::const_iterator startingn = _notes[diff].begin();
static double startingpos = 0.0;
// cout << "startingpos=" << startingpos << " postime=" << postime << " first note at " << (*startingn).first << ":" << (*startingn).second.getPosition() << endl;
startingn++;
}
- map<uint32,Config>::const_iterator n = startingn;
+ map<uint32_t,Config>::const_iterator n = startingn;
glMatrixMode(GL_MODELVIEW);
//on dessine les notes jusqu'Ã 10s
while (n != _notes[diff].end() && (*n).second.getEnd() < postime + 10000)
{
glPushMatrix();
- glTranslatef(0, 0, - SECONDSIZE * (*n).second.getPosition());
+ glTranslatef(0, 0, static_cast<float>(- SECONDSIZE * (*n).second.getPosition()));
(*n).second.display();
glPopMatrix();
n++;
#include "MIDIReader.hpp"
#include "Track.hpp"
-#include "Texture.hpp"
#include "Mixer.hpp"
+#include "PaintGame.h"
+#ifdef WIN32
+#include <SDL.h>
+
+#else
+#include <SDL/SDL.h>
+#endif
-#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>
#include <SDL/SDL_mixer.h>
#endif*/
-extern double SECONDSIZE;
-
-#include "Wiimote.hpp"
-
-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;
-
-int bandVolume, guitarVolume, bipVolume;
-
FILE *logfile = NULL;
//list<double> bips;
//list<double>::iterator cb;
-void init()
-{
- //initializes SDL
- cout << "init SDL" << endl;
- const SDL_VideoInfo* info = NULL;
-
- atexit(SDL_Quit);
-
- 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");
-
- cout << "get video info" << endl;
- info = SDL_GetVideoInfo();
- if(!info)
- throw "Impossible to get information from SDL";
-
- 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;
- }
- }
-
- //initializes Opengl
- if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
- throw "Couldn't initialise Video SubSystem: %s\n";
-
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 8);
-
- int flags = SDL_OPENGL | SDL_OPENGLBLIT | SDL_HWSURFACE;// | SDL_FULLSCREEN;
-
-// int flags = SDL_OPENGL | SDL_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";
-
- // 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)
- throw "Impossible to initialize SDL_GL_MULTISAMPLESAMPLES";
-
- GLdouble ratio = (GLdouble) screen->w / screen->h;
-
- printf("infos : %d %d %d %d\n", screen->flags, screen->w, screen->h, screen->pitch);
- printf("Video resolution: %dx%dx%d (ratio = %3.2f)\n", screen->w, screen->h, screen->format->BitsPerPixel, ratio);
- printf("OpenGL infos\n");
- printf("------------\n");
- printf("Vendor : %s\n", glGetString(GL_VENDOR));
- printf("Renderer : %s\n", glGetString(GL_RENDERER));
- printf("Version : %s\n", glGetString(GL_VERSION));
- printf("Extensions: %s\n", glGetString(GL_EXTENSIONS));
-
- glClearColor(1.0, 1.0, 1.0, 0.0);
- 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);
- glEnable(GL_NORMALIZE);
-
- GLfloat light_ambient[] = { 0.8, 0.7, 0.9, 1.0 };
- GLfloat light_diffuse[] = { 1.0, 0.9, 0.8, 1.0 };
- GLfloat light_specular[] = { 1.0, 0.9, 0.7, 1.0};
- glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
- glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
-// glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 0.5);
- glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.01);
- glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.01);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
-// SDL_EnableKeyRepeat(10, 100);
-
- texturebois = new Texture("wood.jpg", true);
- texturefond = new Texture("back.jpg");
- texturesteel = new Texture("steel.jpg");
-
- fromKeyboard.setPosition(-1);
- fromKeyboard.setEnd(-1);
-}
-
-#define POSITION_HEIGHT 35
-#define POSITION_EYE 45
-#define POSITION_CENTER (-70)
-#define VIEWLENGTH 250
-
-
-void draw(Track &t, uint8 diff)
-{
-#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;
-
-// cout << "draw screen" << endl;
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-// glColor(1.0, 1.0, 1.0, 0.0);
-
- //Draw the back
- glDisable(GL_LIGHTING);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluOrtho2D(0, resolution_x, resolution_y, 0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- glEnable(GL_TEXTURE_2D);
- texturefond->useTexture();
- glBegin(GL_QUADS);
- glColor3f(1.0, 1.0, 1.0);
- glTexCoord2d(0.0, 0.0); glVertex2f(0.0, 0.0);
- glTexCoord2d(0.0, 1.0); glVertex2f(0.0, resolution_y);
- glTexCoord2d(1.0, 1.0); glVertex2f(resolution_x, resolution_y);
- glTexCoord2d(1.0, 0.0); glVertex2f(resolution_x, 0.0);
- glEnd();
- glDisable(GL_TEXTURE_2D);
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective( 45.0f, double(resolution_x) / double(resolution_y), 1/*POSITION_EYE+3*/, VIEWLENGTH );
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- //cout << "posz=" << posz << endl;
- 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);
-
-// cout << "End: " << t.getEndOfTrack() << endl;
-
-//glEnable(GL_LIGHTING);
-
- // Draw the guitar neck
- glEnable(GL_TEXTURE_2D);
- texturebois->useTexture();
- glBegin(GL_QUADS);
- glColor3f(1.0, 1.0, 1.0); // Set The Color To Green
- glTexCoord2d(0.0, 0.0); glVertex3f( NECKWIDTH,0, 0);
- glTexCoord2d(0.0, 20000); glVertex3f( NECKWIDTH,0,-1500000);
- glTexCoord2d(1.0, 20000); glVertex3f(-NECKWIDTH,0,-1500000);
- glTexCoord2d(1.0, 0.0); glVertex3f(-NECKWIDTH,0, 0);
- glEnd();
- glDisable(GL_TEXTURE_2D);
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glTranslatef(0,0,posz);
- //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);
- glVertex3f(NECKWIDTH, 0, 1);
- glVertex3f(NECKWIDTH+.1,0.2, 1);
- glVertex3f(NECKWIDTH+.1,0.2,-VIEWLENGTH);
- glVertex3f(NECKWIDTH,0, -VIEWLENGTH);
- glVertex3f(NECKWIDTH+.1, 0.2, 1);
- glVertex3f(NECKWIDTH+.2,0, 1);
- glVertex3f(NECKWIDTH+.2,0,-VIEWLENGTH);
- glVertex3f(NECKWIDTH+.1,0.2, -VIEWLENGTH);
- glEnd();
- glBegin(GL_QUADS);
- glColor3f(0.8, 0.8, 0.8);
- glNormal3f(0, 1, 0);
- glVertex3f(-NECKWIDTH, 0, 1);
- glVertex3f(-NECKWIDTH-.1,0.2, 1);
- glVertex3f(-NECKWIDTH-.1,0.2,-VIEWLENGTH);
- glVertex3f(-NECKWIDTH,0, -VIEWLENGTH);
- glVertex3f(-NECKWIDTH-.1, 0.2, 1);
- glVertex3f(-NECKWIDTH-.2,0, 1);
- glVertex3f(-NECKWIDTH-.2,0,-VIEWLENGTH);
- glVertex3f(-NECKWIDTH-.1,0.2, -VIEWLENGTH);
- glEnd();
- 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();
-}
-
-void handleKeyOn(keys k)
-{
- fromKeyboard.addKey(k);
-/* switch(k)
- {
- case KEY0:
- cout << "\033[1;32mGREEN\033[0m" << endl;
- break;
- case KEY1:
- cout << "\033[0;31mRED\033[0m" << endl;
- break;
- case KEY2:
- cout << "\033[1;33mYELLOW\033[0m" << endl;
- break;
- case KEY3:
- cout << "\033[1;34mBLUE\033[0m" << endl;
- break;
- case KEY4:
- cout << "\033[0;33mORANGE\033[0m" << endl;
- break;
- }*/
-}
-
-void handleKeyOff(keys k)
-{
-// fromKeyboard.remKey(k);
- if (fromKeyboard.getPosition() == -1)
- return;
-
-#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;
- fromKeyboard.log("Play", logfile);
-
- fromKeyboard.setPosition(postime);
- fromKeyboard.setEnd(-1);
-}
-
-void handleKeys(bool a, bool b, bool c, bool d, bool e)
-{
- if (fromKeyboard.isNone())
- fromKeyboard.setPosition(-1);
- fromKeyboard.setKeys(a, b, c, d, e);
-}
-
-void handleStrokeOn()
-{
-#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;
-
- if (fromKeyboard.getPosition() != -1)
- {
- fromKeyboard.setEnd(postime);
- cout << fromKeyboard << endl;
- fromKeyboard.log("Play", logfile);
- }
- fromKeyboard.setPosition(postime);
- fromKeyboard.setEnd(-1);
-}
-
void handleStrokeOff()
{
}
-class MyWiimote: public Wiimote
-{
- public:
- MyWiimote():Wiimote(1){}
-
- void handleStrumOn() { handleStrokeOn(); }
- void handleStrumOff() { handleStrokeOff(); }
- void handleButtonOn(int k) { handleKeyOn(keys(k)); }
- void handleButtonOff(int k) { handleKeyOff(keys(k)); }
- void handleButtons(bool a, bool b, bool c, bool d, bool e) { handleKeys(a, b, c, d, e); }
-};
-
-bool processEvents()
-{
- SDL_Event event;
-// bool quitProgram = false;
-
- while (SDL_PollEvent (&event))
- {
- Uint8 *keystate;
- switch (event.type)
- {
- case SDL_QUIT:
- return true;
- break;
-
- case SDL_KEYDOWN:
- keystate = SDL_GetKeyState(NULL);
- 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:
- return true;
- case SDLK_UP:
- SECONDSIZE +=10;
- break;
- case SDLK_DOWN:
- SECONDSIZE -=1;
- break;
-/* case SDLK_LEFT:
- posy +=1;
- break;
- case SDLK_RIGHT:
- posy -=1;
- break;*/
- case SDLK_KP_PLUS:
- Mixer::getInstance()->setMusicVolume(Mixer::getInstance()->getMusicVolume() + 10);
- Mixer::getInstance()->setSoundVolume(Mixer::getInstance()->getSoundVolume() + 10);
- break;
- case SDLK_KP_MINUS:
- Mixer::getInstance()->setMusicVolume(Mixer::getInstance()->getMusicVolume() - 10);
- Mixer::getInstance()->setSoundVolume(Mixer::getInstance()->getSoundVolume() - 10);
- break;
-/* case SDLK_a:
- handleKeyOn(KEY0);
- break;
- case SDLK_z:
- handleKeyOn(KEY1);
- break;
- case SDLK_e:
- handleKeyOn(KEY2);
- break;
- case SDLK_r:
- handleKeyOn(KEY3);
- break;
- case SDLK_t:
- handleKeyOn(KEY4);
- break;*/
- case SDLK_SPACE:
- handleStrokeOn();
- break;
- default:
- break;
- }
- break;
-
- case SDL_KEYUP:
- switch(((SDL_KeyboardEvent *)(&event))->keysym.sym)
- {
- case SDLK_F1:
- handleKeyOff(KEY0);
- break;
- case SDLK_F2:
- handleKeyOff(KEY1);
- break;
- case SDLK_F3:
- handleKeyOff(KEY2);
- break;
- case SDLK_F4:
- handleKeyOff(KEY3);
- break;
- case SDLK_F5:
- handleKeyOff(KEY4);
- break;
- case SDLK_SPACE:
- handleStrokeOff();
- break;
- default:
- break;
- }
- keystate = SDL_GetKeyState(NULL);
- handleKeys(keystate[SDLK_F1], keystate[SDLK_F2], keystate[SDLK_F3], keystate[SDLK_F4], keystate[SDLK_F5]);
- break;
- default:
- // lasteventtype = OTHER;
- break;
- }
- }
- return false;
-}
-
int main(int argc, char *argv[])
{
bool iswiimoteconnected = false;
{
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");
+ 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");
}
- init();
-
cout << "Loading song" << endl;
MIDIReader *test;
try
test->readHeader();
Track tr;
+ cout << "Reading tracks" << endl;
test->readTracks(tr);
cout << "Computing metronome bips" << endl;
//compute the ticks positions
- tr.computeBips();
+// tr.computeBips();
+
+ init();
bool quitProgram = false;
Mixer::getInstance()->setMusicVolume(30);
Mixer::getInstance()->setSoundVolume(30);
+
+ cout << "Init paint" << endl;
+ initPaint();
+
cout << "LET'S ROCK!" << endl;
Mixer::getInstance()->playMusic(songname + "/song.ogg");
Mixer::getInstance()->playSound("guitar");
if (rhythm)
Mixer::getInstance()->playSound("rhythm");
-\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;
{
// cout << "events" << endl;
quitProgram = processEvents();
- if (iswiimoteconnected)
- mw->handleEvents();
+ if (iswiimoteconnected)
+ mw->handleEvents();
// cout << "draw" << endl;
draw(tr, NORMAL);
// cout << "pause" << endl;