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_TEMPO_H 00035 #define _JDKMIDI_TEMPO_H 00036 00037 // 00038 // This class makes it easy to deal with Tempos as fixed point 00039 // numbers. 00040 // 00041 // The actual tempo is stored times 256 for 1/256 bpm accuracy. 00042 // 00043 // The default operator int() etc., automatically convert the 00044 // fixed point number so the value is in normal beats per minutes. 00045 // 00046 // 00047 00048 #include "jdkmidi/midi.h" 00049 00050 namespace jdkmidi 00051 { 00052 00053 class MIDITempo 00054 { 00055 public: 00056 MIDITempo() 00057 { 00058 tempo=120<<8; 00059 } 00060 MIDITempo( int a ) 00061 { 00062 tempo=(unsigned long)a << 8; 00063 } 00064 MIDITempo( unsigned int a ) 00065 { 00066 tempo=(unsigned long)a << 8; 00067 } 00068 MIDITempo( long a ) 00069 { 00070 tempo=(unsigned long)a << 8; 00071 } 00072 MIDITempo( unsigned long a ) 00073 { 00074 tempo=a << 8; 00075 } 00076 MIDITempo( float a ) 00077 { 00078 tempo=(unsigned long) (a*256.0); 00079 } 00080 MIDITempo( const MIDITempo &a ) 00081 { 00082 tempo=a.GetFullTempo(); 00083 } 00084 00085 operator short () 00086 { 00087 return (short)((tempo+0x80)>>8); 00088 } 00089 operator unsigned short () 00090 { 00091 return (unsigned short)((tempo+0x80)>>8); 00092 } 00093 00094 operator int () 00095 { 00096 return (int)((tempo+0x80)>>8); 00097 } 00098 operator unsigned int () 00099 { 00100 return (unsigned int)((tempo+0x80)>>8); 00101 } 00102 operator long () 00103 { 00104 return (long)((tempo+0x80)>>8); 00105 } 00106 operator unsigned long () 00107 { 00108 return (unsigned long)((tempo+0x80)>>8); 00109 } 00110 operator float () 00111 { 00112 return (float)tempo / 256.0f; 00113 } 00114 void operator = (unsigned short a ) 00115 { 00116 tempo=(unsigned long)a << 8; 00117 } 00118 void operator = (short a ) 00119 { 00120 tempo=(unsigned long)a << 8; 00121 } 00122 00123 void operator = (unsigned int a ) 00124 { 00125 tempo=(unsigned long)a << 8; 00126 } 00127 void operator = (int a ) 00128 { 00129 tempo=(unsigned long)a << 8; 00130 } 00131 void operator = (unsigned long a ) 00132 { 00133 tempo=(unsigned long)a << 8; 00134 } 00135 void operator = (long a ) 00136 { 00137 tempo=(unsigned long)a << 8; 00138 } 00139 00140 void operator = (float a ) 00141 { 00142 tempo=(unsigned long)(a*256.0); 00143 } 00144 00145 unsigned long GetFullTempo() const 00146 { 00147 return tempo; 00148 } 00149 void SetFullTempo( unsigned long v ) 00150 { 00151 tempo=v; 00152 } 00153 00154 unsigned long GetMIDIFileTempo() 00155 { 00156 if(tempo) return (60000000L/256)/tempo; 00157 else 00158 return (60000000L/256)/(120*256); 00159 } 00160 00161 protected: 00162 unsigned long tempo; 00163 }; 00164 00165 } 00166 00167 #endif 00168 00169