Veda/PackList_TimeTrack.h

Go to the documentation of this file.
00001 /*! \file 
00002     \author victorien ferry & www.m4nkind.com
00003     \brief This file applies the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1 , read file COPYING.
00004 */
00005 #ifndef COM_M4NKIND_PackList_TimeTrack_H
00006 #define COM_M4NKIND_PackList_TimeTrack_H
00007 
00008 #include "PackList.h"
00009 #include "PackFloat_FixedPoint.h"
00010 #include "PackLong.h"
00011 /*!
00012     \class  PackList_TimeTrack
00013     \ingroup    BaseSerializableClass
00014     \brief   List that defines a set of TimeTrackElement extended objects.
00015                 Each elements define when they begin, when they end, and
00016                 an order number, which is different from zero if another element
00017                 is in the same time range.          
00018             The Goal with this class is to unify the ways to create timed lists,
00019             that can be managed by a single GUI gadget for script or spline management.
00020             It was actually made to be used in spline key list, a script manager 
00021             this is only a simple serializable class.
00022 */
00023 
00024 class PackList_TimeTrack : public PackList
00025 {
00026 /*==================================================================
00027                                 PUBLIC
00028 ==================================================================*/
00029 public:
00030     class TimeTrackElement;
00031     //! TimeTrackElementCreatorCallBackFunction stands for a pointer to a static method that make a new TimeTrackElement.
00032     typedef TimeTrackElement *(*TimeTrackElementCreatorCallBackFunction)(void);
00033 
00034     /*!
00035         \brief  Constructor. Like PAckList you specify an element constructor,
00036                 and the meaning of time by elements. Dates and length are then given in seconds.
00037         \param _func a function that return a new object to manage as an element of the list.
00038         \param _SerializeLengthBlock    if false, the date in seconds is serialized by elements,if true, the length of elements is serialized.
00039     */
00040     PackList_TimeTrack( TimeTrackElementCreatorCallBackFunction _func /*,bool _SerializeLengthBlock=false*/);
00041 
00042 #ifdef _ENGINE_EDITABLE_
00043     /*!
00044         \brief  Each BaseType's inherited classes must explicit an ID for their
00045                 class, or let use one of the super class at least through this virtual method.
00046                 This is needed by GUIs to detect the types of each sub-members, and shape
00047                 an interface for each Object according to their member list.
00048         \return a const character string, that must be unique and unchanged for all serializable base type.
00049     */
00050     virtual const char *GetClassID() const { return "PackList::PackList_TimeTrack"; };
00051 #endif
00052 #ifdef _ENGINE_EDITABLE_
00053     /*!
00054         \brief  Edition tool: Exchange 2 neighbour elements in the list, if there is a next element.
00055                 if index is 0, 0 will be 1 and 1 will be 0.
00056         \param  _indexOfElementToSwapWithNext any row, from zero to GetNumberOfCell()-2
00057     */
00058     virtual  void   SwapElements( unsigned int _indexOfElementToSwapWithNext);
00059 #endif
00060     friend class TimeTrackElement;
00061     /*!
00062         \brief  Nested class that describe a dated element in the list. 
00063                 It has to be extended with new serializable members (ex: splines, scripts, music tracks..).
00064                 It manages the fact that the time are kept sorted in edition mode.
00065     */
00066     class TimeTrackElement : public PackStruct
00067     {
00068     public:
00069             //! constructor:
00070             TimeTrackElement();
00071         #ifdef _ENGINE_EDITABLE_
00072             //! \brief Set the time in seconds in edition mode. It assures the dates are sorted.
00073             virtual void    SetTimeInSecond( double _timeSec );
00074         #endif
00075         //! \brief return the time date in second.
00076         inline float    GetTimeInSecond(){ return mSer_Time.Get() ; };
00077         #ifdef _ENGINE_EDITABLE_
00078             //! \brief Private use: In edition mode, used at cell creation:
00079             inline  void    SetListThatManageItAsACell(
00080                         PackList_TimeTrack  *_pList,
00081                         PackStruct::Cell            *_pCell
00082             ){  //m_pListThatManageItAsAElement = _pList ; 
00083                 m_pCellThatManageIt = _pCell ; 
00084             };
00085         #endif
00086 #ifdef _ENGINE_EDITABLE_
00087         /*!
00088             \brief  Nested class that patch the virtual PackFloat_FixedPoint::Set()
00089             in edition mode, in order to force a test to assure that the elements
00090             of the list are kept sorted by time date when edited. (yes, it is tricky, but private.)
00091         */
00092         class PackFloat_FixedPoint_Time : public PackFloat_FixedPoint
00093         {public:
00094             PackFloat_FixedPoint_Time(float _fp) : PackFloat_FixedPoint(_fp){};
00095              virtual void   Set(float _value); 
00096             // void SetNotSorted(float _value); 
00097              inline void    SetElement(TimeTrackElement *_pElement){ m_pElement = _pElement; };
00098         protected:
00099             TimeTrackElement    *m_pElement;
00100         };
00101         friend class PackFloat_FixedPoint_Time;
00102 #else
00103         //in non-editable mode, the time date field in each element is a PackFloat_FixedPoint.
00104         typedef PackFloat_FixedPoint PackFloat_FixedPoint_Time;     
00105 #endif
00106 
00107         // ------------ PROTECTED -----------
00108     protected:
00109         //! the time in second, as serialized.
00110         PackFloat_FixedPoint_Time   mSer_Time;
00111 #ifdef _ENGINE_EDITABLE_
00112         //! in edition mode, the element must know the list that manage it:
00113         //PackList_TimeTrack    *m_pListThatManageItAsAElement;
00114         //! in edition mode, the element must know the Cell that manage it:
00115         PackStruct::Cell            *m_pCellThatManageIt;
00116 #endif
00117 
00118     };
00119     // too complex for gcc3.4.4! friend class TimeTrackElement::PackFloat_FixedPoint_Time;
00120 
00121     /*!
00122         \brief  Find the Cell which match a given date in the list. 
00123             It means the date is between this element and the next elment's date.
00124             Then get its TimeTrackElement with ->GetManagedObject().
00125         \param  _dateInSecond double date in second. 
00126         \return the element, or the first elt if date before.
00127     */
00128     virtual Cell *GetCellByDate( double _dateInSecond );
00129 #ifdef _ENGINE_EDITABLE_
00130     /*!
00131         \brief  Override PackList to assure the list is date-sorted.
00132                 Add a new element, at the given index, in edition context.
00133                 in non-editable, it shouldnt be used, and serialization recreate the elements.
00134              when asked a first element, as the track must have a length,
00135              we create 2 elements: a zero timed one, and a end with default time length.
00136 
00137         \param  _indexWhereToInsert the index where to insert. if -1, at the end.
00138         \param _pObjectToAdd object to manage, or NULL to set it after on the cell.
00139         \return  the element created.
00140     */
00141     virtual Cell * AddElement( int _indexWhereToInsert=-1,BaseType *_pObjectToAdd=0L);
00142 #endif
00143 #ifdef _ENGINE_EDITABLE_
00144     /*!
00145         \brief delete an element at a given index. It closes and destroys the object.
00146         \param _pObWhichCellIsToDestroy ob WhichCellIsToDestroy.
00147     */
00148     virtual void DeleteElement( BaseType *_pObWhichCellIsToDestroy);
00149 #endif
00150 
00151 #ifdef _ENGINE_EDITABLE_
00152     /*!
00153         \brief  Special patch in edition mode to add an init to the elements.
00154         \param  _pDescriptionChunk the objet description chunk. 
00155         \return the end of the chunk written, possibly unlocated. Don't use this if you don't need it.
00156     */
00157     virtual  const unsigned char * Serialize_In( const unsigned char * _pDescriptionChunk);
00158 #endif
00159     /*!
00160         \brief   returns the Total Time length of this media, in seconds, when played at 
00161                 normal speed. This is just an information about the time length of this media,
00162                 and you can pass any date to ProcessMedia().
00163         \return Total Time length of this media, in seconds, when played at normal speed. Can be used or not.
00164     */
00165     inline float    GetEndTime(){ 
00166         if( GetLastCell() ) return  ((TimeTrackElement *)GetLastCell()->GetManagedObject())->GetTimeInSecond();
00167         else return 0.0f;
00168     };
00169 /*==================================================================
00170                                 PROTECTED
00171 ==================================================================*/
00172 protected:
00173     //! if false, the date in seconds is serialized by elements,if true, the length of elements is serialized.
00174     //const bool m_SerializeLengthBlock;
00175 
00176     //! optimisation: GetCellByDate() keep the last searched Cell: most of the time, it is the same from a frame to another.
00177     Cell    *m_pLastCellFound;
00178 
00179 };
00180 // end of file
00181 #endif

      /\/\        4         N         k         !         N         D
                      _______  _ __ ___  _____            ___ _ _  ____
     ___________  __//___   /________  |/    / ___________\_______/    \
    /   _   _   \/   _     /    _   /      _/_/____/    _       __     /
   /    /   /       /     /    /    \      \/     /    /    \   \     /
  \\___/___/___/    ¯    _____/_____/       ______\___/_____/\________\\
               \________/_ ___ __ l____\      /elD!  
                 http://www.m4nkind.com \____/