FBX SDK Reference Guide: ktime.h Source File
Go to the documentation of this file.
00001 
00004 #ifndef _FBXSDK_KTIME_H_
00005 #define _FBXSDK_KTIME_H_
00006 
00007 /**************************************************************************************
00008 
00009  Copyright  2001 - 2008 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 
00042 #include <kbaselib_h.h>
00043 
00044 #include <kbaselib_nsbegin.h>
00045 
00046     //
00047     // Basic constants.
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 K_FORWARD ( KTimeModeObject );
00061 
00065     class KBASELIB_DLL KTime 
00066     {
00067 
00068     public:
00069 
00073         KTime(kLongLong pTime=0) {mTime=pTime;}
00074 
00079 
00101         //
00102         // *** Affected files when adding new enum values ***
00103         // (ktimeinline.h kfcurveview.cxx, kaudioview.cxx, kvideoview.cxx, kttimespanviewoptical.cxx,
00104         //  kttimespanview.cxx, ktcameraswitchertimelinecontrol.cxx, fbxsdk(fpproperties.cxx) )
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 
00310         // Return a Time Snapped on the NEAREST(rounded) Frame (if asked)
00311         KTime   GetFramedTime(bool pRound = true);
00312 
00319     kLongLong GetHour(bool pCummul=false, int pTimeMode=eDEFAULT_MODE, double pFramerate=0.0) const;
00320         
00328     kLongLong GetMinute(bool pCummul=false, int pTimeMode=eDEFAULT_MODE, double pFramerate=0.0) const;
00329         
00337     kLongLong GetSecond(bool pCummul=false, int pTimeMode=eDEFAULT_MODE, double pFramerate=0.0) const;
00338         
00346     kLongLong GetFrame(bool pCummul=false, int pTimeMode=eDEFAULT_MODE, double pFramerate=0.0) const;
00347         
00355     kLongLong GetField(bool pCummul=false, int pTimeMode=eDEFAULT_MODE, double pFramerate=0.0) const;
00356 
00362     kLongLong GetResidual(int pTimeMode=eDEFAULT_MODE, double pFramerate=0.0) const;
00363 
00379         char* GetTimeString 
00380         (
00381             char* pTimeString,  
00382             int pInfo=5, 
00383             int pTimeMode=eDEFAULT_MODE, 
00384         int pTimeFormat=eDEFAULT_PROTOCOL,
00385         double pFramerate = 0.0
00386 
00387         ) const;
00388 
00401     void SetTimeString(char* pTime, int pTimeMode=eDEFAULT_MODE, int pTimeFormat=eDEFAULT_PROTOCOL, double pFramerate = 0.0);
00402 
00404 
00409      
00411         inline bool operator==(const KTime& pTime) const {return mTime == pTime.mTime;}
00412 
00414         inline bool operator!=(const KTime& pTime) const {return mTime != pTime.mTime;}
00415 
00417         inline bool operator>=(const KTime& pTime) const {return mTime >= pTime.mTime;}
00418 
00420         inline bool operator<=(const KTime& pTime) const {return mTime <= pTime.mTime;}
00421 
00423         inline bool operator>(const KTime& pTime) const {return mTime > pTime.mTime;}
00424      
00426         inline bool operator<(const KTime& pTime) const {return mTime < pTime.mTime;} 
00427 
00429         inline KTime& operator=(const KTime& pTime) {mTime = pTime.mTime; return *this;}
00430         
00432         inline KTime& operator+=(const KTime& pTime) {mTime += pTime.mTime; return *this;}
00433         
00435         inline KTime& operator-=(const KTime& pTime) {mTime -= pTime.mTime; return *this;}
00436         
00438         KTime operator+(const KTime& pTime) const;
00439 
00441         KTime operator-(const KTime& pTime) const;
00442 
00444         KTime operator*(const int Mult) const;
00445 
00447         KTime operator/(const KTime &pTime) const;
00448 
00450         KTime operator*(const KTime &pTime) const;
00451 
00453         inline KTime &operator++() {mTime += 1; return (*this);}
00454 
00456         inline KTime &operator--() {mTime -= 1; return (*this);}
00457 
00459         static KTime GetSystemTimer();
00461     //
00462     //  WARNING!
00463     //
00464     //  Anything beyond these lines may not be documented accurately and is 
00465     //  subject to change without notice.
00466     //
00468 
00469     #ifndef DOXYGEN_SHOULD_SKIP_THIS
00470 
00471     private:
00472 
00473         kLongLong mTime; // In 1/46, 186, 158, 000 Seconds
00474 
00475         static ETimeMode gsGlobalTimeMode;
00476         static ETimeProtocol gsGlobalTimeProtocol;
00477         static KTimeModeObject* gsTimeObject;
00478 
00479     #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00480         
00481         // Global Friend Function
00482         friend KBASELIB_DLL KTime::ETimeMode        KTime_GetGlobalTimeMode();
00483         friend KBASELIB_DLL HKTimeModeObject        KTime_GetGlobalTimeModeObject();
00484         friend KBASELIB_DLL KTime::ETimeProtocol    KTime_GetGlobalTimeFormat();
00485         friend KBASELIB_DLL void                    KTime_SetGlobalTimeMode( KTime::ETimeMode pTimeMode, double pFrameRate=0.0 );
00486         friend KBASELIB_DLL void                    KTime_SetGlobalTimeFormat( KTime::ETimeProtocol pTimeFormat );
00487 
00488         inline kLongLong GetOneFrameValue ( int pTimeMode, double pFramerate ) const;
00489 
00490     };
00491 
00492 
00493     #define KTS_FORWARD 1
00494     #define KTS_BACKWARD -1
00495 
00496 #define KTIMESPAN_INFINITE          KTimeSpan (KTIME_MINUS_INFINITE, KTIME_INFINITE)
00497 
00501     class KBASELIB_DLL KTimeSpan
00502     {
00503 
00504     public:
00505 
00507         KTimeSpan() {}
00508 
00513         KTimeSpan(KTime pStart, KTime pStop) {mStart=pStart; mStop=pStop;}
00514 
00519         inline void Set(KTime pStart, KTime pStop) {mStart=pStart; mStop=pStop;}
00520 
00524         inline void SetStart(KTime pStart) {mStart=pStart;}
00525         
00529         inline void SetStop(KTime pStop) {mStop=pStop;}
00530         
00534         inline KTime &GetStart() {return mStart;}
00535         
00539         inline KTime &GetStop() {return mStop;}
00540         
00544         inline KTime GetDuration() const {if (mStop>mStart)return mStop-mStart; else return mStart-mStop;}
00545         
00549         inline KTime GetSignedDuration() const {return mStop-mStart;}
00550         
00554         inline int GetDirection() const {if (mStop>=mStart)return KTS_FORWARD; else return KTS_BACKWARD;}
00555 
00557         bool operator&(KTime &pTime) const;
00558         
00560         KTimeSpan operator&(KTimeSpan &pTime) const;
00561 
00563         bool operator!=(KTimeSpan &pTime);
00564 
00565         
00567     //
00568     //  WARNING!
00569     //
00570     //  Anything beyond these lines may not be documented accurately and is 
00571     //  subject to change without notice.
00572     //
00574 
00575     #ifndef DOXYGEN_SHOULD_SKIP_THIS
00576 
00577     private:
00578 
00579         KTime mStart;
00580         KTime mStop;
00581 
00582     #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00583 
00584     };
00585 
00586 
00587 
00603 enum EOldTimeMode
00604 {
00605     eOLD_DEFAULT_MODE,      
00606     eOLD_CINEMA,            
00607     eOLD_PAL,               
00608     eOLD_FRAMES30,          
00609     eOLD_NTSC_DROP_FRAME,   
00610     eOLD_FRAMES50,          
00611     eOLD_FRAMES60,          
00612     eOLD_FRAMES100,         
00613     eOLD_FRAMES120,         
00614     eOLD_NTSC_FULL_FRAME,   
00615     eOLD_FRAMES30_DROP,     
00616     eOLD_FRAMES1000,        
00617     eOLD_TIME_MODE_COUNT
00618 };
00619 
00620 class KBASELIB_DLL KTimeModeObject
00621 {
00622 public:
00623     double              mFrameRateValue;
00624     char*               mFrameRateString;
00625     KTime::ETimeMode    mTimeMode;
00626     EOldTimeMode        mOldTimeMode;
00627     char*               mTimeModeString;
00628     int                 mShowValue;     
00629 
00630     bool                mSystemRate;    
00631     bool                mExistInOldValue;
00632     kLongLong           mOneFrameValue;  
00633 };
00634 
00635 
00636     KBASELIB_DLL KTime::ETimeMode KTime_GetGlobalTimeMode ();
00637 KBASELIB_DLL HKTimeModeObject       KTime_GetGlobalTimeModeObject();
00638     KBASELIB_DLL KTime::ETimeProtocol KTime_GetGlobalTimeFormat ();
00639 KBASELIB_DLL void                   KTime_SetGlobalTimeMode (KTime::ETimeMode pTimeMode, double pFrameRate);
00640     KBASELIB_DLL void KTime_SetGlobalTimeFormat (KTime::ETimeProtocol pTimeFormat);
00641     //
00642     // Use those functions to keep the compatibility with old timemode since we added new timemode.
00643     //
00644     KBASELIB_DLL int KTime_GetOldTimeModeCorrespondance ( KTime::ETimeMode pNewTimeMode );
00645     KBASELIB_DLL int KTime_GetTimeModeFromOldValue ( int pOldTimeMode );
00646     //
00647     // We now store the framerate instead of the timemode.
00648     //
00649     KBASELIB_DLL int    KTime_GetTimeModeFromFrameRate   ( char* pFrameRate );
00650     KBASELIB_DLL void    KTime_GetControlStringList     ( char* pControlString, KTime::ETimeProtocol pTimeFormat);
00651     KBASELIB_DLL char* KTime_GetGlobalFrameRateString ( KTime::ETimeMode pTimeMode );
00652     KBASELIB_DLL char* KTime_GetGlobalTimeModeString  ( KTime::ETimeMode pTimeMode );
00653 KBASELIB_DLL double KTime_GetFrameRate ( KTime::ETimeMode pTimeMode );
00654     //
00655     // Time format
00656     //
00657     KBASELIB_DLL int   KTime_SelectionToTimeFormat (int pSelection);
00658     KBASELIB_DLL int   KTime_SelectionToTimeMode (int pSelection);
00659     KBASELIB_DLL int   KTime_TimeToSelection (int pTimeMode=KTime::eDEFAULT_MODE, int pTimeFormat=KTime::eDEFAULT_PROTOCOL);
00660     KBASELIB_DLL char*KTime_GetTimeModeName( int pTimeMode );
00661     KBASELIB_DLL int   KTime_GetFrameRateStringListIndex ( KTime::ETimeMode pTimeMode );
00662 KBASELIB_DLL bool  KTime_IsValidCustomFramerate    ( double pFramerate );
00663 KBASELIB_DLL bool  KTime_GetNearestCustomFramerate ( double pFramerate, double& pNearestRate );
00664 
00665     // Compatibility Only
00666     // Ideally, we want to make this go away :)
00667     #define DEFAULT_MODE    KTime::eDEFAULT_MODE
00668     #define CINEMA          KTime::eCINEMA
00669     #define PAL             KTime::ePAL
00670     #define FRAMES30        KTime::eFRAMES30
00671     #define NTSC_DROP_FRAME KTime::eNTSC_DROP_FRAME
00672     #define FRAMES50        KTime::eFRAMES50    
00673     #define FRAMES60        KTime::eFRAMES60
00674     #define FRAMES100       KTime::eFRAMES100
00675     #define FRAMES120       KTime::eFRAMES120
00676     #define NTSC_FULL_FRAME KTime::eNTSC_FULL_FRAME
00677     #define FRAMES30_DROP   KTime::eFRAMES30_DROP
00678     #define FRAMES1000      KTime::eFRAMES1000
00679 
00680     #define TIMEFORMAT_SMPTE  KTime::eSMPTE
00681     #define TIMEFORMAT_FRAME  KTime::eFRAME
00682     #define DEFAULT_FORMAT    KTime::eDEFAULT_PROTOCOL
00683 
00684 #include <kbaselib_nsend.h>
00685 
00686 #endif // #ifndef _FBXSDK_KTIME_H_
00687 
00688