// -------------------------------------------------------------------------- // ========================================================================== // File: TDx9_Sound.CPP // Authors: BCB_Code_Generator v2.00, // Darren Dwyer (source code, documentation, demos, website), // Hugh Edwards (documentation, icons) // Description: This file contains the code for the TDx9_Sound Component // // "TDx9_Sound_Library v1.00" // (c) 2005 BCB-Tools.com Pty. Ltd., Sydney, Australia. // All Rights Reserved. // // Refer to the 'Licence.Txt' file for licencing & copyright information. // ========================================================================== // -------------------------------------------------------------------------- // #includes ... // -------------------------------------------------------------------------- #include #pragma hdrstop // -------------------------------------------------------------------------- #include "TDx9_Sound.H" // -------------------------------------------------------------------------- // external classes used by TDx9_Sound methods. #include "TDSBufferDesc.H" #include "TDx_SoundBuffer.H" #include "TDSCaps.H" // -------------------------------------------------------------------------- #pragma link "TDx_Library_Defns" #pragma link "TDx_Library_Functions" #pragma link "TDx9_Sound_Library_Defns" #pragma link "TDx9_Sound_Library_Functions" // -------------------------------------------------------------------------- // Object Registration... // -------------------------------------------------------------------------- #if (__BORLANDC__ >= 0x0530) // BCB Version 3+ #pragma package(smart_init) #endif // -------------------------------------------------------------------------- static inline void ValidCtrCheck(TDx9_Sound*) { new TDx9_Sound(NULL); } // -------------------------------------------------------------------------- namespace Tdx9_sound { #if (__BORLANDC__ >= 0x0530) // BCB Version 3+ void __fastcall PACKAGE Register() #else void __fastcall Register() #endif { TComponentClass classes[1] = {__classid(TDx9_Sound)}; RegisterComponents("", classes, 0); } } // -------------------------------------------------------------------------- // Constructor: TDx9_Sound::TDx9_Sound() // Description: The default constructor for the TDx9_Sound object. // -------------------------------------------------------------------------- __fastcall TDx9_Sound::TDx9_Sound(TComponent* Owner) : TComponent(Owner) { fErrorValue = DS_OK; fCreated = false; } // -------------------------------------------------------------------------- // Destructor: TDx9_Sound::~TDx9_Sound() // Description: The destructor for the TDx9_Sound object. // -------------------------------------------------------------------------- __fastcall TDx9_Sound::~TDx9_Sound() { // destroy internals if (Created) Destroy(); } // -------------------------------------------------------------------------- // Property: Created // Description: The Created property is true if the internal LPIDIRECTSOUND8 // used in this component has been successfully created, // otherwise Created is false. // // To create the internal LPIDIRECTSOUND8, call the // TDx9_Sound::Create() method. // -------------------------------------------------------------------------- bool __fastcall TDx9_Sound::FGetCreated() { return fCreated; } // -------------------------------------------------------------------------- void __fastcall TDx9_Sound::FSetCreated( bool pCreated ) { fCreated = (pCreated && (fLPIDIRECTSOUND8==NULL)); } // -------------------------------------------------------------------------- // Property: ErrorValue // Description: The ErrorValue property contains the last error value // returned from a call to a TDx9_Sound method or fget/fset. eg. // DS_OK or DDERR_SURFACELOST or TDX_ERROR // -------------------------------------------------------------------------- HRESULT __fastcall TDx9_Sound::FGetErrorValue() { return fErrorValue; } // -------------------------------------------------------------------------- void __fastcall TDx9_Sound::FSetErrorValue( HRESULT pErrorValue ) { fErrorValue = pErrorValue; } // -------------------------------------------------------------------------- // Method: Compact() // Description: The Compact method is used to ... // -------------------------------------------------------------------------- bool __fastcall TDx9_Sound::Compact() { // Original Function Definition // HRESULT Compact(); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::Compact()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPIDIRECTSOUND8->Compact( ); // Handle any Known Results if (fErrorValue!=DS_OK) { // Failure. if (FOnError) FOnError( this, Name+"::Compact()", TDx9_Sound_Library_ErrorString(fErrorValue), TDx9_Sound_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: Create() // Description: The Create() method is used to automatically create the // internal LPIDIRECTSOUND8 interface used in the TDx9_Sound // component and must be called before any methods of the // TDx9_Sound component will function. // -------------------------------------------------------------------------- bool __fastcall TDx9_Sound::Create() { fCreated = true; if (fCreated && FOnCreate) FOnCreate(this); return fCreated; } // -------------------------------------------------------------------------- // Method: CreateSoundBuffer() // Description: The CreateSoundBuffer method is used to ... // Params: pDSBufferDesc - // The DSBufferDesc parameter ... // pDSBuffer - // The DSBuffer parameter ... // pUnkOuter - // The UnkOuter parameter ... // -------------------------------------------------------------------------- bool __fastcall TDx9_Sound::CreateSoundBuffer( TDSBufferDesc* pDSBufferDesc, TDx_SoundBuffer* pDSBuffer, LPUNKNOWN pUnkOuter ) { // Original Function Definition // HRESULT CreateSoundBuffer( // LPCDSBUFFERDESC pcDSBufferDesc, // LPDIRECTSOUNDBUFFER* ppDSBuffer, // LPUNKNOWN pUnkOuter // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::CreateSoundBuffer()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPIDIRECTSOUND8->CreateSoundBuffer( (pDSBufferDesc==NULL) ? NULL : pDSBufferDesc->Internal_DSBUFFERDESC_Ptr, (pDSBuffer==NULL) ? NULL : pDSBuffer->Internal_LPDIRECTSOUNDBUFFER_Ptr, pUnkOuter ); // Translate Data returned from Function if (pDSBufferDesc!=NULL) pDSBufferDesc->Internal_DSBUFFERDESC_Update(); if (pDSBuffer!=NULL) pDSBuffer->Internal_LPDIRECTSOUNDBUFFER_Update(); // Handle any Known Results if (fErrorValue!=DS_OK) { // Failure. if (FOnError) FOnError( this, Name+"::CreateSoundBuffer()", TDx9_Sound_Library_ErrorString(fErrorValue), TDx9_Sound_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: Destroy() // Description: The Destroy() method is used to automatically destroy the // internal LPIDIRECTSOUND8 interface used in the TDx9_Sound // component and should be called when the internal interface is // no longer required. // // Note: This method is called by the component's destructor. // -------------------------------------------------------------------------- bool __fastcall TDx9_Sound::Destroy() { fCreated = false; if (FOnDestroy) FOnDestroy(this); return !fCreated; } // -------------------------------------------------------------------------- // Method: DuplicateSoundBuffer() // Description: The DuplicateSoundBuffer method is used to ... // Params: pDSBufferOriginal - // The DSBufferOriginal parameter ... // pDSBufferDuplicate - // The DSBufferDuplicate parameter ... // -------------------------------------------------------------------------- bool __fastcall TDx9_Sound::DuplicateSoundBuffer( TDx_SoundBuffer* pDSBufferOriginal, TDx_SoundBuffer* pDSBufferDuplicate ) { // Original Function Definition // HRESULT DuplicateSoundBuffer( // LPDIRECTSOUNDBUFFER pDSBufferOriginal, // LPDIRECTSOUNDBUFFER* ppDSBufferDuplicate // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::DuplicateSoundBuffer()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPIDIRECTSOUND8->DuplicateSoundBuffer( (pDSBufferOriginal==NULL) ? NULL : pDSBufferOriginal->Internal_LPDIRECTSOUNDBUFFER, (pDSBufferDuplicate==NULL) ? NULL : pDSBufferDuplicate->Internal_LPDIRECTSOUNDBUFFER_Ptr ); // Translate Data returned from Function if (pDSBufferDuplicate!=NULL) pDSBufferDuplicate->Internal_LPDIRECTSOUNDBUFFER_Update(); // Handle any Known Results if (fErrorValue!=DS_OK) { // Failure. if (FOnError) FOnError( this, Name+"::DuplicateSoundBuffer()", TDx9_Sound_Library_ErrorString(fErrorValue), TDx9_Sound_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: GetCaps() // Description: The GetCaps method is used to ... // Params: pDSCaps - // The DSCaps parameter ... // -------------------------------------------------------------------------- bool __fastcall TDx9_Sound::GetCaps( TDSCaps* pDSCaps ) { // Original Function Definition // HRESULT GetCaps( // LPDSCAPS pDSCaps // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::GetCaps()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPIDIRECTSOUND8->GetCaps( (pDSCaps==NULL) ? NULL : pDSCaps->Internal_DSCAPS_Ptr ); // Translate Data returned from Function if (pDSCaps!=NULL) pDSCaps->Internal_DSCAPS_Update(); // Handle any Known Results if (fErrorValue!=DS_OK) { // Failure. if (FOnError) FOnError( this, Name+"::GetCaps()", TDx9_Sound_Library_ErrorString(fErrorValue), TDx9_Sound_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: GetSpeakerConfig() // Description: The GetSpeakerConfig method is used to ... // Params: pSpeakerConfig - // The SpeakerConfig parameter ... // -------------------------------------------------------------------------- bool __fastcall TDx9_Sound::GetSpeakerConfig( dword* pSpeakerConfig ) { // Original Function Definition // HRESULT GetSpeakerConfig( // LPDWORD pdwSpeakerConfig // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::GetSpeakerConfig()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPIDIRECTSOUND8->GetSpeakerConfig( (LPDWORD) pSpeakerConfig ); // Handle any Known Results if (fErrorValue!=DS_OK) { // Failure. if (FOnError) FOnError( this, Name+"::GetSpeakerConfig()", TDx9_Sound_Library_ErrorString(fErrorValue), TDx9_Sound_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: Initialize() // Description: The Initialize method is used to ... // Params: pGuidDevice - // The GuidDevice parameter ... // -------------------------------------------------------------------------- bool __fastcall TDx9_Sound::Initialize( const GUID* pGuidDevice ) { // Original Function Definition // HRESULT Initialize( // LPCGUID pcGuidDevice // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::Initialize()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPIDIRECTSOUND8->Initialize( (LPCGUID) pGuidDevice ); // Handle any Known Results if (fErrorValue!=DS_OK) { // Failure. if (FOnError) FOnError( this, Name+"::Initialize()", TDx9_Sound_Library_ErrorString(fErrorValue), TDx9_Sound_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: SetCooperativeLevel() // Description: The SetCooperativeLevel method is used to ... // Params: phwnd - // The hwnd parameter ... // pLevel - // The Level parameter ... // -------------------------------------------------------------------------- bool __fastcall TDx9_Sound::SetCooperativeLevel( HWND phwnd, dword pLevel ) { // Original Function Definition // HRESULT SetCooperativeLevel( // HWND hwnd, // DWORD dwLevel // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::SetCooperativeLevel()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPIDIRECTSOUND8->SetCooperativeLevel( phwnd, (DWORD) pLevel ); // Handle any Known Results if (fErrorValue!=DS_OK) { // Failure. if (FOnError) FOnError( this, Name+"::SetCooperativeLevel()", TDx9_Sound_Library_ErrorString(fErrorValue), TDx9_Sound_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: SetSpeakerConfig() // Description: The SetSpeakerConfig method is used to ... // Params: pSpeakerConfig - // The SpeakerConfig parameter ... // -------------------------------------------------------------------------- bool __fastcall TDx9_Sound::SetSpeakerConfig( dword pSpeakerConfig ) { // Original Function Definition // HRESULT SetSpeakerConfig( // DWORD dwSpeakerConfig // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::SetSpeakerConfig()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPIDIRECTSOUND8->SetSpeakerConfig( (DWORD) pSpeakerConfig ); // Handle any Known Results if (fErrorValue!=DS_OK) { // Failure. if (FOnError) FOnError( this, Name+"::SetSpeakerConfig()", TDx9_Sound_Library_ErrorString(fErrorValue), TDx9_Sound_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: VerifyCertification() // Description: The VerifyCertification method is used to ... // Params: pCertified - // The Certified parameter ... // -------------------------------------------------------------------------- bool __fastcall TDx9_Sound::VerifyCertification( dword* pCertified ) { // Original Function Definition // HRESULT VerifyCertification( // LPDWORD pdwCertified // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::VerifyCertification()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPIDIRECTSOUND8->VerifyCertification( (LPDWORD) pCertified ); // Handle any Known Results if (fErrorValue!=DS_OK) { // Failure. if (FOnError) FOnError( this, Name+"::VerifyCertification()", TDx9_Sound_Library_ErrorString(fErrorValue), TDx9_Sound_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Internal Interface Access // -------------------------------------------------------------------------- LPIDIRECTSOUND8 __fastcall TDx9_Sound::FGetInternal_LPIDIRECTSOUND8() { return fLPIDIRECTSOUND8; } // -------------------------------------------------------------------------- LPIDIRECTSOUND8* __fastcall TDx9_Sound::FGetInternal_LPIDIRECTSOUND8_Ptr() { return &fLPIDIRECTSOUND8; } // -------------------------------------------------------------------------- void __fastcall TDx9_Sound::FSetInternal_LPIDIRECTSOUND8( LPIDIRECTSOUND8 pLPIDIRECTSOUND8 ) { if (!fCreated) { fLPIDIRECTSOUND8 = pLPIDIRECTSOUND8; fCreated = (fLPIDIRECTSOUND8!=NULL); } } // -------------------------------------------------------------------------- void __fastcall TDx9_Sound::Internal_LPIDIRECTSOUND8_Update() { fCreated = (fLPIDIRECTSOUND8!=NULL); } // --------------------------------------------------------------------------