Partager via


Making Band Changes Programmatically

In most cases, the band track in a loaded segment performs all necessary program changes. However, you can also do so manually if you have a band object. You must create a secondary segment by using IDirectMusicBand8::CreateSegment, 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 example function creates a segment from a band and plays it on the next measure boundary. It is presumed that the instruments have already been downloaded or that automatic downloading has been enabled.

HRESULT PlayBand(
  IDirectMusicBand8 *pBand,
  IDirectMusicPerformance8 *pPerf,
  REFERENCE_TIME rfTime)
{
  IDirectMusicSegment *pSegment;
 
  HRESULT hr = pBand->CreateSegment(&pSegment);
  if (SUCCEEDED(hr))
  {
    hr = pPerf->PlaySegment(pSegment, DMUS_SEGF_MEASURE | DMUS_SEGF_SECONDARY,
                            rfTime, NULL);
    pSegment->Release();
  }
  return hr;
}

See Also

© 2004 Microsoft Corporation. All rights reserved.