Platform SDK: DirectX

Step 6: Play a Primary Segment

[Visual Basic]

This tutorial pertains only to applications written in C++. See DirectMusic Visual Basic Tutorials.

[C++]

In the previous step, the setup_game function in Donuts.cpp called the ComposeNewSegments function, which created two primary segments to be used for the current game level. Now the setup_game function plays the first of these segments:

gpPerformance->PlaySegment(
    gapSegment[SEGMENT_1], 0, 0, NULL);
 

Note that the absence of any flag causes the segment to be played immediately.

The function now plays the default band segment that was created for the current style. (Remember, there are two different styles that alternate when the game level changes. Each style has two bands, the default band and the "shield" band.) Playing the band segment ensures that the correct set of instruments is playing the music. Note that the band segment must be flagged as secondary. No start time is given in the third parameter because the changes are to be made immediately, and the last parameter is NULL because we don't require a pointer to the segment state.

gpPerformance->PlaySegment(
    gapDefaultSegment[gnCurrentStyle], 
    DMUS_SEGF_SECONDARY, 
    0, NULL);
 

The default band for the style is used when the player's ship is unshielded, which is always the case at the beginning of a level. The application plays the second band inside the UpdateDisplayList function in response to the shields being turned on, and plays the default band again when the shields are turned off.

Next: Step 7: Transition to Another Primary Segment