Step 9: Handle Notifications

Back in Step 4: Set Up Notifications you saw how DMDonuts requests notification whenever a segment ends and whenever a beat or measure boundary is reached. The purpose of this notification is to help limit the number of blowup motifs playing at any one time.

Notifications are retrieved in the WinMain function. After dealing with any messages in the queue, the application checks to see if there are any pending notifications. It does this by calling the IDirectMusicPerformance::GetNotificationPMsg method. If no notification message is pending, the method returns S_FALSE and no further action is needed. A return of S_OK indicates that a notification message has been placed in *pEvent. Because it has only requested notifications relevant to the beat, the application does not actually need to examine the message, which is immediately discarded. It then resets snMaxBlowUps, which tracks how many more blowup motifs can be played till the next beat.

if (gpPerformance)
{
    DMUS_NOTIFICATION_PMSG* pEvent;
    while ( S_OK == gpPerformance->GetNotificationPMsg(&pEvent))
    {
        gpPerformance->FreePMsg((DMUS_PMSG*)pEvent);
        snMaxBlowUps = BLOWUPS_PER_BEAT;
    }
}

Next: Step 10: Shut Down DirectMusic

 Last updated on Monday, April 12, 2004

© 1992-2002 Microsoft Corporation. All rights reserved.