jdkmidi class library documentation

Copyright © 2004 J.D. Koftinoff Software, Ltd.

Released under the GNU General Public License (GPL)




Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

tests/jdkmidi_test_parse.cpp

Go to the documentation of this file.
00001 /*
00002  *  libjdkmidi-2004 C++ Class Library for MIDI
00003  *
00004  *  Copyright (C) 2004  J.D. Koftinoff Software, Ltd.
00005  *  www.jdkoftinoff.com
00006  *  jeffk@jdkoftinoff.com
00007  *
00008  *  *** RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE (GPL) April 27, 2004 ***
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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