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