DirectX SDK |
By default, when you play a MIDI file, the instruments used are those in the Roland GM/GS Sound Set, contained in the Gm.dls file. However, you can play a MIDI file, using instruments from any collection.
To do so, first load the collection, as described in Loading a Collection, obtaining a pointer to the IDirectMusicCollection interface. Then call IDirectMusicSegment::SetParam on the MIDI segment to establish a connection between the segment and the collection.
The following code example shows how the connection is made:
/* Assume that pSegment was created from a MIDI file and that pLoadedCollection is a valid IDirectMusicCollection pointer. */ HRESULT hr = pSegment->SetParam(GUID_ConnectToDLSCollection, 0xFFFFFFFF, 0, 0, (void*)pLoadedCollection);
As with any other collection, instruments to be used in playing a MIDI file must be downloaded before the segment is played, unless automatic downloading has been enabled. (For more information on automatic downloading, see Setting and Retrieving Global Parameters and Downloading and Unloading Bands.) If instruments are not being downloaded automatically, you must download them by calling IDirectMusicSegment::SetParam, as in the following code example:
/* pSegment is an IDirectMusicSegment pointer, and pPerformance is a valid pointer to IDirectMusicPerformance. */ pSegment->SetParam(GUID_Download, 0xFFFFFFFF, 0, 0, (void *) pPerformance);
For more information on downloading by using SetParam, see Setting and Retrieving Track Parameters.
To do so, load the collection, associate it with the segment, based on the MIDI file, and download the collection as you would with any other segment. For more information, see Loading a Collection.
Note When a custom collection is attached to a MIDI segment, the connection to the GM collection is not broken. For example, suppose you load a collection containing a single instrument that has a patch number of 12 and connect this to the segment. MIDI channels with any patch number other than 12 continue to be played by the appropriate instruments in the GM collection.