Blame view

ana_midi.c 7.58 KB
a7d90708   aarnaude   analyse fichier MIDI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
  #include <stdio.h>
  #include <stdlib.h>
  
  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;
  }