home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 8 Other
/
08-Other.zip
/
midifos2.zip
/
MFTEXT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-14
|
5KB
|
260 lines
/*
* mftext
*
* Convert a MIDI file to verbose text.
*/
#include <stdio.h>
#include <ctype.h>
#include <os2.h>
#include "midifile.h"
static FILE *F;
VOID prtime(VOID);
VOID initfuncs(VOID);
int filegetc(VOID)
{
return(getc(F));
}
main(int argc, 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(char *name, char *mode)
{
FILE *f;
extern int errno;
#ifdef OS2
CHAR buf[1024];
ULONG cbBuf;
#else
extern char *sys_errlist[];
extern int sys_nerr;
char *errmess;
#endif
if ( (f=fopen(name,mode)) == NULL )
{
#ifdef OS2
if (DosGetMessage(NULL, 0, buf, 1024, errno, "oso001.msg", &cbBuf))
fprintf(stderr, "SYS%04d: error text unavailable\n", errno);
else
{
buf[cbBuf] = (char)0;
fprintf(stderr,"%s\n",buf);
}
#else
fprintf(stderr,"*** ERROR *** Cannot open '%s'!\n",name);
if ( errno <= sys_nerr )
errmess = sys_errlist[errno];
else
errmess = "Unknown error!";
fprintf(stderr,"************* Reason: %s\n",errmess);
#endif
exit(1);
}
return(f);
}
VOID error(char *s)
{
fprintf(stderr,"Error: %s\n",s);
}
VOID txt_header(int format, int ntrks, int division)
{
printf("Header format=%d ntrks=%d division=%d\n",format,ntrks,division);
}
VOID txt_trackstart(VOID)
{
printf("Track start\n");
}
VOID txt_trackend(VOID)
{
printf("Track end\n");
}
VOID txt_noteon(int chan, int pitch, int vol)
{
prtime();
printf("Note on, chan=%d pitch=%d vol=%d\n",chan+1,pitch,vol);
}
VOID txt_noteoff(int chan, int pitch, int vol)
{
prtime();
printf("Note off, chan=%d pitch=%d vol=%d\n",chan+1,pitch,vol);
}
VOID txt_pressure(int chan, int pitch,int press)
{
prtime();
printf("Pressure, chan=%d pitch=%d press=%d\n",chan+1,pitch,press);
}
VOID txt_parameter(int chan, int control, int value)
{
prtime();
printf("Parameter, chan=%d c1=%d c2=%d\n",chan+1,control,value);
}
VOID txt_pitchbend(int chan, int msb, int lsb)
{
prtime();
printf("Pitchbend, chan=%d msb=%d lsb=%d\n",chan+1,msb,lsb);
}
VOID txt_program(int chan, int program)
{
prtime();
printf("Program, chan=%d program=%d\n",chan+1,program);
}
VOID txt_chanpressure(int chan, int press)
{
prtime();
printf("Channel pressure, chan=%d pressure=%d\n",chan+1,press);
}
VOID txt_sysex(int leng, char *mess)
{
prtime();
printf("Sysex, leng=%d\n",leng);
}
VOID txt_metamisc(int type, int leng, char *mess)
{
prtime();
printf("Meta event, unrecognized, type=0x%02x leng=%d\n",type,leng);
}
VOID txt_metaspecial(int type, char *mess)
{
prtime();
printf("Meta event, sequencer-specific, type=0x%02x",type);
}
VOID txt_metatext(int type, int 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;
int n, c;
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(int num)
{
prtime();
printf("Meta event, sequence number = %d\n",num);
}
VOID txt_metaeot(VOID)
{
prtime();
printf("Meta event, end of track\n");
}
VOID txt_keysig(int sf, int mi)
{
prtime();
printf("Key signature, sharp/flats=%d minor=%d\n",sf,mi);
}
VOID txt_tempo(int tempo)
{
prtime();
printf("Tempo, microseconds-per-MIDI-quarter-note=%d\n",tempo);
}
VOID txt_timesig(int nn, int dd, int cc, int 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(int hr, int mn, int se, int fr, int ff)
{
prtime();
printf("SMPTE, hour=%d minute=%d second=%d frame=%d fract-frame=%d\n",
hr,mn,se,fr,ff);
}
VOID txt_arbitrary(int leng,char *mess)
{
prtime();
printf("Arbitrary bytes, leng=%d\n",leng);
}
VOID prtime(VOID)
{
printf("Time=%ld ",Mf_currtime);
}
VOID initfuncs(VOID)
{
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;
}