|By Tom Hays
November 6, 1998
Vol. 2: Issue 44
Published in Game Developer Magazine, September 1998
Basic Playback with the Performance API
DirectMusic's playback objects include Port, Performance, Track, and Segment. The Performance object is the music playback überobject. It adds and removes Ports, downloads Instruments, attaches graphs of Tools, deals with event notification, and plays Segments. Segment objects contain data in one or more Tracks, which is where the actual music data resides.
A DirectMusic Track is not the same thing as a track within a type 1 MIDI file. In fact, a DirectMusic Segment can contain all of the data from an entire imported MIDI file.
About the simplest thing an application can do with DirectMusic is to create a Performance, create a Loader, and tell it to load a single MIDI file. The Loader returns the MIDI file in the form of a Segment. To play the Segment, call the Performance's PlaySegment method.
While it's possible simply to play a MIDI file without invoking any more of the Performance API than I just described, an application can easily bring to bear more of DirectMusic's control mechanisms. For example, you could create a Performance containing Segments, each comprising a single, complete MIDI file. Using the Performance API, an application can then queue, layer, and modify these Segments. Each Segment can get a delay value when queued for playback; this value can then adjust itself to match tempo changes. The PlaySegment method also accepts a parameter telling it what type of rhythmic juncture - beat, bar, note, and so on - to jump in on. By playing multiple Segments simultaneously, an application can add and subtract musical elements.
The next logical item on many game music composers' current wish lists is a way to manage segment playback based on game state inputs using an authoring-level scripting scheme or something similar. Using a set of variables shared between the music engine and the host application, this type of system could emulate what a music editor does for a film: watch what's going on and select, mix, and match existing musical elements accordingly.
High-level scripting isn't part of DirectMusic. Some developers think this should have been the fundamental thrust of any music system from Microsoft, and that DirectMusic misses the point. Its authoring-level logic doesn't go beyond the single-segment level; to do more requires application code.
On the other hand, I can't see anything in DirectMusic's architecture that would preclude a higher-level system for real-time rendered music editing. Its low-level code should make this sort of thing easier and more reliable than it was under the old MidiOut system.