Microsoft DirectX 9.0 |
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 objDesc;
mbstowcs(objDesc.wszFileName,pszFileName,DMUS_MAX_FILENAME);
objDesc.dwSize = sizeof(DMUS_OBJECTDESC);
objDesc.guidClass = CLSID_DirectMusicCollection;
objDesc.dwValidData = DMUS_OBJ_CLASS
| DMUS_OBJ_FILENAME
| DMUS_OBJ_FULLPATH;
hr = pILoader->GetObject(&objDesc,
IID_IDirectMusicCollection8,
(void **) ppICollection);
return hr;
}
Next, you must associate the DLS data with the segment by calling IDirectMusicSegment8::SetParam, as shown in the following example:
HRESULT ConnectCollection(IDirectMusicSegment8* pSegment,
IDirectMusicCollection8* pCollection)
{
HRESULT hr = pSegment->SetParam(GUID_ConnectToDLSCollection,
0xFFFFFFFF, DMUS_SEG_ALLTRACKS, 0, (void*)pCollection);
return hr;
}
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.
See Also