00001 
00004 #ifndef FBXFILESDK_COMPONENTS_KBASELIB_KLIB_KTIME_H
00005 #define FBXFILESDK_COMPONENTS_KBASELIB_KLIB_KTIME_H
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 #include <fbxfilesdk/components/kbaselib/kbaselib_h.h>
00043 
00044 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00045 
00046     
00047 
00048     
00049 #define KTIME_INFINITE          KTime (K_LONGLONG( 0x7fffffffffffffff))
00050 #define KTIME_MINUS_INFINITE    KTime (K_LONGLONG(-0x7fffffffffffffff))
00051 #define KTIME_ZERO              KTime (0)
00052 #define KTIME_EPSILON           KTime (1)
00053 #define KTIME_ONE_SECOND        KTime (K_LONGLONG(46186158000))
00054     #define KTIME_ONE_MINUTE        KTime (K_LONGLONG(2771169480000))
00055     #define KTIME_ONE_HOUR          KTime (K_LONGLONG(166270168800000))
00056 
00057     #define KTIME_FIVE_SECONDS      KTime (K_LONGLONG(230930790000))
00058 #define KTIME_ASSERT_EPSILON    0.5
00059 
00060 KFBX_FORWARD(KTimeModeObject);
00061 
00065 class KFBX_DLL KTime 
00066 {
00067 
00068 public:
00069 
00073     KTime(kLongLong pTime=0) {mTime=pTime;}
00074 
00079 
00101     
00102     
00103     
00104     
00105     
00123     enum ETimeMode
00124     {
00125         eDEFAULT_MODE       = 0,
00126         eFRAMES120          = 1,
00127         eFRAMES100          = 2,
00128         eFRAMES60           = 3,
00129         eFRAMES50           = 4,
00130         eFRAMES48           = 5,
00131         eFRAMES30           = 6,
00132         eFRAMES30_DROP      = 7,
00133         eNTSC_DROP_FRAME    = 8,
00134         eNTSC_FULL_FRAME    = 9,
00135         ePAL                = 10,
00136         eCINEMA             = 11,
00137         eFRAMES1000         = 12,
00138         eCINEMA_ND      = 13,
00139         eCUSTOM             = 14,
00140         eTIME_MODE_COUNT    = 15
00141     };
00142 
00148     enum ETimeProtocol
00149     {
00150         eSMPTE,
00151         eFRAME,
00152         eDEFAULT_PROTOCOL,
00153         eTIME_PROTOCOL_COUNT
00154     };
00155 
00161     static void SetGlobalTimeMode(ETimeMode pTimeMode, double pFrameRate=0.0);
00162 
00167     static ETimeMode GetGlobalTimeMode();
00168     
00173     static void SetGlobalTimeProtocol(ETimeProtocol pTimeProtocol);
00174 
00179     static ETimeProtocol GetGlobalTimeProtocol();
00180 
00185     static double GetFrameRate(ETimeMode pTimeMode);
00186 
00193     static ETimeMode ConvertFrameRateToTimeMode(double pFrameRate, double lPrecision = 0.00000001);
00194 
00196     
00201     
00205     inline void Set(kLongLong pTime) {mTime = pTime;}
00206 
00210     inline const kLongLong& Get() const {return mTime;}
00211 
00215     inline void SetMilliSeconds(kLongLong pMilliSeconds) {mTime = pMilliSeconds * K_LONGLONG(46186158);}
00216 
00220     inline kLongLong GetMilliSeconds() const {return mTime / K_LONGLONG(46186158);}
00221 
00225     void SetSecondDouble(double pTime);
00226 
00230     double GetSecondDouble() const;
00231 
00232 
00245     void SetTime 
00246     (
00247         int pHour, 
00248         int pMinute, 
00249         int pSecond, 
00250         int pFrame = 0, 
00251         int pField = 0, 
00252         int pTimeMode=eDEFAULT_MODE,
00253         double pFramerate = 0.0
00254     );
00255 
00274     void SetTime 
00275     (
00276         int pHour, 
00277         int pMinute, 
00278         int pSecond, 
00279         int pFrame, 
00280         int pField, 
00281         int pResidual, 
00282         int pTimeMode,
00283         double pFramerate = 0.0
00284     );
00285 
00298     bool GetTime 
00299     (
00300         kLongLong& pHour, 
00301         kLongLong& pMinute, 
00302         kLongLong& pSecond, 
00303         kLongLong& pFrame, 
00304         kLongLong& pField, 
00305         kLongLong& pResidual, 
00306         int pTimeMode=eDEFAULT_MODE,
00307         double pFramerate = 0.0
00308     ) const;
00309 
00313     KTime   GetFramedTime(bool pRound = true);
00314 
00321     kLongLong GetHour(bool pCummul=false, int pTimeMode=eDEFAULT_MODE, double pFramerate=0.0) const;
00322     
00330     kLongLong GetMinute(bool pCummul=false, int pTimeMode=eDEFAULT_MODE, double pFramerate=0.0) const;
00331     
00339     kLongLong GetSecond(bool pCummul=false, int pTimeMode=eDEFAULT_MODE, double pFramerate=0.0) const;
00340     
00348     kLongLong GetFrame(bool pCummul=false, int pTimeMode=eDEFAULT_MODE, double pFramerate=0.0) const;
00349     
00357     kLongLong GetField(bool pCummul=false, int pTimeMode=eDEFAULT_MODE, double pFramerate=0.0) const;
00358 
00364     kLongLong GetResidual(int pTimeMode=eDEFAULT_MODE, double pFramerate=0.0) const;
00365 
00381     char* GetTimeString 
00382     (
00383         char* pTimeString,  
00384         int pInfo=5, 
00385         int pTimeMode=eDEFAULT_MODE, 
00386     int pTimeFormat=eDEFAULT_PROTOCOL,
00387     double pFramerate = 0.0
00388 
00389     ) const;
00390 
00403     void SetTimeString(char* pTime, int pTimeMode=eDEFAULT_MODE, int pTimeFormat=eDEFAULT_PROTOCOL, double pFramerate = 0.0);
00404 
00406 
00411  
00416     inline bool operator==(const KTime& pTime) const {return mTime == pTime.mTime;}
00417 
00422     inline bool operator!=(const KTime& pTime) const {return mTime != pTime.mTime;}
00423 
00428     inline bool operator>=(const KTime& pTime) const {return mTime >= pTime.mTime;}
00429 
00434     inline bool operator<=(const KTime& pTime) const {return mTime <= pTime.mTime;}
00435 
00440     inline bool operator>(const KTime& pTime) const {return mTime > pTime.mTime;}
00441  
00446     inline bool operator<(const KTime& pTime) const {return mTime < pTime.mTime;} 
00447 
00451     inline KTime& operator=(const KTime& pTime) {mTime = pTime.mTime; return *this;}
00452     
00457     inline KTime& operator+=(const KTime& pTime) {mTime += pTime.mTime; return *this;}
00458     
00463     inline KTime& operator-=(const KTime& pTime) {mTime -= pTime.mTime; return *this;}
00464     
00469     KTime operator+(const KTime& pTime) const;
00470 
00475     KTime operator-(const KTime& pTime) const;
00476 
00481     KTime operator*(const int Mult) const;
00482 
00487     KTime operator/(const KTime &pTime) const;
00488 
00493     KTime operator*(const KTime &pTime) const;
00494 
00496     inline KTime &operator++() {mTime += 1; return (*this);}
00497 
00499     inline const KTime operator++(int) {KTime lOld = *this; ++(*this); return lOld;}
00500 
00502     inline KTime &operator--() {mTime -= 1; return (*this);}
00503 
00505     inline const KTime operator--(int) {KTime lOld = *this; --(*this); return lOld;}
00506 
00508     static KTime GetSystemTimer();
00510     
00511     
00512     
00513     
00514     
00515     
00517 
00518 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00519 
00520 private:
00521 
00522     kLongLong mTime; 
00523 
00524     static ETimeMode gsGlobalTimeMode;
00525     static ETimeProtocol gsGlobalTimeProtocol;
00526     static KTimeModeObject* gsTimeObject;
00527 
00528 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00529     
00530     
00531     friend KFBX_DLL KTime::ETimeMode        KTime_GetGlobalTimeMode();
00532     friend KFBX_DLL HKTimeModeObject        KTime_GetGlobalTimeModeObject();
00533     friend KFBX_DLL KTime::ETimeProtocol    KTime_GetGlobalTimeFormat();
00534     friend KFBX_DLL void                    KTime_SetGlobalTimeMode( KTime::ETimeMode pTimeMode, double pFrameRate=0.0 );
00535     friend KFBX_DLL void                    KTime_SetGlobalTimeFormat( KTime::ETimeProtocol pTimeFormat );
00536 
00537     inline kLongLong GetOneFrameValue ( int pTimeMode, double pFramerate ) const;
00538 
00539 };
00540 
00541 
00542 #define KTS_FORWARD 1
00543 #define KTS_BACKWARD -1
00544 
00545 #define KTIMESPAN_INFINITE          KTimeSpan (KTIME_MINUS_INFINITE, KTIME_INFINITE)
00546 
00550 class KFBX_DLL KTimeSpan
00551 {
00552 
00553 public:
00554 
00556     KTimeSpan() {}
00557 
00562     KTimeSpan(KTime pStart, KTime pStop) {mStart=pStart; mStop=pStop;}
00563 
00568     inline void Set(KTime pStart, KTime pStop) {mStart=pStart; mStop=pStop;}
00569 
00573     inline void SetStart(KTime pStart) {mStart=pStart;}
00574     
00578     inline void SetStop(KTime pStop) {mStop=pStop;}
00579     
00583     inline KTime &GetStart() {return mStart;}
00584     
00588     inline KTime &GetStop() {return mStop;}
00589     
00593     inline KTime GetDuration() const {if (mStop>mStart)return mStop-mStart; else return mStart-mStop;}
00594     
00598     inline KTime GetSignedDuration() const {return mStop-mStart;}
00599     
00603     inline int GetDirection() const {if (mStop>=mStart)return KTS_FORWARD; else return KTS_BACKWARD;}
00604 
00609     bool operator&(KTime &pTime) const;
00610     
00615     KTimeSpan operator&(KTimeSpan &pTime) const;
00616 
00621     bool operator!=(KTimeSpan &pTime);
00622 
00623     
00625     
00626     
00627     
00628     
00629     
00630     
00632 
00633 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00634 
00635 private:
00636 
00637     KTime mStart;
00638     KTime mStop;
00639 
00640 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00641 
00642 };
00643 
00644 
00645 
00661 enum EOldTimeMode
00662 {
00663     eOLD_DEFAULT_MODE,      
00664     eOLD_CINEMA,            
00665     eOLD_PAL,               
00666     eOLD_FRAMES30,          
00667     eOLD_NTSC_DROP_FRAME,   
00668     eOLD_FRAMES50,          
00669     eOLD_FRAMES60,          
00670     eOLD_FRAMES100,         
00671     eOLD_FRAMES120,         
00672     eOLD_NTSC_FULL_FRAME,   
00673     eOLD_FRAMES30_DROP,     
00674     eOLD_FRAMES1000,        
00675     eOLD_TIME_MODE_COUNT
00676 };
00677 
00678 class KFBX_DLL KTimeModeObject
00679 {
00680 public:
00681     double              mFrameRateValue;
00682     char*               mFrameRateString;
00683     KTime::ETimeMode    mTimeMode;
00684     EOldTimeMode        mOldTimeMode;
00685     char*               mTimeModeString;
00686     int                 mShowValue;     
00687 
00688     bool                mSystemRate;    
00689     bool                mExistInOldValue;
00690     kLongLong           mOneFrameValue;  
00691 };
00692 
00693 
00694 KFBX_DLL KTime::ETimeMode       KTime_GetGlobalTimeMode();
00695 KFBX_DLL HKTimeModeObject       KTime_GetGlobalTimeModeObject();
00696 KFBX_DLL KTime::ETimeProtocol   KTime_GetGlobalTimeFormat();
00697 KFBX_DLL void                   KTime_SetGlobalTimeMode(KTime::ETimeMode pTimeMode, double pFrameRate);
00698 KFBX_DLL void                   KTime_SetGlobalTimeFormat(KTime::ETimeProtocol pTimeFormat);
00699 
00700 
00701 
00702 KFBX_DLL int                    KTime_GetOldTimeModeCorrespondance(KTime::ETimeMode pNewTimeMode);
00703 KFBX_DLL int                    KTime_GetTimeModeFromOldValue(int pOldTimeMode);
00704 
00705 
00706 
00707 KFBX_DLL int                    KTime_GetTimeModeFromFrameRate(char* pFrameRate);
00708 KFBX_DLL void                   KTime_GetControlStringList(char* pControlString, KTime::ETimeProtocol pTimeFormat);
00709 KFBX_DLL char*                  KTime_GetGlobalFrameRateString(KTime::ETimeMode pTimeMode);
00710 KFBX_DLL char*                  KTime_GetGlobalTimeModeString(KTime::ETimeMode pTimeMode);
00711 KFBX_DLL double                 KTime_GetFrameRate(KTime::ETimeMode pTimeMode);
00712 
00713 
00714 
00715 KFBX_DLL int                    KTime_SelectionToTimeFormat(int pSelection);
00716 KFBX_DLL int                    KTime_SelectionToTimeMode(int pSelection);
00717 KFBX_DLL int                    KTime_TimeToSelection(int pTimeMode=KTime::eDEFAULT_MODE, int pTimeFormat=KTime::eDEFAULT_PROTOCOL);
00718 KFBX_DLL char*                  KTime_GetTimeModeName(int pTimeMode);
00719 KFBX_DLL int                    KTime_GetFrameRateStringListIndex(KTime::ETimeMode pTimeMode);
00720 KFBX_DLL bool                   KTime_IsValidCustomFramerate(double pFramerate);
00721 KFBX_DLL bool                   KTime_GetNearestCustomFramerate(double pFramerate, double& pNearestRate);
00722 
00723 
00724 
00725 #define DEFAULT_MODE        KTime::eDEFAULT_MODE
00726 #define CINEMA              KTime::eCINEMA
00727 #define PAL                 KTime::ePAL
00728 #define FRAMES30            KTime::eFRAMES30
00729 #define NTSC_DROP_FRAME     KTime::eNTSC_DROP_FRAME
00730 #define FRAMES50            KTime::eFRAMES50    
00731 #define FRAMES60            KTime::eFRAMES60
00732 #define FRAMES100           KTime::eFRAMES100
00733 #define FRAMES120           KTime::eFRAMES120
00734 #define NTSC_FULL_FRAME     KTime::eNTSC_FULL_FRAME
00735 #define FRAMES30_DROP       KTime::eFRAMES30_DROP
00736 #define FRAMES1000          KTime::eFRAMES1000
00737 
00738 #define TIMEFORMAT_SMPTE    KTime::eSMPTE
00739 #define TIMEFORMAT_FRAME    KTime::eFRAME
00740 #define DEFAULT_FORMAT      KTime::eDEFAULT_PROTOCOL
00741 
00742 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00743 
00744 #endif // FBXFILESDK_COMPONENTS_KBASELIB_KLIB_KTIME_H
00745