home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The CDPD Public Domain Collection for CDTV 4
/
CDPD_IV.bin
/
amfm
/
amfm2
/
utilities
/
mft
/
mftext.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-06-20
|
5KB
|
258 lines
/****************************************
* *
* mftext *
* *
* Convert a MIDI file to verbose text. *
* *
****************************************/
#include <stdio.h>
#include <ctype.h>
#include "midifile.h"
void prtime();
void initfuncs();
static FILE *F;
filegetc()
{
return(getc(F));
}
main(argc,argv)
char **argv;
{
FILE *efopen();
if ( argc > 1 )
F = efopen(argv[1],"r");
else
F = stdin;
initfuncs();
Mf_getc = filegetc;
midifile();
fclose(F);
exit(0);
}
FILE *
efopen(name,mode)
char *name;
char *mode;
{
FILE *f;
extern int errno;
extern char *sys_errlist[];
extern int sys_nerr;
char *errmess;
if ( (f=fopen(name,mode)) == NULL ) {
(void) fprintf(stderr,"*** ERROR *** Cannot open '%s'!\n",name);
if ( errno <= sys_nerr )
errmess = sys_errlist[errno];
else
errmess = "Unknown error!";
(void) fprintf(stderr,"************* Reason: %s\n",errmess);
exit(1);
}
return(f);
}
void error(char *s)
{
fprintf(stderr,"Error: %s\n",s);
}
void txt_header(format,ntrks,division)
{
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)
{
prtime();
printf("Note on, chan=%d pitch=%d vol=%d\n",chan+1,pitch,vol);
}
void txt_noteoff(chan,pitch,vol)
{
prtime();
printf("Note off, chan=%d pitch=%d vol=%d\n",chan+1,pitch,vol);
}
void txt_pressure(chan,pitch,press)
{
prtime();
printf("Pressure, chan=%d pitch=%d press=%d\n",chan+1,pitch,press);
}
void txt_parameter(chan,control,value)
{
prtime();
printf("Parameter, chan=%d c1=%d c2=%d\n",chan+1,control,value);
}
void txt_pitchbend(chan,msb,lsb)
{
prtime();
printf("Pitchbend, chan=%d msb=%d lsb=%d\n",chan+1,msb,lsb);
}
void txt_program(chan,program)
{
prtime();
printf("Program, chan=%d program=%d\n",chan+1,program);
}
void txt_chanpressure(chan,press)
{
prtime();
printf("Channel pressure, chan=%d pressure=%d\n",chan+1,press);
}
void txt_sysex(leng,mess)
char *mess;
{
prtime();
printf("Sysex, leng=%d\n",leng);
}
void txt_metamisc(type,leng,mess)
char *mess;
{
prtime();
printf("Meta event, unrecognized, type=0x%02x leng=%d\n",type,leng);
}
void txt_metaspecial(type,leng,mess)
char *mess;
{
prtime();
printf("Meta event, sequencer-specific, type=0x%02x leng=%d\n",type,leng);
}
void txt_metatext(type,leng,mess)
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++;
printf( (isprint(c)||isspace(c)) ? "%c" : "\\0x%02x" , c);
}
printf(">\n");
}
void txt_metaseq(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)
{
prtime();
printf("Key signature, sharp/flats=%d minor=%d\n",sf,mi);
}
void txt_tempo(tempo)
long tempo;
{
prtime();
printf("Tempo, microseconds-per-MIDI-quarter-note=%d\n",tempo);
}
void 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);
}
void txt_smpte(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 prtime()
{
printf("Time=%ld ",Mf_currtime);
}
void initfuncs()
{
Mf_error = error;
Mf_header = txt_header;
Mf_starttrack = txt_trackstart;
Mf_endtrack = txt_trackend;
Mf_on = txt_noteon;
Mf_off = txt_noteoff;
Mf_pressure = txt_pressure;
Mf_controller = 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_sqspecific = txt_metaspecial;
Mf_text = txt_metatext;
Mf_arbitrary = txt_arbitrary;
}
/* End of File */