First Steps in DirectMusic Programming
This topic gives an overview of the basic steps required for setting up a DirectMusic performance and playing a file. For details, see Using DirectMusic. For sample code, see Tutorial 1: Playing Audio Files.
To produce a sound, an application needs to do the following:
- Initialize COM. There are no helper functions for creating DirectMusic objects. To initialize COM, you must call CoInitializeEx.
- Create and initialize the performance. Most applications have a single performance object. Create the performance by calling CoCreateInstance, obtaining the IDirectMusicPerformance8 interface. Then call IDirectMusicPerformance8::InitAudio. This method can set up a default audiopath.
- Create the loader. Using CoCreateInstance, create a loader object and obtain an IDirectMusicLoader8 interface. You need to do this only once, and normally you should keep the same loader object for the life of the application.
- Load a segment. Call IDirectMusicLoader8::SetSearchDirectory so the loader can find the data files. Then call IDirectMusicLoader8::GetObject to load a segment from a file or resource and obtain its IDirectMusicSegment8 interface.
- Download the band. Download instrument data to the synthesizer so that notes can be synthesized. WAV files must also be downloaded. The simplest way to download all instruments and waves is by calling IDirectMusicSegment8::Download.
- Play the segment. Pass the segment pointer to IDirectMusicPerformance8::PlaySegmentEx.