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 KTime &operator--() {mTime -= 1; return (*this);}
00500
00502 static KTime GetSystemTimer();
00504
00505
00506
00507
00508
00509
00511
00512 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00513
00514 private:
00515
00516 kLongLong mTime;
00517
00518 static ETimeMode gsGlobalTimeMode;
00519 static ETimeProtocol gsGlobalTimeProtocol;
00520 static KTimeModeObject* gsTimeObject;
00521
00522 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00523
00524
00525 friend KFBX_DLL KTime::ETimeMode KTime_GetGlobalTimeMode();
00526 friend KFBX_DLL HKTimeModeObject KTime_GetGlobalTimeModeObject();
00527 friend KFBX_DLL KTime::ETimeProtocol KTime_GetGlobalTimeFormat();
00528 friend KFBX_DLL void KTime_SetGlobalTimeMode( KTime::ETimeMode pTimeMode, double pFrameRate=0.0 );
00529 friend KFBX_DLL void KTime_SetGlobalTimeFormat( KTime::ETimeProtocol pTimeFormat );
00530
00531 inline kLongLong GetOneFrameValue ( int pTimeMode, double pFramerate ) const;
00532
00533 };
00534
00535
00536 #define KTS_FORWARD 1
00537 #define KTS_BACKWARD -1
00538
00539 #define KTIMESPAN_INFINITE KTimeSpan (KTIME_MINUS_INFINITE, KTIME_INFINITE)
00540
00544 class KFBX_DLL KTimeSpan
00545 {
00546
00547 public:
00548
00550 KTimeSpan() {}
00551
00556 KTimeSpan(KTime pStart, KTime pStop) {mStart=pStart; mStop=pStop;}
00557
00562 inline void Set(KTime pStart, KTime pStop) {mStart=pStart; mStop=pStop;}
00563
00567 inline void SetStart(KTime pStart) {mStart=pStart;}
00568
00572 inline void SetStop(KTime pStop) {mStop=pStop;}
00573
00577 inline KTime &GetStart() {return mStart;}
00578
00582 inline KTime &GetStop() {return mStop;}
00583
00587 inline KTime GetDuration() const {if (mStop>mStart)return mStop-mStart; else return mStart-mStop;}
00588
00592 inline KTime GetSignedDuration() const {return mStop-mStart;}
00593
00597 inline int GetDirection() const {if (mStop>=mStart)return KTS_FORWARD; else return KTS_BACKWARD;}
00598
00603 bool operator&(KTime &pTime) const;
00604
00609 KTimeSpan operator&(KTimeSpan &pTime) const;
00610
00615 bool operator!=(KTimeSpan &pTime);
00616
00617
00619
00620
00621
00622
00623
00624
00626
00627 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00628
00629 private:
00630
00631 KTime mStart;
00632 KTime mStop;
00633
00634 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00635
00636 };
00637
00638
00639
00655 enum EOldTimeMode
00656 {
00657 eOLD_DEFAULT_MODE,
00658 eOLD_CINEMA,
00659 eOLD_PAL,
00660 eOLD_FRAMES30,
00661 eOLD_NTSC_DROP_FRAME,
00662 eOLD_FRAMES50,
00663 eOLD_FRAMES60,
00664 eOLD_FRAMES100,
00665 eOLD_FRAMES120,
00666 eOLD_NTSC_FULL_FRAME,
00667 eOLD_FRAMES30_DROP,
00668 eOLD_FRAMES1000,
00669 eOLD_TIME_MODE_COUNT
00670 };
00671
00672 class KFBX_DLL KTimeModeObject
00673 {
00674 public:
00675 double mFrameRateValue;
00676 char* mFrameRateString;
00677 KTime::ETimeMode mTimeMode;
00678 EOldTimeMode mOldTimeMode;
00679 char* mTimeModeString;
00680 int mShowValue;
00681
00682 bool mSystemRate;
00683 bool mExistInOldValue;
00684 kLongLong mOneFrameValue;
00685 };
00686
00687
00688 KFBX_DLL KTime::ETimeMode KTime_GetGlobalTimeMode ();
00689 KFBX_DLL HKTimeModeObject KTime_GetGlobalTimeModeObject();
00690 KFBX_DLL KTime::ETimeProtocol KTime_GetGlobalTimeFormat ();
00691 KFBX_DLL void KTime_SetGlobalTimeMode (KTime::ETimeMode pTimeMode, double pFrameRate);
00692 KFBX_DLL void KTime_SetGlobalTimeFormat (KTime::ETimeProtocol pTimeFormat);
00693
00694
00695
00696 KFBX_DLL int KTime_GetOldTimeModeCorrespondance ( KTime::ETimeMode pNewTimeMode );
00697 KFBX_DLL int KTime_GetTimeModeFromOldValue ( int pOldTimeMode );
00698
00699
00700
00701 KFBX_DLL int KTime_GetTimeModeFromFrameRate ( char* pFrameRate );
00702 KFBX_DLL void KTime_GetControlStringList ( char* pControlString, KTime::ETimeProtocol pTimeFormat);
00703 KFBX_DLL char* KTime_GetGlobalFrameRateString ( KTime::ETimeMode pTimeMode );
00704 KFBX_DLL char* KTime_GetGlobalTimeModeString ( KTime::ETimeMode pTimeMode );
00705 KFBX_DLL double KTime_GetFrameRate ( KTime::ETimeMode pTimeMode );
00706
00707
00708
00709 KFBX_DLL int KTime_SelectionToTimeFormat (int pSelection);
00710 KFBX_DLL int KTime_SelectionToTimeMode (int pSelection);
00711 KFBX_DLL int KTime_TimeToSelection (int pTimeMode=KTime::eDEFAULT_MODE, int pTimeFormat=KTime::eDEFAULT_PROTOCOL);
00712 KFBX_DLL char*KTime_GetTimeModeName( int pTimeMode );
00713 KFBX_DLL int KTime_GetFrameRateStringListIndex ( KTime::ETimeMode pTimeMode );
00714 KFBX_DLL bool KTime_IsValidCustomFramerate ( double pFramerate );
00715 KFBX_DLL bool KTime_GetNearestCustomFramerate ( double pFramerate, double& pNearestRate );
00716
00717
00718
00719 #define DEFAULT_MODE KTime::eDEFAULT_MODE
00720 #define CINEMA KTime::eCINEMA
00721 #define PAL KTime::ePAL
00722 #define FRAMES30 KTime::eFRAMES30
00723 #define NTSC_DROP_FRAME KTime::eNTSC_DROP_FRAME
00724 #define FRAMES50 KTime::eFRAMES50
00725 #define FRAMES60 KTime::eFRAMES60
00726 #define FRAMES100 KTime::eFRAMES100
00727 #define FRAMES120 KTime::eFRAMES120
00728 #define NTSC_FULL_FRAME KTime::eNTSC_FULL_FRAME
00729 #define FRAMES30_DROP KTime::eFRAMES30_DROP
00730 #define FRAMES1000 KTime::eFRAMES1000
00731
00732 #define TIMEFORMAT_SMPTE KTime::eSMPTE
00733 #define TIMEFORMAT_FRAME KTime::eFRAME
00734 #define DEFAULT_FORMAT KTime::eDEFAULT_PROTOCOL
00735
00736 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00737
00738 #endif // FBXFILESDK_COMPONENTS_KBASELIB_KLIB_KTIME_H
00739