DirectX SDK

Making Band Changes Programmatically

Usually, the band track in a loaded segment performs program changes. However, you can also do so manually.

[C++]

First, create a secondary segment with a call to the IDirectMusicBand::CreateSegment method, and then play that segment by calling IDirectMusicPerformance::PlaySegment. Typically, you would use DMUS_SEGF_MEASURE or DMUS_SEGF_GRID (see DMUS_SEGF_FLAGS) in the dwFlags parameter to ensure that the band change takes effect on an appropriate boundary.

The following code example creates a segment from a band and plays it:

/ * It is presumed that automatic downloading is turned on or that the application has called pBand->Download. */
 
HRESULT myPlayBand(
    IDirectMusicBand *pBand,         // Pointer to a band object
    IDirectMusicPerformance *pPerf,  // Performance to use the band
    REFERENCE_TIME rfTime,           // Time to play at
    DWORD dwFlags)                   // Performance flags
 
{
    IDirectMusicSegment *pSegment;
    HRESULT hr = pBand->CreateSegment(&pSegment);
    if (SUCCEEDED(hr))
    {
        hr = pPerf->PlaySegment(pSegment,
                dwFlags | DMUS_SEGF_SECONDARY,
                rfTime,
                NULL);
        pSegment->Release();
    }
    return hr;
}
[Visual Basic]

First, create a segment by using DirectMusicBand.CreateSegment, and then play that segment by calling DirectMusicPerformance.PlaySegment. Typically, you would use DMUS_SEGF_MEASURE or DMUS_SEGF_GRID (see CONST_DMUS_SEGF_FLAGS) in the lFlags parameter to ensure that the band change takes effect on an appropriate boundary.

A performance can be playing instruments from more than one band at a time. For example, suppose your application is playing a primary segment using one band, and then plays a motif from a style that has a different band. As long as the instruments in the first band are mapped to different PChannels than the instruments in the second, no conflict arises. However, motif segments do not normally have their own band tracks, so you might get silence from the motif's PChannels unless you first create a band segment and play it. (It is possible to add a band track to a motif segment, but creating a separate band segment is easier.)