Microsoft DirectX 8.1 (C++)

Ensuring Timely Band Changes

A consideration in playing band segments is the randomness in the timing of notes played by a style track. For instance, a note that is on measure 1, beat 1 might actually play somewhat earlier or later than the actual beat boundary. The band segment isn't aware of this, with the result that some of the notes might play with the incorrect instrument.

To prevent this problem, an application should cue the band segment early. Suppose, for example, that you have a style-based segment pStyleSeg and a band segment pBandSeg. You want to play both the style segment and the band segment on the next measure boundary of the performance (pPerf). You know that the style contains notes that could go out up to 30 ticks earlier, in music time, than the start time of the segment. The following code example ensures that the band segment is played 31 ticks before the style segment, so all instruments are in place before any note is played:

// First get the time of the next measure, and convert it to 
// music time. 
 
REFERENCE_TIME rtResolved;
MUSIC_TIME mtResolved;
 
pPerf->GetResolvedTime( 0, &rtResolved, DMUS_TIME_RESOLVE_MEASURE );
pPerf->ReferenceToMusicTime( rtResolved, &mtResolved );
 
// Now play the band segment 31 ticks before the measure boundary.
 
mtResolved -= 31; 
pPerf->PlaySegment(pBandSeg, 0, mtResolved, NULL);
 
// Play the style segment on the measure boundary.
 
pPerf->PlaySegment(pStyleSeg, DMUS_TIME_RESOLVE_MEASURE, 0, NULL);

Note   If there is no randomness in the notes played by a segment (for example, one loaded from a MIDI file), you don't need to worry about the timeliness of a band segment played at the same time. By default, all band segments start 1 tick early.