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.

191 lines
6.1 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef DMETRACK_H
  7. #define DMETRACK_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "tier1/utlflags.h"
  12. #include "datamodel/dmelement.h"
  13. #include "datamodel/dmehandle.h"
  14. #include "movieobjects/dmeclip.h"
  15. //-----------------------------------------------------------------------------
  16. // Forward declarations
  17. //-----------------------------------------------------------------------------
  18. class CDmeClip;
  19. enum DmeClipType_t;
  20. //-----------------------------------------------------------------------------
  21. // Default track name
  22. //-----------------------------------------------------------------------------
  23. #define DMETRACK_DEFAULT_NAME "default"
  24. //-----------------------------------------------------------------------------
  25. // Constructor, destructor
  26. //-----------------------------------------------------------------------------
  27. class CDmeTrack : public CDmElement
  28. {
  29. DEFINE_ELEMENT( CDmeTrack, CDmElement );
  30. public:
  31. // Methods of IDmElement
  32. virtual void OnAttributeChanged( CDmAttribute *pAttribute );
  33. void SetCollapsed( bool state );
  34. bool IsCollapsed() const;
  35. void SetVolume( float state );
  36. float GetVolume() const;
  37. void SetMute( bool state );
  38. bool IsMute( bool bCheckSoloing = true ) const;
  39. // Is this track synched to the film track?
  40. void SetSynched( bool bState );
  41. bool IsSynched() const;
  42. int GetClipCount() const;
  43. CDmeClip *GetClip( int i ) const;
  44. const CUtlVector< DmElementHandle_t > &GetClips( ) const;
  45. void AddClip( CDmeClip *clip );
  46. bool RemoveClip( CDmeClip *clip );
  47. void RemoveClip( int i );
  48. void RemoveAllClips();
  49. int FindClip( CDmeClip *clip );
  50. CDmeClip *FindNamedClip( const char *name );
  51. DmeClipType_t GetClipType() const;
  52. void SetClipType( DmeClipType_t type );
  53. // Find clips at, intersecting or within a particular time interval
  54. void FindClipsAtTime( DmeTime_t time, DmeClipSkipFlag_t flags, CUtlVector< CDmeClip * >& clips ) const;
  55. void FindClipsIntersectingTime( DmeTime_t startTime, DmeTime_t endTime, DmeClipSkipFlag_t flags, CUtlVector< CDmeClip * >& clips ) const;
  56. void FindClipsWithinTime( DmeTime_t startTime, DmeTime_t endTime, DmeClipSkipFlag_t flags, CUtlVector< CDmeClip * >& clips ) const;
  57. // Methods to shift clips around
  58. // These methods shift clips that straddle the start/end time (NOTE: time is measured in local time)
  59. // NOTE: bTestStartingTime true means if the starting time is after the start time, then shift
  60. // Setting it to false means if the clip intersects the time at all, then shift
  61. void ShiftAllClipsAfter ( DmeTime_t startTime, DmeTime_t dt, bool bTestStartingTime = true );
  62. void ShiftAllClipsBefore( DmeTime_t endTime, DmeTime_t dt, bool bTestEndingTime = true );
  63. void ShiftAllClips( DmeTime_t dt );
  64. // A version that works only on film clips
  65. void ShiftAllFilmClipsAfter ( CDmeClip *pClip, DmeTime_t dt, bool bShiftClip = false );
  66. void ShiftAllFilmClipsBefore( CDmeClip *pClip, DmeTime_t dt, bool bShiftClip = false );
  67. // Sorts all children so they ascend in time
  68. void SortClipsByStartTime( );
  69. // Shifts all clips to be non-overlapping
  70. void FixOverlaps();
  71. // Can this track contain clips that overlap in time?
  72. // NOTE: Non-overlapping clips will be
  73. bool IsNonoverlapping() const;
  74. // Is this a film track?
  75. bool IsFilmTrack() const;
  76. // Returns the next/previous clip in a film track
  77. CDmeClip* FindPrevFilmClip( CDmeClip *pClip );
  78. CDmeClip* FindNextFilmClip( CDmeClip *pClip );
  79. void FindAdjacentFilmClips( CDmeClip *pClip, CDmeClip *&pPrevClip, CDmeClip *&pNextClip );
  80. void FindAdjacentFilmClips( DmeTime_t localTime, CDmeClip *&pPrevClip, CDmeClip *&pNextClip );
  81. // Finds a clip at a particular time
  82. CDmeClip* FindFilmClipAtTime( DmeTime_t localTime );
  83. // Find first clip that intersects a specific time range
  84. CDmeClip* FindFirstFilmClipIntesectingTime( DmeTime_t localStartTime, DmeTime_t localEndTime );
  85. // Inserts space in a film track for a film clip
  86. void InsertSpaceInFilmTrack( DmeTime_t localStartTime, DmeTime_t localEndTime );
  87. // Singleton solo track (of the same clip type that this track is)
  88. CDmeTrack *GetSoloTrack( ) const;
  89. void SetSoloTrack( );
  90. bool IsSoloTrack() const;
  91. static CDmeTrack *GetSoloTrack( DmeClipType_t clipType );
  92. static void SetSoloTrack( DmeClipType_t clipType, CDmeTrack *pTrack );
  93. // Fills all gaps in a film track with slugs
  94. void FillAllGapsWithSlugs( const char *pSlugName, DmeTime_t startTime, DmeTime_t endTime );
  95. private:
  96. class CSuppressAutoFixup
  97. {
  98. public:
  99. CSuppressAutoFixup( CDmeTrack *pTrack, int nFlags ) : m_pTrack( pTrack ), m_nFlags( nFlags )
  100. {
  101. m_pTrack->m_Flags.SetFlag( m_nFlags );
  102. }
  103. ~CSuppressAutoFixup()
  104. {
  105. m_pTrack->m_Flags.ClearFlag( m_nFlags );
  106. }
  107. private:
  108. CDmeTrack *m_pTrack;
  109. int m_nFlags;
  110. };
  111. enum
  112. {
  113. IS_SORTED = 0x1,
  114. SUPPRESS_OVERLAP_FIXUP = 0x2,
  115. SUPPRESS_DIRTY_ORDERING = 0x4,
  116. };
  117. CDmaElementArray< CDmeClip > m_Clips;
  118. CDmaVar< float > m_Volume;
  119. CDmaVar< bool > m_Collapsed;
  120. CDmaVar< bool > m_Mute;
  121. CDmaVar< bool > m_Synched;
  122. CDmaVar< int > m_ClipType;
  123. CUtlFlags< unsigned char > m_Flags;
  124. DmElementHandle_t m_hOwner;
  125. static DmElementHandle_t m_hSoloTrack[DMECLIP_TYPE_COUNT];
  126. friend class CSuppressAutoFixup;
  127. };
  128. //-----------------------------------------------------------------------------
  129. // Indicates whether tracks contain clips that are non-overlapping in time
  130. //-----------------------------------------------------------------------------
  131. inline bool CDmeTrack::IsNonoverlapping() const
  132. {
  133. return m_ClipType == DMECLIP_FILM;
  134. }
  135. //-----------------------------------------------------------------------------
  136. // Is this a film track?
  137. //-----------------------------------------------------------------------------
  138. inline bool CDmeTrack::IsFilmTrack() const
  139. {
  140. return m_ClipType == DMECLIP_FILM;
  141. }
  142. //-----------------------------------------------------------------------------
  143. // helper methods
  144. //-----------------------------------------------------------------------------
  145. CDmeTrackGroup *GetParentTrackGroup( CDmeTrack *pTrack );
  146. #endif // DMETRACK_H