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 may actually play earlier or later than measure 1 beat 1. The band segment doesn't know anything about 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 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 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 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, 0, 0, DMUS_TIME_RESOLVE_MEASURE );
Note If there is no randomness in the notes played by a segment, 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.