Platform SDK: DirectX

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.

[C++]

Using the largest building blocks, you load highly structured segments (either style-based or MIDI-based) that contain everything that the performance needs to know about the music 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, plays the MIDI sequence. Band changes are usually contained in the segment, as well.

[Visual Basic]

Using the largest building blocks, you load highly structured segments (either style-based or MIDI-based) that contain everything that the performance needs to know about the music to play it. All you have to do is load the segment by using the DirectMusicLoader.LoadSegment or the DirectMusicLoader.LoadSegmentFromResource method. You then pass the returned DirectMusicSegment object to the DirectMusicPerformance.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, plays the MIDI sequence. Band changes are usually contained in the segment, as well.

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

[C++]

You then construct a segment by combining any chord map, style, and template, using the IDirectMusicComposer::ComposeSegmentFromTemplate method.

To have even more flexibility in music composition at run time, 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 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 might 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.

[Visual Basic]

You then construct a segment by combining any chord map, style, and template, using the DirectMusicComposer.ComposeSegmentFromTemplate method.

To have even more flexibility in music composition at run time, create segments based on predefined shapes, rather than templates, using the DirectMusicComposer.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 might 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 DirectMusicBand.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.