diff --git a/ana_midi.c b/ana_midi.c new file mode 100644 index 0000000..d5d525f --- /dev/null +++ b/ana_midi.c @@ -0,0 +1,205 @@ +#include +#include + +int main(int argc,char *argv[]){ + if(argc<2) exit(EXIT_FAILURE); + char *nom=argv[1]; + FILE *fichier=fopen(nom,"r"); + if(fichier==NULL) exit(EXIT_FAILURE); + unsigned char c[2]; + + + // HEADER + fread(c,2,1,fichier); + if((c[0]==0x4d) && (c[1]==0x54)) + { + fread(c,2,1,fichier); + printf("Fichier MIDI détecté.\n"); + fread(c,2,1,fichier); + + + //longueur header + int longueur=0; + longueur=(c[1] << 16) + (c[0] << 32); + fread(c,2,1,fichier); + longueur=longueur + c[1] + (c[0] << 8); + printf("taille header = %d \n",longueur); + + + //format header + fread(c,2,1,fichier); + if(c[1]==0x00) printf("le format est : single track\n"); + if(c[1]==0x01) printf("le format est : multiple track\n"); + if(c[1]==0x02) printf("le format est : multiple song\n"); + + + //nbre de morceaux + fread(c,2,1,fichier); + int n = 0; + n=c[1] + (c[0] << 8); + printf("le nombre de gros morceaux est : %d \n", n); + + + //nbre ticks/beat + fread(c,2,1,fichier); + int ticks = 0; + ticks = c[1] + (c[0] << 8); + printf("nombre de ticks/beat = %d \n",ticks); + + + //Dans un morceau RECUPERATION DE LA TAILLE DE LA CHANSON à partir du Mrtk + fread(c,2,1,fichier); + int longueur_track =0; + if ((c[0]==0x4d) && (c[1]==0x54)) + { + printf("morceau?\n"); + fread(c,2,1,fichier); + if ((c[0]==0x72) && (c[1]==0x6b)) { printf("oui\n");} + + fread(c,2,1,fichier); + longueur_track = (int)(c[1] << 16) + (int)(c[0] << 32); + fread(c,2,1,fichier); + longueur_track = longueur_track + c[1] + (c[0] << 8); + printf("la longueur du morceau est de : %d octets \n", longueur_track); + } + + //Track event + int fin_track = 0; + while(fin_track < longueur_track) + { + fin_track++; + //recup timing + fread(c,1,1,fichier); + int time= c[0]; + if(c[0]>128) + { + unsigned char k; + fread(&k,1,1,fichier); + time = ((c[0]&0x0F)<<8) + k; + printf("moment evenement : %d\n",time); + } + printf("moment evenement : %d\n",time); + + + //QUEL TYPE EVENEMENT + fread(c,1,1,fichier); + + + + //meta evevenemnt + if (c[0]==0xff) + { + printf("meta evenement : \n"); + fread(c,2,1,fichier); + if(c[0]==0x00) + {printf("le numéro de la sequence est: \n");} + if(c[0]==0x01) + {printf("evenement text \n");} + if(c[0]==0x02) + {printf("copyright notice\n");} + if(c[0]==0x03) + {printf("sequence or track name \n");} + if(c[0]==0x04) + {printf("instrument name \n");} + if(c[0]==0x05) + {printf("lyric text \n");} + if(c[0]==0x06) + {printf("marker text \n");} + if(c[0]==0x07) + {printf("cue point \n");} + if(c[0]==0x20) + {printf("MIDI channel \n");} + if(c[0]==0x2f) + {printf("end of track \n");} + if(c[0]==0x51) + {printf("tempo setting \n");} + if(c[0]==0x54) + {printf("SMPTE offset \n");} + if(c[0]==0x58) + {printf("Time signature \n");} + if(c[0]==0x59) + {printf("Key signature \n");} + if(c[0]==0x7f) + {printf("Sequencer specific event \n");} + int nbre_oct = c[1]; + printf("nbre oc = %d \n",nbre_oct); + int p = 0; + while(p != nbre_oct) + { + p++; + fread(c,1,1,fichier); + } + } + + //sys event inutile, on sarrete donc quand on trouve le marqueur de fin (0xf7) + if((c[0]==0xf0) | (c[0]==0xf1) | (c[0]==0xf2) | (c[0]==0xf3) |(c[0]==0xf4) | (c[0]==0xf5) | (c[0]==0xf6) | (c[0]==0xf7) | (c[0]==0xf8) | (c[0]==0xf9) | (c[0]==0xfa) | (c[0]==0xfb) | (c[0]==0xfc) | (c[0]==0xfd) | (c[0]==0xfe)) + { + unsigned char d; + printf("sys event\n"); + fread(&d,1,1,fichier); + while(d!= 0xf7) + { + fread(&d,1,1,fichier); + + } + } + + //MIDI event + //Note off + if((c[0]==0x80) | (c[0]==0x81) | (c[0]==0x82) | (c[0]==0x83) |(c[0]==0x84) | (c[0]==0x85) | (c[0]==0x86) | (c[0]==0x87) | (c[0]==0x88) | (c[0]==0x89) | (c[0]==0x8a) | (c[0]==0x8b) | (c[0]==0x8c) | (c[0]==0x8d) | (c[0]==0x8e) | (c[0]==0x8f)) + { + fread(c,2,1,fichier); + printf("Note off : %d, intensite : %d\n", c[0], c[1]); + + } + //Note on + if((c[0]==0x90) | (c[0]==0x91) | (c[0]==0x92) | (c[0]==0x93) |(c[0]==0x94) | (c[0]==0x95) | (c[0]==0x96) | (c[0]==0x97) | (c[0]==0x98) | (c[0]==0x99) | (c[0]==0x9a) | (c[0]==0x9b) | (c[0]==0x9c) | (c[0]==0x9d) | (c[0]==0x9e) | (c[0]==0x9f)) + { + fread(c,2,1,fichier); + printf("Note on : %d, intensite : %d\n", c[0], c[1]); + + } + + //aftertouch + if((c[0]==0xa0) | (c[0]==0xa1) | (c[0]==0xa2) | (c[0]==0xa3) |(c[0]==0xa4) | (c[0]==0xa5) | (c[0]==0xa6) | (c[0]==0xa7) | (c[0]==0xa8) | (c[0]==0xa9) | (c[0]==0xaa) | (c[0]==0xab) | (c[0]==0xac) | (c[0]==0xad) | (c[0]==0xae) | (c[0]==0xaf)) + { + fread(c,2,1,fichier); + + } + //Continuous controller + if((c[0]==0xb0) | (c[0]==0xb1) | (c[0]==0xb2) | (c[0]==0xb3) |(c[0]==0xb4) | (c[0]==0xb5) | (c[0]==0xb6) | (c[0]==0xb7) | (c[0]==0xb8) | (c[0]==0xb9) | (c[0]==0xba) | (c[0]==0xbb) | (c[0]==0xbc) | (c[0]==0xbd) | (c[0]==0xbe) | (c[0]==0xbf)) + { + fread(c,2,1,fichier); + + } + //Patch change + if((c[0]==0xc0) | (c[0]==0xc1) | (c[0]==0xc2) | (c[0]==0xc3) |(c[0]==0xc4) | (c[0]==0xc5) | (c[0]==0xc6) | (c[0]==0xc7) | (c[0]==0xc8) | (c[0]==0xc9) | (c[0]==0xca) | (c[0]==0xcb) | (c[0]==0xcc) | (c[0]==0xcd) | (c[0]==0xce) | (c[0]==0xcf)) + { + fread(c,2,1,fichier); + + } + //Channel Pressure + if((c[0]==0xd0) | (c[0]==0xd1) | (c[0]==0xd2) | (c[0]==0xd3) |(c[0]==0xd4) | (c[0]==0xd5) | (c[0]==0xd6) | (c[0]==0xd7) | (c[0]==0xd8) | (c[0]==0xd9) | (c[0]==0xda) | (c[0]==0xdb) | (c[0]==0xdc) | (c[0]==0xdd) | (c[0]==0xde) | (c[0]==0xdf)) + { + fread(c,1,1,fichier); + + } + //Pitch bend + if((c[0]==0xe0) | (c[0]==0xe1) | (c[0]==0xe2) | (c[0]==0xe3) |(c[0]==0xe4) | (c[0]==0xe5) | (c[0]==0xe6) | (c[0]==0xe7) | (c[0]==0xe8) | (c[0]==0xe9) | (c[0]==0xea) | (c[0]==0xeb) | (c[0]==0xec) | (c[0]==0xed) | (c[0]==0xee) | (c[0]==0xef)) + { + fread(c,2,1,fichier); + } + } + + } + else + { + printf("Mauvais format de fichier, prendre du MIDI\n"); + } + + + + + printf("\n"); + return 0; +} -- libgit2 0.21.2