Microsoft DirectX 8.0 (Visual Basic) |
A curve is a series of MIDI controller changes bringing about a smooth transition from one value to another—for example, volume fade-out or fade-in.
You can execute a curve by sending a single performance message, using DirectMusicPerformance8.SendCurvePMSG. The DMUS_CURVE_PMSG type passed to this method enables you to set the start and end values, the duration of the curve, and its shape. Optionally, you can also set a reset value, which is the value to which the controller will return in case of an invalidation.
The measure, offset, beat, grid, and mtOriginalStart members of the message structure are used in messages sent by DirectMusic Producer segments. In messages sent by applications, these values should be 0.
The MergeIndex member is used to determine whether changes are cumulative or overriding. Two curve messages with different merge indexes are cumulative; otherwise, each message in turn overrides settings made by a previous message.
The ccData member contains the MIDI controller number for controller changes, and is otherwise ignored. For information on controller numbers, see the MIDI specification.
The following sample code fades out the current volume over a duration of 5 seconds:
Dim curveMsg As DMUS_CURVE_PMSG curveMsg.curveShape = DMUS_CURVES_LINEAR curveMsg.mtDuration = 5000 curveMsg.Type = DMUS_CURVET_CCCURVE curveMsg.ccData = 7 ' MIDI channel volume controller curveMsg.flags = DMUS_CURVE_START_FROM_CURRENT dmPerf.SendCurvePMSG 0, _ DMUS_PMSGF_REFTIME Or DMUS_PMSGF_LOCKTOREFTIME, _ DMUS_PCHANNEL_BROADCAST_PERFORMANCE, curveMsg
Note A simpler way to implement volume fading is by using DirectMusicAudioPath8.SetVolume. This method always uses the linear shape for the curve.
The following code changes the pitch bend from the current value to the maximum value over a duration of 3 seconds. If an invalidation occurs during that period, which might happen if another segment replaces the currently playing segment, the pitch is reset to the value in g_Pitch.
curveMsg.curveShape = DMUS_CURVES_LINEAR curveMsg.startValue = 0 ' Ignored, start from current. curveMsg.endValue = 16383 curveMsg.mtDuration = 3000 curveMsg.Type = DMUS_CURVET_PBCURVE curveMsg.ccData = 0 curveMsg.flags = DMUS_CURVE_RESET Or DMUS_CURVE_START_FROM_CURRENT curveMsg.resetValue = g_Pitch curveMsg.mtResetDuration = 0 dmPerf.SendCurvePMSG 0, _ DMUS_PMSGF_REFTIME Or DMUS_PMSGF_LOCKTOREFTIME, _ DMUS_PCHANNEL_BROADCAST_PERFORMANCE, curveMsg