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

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 #include "jdkmidi/filewritemultitrack.h"
00036 
00037 int main( int argc, char **argv )
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 }