CREATING NORMAL MUSIC
Now that you've got DirectMusic Producer installed and your MIDI keyboard hooked up, it's time to start creating a song! My process (which you are free to follow) goes like this:Choose instruments that will be used in the music.Create the first band (in other words, set up default panning and volume for the instruments).Create the patterns of music (this is usually the biggest step).String the patterns together in the segment.Tweak everything as needed.Save and enjoy.
Tip | If you don't want to walk through all of the steps in this section, I've included the project file for this appendix on your CD. |
Remember, this section is strictly about creating normal music. You'll walk through all of these steps at their simplest levels (no dynamic features); then, in the later parts of this appendix, you'll revisit what you created in this section and change it from static music into dynamic music.
Creating the Objects
Every journey begins with a single footstep, and every piece of dynamic music begins with a new DirectMusic project. Click New from the file pull-down menu, and select Project. Next, create a new style using the same dialog. Notice how when you created a new style, you automatically got a new band and a new pattern as well.
Tip | The list of objects in the new dialog is multiselectable, so in the future, you can create a new project and a new style in one fell swoop by holding down control and clicking on both Style and Project. |
This example is small, so you can get away with not renaming the objects DirectMusic creates into names more descriptive than Band1, Pattern1, and so on. However, when creating your music for real, you should get in the habit of assigning descriptive names to your patterns.
Icons, Extensions, and File Formats
Before you go any further, you should learn how to recognize the objects you've just created. If you're staring in bewilderment at all the icons in DirectMusic's tree view, this section's for you. Table A.1 provides the icons, file extensions, and short descriptions of the objects available in DirectMusic Producer.
Icon | Object | Normal | Runtime |
---|---|---|---|
![]() | Project—The top-level object | PRO | N/A |
![]() | DLS Collection—Custom instrumentsand samples (drumloops, and so on)live in DLS Collections | DLP | DLS |
![]() | Instrument in a DLS Collection | Embeddedin DLS | Embeddedin DLS |
![]() | WAV file in a DLS collection | WAV | Embeddedin DLS |
![]() | Style—A collection of Patterns,Motifs, and Bands | STP | STY |
![]() | Band—List of instruments used in apattern | BNP | BND |
![]() | Segment—Tells DirectMusic whichstyle (and pattern within that style)to play | SGP | SGT |
![]() | Audiopath—for example, stereo,mono, stereo with reverb, and so on | AUP | AUD |
![]() | Motif—a musical sound effecttriggered by the game (and guaranteedin Style to be in key!) | Embedded | Embedded |
![]() | Pattern—A chunk of music rangingbetween 1 and several measures inin Style length | Embedded | Embedded |
![]() | Script—Tells DirectMusic what to doto play a sound effect | SPP | SPT |
![]() | WAV File—Used for sound effectsor sampled music (for example, guitarriffs) | WVP | WAV |
![]() | Chordmap—Used for dynamic musiccomposition | CDP | CDM |
![]() | Container—Contains custom objects | COP | CON |
![]() | Tool Graph—Applies tools and effectsto certain PChannels | TGP | TGR |
The objects of DirectMusic can be saved to disk in two different ways: regularly or in runtime format. As you're creating your music, you save it normally, but when you're finished and you want to hear your music in your application, you should save in runtime format. The runtime formats don't have editing data in them, so they're a little smaller than their regularly saved counterparts.
Creating a DLS Collection
For this song, you'll use a custom drumloop sample to add some flair. To do this, you need a DLS collection; if all you need are the instruments offered by the General MIDI sound set, you won't need to create a DLS collection.Create the DLS collection by clicking the New button and selecting DLS collection. Next, look at it in your tree view—you'll see it's broken into two folders: instruments and waves.The waves folder contains the raw WAV samples used to create instruments. This means that your first step is to add a WAV sample to the waves folder. Do this by right-clicking on the folder and selecting Insert Wave. Navigate to and select the wave file you want to insert (in this case,


Figure A.3: The controls to set an instrument's ID, and whether or not it's a drum set.
This makes it very easy to input drum tracks. If each drum were its own instrument, you'd have to have different parts for all of them, which means you'd have to first record the bass drum, then the snare drum, then the hi-hats—everything separate. However, with a drum kit, you can record all the drums at once by hitting different keys on your keyboard. It's still not the same as playing real drums, but it's much easier than laying each drum down separately.Immediately to the left of the drums checkbox are three numbers that jointly specify the instrument's ID. MSB stands for Most Significant Byte; LSB is Least Significant Byte. My advice is, unless you have more than 127 custom instruments, just leave the MSB and patch numbers set to zero and use the LSB as the instrument ID. A good strategy is to group like instruments together—for example, start your strings as LSB 10, your woodwinds at LSB 20, and so on.For this example, the instrument ID really doesn't matter, so I just picked MSB 0, LSB 1, patch 0. The shorthand for this is (0, 1, 0).
Tip | For more information on MSB, LSB, and patch numbers, see the DirectMusic documentation, at Playback and Recording\Patch Numbers and Bank Select. |
The next step to creating this custom drumloop is to make sure that your articulation is set up correctly. The term articulation refers to the note's relative volume over time. Different instruments have different articulations; a note played by a piano, for example, gets loud very quickly, then slowly fades off. A note played by a different instrument may start soft and get louder over time. The bleeps of an analog synthesizer are instant-on, instant-off, like the flip of a switch—they have no fade out period.If you were creating a real instrument here, you'd want to adjust the attack, decay, sustain, and release (ADSR) for the volume of the instrument. This is a MIDI thing; attack refers to how quickly the note reaches its maximum volume, delay speaks to how quickly it fades from that maximum volume, sustain represents the volume the note "holds," and release specifies how quickly the note fades out completely (see Figure A.4). Note that there are also four more ADSR values for the instrument's pitch, although these values are rarely changed.

Figure A.4: Every instrument in a DLS1 collection has points for attack, sustain, decay, and release (ADSR).
Tip | At the time of this writing, there are two versions of the DLS standard: DLS level 1 and DLS level 2. The older DLS level 1 specification supports the attack, decay, sustain, and release variables for instruments, but DLS level 2 allows even more precise tweaking, by providing Delay and Hold variables as well (see Figure A.5). If you want to use these, uncheck the DLS1 checkbox, but realize that now your instrument set will only work if the software synthesizer supports DLS2 (DirectMusic, starting with DirectX 8.0, does). For more information on the differences between DLS1 and DLS2, check out the DirectMusic Producer online help, at Playback and Recording\DLS Designer\DLS Level 1 and Level 2. |

Figure A.5: DLS level 2 instruments have delay, attack, hold, decay, sustain, and release points.
Since you're creating a drumloop sample, you don't want anything fancy, so set the attack, decay, and release values at 0.001, and the sustain value at 100%. This tells DirectMusic that the note comes on instantly, stays at full volume, then stops itself instantly—exactly what a drumloop should do.One last thing before you're done creating your custom instrument—uncheck the Note Overlap Allowed checkbox. This tells DirectMusic that if this instrument is playing, and another note for it is encountered, DirectMusic should stop the first note from playing, instead of playing both notes on top of each other. In other words, the instrument has only 1 level of polyphony—only one instance of the sound can be playing at any time. This is great for drum samples and drum loops; it's not so great for regular instruments.Go ahead and press the C5 key on your keyboard a few times, and notice how the sample starts as soon as the key is down, and stops as soon as you lift your finger off the key. If this whole ADSR business is new to you, play around with the variables a little and see how they influence what happens when you hit that C5 key.Congratulations, that's it—you've just created the custom DLS instrument for this example song. There are options in this dialog box that I didn't talk about, because they're not usually used and/or they're not relevant to this example. To fill in the blanks, consult the DirectMusic Producer documentation, at Playback and Recording\DLS Designer.
Tip | An easy assumption to make would be that you have to set up custom DLS collections if you want sound effect segments you can play on demand. You could create a DLS collection, put in your sample, and then just create a segment that played a style containing only one pattern, and in that one pattern there would be only one note—a C5 note of the sound effect you want to play.This would work, but an easier way is to use wave-based segments (that is, segments whose content is a wave file, not notes). DirectMusic supports this, and it's the official and usually best way to integrate sound effects into your project. Creating wave-based segments is covered in Chapter 12. |
Setting Up the Band
Now that you've created the drumloop as a custom DLS instrument, it's time to turn your attention to the style object, and specifically, to the instruments you'd like to use in the patterns of that style.First, the definition: A band is a subset of the General MIDI sound set and any DLS collections you have; a band also tells DirectMusic the default volume, panning, octave, and transposition values for the instruments of the style. Every instrument in a band exists in either the GM sound set or in a custom DLS collection, but not every GM sound set and DLS sound is necessarily in a band. Or, in programmer terms, a band is an added level of indirection for choosing an instrument.Thankfully, setting up a band is less complicated than turning a drumloop WAV file into a DLS instrument. To set up your band, double-click on Band1, inside the Bands folder of your style. You should see the Band Editor, as shown in Figure A.6.

Figure A.6: The band editor of DirectMusic Producer.
First, assign your custom drum sample to PChannel 10. Why channel 10? The MIDI spec says that drum kits must be on channel 10. You told DirectMusic that your drumloop was a drum kit when you checked the drums checkbox in the DLS editor; therefore, DirectMusic will only let you assign that instrument to channel 10.Double-click on PChannel 10 in the left list box (or right-click it and select properties, or press F11—it's all the same). Check the instrument checkbox, then click the big button underneath it. From the pop-up menu that appears, choose the bottom entry: Other DLS. A dialog box will appear in which you can choose a DLS collection and an instrument within that collection to assign to that performance channel. If you've followed the tutorial correctly so far, you should see your (0,1,0) instrument in the list. Click OK to assign this instrument to PChannel 10. Close the properties window and notice that the list box has changed.You also need to set up the two other (real) instruments you'll use in this example music. The music will have two parts—harmony and melody. The harmony will use PChannel 1, and the melody will live on PChannel 2. Since you'll be inputting arpeggios for the harmony, I'd suggest using a piano; for the melody, I chose the "Voice Oohs" GM sound.The graph to the right allows you to adjust the relative volume and panning for the instruments in your band.
Tip | By default, only 16 PChannels are listed in the band editor. You can add more (or delete some of them) by rightclicking inside the list. |
Volume runs vertically, panning horizontally. If you wanted to make an instrument play at maximum volume and center pan, put it on the top, centered. However, you generally don't want to do that just yet. I prefer to adjust panning and relative volumes after I have a pattern put together, so for now, move all of the instruments to the exact center of the graph; you can come back and spread them out later once you have something you can listen to.That should do it for the band!
Creating Your First Pattern
You've created your DLS instruments and assembled your band—now you can create some music. In this section, you'll create one four-measure section of the example song.
The Pattern Editor
Double-click Pattern1, inside the Patterns folder of your style, and the Pattern Editor will appear. Get comfortable with this editor; it's where you'll be spending the bulk of your time. Here's an explanation of everything in this editor, starting at the top and working down.At the very top is your time signature track. The heavy lines are bars (measures), and the dark blue lines are beats within a measure. The red line is the play cursor. You'd think that to change the time signature, you'd right-click here, but instead, you have to right-click on the style node itself, and select properties.Below the timeline is the chord track. This tells DirectMusic which chord goes with each of the measures in your song. You'll learn more about the chord track in a few pages, when you get to the section on Advanced Dynamic Music.Next are the instrument parts. Right now, there's only one instrument part. Notice the maximize and minimize buttons for each part, on the right—go ahead and maximize a part, and you'll be treated to the piano roll display for that part, allowing you to edit notes and variations. At the top are 32 buttons arranged in a 16x2 grid. These are the variation buttons; you'll learn more about them when you get to the Dynamic Music section.
Tip | Note that you can stretch the main windows vertically by hovering your mouse over their vertical boundaries (watch for the icon to change) and dragging. |
To the left of the variation buttons are the vertical zoom in and zoom out buttons; their horizontal counterparts are located to the right of the horizontal scroll bar at the bottom of your window. Table A.2 describes the hotkeys for zooming.
Hotkey | Result |
---|---|
A | Vertical zoom in |
Z | Vertical zoom out |
I | Horizontal zoom in |
O | Horizontal zoom out |
To the left of the vertical zoom buttons is a button that allows you to change the instrument for this particular part. Note that what you're really doing here is changing the band; selecting a new instrument here is equivalent to going to the band editor and selecting a new instrument for that PChannel. Next to the instrument name is a little band button that acts as a shortcut to the band editor.Now you get to the piano roll display. This is the core of the pattern editor. Time runs horizontal, pitch vertical, and notes are represented as bars. The louder the note, the taller the bar, and the longer the note, the wider the bar. You can click a piano key with your mouse and hear that note; you can also insert a note at the current cursor position (red line) by hitting the insert key. You can select and manipulate notes using common selection methods and functions (cut, copy, paste, and so on).Below the piano roll is the variation switch point track. This track tells DirectMusic when it's safe to switch variations in mid-pattern. You'll learn more about it in the Advanced Dynamic Music section.The final, lowest track is the CC, or Control Curve track. This is where control commands, such as pitch bend and modulation, live. You'll learn how to set up a control curve in this section.
Entering Some Notes
Enough chat—now it's time to make some music. You'll start by lengthening Pattern1 inside the Patterns folder of your style. Do this by opening the properties for the pattern and upping the length of the pattern. I like to over-lengthen the patterns at first, and adjust them to their proper lengths after I've recorded data into them. Super-long patterns allow you to record several takes at once, without having to hit stop, rewind, and record again. Then, once you have several takes recorded, you pick the one that you like best, delete everything else, and move your good take to the start of the pattern (either through cut and paste or by selecting the notes and dragging them all at once).To enter notes, maximize the first part and highlight the piano roll by clicking anywhere inside it (it will turn light yellow). Next, move your cursor to the beginning of the song by clicking, or by pressing the home key. Finally, click the record button to start recording. Alternatively, you can also create notes by clicking where you want the note, and hitting the insert key—it's tedious, but it's one way of inputting music if you don't have a MIDI keyboard.Summon your mad keyboarding skills (you do have mad keyboarding skills, right?) and input the eight measures shown in Figure A.7.

Figure A.7: Eight-measure background piano part for Pattern1.
Tip | As you're recording, if you'd like the computer to keep time for you, click on the little metronome toolbar button. |
The musical theorists out there will instantly recognize the chord progression in Figure A.7 as a simple I—VI—IV—V progression in the key of C. This means that the pattern starts in the key of C major, moves to A minor, F major, and then to G major. Keep this in mind; it will become important in later sections.
Quantizing Notes
After you input your notes, you'll notice that (unless you're a very, very good musician) you hit certain notes a little early, and others a little late. You should correct these so that everything is lined up exactly on the beat or grid that it's supposed to be on. If you want to preserve the "live human performance" feel, you can add random delays using the note properties window shown in Figure A.8 (after you've corrected the notes).

