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_multitrack.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 #ifdef WIN32
00026 #include <windows.h>
00027 #endif
00028 
00029 #include "jdkmidi/world.h"
00030 #include "jdkmidi/track.h"
00031 #include "jdkmidi/multitrack.h"
00032 #include "jdkmidi/filereadmultitrack.h"
00033 #include "jdkmidi/fileread.h"
00034 #include "jdkmidi/fileshow.h"
00035 
00036 using namespace jdkmidi;
00037 
00038 void DumpMIDITimedBigMessage( MIDITimedBigMessage *msg )
00039 {
00040   if( msg )
00041   {
00042     char msgbuf[1024];
00043     
00044     fprintf( stdout, "%8ld : %s\n", msg->GetTime(), msg->MsgToText(msgbuf) );
00045     if( msg->IsSysEx() )
00046     {
00047       fprintf( stdout, "\tSYSEX length: %d\n", msg->GetSysEx()->GetLength() );
00048     }
00049     
00050   } 
00051   
00052 }
00053 
00054 void DumpMIDITrack( MIDITrack *t )
00055 {
00056   MIDITimedBigMessage *msg;
00057   
00058   for( int i=0; i<t->GetNumEvents(); ++i )
00059   {
00060     msg = t->GetEventAddress( i );
00061     DumpMIDITimedBigMessage( msg );   
00062     
00063   }
00064   
00065 }
00066 
00067 void DumpAllTracks( MIDIMultiTrack *mlt )
00068 {
00069   
00070   fprintf( stdout , "Clocks per beat: %d\n\n", mlt->GetClksPerBeat() );
00071   
00072   for( int i=0; i<mlt->GetNumTracks(); ++i )
00073   {
00074     if( mlt->GetTrack(i)->GetNumEvents() > 0 )
00075     {
00076       fprintf( stdout, "DUMP OF TRACK #%2d:\n", i );
00077       DumpMIDITrack( mlt->GetTrack(i) );
00078       fprintf( stdout, "\n" );
00079     }
00080     
00081   }
00082   
00083 }
00084 
00085 
00086 void DumpMIDIMultiTrack( MIDIMultiTrack *mlt )
00087 {
00088   MIDIMultiTrackIterator i( mlt );
00089   MIDITimedBigMessage *msg;
00090   
00091   fprintf( stdout , "Clocks per beat: %d\n\n", mlt->GetClksPerBeat() );
00092   
00093   i.GoToTime(0);
00094   
00095   do
00096   {
00097     int trk_num;
00098     
00099     if( i.GetCurEvent(&trk_num, &msg ) )
00100     {
00101       fprintf( stdout, "#%2d - ", trk_num );
00102       DumpMIDITimedBigMessage( msg );
00103     }       
00104   } while( i.GoToNextEvent() );
00105   
00106 }
00107 
00108 
00109 
00110 int main( int argc, char **argv )
00111 {
00112   if( argc>1 )
00113   {   
00114     MIDIFileReadStreamFile rs( argv[1] );
00115     MIDIMultiTrack tracks;
00116     MIDIFileReadMultiTrack track_loader( &tracks );
00117     MIDIFileRead reader( &rs, &track_loader );
00118     
00119     reader.Parse();
00120     
00121     DumpMIDIMultiTrack( &tracks );
00122     
00123   }
00124   
00125   return 0;   
00126 }