Source code of Windows XP (NT5)
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.

253 lines
6.5 KiB

  1. //
  2. // bandtrk.h
  3. //
  4. // Copyright (c) 1997-2000 Microsoft Corporation
  5. //
  6. #ifndef BANDTRK_H
  7. #define BANDTRK_H
  8. #include "dmbndtrk.h"
  9. #include "dmbandp.h"
  10. class SeekEvent;
  11. struct IDirectMusicPerformance;
  12. class CRiffParser;
  13. //////////////////////////////////////////////////////////////////////
  14. // Class CBandTrk
  15. class CBandTrk : public IDirectMusicTrack8, public IDirectMusicBandTrk, public IPersistStream
  16. {
  17. friend CBand;
  18. public:
  19. // IUnknown
  20. //
  21. STDMETHODIMP QueryInterface(const IID &iid, void **ppv);
  22. STDMETHODIMP_(ULONG) AddRef();
  23. STDMETHODIMP_(ULONG) Release();
  24. // IPersist
  25. STDMETHODIMP GetClassID(CLSID* pClassID);
  26. // IPersistStream
  27. STDMETHODIMP IsDirty() {return S_FALSE;}
  28. STDMETHODIMP Load(IStream* pStream);
  29. STDMETHODIMP Save(IStream* pStream, BOOL fClearDirty) {return E_NOTIMPL;}
  30. STDMETHODIMP GetSizeMax(ULARGE_INTEGER* pcbSize) {return E_NOTIMPL;}
  31. // IDirectMusicTrack
  32. STDMETHODIMP Init(IDirectMusicSegment* pSegment);
  33. STDMETHODIMP InitPlay(IDirectMusicSegmentState* pSegmentState,
  34. IDirectMusicPerformance* pPerformance,
  35. void** ppStateData,
  36. DWORD dwVirtualTrackID,
  37. DWORD dwFlags);
  38. STDMETHODIMP EndPlay(void* pStateData);
  39. STDMETHODIMP Play(void* pStateData,
  40. MUSIC_TIME mtStart,
  41. MUSIC_TIME mtEnd,
  42. MUSIC_TIME mtOffset,
  43. DWORD dwFlags,
  44. IDirectMusicPerformance* pPerf,
  45. IDirectMusicSegmentState* pSegSt,
  46. DWORD dwVirtualID);
  47. STDMETHODIMP GetParam(REFGUID rguidDataType,
  48. MUSIC_TIME mtTime,
  49. MUSIC_TIME* pmtNext,
  50. void* pData);
  51. STDMETHODIMP SetParam(REFGUID rguidDataType,
  52. MUSIC_TIME mtTime,
  53. void* pData);
  54. STDMETHODIMP IsParamSupported(REFGUID rguidDataType);
  55. STDMETHODIMP AddNotificationType(REFGUID rguidNotify);
  56. STDMETHODIMP RemoveNotificationType(REFGUID rguidNotify);
  57. STDMETHODIMP Clone( MUSIC_TIME mtStart,
  58. MUSIC_TIME mtEnd,
  59. IDirectMusicTrack** ppTrack);
  60. // IDirectMusicTrack8
  61. STDMETHODIMP PlayEx(void* pStateData,REFERENCE_TIME rtStart,
  62. REFERENCE_TIME rtEnd,REFERENCE_TIME rtOffset,
  63. DWORD dwFlags,IDirectMusicPerformance* pPerf,
  64. IDirectMusicSegmentState* pSegSt,DWORD dwVirtualID) ;
  65. STDMETHODIMP GetParamEx(REFGUID rguidType,REFERENCE_TIME rtTime,
  66. REFERENCE_TIME* prtNext,void* pParam,void * pStateData, DWORD dwFlags) ;
  67. STDMETHODIMP SetParamEx(REFGUID rguidType,REFERENCE_TIME rtTime,void* pParam, void * pStateData, DWORD dwFlags) ;
  68. STDMETHODIMP Compose(IUnknown* pContext,
  69. DWORD dwTrackGroup,
  70. IDirectMusicTrack** ppResultTrack) ;
  71. STDMETHODIMP Join(IDirectMusicTrack* pNewTrack,
  72. MUSIC_TIME mtJoin,
  73. IUnknown* pContext,
  74. DWORD dwTrackGroup,
  75. IDirectMusicTrack** ppResultTrack) ;
  76. // IDirectMusicCommon
  77. STDMETHODIMP GetName(BSTR* pbstrName);
  78. // IDirectMusicBandTrk (Private Interface)
  79. STDMETHODIMP AddBand(DMUS_IO_PATCH_ITEM* BandEvent);
  80. STDMETHODIMP AddBand(IDirectMusicBand* pIDMBand);
  81. STDMETHODIMP SetGMGSXGMode(MUSIC_TIME mtTime, DWORD dwMidiMode)
  82. {
  83. TListItem<StampedGMGSXG>* pPair = new TListItem<StampedGMGSXG>;
  84. if (!pPair) return E_OUTOFMEMORY;
  85. pPair->GetItemValue().mtTime = mtTime;
  86. pPair->GetItemValue().dwMidiMode = dwMidiMode;
  87. TListItem<StampedGMGSXG>* pScan = m_MidiModeList.GetHead();
  88. TListItem<StampedGMGSXG>* pPrev = NULL;
  89. if(!pScan)
  90. {
  91. // Empty list
  92. m_MidiModeList.AddHead(pPair);
  93. }
  94. else
  95. {
  96. while(pScan && pPair->GetItemValue().mtTime > pScan->GetItemValue().mtTime)
  97. {
  98. pPrev = pScan;
  99. pScan = pScan->GetNext();
  100. }
  101. if(pPrev)
  102. {
  103. // Insert in the middle or end of list
  104. pPair->SetNext(pScan);
  105. pPrev->SetNext(pPair);
  106. }
  107. else
  108. {
  109. // Insert at beginning
  110. m_MidiModeList.AddHead(pPair);
  111. }
  112. }
  113. CBand* pBand = BandList.GetHead();
  114. for(; pBand; pBand = pBand->GetNext())
  115. {
  116. // only set bands affected by new mode
  117. if ( (pBand->m_lTimeLogical >= pPair->GetItemValue().mtTime) &&
  118. ( !pScan || pBand->m_lTimeLogical < pScan->GetItemValue().mtTime) )
  119. {
  120. pBand->SetGMGSXGMode(dwMidiMode);
  121. }
  122. }
  123. return S_OK;
  124. }
  125. // Class
  126. CBandTrk();
  127. ~CBandTrk();
  128. private:
  129. HRESULT BuildDirectMusicBandList(CRiffParser *pParser);
  130. HRESULT ExtractBand(CRiffParser *pParser);
  131. HRESULT LoadBand(IStream *pIStream, CBand* pBand);
  132. HRESULT LoadClone(IDirectMusicBandTrk* pBandTrack,
  133. MUSIC_TIME mtStart,
  134. MUSIC_TIME mtEnd);
  135. HRESULT InsertBand(CBand* pNewBand);
  136. HRESULT Seek(CBandTrkStateData* pBandTrkStateData,
  137. MUSIC_TIME mtStart,
  138. MUSIC_TIME mtOffset,
  139. REFERENCE_TIME rtOffset,
  140. bool fClockTime);
  141. HRESULT FindSEReplaceInstr(TList<SeekEvent>& SEList,
  142. DWORD dwPChannel,
  143. CBandInstrument* pInstrument);
  144. // Shared implentation of play for either music or clock time.
  145. HRESULT PlayMusicOrClock(
  146. void *pStateData,
  147. MUSIC_TIME mtStart,
  148. MUSIC_TIME mtEnd,
  149. MUSIC_TIME mtOffset,
  150. REFERENCE_TIME rtOffset,
  151. DWORD dwFlags,
  152. IDirectMusicPerformance* pPerf,
  153. IDirectMusicSegmentState* pSegSt,
  154. DWORD dwVirtualID,
  155. bool fClockTime);
  156. HRESULT CBandTrk::JoinInternal(
  157. IDirectMusicTrack* pNewTrack,
  158. MUSIC_TIME mtJoin,
  159. DWORD dwTrackGroup);
  160. private:
  161. CRITICAL_SECTION m_CriticalSection;
  162. BOOL m_fCSInitialized;
  163. DWORD m_dwValidate; // used to validate state data
  164. CBandList BandList;
  165. bool m_bAutoDownload;
  166. bool m_fLockAutoDownload; // if true, this flag indicates that we've specifically
  167. // commanded the band to autodownload. Otherwise,
  168. // it gets its preference from the performance via
  169. // GetGlobalParam.
  170. DWORD m_dwFlags;
  171. TList<StampedGMGSXG> m_MidiModeList; // List of time-stamped midi mode messages
  172. long m_cRef;
  173. };
  174. //////////////////////////////////////////////////////////////////////
  175. // Class BandTrkStateData
  176. class CBandTrkStateData
  177. {
  178. public:
  179. CBandTrkStateData() :
  180. m_pSegmentState(NULL),
  181. m_pPerformance(NULL),
  182. m_pNextBandToSPE(NULL),
  183. m_fPlayPreviousInSeek(FALSE),
  184. m_dwVirtualTrackID(0),
  185. dwValidate(0){}
  186. ~CBandTrkStateData(){}
  187. public:
  188. IDirectMusicSegmentState* m_pSegmentState;
  189. IDirectMusicPerformance* m_pPerformance;
  190. IDirectMusicBand* m_pNextBandToSPE;
  191. DWORD m_dwVirtualTrackID;
  192. BOOL m_fPlayPreviousInSeek;
  193. DWORD dwValidate;
  194. };
  195. //////////////////////////////////////////////////////////////////////
  196. // Class SeekEvent
  197. class SeekEvent
  198. {
  199. public:
  200. SeekEvent() :
  201. m_pParentBand(NULL),
  202. m_pInstrument(NULL),
  203. m_dwPChannel(0) {}
  204. ~SeekEvent(){}
  205. public:
  206. CBand* m_pParentBand;
  207. CBandInstrument* m_pInstrument;
  208. DWORD m_dwPChannel;
  209. };
  210. #endif // #ifndef BANDTRK_H