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_rewrite_midifile.cpp File Reference

#include "jdkmidi/world.h"
#include "jdkmidi/track.h"
#include "jdkmidi/multitrack.h"
#include "jdkmidi/filereadmultitrack.h"
#include "jdkmidi/fileread.h"
#include "jdkmidi/fileshow.h"
#include "jdkmidi/filewritemultitrack.h"

Go to the source code of this file.

Functions

int main (int argc, char **argv)


Function Documentation

int main int  argc,
char **  argv
 

Definition at line 37 of file jdkmidi_rewrite_midifile.cpp.

References jdkmidi::MIDIFileRead::GetDivision(), jdkmidi::MIDIFileRead::GetNumberTracks(), jdkmidi::MIDIFileWriteStreamFileName::IsValid(), jdkmidi::MIDIFileRead::Parse(), and jdkmidi::MIDIFileWriteMultiTrack::Write().

00038 {
00039   int return_code=-1;
00040   if( argc>2 )
00041   {   
00042     const char *infile_name = argv[1];
00043     const char *outfile_name = argv[2];
00044     
00045     // the stream used to read the input file
00046     jdkmidi::MIDIFileReadStreamFile rs( infile_name );
00047 
00048     // the object which will hold all the tracks
00049     jdkmidi::MIDIMultiTrack tracks;
00050 
00051     // the object which loads the tracks into the tracks object
00052     jdkmidi::MIDIFileReadMultiTrack track_loader( &tracks );
00053 
00054     // the object which parses the midifile and gives it to the multitrack loader
00055     jdkmidi::MIDIFileRead reader( &rs, &track_loader );
00056  
00057     // load the midifile into the multitrack object
00058     reader.Parse();
00059     
00060     // create the output stream
00061     jdkmidi::MIDIFileWriteStreamFileName out_stream( outfile_name );
00062     
00063     if( out_stream.IsValid() )
00064     {
00065       // the object which takes the midi tracks and writes the midifile to the output stream
00066       jdkmidi::MIDIFileWriteMultiTrack writer(
00067         &tracks,
00068         &out_stream
00069         );
00070 
00071       // extract the original multitrack division and number of tracks
00072       
00073       int num_tracks = reader.GetNumberTracks();
00074       int division = reader.GetDivision();
00075 
00076       // write the output file
00077       if( writer.Write( num_tracks, division ) )
00078       {
00079         return_code = 0;
00080       }
00081       else
00082       {
00083         fprintf( stderr, "Error writing file '%s'\n", outfile_name );
00084       }
00085     }
00086     else
00087     {
00088       fprintf( stderr, "Error opening file '%s'\n", outfile_name );
00089     }
00090   }
00091   else
00092   {
00093     fprintf( stderr, "usage:\n\tjdkmidi_rewrite_midifile INFILE.mid OUTFILE.mid\n" );
00094   }
00095   
00096   return return_code; 
00097 }