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.
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
MKInstrument
s are ubiquitous.
MKPerformer
s provide a convenient means for
acquiring or generating MKNote
s but they're not
essential to a performance application; in fact, some applications
can't use MKPerformer
s but, instead, must
manufacture MKNote
s themselves and send them
directly to MKInstrument
s. 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―MKInstrument
s. 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
MKPerformer
s. 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
MKNote
s 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: