Microsoft DirectX 8.1 (Visual Basic) |
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 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.PlaySegmentEx(bandSeg, 0, mtResolved)
' Play the style segment on the measure boundary.
Call perf.PlaySegmentEx(styleSeg, DMUS_SEGF_MEASURE, 0 )
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.