Microsoft DirectX 9.0

CMusicSegment Sample Class

The CMusicSegment sample class represents a segment, and contains methods for downloading and unloading instruments, playing and stopping the segment, and retrieving a style from the segment.

class CMusicSegment
    IDirectMusicSegment8*     m_pSegment;
    IDirectMusicLoader8*      m_pLoader;
    IDirectMusicPerformance8* m_pPerformance;
    IDirectMusicAudioPath8*   m_pEmbeddedAudioPath;
    BOOL                      m_bDownloaded;

    CMusicSegment(IDirectMusicPerformance8* pPerformance, 
                  IDirectMusicLoader8* pLoader,
                  IDirectMusicSegment8* pSegment);
    virtual ~CMusicSegment();
    inline  IDirectMusicSegment8* GetSegment() { return m_pSegment; }
    HRESULT GetStyle(IDirectMusicStyle8** ppStyle, 
        DWORD dwStyleIndex = 0);
    HRESULT SetRepeats(DWORD dwRepeats);
        IDirectMusicAudioPath8* pAudioPath = NULL);
    HRESULT Stop(DWORD dwFlags = 0);
    HRESULT Download( IDirectMusicAudioPath8* pAudioPath = NULL );
    HRESULT Unload(IDirectMusicAudioPath8* pAudioPath = NULL);
    BOOL    IsPlaying();


The constructor stores pointers to the performance, loader, and segment objects. It also attempts to create an audiopath from an audiopath configuration embedded in the segment.

Public Methods

The class contains the following public methods, in alphabetical order.

Method Description
Download Downloads the segment's instruments to the supplied audiopath. If no audiopath is supplied, this method downloads to the embedded audiopath if there is one, or to the performance otherwise.
GetSegment Retrieves the IDirectMusicSegment8 interface pointer.
GetStyle Retrieves a style in the segment, if the segment has a style track.
IsPlaying Returns a Boolean variable that specifies whether the segment is playing. This method calls IDirectMusicPerformance8::IsPlaying.
Play Plays the segment, using the specified flags and audiopath. If no audiopath is specified, this method plays on the embedded audiopath if there is one, or on the default audiopath otherwise. The method fails if the instruments have not been downloaded.
SetRepeats Calls IDirectMusicSegment8::SetRepeats.
Unload Unloads instruments from the specified audiopath. If no audiopath is specified, this method unloads from the embedded audiopath if there is one, or from the performance otherwise.

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

See Also