Microsoft DirectX 9.0

CMusicManager Sample Class

The CMusicManager sample class contains methods for loading and creating objects, creating the performance, and managing memory.

class CMusicManager
{
protected:
    BOOL                      m_bCleanupCOM;
    IDirectMusicLoader8*      m_pLoader;
    IDirectMusicPerformance8* m_pPerformance;
    IDirectSound3DListener*   m_pDSListener;
    DS3DLISTENER              m_dsListenerParams;

public:
    CMusicManager();
    ~CMusicManager();

    inline IDirectMusicLoader8*  GetLoader()
        { return m_pLoader; }
    inline IDirectMusicPerformance8* GetPerformance()
        { return m_pPerformance; }
    inline IDirectSound3DListener*   GetListener()
        { return m_pDSListener; }
    IDirectMusicAudioPath8* GetDefaultAudioPath();
    HRESULT Initialize(HWND hWnd, DWORD dwPChannels = 128, 
        DWORD dwDefaultPathType = DMUS_APATH_DYNAMIC_STEREO, 
        LPDIRECTSOUND pDS = NULL);
    HRESULT SetSearchDirectory(const TCHAR* strMediaPath);
    VOID    CollectGarbage();
    VOID    StopAll();
    HRESULT CreateSegmentFromFile(CMusicSegment** ppSegment, 
        TCHAR* strFileName, BOOL bDownloadNow = TRUE, 
        BOOL bIsMidiFile = FALSE);
    HRESULT Create3DSegmentFromFile(C3DMusicSegment** ppSegment,
        TCHAR* strFileName, BOOL bDownloadNow = TRUE, 
        BOOL bIsMidiFile = FALSE, IDirectMusicAudioPath8* p3DAudioPath = NULL);
    HRESULT CreateScriptFromFile(CMusicScript** ppScript, 
        TCHAR* strFileName);
    HRESULT CreateChordMapFromFile(IDirectMusicChordMap8** ppChordMap,
        TCHAR* strFileName);
    HRESULT CreateStyleFromFile(IDirectMusicStyle8** ppStyle, 
        TCHAR* strFileName);
    HRESULT GetMotifFromStyle(IDirectMusicSegment8** ppMotif, 
        TCHAR* strStyle, TCHAR* wstrMotif);
    HRESULT CreateSegmentFromResource(CMusicSegment** ppSegment, 
        TCHAR* strResource, TCHAR* strResourceType, 
        BOOL bDownloadNow = TRUE, BOOL bIsMidiFile = FALSE);
    VOID Set3DParameters(FLOAT fDistanceFactor, FLOAT fDopplerFactor, FLOAT fRolloffFactor);
};

Constructor

The constructor initializes COM and the private data members.

Public Methods

The class contains the following methods, in alphabetical order.

Method Description
CollectGarbage Calls the IDirectMusicLoader8::CollectGarbage method, after ensuring that the loader still exists.
Create3DSegmentFromFile Loads an object from a file and encapsulates it in a C3DMusicSegment object. If instructed to do so, sets the standard MIDI file parameter and downloads instruments.
CreateChordMapFromFile Loads a chordmap from a file and returns the IDirectMusicChordMap8 interface.
CreateScriptFromFile Loads a script from a file and encapsulates it in a CMusicScript object.
CreateSegmentFromFile Loads an object from a file and encapsulates it in a CMusicSegment object. If instructed to do so, sets the standard MIDI file parameter and downloads instruments.
CreateSegmentFromResource Loads an object from memory and encapsulates it in a CMusicSegment object. If instructed to do so, sets the standard MIDI file parameter and downloads instruments.
CreateStyleFromFile Loads a style from a file and returns the IDirectMusicStyle8 interface.
GetDefaultAudioPath Returns a pointer to the IDirectMusicAudioPath8 interface for the default audiopath created in the Initialize method.
GetListener Returns a pointer to the IDirectSound3DListener8 interface.
GetLoader Returns a pointer to the IDirectMusicLoader8 interface obtained in the Initialize method.
GetMotifFromStyle Loads a motif from a style file and returns the IDirectMusicSegment8 interface.
GetPerformance Returns a pointer to the IDirectMusicPerformance8 interface obtained in the Initialize method.
Initialize Creates the loader and the performance, and initializes the performance with the supplied parameters. Note that in most cases pDs can be NULL.
Set3DParameters Sets the distance factor, Doppler factor, and rolloff factor.
SetSearchDirectory Sets the search directory for all types of objects.
StopAll Stops all playing segments by calling IDirectMusicPerformance8::Stop, after ensuring that the performance still exists.

The class is implemented in (SDK root)\samples\C++\Common\Src\Dmutil.cpp.

See Also