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

include/jdkmidi/fileread.h

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 **  Copyright 1986 to 1998 By J.D. Koftinoff Software, Ltd.
00026 **
00027 **  All rights reserved.
00028 **
00029 **  No one may duplicate this source code in any form for any reason
00030 **  without the written permission given by J.D. Koftinoff Software, Ltd.
00031 **
00032 */
00033 
00034 #ifndef _JDKMIDI_FILEREAD_H
00035 #define _JDKMIDI_FILEREAD_H
00036 
00037 #include "jdkmidi/midi.h"
00038 #include "jdkmidi/msg.h"
00039 #include "jdkmidi/sysex.h"
00040 #include "jdkmidi/file.h"
00041 
00042 namespace jdkmidi
00043 {
00044   class MIDIFileReadStream;
00045   class MIDIFileReadStreamFile;
00046   class MIDIFileEvents;
00047   class MIDIFileRead;
00048   
00049   
00050   class MIDIFileReadStream  
00051     {
00052     public:
00053       MIDIFileReadStream()
00054         {
00055         }
00056       
00057       virtual ~MIDIFileReadStream()
00058         {
00059         }
00060       
00061       virtual int ReadChar() = 0;
00062     }; 
00063   
00064   class MIDIFileReadStreamFile : public MIDIFileReadStream  
00065     {
00066     public: 
00067       explicit MIDIFileReadStreamFile( const char *fname )  
00068         {
00069           f=fopen( fname, "rb" );
00070         } 
00071       
00072       explicit MIDIFileReadStreamFile( FILE *f_ ) : f(f_) 
00073         {
00074         } 
00075       
00076       virtual ~MIDIFileReadStreamFile() 
00077         {
00078           if( f )
00079           { 
00080             fclose(f);
00081           }
00082           
00083         } 
00084       
00085       
00086       virtual int ReadChar()  
00087         {
00088           int r=-1;
00089           
00090           if( f && !feof(f) && !ferror(f) )
00091           { 
00092             r=fgetc(f);
00093           }
00094           
00095           return r;
00096         } 
00097       
00098       
00099     private:
00100       FILE *f;
00101     }; 
00102   
00103   class MIDIFileEvents : protected MIDIFile 
00104     {
00105     public:
00106       MIDIFileEvents()
00107         {
00108         }
00109       
00110       virtual ~MIDIFileEvents()
00111         {
00112         }
00113       
00114       
00115 //
00116 // The possible events in a MIDI Files
00117 //
00118       
00119       virtual void    mf_system_mode( const MIDITimedMessage &msg );
00120       virtual void    mf_note_on( const MIDITimedMessage &msg );
00121       virtual void    mf_note_off( const  MIDITimedMessage &msg );
00122       virtual void    mf_poly_after( const MIDITimedMessage &msg );
00123       virtual void    mf_bender( const MIDITimedMessage &msg );
00124       virtual void    mf_program( const MIDITimedMessage &msg );
00125       virtual void    mf_chan_after( const MIDITimedMessage &msg );
00126       virtual void    mf_control( const MIDITimedMessage &msg );
00127       virtual void    mf_sysex( MIDIClockTime time, const MIDISystemExclusive &ex );
00128       
00129       virtual void    mf_arbitrary( MIDIClockTime time, int len, unsigned char *data );
00130       virtual void    mf_metamisc( MIDIClockTime time, int, int, unsigned char *  );
00131       virtual void    mf_seqnum( MIDIClockTime time, int );
00132       virtual void    mf_smpte( MIDIClockTime time, int, int, int, int, int );
00133       virtual void    mf_timesig( MIDIClockTime time, int, int, int, int );
00134       virtual void    mf_tempo( MIDIClockTime time, unsigned long tempo );
00135       virtual void    mf_keysig(MIDIClockTime time, int, int );
00136       virtual void    mf_sqspecific( MIDIClockTime time, int, unsigned char * );
00137       virtual void    mf_text( MIDIClockTime time, int, int, unsigned char * );
00138       virtual void    mf_eot( MIDIClockTime time );
00139       
00140 //
00141 // the following methods are to be overridden for your specific purpose
00142 //
00143       
00144       virtual void    mf_error( char * );
00145       
00146       virtual void    mf_starttrack( int trk );
00147       virtual void    mf_endtrack( int trk );
00148       virtual void    mf_header( int, int, int );
00149       
00150 //
00151 // Higher level dispatch functions
00152 // 
00153       virtual void  UpdateTime( MIDIClockTime delta_time );
00154       virtual void    MetaEvent( MIDIClockTime time, int type, int len, unsigned char *buf );
00155       virtual void    ChanMessage( const MIDITimedMessage &msg );
00156       
00157     }; 
00158   
00159   class MIDIFileRead : protected MIDIFile 
00160     {
00161     public:
00162       
00163       MIDIFileRead(
00164         MIDIFileReadStream *input_stream_,
00165         MIDIFileEvents *event_handler_,
00166         unsigned long max_msg_len=8192 
00167         );
00168       virtual         ~MIDIFileRead();
00169       
00170       virtual bool    Parse();
00171       
00172       int   GetFormat()     { return header_format;   }
00173       int   GetNumberTracks()   { return header_ntrks;    }
00174       int   GetDivision()   { return header_division; }
00175       
00176     protected:
00177       
00178       virtual int  ReadHeader();
00179       
00180       virtual void    mf_error( char * );
00181       
00182     protected:
00183       int  no_merge;
00184       MIDIClockTime   cur_time;
00185       int  skip_init;
00186       unsigned long   to_be_read;
00187       int   cur_track;
00188       int   abort_parse;
00189       
00190       unsigned char   *the_msg;
00191       int   max_msg_len;
00192       int     msg_index;
00193       
00194     private:
00195       unsigned long   ReadVariableNum();
00196       unsigned long   Read32Bit();
00197       int   Read16Bit();
00198       
00199       void    ReadTrack();
00200       
00201       void    MsgAdd( int );
00202       void    MsgInit();
00203       
00204       int   EGetC();
00205       
00206       int   ReadMT( unsigned long, int );
00207       void    BadByte( int );
00208       
00209       void  FormChanMessage( unsigned char st, unsigned char b1, unsigned char b2 );
00210       
00211       
00212       int   header_format;
00213       int   header_ntrks;
00214       int   header_division;
00215       
00216       MIDIFileReadStream *input_stream;
00217       MIDIFileEvents *event_handler;
00218     }; 
00219 }
00220 
00221 #endif
00222