Microsoft DirectX 8.1 (C++)

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 waves that contain everything the performance needs in order to play the sound. All you have to do is load the segment and query for the IDirectMusicSegment8 interface. You 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 authored right into 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. For more information, see Using Bands.