ktime.h

Go to the documentation of this file.
00001 
00004 #ifndef FBXFILESDK_COMPONENTS_KBASELIB_KLIB_KTIME_H
00005 #define FBXFILESDK_COMPONENTS_KBASELIB_KLIB_KTIME_H
00006 
00007 /**************************************************************************************
00008 
00009  Copyright (C) 2001 - 2009 Autodesk, Inc. and/or its licensors.
00010  All Rights Reserved.
00011 
00012  The coded instructions, statements, computer programs, and/or related material 
00013  (collectively the "Data") in these files contain unpublished information 
00014  proprietary to Autodesk, Inc. and/or its licensors, which is protected by 
00015  Canada and United States of America federal copyright law and by international 
00016  treaties. 
00017  
00018  The Data may not be disclosed or distributed to third parties, in whole or in
00019  part, without the prior written consent of Autodesk, Inc. ("Autodesk").
00020 
00021  THE DATA IS PROVIDED "AS IS" AND WITHOUT WARRANTY.
00022  ALL WARRANTIES ARE EXPRESSLY EXCLUDED AND DISCLAIMED. AUTODESK MAKES NO
00023  WARRANTY OF ANY KIND WITH RESPECT TO THE DATA, EXPRESS, IMPLIED OR ARISING
00024  BY CUSTOM OR TRADE USAGE, AND DISCLAIMS ANY IMPLIED WARRANTIES OF TITLE, 
00025  NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR USE. 
00026  WITHOUT LIMITING THE FOREGOING, AUTODESK DOES NOT WARRANT THAT THE OPERATION
00027  OF THE DATA WILL BE UNINTERRUPTED OR ERROR FREE. 
00028  
00029  IN NO EVENT SHALL AUTODESK, ITS AFFILIATES, PARENT COMPANIES, LICENSORS
00030  OR SUPPLIERS ("AUTODESK GROUP") BE LIABLE FOR ANY LOSSES, DAMAGES OR EXPENSES
00031  OF ANY KIND (INCLUDING WITHOUT LIMITATION PUNITIVE OR MULTIPLE DAMAGES OR OTHER
00032  SPECIAL, DIRECT, INDIRECT, EXEMPLARY, INCIDENTAL, LOSS OF PROFITS, REVENUE
00033  OR DATA, COST OF COVER OR CONSEQUENTIAL LOSSES OR DAMAGES OF ANY KIND),
00034  HOWEVER CAUSED, AND REGARDLESS OF THE THEORY OF LIABILITY, WHETHER DERIVED
00035  FROM CONTRACT, TORT (INCLUDING, BUT NOT LIMITED TO, NEGLIGENCE), OR OTHERWISE,
00036  ARISING OUT OF OR RELATING TO THE DATA OR ITS USE OR ANY OTHER PERFORMANCE,
00037  WHETHER OR NOT AUTODESK HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS
00038  OR DAMAGE. 
00039 
00040 **************************************************************************************/
00041 #include <fbxfilesdk/fbxfilesdk_def.h>
00042 
00043 #ifdef K_QUICKTIME_PLUGIN
00044     #ifdef KFBX_DLL
00045     #undef KFBX_DLL
00046     #endif
00047     #define KFBX_DLL
00048 #endif
00049 
00050 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00051 
00052 // Basic constants.
00053 #define KTIME_INFINITE          KTime (K_LONGLONG( 0x7fffffffffffffff))
00054 #define KTIME_MINUS_INFINITE    KTime (K_LONGLONG(-0x7fffffffffffffff))
00055 #define KTIME_ZERO              KTime (0)
00056 #define KTIME_EPSILON           KTime (1)
00057 #define KTIME_ONE_SECOND        KTime (K_LONGLONG(46186158000))
00058 
00059 #define KTIME_ASSERT_EPSILON    0.5
00060 
00061 KFBX_FORWARD(KTimeModeObject);
00062 
00071 class KFBX_DLL KTime 
00072 {
00073 public:
00077     KTime(kLongLong pTime=0) {mTime=pTime;}
00078 
00083 
00105     //
00106     // *** Affected files when adding new enum values ***
00107     // (ktimeinline.h kfcurveview.cxx, kaudioview.cxx, kvideoview.cxx, kttimespanviewoptical.cxx,
00108     //  kttimespanview.cxx, ktcameraswitchertimelinecontrol.cxx, fbxsdk(fpproperties.cxx) )
00109     //
00128     enum ETimeMode
00129     {
00130         eDEFAULT_MODE       = 0,
00131         eFRAMES120          = 1,
00132         eFRAMES100          = 2,
00133         eFRAMES60           = 3,
00134         eFRAMES50           = 4,
00135         eFRAMES48           = 5,
00136         eFRAMES30           = 6,
00137         eFRAMES30_DROP      = 7,
00138         eNTSC_DROP_FRAME    = 8,
00139         eNTSC_FULL_FRAME    = 9,
00140         ePAL                = 10,
00141         eCINEMA             = 11,
00142         eFRAMES1000         = 12,
00143         eCINEMA_ND      = 13,
00144         eCUSTOM             = 14,
00145         eTIME_MODE_COUNT    = 15
00146     };
00147 
00154     enum ETimeProtocol
00155     {
00156         eSMPTE,
00157         eFRAME,
00158         eDEFAULT_PROTOCOL,
00159         eTIME_PROTOCOL_COUNT
00160     };
00161 
00167     static void SetGlobalTimeMode(ETimeMode pTimeMode, double pFrameRate=0.0);
00168 
00173     static ETimeMode GetGlobalTimeMode();
00174     
00179     static void SetGlobalTimeProtocol(ETimeProtocol pTimeProtocol);
00180 
00185     static ETimeProtocol GetGlobalTimeProtocol();
00186 
00191     static double GetFrameRate(ETimeMode pTimeMode);
00192 
00199     static ETimeMode ConvertFrameRateToTimeMode(double pFrameRate, double lPrecision = 0.00000001);
00200 
00202     
00207     
00211     inline void Set(kLongLong pTime) {mTime = pTime;}
00212 
00216     inline const kLongLong& Get() const {return mTime;}
00217 
00221     inline void SetMilliSeconds(kLongLong pMilliSeconds) {mTime = pMilliSeconds * K_LONGLONG(46186158);}
00222 
00226     inline kLongLong GetMilliSeconds() const {return mTime / K_LONGLONG(46186158);}
00227 
00231     void SetSecondDouble(double pTime);
00232 
00236     double GetSecondDouble() const;
00237 
00238 
00251     void SetTime 
00252     (
00253         int pHour, 
00254         int pMinute, 
00255         int pSecond, 
00256         int pFrame = 0, 
00257         int pField = 0, 
00258         int pTimeMode=eDEFAULT_MODE,
00259         double pFramerate = 0.0
00260     );
00261 
00280     void SetTime 
00281     (
00282         int pHour, 
00283         int pMinute, 
00284         int pSecond, 
00285         int pFrame, 
00286         int pField, 
00287         int pResidual, 
00288         int pTimeMode,
00289         double pFramerate = 0.0
00290     );
00291 
00304     bool GetTime 
00305     (
00306         kLongLong& pHour, 
00307         kLongLong& pMinute, 
00308         kLongLong& pSecond, 
00309         kLongLong& pFrame, 
00310         kLongLong& pField, 
00311         kLongLong& pResidual, 
00312         int pTimeMode=eDEFAULT_MODE,
00313         double pFramerate = 0.0
00314     ) const;
00315 
00320     KTime   GetFramedTime(bool pRound = true);
00321 
00328     kLongLong GetHour(bool pCummul=false, int pTimeMode=eDEFAULT_MODE, double pFramerate=0.0) const;
00329     
00337     kLongLong GetMinute(bool pCummul=false, int pTimeMode=eDEFAULT_MODE, double pFramerate=0.0) const;
00338     
00346     kLongLong GetSecond(bool pCummul=false, int pTimeMode=eDEFAULT_MODE, double pFramerate=0.0) const;
00347     
00355     kLongLong GetFrame(bool pCummul=false, int pTimeMode=eDEFAULT_MODE, double pFramerate=0.0) const;
00356     
00364     kLongLong GetField(bool pCummul=false, int pTimeMode=eDEFAULT_MODE, double pFramerate=0.0) const;
00365 
00371     kLongLong GetResidual(int pTimeMode=eDEFAULT_MODE, double pFramerate=0.0) const;
00372 
00388     char* GetTimeString 
00389     (
00390         char* pTimeString,  
00391         int pInfo=5, 
00392         int pTimeMode=eDEFAULT_MODE, 
00393         int pTimeFormat=eDEFAULT_PROTOCOL,
00394         double pFramerate = 0.0
00395     ) const;
00396 
00409     void SetTimeString(char* pTime, int pTimeMode=eDEFAULT_MODE, int pTimeFormat=eDEFAULT_PROTOCOL, double pFramerate = 0.0);
00410 
00412 
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  
00452     inline bool operator<(const KTime& pTime) const {return mTime < pTime.mTime;} 
00453 
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     inline KTime& operator-=(const KTime& pTime) {mTime -= pTime.mTime; return *this;}
00470     
00475     KTime operator+(const KTime& pTime) const;
00476 
00481     KTime operator-(const KTime& pTime) const;
00482 
00487     KTime operator*(const int Mult) const;
00488 
00493     KTime operator/(const KTime &pTime) const;
00494 
00499     KTime operator*(const KTime &pTime) const;
00500 
00502     inline KTime &operator++() {mTime += 1; return (*this);}
00503 
00505     inline const KTime operator++(int) {KTime lOld = *this; ++(*this); return lOld;}
00506 
00508     inline KTime &operator--() {mTime -= 1; return (*this);}
00509 
00511     inline const KTime operator--(int) {KTime lOld = *this; --(*this); return lOld;}
00512 
00514     static KTime GetSystemTimer();
00516     //
00517     //  WARNING!
00518     //
00519     //  Anything beyond these lines may not be documented accurately and is 
00520     //  subject to change without notice.
00521     //
00523 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00524 private:
00525     kLongLong mTime; // In 1/46, 186, 158, 000 Seconds
00526 
00527     static ETimeMode gsGlobalTimeMode;
00528     static ETimeProtocol gsGlobalTimeProtocol;
00529     static KTimeModeObject* gsTimeObject;
00530 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00531     
00532     // Global Friend Function
00533     friend KFBX_DLL KTime::ETimeMode        KTime_GetGlobalTimeMode();
00534     friend KFBX_DLL HKTimeModeObject        KTime_GetGlobalTimeModeObject();
00535     friend KFBX_DLL KTime::ETimeProtocol    KTime_GetGlobalTimeFormat();
00536     friend KFBX_DLL void                    KTime_SetGlobalTimeMode( KTime::ETimeMode pTimeMode, double pFrameRate=0.0 );
00537     friend KFBX_DLL void                    KTime_SetGlobalTimeFormat( KTime::ETimeProtocol pTimeFormat );
00538 
00539     inline kLongLong GetOneFrameValue ( int pTimeMode, double pFramerate ) const;
00540 };
00541 
00542 #define KTS_FORWARD 1
00543 #define KTS_BACKWARD -1
00544 
00549 class KFBX_DLL KTimeSpan
00550 {
00551 public:
00553     KTimeSpan() {}
00554 
00559     KTimeSpan(KTime pStart, KTime pStop) {mStart=pStart; mStop=pStop;}
00560 
00565     inline void Set(KTime pStart, KTime pStop) {mStart=pStart; mStop=pStop;}
00566 
00570     inline void SetStart(KTime pStart) {mStart=pStart;}
00571     
00575     inline void SetStop(KTime pStop) {mStop=pStop;}
00576     
00580     inline KTime &GetStart() {return mStart;}
00581     
00585     inline KTime &GetStop() {return mStop;}
00586     
00590     inline KTime GetDuration() const {if (mStop>mStart)return mStop-mStart; else return mStart-mStop;}
00591     
00595     inline KTime GetSignedDuration() const {return mStop-mStart;}
00596     
00600     inline int GetDirection() const {if (mStop>=mStart)return KTS_FORWARD; else return KTS_BACKWARD;}
00601 
00606     bool operator&(KTime &pTime) const;
00607     
00612     KTimeSpan operator&(KTimeSpan &pTime) const;
00613 
00618     bool operator!=(KTimeSpan &pTime);
00619 
00620     
00622     //
00623     //  WARNING!
00624     //
00625     //  Anything beyond these lines may not be documented accurately and is 
00626     //  subject to change without notice.
00627     //
00629 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00630 private:
00631     KTime mStart;
00632     KTime mStop;
00633 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00634 };
00635 
00651 enum EOldTimeMode
00652 {
00653     eOLD_DEFAULT_MODE,      
00654     eOLD_CINEMA,            
00655     eOLD_PAL,               
00656     eOLD_FRAMES30,          
00657     eOLD_NTSC_DROP_FRAME,   
00658     eOLD_FRAMES50,          
00659     eOLD_FRAMES60,          
00660     eOLD_FRAMES100,         
00661     eOLD_FRAMES120,         
00662     eOLD_NTSC_FULL_FRAME,   
00663     eOLD_FRAMES30_DROP,     
00664     eOLD_FRAMES1000,        
00665     eOLD_TIME_MODE_COUNT
00666 };
00667 
00668 class KFBX_DLL KTimeModeObject
00669 {
00670 public:
00671     double              mFrameRateValue;
00672     char*               mFrameRateString;
00673     KTime::ETimeMode    mTimeMode;
00674     EOldTimeMode        mOldTimeMode;
00675     char*               mTimeModeString;
00676     int                 mShowValue;     
00677 
00678     bool                mSystemRate;    
00679     bool                mExistInOldValue;
00680     kLongLong           mOneFrameValue;  
00681 };
00682 
00683 
00684 KFBX_DLL KTime::ETimeMode       KTime_GetGlobalTimeMode();
00685 KFBX_DLL HKTimeModeObject       KTime_GetGlobalTimeModeObject();
00686 KFBX_DLL KTime::ETimeProtocol   KTime_GetGlobalTimeFormat();
00687 KFBX_DLL void                   KTime_SetGlobalTimeMode(KTime::ETimeMode pTimeMode, double pFrameRate);
00688 KFBX_DLL void                   KTime_SetGlobalTimeFormat(KTime::ETimeProtocol pTimeFormat);
00689 //
00690 // Use those functions to keep the compatibility with old time mode since we added new time mode.
00691 //
00692 KFBX_DLL int                    KTime_GetOldTimeModeCorrespondance(KTime::ETimeMode pNewTimeMode);
00693 KFBX_DLL int                    KTime_GetTimeModeFromOldValue(int pOldTimeMode);
00694 //
00695 // We now store the framerate instead of the time mode.
00696 //
00697 KFBX_DLL int                    KTime_GetTimeModeFromFrameRate(char* pFrameRate);
00698 KFBX_DLL void                   KTime_GetControlStringList(char* pControlString, KTime::ETimeProtocol pTimeFormat);
00699 KFBX_DLL char*                  KTime_GetGlobalFrameRateString(KTime::ETimeMode pTimeMode);
00700 KFBX_DLL char*                  KTime_GetGlobalTimeModeString(KTime::ETimeMode pTimeMode);
00701 KFBX_DLL double                 KTime_GetFrameRate(KTime::ETimeMode pTimeMode);
00702 //
00703 // Time format
00704 //
00705 KFBX_DLL int                    KTime_SelectionToTimeFormat(int pSelection);
00706 KFBX_DLL int                    KTime_SelectionToTimeMode(int pSelection);
00707 KFBX_DLL int                    KTime_TimeToSelection(int pTimeMode=KTime::eDEFAULT_MODE, int pTimeFormat=KTime::eDEFAULT_PROTOCOL);
00708 KFBX_DLL char*                  KTime_GetTimeModeName(int pTimeMode);
00709 KFBX_DLL int                    KTime_GetFrameRateStringListIndex(KTime::ETimeMode pTimeMode);
00710 KFBX_DLL bool                   KTime_IsValidCustomFramerate(double pFramerate);
00711 KFBX_DLL bool                   KTime_GetNearestCustomFramerate(double pFramerate, double& pNearestRate);
00712 
00713 // Compatibility Only
00714 // Ideally, we want to make this go away :)
00715 #define DEFAULT_MODE        KTime::eDEFAULT_MODE
00716 #define CINEMA              KTime::eCINEMA
00717 #define PAL                 KTime::ePAL
00718 #define FRAMES30            KTime::eFRAMES30
00719 #define NTSC_DROP_FRAME     KTime::eNTSC_DROP_FRAME
00720 #define FRAMES50            KTime::eFRAMES50    
00721 #define FRAMES60            KTime::eFRAMES60
00722 #define FRAMES100           KTime::eFRAMES100
00723 #define FRAMES120           KTime::eFRAMES120
00724 #define NTSC_FULL_FRAME     KTime::eNTSC_FULL_FRAME
00725 #define FRAMES30_DROP       KTime::eFRAMES30_DROP
00726 #define FRAMES1000          KTime::eFRAMES1000
00727 #define TIMEFORMAT_SMPTE    KTime::eSMPTE
00728 #define TIMEFORMAT_FRAME    KTime::eFRAME
00729 #define DEFAULT_FORMAT      KTime::eDEFAULT_PROTOCOL
00730 
00731 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00732 
00733 #endif // FBXFILESDK_COMPONENTS_KBASELIB_KLIB_KTIME_H
00734