From: Thomas Pietrzak Date: Mon, 30 May 2011 21:56:54 +0000 (+0000) Subject: debug strings in console, changed speed/accuracy experiment track generation X-Git-Url: https://git.thomaspietrzak.com/?a=commitdiff_plain;h=6c44daab217c2945791d97e192dee8b0ce2ff09e;p=hapticmetronome.git debug strings in console, changed speed/accuracy experiment track generation git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@18 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- diff --git a/Haptic Metronome/Haptic Metronome.suo b/Haptic Metronome/Haptic Metronome.suo index 8e8eb83..a3b5701 100644 Binary files a/Haptic Metronome/Haptic Metronome.suo and b/Haptic Metronome/Haptic Metronome.suo differ diff --git a/include/Mixer.hpp b/include/Mixer.hpp index 512b3b2..1da3798 100644 --- a/include/Mixer.hpp +++ b/include/Mixer.hpp @@ -32,7 +32,6 @@ #include #else #include -#include #endif class Mixer @@ -74,7 +73,6 @@ class Mixer int _musicVolume, _soundVolume; static Mixer *_minstance; - static SDL_mutex *_mutex; }; #endif diff --git a/src/MIDIReader.cpp b/src/MIDIReader.cpp index 5783ded..9429c9d 100644 --- a/src/MIDIReader.cpp +++ b/src/MIDIReader.cpp @@ -1,13 +1,15 @@ // For format explanation, see http://www.sonicspot.com/guide/midifiles.html -#include +#include "MIDIReader.hpp" //#include #include using namespace std; -#include +#include "String.h" #include "Tools.hpp" +#include + 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) diff --git a/src/MetronomeAudio.cpp b/src/MetronomeAudio.cpp index 7d4de30..9a9ac54 100644 --- a/src/MetronomeAudio.cpp +++ b/src/MetronomeAudio.cpp @@ -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++; } diff --git a/src/MetronomeHaptic.cpp b/src/MetronomeHaptic.cpp index 30c1c93..26f921f 100644 --- a/src/MetronomeHaptic.cpp +++ b/src/MetronomeHaptic.cpp @@ -18,8 +18,17 @@ 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]; buffer1[0] = 'N'; buffer1[1] = 0x00; buffer1[2] = 0x01; unsigned char buffer2[6]; @@ -210,10 +219,12 @@ int MetronomeHaptic::thread_func(void *obj) bool written = thismetronome->_comport->WriteData(outBuffer, 5); */ - //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++; } diff --git a/src/Mixer.cpp b/src/Mixer.cpp index f895c7a..538095b 100644 --- a/src/Mixer.cpp +++ b/src/Mixer.cpp @@ -23,10 +23,11 @@ #include "Tools.hpp" //#include "log.hpp" +#include + 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; } diff --git a/src/PaintGame.cpp b/src/PaintGame.cpp index e585170..40dbbfd 100644 --- a/src/PaintGame.cpp +++ b/src/PaintGame.cpp @@ -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"); diff --git a/src/SerialWindows.cpp b/src/SerialWindows.cpp index 73f434e..584ff8c 100644 --- a/src/SerialWindows.cpp +++ b/src/SerialWindows.cpp @@ -26,9 +26,12 @@ SerialWindows::SerialWindows(char *portName) { //If not success full display an Error if(GetLastError() == ERROR_FILE_NOT_FOUND) - cerr << "ERROR: Handle was not attached. Reason: " << portName << " not available." << endl; + SDL_LogError(SDL_LOG_CATEGORY_ERROR, "ERROR: Handle was not attached. Reason: %s not available.\n", portName); else cerr << "ERROR unknown" << endl; + char buffer[256]; + sprintf(buffer, "Port %s does not exist or not reachable", portName); + throw buffer; } else { @@ -49,7 +52,7 @@ SerialWindows::SerialWindows(char *portName) //Try to get the current if (!GetCommState(_hSerial, &dcbSerialParams)) //If impossible, show an error - cerr << "ERROR: failed to get current serial parameters!" << endl; + SDL_LogError(SDL_LOG_CATEGORY_ERROR, "ERROR: failed to get current serial parameters!\n"); else { //Define serial connection parameters for the arduino board @@ -60,7 +63,7 @@ SerialWindows::SerialWindows(char *portName) //Set the parameters and check for their proper application if(!SetCommState(_hSerial, &dcbSerialParams)) - cerr << "ERROR: Could not set Serial Port parameters" << endl; + SDL_LogError(SDL_LOG_CATEGORY_ERROR, "ERROR: Could not set Serial Port parameters\n"); else { //If everything went fine we're connected diff --git a/src/Sound.cpp b/src/Sound.cpp index 6ab02cb..d34d95d 100644 --- a/src/Sound.cpp +++ b/src/Sound.cpp @@ -21,6 +21,8 @@ #include "Sound.hpp" #include "Tools.hpp" +#include + 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; } diff --git a/src/Track.cpp b/src/Track.cpp index c9e2c20..3c115a9 100644 --- a/src/Track.cpp +++ b/src/Track.cpp @@ -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 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::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::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::iterator i = _notes[k].begin(); i != _notes[k].end(); ++i) + cout << (*i).first << ": " << (*i).second << endl; + } } void Track::debugTempo() diff --git a/src/main.cpp b/src/main.cpp index f9df849..6f6b4b8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,6 +13,7 @@ #endif #include +#include #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