DirectX SDK

DirectMusic Loader

[C++]

Many DirectMusic objects have to be loaded from a file or resource before they can be incorporated into a music performance. The IDirectMusicLoader interface is used to manage the loading of such objects, as well as to find and enumerate objects and cache them so that they are not loaded more than once.

An application should have only one instance of the loader in existence at a time. You should create a single global loader object and not free it until there is no more loading to be done. This strategy ensures that objects are found and cached efficiently.

The DirectMusic implementation of IStream streams the data from the source. The parsing of the data is handled by the various objects themselves through their implementations of IPersistStream. When you are dealing only with standard DirectMusic data, you do not need to use these interfaces directly.

Objects that are referred to by other objects are loaded transparently. For example, suppose a style being loaded from a DirectMusic Producer file contains a reference to a band whose data is in another file. When the style's IPersistStream finds the reference, it obtains the IDirectMusicGetLoader interface from the IStream that passed it the data stream. Using this interface, it obtains a pointer to the DirectMusicLoader. Then it calls IDirectMusicLoader::GetObject to load the band.

[Visual Basic]

Many DirectMusic objects have to be loaded from a file or resource before they can be incorporated into a music performance. The DirectMusicLoader class is used to manage the loading of such objects.

An application should have only one DirectMusicLoader object in existence at a time. You should create a single global loader object and not free it until there is no more loading to be done. This strategy ensures that objects are found and loaded efficiently.

However, if your application has occasion to load a segment more than once, you should be aware that because of the caching system used internally by DirectMusic, you might get back the same segment object, with the same settings such as start and loop points and any connection to a DLS collection. To ensure that this does not happen, you should release the DirectMusicLoader object by setting it to Nothing, and then create a new one, before reloading the segment.

Objects that are referred to by other objects are loaded transparently. For example, suppose a style being loaded from a DirectMusic Producer file contains a reference to a band whose data is in another file. DirectMusic loads the band automatically, and the application retrieves it by using the DirectMusicStyle.GetBand method.

More information on using the loader is contained in the following topics: