DirectX SDK |
This topic pertains only to application development in DirectX for Visual Basic.
In the definition of the Vocals instrument in Boids.dls, the region of the heart sample is in the range from B7 through B8. As the sound is playing in the sample application, the user can choose a note within this region by using the Note slider. Each time the slider is changed, the existing note is stopped, and a new one is sent.
Because the duration of the note is indefinite, it is sent in the form of a standard MIDI note-on message by using DirectMusicPerformance.SendMIDIPMSG. (You could also use DirectMusicPerformance.SendNotePMSG, specifying a very large number for the duration of the note.) The current frequency and velocity are given in the last two parameters. Because the method accepts the channel as a separate parameter, the MIDI status byte (&H90) does not contain the channel number in the 4 lower bits, as it would in a standard MIDI message.
Call perf.SendMIDIPMSG(0, DMUS_PMSGF_REFTIME, hbchannel, _ &H90, B7Freq, gVelocity)
In addition to changing the note for the heartbeat, the user can also assign a pitch bend to the channel on which the note is played. The pitch bend is also sent as a standard MIDI message:
Call perf.SendMIDIPMSG(0, DMUS_PMSGF_REFTIME, hbchannel, _ &HE0, lo, hi)
The lo and hi parameters are 7-bit values, so there are 16,384 possible settings for a pitch bend. For more information, see the MIDI specification.
To stop the heartbeat note, the sample application sends a note of the same pitch as the currently playing note, using the SendNotePMSG method, with the flags member of the DMUS_NOTE_PMSG type set to 0, instead of the usual DMUS_NOTEF_NOTEON.
Private Sub B7NoteOff() Dim noteMsg As DMUS_NOTE_PMSG noteMsg.flags = 0 noteMsg.midiValue = B7Freq ' B7Freq is pitch of last note-on Call perf.SendNotePMSG(0, DMUS_PMSGF_REFTIME, hbchannel, noteMsg) End Sub
The pitch bend on the channel does not affect this operation.