Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

249 lines
7.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef DMETRACKGROUP_H
  7. #define DMETRACKGROUP_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier1/utlflags.h"
  12. #include "datamodel/dmelement.h"
  13. #include "datamodel/dmattribute.h"
  14. #include "datamodel/dmattributevar.h"
  15. #include "datamodel/dmehandle.h"
  16. #include "movieobjects/timeutils.h"
  17. //-----------------------------------------------------------------------------
  18. // Forward declarations
  19. //-----------------------------------------------------------------------------
  20. class CDmeClip;
  21. class CDmeFilmClip;
  22. class CDmeTrack;
  23. enum DmeClipType_t;
  24. enum DmeClipSkipFlag_t;
  25. //-----------------------------------------------------------------------------
  26. // Default track group name
  27. //-----------------------------------------------------------------------------
  28. #define DMETRACKGROUP_DEFAULT_NAME "default"
  29. //-----------------------------------------------------------------------------
  30. // A track group
  31. //-----------------------------------------------------------------------------
  32. class CDmeTrackGroup : public CDmElement
  33. {
  34. DEFINE_ELEMENT( CDmeTrackGroup, CDmElement );
  35. public:
  36. // Max track count
  37. void SetMaxTrackCount( int nCount );
  38. // Owning clip
  39. CDmeClip *GetOwnerClip();
  40. void SetOwnerClip( CDmeClip *pClip );
  41. // track helper methods
  42. void AddTrack( CDmeTrack *track );
  43. CDmeTrack* AddTrack( const char *pTrackName, DmeClipType_t trackType );
  44. CDmeTrack* FindOrAddTrack( const char *pTrackName, DmeClipType_t trackType );
  45. void RemoveTrack( CDmeTrack *track );
  46. void RemoveTrack( const char *pTrackName );
  47. void RemoveTrack( int nIndex );
  48. const CUtlVector< DmElementHandle_t > &GetTracks( ) const;
  49. int GetTrackCount( ) const;
  50. CDmeTrack *GetTrack( int nIndex ) const;
  51. CDmeTrack *FindTrack( const char *pTrackName ) const;
  52. int GetTrackIndex( CDmeTrack *pTrack ) const;
  53. // Clip helper methods
  54. // AddClip/ChangeTrack returns non-NULL if it was successfully added
  55. CDmeTrack *AddClip( CDmeClip *pClip, const char *pTrackName );
  56. bool RemoveClip( CDmeClip *pClip );
  57. CDmeTrack *ChangeTrack( CDmeClip *pClip, const char *pNewTrack );
  58. CDmeTrack *FindTrackForClip( CDmeClip *pClip ) const;
  59. bool FindTrackForClip( CDmeClip *pClip, int *pTrackIndex, int *pClipIndex = NULL ) const;
  60. // Finding clips at a particular time
  61. void FindClipsAtTime( DmeClipType_t clipType, DmeTime_t time, DmeClipSkipFlag_t flags, CUtlVector< CDmeClip * >& clips ) const;
  62. void FindClipsIntersectingTime( DmeClipType_t clipType, DmeTime_t startTime, DmeTime_t endTime, DmeClipSkipFlag_t flags, CUtlVector< CDmeClip * >& clips ) const;
  63. void FindClipsWithinTime( DmeClipType_t clipType, DmeTime_t startTime, DmeTime_t endTime, DmeClipSkipFlag_t flags, CUtlVector< CDmeClip * >& clips ) const;
  64. // Are we a film track group?
  65. bool IsFilmTrackGroup();
  66. // Gets the film track (if this is a film track group)
  67. CDmeTrack *GetFilmTrack();
  68. // Is a particular clip typed able to be added?
  69. bool IsSubClipTypeAllowed( DmeClipType_t type );
  70. // Is this track group visible?
  71. void SetVisible( bool bVisible );
  72. bool IsVisible() const;
  73. // Is this track group minimized?
  74. void SetMinimized( bool bLocked );
  75. bool IsMinimized() const;
  76. // Track group display size
  77. void SetDisplaySize( int nDisplaySize );
  78. int GetDisplaySize() const;
  79. // Creates the film track group [for internal use only]
  80. CDmeTrack *CreateFilmTrack();
  81. // Sort tracks by track type, then alphabetically
  82. void SortTracksByType();
  83. // Removes empty tracks
  84. void RemoveEmptyTracks();
  85. // Muting track groups
  86. void SetMute( bool state );
  87. bool IsMute( ) const;
  88. // Volume for track group
  89. void SetVolume( float state );
  90. float GetVolume() const;
  91. // Returns the flattened clip count
  92. int GetSubClipCount() const;
  93. void GetSubClips( CDmeClip **ppClips );
  94. private:
  95. CDmaElementArray< CDmeTrack > m_Tracks;
  96. CDmaVar<bool> m_bIsVisible;
  97. CDmaVar<bool> m_bMinimized;
  98. CDmaVar< bool > m_bMute;
  99. CDmaVar< float > m_Volume;
  100. CDmaVar<int> m_nDisplaySize;
  101. DmElementHandle_t m_hOwner;
  102. int m_nMaxTrackCount;
  103. };
  104. //-----------------------------------------------------------------------------
  105. // Inline methods
  106. //-----------------------------------------------------------------------------
  107. inline int CDmeTrackGroup::GetTrackCount( ) const
  108. {
  109. return m_Tracks.Count();
  110. }
  111. inline CDmeTrack *CDmeTrackGroup::GetTrack( int nIndex ) const
  112. {
  113. return m_Tracks[nIndex];
  114. }
  115. inline const CUtlVector< DmElementHandle_t > &CDmeTrackGroup::GetTracks( ) const
  116. {
  117. return m_Tracks.Get();
  118. }
  119. //-----------------------------------------------------------------------------
  120. // Is this track group visible?
  121. //-----------------------------------------------------------------------------
  122. inline void CDmeTrackGroup::SetVisible( bool bVisible )
  123. {
  124. m_bIsVisible = bVisible;
  125. }
  126. inline bool CDmeTrackGroup::IsVisible() const
  127. {
  128. return m_bIsVisible;
  129. }
  130. //-----------------------------------------------------------------------------
  131. // Is this track group minimized?
  132. //-----------------------------------------------------------------------------
  133. inline void CDmeTrackGroup::SetMinimized( bool bMinimized )
  134. {
  135. m_bMinimized = bMinimized;
  136. }
  137. inline bool CDmeTrackGroup::IsMinimized() const
  138. {
  139. return m_bMinimized;
  140. }
  141. //-----------------------------------------------------------------------------
  142. // Track group display size
  143. //-----------------------------------------------------------------------------
  144. inline void CDmeTrackGroup::SetDisplaySize( int nDisplaySize )
  145. {
  146. m_nDisplaySize = nDisplaySize;
  147. }
  148. inline int CDmeTrackGroup::GetDisplaySize() const
  149. {
  150. return m_nDisplaySize;
  151. }
  152. //-----------------------------------------------------------------------------
  153. // Iterator macro
  154. //-----------------------------------------------------------------------------
  155. #define DMETRACKGROUP_FOREACH_CLIP_START( _dmeTrackGroup, _dmeTrack, _dmeClip ) \
  156. { \
  157. int _tc = (_dmeTrackGroup)->GetTrackCount(); \
  158. for ( int _i = 0; _i < _tc; ++_i ) \
  159. { \
  160. CDmeTrack *_dmeTrack = (_dmeTrackGroup)->GetTrack( _i ); \
  161. if ( !_dmeTrack ) \
  162. continue; \
  163. \
  164. int _cc = _dmeTrack->GetClipCount(); \
  165. for ( int _j = 0; _j < _cc; ++_j ) \
  166. { \
  167. CDmeClip *_dmeClip = _dmeTrack->GetClip( _j ); \
  168. if ( !_dmeClip ) \
  169. continue;
  170. #define DMETRACKGROUP_FOREACH_CLIP_END( ) \
  171. } \
  172. } \
  173. }
  174. #define DMETRACKGROUP_FOREACH_CLIP_TYPE_START( _clipType, _dmeTrackGroup, _dmeTrack, _dmeClip ) \
  175. { \
  176. int _tc = (_dmeTrackGroup)->GetTrackCount(); \
  177. for ( int _i = 0; _i < _tc; ++_i ) \
  178. { \
  179. CDmeTrack *_dmeTrack = (_dmeTrackGroup)->GetTrack( _i ); \
  180. if ( !_dmeTrack ) \
  181. continue; \
  182. \
  183. if ( _dmeTrack->GetClipType() != CDmeClipInfo< _clipType >::ClipType() ) \
  184. continue; \
  185. \
  186. int _cc = _dmeTrack->GetClipCount(); \
  187. for ( int _j = 0; _j < _cc; ++_j ) \
  188. { \
  189. _clipType *_dmeClip = static_cast< _clipType* >( _dmeTrack->GetClip( _j ) ); \
  190. if ( !_dmeClip ) \
  191. continue;
  192. #define DMETRACKGROUP_FOREACH_CLIP_TYPE_END( ) \
  193. } \
  194. } \
  195. }
  196. //-----------------------------------------------------------------------------
  197. // helper methods
  198. //-----------------------------------------------------------------------------
  199. CDmeFilmClip *GetParentClip( CDmeTrackGroup *pTrackGroup );
  200. #endif // DMETRACKGROUP_H