debug strings in console, changed speed/accuracy experiment track generation
authorThomas Pietrzak <thomas.pietrzak@gmail.com>
Mon, 30 May 2011 21:56:54 +0000 (21:56 +0000)
committerThomas Pietrzak <thomas.pietrzak@gmail.com>
Mon, 30 May 2011 21:56:54 +0000 (21:56 +0000)
git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@18 47cf9a05-e0a8-4ed5-9e9b-101a649bc004

Haptic Metronome/Haptic Metronome.suo
include/Mixer.hpp
src/MIDIReader.cpp
src/MetronomeAudio.cpp
src/MetronomeHaptic.cpp
src/Mixer.cpp
src/PaintGame.cpp
src/SerialWindows.cpp
src/Sound.cpp
src/Track.cpp
src/main.cpp

index 8e8eb835a6076069edf1f2140bcf3a3c5d669745..a3b5701c4c8ad878db1c45df4247c567efc915b5 100644 (file)
Binary files a/Haptic Metronome/Haptic Metronome.suo and b/Haptic Metronome/Haptic Metronome.suo differ
index 512b3b24b898040c46304eccf3047deca076e096..1da3798d102b0966b11585d9d3d965a5b4c63355 100644 (file)
@@ -32,7 +32,6 @@
 #include <SDL_mixer/SDL_mixer.h>
 #else
 #include <SDL/SDL_mixer.h>
-#include <SDL/SDL_mutex.h>
 #endif
 
 class Mixer
@@ -74,7 +73,6 @@ class Mixer
     int _musicVolume, _soundVolume;
 
     static Mixer *_minstance;
-       static SDL_mutex *_mutex;
 };
 
 #endif
index 5783ded0295a34fe524aee0897c9c4a27019d780..9429c9de3427a72c4b54b29eca9fe6dc72b1c81d 100644 (file)
@@ -1,13 +1,15 @@
 // For format explanation, see http://www.sonicspot.com/guide/midifiles.html
 
-#include <MIDIReader.hpp>
+#include "MIDIReader.hpp"
 //#include <arpa/inet.h>
 #include <iostream>
 using namespace std;
-#include <string.h>
+#include "String.h"
 
 #include "Tools.hpp"
 
+#include <SDL/SDL_log.h>
+
 MIDIReader::MIDIReader()
 :_file(NULL), _nbtracks(0), _timedivision(0), _position(0)
 {
@@ -56,31 +58,31 @@ void MIDIReader::readHeader()
        fread((void *)(temp), 1, 4, _file);
        if (strncmp((char *)temp, "MThd", 4) != 0)
        {
-               cerr << "Wrong chunk '" << (char)temp[0] << (char)temp[1] << (char)(char)temp[2] << (char)temp[3] << "'" << endl;
+               SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Wrong chunk '%c%c%c%c'\n", (char)temp[0], (char)temp[1], (char)(char)temp[2], (char)temp[3]);
                return;
        }
 
        //read the chunk size
        uint32_t chunksize;
        readBytes(&chunksize, 4);
-       cout << "Header size: " << chunksize << endl;
+       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Header size: %d\n", chunksize);
 
        //read the format
        uint16_t format;
        readBytes(&format, 2);
-       cout << "Format type: " << format << endl;
+       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Format type: %d\n", format);
        
        //read the format
        readBytes(&_nbtracks, 2);
-       cout << "Nb of tracks: " << _nbtracks << endl;
+       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION,  "Nb of tracks: %d\n", _nbtracks);
        
        //read the format
        readBytes(&_timedivision, 2);
-       cout << "Time division: " << _timedivision << endl;
+       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Time division: %d\n", _timedivision);
 
        //In theory there is no more than 6 bytes in the header...
        if (chunksize > 6)
-               cout << (chunksize - 6) << "more bytes in the header" << endl;
+               SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%d more bytes in the header\n", (chunksize - 6));
 }
 
 void MIDIReader::skipTrack()
@@ -91,16 +93,16 @@ void MIDIReader::skipTrack()
 //      cerr << temp << endl;
        if (strncmp((char *)temp, "MTrk", 4) != 0)
        {
-               cerr << "Wrong track chunk '" << (char)temp[0] << (char)temp[1] << (char)temp[2] << (char)temp[3] << "'" << endl;
+               SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Wrong track chunk '%c%c%c%c'\n", (char)temp[0], (char)temp[1], (char)temp[2], (char)temp[3]);
                return;
        }
 
        //read the chunk size
        uint32_t chunksize;
        readBytes(&chunksize, 4);
-       cout << "Chunk size: " << chunksize << endl;
-               fseek(_file, chunksize, SEEK_CUR);
-       cout << "Track Skipped" << endl;
+       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Chunk size: %d\n", chunksize);
+       fseek(_file, chunksize, SEEK_CUR);
+       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Track Skipped\n");
 }
 
 void MIDIReader::readTrack(Track &tr, bool addbips)
@@ -111,14 +113,14 @@ void MIDIReader::readTrack(Track &tr, bool addbips)
 //      cerr << temp << endl;
        if (strncmp((char *)temp, "MTrk", 4) != 0)
        {
-               cerr << "Wrong track chunk '" << (char)temp[0] << (char)temp[1] << (char)temp[2] << (char)temp[3] << "'" << endl;
+               SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Wrong track chunk '%c%c%c%c'\n", (char)temp[0], (char)temp[1], (char)temp[2], (char)temp[3]);
                return;
        }
 
        //read the chunk size
        uint32_t chunksize;
        readBytes(&chunksize, 4);
-       cout << "Chunk size: " << chunksize << endl;
+       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Chunk size: %d\n", chunksize);
 
 //      unsigned long
        _position = 0;
@@ -192,7 +194,7 @@ void MIDIReader::readTrack(Track &tr, bool addbips)
                if ((eventandchannel & 0xff) == 0xff)
                {
                        if (end)
-                               cerr << "EXTRA EVT ";
+                               SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "EXTRA EVT");
                        uint8_t type;
                        readBytes(&type, 1);
 
@@ -206,62 +208,63 @@ void MIDIReader::readTrack(Track &tr, bool addbips)
                        switch(type)
                        {
                                case 0x00:
-                                       cout << "Sequence number: " << data[0] << " ; " << data[1] << endl;
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Sequence number: %d;%d", data[0], data[1]);
                                        break;
                                case 0x01:
-                                       cout << "Text: ";
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Text: ");
                                        printBytes(data, length);
                                        break;
                                case 0x02:
-                                       cout << "Copyright: ";
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Copyright: ");
                                        printBytes(data, length);
                                        break;
                                case 0x03:
-                                       cout << "Track name: ";
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Track name: ");
                                        printBytes(data, length);
                                        break;
                                case 0x04:
-                                       cout << "Instrument name: ";
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Instrument name: ");
                                        printBytes(data, length);
                                        break;
                                case 0x05:
-                                       cout << "Lyrics: ";
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Lyrics: ");
                                        printBytes(data, length);
                                        break;
                                case 0x06:
-                                       cout << "Maker: ";
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Maker: ");
                                        printBytes(data, length);
                                        break;
                                case 0x07:
-                                       cout << "Cue point: ";
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Cue point: ");
                                        printBytes(data, length);
                                        break;
                                case 0x20:
-                                       cout << "MIDI Channel prefix: " << data << endl;
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "MIDI Channel prefix: %d", data);
                                        break;
                                case 0x2F:
-                                       cout << "End of track at " << ticks << endl;
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "End of track at %d", ticks);
                                        tr.setEndOfTrack(ticks);
                                        end = true;
                                        break;
                                case 0x51:
                                        tempo = ((uint32_t(data[2] & 0x000000ff) << 16) + (uint32_t(data[1] & 0x000000ff) << 8) + uint32_t(data[0] & 0x000000ff));
-                                       cout << "Tempo at " << ticks << " : x=" << tempo << "=" << 60000000 / tempo << "bpm" << endl;
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Tempo at %d : x = %d = %d bpm\n", ticks, tempo, 60000000 / tempo);
                                        currenttempo = tempo;
                                        tr.addTempo(ticks, timestamp, tempo);
                                        break;
                                case 0x58:
-                                       cout << "Time signature at " << ticks<< " : " << uint8_t(data[3]) << "|" << int(pow(float(2), uint8_t(data[2]))) << " " << int(data[1]) << " ticks " << int(data[0]) << "x" << endl;
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Time signature at %d : %d|%d %d ticks %d x", 
+                                               ticks, uint8_t(data[3]), int(pow(float(2), uint8_t(data[2]))), int(data[1]), int(data[0]));
                                        tr.addTimesignature(ticks, timestamp, uint8_t(data[3]));
                                        break;
                                case 0x59:
-                                       cout << "Key signature: " << uint8_t(data[1]) << " " << uint8_t(data[0]) << endl;
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Key signature: %d %d\n", uint8_t(data[1]), uint8_t(data[0]));
                                        break;
                                case 0x7F:
-                                       cout << "Sequencer stuff!" << endl;
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Sequencer stuff!\n");
                                        break;
                                default:
-                                       printf("Unknown chunk: %0x, size=%d\n", type, length);
+                                       SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unknown chunk: %0x, size=%d\n", type, length);
                                        break;
                        }
                        delete []data;
@@ -274,7 +277,7 @@ void MIDIReader::readTrack(Track &tr, bool addbips)
                        readVariableLength(length);
                        uint8_t *data = new uint8_t[length];
                        readBytes(data, length);
-                       printf("System data\n");
+                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "System data\n");
                        delete []data;
                }
                //Other events
@@ -310,25 +313,25 @@ void MIDIReader::readTrack(Track &tr, bool addbips)
                                case 0xA0:
                                        readBytes(&par1, 1);
                                        readBytes(&par2, 1);
-                                       printf("Delta : %4d ; Note Aftertouch\n", delta);
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Delta : %4d ; Note Aftertouch\n", delta);
                                        break;
                                case 0xB0:
                                        readBytes(&par1, 1);
                                        readBytes(&par2, 1);
-                                       printf("Delta : %4d ; Controller\n", delta);
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Delta : %4d ; Controller\n", delta);
                                        break;
                                case 0xC0:
                                        readBytes(&par1, 1);
-                                       printf("Delta : %4d ; Program Change\n", delta);
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Delta : %4d ; Program Change\n", delta);
                                        break;
                                case 0xD0:
                                        readBytes(&par1, 1);
-                                       printf("Delta : %4d ; Channel Aftertouch\n", delta);
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Delta : %4d ; Channel Aftertouch\n", delta);
                                        break;
                                case 0xE0:
                                        readBytes(&par1, 1);
                                        readBytes(&par2, 1);
-                                       printf("Delta : %4d ; Pitch Bend\n", delta);
+                                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Delta : %4d ; Pitch Bend\n", delta);
                                        break;
                                default:
                                        readBytes(&par1, 1);
@@ -381,29 +384,25 @@ void MIDIReader::readTracks(Track &t)//, int &nb)
        //skip other tracks
        for (int i = 2 ; i < _nbtracks ; i++)
        {
-               cout << "Skipping Track " << i << endl;
+               SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Skipping Track %d\n", i);
                skipTrack();
        }
 
 
-       cout << "Stats Track " << endl;
+       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Stats Track\n");
        for (int j = 0 ; j < NBDIFFICULTIES ; j++)
-       {
-               cout << "       Difficulty " << j << " ";
-               cout << t.getNbNotes(j) << " notes ";
-               cout << " l=" << t.getTotalLength(j) << endl;
-       }
+               SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "    Difficulty %d ; %d notes ; l=%d\n", j, t.getNbNotes(j), t.getTotalLength(j));
 
 //      t.debugTempo();
 
        int total = 0;
-       cout << "Notes : ";
+       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Notes : ");
        for (int j = 0 ; j < 128 ; j++)
        {
-               cout << j << ":" << t.getTotalNotes(j) << " ";
+               SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "%d:%d ", j, t.getTotalNotes(j));
                total += t.getTotalNotes(j);
        }
-       cout << endl << "Total : " << total << endl;
+               SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Total : %d\n");
 }
 
 uint8_t MIDIReader::readVariableLength(uint32_t &nb)
index 7d4de3042f5bb886b33fd0610c65283d3dbff0ae..9a9ac548d7341f56b69d105b857fc5280d4d07af 100644 (file)
@@ -88,9 +88,11 @@ int MetronomeAudio::thread_func(void *obj)
                while (cTimesignature != timesignatures->end() && (*cTimesignature).second.getX() < currenttime)
                {
                        //tempo change
-                       stringstream s;
-                       s << "Time signature change at " << currenttime << " : tick=" << (*cTimesignature).first << " at " << (*cTimesignature).second.getX() << " for " << (*cTimesignature).second.getY() << " beats " << endl;
-                       OutputDebugString(s.str().c_str());
+                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Time signature change at %d : tick=%d at %d for %d beats\n", 
+                               currenttime, 
+                               (*cTimesignature).first, 
+                               (*cTimesignature).second.getX(), 
+                               (*cTimesignature).second.getY());
                        thismetronome->_nbbeats = (*cTimesignature).second.getY();
                        cTimesignature++;
                }
index 30c1c932aff5f9e63f40ab3f82e8dc5fd680be65..26f921f5c4515d382bba013d01128b6d55cd06f8 100644 (file)
 extern FILE *logfile;
 
 MetronomeHaptic::MetronomeHaptic(const Track *track, uint32_t nbbeats, uint32_t tempo, bool activated)
-:Metronome(track, nbbeats, tempo, activated), thread(NULL), _comport(new SerialWindows("COM3"))
+:Metronome(track, nbbeats, tempo, activated), thread(NULL)
 {
+       try
+       {
+                _comport = new SerialWindows("COM3");
+       }
+       catch (char *error)
+       {
+               SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s\n", error);
+                _comport = new SerialWindows("COM5");
+       }
        unsigned char buffer1[3];\r
        buffer1[0] = 'N'; buffer1[1] = 0x00; buffer1[2] = 0x01;\r
        unsigned char buffer2[6];\r
@@ -210,10 +219,12 @@ int MetronomeHaptic::thread_func(void *obj)
        \r
                        bool written = thismetronome->_comport->WriteData(outBuffer, 5);\r
        */                      
-                       //tempo change
-                       stringstream s;
-                       s << "Time signature change at " << currenttime << " : tick=" << (*cTimesignature).first << " at " << (*cTimesignature).second.getX() << " for " << (*cTimesignature).second.getY() << " beats " << endl;
-                       OutputDebugString(s.str().c_str());
+                       //time signature change
+                       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Time signature change at %d : tick=%d at %d for %d beats\n", 
+                               currenttime, 
+                               (*cTimesignature).first, 
+                               (*cTimesignature).second.getX(), 
+                               (*cTimesignature).second.getY());
                        thismetronome->_nbbeats = (*cTimesignature).second.getY();
                        cTimesignature++;
                }
index f895c7a08c61bb67f983915a8c9329cea2be6695..538095b4dcbd4e2b6f6bc18e2662f1a89c13d7bb 100644 (file)
 #include "Tools.hpp"
 //#include "log.hpp"
 
+#include <SDL/SDL_log.h>
+
 Mix_Music *Mixer::_music = NULL;
 Mixer *Mixer::_minstance = NULL;
 int *Mixer::_soundChannels = NULL;
-SDL_mutex *Mixer::_mutex = SDL_CreateMutex();
 
 Mixer::Mixer()
 :/*_music(NULL), *//*_soundChannels(new int[MAXSOUNDS]),*/ _musicVolume(-1), _soundVolume(-1)
@@ -57,7 +58,6 @@ Mixer::~Mixer()
         //for the moment we never unload Sounds...
        if (_music)
                stopMusic();
-       SDL_DestroyMutex(_mutex);
 }
 
 
@@ -95,19 +95,17 @@ void Mixer::loadMusic(const String &filename)
 
        if (buffer != "")
        {
-//             SDL_mutexP(_mutex);
                _music = Mix_LoadMUS(buffer.c_str());
                if(_music==NULL)
-                       fprintf(stderr, "cannot load music %s\n",buffer.c_str());
+                       SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "cannot load music %s\n",buffer.c_str());
 /*             else
                {
                        Mix_PlayMusic(_music, -1);
                        Mix_HookMusicFinished(stopMusic);
                }*/
-//             SDL_mutexV(_mutex);
        }
        else
-               fprintf(stderr, "music file %s not found\n",filename.c_str());
+               SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "music file %s not found\n",filename.c_str());
 
        //else
        //      cout << "music file " << filename << " not found" << endl;
@@ -142,9 +140,7 @@ bool Mixer::addSound(const String &s, const String &filename)
                snd = _sounds[s];
        }
 
-//     SDL_mutexP(_mutex);
        bool res = snd->addSound(filename);
-//     SDL_mutexV(_mutex);
 
        return res;
 }
index e585170a89fbcee9bdc1bafbcbd18becbb3b2b32..40dbbfd834f77982824a6d113c385dee063f63c5 100644 (file)
@@ -38,28 +38,32 @@ SDL_Renderer *renderer;
 void init()
 {
        //initializes SDL
-       cout << "init SDL" << endl;
+       SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "Init SDL\n");
        const SDL_VideoInfo* info = NULL;
 
        atexit(SDL_Quit);
 
-       if( SDL_Init(SDL_INIT_EVERYTHING) <0 )
-       throw "Error while loading SDL";
+       if (SDL_Init(SDL_INIT_EVERYTHING) < 0)
+               throw "Error while loading SDL";
 
        //Initialize SDL_mixer
-       if (Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 1024 ) == -1 )
-       throw String("Can't initialize sound");
+       if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 1024 ) == -1)
+               throw "Can't initialize sound";
 
-       cout << "get video info" << endl;
+       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Get video info\n");
        info = SDL_GetVideoInfo();
        if(!info)
-       throw "Impossible to get information from SDL";
+               throw "Impossible to get information from SDL";
 
        SDL_EnableUNICODE(1);
 
        //   int width, height;
        // we search for the available screen sizes
+#if FULLSCREEN
        int searchflags = SDL_HWSURFACE | SDL_FULLSCREEN;
+#else
+       int searchflags = SDL_HWSURFACE;
+#endif
        SDL_Rect **modes = SDL_ListModes(NULL, searchflags);
        if (modes == NULL)
                throw "Impossible to get the screen resolution !";
@@ -75,7 +79,7 @@ void init()
                resolution_y = 768;
                for (i=0 ; modes[i] ; i++)
                {
-                       cout << "Resolution available: " << modes[i]->w << "x" << modes[i]->h << endl;
+                       SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Resolution available: %d x %d\n", modes[i]->w, modes[i]->h);
                        //if (modes[i]->w== 1600 && modes[i]->h == 900) //> resolution_x)//
                        if (modes[i]->w * modes[i]->h > resolution_x * resolution_x)
                        {
@@ -140,10 +144,14 @@ void init()
     throw "Impossible to initialize SDL_GL_MULTISAMPLESAMPLES";
        
 //   int flags = SDL_OPENGL | SDL_OPENGLBLIT | SDL_SWSURFACE | SDL_FULLSCREEN;
-  int flags = SDL_OPENGL;// | SDL_FULLSCREEN;
-  SDL_Surface * screen;
+#if FULLSCREEN
+  int flags = SDL_OPENGL | SDL_FULLSCREEN;
+#else
+  int flags = SDL_OPENGL;
   resolution_x = 1024;
   resolution_y = 768;
+#endif
+  SDL_Surface * screen;
 //  if (!(screen = SDL_SetVideoMode(resolution_x, resolution_y, 0, flags)))
   if (!(screen = SDL_SetVideoMode(resolution_x, resolution_y, 0, flags)))
     throw "Impossible to change the video mode";
@@ -152,14 +160,14 @@ void init()
 
   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));
+  SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "infos : %d %d %d %d\n", screen->flags, screen->w, screen->h, screen->pitch);
+  SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Video resolution: %dx%dx%d (ratio = %3.2f)\n", screen->w, screen->h, screen->format->BitsPerPixel, ratio);
+  SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "OpenGL infos\n");
+  SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "------------\n");
+  SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Vendor    : %s\n", glGetString(GL_VENDOR));
+  SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Renderer  : %s\n", glGetString(GL_RENDERER));
+  SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Version   : %s\n", glGetString(GL_VERSION));
+  SDL_LogDebug(SDL_LOG_CATEGORY_VIDEO, "Extensions: %s\n", glGetString(GL_EXTENSIONS));
 #endif
 
   glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
@@ -635,13 +643,23 @@ void loop(const Track &tr, const String &songname)
        catch(...){}
 
        init();
-       cout << "Create Metronome" << endl;
+       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Create Metronome\n");
 //     Metronome *m = new MetronomeAudio(&tr);
-       Metronome *m = new MetronomeHaptic(&tr);
+       Metronome *m;
+       try
+       {
+               m = new MetronomeHaptic(&tr);
+       }
+       catch (char *error)
+       {
+//             cout << error << endl;
+               SDL_LogError(SDL_LOG_CATEGORY_ERROR, "%s\n", error);
+               m = NULL;
+       }
 
        bool quitProgram = false;
 
-       cout << "Loading sounds" << endl;
+       SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "Loading sounds\n");
 
 //     Mixer::getInstance()->addSound("guitar", songname + "/guitar.ogg");
 //     bool rhythm = Mixer::getInstance()->addSound("rhythm", songname + "/rhythm.ogg");
@@ -649,7 +667,7 @@ void loop(const Track &tr, const String &songname)
        Mixer::getInstance()->setMusicVolume(30);
        Mixer::getInstance()->setSoundVolume(30);
 
-       cout << "Init paint" << endl;
+       SDL_LogDebug(SDL_LOG_CATEGORY_SYSTEM, "Init paint\n");
        initPaint();
        Mixer::getInstance()->loadMusic(songname + "/tout.ogg");
 
@@ -662,11 +680,12 @@ void loop(const Track &tr, const String &songname)
      gettimeofday(&start, NULL);
 #endif
 
-       cout << "LET'S ROCK!" << endl;
+       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "LET'S ROCK!\n");
        //m->setActive(true);
 
        Mixer::getInstance()->playMusic();
-       m->run();
+       if (m)
+               m->run();
 /*     Mixer::getInstance()->playSound("guitar");
        if (rhythm)
                Mixer::getInstance()->playSound("rhythm");
index 73f434e484c6a5bf661a9303cc95e462a3e7b146..584ff8c81882f0f41471a3d1cc93e27c1bc09471 100644 (file)
@@ -26,9 +26,12 @@ SerialWindows::SerialWindows(char *portName)
     {\r
         //If not success full display an Error\r
         if(GetLastError() == ERROR_FILE_NOT_FOUND)\r
-            cerr << "ERROR: Handle was not attached. Reason: " << portName << " not available." << endl;\r
+            SDL_LogError(SDL_LOG_CATEGORY_ERROR, "ERROR: Handle was not attached. Reason: %s not available.\n", portName);\r
         else\r
             cerr << "ERROR unknown" << endl;\r
+               char buffer[256];\r
+               sprintf(buffer, "Port %s does not exist or not reachable", portName);\r
+               throw buffer;\r
     }\r
     else\r
     {\r
@@ -49,7 +52,7 @@ SerialWindows::SerialWindows(char *portName)
         //Try to get the current\r
         if (!GetCommState(_hSerial, &dcbSerialParams))\r
             //If impossible, show an error\r
-            cerr << "ERROR: failed to get current serial parameters!" << endl;\r
+            SDL_LogError(SDL_LOG_CATEGORY_ERROR, "ERROR: failed to get current serial parameters!\n");\r
         else\r
         {\r
             //Define serial connection parameters for the arduino board\r
@@ -60,7 +63,7 @@ SerialWindows::SerialWindows(char *portName)
 \r
              //Set the parameters and check for their proper application\r
              if(!SetCommState(_hSerial, &dcbSerialParams))\r
-                cerr << "ERROR: Could not set Serial Port parameters" << endl;\r
+                SDL_LogError(SDL_LOG_CATEGORY_ERROR, "ERROR: Could not set Serial Port parameters\n");\r
              else\r
              {\r
                  //If everything went fine we're connected\r
index 6ab02cbfc2597f5a590481a1df8cc8c23e1a4e7b..d34d95d3d33ef842b05e5eafbba291754eb26e0d 100644 (file)
@@ -21,6 +21,8 @@
 #include "Sound.hpp"
 #include "Tools.hpp"
 
+#include <SDL/SDL_log.h>
+
 Sound::Sound()
 :nbrchunks(0), _chunks(NULL)
 {
@@ -59,10 +61,10 @@ bool Sound::addSound(const String &filename)
                if(c)
                        return addChunk(c);
                else
-                       fprintf(stderr, "cannot load sound %s ; %s\n",buffer.c_str(), SDL_GetError());
+                       SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "cannot load sound %s ; %s\n",buffer.c_str(), SDL_GetError());
        }
        else
-               fprintf(stderr, "sound file %s not found\n",filename.c_str());
+               SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "sound file %s not found\n",filename.c_str());
 
        return false;
 }
index c9e2c207c14df5ff336b9bf84346ea34ce206d9c..3c115a903110687fc3ad3b244e0bc58fa137dc57 100644 (file)
@@ -31,14 +31,14 @@ Track::Track()
 
 Track::Track(const Track &tr)
 {
-       cerr << "WARNING: COPYING THE TRACK!" << endl;
-  for (uint8_t i = 0 ; i < NBDIFFICULTIES ; i++)
-  {
-    _notes[i] = tr._notes[i];
-    _currentconfig[i] = tr._currentconfig[i];
-    _nbnotes[i] = 0;
-    _totallength[i] = 0;
-  }
+       SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "WARNING: COPYING THE TRACK!\n");
+       for (uint8_t i = 0 ; i < NBDIFFICULTIES ; i++)
+       {
+               _notes[i] = tr._notes[i];
+               _currentconfig[i] = tr._currentconfig[i];
+               _nbnotes[i] = 0;
+               _totallength[i] = 0;
+       }
 }
 
 /**
@@ -74,15 +74,20 @@ Track::Track(uint8_t nbbuttons, uint8_t repetitions, uint8_t nbspeeds, uint32_t
                addTempo(tick, timestamp, tempo);
                vector<uint8_t> configs;
 
+               //creates a block with repetitions of all the patterns (excluding the empty pattern)
                for (int i = 1 ; i < (int)pow(2.0, (double)nbbuttons) ; i++)
                        for (int j = 0 ; j < repetitions ; j++)
                                configs.push_back(i);
+
+               //generate a random permutation of the elements
                random_shuffle(configs.begin(), configs.end());
 
+               //add the permutation to the note list
                for (vector<uint8_t>::iterator it = configs.begin() ; it != configs.end() ; it++)
                {
+                       uint8_t cfg = ((*it) & 0x03) | (((*it) & 0x0c) << 1);
                        for (int d=0 ; d < NBDIFFICULTIES ; d++)
-                               _notes[d][tick] = Config(*it, timestamp, timestamp+100, tick, 1);
+                               _notes[d][tick] = Config(cfg, timestamp, timestamp+100, tick, 1);
                        tick++;
                        timestamp += tempo / 1000;
                }
@@ -343,13 +348,13 @@ void Track::computeBips()
 
 void Track::displayTracks()
 {
-  cout << "TRACK:" << endl;
-  for (uint8_t k=0 ; k < NBDIFFICULTIES ; k++)
-  {
-    cout << "Difficulty " << (k+0) << ":" << endl;
-    for(map<uint32_t,Config>::iterator i = _notes[k].begin(); i != _notes[k].end(); ++i)
-      cout << (*i).first << ": " << (*i).second << endl;
-  }
+       cout << "TRACK:" << endl;
+       for (uint8_t k=0 ; k < NBDIFFICULTIES ; k++)
+       {
+               cout << "Difficulty " << (k+0) << ":" << endl;
+               for(map<uint32_t,Config>::iterator i = _notes[k].begin(); i != _notes[k].end(); ++i)
+                       cout << (*i).first << ": " << (*i).second << endl;
+       }
 }
 
 void Track::debugTempo()
index f9df849c1406cfe1d7e35f6966965cbdd51ded46..6f6b4b8b658c42915c8a0dc9d2e811ab2340ca67 100644 (file)
@@ -13,6 +13,7 @@
 #endif
 
 #include <SDL/SDL.h>
+#include <SDL/SDL_log.h>
 
 
 #ifdef WIN32
@@ -47,7 +48,9 @@ int main(int argc, char *argv[])
        time_t tim = time(NULL);
        struct tm *t  = gmtime(&tim);
 
-       cout << "Loading song" << endl;
+       SDL_LogSetAllPriority(SDL_LOG_PRIORITY_VERBOSE);
+
+       SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Loading song\n");
        //6 params => toms law experiment
        // v0 = prog
        // v1 = condition
@@ -104,13 +107,13 @@ int main(int argc, char *argv[])
                }
                catch(...)
                {
-                       cerr << "Unable to load the song file" << endl;
+                       SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Unable to load the song fil\n");
                        exit(0);
                }
 
-               cout << "Loading notes" << endl;
+               SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Loading notes\n");
                test->readHeader();
-               cout << "Reading tracks" << endl;
+               SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, "Reading tracks\n");
                test->readTracks(tr);
 
                //run the game with a song