Figure A.8: The note properties window.
To begin lining up your notes, right-click in the piano roll and select Snap To None from the context menu that appears. This will allow you to move the notes around freely. You can move a note graphically by grabbing its middle (watch for your mouse cursor to change), or numerically using the note properties window. Don't worry about getting the notes lined up perfectly—just get them pretty close.Once you've done that, you can have the computer take over. This is like washing dishes—you get them sort of clean and the machine gets them really clean. The computer can make your notes start at exactly the right time through a procedure called quantization. Quantization is just a fancy word for snapping notes to the nearest beat you specify. You can choose to quantize based on quarter notes, eighth notes, and a wide variety of other things. For this example, you'll want to quantize on eighth notes, so go to the Edit pull-down menu, select Quantize, adjust the parameters as needed, and hit OK.It may take a couple of tries to get the note timings exactly right. DirectMusic Producer may snap some notes incorrectly during quantization, so you should play your work in progress after you've finished lining up the notes to make sure it sounds correct.
Adding Additional Parts
What you just entered was just the background chords; now it's time to add the melody. First, jump back over to your band editor and add Voice Oohs (or your favorite melody-carrying instrument) to PChannel 2. Then, jump back into the pattern editor and right-click on the piano roll. Click Add Pattern Parts, near the bottom of the context menu, to add a new part for PChannel 2.
Tip | Alternatively, you could have recorded both melody and chords at once into the piano track. Then, once you had both recorded, you could cut the melody out and paste it into the second part. |
Now you can highlight part 2's piano roll and input the melody in Figure A.9. After that, quantize the notes as explained in the previous section.

