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

src/jdkmidi_file.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 **  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 #include "jdkmidi/world.h"
00035 
00036 #include "jdkmidi/file.h"
00037 
00038 #if DEBUG_MDFILE
00039 # undef DBG
00040 # define DBG(a) a
00041 #endif
00042 
00043 namespace jdkmidi
00044 {
00045   
00046   
00047   MIDIFile::MIDIFile()  
00048   {
00049   } 
00050   
00051   MIDIFile::~MIDIFile() 
00052   {
00053   } 
00054   
00055   unsigned long MIDIFile::ConvertTempoToFreq(
00056     short division,
00057     MIDITempo &tempo
00058     ) 
00059   {
00060     if( division>0 )
00061     {
00062       long clocks_per_beat = (long)division*1000;
00063       long micro_sec_per_beat = tempo.GetMIDIFileTempo()/1000;
00064       
00065       return (unsigned long) clocks_per_beat/micro_sec_per_beat;
00066     }
00067     else
00068     {
00069       // TO DO: handle smpte frame rate references
00070       return 120;
00071     }
00072   } 
00073   
00074   
00075   unsigned long MIDIFile::ReadVariableLengthNumber( unsigned char **in )  
00076   {
00077     unsigned long num=0;
00078     unsigned char *t=*in;
00079     
00080     do
00081     {
00082       num <<= 7;
00083       num |= (*t);
00084     } while( (*t++)&0x80 );
00085     
00086     *in=t;
00087     return num;
00088   } 
00089   
00090   unsigned char * MIDIFile::WriteVariableLengthNumber( unsigned long num, unsigned char *out )  
00091   {
00092     register unsigned long buffer;
00093     
00094     buffer = num & 0x7f;
00095     while( (num >>=7 )>0 )
00096     {
00097       buffer <<= 8;
00098       buffer |=0x80;
00099       buffer += (num & 0x7f);
00100     }
00101     
00102     do
00103     {
00104       *out++ = (unsigned char)buffer;
00105       if( buffer & 0x80 )
00106         buffer >>=8;
00107       else
00108         break;            
00109     } while( true );
00110     
00111     return out;
00112   } 
00113   
00114 }