⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dynamicmusic.cpp

📁 游戏音频程序设计-Beginning.Game.Audio.Programming
💻 CPP
字号:
// DynamicMusic.cpp: implementation of the CDynamicMusic class.
//
//////////////////////////////////////////////////////////////////////

#pragma warning(disable: 4786)

#include "DynamicMusic.h"
#include "AudioManager.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

namespace AudioEngine {

CDynamicMusic::CDynamicMusic(CAudioManager *mgr) : CDirectMusicSegment(mgr)
{

}

CDynamicMusic::~CDynamicMusic()
{
  for (std::map<std::string, CDirectMusicSegment *>::iterator i = m_MotifMap.begin(); i != m_MotifMap.end(); ++i) {
    delete (*i).second;
  }
  m_MotifMap.clear();
}

void CDynamicMusic::LoadMotifs()
{
  IDirectMusicStyle8* pStyle = NULL;
  DWORD dwStyleIndex = 0;

  while(1)
  {
    HRESULT hr = GetSegment()->GetParam( GUID_IDirectMusicStyle, 0xffffffff, dwStyleIndex, 0, NULL, (VOID*)&pStyle);

    if(FAILED(hr)) {
      // not a fatal error... just means there are no more styles.
      break;
    }

    DWORD dwIndex = 0;
    while(1)
    {
      WCHAR wstrMotifName[MAX_PATH];
      CHAR  strMotifName[MAX_PATH];
      if(S_FALSE == pStyle->EnumMotif(dwIndex, wstrMotifName)) {
        // no more motifs in this style
        break; 
      }

      wcstombs(strMotifName, wstrMotifName, wcslen(wstrMotifName) + 1);
      CDirectMusicSegment *newseg = new CDirectMusicSegment(m_Manager);

      hr = pStyle->GetMotif(wstrMotifName, (IDirectMusicSegment **)&newseg->m_Segment);
      ThrowIfFailed(hr, "CDynamicMusic::LoadMotifs: pStyle->GetMotif() failed.");

      // add this segment to our map
      m_MotifMap[std::string(strMotifName)] = newseg;

      dwIndex++;
    }

    SAFE_RELEASE(pStyle);
    dwStyleIndex++;
  }
}



void CDynamicMusic::PlayMotif(std::string name, bool bUseDefaultBoundary, bool bUseGridBoundary, bool bUseMeasureBoundary, bool bUseBeatBoundary)
{
  if (m_MotifMap.find(name) != m_MotifMap.end()) {
    CDirectMusicSegment *motifseg = m_MotifMap[name];

    int segflags = 0;
    if (bUseDefaultBoundary) segflags |= DMUS_SEGF_DEFAULT;
    if (bUseGridBoundary) segflags |= DMUS_SEGF_GRID;
    if (bUseMeasureBoundary) segflags |= DMUS_SEGF_BEAT;
    if (bUseBeatBoundary) segflags |= DMUS_SEGF_MEASURE;

     HRESULT hr = m_Manager->GetPerformance()->PlaySegment( motifseg->GetSegment(), segflags, 0, NULL);
    ThrowIfFailed(hr, "CDynamicMusic::PlayMotif: PlaySegment failed.");
  }
}

} // namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -