Platform SDK: DirectX

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 is not aware of this; therefore, some of the notes might play with the incorrect instrument.

[C++]

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 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);
[Visual Basic]

To prevent this problem, an application should cue the band segment early. Suppose, for example, that you have a style segment styleSeg and a band segment bandSeg. You want to play both the style segment and the band segment on the next measure boundary of the performance (perf). 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. 
 
Dim ctResolved As Long
Dim mtResolved As Long
 
ctResolved = perf.GetResolvedTime(ctResolved, DMUS_SEGF_MEASURE)
mtResolved = perf.ClockToMusicTime(ctResolved)
 
' Now, play the band segment 31 ticks before the measure boundary.
 
mtResolved = mtResolved - 31 
Call perf.PlaySegment(bandSeg, 0, mtResolved)
 
' Play the style segment on the measure boundary. 
 
Call perf.PlaySegment(styleSeg, DMUS_SEGF_MEASURE, 0 )

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