Microsoft DirectX 8.1 (C++)

PlayMotif

Description

The PlayMotif sample demonstrates how a motif played as a secondary segment can be aligned to the rhythm of the primary segment in various ways.

Path

Source: (SDK root)\Samples\Multimedia\DirectMusic\PlayMotif

Executable: (SDK root)\Samples\Multimedia\DirectMusic\Bin

User's Guide

Play the default segment, or load another DirectMusic segment based on a style that contains motifs. Select one of the patterns in the list box and one of the Align Option buttons, and then click Play Motif. Note how the motif does not begin playing until an appropriate boundary in the primary segment has been reached.

Programming Notes

The PlayMotif sample is very similar in form to the PlayAudio sample. For detailed programming notes on the basics of this sample, see PlayAudio.

When loading the file, PlayMotif performs the same steps as PlayAudio, with the following additions in the LoadSegmentFile function:

  1. Loops through styles in the segment, searching it for motifs. It calls IDirectMusicSegment8::GetParam, passing GUID_IDirectMusicStyle and an incrementing index to get each of the styles in turn. The method fails when there are no more styles.
  2. For each style, it calls IDirectMusicStyle8::EnumMotif, passing an incrementing motif index. This call retrieves the motif name at that index. When the call returns S_FALSE, there are no more motifs in the style.

Passes the motif name to IDirectMusicStyle8::GetMotif to get an IDirectMusicSegment8 interface pointer to the motif, and stores this as data associated with the item in the list box.

When Play Motif is clicked, the OnPlayMotif function performs the following tasks:

  1. Retrieves the desired alignment option from the interface.
  2. Gets the selected motif from the listbox, along with its MOTIF_NODE item data.  The MOTIF_NODE structure keeps a count of the number of plays currently occurring, as well as a pointer to the IDirectMusicSegment interface of the motif.
  3. Calls IDirectMusicPerformance8::PlaySegment, passing the motif's IDirectMusicSegment and flags including DMUS_SEGF_SECONDARY as well as any alignment option.

DirectMusic notifications are handled much as in PlayAudio, but this application also takes note of any motif starting or stopping and updates the play count in the MOTIF_NODE structure. If the play count is greater than zero then it updates the user interface to show that the motif is playing.

See Also