Microsoft DirectX 9.0

Overview of Programming for Composition

When you implement music composed at run time, you will use previously authored objects as building blocks. In consultation with the author or other content provider, you can choose to get the musical data in the form of small building blocks that offer you the greatest possible flexibility and variation at run time, or you can use larger prefabricated elements that define the form of the music more fully.

Using the largest building blocks, you load highly structured segments based on styles, MIDI files, or waveforms that contain everything the performance requires to play the sound. All you have to do is load the segment and query for the IDirectMusicSegment8 interface. Pass this interface pointer to the IDirectMusicPerformance8::PlaySegment or IDirectMusicPerformance8::PlaySegmentEx method. The style playback engine selects pattern variations from the style and plays them according to a fixed chord progression—or, in the case of a MIDI-based segment, simply plays the MIDI sequence. Band changes are usually contained in the segment as well.

If you want to use smaller building blocks, you obtain the following elements:

You can construct a segment by combining any chordmap, style, and template, using the IDirectMusicComposer8::ComposeSegmentFromTemplate method.

To have even more flexibility in music composition at run time, you can create segments based on predefined shapes rather than templates, using the IDirectMusicComposer8::ComposeSegmentFromShape method. The shape is used in creating the command and signpost tracks, which control the choice of embellishment patterns, the chord progression, and the frequency of chord changes.

When playing segments, you can also control the band used to play the parts. Bands are typically included in styles and templates, but they can also be supplied as separate files. To make band changes dynamically, create a secondary segment containing only the band, using the IDirectMusicBand8::CreateSegment method, and play this segment when it is time to assign instruments and instrument settings to the primary segment.

DirectMusic provides many options for creating transitions between segments. When you cue one segment to play after another, or to replace a currently playing segment, you have very precise control over the timing, and can synchronize the transition with the rhythm. In addition, you can have the DirectMusic composer object create a transitional measure.