// -------------------------------------------------------------------------- // ========================================================================== // File: TDx9_Music.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_Music Component // // "TDx9_Music_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_Music.H" // -------------------------------------------------------------------------- // external classes used by TDx9_Music methods. #include "TDMus_BufferDesc.H" #include "TDMus_ClockInfo.H" #include "TDMus_PortCaps.H" #include "TDx_Sound.H" // -------------------------------------------------------------------------- #pragma link "TDx_Library_Defns" #pragma link "TDx_Library_Functions" #pragma link "TDx9_Music_Library_Defns" #pragma link "TDx9_Music_Library_Functions" // -------------------------------------------------------------------------- // Object Registration... // -------------------------------------------------------------------------- #if (__BORLANDC__ >= 0x0530) // BCB Version 3+ #pragma package(smart_init) #endif // -------------------------------------------------------------------------- static inline void ValidCtrCheck(TDx9_Music*) { new TDx9_Music(NULL); } // -------------------------------------------------------------------------- namespace Tdx9_music { #if (__BORLANDC__ >= 0x0530) // BCB Version 3+ void __fastcall PACKAGE Register() #else void __fastcall Register() #endif { TComponentClass classes[1] = {__classid(TDx9_Music)}; RegisterComponents("", classes, 0); } } // -------------------------------------------------------------------------- // Constructor: TDx9_Music::TDx9_Music() // Description: The default constructor for the TDx9_Music object. // -------------------------------------------------------------------------- __fastcall TDx9_Music::TDx9_Music(TComponent* Owner) : TComponent(Owner) { fErrorValue = S_OK; fCreated = false; } // -------------------------------------------------------------------------- // Destructor: TDx9_Music::~TDx9_Music() // Description: The destructor for the TDx9_Music object. // -------------------------------------------------------------------------- __fastcall TDx9_Music::~TDx9_Music() { // destroy internals if (Created) Destroy(); } // -------------------------------------------------------------------------- // Property: Created // Description: The Created property is true if the internal LPIDIRECTMUSIC // used in this component has been successfully created, // otherwise Created is false. // // To create the internal LPIDIRECTMUSIC, call the // TDx9_Music::Create() method. // -------------------------------------------------------------------------- bool __fastcall TDx9_Music::FGetCreated() { return fCreated; } // -------------------------------------------------------------------------- void __fastcall TDx9_Music::FSetCreated( bool pCreated ) { fCreated = (pCreated && (fLPIDIRECTMUSIC==NULL)); } // -------------------------------------------------------------------------- // Property: ErrorValue // Description: The ErrorValue property contains the last error value // returned from a call to a TDx9_Music method or fget/fset. eg. // S_OK or DDERR_SURFACELOST or TDX_ERROR // -------------------------------------------------------------------------- HRESULT __fastcall TDx9_Music::FGetErrorValue() { return fErrorValue; } // -------------------------------------------------------------------------- void __fastcall TDx9_Music::FSetErrorValue( HRESULT pErrorValue ) { fErrorValue = pErrorValue; } // -------------------------------------------------------------------------- // Method: Activate() // Description: The Activate method is used to ... // Params: pEnable - // The Enable parameter ... // -------------------------------------------------------------------------- bool __fastcall TDx9_Music::Activate( bool pEnable ) { // Original Function Definition // HRESULT Activate( // BOOL fEnable // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::Activate()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPIDIRECTMUSIC->Activate( (BOOL) pEnable ); // Handle any Known Results if (fErrorValue!=S_OK) { // Failure. if (FOnError) FOnError( this, Name+"::Activate()", TDx9_Music_Library_ErrorString(fErrorValue), TDx9_Music_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: Create() // Description: The Create() method is used to automatically create the // internal LPIDIRECTMUSIC interface used in the TDx9_Music // component and must be called before any methods of the // TDx9_Music component will function. // -------------------------------------------------------------------------- bool __fastcall TDx9_Music::Create() { fCreated = true; if (fCreated && FOnCreate) FOnCreate(this); return fCreated; } // -------------------------------------------------------------------------- // Method: CreateMusicBuffer() // Description: The CreateMusicBuffer method is used to ... // Params: pBufferDesc - // The BufferDesc parameter ... // p - // The parameter ... // pUnkOuter - // The UnkOuter parameter ... // -------------------------------------------------------------------------- bool __fastcall TDx9_Music::CreateMusicBuffer( TDMus_BufferDesc* pBufferDesc, LPDIRECTMUSICBUFFER*..ppBuffer p, LPUNKNOWN pUnkOuter ) { // Original Function Definition // HRESULT CreateMusicBuffer( // LPDMUS_BUFFERDESC pBufferDesc, // LPDIRECTMUSICBUFFER*..ppBuffer, // LPUNKNOWN pUnkOuter // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::CreateMusicBuffer()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPIDIRECTMUSIC->CreateMusicBuffer( (pBufferDesc==NULL) ? NULL : pBufferDesc->Internal_DMUS_BUFFERDESC_Ptr, p, pUnkOuter ); // Translate Data returned from Function if (pBufferDesc!=NULL) pBufferDesc->Internal_DMUS_BUFFERDESC_Update(); // Handle any Known Results if (fErrorValue!=S_OK) { // Failure. if (FOnError) FOnError( this, Name+"::CreateMusicBuffer()", TDx9_Music_Library_ErrorString(fErrorValue), TDx9_Music_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: CreatePort() // Description: The CreatePort method is used to ... // Params: pPort - // The Port parameter ... // pPortParams - // The PortParams parameter ... // pUnkOuter - // The UnkOuter parameter ... // -------------------------------------------------------------------------- // -------------------------------------------------------------------------- // Method: Destroy() // Description: The Destroy() method is used to automatically destroy the // internal LPIDIRECTMUSIC interface used in the TDx9_Music // 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_Music::Destroy() { fCreated = false; if (FOnDestroy) FOnDestroy(this); return !fCreated; } // -------------------------------------------------------------------------- // Method: EnumMasterClock() // Description: The EnumMasterClock method is used to ... // Params: pIndex - // The Index parameter ... // pClockInfo - // The ClockInfo parameter ... // -------------------------------------------------------------------------- bool __fastcall TDx9_Music::EnumMasterClock( dword pIndex, TDMus_ClockInfo* pClockInfo ) { // Original Function Definition // HRESULT EnumMasterClock( // DWORD dwIndex, // LPDMUS_CLOCKINFO lpClockInfo // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::EnumMasterClock()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPIDIRECTMUSIC->EnumMasterClock( (DWORD) pIndex, (pClockInfo==NULL) ? NULL : pClockInfo->Internal_DMUS_CLOCKINFO_Ptr ); // Translate Data returned from Function if (pClockInfo!=NULL) pClockInfo->Internal_DMUS_CLOCKINFO_Update(); // Handle any Known Results if (fErrorValue!=S_OK) { // Failure. if (FOnError) FOnError( this, Name+"::EnumMasterClock()", TDx9_Music_Library_ErrorString(fErrorValue), TDx9_Music_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: EnumPort() // Description: The EnumPort method is used to ... // Params: pIndex - // The Index parameter ... // pPortCaps - // The PortCaps parameter ... // -------------------------------------------------------------------------- bool __fastcall TDx9_Music::EnumPort( dword pIndex, TDMus_PortCaps* pPortCaps ) { // Original Function Definition // HRESULT EnumPort( // DWORD dwIndex, // LPDMUS_PORTCAPS pPortCaps // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::EnumPort()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPIDIRECTMUSIC->EnumPort( (DWORD) pIndex, (pPortCaps==NULL) ? NULL : pPortCaps->Internal_DMUS_PORTCAPS_Ptr ); // Translate Data returned from Function if (pPortCaps!=NULL) pPortCaps->Internal_DMUS_PORTCAPS_Update(); // Handle any Known Results if (fErrorValue!=S_OK) { // Failure. if (FOnError) FOnError( this, Name+"::EnumPort()", TDx9_Music_Library_ErrorString(fErrorValue), TDx9_Music_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: GetDefaultPort() // Description: The GetDefaultPort method is used to ... // Params: pPort - // The Port parameter ... // -------------------------------------------------------------------------- bool __fastcall TDx9_Music::GetDefaultPort( GUID* pPort ) { // Original Function Definition // HRESULT GetDefaultPort( // LPGUID pguidPort // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::GetDefaultPort()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPIDIRECTMUSIC->GetDefaultPort( (LPGUID) pPort ); // Handle any Known Results if (fErrorValue!=S_OK) { // Failure. if (FOnError) FOnError( this, Name+"::GetDefaultPort()", TDx9_Music_Library_ErrorString(fErrorValue), TDx9_Music_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: GetMasterClock() // Description: The GetMasterClock method is used to ... // Params: pClock - // The Clock parameter ... // pReferenceClock - // The ReferenceClock parameter ... // -------------------------------------------------------------------------- bool __fastcall TDx9_Music::GetMasterClock( GUID* pClock, IReferenceClock** pReferenceClock ) { // Original Function Definition // HRESULT GetMasterClock( // LPGUID pguidClock, // IReferenceClock** ppReferenceClock // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::GetMasterClock()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPIDIRECTMUSIC->GetMasterClock( (LPGUID) pClock, pReferenceClock ); // Handle any Known Results if (fErrorValue!=S_OK) { // Failure. if (FOnError) FOnError( this, Name+"::GetMasterClock()", TDx9_Music_Library_ErrorString(fErrorValue), TDx9_Music_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: SetDirectSound() // Description: The SetDirectSound method is used to ... // Params: pDirectSound - // The DirectSound parameter ... // pWnd - // The Wnd parameter ... // -------------------------------------------------------------------------- bool __fastcall TDx9_Music::SetDirectSound( TDx_Sound* pDirectSound, HWND pWnd ) { // Original Function Definition // HRESULT SetDirectSound( // LPDIRECTSOUND pDirectSound, // HWND hWnd // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::SetDirectSound()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPIDIRECTMUSIC->SetDirectSound( (pDirectSound==NULL) ? NULL : pDirectSound->Internal_LPDIRECTSOUND, pWnd ); // Handle any Known Results if (fErrorValue!=S_OK) { // Failure. if (FOnError) FOnError( this, Name+"::SetDirectSound()", TDx9_Music_Library_ErrorString(fErrorValue), TDx9_Music_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: SetExternalMasterClock() // Description: The SetExternalMasterClock method is used to ... // Params: pClock - // The Clock parameter ... // -------------------------------------------------------------------------- bool __fastcall TDx9_Music::SetExternalMasterClock( IReferenceClock* pClock ) { // Original Function Definition // HRESULT SetExternalMasterClock( // IReferenceClock *pClock // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::SetExternalMasterClock()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPIDIRECTMUSIC->SetExternalMasterClock( pClock ); // Handle any Known Results if (fErrorValue!=S_OK) { // Failure. if (FOnError) FOnError( this, Name+"::SetExternalMasterClock()", TDx9_Music_Library_ErrorString(fErrorValue), TDx9_Music_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Method: SetMasterClock() // Description: The SetMasterClock method is used to ... // Params: pClock - // The Clock parameter ... // -------------------------------------------------------------------------- bool __fastcall TDx9_Music::SetMasterClock( REFGUID pClock ) { // Original Function Definition // HRESULT SetMasterClock( // REFGUID rguidClock // ); // if the component internals are not already created, exit if (!fCreated) { fErrorValue = TDX_NOTCREATED; if (FOnError) FOnError( this, Name+"::SetMasterClock()", "TDX_NOTCREATED", "The "+Name+" component has not been created successfully." ); return false; } // Call Original Function fErrorValue = (uint) fLPIDIRECTMUSIC->SetMasterClock( pClock ); // Handle any Known Results if (fErrorValue!=S_OK) { // Failure. if (FOnError) FOnError( this, Name+"::SetMasterClock()", TDx9_Music_Library_ErrorString(fErrorValue), TDx9_Music_Library_ErrorMessage(fErrorValue) ); return false; } // Success! return true; } // -------------------------------------------------------------------------- // Internal Interface Access // -------------------------------------------------------------------------- LPIDIRECTMUSIC __fastcall TDx9_Music::FGetInternal_LPIDIRECTMUSIC() { return fLPIDIRECTMUSIC; } // -------------------------------------------------------------------------- LPIDIRECTMUSIC* __fastcall TDx9_Music::FGetInternal_LPIDIRECTMUSIC_Ptr() { return &fLPIDIRECTMUSIC; } // -------------------------------------------------------------------------- void __fastcall TDx9_Music::FSetInternal_LPIDIRECTMUSIC( LPIDIRECTMUSIC pLPIDIRECTMUSIC ) { if (!fCreated) { fLPIDIRECTMUSIC = pLPIDIRECTMUSIC; fCreated = (fLPIDIRECTMUSIC!=NULL); } } // -------------------------------------------------------------------------- void __fastcall TDx9_Music::Internal_LPIDIRECTMUSIC_Update() { fCreated = (fLPIDIRECTMUSIC!=NULL); } // --------------------------------------------------------------------------