Microsoft DirectX 8.1 (Visual Basic) |
The application now has all the objects it needs for loading and playing sounds. In the sample, one of three sound files is always played in response to the Play button, depending on the user's choice of file type.
The LoadSound procedure is called in response to the first click of the Play button, and also in response to the selection of an option button. The first thing the procedure does is verify that the file exists, as follows:
If Dir$(sFile) = vbNullString Then
MsgBox "Unable to find " & sFile, vbOKOnly Or vbCritical, _
"Not found."
Unload Me
End If
If a segment has already been loaded, its band or bands are unloaded from the synthesizer, and the segment is released:
If Not (dmSeg Is Nothing) Then
dmSeg.Unload dmPath
Set dmSeg = Nothing
End If
Then the new segment is loaded. If it is a MIDI file, the application calls DirectMusicSegment8.SetStandardMidiFile. A standard MIDI file behaves somewhat differently than one that has been saved as a DirectMusic Producer segment, and this call ensures that it is handled properly.
Set dmSeg = dml.LoadSegment(sFile)
If Right$(sFile, 4) = ".mid" Then dmSeg.SetStandardMidiFile
The LoadSound procedure is concluded in the next topic, Step 5: Download the Band