00001
00004 #ifndef _FBXSDK_KTIME_H_
00005 #define _FBXSDK_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 <kbaselib_h.h>
00043
00044 #include <kbaselib_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
00064 class KBASELIB_DLL KTime
00065 {
00066
00067 public:
00068
00072 KTime(kLongLong pTime=0) {mTime=pTime;}
00073
00078
00100
00101
00102
00103
00104
00121 enum ETimeMode
00122 {
00123 eDEFAULT_MODE = 0,
00124 eFRAMES120 = 1,
00125 eFRAMES100 = 2,
00126 eFRAMES60 = 3,
00127 eFRAMES50 = 4,
00128 eFRAMES48 = 5,
00129 eFRAMES30 = 6,
00130 eFRAMES30_DROP = 7,
00131 eNTSC_DROP_FRAME = 8,
00132 eNTSC_FULL_FRAME = 9,
00133 ePAL = 10,
00134 eCINEMA = 11,
00135 eFRAMES1000 = 12,
00136 eCINEMA_DROP = 13,
00137 eTIME_MODE_COUNT = 14
00138 };
00139
00145 enum ETimeProtocol
00146 {
00147 eSMPTE,
00148 eFRAME,
00149 eDEFAULT_PROTOCOL,
00150 eTIME_PROTOCOL_COUNT
00151 };
00152
00157 static void SetGlobalTimeMode(ETimeMode pTimeMode);
00158
00163 static ETimeMode GetGlobalTimeMode();
00164
00169 static void SetGlobalTimeProtocol(ETimeProtocol pTimeProtocol);
00170
00175 static ETimeProtocol GetGlobalTimeProtocol();
00176
00181 static double GetFrameRate(ETimeMode pTimeMode);
00182
00189 static ETimeMode ConvertFrameRateToTimeMode(double pFrameRate, double lPrecision = 0.00000001);
00190
00192
00197
00201 inline void Set(kLongLong pTime) {mTime = pTime;}
00202
00206 inline const kLongLong& Get() const {return mTime;}
00207
00211 inline void SetMilliSeconds(kLongLong pMilliSeconds) {mTime = pMilliSeconds * K_LONGLONG(46186158);}
00212
00216 inline kLongLong GetMilliSeconds() const {return mTime / K_LONGLONG(46186158);}
00217
00221 void SetSecondDouble(double pTime);
00222
00226 double GetSecondDouble() const;
00227
00228
00240 void SetTime
00241 (
00242 int pHour,
00243 int pMinute,
00244 int pSecond,
00245 int pFrame = 0,
00246 int pField = 0,
00247 int pTimeMode=eDEFAULT_MODE
00248 );
00249
00267 void SetTime
00268 (
00269 int pHour,
00270 int pMinute,
00271 int pSecond,
00272 int pFrame,
00273 int pField,
00274 int pResidual,
00275 int pTimeMode
00276 );
00277
00289 bool GetTime
00290 (
00291 kLongLong& pHour,
00292 kLongLong& pMinute,
00293 kLongLong& pSecond,
00294 kLongLong& pFrame,
00295 kLongLong& pField,
00296 kLongLong& pResidual,
00297 int pTimeMode=eDEFAULT_MODE
00298 ) const;
00299
00300
00301 KTime GetFramedTime(bool pRound = true);
00302
00308 kLongLong GetHour(bool pCummul=false, int pTimeMode=eDEFAULT_MODE) const;
00309
00316 kLongLong GetMinute(bool pCummul=false, int pTimeMode=eDEFAULT_MODE) const;
00317
00324 kLongLong GetSecond(bool pCummul=false, int pTimeMode=eDEFAULT_MODE) const;
00325
00332 kLongLong GetFrame(bool pCummul=false, int pTimeMode=eDEFAULT_MODE) const;
00333
00340 kLongLong GetField(bool pCummul=false, int pTimeMode=eDEFAULT_MODE) const;
00341
00346 kLongLong GetResidual(int pTimeMode=eDEFAULT_MODE) const;
00347
00362 char* GetTimeString
00363 (
00364 char* pTimeString,
00365 int pInfo=5,
00366 int pTimeMode=eDEFAULT_MODE,
00367 int pTimeFormat=eDEFAULT_PROTOCOL
00368 ) const;
00369
00381 void SetTimeString(char* pTime, int pTimeMode=eDEFAULT_MODE, int pTimeFormat=eDEFAULT_PROTOCOL);
00382
00384
00389
00391 inline bool operator==(const KTime& pTime) const {return mTime == pTime.mTime;}
00392
00394 inline bool operator!=(const KTime& pTime) const {return mTime != pTime.mTime;}
00395
00397 inline bool operator>=(const KTime& pTime) const {return mTime >= pTime.mTime;}
00398
00400 inline bool operator<=(const KTime& pTime) const {return mTime <= pTime.mTime;}
00401
00403 inline bool operator>(const KTime& pTime) const {return mTime > pTime.mTime;}
00404
00406 inline bool operator<(const KTime& pTime) const {return mTime < pTime.mTime;}
00407
00409 inline KTime& operator=(const KTime& pTime) {mTime = pTime.mTime; return *this;}
00410
00412 inline KTime& operator+=(const KTime& pTime) {mTime += pTime.mTime; return *this;}
00413
00415 inline KTime& operator-=(const KTime& pTime) {mTime -= pTime.mTime; return *this;}
00416
00418 KTime operator+(const KTime& pTime) const;
00419
00421 KTime operator-(const KTime& pTime) const;
00422
00424 KTime operator*(const int Mult) const;
00425
00427 KTime operator/(const KTime &pTime) const;
00428
00430 KTime operator*(const KTime &pTime) const;
00431
00433 inline KTime &operator++() {mTime += 1; return (*this);}
00434
00436 inline KTime &operator--() {mTime -= 1; return (*this);}
00437
00439
00441
00442
00443
00444
00445
00446
00448
00449 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00450
00451 private:
00452
00453 kLongLong mTime;
00454
00455 static ETimeMode gsGlobalTimeMode;
00456 static ETimeProtocol gsGlobalTimeProtocol;
00457
00458 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00459
00460
00461 friend KBASELIB_DLL KTime::ETimeMode KTime_GetGlobalTimeMode();
00462 friend KBASELIB_DLL KTime::ETimeProtocol KTime_GetGlobalTimeFormat();
00463 friend KBASELIB_DLL void KTime_SetGlobalTimeMode( KTime::ETimeMode pTimeMode );
00464 friend KBASELIB_DLL void KTime_SetGlobalTimeFormat( KTime::ETimeProtocol pTimeFormat );
00465
00466 };
00467
00468
00469 #define KTS_FORWARD 1
00470 #define KTS_BACKWARD -1
00471
00472
00476 class KBASELIB_DLL KTimeSpan
00477 {
00478
00479 public:
00480
00482 KTimeSpan() {}
00483
00488 KTimeSpan(KTime pStart, KTime pStop) {mStart=pStart; mStop=pStop;}
00489
00494 inline void Set(KTime pStart, KTime pStop) {mStart=pStart; mStop=pStop;}
00495
00499 inline void SetStart(KTime pStart) {mStart=pStart;}
00500
00504 inline void SetStop(KTime pStop) {mStop=pStop;}
00505
00509 inline KTime &GetStart() {return mStart;}
00510
00514 inline KTime &GetStop() {return mStop;}
00515
00519 inline KTime GetDuration() const {if (mStop>mStart)return mStop-mStart; else return mStart-mStop;}
00520
00524 inline KTime GetSignedDuration() const {return mStop-mStart;}
00525
00529 inline int GetDirection() const {if (mStop>=mStart)return KTS_FORWARD; else return KTS_BACKWARD;}
00530
00532 bool operator&(KTime &pTime) const;
00533
00535 KTimeSpan operator&(KTimeSpan &pTime) const;
00536
00538 bool operator!=(KTimeSpan &pTime);
00540
00541
00542
00543
00544
00545
00547
00548 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00549
00550 private:
00551
00552 KTime mStart;
00553 KTime mStop;
00554
00555 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00556
00557 };
00558
00559 KBASELIB_DLL KTime::ETimeMode KTime_GetGlobalTimeMode ();
00560 KBASELIB_DLL KTime::ETimeProtocol KTime_GetGlobalTimeFormat ();
00561 KBASELIB_DLL void KTime_SetGlobalTimeMode (KTime::ETimeMode pTimeMode);
00562 KBASELIB_DLL void KTime_SetGlobalTimeFormat (KTime::ETimeProtocol pTimeFormat);
00563
00564
00565
00566 KBASELIB_DLL int KTime_GetOldTimeModeCorrespondance ( KTime::ETimeMode pNewTimeMode );
00567 KBASELIB_DLL int KTime_GetTimeModeFromOldValue ( int pOldTimeMode );
00568
00569
00570
00571 KBASELIB_DLL int KTime_GetTimeModeFromFrameRate ( char* pFrameRate );
00572 KBASELIB_DLL void KTime_GetControlStringList ( char* pControlString, KTime::ETimeProtocol pTimeFormat);
00573 KBASELIB_DLL char* KTime_GetGlobalFrameRateString ( KTime::ETimeMode pTimeMode );
00574 KBASELIB_DLL char* KTime_GetGlobalTimeModeString ( KTime::ETimeMode pTimeMode );
00575 KBASELIB_DLL double KTime_GetFrameRate ( );
00576
00577
00578
00579 KBASELIB_DLL int KTime_SelectionToTimeFormat (int pSelection);
00580 KBASELIB_DLL int KTime_SelectionToTimeMode (int pSelection);
00581 KBASELIB_DLL int KTime_TimeToSelection (int pTimeMode=KTime::eDEFAULT_MODE, int pTimeFormat=KTime::eDEFAULT_PROTOCOL);
00582 KBASELIB_DLL char*KTime_GetTimeModeName( int pTimeMode );
00583 KBASELIB_DLL int KTime_GetFrameRateStringListIndex ( KTime::ETimeMode pTimeMode );
00584
00585
00586
00587 #define DEFAULT_MODE KTime::eDEFAULT_MODE
00588 #define CINEMA KTime::eCINEMA
00589 #define PAL KTime::ePAL
00590 #define FRAMES30 KTime::eFRAMES30
00591 #define NTSC_DROP_FRAME KTime::eNTSC_DROP_FRAME
00592 #define FRAMES50 KTime::eFRAMES50
00593 #define FRAMES60 KTime::eFRAMES60
00594 #define FRAMES100 KTime::eFRAMES100
00595 #define FRAMES120 KTime::eFRAMES120
00596 #define NTSC_FULL_FRAME KTime::eNTSC_FULL_FRAME
00597 #define FRAMES30_DROP KTime::eFRAMES30_DROP
00598 #define FRAMES1000 KTime::eFRAMES1000
00599
00600 #define TIMEFORMAT_SMPTE KTime::eSMPTE
00601 #define TIMEFORMAT_FRAME KTime::eFRAME
00602 #define DEFAULT_FORMAT KTime::eDEFAULT_PROTOCOL
00603
00604 #include <kbaselib_nsend.h>
00605
00606 #endif // #ifndef _FBXSDK_KTIME_H_
00607
00608