00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "jdkmidi/world.h"
00026 #include "jdkmidi/midi.h"
00027 #include "jdkmidi/msg.h"
00028 #include "jdkmidi/sysex.h"
00029 #include "jdkmidi/parser.h"
00030
00031 using namespace jdkmidi;
00032
00033
00034 void PrintSysEx( FILE *f, MIDISystemExclusive *ex )
00035 {
00036 int l = ex->GetLength();
00037
00038 fprintf( f, "Sysex Len=%d", l );
00039
00040 for( int i=0; i<l; ++i )
00041 {
00042 if( ((i)%20) == 0 )
00043 {
00044 fprintf( f, "\n" );
00045 }
00046 fprintf( f, "%02x ", (int)ex->GetData( i ) );
00047 }
00048 fprintf( f, "\n" );
00049 fflush(f);
00050 }
00051
00052
00053 void PrintMsg( FILE *f, MIDIMessage *m )
00054 {
00055 int l = m->GetLength();
00056
00057 fprintf( f, "Msg : " );
00058
00059 if( l==1 )
00060 {
00061 fprintf( f, " %02x \t=", m->GetStatus() );
00062 }
00063 else if( l==2 )
00064 {
00065 fprintf( f, " %02x %02x \t=", m->GetStatus(), m->GetByte1() );
00066 }
00067 else if( l==3 )
00068 {
00069 fprintf( f, " %02x %02x %02x \t=", m->GetStatus(), m->GetByte1(), m->GetByte2() );
00070 }
00071
00072 char buf[129];
00073
00074 m->MsgToText( buf );
00075
00076 fprintf( f, "%s\n", buf );
00077 fflush(f);
00078 }
00079
00080
00081 int main( int argc, char ** argv )
00082 {
00083 fprintf( stdout, "mdparse:\n" );
00084
00085 MIDIParser p(32*1024);
00086 MIDIMessage m;
00087 FILE *f = stdin;
00088
00089 while( !feof(f) )
00090 {
00091 int c = fgetc(f);
00092
00093 if( c==EOF )
00094 break;
00095
00096 if( p.Parse( (uchar)c, &m ) )
00097 {
00098 if( m.IsSysEx() )
00099 {
00100 PrintSysEx( stdout, p.GetSystemExclusive() );
00101 }
00102 else
00103 {
00104 PrintMsg( stdout, &m );
00105 }
00106 }
00107 }
00108
00109 return 0;
00110 }
00111