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/smpte.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_SMPTE_H
00035 #define _JDKMIDI_SMPTE_H
00036 
00037 namespace jdkmidi
00038 {
00039   
00040   enum SMPTE_RATE
00041     {
00042       SMPTE_RATE_24=0,
00043       SMPTE_RATE_25,
00044       SMPTE_RATE_2997,
00045       SMPTE_RATE_2997DF,
00046       SMPTE_RATE_30,
00047       SMPTE_RATE_30DF
00048     };
00049   
00050   
00051   
00052   enum SAMPLE_RATE
00053     {
00054       SAMPLE_32000=0,
00055       SAMPLE_44056,
00056       SAMPLE_44100,
00057       SAMPLE_47952,
00058       SAMPLE_48000,
00059       SAMPLE_48048
00060     };
00061   
00062   
00063   
00064   
00065 //
00066 // MDGetSMPTERateFrequency() converts the SMPTE_RATE enum to a double frequency.
00067 //
00068   
00069   inline double GetSMPTERateFrequency( SMPTE_RATE r )
00070     {
00071       extern const double smpte_smpte_rates[];
00072       
00073       return smpte_smpte_rates[(int)r];
00074     }
00075   
00076   
00077 //
00078 // MDGetSMPTERateFrequencyLong() convert the SMPTE_RATE enum to an int
00079 // frequency times 100
00080 //
00081   
00082   inline long GetSMPTERateFrequencyLong( SMPTE_RATE r )
00083     {
00084       extern const double smpte_smpte_rates_long[];
00085       
00086       return (long)smpte_smpte_rates_long[(int)r];
00087     }
00088   
00089   
00090 //
00091 // GetSampleRateFrequency() convert the SAMPLE_RATE enum to a double frequency
00092 //
00093   
00094   
00095   inline  double  GetSampleRateFrequency( SAMPLE_RATE r )
00096     {
00097       extern const double smpte_sample_rates[];
00098       
00099       return smpte_sample_rates[(int)r];
00100     }
00101   
00102   
00103 //
00104 // MDGetSampleRateFrequencyLong() converts the SAMPLE_RATE enum to a long
00105 // frequency times 10
00106 //
00107   
00108   
00109   inline  long  GetSampleRateFrequencyLong( SAMPLE_RATE r )
00110     {
00111       // return the sample rate as a long word of the frequency times 10.
00112       
00113       extern const long smpte_sample_rates_long[];
00114       return smpte_sample_rates_long[(int)r];
00115     }
00116   
00117   
00118   
00119   
00120   
00121   
00122   class  SMPTE
00123     {
00124     public:
00125       SMPTE(
00126         SMPTE_RATE smpte_rate=SMPTE_RATE_30,
00127         SAMPLE_RATE sample_rate=SAMPLE_48000
00128         );
00129       
00130       SMPTE(
00131         const SMPTE & s
00132         );
00133       
00134       void  SetSMPTERate( SMPTE_RATE r )  { smpte_rate=r; sample_number_dirty=true; }
00135       SMPTE_RATE GetSMPTERate()   { return smpte_rate;        }
00136       
00137       void  SetSampleRate( SAMPLE_RATE r )  { sample_rate=r; sample_number_dirty=true;  }
00138       SAMPLE_RATE GetSampleRate()   { return sample_rate;       }  
00139       
00140       void  SetSampleNumber( ulong n )  { sample_number=n; SampleToTime();    }
00141       ulong GetSampleNumber() { if( sample_number_dirty ) TimeToSample(); return sample_number; }
00142       
00143       void  SetTime( uchar h, uchar m, uchar s, uchar f=0, uchar sf=0 )
00144         { hours=h; minutes=m; seconds=s; frames=f; sub_frames=sf; sample_number_dirty=true; }
00145       
00146       uchar GetHours()    { return hours;   }
00147       uchar GetMinutes()    { return minutes; }
00148       uchar GetSeconds()    { return seconds; }
00149       uchar   GetFrames()   { return frames;  }
00150       uchar GetSubFrames()    { return sub_frames;  }
00151       
00152       void  SetHours( uchar h ) { hours=h;     sample_number_dirty=true;  }
00153       void  SetMinutes( uchar m ) { minutes=m;   sample_number_dirty=true;  }
00154       void  SetSeconds( uchar s ) { seconds=s;   sample_number_dirty=true;  }
00155       void  SetFrames( uchar f )  { frames=f;    sample_number_dirty=true;  }
00156       void  SetSubFrames( uchar sf) { sub_frames=sf; sample_number_dirty=true;  }
00157       
00158       void  AddHours( char h );
00159       void  AddMinutes( char m );
00160       void  AddSeconds( char s );
00161       void  AddFrames( char f );
00162       void  AddSubFrames( char sf );
00163       void  AddSamples( long n )  { sample_number=GetSampleNumber()+n; SampleToTime();  }
00164       
00165       void  IncHours()  { AddHours(1);    }
00166       void  IncMinutes()  { AddMinutes(1);  }
00167       void  IncSeconds()  { AddSeconds(1);  }
00168       void  IncFrames() { AddFrames(1);   }
00169       void  IncSubFrames()  { AddSubFrames(1);  }
00170       void  IncSamples()  { AddSamples(1);  }
00171       
00172       void  DecHours()  { AddHours(-1);   }
00173       void  DecMinutes()  { AddMinutes(-1); }
00174       void  DecSeconds()  { AddSeconds(-1); }
00175       void  DecFrames() { AddFrames(-1);  }
00176       void  DecSubFrames()  { AddSubFrames(-1); }
00177       void  DecSamples()  { AddSamples(-1); }
00178       
00179       
00180       
00181       const SMPTE & operator =  ( const SMPTE & s ) { Copy(s); return *this;  }
00182       bool operator == ( SMPTE & s )  { return Compare(s)==0;   }
00183       bool operator != ( SMPTE & s )  { return Compare(s)!=0;   }
00184       bool operator <  ( SMPTE & s )  { return Compare(s)<0;    }
00185       bool operator >  ( SMPTE & s )  { return Compare(s)>0;    }
00186       bool operator <= ( SMPTE & s )  { return Compare(s)<=0;   }
00187       bool operator >= ( SMPTE & s )  { return Compare(s)>=0;   }
00188       
00189       const SMPTE & operator += ( SMPTE & s ) { Add( s ); return *this; }
00190       const SMPTE & operator -= ( SMPTE & s ) { Subtract( s ); return *this;  }
00191       
00192     protected:
00193       void  SampleToTime();
00194       void  TimeToSample();
00195       
00196       void  Copy( const SMPTE & s );
00197       int Compare( SMPTE & s );
00198       void  Add( SMPTE & s );
00199       void  Subtract( SMPTE & s );
00200       
00201       long  GetSampleRateLong()
00202         { return GetSampleRateFrequencyLong( sample_rate ); }
00203       
00204       int GetSMPTERateLong()
00205         { return GetSMPTERateFrequencyLong( smpte_rate ); }
00206       
00207     private:
00208       SMPTE_RATE  smpte_rate;
00209       SAMPLE_RATE sample_rate;
00210       ulong   sample_number;
00211       
00212       uchar   hours;
00213       uchar   minutes;
00214       uchar   seconds;
00215       uchar   frames;
00216       uchar   sub_frames;
00217       uchar   sample_number_dirty;
00218       
00219       
00220       friend  SMPTE operator + ( SMPTE a, SMPTE b );
00221       friend  SMPTE operator - ( SMPTE a, SMPTE b );
00222     };
00223   
00224   inline SMPTE operator + ( SMPTE a, SMPTE b )
00225     {
00226       SMPTE c(a);
00227       
00228       c+=b;
00229       return c;
00230     }
00231   
00232   inline SMPTE operator - ( SMPTE a, SMPTE b )
00233     {
00234       SMPTE c(a);
00235       
00236       c-=b;
00237       return c;
00238     }
00239   
00240 }
00241 
00242 #endif
00243 
00244