📄 dmutil.cpp
字号:
//-----------------------------------------------------------------------------
// Name: CMusicSegment::IsPlaying()
// Desc:
//-----------------------------------------------------------------------------
BOOL CMusicSegment::IsPlaying()
{
if( m_pSegment == NULL || m_pPerformance == NULL )
return FALSE;
return ( m_pPerformance->IsPlaying( m_pSegment, NULL ) == S_OK );
}
//-----------------------------------------------------------------------------
// Name: CMusicSegment::Stop()
// Desc: Stops the sound from playing
//-----------------------------------------------------------------------------
HRESULT CMusicSegment::Stop( DWORD dwFlags )
{
if( m_pSegment == NULL || m_pPerformance == NULL )
return CO_E_NOTINITIALIZED;
return m_pPerformance->Stop( m_pSegment, NULL, 0, dwFlags );;
}
//-----------------------------------------------------------------------------
// Name: CMusicSegment::SetRepeats()
// Desc:
//-----------------------------------------------------------------------------
HRESULT CMusicSegment::SetRepeats( DWORD dwRepeats )
{
if( m_pSegment == NULL )
return CO_E_NOTINITIALIZED;
return m_pSegment->SetRepeats( dwRepeats );
}
//-----------------------------------------------------------------------------
// Name: CMusicSegment::GetStyle()
// Desc:
//-----------------------------------------------------------------------------
HRESULT CMusicSegment::GetStyle( IDirectMusicStyle8** ppStyle, DWORD dwStyleIndex )
{
// Get the Style from the Segment by calling the Segment's GetData() with
// the data type GUID_StyleTrackStyle. 0xffffffff indicates to look at
// tracks in all TrackGroups in the segment. The first 0 indicates to
// retrieve the Style from the first Track in the indicated TrackGroup.
// The second 0 indicates to retrieve the Style from the beginning of the
// segment, i.e. time 0 in Segment time. If this Segment was loaded from a
// section file, there is only one Style and it is at time 0.
return m_pSegment->GetParam( GUID_IDirectMusicStyle, 0xffffffff, dwStyleIndex,
0, NULL, (VOID*)ppStyle );
}
//-----------------------------------------------------------------------------
// Name: C3DMusicSegment::C3DMusicSegment()
// Desc: Constructs the class
//-----------------------------------------------------------------------------
C3DMusicSegment::C3DMusicSegment( IDirectMusicPerformance8* pPerformance,
IDirectMusicLoader8* pLoader,
IDirectMusicSegment8* pSegment,
IDirectMusicAudioPath8* pAudioPath ) :
CMusicSegment( pPerformance, pLoader, pSegment )
{
m_p3DAudioPath = pAudioPath;
m_pDS3DBuffer = NULL;
m_bDeferSettings = FALSE;
m_bCleanupAudioPath = FALSE;
}
//-----------------------------------------------------------------------------
// Name: C3DMusicSegment::~C3DMusicSegment()
// Desc: Destroys the class
//-----------------------------------------------------------------------------
C3DMusicSegment::~C3DMusicSegment()
{
SAFE_RELEASE( m_pDS3DBuffer );
if( m_bCleanupAudioPath )
SAFE_RELEASE( m_p3DAudioPath );
}
//-----------------------------------------------------------------------------
// Name: Init()
// Desc:
//-----------------------------------------------------------------------------
HRESULT C3DMusicSegment::Init()
{
HRESULT hr;
if( NULL == m_p3DAudioPath )
{
// Create a 3D audiopath with a 3d buffer.
// We can then play all segments into this buffer and directly control its
// 3D parameters.
if( FAILED( hr = m_pPerformance->CreateStandardAudioPath( DMUS_APATH_DYNAMIC_3D,
64, TRUE, &m_p3DAudioPath ) ) )
return DXTRACE_ERR( TEXT("CreateStandardAudioPath"), hr );
m_bCleanupAudioPath = TRUE;
}
// Get the 3D buffer in the audio path.
if( FAILED( hr = m_p3DAudioPath->GetObjectInPath( 0, DMUS_PATH_BUFFER, 0,
GUID_NULL, 0, IID_IDirectSound3DBuffer,
(LPVOID*) &m_pDS3DBuffer ) ) )
return DXTRACE_ERR( TEXT("GetObjectInPath"), hr );
// Get the 3D buffer parameters
m_dsBufferParams.dwSize = sizeof(DS3DBUFFER);
m_pDS3DBuffer->GetAllParameters( &m_dsBufferParams );
// Set new 3D buffer parameters
m_dsBufferParams.dwMode = DS3DMODE_HEADRELATIVE;
m_pDS3DBuffer->SetAllParameters( &m_dsBufferParams, DS3D_IMMEDIATE );
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: Play
// Desc:
//-----------------------------------------------------------------------------
HRESULT C3DMusicSegment::Play( DWORD dwFlags, IDirectMusicAudioPath8* pAudioPath )
{
if( pAudioPath )
return CMusicSegment::Play( dwFlags, pAudioPath );
else
return CMusicSegment::Play( dwFlags, m_p3DAudioPath );
}
//-----------------------------------------------------------------------------
// Name: Set3DParameters
// Desc:
//-----------------------------------------------------------------------------
VOID C3DMusicSegment::Set3DParameters( FLOAT fMinDistance, FLOAT fMaxDistance )
{
// Every change to 3-D sound buffer and listener settings causes
// DirectSound to remix, at the expense of CPU cycles.
// To minimize the performance impact of changing 3-D settings,
// use the DS3D_DEFERRED flag in the dwApply parameter of any of
// the IDirectSound3DListener or IDirectSound3DBuffer methods that
// change 3-D settings. Then call the IDirectSound3DListener::CommitDeferredSettings
// method to execute all of the deferred commands at once.
DWORD dwApplyFlag = ( m_bDeferSettings ) ? DS3D_DEFERRED : DS3D_IMMEDIATE;
m_dsBufferParams.flMinDistance = fMinDistance;
m_dsBufferParams.flMaxDistance = fMaxDistance;
if( m_pDS3DBuffer )
m_pDS3DBuffer->SetAllParameters( &m_dsBufferParams, dwApplyFlag );
}
//-----------------------------------------------------------------------------
// Name: SetObjectProperties
// Desc:
//-----------------------------------------------------------------------------
VOID C3DMusicSegment::SetObjectProperties( D3DVECTOR* pvPosition, D3DVECTOR* pvVelocity )
{
DWORD dwApplyFlag = ( m_bDeferSettings ) ? DS3D_DEFERRED : DS3D_IMMEDIATE;
// Every change to 3-D sound buffer and listener settings causes
// DirectSound to remix, at the expense of CPU cycles.
// To minimize the performance impact of changing 3-D settings,
// use the DS3D_DEFERRED flag in the dwApply parameter of any of
// the IDirectSound3DListener or IDirectSound3DBuffer methods that
// change 3-D settings. Then call the IDirectSound3DListener::CommitDeferredSettings
// method to execute all of the deferred commands at once.
memcpy( &m_dsBufferParams.vPosition, pvPosition, sizeof(D3DVECTOR) );
memcpy( &m_dsBufferParams.vVelocity, pvVelocity, sizeof(D3DVECTOR) );
if( m_pDS3DBuffer )
{
m_pDS3DBuffer->SetPosition( m_dsBufferParams.vPosition.x,
m_dsBufferParams.vPosition.y,
m_dsBufferParams.vPosition.z, dwApplyFlag );
m_pDS3DBuffer->SetVelocity( m_dsBufferParams.vVelocity.x,
m_dsBufferParams.vVelocity.y,
m_dsBufferParams.vVelocity.z, dwApplyFlag );
}
}
//-----------------------------------------------------------------------------
// Name: CMusicScript::CMusicScript()
// Desc: Constructs the class
//-----------------------------------------------------------------------------
CMusicScript::CMusicScript( IDirectMusicPerformance8* pPerformance,
IDirectMusicLoader8* pLoader,
IDirectMusicScript8* pScript )
{
m_pPerformance = pPerformance;
m_pLoader = pLoader;
m_pScript = pScript;
}
//-----------------------------------------------------------------------------
// Name: CMusicScript::~CMusicScript()
// Desc: Destroys the class
//-----------------------------------------------------------------------------
CMusicScript::~CMusicScript()
{
if( m_pLoader )
{
// Tell the loader that this object should now be released
m_pLoader->ReleaseObjectByUnknown( m_pScript );
m_pLoader = NULL;
}
SAFE_RELEASE( m_pScript );
m_pPerformance = NULL;
}
//-----------------------------------------------------------------------------
// Name: CMusicScript::Play()
// Desc: Calls a routine in the script
//-----------------------------------------------------------------------------
HRESULT CMusicScript::CallRoutine( LPCTSTR strRoutine )
{
// DMusic only takes wide strings
WCHAR wstrRoutine[MAX_PATH];
DXUtil_ConvertGenericStringToWideCch( wstrRoutine, strRoutine, sizeof(wstrRoutine)/sizeof(TCHAR) );
return m_pScript->CallRoutine( wstrRoutine, NULL );
}
//-----------------------------------------------------------------------------
// Name: CMusicScript::SetVariableNumber()
// Desc: Sets the value of a variable in the script
//-----------------------------------------------------------------------------
HRESULT CMusicScript::SetVariableNumber( LPCTSTR strVariable, LONG lValue )
{
// DMusic only takes wide strings
WCHAR wstrVariable[MAX_PATH];
DXUtil_ConvertGenericStringToWideCch( wstrVariable, strVariable, sizeof(wstrVariable)/sizeof(TCHAR) );
return m_pScript->SetVariableNumber( wstrVariable, lValue, NULL );
}
//-----------------------------------------------------------------------------
// Name: CMusicScript::GetVariableNumber()
// Desc: Gets the value of a variable in the script
//-----------------------------------------------------------------------------
HRESULT CMusicScript::GetVariableNumber( LPCTSTR strVariable, LONG* plValue )
{
// DMusic only takes wide strings
WCHAR wstrVariable[MAX_PATH];
DXUtil_ConvertGenericStringToWideCch( wstrVariable, strVariable, sizeof(wstrVariable)/sizeof(TCHAR) );
return m_pScript->GetVariableNumber( wstrVariable, plValue, NULL );
}
//-----------------------------------------------------------------------------
// Name: CMusicScript::SetVariableObject()
// Desc: Sets an object in the script
//-----------------------------------------------------------------------------
HRESULT CMusicScript::SetVariableObject( LPCTSTR strVariable, IUnknown *punkValue )
{
// DMusic only takes wide strings
WCHAR wstrVariable[MAX_PATH];
DXUtil_ConvertGenericStringToWideCch( wstrVariable, strVariable, sizeof(wstrVariable)/sizeof(TCHAR) );
return m_pScript->SetVariableObject( wstrVariable, punkValue, NULL );
}
//-----------------------------------------------------------------------------
// Name: CMusicScript::GetVariableObject()
// Desc: Gets an object from the script
//-----------------------------------------------------------------------------
HRESULT CMusicScript::GetVariableObject( LPCTSTR strVariable, REFIID riid, LPVOID FAR *ppv )
{
// DMusic only takes wide strings
WCHAR wstrVariable[MAX_PATH];
DXUtil_ConvertGenericStringToWideCch( wstrVariable, strVariable, sizeof(wstrVariable)/sizeof(TCHAR) );
return m_pScript->GetVariableObject( wstrVariable, riid, ppv, NULL );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -