Chapter 6. Music Performance

Table of Contents
Design Philosophy
Performance Outline
The MKInstrument Class
Receiving MKNotes
Realizing MKNotes
Creating an MKInstrument Subclass
The MKConductor Class
MKConductors Created by the MusicKit
The Message Request Queue
The MKPerformer Class
Using a MKPerformer
Creating a MKPerformer Subclass
Fine-Tuning a Performance Application
Responsiveness
Separate-Threaded Performance
Performance Priority
Performing with the DSP
The Relationships between MIDI, the DSP, the MKConductor and the Clock on the Wall

This chapter describes the classes and functions that you use to create a musical performance with the MusicKit. The material presented here falls roughly into three sections: realizing music data, MusicKit scheduling, and guidelines for building an efficient application. To fully appreciate this chapter, you should be familiar with the material in the preceding two chapters, Chapter 4 and Chapter 5.

Design Philosophy

The primary task in a musical performance is to take a representation of music and render it in an appropriate fashion. Traditionally, this task is met by a performer wielding an instrument. Similarly, the MusicKit has its MKPerformer and MKInstrument objects: A MKPerformer obtains a MKNote object, either by reading it from a database such as a MKPart or scorefile or by improvising the MKNote itself. The MKPerformer then relays the MKNote to an MKInstrument that provides the machinery for rendering, or realizing, the MKNote.

Of MKInstrument and MKPerformer, the former is the more crucial to a MusicKit performance. Realization is the whole point of a performance, thus MKInstruments are ubiquitous. MKPerformers provide a convenient means for acquiring or generating MKNotes but they're not essential to a performance application; in fact, some applications can't use MKPerformers but, instead, must manufacture MKNotes themselves and send them directly to MKInstruments. In any case, the means by which a MKNote is acquired is separated from its means of realization and the mechanism for connecting an agent of acquisition to that of realization is extremely general. Specifically, any MKPerformer (or your application) can be connected to any―and any number of―MKInstruments. These connections can be created and severed dynamically, allowing you to create a kaleidoscopic network of MKNote sources and destinations.

With MKPerformer and MKInstrument, the MKConductor class completes the triumvirate of preeminent performance classes. A MKConductor object acts as a time keeper as it determines the tempo of the performance and starts and stops groups of MKPerformers. Essentially, a MKConductor is a timed-message sending object that dispatches Objective-C messages at distinct times (in this regard, it's similar to the timed entry mechanism of NSTimer, but with a more sophisticated interface). For example, it's through a MKConductor that a MKPerformer schedules the messages that relay MKNotes to an MKInstrument.

Because of the demands of music performance, the MusicKit provides hooks into the operating system that allow you to create applications that can run with heightened priority. Well-debugged and fine-tuned applications will find great benefit in these enhancements.

Figure 6-1 is a subset of the MusicKit's performance classes, showing their hierarchical relationship:

Figure 6-1. Performance Classes