Now that we have a basic piece of music playing over some chord changes, we want to add some variation to the playback so that each time our bass line plays, it plays a little bit differently. Open the BassSegment.sgt that we created earlier, and open the Pattern Track. Notice the variation bar. By default, DirectMusic Producer fills in all of these variations with the same data.

click to expand
Figure 5-9: The variation bar.

Select only the variation to work on. Notice in the above figure that we selected all variations because every number in the bar is depressed. You can quickly select or unselect all variations by clicking the vertical bar on the leftmost edge of the variation bar. Click this bar so that every variation number is not depressed, then select variation 2. Your variation bar should look like this:

click to expand
Figure 5-10: Only variation 2 is selected.

In the pattern, raise the note on the second beat to an E, and lower the last note to an E. Your pattern should look like this:

click to expand
Figure 5-11: Our first bass line variation.

If we play the project now, we would only hear this variation one out of 32 times, since DirectMusic fills out our 32 Segments for us by default. To have the variation play more often, disable all variations except for variations 1 and 2 by deselecting variation 2 and selecting variations 3 and higher. Right-click on the Variation tab, and select Disable. Your Variation tab should now look like this:

click to expand
Figure 5-12: Variations 1 and 2 are enabled, while all others are disabled.

Play the master Segment, and notice how both our original bass line and our variation play.

Again, we saved a completed version of this section of the tutorial on the companion CD in the folder Unit I\Chapter 5\Tutorial Part Two.


In the previous two sections of this chapter, we stored our musical data in Pattern Tracks. Pattern Tracks have a lot of power, as they can follow chord changes in multiple ways and contain up to 32 variations. However, even more powerful than patterns are Styles. As defined in Chapter 4, a Style is a collection of patterns, which DirectMusic chooses based on various parameters. Each pattern within a Style acts just like Pattern Tracks, containing chord mappings and variations. Moreover, because you can place multiple patterns within a Style, they allow you an unlimited number of variations. More importantly, they respond to the groove level.

While groove level can be used in many ways, it is easiest to think of it as an intensity filter. Each pattern within a Style has a groove range in which it is valid. Our melodic line might be simpler at groove levels one through ten, while a more active one is used from 11 to 20. When the Style is choosing the pattern to play, it looks at the current groove level and determines which patterns are valid within the Style. A typical game implementation involves tying groove level to the intensity of the current game situation. If there is a lot of action going on, the groove level raises and the music intensifies, and when the action dies down, the groove level lowers and the music calms down.

Creating Our First Style

Create a new Style by clicking File>New and selecting Style from the menu. In the left-hand menu, open the folder in the Style named Patterns. Double-click on the pattern to open it. Using the same techniques we used in the first tutorial in this chapter, copy the data from our melody pattern to this Pattern Track. You will need to set the pchannel for this part to two, as well. Now select the pattern in the left-hand menu, and press Ctrl+C to copy it into memory and Ctrl+V to paste it. Your Style should now have two patterns called pattern one and pattern two. Open pattern two, and adjust the notes to make the melody into more of an accompaniment Style line. You can use the right-click menu on the mouse to add new notes if you need to. Our accompaniment looks like this:

click to expand
Figure 5-13: Our accompaniment pattern.

Rename the Style Piano.

Open our MasterSegment file, and use the right-click menu to delete our current melody Segment Trigger Track. Use the right-click menu to add a Style Track. Right-click on the first bar in the Style Track, and select Insert. Select our Piano Style from the menu.

Press Play on the master Segment and notice that both patterns are chosen from our Style. Also of note is that we do not have to place references to our Style in every measure of the master Segment. This is because a Style Track is assumed to repeat, unlike our Segments, which have a fixed length.

Adding Groove Level

Go back to our Style, and bring up the properties on pattern two. Notice that there is a Low and High setting under Groove Range. This sets which groove levels this pattern is valid. Set these numbers to 1 and 10, respectively. This will make this pattern only viable from groove levels one to ten.

Now select pattern one, and set its groove range from five to 100.

Go back to our master Segment, and use the right-click menu to add a new track. This time, select Groove Track from the menu. Select the first bar in the Groove Track and press Insert.

Play the master Segment, and notice that only pattern two is used. This is because our groove level is set to 1, which is not a valid groove level for pattern one to play. Now set the groove level to 6 in our Groove Track, and play the master Segment. You will notice that both patterns now play. This is because both patterns are valid, so DirectMusic will choose between them every measure.

Set the groove level to 11 in our Groove Track. You will notice that only pattern one plays, because pattern two's groove range is too low to play. Save your project.

The wonderful thing about using groove levels to control your music is that it's very easy to work with and test on the musical end and provides a simple mapping for a game to use that doesn't require your programmers to understand how your music is composed. Often, groove level can be tied to something very simple for a game engine to understand, such as the number of monsters in the area, and the composer can decide what the music should do in these cases.

Once again, we saved a completed version of this section of the tutorial on the companion CD in the folder Unit I\Chapter 5\Tutorial Part Three.

This chapter offered some insight into the basic mechanics of using DirectMusic Producer. While DirectMusic Producer can seem daunting at first, once you become familiar with the interface, you will find it efficient and well designed. Remember to start small and be prepared to build several projects as a learning experience.