-
Notifications
You must be signed in to change notification settings - Fork 15
/
mftext.c
288 lines (250 loc) · 5.55 KB
/
mftext.c
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
* mftext
*
* Convert a MIDI file to verbose text.
*
* modified for portability 22/6/98 - error checking on file open failure
* removed.
*/
#include <stdio.h>
#include <stdlib.h>
#ifdef ANSILIBS
#include <ctype.h>
#endif
#include "midifile.h"
void initfuncs();
void midifile();
static FILE *F;
int SECONDS; /* global that tells whether to display seconds or ticks */
int division; /* from the file header */
long tempo = 500000; /* the default tempo is 120 beats/minute */
int filegetc()
{
return(getc(F));
}
/* for crack */
extern int arg_index;
int main(argc,argv)
char **argv;
{
FILE *efopen();
char *ch;
char *crack();
SECONDS = 0;
while((ch = crack(argc,argv,"s",0)) != NULL){
switch(*ch){
case 's' : SECONDS = 1; break;
}
}
if ((argc < 2 && !SECONDS) || (argc < 3 && SECONDS))
F = stdin;
else
F = efopen(argv[arg_index],"rb");
initfuncs();
Mf_getc = filegetc;
midifile();
fclose(F);
exit(0);
}
FILE *
efopen(name,mode)
char *name;
char *mode;
{
FILE *f;
if ( (f=fopen(name,mode)) == NULL ) {
fprintf(stderr,"Error - Cannot open file %s\n",name);
exit(0);
}
return(f);
}
void error(s)
char *s;
{
fprintf(stderr,"Error: %s\n",s);
}
void prtime()
{
if(SECONDS)
printf("Time=%f ",mf_ticks2sec(Mf_currtime,division,tempo));
else
printf("Time=%ld ",Mf_currtime);
}
void txt_header(format,ntrks,ldivision)
int format, ntrks, ldivision;
{
division = ldivision;
printf("Header format=%d ntrks=%d division=%d\n",format,ntrks,division);
}
void txt_trackstart()
{
printf("Track start\n");
}
void txt_trackend()
{
printf("Track end\n");
}
void txt_noteon(chan,pitch,vol)
int chan, pitch, vol;
{
prtime();
printf("Note on, chan=%d pitch=%d vol=%d\n",chan+1,pitch,vol);
}
void txt_noteoff(chan,pitch,vol)
int chan, pitch, vol;
{
prtime();
printf("Note off, chan=%d pitch=%d vol=%d\n",chan+1,pitch,vol);
}
void txt_pressure(chan,pitch,press)
int chan, pitch,press;
{
prtime();
printf("Pressure, chan=%d pitch=%d press=%d\n",chan+1,pitch,press);
}
void txt_parameter(chan,control,value)
int chan, control, value;
{
prtime();
printf("Parameter, chan=%d c1=%d c2=%d\n",chan+1,control,value);
}
void txt_pitchbend(chan,msb,lsb)
int chan, msb, lsb;
{
prtime();
printf("Pitchbend, chan=%d msb=%d lsb=%d\n",chan+1,msb,lsb);
}
void txt_program(chan,program)
int chan, program;
{
prtime();
printf("Program, chan=%d program=%d\n",chan+1,program);
}
void txt_chanpressure(chan,press)
int chan, press;
{
prtime();
printf("Channel pressure, chan=%d pressure=%d\n",chan+1,press);
}
void txt_sysex(leng,mess)
int leng;
char *mess;
{
prtime();
printf("Sysex, leng=%d\n",leng);
}
void txt_metamisc(type,leng,mess)
int type, leng;
char *mess;
{
prtime();
printf("Meta event, unrecognized, type=0x%02x leng=%d\n",type,leng);
}
void txt_metaspecial(type,leng,mess)
int type, leng;
char *mess;
{
prtime();
printf("Meta event, sequencer-specific, type=0x%02x leng=%d\n",type,leng);
}
void txt_metatext(type,leng,mess)
int type, leng;
char *mess;
{
static char *ttype[] = {
NULL,
"Text Event", /* type=0x01 */
"Copyright Notice", /* type=0x02 */
"Sequence/Track Name",
"Instrument Name", /* ... */
"Lyric",
"Marker",
"Cue Point", /* type=0x07 */
"Unrecognized"
};
int unrecognized = (sizeof(ttype)/sizeof(char *)) - 1;
register int n, c;
register char *p = mess;
if ( type < 1 || type > unrecognized )
type = unrecognized;
prtime();
printf("Meta Text, type=0x%02x (%s) leng=%d\n",type,ttype[type],leng);
printf(" Text = <");
for ( n=0; n<leng; n++ ) {
c = (*p++) & 0xff;
printf( (isprint(c)||isspace(c)) ? "%c" : "\\0x%02x" , c);
}
printf(">\n");
}
void txt_metaseq(num)
int num;
{
prtime();
printf("Meta event, sequence number = %d\n",num);
}
void txt_metaeot()
{
prtime();
printf("Meta event, end of track\n");
}
void txt_keysig(sf,mi)
int sf,mi;
{
prtime();
printf("Key signature, sharp/flats=%d minor=%d\n",sf,mi);
}
void txt_tempo(ltempo)
long ltempo;
{
tempo = ltempo;
prtime();
printf("Tempo, microseconds-per-MIDI-quarter-note=%ld\n",tempo);
}
void txt_timesig(nn,dd,cc,bb)
int nn, dd, cc, bb;
{
int denom = 1;
while ( dd-- > 0 )
denom *= 2;
prtime();
printf("Time signature=%d/%d MIDI-clocks/click=%d 32nd-notes/24-MIDI-clocks=%d\n",
nn,denom,cc,bb);
}
void txt_smpte(hr,mn,se,fr,ff)
int hr, mn, se, fr, ff;
{
prtime();
printf("SMPTE, hour=%d minute=%d second=%d frame=%d fract-frame=%d\n",
hr,mn,se,fr,ff);
}
void txt_arbitrary(leng,mess)
char *mess;
{
prtime();
printf("Arbitrary bytes, leng=%d\n",leng);
}
void initfuncs()
{
Mf_error = error;
Mf_header = txt_header;
Mf_trackstart = txt_trackstart;
Mf_trackend = txt_trackend;
Mf_noteon = txt_noteon;
Mf_noteoff = txt_noteoff;
Mf_pressure = txt_pressure;
Mf_parameter = txt_parameter;
Mf_pitchbend = txt_pitchbend;
Mf_program = txt_program;
Mf_chanpressure = txt_chanpressure;
Mf_sysex = txt_sysex;
Mf_metamisc = txt_metamisc;
Mf_seqnum = txt_metaseq;
Mf_eot = txt_metaeot;
Mf_timesig = txt_timesig;
Mf_smpte = txt_smpte;
Mf_tempo = txt_tempo;
Mf_keysig = txt_keysig;
Mf_seqspecific = txt_metaspecial;
Mf_text = txt_metatext;
Mf_arbitrary = txt_arbitrary;
}