Commit a7d90708a781fc366cf2037a70f65f45197408a2
1 parent
9517040e
analyse fichier MIDI
Showing
1 changed file
with
205 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,205 @@ |
1 | +#include <stdio.h> | |
2 | +#include <stdlib.h> | |
3 | + | |
4 | +int main(int argc,char *argv[]){ | |
5 | + if(argc<2) exit(EXIT_FAILURE); | |
6 | + char *nom=argv[1]; | |
7 | + FILE *fichier=fopen(nom,"r"); | |
8 | + if(fichier==NULL) exit(EXIT_FAILURE); | |
9 | + unsigned char c[2]; | |
10 | + | |
11 | + | |
12 | + // HEADER | |
13 | + fread(c,2,1,fichier); | |
14 | + if((c[0]==0x4d) && (c[1]==0x54)) | |
15 | + { | |
16 | + fread(c,2,1,fichier); | |
17 | + printf("Fichier MIDI détecté.\n"); | |
18 | + fread(c,2,1,fichier); | |
19 | + | |
20 | + | |
21 | + //longueur header | |
22 | + int longueur=0; | |
23 | + longueur=(c[1] << 16) + (c[0] << 32); | |
24 | + fread(c,2,1,fichier); | |
25 | + longueur=longueur + c[1] + (c[0] << 8); | |
26 | + printf("taille header = %d \n",longueur); | |
27 | + | |
28 | + | |
29 | + //format header | |
30 | + fread(c,2,1,fichier); | |
31 | + if(c[1]==0x00) printf("le format est : single track\n"); | |
32 | + if(c[1]==0x01) printf("le format est : multiple track\n"); | |
33 | + if(c[1]==0x02) printf("le format est : multiple song\n"); | |
34 | + | |
35 | + | |
36 | + //nbre de morceaux | |
37 | + fread(c,2,1,fichier); | |
38 | + int n = 0; | |
39 | + n=c[1] + (c[0] << 8); | |
40 | + printf("le nombre de gros morceaux est : %d \n", n); | |
41 | + | |
42 | + | |
43 | + //nbre ticks/beat | |
44 | + fread(c,2,1,fichier); | |
45 | + int ticks = 0; | |
46 | + ticks = c[1] + (c[0] << 8); | |
47 | + printf("nombre de ticks/beat = %d \n",ticks); | |
48 | + | |
49 | + | |
50 | + //Dans un morceau RECUPERATION DE LA TAILLE DE LA CHANSON à partir du Mrtk | |
51 | + fread(c,2,1,fichier); | |
52 | + int longueur_track =0; | |
53 | + if ((c[0]==0x4d) && (c[1]==0x54)) | |
54 | + { | |
55 | + printf("morceau?\n"); | |
56 | + fread(c,2,1,fichier); | |
57 | + if ((c[0]==0x72) && (c[1]==0x6b)) { printf("oui\n");} | |
58 | + | |
59 | + fread(c,2,1,fichier); | |
60 | + longueur_track = (int)(c[1] << 16) + (int)(c[0] << 32); | |
61 | + fread(c,2,1,fichier); | |
62 | + longueur_track = longueur_track + c[1] + (c[0] << 8); | |
63 | + printf("la longueur du morceau est de : %d octets \n", longueur_track); | |
64 | + } | |
65 | + | |
66 | + //Track event | |
67 | + int fin_track = 0; | |
68 | + while(fin_track < longueur_track) | |
69 | + { | |
70 | + fin_track++; | |
71 | + //recup timing | |
72 | + fread(c,1,1,fichier); | |
73 | + int time= c[0]; | |
74 | + if(c[0]>128) | |
75 | + { | |
76 | + unsigned char k; | |
77 | + fread(&k,1,1,fichier); | |
78 | + time = ((c[0]&0x0F)<<8) + k; | |
79 | + printf("moment evenement : %d\n",time); | |
80 | + } | |
81 | + printf("moment evenement : %d\n",time); | |
82 | + | |
83 | + | |
84 | + //QUEL TYPE EVENEMENT | |
85 | + fread(c,1,1,fichier); | |
86 | + | |
87 | + | |
88 | + | |
89 | + //meta evevenemnt | |
90 | + if (c[0]==0xff) | |
91 | + { | |
92 | + printf("meta evenement : \n"); | |
93 | + fread(c,2,1,fichier); | |
94 | + if(c[0]==0x00) | |
95 | + {printf("le numéro de la sequence est: \n");} | |
96 | + if(c[0]==0x01) | |
97 | + {printf("evenement text \n");} | |
98 | + if(c[0]==0x02) | |
99 | + {printf("copyright notice\n");} | |
100 | + if(c[0]==0x03) | |
101 | + {printf("sequence or track name \n");} | |
102 | + if(c[0]==0x04) | |
103 | + {printf("instrument name \n");} | |
104 | + if(c[0]==0x05) | |
105 | + {printf("lyric text \n");} | |
106 | + if(c[0]==0x06) | |
107 | + {printf("marker text \n");} | |
108 | + if(c[0]==0x07) | |
109 | + {printf("cue point \n");} | |
110 | + if(c[0]==0x20) | |
111 | + {printf("MIDI channel \n");} | |
112 | + if(c[0]==0x2f) | |
113 | + {printf("end of track \n");} | |
114 | + if(c[0]==0x51) | |
115 | + {printf("tempo setting \n");} | |
116 | + if(c[0]==0x54) | |
117 | + {printf("SMPTE offset \n");} | |
118 | + if(c[0]==0x58) | |
119 | + {printf("Time signature \n");} | |
120 | + if(c[0]==0x59) | |
121 | + {printf("Key signature \n");} | |
122 | + if(c[0]==0x7f) | |
123 | + {printf("Sequencer specific event \n");} | |
124 | + int nbre_oct = c[1]; | |
125 | + printf("nbre oc = %d \n",nbre_oct); | |
126 | + int p = 0; | |
127 | + while(p != nbre_oct) | |
128 | + { | |
129 | + p++; | |
130 | + fread(c,1,1,fichier); | |
131 | + } | |
132 | + } | |
133 | + | |
134 | + //sys event inutile, on sarrete donc quand on trouve le marqueur de fin (0xf7) | |
135 | + 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)) | |
136 | + { | |
137 | + unsigned char d; | |
138 | + printf("sys event\n"); | |
139 | + fread(&d,1,1,fichier); | |
140 | + while(d!= 0xf7) | |
141 | + { | |
142 | + fread(&d,1,1,fichier); | |
143 | + | |
144 | + } | |
145 | + } | |
146 | + | |
147 | + //MIDI event | |
148 | + //Note off | |
149 | + 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)) | |
150 | + { | |
151 | + fread(c,2,1,fichier); | |
152 | + printf("Note off : %d, intensite : %d\n", c[0], c[1]); | |
153 | + | |
154 | + } | |
155 | + //Note on | |
156 | + 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)) | |
157 | + { | |
158 | + fread(c,2,1,fichier); | |
159 | + printf("Note on : %d, intensite : %d\n", c[0], c[1]); | |
160 | + | |
161 | + } | |
162 | + | |
163 | + //aftertouch | |
164 | + 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)) | |
165 | + { | |
166 | + fread(c,2,1,fichier); | |
167 | + | |
168 | + } | |
169 | + //Continuous controller | |
170 | + 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)) | |
171 | + { | |
172 | + fread(c,2,1,fichier); | |
173 | + | |
174 | + } | |
175 | + //Patch change | |
176 | + 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)) | |
177 | + { | |
178 | + fread(c,2,1,fichier); | |
179 | + | |
180 | + } | |
181 | + //Channel Pressure | |
182 | + 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)) | |
183 | + { | |
184 | + fread(c,1,1,fichier); | |
185 | + | |
186 | + } | |
187 | + //Pitch bend | |
188 | + 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)) | |
189 | + { | |
190 | + fread(c,2,1,fichier); | |
191 | + } | |
192 | + } | |
193 | + | |
194 | + } | |
195 | + else | |
196 | + { | |
197 | + printf("Mauvais format de fichier, prendre du MIDI\n"); | |
198 | + } | |
199 | + | |
200 | + | |
201 | + | |
202 | + | |
203 | + printf("\n"); | |
204 | + return 0; | |
205 | +} | ... | ... |