Most often the band track in a loaded segment will perform program changes. However, you can also do so manually. 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 function 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 band object
IDirectMusicPerformance *pPerf, // Performance to use 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;
}
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. Note, though, that 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.)