add #include #include #include "midifile.h" static FILE *F; int division; /* from the file header */ long tempo = 500000; /* the default tempo is 120 beats/minute */ filegetc() { return(getc(F)); } main(int argc,char **argv) { char ch; if(argc > 1) { if(F = fopen(argv[1],"r")) { initfuncs(); Mf_getc = filegetc; midifile(); fclose(F); } else printf("Error reading midi file!\n"); } } error(char *s) { fprintf(stderr,"Error: %s\n",s); } txt_header(format,ntrks,ldivision) { division = ldivision; printf("Header format=%d ntrks=%d division=%d\n",format,ntrks,division); } txt_trackstart() { printf("Track start\n"); } txt_trackend() { printf("Track end\n"); } txt_noteon(chan,pitch,vol) { prtime(); printf("Note on, chan=%d pitch=%d vol=%d\n",chan+1,pitch,vol); } txt_noteoff(chan,pitch,vol) { prtime(); printf("Note off, chan=%d pitch=%d vol=%d\n",chan+1,pitch,vol); } txt_pressure(chan,pitch,press) { } txt_parameter(chan,control,value) { } txt_pitchbend(chan,msb,lsb) { } txt_program(chan,program) { prtime(); printf("Program, chan=%d program=%d\n",chan+1,program); } txt_chanpressure(chan,press) { } txt_sysex(leng,mess) char *mess; { } txt_metamisc(type,leng,mess) char *mess; { } txt_metaspecial(type,leng,mess) char *mess; { } txt_metatext(type,leng,mess) char *mess; { } txt_metaseq(num) { } txt_metaeot() { prtime(); printf("Meta event, end of track\n"); } txt_keysig(sf,mi) { } txt_tempo(ltempo) long ltempo; { tempo = ltempo; prtime(); printf("Tempo, microseconds-per-MIDI-quarter-note=%ld\n",tempo); } txt_timesig(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); } txt_smpte(hr,mn,se,fr,ff) { } txt_arbitrary(leng,mess) char *mess; { } prtime() { printf("Time=%f ",mf_ticks2sec(Mf_currtime,division,tempo)); } 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; } . 0