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/file.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 
00035 #ifndef _JDKMIDI_FILE_H
00036 #define _JDKMIDI_FILE_H
00037 
00038 #include "jdkmidi/midi.h"
00039 #include "jdkmidi/msg.h"
00040 #include "jdkmidi/sysex.h"
00041 #include "jdkmidi/tempo.h"
00042 
00043 
00044 namespace jdkmidi
00045 {
00046   
00047 //
00048 // The MIDIFile class contains definitions and utilities to deal with
00049 // reading and writing midi files.
00050 //
00051   
00052   
00053   const unsigned long _MThd=OSTYPE('M','T','h','d');
00054   const unsigned long  _MTrk=OSTYPE('M','T','r','k');
00055   
00056   class  MIDIFile 
00057     {
00058     public:
00059       
00060       MIDIFile();
00061       virtual ~MIDIFile();
00062       
00063       struct MIDIFileChunk
00064       {
00065         unsigned long id;
00066         unsigned long length;
00067       };
00068       
00069       struct MIDIFileHeader
00070       {
00071         short format;
00072         short ntrks;
00073         short division;
00074       };
00075       
00076       //
00077       // define all the different meta event message types.
00078       //
00079       
00080       enum
00081         {
00082           MF_SEQUENCE_NUMBER  =0,
00083           MF_TEXT_EVENT   =1,
00084           MF_COPYRIGHT    =2,
00085           MF_TRACK_NAME   =3,
00086           MF_INSTRUMENT_NAME  =4,
00087           MF_LYRIC    =5,
00088           MF_MARKER   =6,
00089           MF_CUE_POINT    =7,
00090           MF_GENERIC_TEXT_8 =8,
00091           MF_GENERIC_TEXT_9 =9,
00092           MF_GENERIC_TEXT_A =0xA,
00093           MF_GENERIC_TEXT_B =0xB,
00094           MF_GENERIC_TEXT_C =0xC,
00095           MF_GENERIC_TEXT_D =0xD,
00096           MF_GENERIC_TEXT_E =0xE,
00097           MF_GENERIC_TEXT_F =0xF,
00098           
00099           MF_OUTPUT_CABLE   =0x21,
00100           MF_TRACK_LOOP   =0x2E,
00101           MF_END_OF_TRACK   =0x2F,
00102           MF_TEMPO    =0x51,
00103           MF_SMPTE    =0x54,
00104           MF_TIMESIG    =0x58,
00105           MF_KEYSIG   =0x59,
00106           MF_SEQUENCER_SPECIFIC =0x7F
00107         };
00108       
00109       
00110       //
00111       // ConvertTempoToFreq() returns the frequency of the required
00112       // tempo clock
00113       //
00114       
00115       static  unsigned long ConvertTempoToFreq( 
00116         short division,
00117         MIDITempo &tempo 
00118         );
00119       
00120       //
00121       // Convert a four byte number to an unsigned long.
00122       //
00123       
00124       static  unsigned long   To32Bit( unsigned char  a, unsigned char b, unsigned char c, unsigned char d )  
00125         {
00126           return    ((unsigned long)a << 24)
00127             + ((unsigned long)b << 16)
00128             + ((unsigned long)c << 8 )
00129             + ((unsigned long)d << 0 );
00130         } 
00131       
00132       
00133       //
00134       // Convert a two byte number to an unsigned short
00135       //
00136       
00137       static  unsigned short  To16Bit( unsigned char a, unsigned char b ) 
00138         {
00139           return    (unsigned short)(((unsigned short)a << 8)
00140                                            + ((unsigned short)b << 0));
00141         } 
00142       
00143       static  unsigned long ReadVariableLengthNumber( unsigned char **in ); 
00144       
00145       static  unsigned char * WriteVariableLengthNumber( unsigned long num, unsigned char *out );
00146       
00147     }; 
00148   
00149 }
00150 
00151 #endif
00152