Microsoft DirectX 8.1 (C++)

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 control segment usually manages the tempo, but it is also possible for an application to set the tempo dynamically.

There are two ways to change the tempo: by sending a message and by setting a track parameter on the control segment.

The following code example sends a message to change the tempo:

// Assume that pIDMSegment is a valid IDirectMusicSegment8 and 
// IDMPerformance is a valid IDirectMusicPerformance8. 
 
// 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)))
{
  // Cue 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 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);

You can also change the master tempo, which adjusts the tempo set by any control segment. See Setting and Retrieving Global Parameters