📄 dmutil.cpp
字号:
BOOL bIsMidiFile,
IDirectMusicAudioPath8* p3DAudioPath )
{
HRESULT hr;
IDirectMusicSegment8* pSegment = NULL;
// DMusic only takes wide strings
WCHAR wstrFileName[MAX_PATH];
DXUtil_ConvertGenericStringToWideCch( wstrFileName, strFileName, sizeof(wstrFileName)/sizeof(TCHAR) );
if ( FAILED( hr = m_pLoader->LoadObjectFromFile( CLSID_DirectMusicSegment,
IID_IDirectMusicSegment8,
wstrFileName,
(LPVOID*) &pSegment ) ) )
{
if( hr == DMUS_E_LOADER_FAILEDOPEN )
return hr;
return DXTRACE_ERR( TEXT("LoadObjectFromFile"), hr );
}
*pp3DMusicSegment = new C3DMusicSegment( m_pPerformance, m_pLoader, pSegment, p3DAudioPath );
if (!*pp3DMusicSegment)
return E_OUTOFMEMORY;
if( FAILED( hr = (*pp3DMusicSegment)->Init() ) )
return DXTRACE_ERR( TEXT("SetParam"), hr );
if( bIsMidiFile )
{
if( FAILED( hr = pSegment->SetParam( GUID_StandardMIDIFile,
0xFFFFFFFF, 0, 0, NULL ) ) )
return DXTRACE_ERR( TEXT("SetParam"), hr );
}
if( bDownloadNow )
{
if( FAILED( hr = (*pp3DMusicSegment)->Download() ) )
return DXTRACE_ERR( TEXT("Download"), hr );
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: CMusicManager::CreateScriptFromFile()
// Desc:
//-----------------------------------------------------------------------------
HRESULT CMusicManager::CreateScriptFromFile( CMusicScript** ppScript,
LPCTSTR strFileName )
{
HRESULT hr;
IDirectMusicScript* pScript = NULL;
// DMusic only takes wide strings
WCHAR wstrFileName[MAX_PATH];
DXUtil_ConvertGenericStringToWideCch( wstrFileName, strFileName, sizeof(wstrFileName)/sizeof(TCHAR) );
if ( FAILED( hr = m_pLoader->LoadObjectFromFile( CLSID_DirectMusicScript,
IID_IDirectMusicScript8,
wstrFileName,
(LPVOID*) &pScript ) ) )
return DXTRACE_ERR( TEXT("LoadObjectFromFile"), hr );
if ( FAILED( hr = pScript->Init( m_pPerformance, NULL ) ) )
return DXTRACE_ERR_MSGBOX( TEXT("Init"), hr );
*ppScript = new CMusicScript( m_pPerformance, m_pLoader, pScript );
if (!*ppScript)
return E_OUTOFMEMORY;
return hr;
}
//-----------------------------------------------------------------------------
// Name: CMusicManager::CreateChordMapFromFile()
// Desc:
//-----------------------------------------------------------------------------
HRESULT CMusicManager::CreateChordMapFromFile( IDirectMusicChordMap8** ppChordMap,
LPCTSTR strFileName )
{
// DMusic only takes wide strings
WCHAR wstrFileName[MAX_PATH];
DXUtil_ConvertGenericStringToWideCch( wstrFileName, strFileName, sizeof(wstrFileName)/sizeof(TCHAR) );
return m_pLoader->LoadObjectFromFile( CLSID_DirectMusicChordMap,
IID_IDirectMusicChordMap8,
wstrFileName, (LPVOID*) ppChordMap );
}
//-----------------------------------------------------------------------------
// Name: CMusicManager::CreateChordMapFromFile()
// Desc:
//-----------------------------------------------------------------------------
HRESULT CMusicManager::CreateStyleFromFile( IDirectMusicStyle8** ppStyle,
LPCTSTR strFileName )
{
// DMusic only takes wide strings
WCHAR wstrFileName[MAX_PATH];
DXUtil_ConvertGenericStringToWideCch( wstrFileName, strFileName, sizeof(wstrFileName)/sizeof(TCHAR) );
return m_pLoader->LoadObjectFromFile( CLSID_DirectMusicStyle,
IID_IDirectMusicStyle8,
wstrFileName, (LPVOID*) ppStyle );
}
//-----------------------------------------------------------------------------
// Name: CMusicManager::GetMotifFromStyle()
// Desc:
//-----------------------------------------------------------------------------
HRESULT CMusicManager::GetMotifFromStyle( IDirectMusicSegment8** ppMotif8,
LPCTSTR strStyle, LPCTSTR strMotif )
{
UNREFERENCED_PARAMETER( strMotif );
HRESULT hr;
IDirectMusicStyle8* pStyle = NULL;
IDirectMusicSegment* pMotif = NULL;
if( FAILED( hr = CreateStyleFromFile( &pStyle, strStyle ) ) )
return DXTRACE_ERR_MSGBOX( TEXT("CreateStyleFromFile"), hr );
if( pStyle )
{
// DMusic only takes wide strings
WCHAR wstrMotif[MAX_PATH];
DXUtil_ConvertGenericStringToWideCch( wstrMotif, strStyle, sizeof(wstrMotif)/sizeof(TCHAR) );
hr = pStyle->GetMotif( wstrMotif, &pMotif );
SAFE_RELEASE( pStyle );
if( FAILED( hr ) )
return DXTRACE_ERR_MSGBOX( TEXT("GetMotif"), hr );
pMotif->QueryInterface( IID_IDirectMusicSegment8, (LPVOID*) ppMotif8 );
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: Set3DParameters
// Desc:
//-----------------------------------------------------------------------------
VOID CMusicManager::Set3DParameters( FLOAT fDistanceFactor, FLOAT fDopplerFactor, FLOAT fRolloffFactor )
{
m_dsListenerParams.flDistanceFactor = fDistanceFactor;
m_dsListenerParams.flDopplerFactor = fDopplerFactor;
m_dsListenerParams.flRolloffFactor = fRolloffFactor;
if( m_pDSListener )
m_pDSListener->SetAllParameters( &m_dsListenerParams, DS3D_IMMEDIATE );
}
//-----------------------------------------------------------------------------
// Name: CMusicSegment::CMusicSegment()
// Desc: Constructs the class
//-----------------------------------------------------------------------------
CMusicSegment::CMusicSegment( IDirectMusicPerformance8* pPerformance,
IDirectMusicLoader8* pLoader,
IDirectMusicSegment8* pSegment )
{
m_pPerformance = pPerformance;
m_pLoader = pLoader;
m_pSegment = pSegment;
m_pEmbeddedAudioPath = NULL;
m_bDownloaded = FALSE;
// Try to pull out an audio path from the segment itself if there is one.
// This embedded audio path will be used instead of the default
// audio path if the app doesn't wish to use an overriding audio path.
IUnknown* pConfig = NULL;
if( SUCCEEDED( m_pSegment->GetAudioPathConfig( &pConfig ) ) )
{
m_pPerformance->CreateAudioPath( pConfig, TRUE, &m_pEmbeddedAudioPath );
SAFE_RELEASE( pConfig );
}
}
//-----------------------------------------------------------------------------
// Name: CMusicSegment::~CMusicSegment()
// Desc: Destroys the class
//-----------------------------------------------------------------------------
CMusicSegment::~CMusicSegment()
{
if( m_pSegment )
{
// Tell the loader that this object should now be released
if( m_pLoader )
m_pLoader->ReleaseObjectByUnknown( m_pSegment );
if( m_bDownloaded )
{
if( m_pEmbeddedAudioPath )
m_pSegment->Unload( m_pEmbeddedAudioPath );
else
m_pSegment->Unload( m_pPerformance );
}
SAFE_RELEASE( m_pEmbeddedAudioPath );
SAFE_RELEASE( m_pSegment );
}
m_pPerformance = NULL;
}
//-----------------------------------------------------------------------------
// Name: CMusicSegment::Play()
// Desc: Plays the sound using voice management flags. Pass in DSBPLAY_LOOPING
// in the dwFlags to loop the sound
//-----------------------------------------------------------------------------
HRESULT CMusicSegment::Play( DWORD dwFlags, IDirectMusicAudioPath8* pAudioPath )
{
if( m_pSegment == NULL || m_pPerformance == NULL )
return CO_E_NOTINITIALIZED;
if( !m_bDownloaded )
return E_FAIL;
// If an audio path was passed in then use it, otherwise
// use the embedded audio path if there was one.
if( pAudioPath == NULL && m_pEmbeddedAudioPath != NULL )
pAudioPath = m_pEmbeddedAudioPath;
// If pAudioPath is NULL then this plays on the default audio path.
return m_pPerformance->PlaySegmentEx( m_pSegment, 0, NULL, dwFlags,
0, 0, NULL, pAudioPath );
}
//-----------------------------------------------------------------------------
// Name: CMusicSegment::Download()
// Desc:
//-----------------------------------------------------------------------------
HRESULT CMusicSegment::Download( IDirectMusicAudioPath8* pAudioPath )
{
HRESULT hr;
if( m_pSegment == NULL )
return CO_E_NOTINITIALIZED;
// If no audio path was passed in, then download
// to the embedded audio path if it exists
// else download to the performance
if( pAudioPath == NULL )
{
if( m_pEmbeddedAudioPath )
hr = m_pSegment->Download( m_pEmbeddedAudioPath );
else
hr = m_pSegment->Download( m_pPerformance );
}
else
{
hr = m_pSegment->Download( pAudioPath );
}
if ( SUCCEEDED( hr ) )
m_bDownloaded = TRUE;
return hr;
}
//-----------------------------------------------------------------------------
// Name: CMusicSegment::Unload()
// Desc:
//-----------------------------------------------------------------------------
HRESULT CMusicSegment::Unload( IDirectMusicAudioPath8* pAudioPath )
{
HRESULT hr;
if( m_pSegment == NULL )
return CO_E_NOTINITIALIZED;
// If no audio path was passed in, then unload
// from the embedded audio path if it exists
// else unload from the performance
if( pAudioPath == NULL )
{
if( m_pEmbeddedAudioPath )
hr = m_pSegment->Unload( m_pEmbeddedAudioPath );
else
hr = m_pSegment->Unload( m_pPerformance );
}
else
{
hr = m_pSegment->Unload( pAudioPath );
}
if ( SUCCEEDED( hr ) )
m_bDownloaded = FALSE;
return hr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -