DirectX SDK

Step 1: Create the Performance and Loader

[C++]

This topic pertains only to DirectX for Visual Basic. See DirectMusic C/C++ Tutorials.

[Visual Basic]

The central object of any DirectMusic application is an instance of the DirectMusicPerformance class. Most applications require only a single performance object, although it is possible to have multiple performances playing to different ports, with different tempos, and so on. To load any musical data, the application also needs a DirectMusicLoader object.

To create these objects, you must first declare a global DirectX7 object.

The following global declarations create the DirectX7 object and variables for the other necessary objects:

Public gObjDX As New DirectX7
Public gObjDMLoader As DirectMusicLoader
Public gObjDMPerformance As DirectMusicPerformance

In the startup code, create the performance and loader objects as follows:

Set gObjDMLoader = gObjDX.DirectMusicLoaderCreate
Set gObjDMPerformance = gObjDX.DirectMusicPerformanceCreate

You must also initialize the performance and assign a port to it. The following code has the performance create its own DirectSound object and assigns the default port, which is always either the Microsoft Software Synthesizer or a DLS-capable hardware synthesizer. A single channel group is assigned to the port because a MIDI file requires a maximum of 16 channels. If you are writing an application that plays other kinds of segments as well, you might need to increase this number.

' hWnd is the window handle of the main form
Call gObjDMPerformance.Init(Nothing, hWnd)
Call gObjDMPerformance.SetPort(-1, 1)

Next: Step 2: Load the MIDI File