The tempo of a performance dictates the conversion between the two types of time used in DirectMusic, which in turn controls the resolution of events to musical boundaries. (See Reference Time vs. Music Time.) The tempo track of the primary segment usually controls the tempo, but it is also possible for an application to set the tempo dynamically.
There are two ways to do so: by sending a message, and by setting a track parameter.
The following example sends a message to change the tempo:
/* Assume that pIDMSegment is a valid IDirectMusicSegment, and
IDMPerformance is a valid IDirectMusicPerformance. */
// Disable tempo track in segment so that it does not reset tempo
pIDMSegment->SetParam( GUID_DisableTempo, 0xFFFF,0,0, NULL );
DMUS_TEMPO_PMSG* pTempo;
if( SUCCEEDED(pIDMPerformance->AllocPMsg(
sizeof(DMUS_TEMPO_PMSG), (DMUS_PMSG**)&pTempo)))
{
// Queue tempo event
ZeroMemory(pTempo, sizeof(DMUS_TEMPO_PMSG));
pTempo->dwSize = sizeof(DMUS_TEMPO_PMSG);
pTempo->dblTempo = 100;
pTempo->dwFlags = DMUS_PMSGF_REFTIME;
pTempo->dwType = DMUS_PMSGT_TEMPO;
pIDMPerformance->SendPMsg((DMUS_PMSG*)pTempo);
}
The following sample code shows how to change the tempo parameter. For more information, see Setting and Retrieving Track Parameters.
DMUS_TEMPO_PARAM Tempo;
Tempo.dblTempo = 100;
pIDMSegment->SetParam(GUID_TempoParam, 0xFFFF, 0, 0, &Tempo);