NotifyTool.cpp
上传用户:sycq158
上传日期:2008-10-22
资源大小:15361k
文件大小:6k
源码类别:

游戏

开发平台:

Visual C++

  1. //-----------------------------------------------------------------------------
  2. // File: notifytool.cpp
  3. //
  4. // Copyright (C) Microsoft Corporation. All Rights Reserved.
  5. //-----------------------------------------------------------------------------
  6. #include "stdafx.h"
  7. //-----------------------------------------------------------------------------
  8. // Name: CNotifyTool::CNotifyTool
  9. // Desc: 
  10. //-----------------------------------------------------------------------------
  11. CNotifyTool::CNotifyTool( CMyApplication* pApp )
  12. {
  13.     m_pApp = pApp;
  14.     m_cRef = 1; 
  15. }
  16. //-----------------------------------------------------------------------------
  17. // Name: CNotifyTool::QueryInterface()
  18. // Desc: 
  19. //-----------------------------------------------------------------------------
  20. STDMETHODIMP CNotifyTool::QueryInterface(const IID &iid, void **ppv)
  21. {
  22.     if (iid == IID_IUnknown || iid == IID_IDirectMusicTool)
  23.     {
  24.         *ppv = static_cast<IDirectMusicTool*>(this);
  25.     } 
  26.     else
  27.     {
  28.         *ppv = NULL;
  29.         return E_NOINTERFACE;
  30.     }
  31.     
  32.     reinterpret_cast<IUnknown*>(this)->AddRef();
  33.     return S_OK;
  34. }
  35. //-----------------------------------------------------------------------------
  36. // Name: CNotifyTool::AddRef()
  37. // Desc: 
  38. //-----------------------------------------------------------------------------
  39. STDMETHODIMP_(ULONG) CNotifyTool::AddRef()
  40. {
  41.     return InterlockedIncrement(&m_cRef);
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Name: CNotifyTool::Release()
  45. // Desc: 
  46. //-----------------------------------------------------------------------------
  47. STDMETHODIMP_(ULONG) CNotifyTool::Release()
  48. {
  49.     if( 0 == InterlockedDecrement(&m_cRef) )
  50.     {
  51.         delete this;
  52.         return 0;
  53.     }
  54.     return m_cRef;
  55. }
  56. //-----------------------------------------------------------------------------
  57. // Name: CNotifyTool::Init()
  58. // Desc: 
  59. //-----------------------------------------------------------------------------
  60. HRESULT STDMETHODCALLTYPE CNotifyTool::Init( IDirectMusicGraph* pGraph )
  61. {
  62.     // This tool has no need to do any type of initialization.
  63.     return S_OK;
  64. }
  65. //-----------------------------------------------------------------------------
  66. // Name: CNotifyTool::GetMsgDeliveryType()
  67. // Desc: 
  68. //-----------------------------------------------------------------------------
  69. HRESULT STDMETHODCALLTYPE CNotifyTool::GetMsgDeliveryType( DWORD* pdwDeliveryType )
  70. {
  71.     // This tool wants messages at the time stamp, not before, since it
  72.     // will synchronize graphics to the lyrics.
  73.     
  74.     *pdwDeliveryType = DMUS_PMSGF_TOOL_ATTIME;
  75.     return S_OK;
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Name: CNotifyTool::GetMediaTypeArraySize()
  79. // Desc: 
  80. //-----------------------------------------------------------------------------
  81. HRESULT STDMETHODCALLTYPE CNotifyTool::GetMediaTypeArraySize( DWORD* pdwNumElements )
  82. {
  83.     // This tool only wants lyric messages. Since it receives them 
  84.     // at DMUS_PMSGF_TOOL_ATTIME, it's important that it not process other message
  85.     // types because it would cause a timing delay for music performance messages,
  86.     // such as notes, that need to be sent at DMUS_PMSGF_TOOL_QUEUE time.
  87.     
  88.     *pdwNumElements = 1;
  89.     return S_OK;
  90. }
  91. //-----------------------------------------------------------------------------
  92. // Name: CNotifyTool::GetMediaTypes()
  93. // Desc: 
  94. //-----------------------------------------------------------------------------
  95. HRESULT STDMETHODCALLTYPE CNotifyTool::GetMediaTypes( DWORD** padwMediaTypes, 
  96.                                                     DWORD dwNumElements )
  97. {
  98.     // Fill in the array padwMediaTypes with the type of
  99.     // messages this tool wants to process. In this case,
  100.     // dwNumElements will be 1, since that is what this
  101.     // tool returns from GetMediaTypeArraySize().
  102.     
  103.     if( dwNumElements == 1 )
  104.     {
  105.         (*padwMediaTypes)[0] = DMUS_PMSGT_LYRIC;
  106.         return S_OK;
  107.     }
  108.     else
  109.     {
  110.         // This should never happen
  111.         return E_FAIL;
  112.     }
  113. }
  114. //-----------------------------------------------------------------------------
  115. // Name: CNotifyTool::ProcessPMsg()
  116. // Desc: 
  117. //-----------------------------------------------------------------------------
  118. HRESULT STDMETHODCALLTYPE CNotifyTool::ProcessPMsg( IDirectMusicPerformance* pPerf, 
  119.                                                     DMUS_PMSG* pPMsg )
  120. {
  121.     // Since this tool is capturing only the lyric messages and promptly discarding them,
  122.     // there is no need to call StampPMsg on the graph to set up the next tool to process
  123.     // after this one.
  124.     // Start by ensuring that this is indeed a lyric message. This should never fail, but
  125.     // just to be safe...
  126.     if (pPMsg->dwType == DMUS_PMSGT_LYRIC)
  127.     {
  128.         // Decode the lyric and use to set the app state.
  129.         DMUS_LYRIC_PMSG *pLyric = (DMUS_LYRIC_PMSG *) pPMsg;
  130.         if (!(_wcsicmp(pLyric->wszString,L"AdvanceLevel")))
  131.         {
  132.             // This string is sent when we transition to a new level screen.
  133.             // It indicates that the wait for the music to end is now over.
  134.             // So, go and directly reset the app state.
  135.             m_pApp->SetAppState( APPSTATE_TRIGGERLEVELSCREEN );
  136.         }
  137.         else if (!(_wcsicmp(pLyric->wszString,L"StartLevel")))
  138.         {
  139.             // This indicates the change level music has
  140.             // finished playing and we can now move on to the new level screen.
  141.             m_pApp->SetAppState( APPSTATE_BEGINACTIVESCREEN );
  142.         }
  143.     }
  144.  
  145.     // Return DMUS_S_FREE since there's no need to do anything more with this lyric.
  146.     return DMUS_S_FREE;
  147. }
  148. //-----------------------------------------------------------------------------
  149. // Name: CNotifyTool::Flush()
  150. // Desc: 
  151. //-----------------------------------------------------------------------------
  152. HRESULT STDMETHODCALLTYPE CNotifyTool::Flush( IDirectMusicPerformance* pPerf, 
  153.                                             DMUS_PMSG* pDMUS_PMSG,
  154.                                             REFERENCE_TIME rt)
  155. {
  156.     // This tool does not need to flush.
  157.     return E_NOTIMPL;
  158. }