Microsoft DirectX 8.1 (C++)

Making Band Changes Programmatically

Usually, 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 IDirectMusicBand8::CreateSegment method, and then play that segment by calling IDirectMusicPerformance8::PlaySegment or IDirectMusicPerformance8::PlaySegmentEx. Typically, you would use DMUS_SEGF_MEASURE or DMUS_SEGF_GRID in the dwFlags parameter to ensure that the band change takes effect on an appropriate boundary.

The following sample function creates a segment from a band and plays it. It is presumed that the instruments have been downloaded or that automatic downloading has been enabled.

HRESULT myPlayBand(
  IDirectMusicBand8 *pBand,    // Pointer to a band object.
  IDirectMusicPerformance8 *pPerf, // Performance to use the band.
  REFERENCE_TIME rfTime,     // Time to play at.
  DWORD dwFlags)       // Performance flags.
{
  IDirectMusicSegment *pSegment;
 
// We don't need IDirectMusicSegment8, which we'd have to QI for. 
 
  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 two bands are mapped to different performance channels, no conflict arises. Note, though, that motif segments don't always have their own band tracks, so you might get silence from the motif's channels unless you first create a band segment and play it.