Counter Strike : Global Offensive Source Code
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.6 KiB

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