Overview of Programming for Composition

As a developer of software that implements 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 and query for the IDirectMusicSegment interface. You pass this interface pointer to the IDirectMusicPerformance::PlaySegment method. The style playback engine then 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 will usually be contained in the segment as well.

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

You then construct a segment by combining any chordmap, style, and template, using the IDirectMusicComposer::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 IDirectMusicComposer::ComposeSegmentFromShape method. The shape is used in creating the command and signpost tracks, which control the groove level of the music, the choice of embellishment patterns, and the chord progression.

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 may be supplied as separate files so that band changes can be made dynamically by the application. In this case, you must create a secondary segment containing only the band, using the IDirectMusicBand::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.