Microsoft DirectX 8.1 (Visual Basic)

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 (either style-based or MIDI-based) that contain everything the performance needs to know about the music in order to play it. All you have to do is load the segment by using the DirectMusicLoader8.LoadSegment or the DirectMusicLoader8.LoadSegmentFromResource method. You then pass the returned DirectMusicSegment8 object to the DirectMusicPerformance8.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 DirectMusicComposer8.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 DirectMusicComposer8.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 DirectMusicBand8.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.