From 86ffaf44f880d0356093e283eee2d5ef09bb58c3 Mon Sep 17 00:00:00 2001 From: Thomas Pietrzak Date: Fri, 1 Apr 2011 15:43:52 +0000 Subject: [PATCH] Load bips when parsing, using more precision git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@6 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- Haptic Metronome/Haptic Metronome.suo | Bin 19456 -> 45568 bytes include/Config.hpp | 16 +- include/MIDIReader.hpp | 2 +- include/Mixer.hpp | 21 +- include/PaintGame.h | 38 ++ include/Sound.hpp | 53 +++ include/Tools.hpp | 4 - include/Track.hpp | 67 +-- src/Config.cpp | 13 +- src/MIDIReader.cpp | 80 +++- src/Mixer.cpp | 110 ----- src/PaintGame.cpp | 606 ++++++++++++++++++++++++++ src/Sound.cpp | 132 ++++++ src/Track.cpp | 190 +++----- src/main.cpp | 538 +---------------------- 15 files changed, 1023 insertions(+), 847 deletions(-) create mode 100644 include/PaintGame.h create mode 100644 include/Sound.hpp create mode 100644 src/PaintGame.cpp create mode 100644 src/Sound.cpp diff --git a/Haptic Metronome/Haptic Metronome.suo b/Haptic Metronome/Haptic Metronome.suo index 66ff2c7e49dec0d91b0e3b18bdc596bcad34f41b..42d219de8c34190fa86d00ba9ffdcb0d055d5658 100644 GIT binary patch literal 45568 zcmeHQ37k_!ntzR)Dk`XWfkeccv`P8~6zNVHP+D5M1y+NQPF^>$(@7>tH{A;2fjR@~ zuH!N4sw1w~j^lmcpo0vf;yJQjql}BkC^I{|Ty^7~Tn z)vH%ueRX{G)mK&D+w|I~4^}^X=!Z&*J6YL7`F_U;WoSZp5v~cE+fPvj;bITK_d9m% z5P^z<%iS)IO5i)>bucRLaKI42FaYa(IA8=|FTkFFeE@p{Mgmav%D#Y6fYE^c0S5ra z01gBk1ULk6FyK(YSioU`aR3WoJirP#0&pZ?0$?KGD8SKxV*urVQvt^Tjt86om;_*3 zBbUO8#eg>c#Py=uRT!30YF<>TO7N8Dr z8lVg?7jQaY4xk=j2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@ 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){} @@ -44,11 +42,11 @@ class Config 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; @@ -61,7 +59,7 @@ class Config private: double _position, _end; - uint32 _time, _ticks; + uint32_t _time, _ticks; bool _a, _b, _c, _d, _e; }; diff --git a/include/MIDIReader.hpp b/include/MIDIReader.hpp index 2e620f5..6c5da33 100644 --- a/include/MIDIReader.hpp +++ b/include/MIDIReader.hpp @@ -17,7 +17,7 @@ class MIDIReader void readHeader(); void skipTrack(); - void readTrack(Track &); + void readTrack(Track &, bool addbips); void readTracks(Track &t); private: MIDIReader(); diff --git a/include/Mixer.hpp b/include/Mixer.hpp index ed21914..64cb5c5 100644 --- a/include/Mixer.hpp +++ b/include/Mixer.hpp @@ -26,6 +26,8 @@ #include "String.hpp" #include "PrefixTree.hpp" +#include "Sound.hpp" + #ifdef __APPLE__ #include #elif WIN32 @@ -34,25 +36,6 @@ #include #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: diff --git a/include/PaintGame.h b/include/PaintGame.h new file mode 100644 index 0000000..c472f95 --- /dev/null +++ b/include/PaintGame.h @@ -0,0 +1,38 @@ +#ifndef _PAINTGAME_ +#define _PAINTGAME_ + +#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); +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); + +void handleKeyOn(keys k); +void handleKeyOff(keys k); +void handleKeys(bool a, bool b, bool c, bool d, bool e); +void handleStrokeOn(); +void handleStrokeOff(); +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); } +}; + +#endif diff --git a/include/Sound.hpp b/include/Sound.hpp new file mode 100644 index 0000000..fbe81f1 --- /dev/null +++ b/include/Sound.hpp @@ -0,0 +1,53 @@ +/* + * 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 +#elif WIN32 +#include +#else +#include +#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 diff --git a/include/Tools.hpp b/include/Tools.hpp index b5e55bb..923bfed 100644 --- a/include/Tools.hpp +++ b/include/Tools.hpp @@ -21,10 +21,6 @@ #ifndef __MYTOOLS__ #define __MYTOOLS__ -typedef unsigned char uint8; -typedef unsigned short uint16; -typedef unsigned int uint32; - #include "String.hpp" #include "Vector2D.hpp" #include diff --git a/include/Track.hpp b/include/Track.hpp index 9bfa783..6883c44 100644 --- a/include/Track.hpp +++ b/include/Track.hpp @@ -7,9 +7,16 @@ enum difficulties { EASY, NORMAL, HARD, EXPERT }; #include #include -/*#include +#include + +//temp +#include +#include using namespace std; -*/ + +#include +//temp + #include "Config.hpp" #include "Tools.hpp" @@ -20,51 +27,61 @@ class Track 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 > getBips() const { return _bips; } + void addBip(uint32_t tick, double timestamp) { + stringstream strs; + strs << "Bip at " << tick << ":" << timestamp << endl; + OutputDebugString( strs.str().c_str() ) ; + _bips.push_back(Pair(tick, timestamp)); } - void computeBips(); + //void computeBips(); void debugTempo(); - private: + private: //notes : position ; configs - map _notes[NBDIFFICULTIES]; - map _tempo; + map _notes[NBDIFFICULTIES]; + map _tempo; + map _timesignatures; // private: - list _bips; + list > _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; }; diff --git a/src/Config.cpp b/src/Config.cpp index 95e035e..b8df6d7 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -1,6 +1,8 @@ #include "Config.hpp" #include +#include "PaintGame.h" + void Config::addKey(keys k) { switch(k) @@ -58,16 +60,17 @@ void Config::display() const { if (_ticks > 240) { + float notelength = static_cast(_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) diff --git a/src/MIDIReader.cpp b/src/MIDIReader.cpp index bc3f1c3..86c2f99 100644 --- a/src/MIDIReader.cpp +++ b/src/MIDIReader.cpp @@ -103,7 +103,7 @@ void MIDIReader::skipTrack() cout << "Track Skipped" << endl; } -void MIDIReader::readTrack(Track &tr) +void MIDIReader::readTrack(Track &tr, bool addbips) { uint8_t temp[4]; //read the chunk ID @@ -130,19 +130,45 @@ void MIDIReader::readTrack(Track &tr) // 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); @@ -212,17 +238,19 @@ void MIDIReader::readTrack(Track &tr) 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; @@ -261,7 +289,7 @@ void MIDIReader::readTrack(Track &tr) 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; @@ -271,9 +299,9 @@ void MIDIReader::readTrack(Track &tr) 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; @@ -309,6 +337,28 @@ void MIDIReader::readTrack(Track &tr) } // 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(); } @@ -323,9 +373,9 @@ void MIDIReader::readTracks(Track &t)//, int &nb) // 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++) { diff --git a/src/Mixer.cpp b/src/Mixer.cpp index 4d9d9ae..575e716 100644 --- a/src/Mixer.cpp +++ b/src/Mixer.cpp @@ -23,116 +23,6 @@ #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; diff --git a/src/PaintGame.cpp b/src/PaintGame.cpp new file mode 100644 index 0000000..4f43850 --- /dev/null +++ b/src/PaintGame.cpp @@ -0,0 +1,606 @@ +#include "PaintGame.h" + +#include "Texture.hpp" +#include "Mixer.hpp" + +#include + +#ifdef WIN32 +#include +#include + +#include +#include +#include +#else +#include + +#include +#include +#include +#endif + +#include +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; +} diff --git a/src/Sound.cpp b/src/Sound.cpp new file mode 100644 index 0000000..6ab02cb --- /dev/null +++ b/src/Sound.cpp @@ -0,0 +1,132 @@ +/* + * 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; +} diff --git a/src/Track.cpp b/src/Track.cpp index a8405d1..77ce890 100644 --- a/src/Track.cpp +++ b/src/Track.cpp @@ -5,124 +5,27 @@ #include -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]; @@ -176,13 +79,13 @@ Track::~Track() 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) { @@ -236,12 +139,12 @@ void Track::addKey(uint32 time, uint8 note) // 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) { @@ -258,9 +161,9 @@ void Track::remKey(uint32 time, uint8 note) { _currentconfig[difficulty].setTicks(time - _currentconfig[difficulty].getTime()); //compute the note duration and position - uint32 currenttempo = 0, lasttick = 0; - map::iterator ti = _tempo.begin(); - uint32 tickpos = _currentconfig[difficulty].getTime(); + uint32_t currenttempo = 0, lasttick = 0; + map::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)); @@ -333,26 +236,33 @@ void Track::remKey(uint32 time, uint8 note) // 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::iterator p = _tempo.begin(); - for (uint32 i = 0 ; i < getEndOfTrack() ; i += 480) + uint32_t currenttempo = 120; + map::iterator p = _tempo.begin(); + for (uint32_t i = 0 ; i < getEndOfTrack() ; i += 480) { //cout << "Bip @ " << pos << endl; _bips.push_back(pos); @@ -366,15 +276,15 @@ void Track::computeBips() 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::iterator i = _notes[k].begin(); i != _notes[k].end(); ++i) + for(map::iterator i = _notes[k].begin(); i != _notes[k].end(); ++i) cout << (*i).first << ": " << (*i).second << endl; } } @@ -382,52 +292,52 @@ void Track::displayTracks() void Track::debugTempo() { cout << "Tempo changes: " << endl; - for( map::iterator ii=_tempo.begin(); ii!=_tempo.end(); ++ii) + for( map::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::const_iterator startingbips = _bips.begin(); + static list >::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::const_iterator b = startingbips; + list >::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(- 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::const_iterator startingn = _notes[diff].begin(); + static map::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; @@ -445,14 +355,14 @@ void Track::drawNotes(double postime, uint8 diff) const startingn++; } - map::const_iterator n = startingn; + map::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(- SECONDSIZE * (*n).second.getPosition())); (*n).second.display(); glPopMatrix(); n++; diff --git a/src/main.cpp b/src/main.cpp index 0bf677c..f06c20d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,24 +2,21 @@ #include "MIDIReader.hpp" #include "Track.hpp" -#include "Texture.hpp" #include "Mixer.hpp" +#include "PaintGame.h" +#ifdef WIN32 +#include + +#else +#include +#endif -#include #ifdef WIN32 #include - -#include -#include -#include #else #include - -#include -#include -#include #endif #include @@ -29,508 +26,14 @@ #include #endif*/ -extern double SECONDSIZE; - -#include "Wiimote.hpp" - -double posz=0.0; - -#ifdef WIN32 - struct { int tv_sec, tv_usec; } start; - DWORD t; -#else - struct timeval start; -#endif - -Texture *texturebois, *texturefond, *texturesteel; -int resolution_x, resolution_y; -Config fromKeyboard; - -int bandVolume, guitarVolume, bipVolume; - FILE *logfile = NULL; //list bips; //list::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 - 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 - 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 - 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); -} - 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; @@ -553,12 +56,10 @@ int main(int argc, char *argv[]) { 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 @@ -575,12 +76,15 @@ int main(int argc, char *argv[]) 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; @@ -593,20 +97,16 @@ int main(int argc, char *argv[]) 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"); - -#ifdef WIN32 - t = timeGetTime (); - start.tv_sec = t / 1000; - start.tv_usec = (t % 1000) * 1000; -#else - gettimeofday(&start, NULL); -#endif /* Sound music; cout << "Load sounds" << endl; @@ -630,8 +130,8 @@ int main(int argc, char *argv[]) { // cout << "events" << endl; quitProgram = processEvents(); - if (iswiimoteconnected) - mw->handleEvents(); + if (iswiimoteconnected) + mw->handleEvents(); // cout << "draw" << endl; draw(tr, NORMAL); // cout << "pause" << endl; -- 2.30.2