2014-04-08 14:23:22 +02:00
|
|
|
|
#include "lecture.h"
|
2014-04-07 20:51:04 +02:00
|
|
|
|
|
2014-04-08 14:23:22 +02:00
|
|
|
|
void lireTick (Motif* m, int tmp, Mix_Chunk* chunk[], int nbrPortees) { // On va lire les ticks (plus petite division temporelle de la playlist) de haut en bas
|
2014-04-07 20:51:04 +02:00
|
|
|
|
|
2014-04-08 14:23:22 +02:00
|
|
|
|
int tempsPrecedent = SDL_GetTicks();
|
2014-04-07 20:51:04 +02:00
|
|
|
|
|
2014-04-10 14:33:33 +02:00
|
|
|
|
for (int chaine = 0; chaine < nbrPortees; chaine++) { // On va lire les chaines une <20> une par num<75>ro croissant
|
2014-04-08 14:23:22 +02:00
|
|
|
|
if (m != NULL) {
|
|
|
|
|
if (getNote(m,0,tmp) == -1) Mix_HaltChannel(chaine); // Si la note est un silence, la chaine s'arr<72>te
|
2014-04-10 14:33:33 +02:00
|
|
|
|
else {
|
|
|
|
|
Mix_PlayChannel(-1, chunk[getInstrument(m,chaine,tmp)], -1); // Sinon le sample de la chaine est jou<6F> en boucle
|
|
|
|
|
}
|
2014-04-08 14:23:22 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-10 14:33:33 +02:00
|
|
|
|
while (SDL_GetTicks() - tempsPrecedent < 250) {} // Si 250 ms se sont <20>coul<75>es (il faudra r<>gler ce temps sur le tempo)
|
|
|
|
|
tempsPrecedent = tempsPrecedent + 250;
|
2014-04-08 14:23:22 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void lecture (int nombreChaines, Motif* melodie[]) {
|
2014-04-08 08:10:04 +02:00
|
|
|
|
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
|
|
|
|
|
|
|
|
|
|
//INITIALISATION SAMPLES ET CHANNELS
|
2014-04-08 14:23:22 +02:00
|
|
|
|
Mix_AllocateChannels(nombreChaines); // On ouvre le nombre de chaines n<>cessaires dans le mixer
|
|
|
|
|
Mix_Chunk* chunk[2] = {Mix_LoadWAV("Square.wav"), Mix_LoadWAV("Saw.wav")};
|
2014-04-08 08:10:04 +02:00
|
|
|
|
//Lecture des motifs
|
2014-04-08 14:23:22 +02:00
|
|
|
|
for (courant = 0; courant < taille; courant++) {
|
2014-04-08 08:10:04 +02:00
|
|
|
|
for (int i = 0; i < melodie[courant] -> nbrTmp; i++) {
|
2014-04-10 14:33:33 +02:00
|
|
|
|
printf("lecture temps %d : N=%d I=%d\n",i,getNote(melodie[courant],0,i),getInstrument(melodie[courant],0,i));
|
2014-04-08 14:23:22 +02:00
|
|
|
|
lireTick (melodie[courant], i, chunk, nombreChaines);
|
2014-04-08 08:10:04 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Mix_CloseAudio();
|
|
|
|
|
SDL_Quit();
|
2014-04-07 20:51:04 +02:00
|
|
|
|
}
|