Platform SDK: DirectX

Creating the Performance

[C++]

The manager of music playback is the performance object, which does most of the work of getting music from the source to the output buffer. It performs the following tasks:

Most applications have a single DirectMusicPerformance object, but it is possible to have more than one performance with different parameters, such as master tempo or volume.

The following code example creates a performance and obtains a pointer to the IDirectMusicPerformance interface:

IDirectMusicPerformance* pPerf;
 
if (FAILED(CoCreateInstance(
        CLSID_DirectMusicPerformance,
        NULL,
        CLSCTX_INPROC, 
        IID_IDirectMusicPerformance,
        (void**)&pPerf
    )))
{
    pPerf = NULL;
}

Once the performance is created, it must be initialized. An important part of initialization is the creation of a DirectMusic object. You can create a DirectMusic object by passing CLSID_DirectMusic to CoCreateInstance, and then passing the IDirectMusic interface pointer to IDirectMusicPerformance::Init. However, in most cases, it is more convenient to have Init create the DirectMusic object. You can also choose whether or not to retrieve a pointer to the IDirectMusic interface, depending on how much control you need over ports and the master clock. If you intend to use only the default synthesizer and the default master clock, you probably do not need access to the methods of IDirectMusic; in this case, you would pass NULL to Init.

The following code example initializes the performance, retrieves a pointer to IDirectMusic, and creates an IDirectSound interface initialized with the application window handle:

IDirectMusic* pDirectMusic; 
 
if (SUCCEEDED(pPerf->Init(&pDirectMusic,
        NULL,     // Create a DirectSound object.
        hWnd      // Application window handle
        )))
{
    // Performance initialized
}
[Visual Basic]

The manager of music playback is the performance object, which does most of the work of getting music from the source to the output buffer. It performs the following tasks:

Most applications have a single DirectMusicPerformance object, but it is possible to have more than one performance with different parameters, such as master tempo or volume, or even playing on different ports.

The follow code example, in which objDX is a DirectX7 object, creates a performance with its own DirectSound object, initializes it, and sets it to use the default port with one channel group:

Dim objDMPerformance as DirectMusicPerformance
 
Set objDMPerformance = objDX.DirectMusicPerformanceCreate
Call objDMPerformance.Init(Nothing, 0)
Call objDMPerformance.SetPort(-1, 1)

For more information on setting up the performance, see Integrating DirectMusic and DirectSound and Using Ports.