Figure A.9: The melody part for Pattern1.
Finishing Up Pattern Input
Now that you've seen the process in detail, gain some experience by practicing. Create another pattern and input the two parts and eight measures shown in Figure A.10.

Figure A.10: Background and melody parts for Pattern2.
You should now have a full 16 measures of music.
Tip | If you already have a favorite piece of software that can record in MIDI, you can use that to record your playing and just import MIDI files into DirectMusic Producer. In DirectMusic Producer, select Import File into Project off the File menu, and go from there. |
Stringing Patterns Together Inside the Segment
The final step to creating the basic song is to string these five patterns together. To do that, you'll need a segment—go ahead and create a new one, 16 measures long.DirectMusic Producer will automatically prompt you to add tracks; by default, a segment has only a time signature track. You want to add a style track and a groove track.The style track tells DirectMusic what styles to play, and when to play them. In this example, the style track is very straightforward—you want it to play the style you created in the previous section, for the entire length of the segment. Position your play cursor at the beginning of the segment (hit the home key) and press the insert key to insert a new entry into the style track. The style properties dialog will appear, allowing you to select a style. You should see your style listed in the drop-down list; select it, and set it to take effect at measure 1. Also note that when you insert your entry, a new band track appears, preset to the band in your style.Now DirectMusic knows that at measure 1 of your segment, it should use some particular pattern inside the style you specified. But how does it know which pattern? If you play the segment at this point, you'll hear one of your patterns at random. That's great for certain situations, but what if you want your patterns to be played in a certain order?That's where the groove track comes in. The groove track provides two vital parameters—first, it sets the groove level, which DirectMusic Producer uses to "rule out" patterns in the style (patterns with a groove range outside the current groove level cannot be played). The second vital parameter tells DirectMusic what to do when more than one pattern can be played. By default, DirectMusic plays one pattern at random, but you can change this to have it play all of the valid patterns in order—exactly what you need for this demo song.Right-click on the groove track and select Properties. From the Properties window that appears, select Sequential from First from the Repeat Pattern drop-down menu. Now, play your song—you should hear all of your patterns played in the correct order.
Looping the Segment
One last thing—you need to make the eighteen measures of your segment loop infinitely. Rightclick on the segment in the tree and select properties. From the segment properties window, select the loop tab, then click the Infinite checkbox. As you can see, there's other advanced looping parameters you can use, but most of the time a simple infinite loop will get the job done just fine.
Saving as Runtime Format
At this point you've done enough to be able to use this (short) piece of music in your game. But, to do so, you need to save it in runtime format. This is as easy as selecting Runtime Save All from the File menu.
Tip | You can embed copyright and other miscellaneous information into your music by using the info tab found in most of the property windows for your objects. The info tab allows you to specify a subject, author, copyright, and version, along with any additional text you'd like. |
When you do this, DirectMusic Producer saves each file in your project in runtime format. (much quicker than compiling source code!) It puts the runtime files in a RuntimeFiles directory inside your project's home directory, usually inside My Documents\DMUSProducer.