#include <SDL_mixer/SDL_mixer.h>
#else
#include <SDL/SDL_mixer.h>
-#include <SDL/SDL_mutex.h>
#endif
class Mixer
int _musicVolume, _soundVolume;
static Mixer *_minstance;
- static SDL_mutex *_mutex;
};
#endif
// 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)
{
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()
// 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)
// 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;
if ((eventandchannel & 0xff) == 0xff)
{
if (end)
- cerr << "EXTRA EVT ";
+ SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "EXTRA EVT");
uint8_t type;
readBytes(&type, 1);
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;
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
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);
//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)
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++;
}
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
\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++;
}
#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)
//for the moment we never unload Sounds...
if (_music)
stopMusic();
- SDL_DestroyMutex(_mutex);
}
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;
snd = _sounds[s];
}
-// SDL_mutexP(_mutex);
bool res = snd->addSound(filename);
-// SDL_mutexV(_mutex);
return res;
}
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 !";
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)
{
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";
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);
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");
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");
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");
{\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
//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
\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
#include "Sound.hpp"
#include "Tools.hpp"
+#include <SDL/SDL_log.h>
+
Sound::Sound()
:nbrchunks(0), _chunks(NULL)
{
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;
}
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;
+ }
}
/**
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;
}
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()
#endif
#include <SDL/SDL.h>
+#include <SDL/SDL_log.h>
#ifdef WIN32
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
}
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