Microsoft DirectX 8.1 (C++) |
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 use instruments from any
First load the collection and retrieve a pointer to the IDirectMusicCollection8 interface.
The following example function loads a collection by file name:
HRESULT LoadCollectionByName(
IDirectMusicLoader8 *pILoader,
char *pszFileName,
IDirectMusicCollection8 **ppICollection)
{
HRESULT hr;
DMUS_OBJECTDESC Desc; // Descriptor.
// Start by initializing Desc with the file name
// and GUIDfor the collection object.
// The file name starts as a char string, so convert
// to Unicode.
mbstowcs(Desc.wszFileName,pszFileName,DMUS_MAX_FILENAME);
Desc.dwSize = sizeof(DMUS_OBJECTDESC);
Desc.guidClass = CLSID_DirectMusicCollection;
Desc.dwValidData = DMUS_OBJ_CLASS
| DMUS_OBJ_FILENAME
| DMUS_OBJ_FULLPATH;
hr = pILoader->GetObject(&Desc,
IID_IDirectMusicCollection8,
(void **) ppICollection);
return hr;
}
Next you must connect the DLS data to the segment by calling IDirectMusicSegment8::SetParam.The following code example shows how to make a connection between a segment and a collection returned by the LoadCollectionByName function.
// Assume that pSegment was created from a MIDI file and that
// pLoadedCollection is a valid IDirectMusicCollection8 pointer.
HRESULT hr = pSegment->SetParam(GUID_ConnectToDLSCollection,
0xFFFFFFFF, DMUS_SEG_ALLTRACKS, 0,
(void*)pLoadedCollection);
Finally, download the instruments in the collection to the performance or audiopath by calling IDirectMusicSegment8::Download.
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.
For more information on collections, see Using Instrument Collections.