DirectX SDK

Changing the Tempo

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 Clock Time vs. Music Time.) The tempo track of the primary segment usually controls the tempo, but an application can also set the tempo dynamically.

[C++]

There are two ways to do so: by sending a message and by setting a track parameter.

The following code 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 the 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 the 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 code example 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);
[Visual Basic]

There are two ways to do so: by setting the master tempo and by sending a tempo message.

The master tempo is a factor by which all tempos in the performance are multiplied. For example, if you set the master tempo by calling DirectMusicPerformance.SetMasterTempo with a parameter of 0.75, and then play a segment that has a tempo of 120 beats per minute, the segment plays with a tempo of 90.

Sending a tempo by using the DirectMusicPerformance.SendTempoPMSG method changes the tempo at the time for which the message is stamped. The new tempo is valid until another tempo message is sent, either directly by the application or by a segment that is being played. The tempo value can be modified by the master tempo.

The following call, where perf is a DirectMusicPerformance object, immediately sets the tempo to 100 beats per minute. If you pass 0 as the lTime parameter to signify that the message is to go out immediately, you must also set the DMUS_PMSGF_REFTIME flag.

Call perf.SendTempoPMSG(0, DMUS_PMSGF_REFTIME, 100)