#import <MKPerformer.h>
Public Member Functions | |
(NSArray *) | - noteSenders |
Creates and returns a NSArray containing the receiver's MKNoteSenders. | |
(BOOL) | - isNoteSenderPresent: |
Returns YES if aNoteSender is a member of the receiver's MKNoteSender NSArray. | |
(id) | - disconnectNoteSenders |
Sends -disconnectAllReceivers to each of the object's MKNoteSenders. | |
(id) | - releaseNoteSenders |
Disconnects and releases the receiver's MKNoteSenders. | |
(id) | - removeNoteSenders |
Removes the receiver's MKNoteSenders (but doesn't free them). | |
(MKNoteSender *) | - noteSender |
Returns the first MKNoteSender in the receiver's NSArray. | |
(MKNoteSender *) | - removeNoteSender: |
Removes aNoteSender from the receiver. | |
(MKNoteSender *) | - addNoteSender: |
Adds aNoteSender to the recevier. | |
(BOOL) | - setConductor: |
Sets the receiver's MKConductor to aConductor. | |
(MKConductor *) | - conductor |
Returns the receiver's MKConductor. | |
(id) | - activateSelf |
You never invoke this method directly; it's invoked automatically from the activate method. | |
(id) | - perform |
This is a subclass responsibility expected to send a MKNote and then set the value of nextPerform. | |
(id) | - setTimeShift: |
Shifts the receiver's performance time by timeShift beats. | |
(id) | - setDuration: |
Sets the receiver's maximum performance duration to dur in beats. | |
(double) | - timeShift |
Returns the receiver's time shift value. | |
(double) | - duration |
Returns the receiver's duration value. | |
(int) | - status |
Returns the receiver's status. | |
(int) | - performCount |
Returns the number of perform messages the receiver has recieved in the current performance. | |
(id) | - activate |
If the receiver isn't inactive, immediately returns the receiver; if its duration is less than or equal to 0.0, immediately returns nil. | |
(void) | - deactivate |
If the receiver's status is inactive, this does nothing and immediately returns the receiver. | |
(id) | - init |
Initializes the receiver. | |
(id) | - pause |
Suspends the receiver's performance and returns the receiver. | |
(id) | - pauseFor: |
Like pause, but also enqueues a resume message to be sent the specified number of beats into the future. | |
(id) | - resume |
Resumes the receiver's performance and returns the receiver. | |
(id) | - copyWithZone: |
Creates and returns an initialised, inactive MKPerformer as a copy of the receiver. | |
(double) | - time |
Returns the time, in beats, that the receiver last received the perform message. | |
(id) | - setFirstTimeTag: |
Implements an informal protocol for firstTimeTag/lastTimeTag. | |
(id) | - setLastTimeTag: |
Implements an informal protocol for firstTimeTag/lastTimeTag. | |
(double) | - firstTimeTag |
Returns the first time tag in beats. Returns 0. | |
(double) | - lastTimeTag |
Returns the last time tag in beats. | |
(void) | - setDelegate: |
Assigns a delegate to receive messages described in MKPerformerDelegate.h. | |
(id) | - delegate |
Returns the receiver's delegate, if any. | |
(id) | - rescheduleBy: |
Shifts the MKPerformer's next scheduled invocation of perform by aTimeIncrement. | |
(id) | - rescheduleAtTime: |
Shifts the MKPerformer's next scheduled invocation of perform to time, which is in the receiver's MKConductor's time base. | |
(void) | - encodeWithCoder: |
You never send this message directly. | |
(id) | - initWithCoder: |
You never send this message directly. | |
(BOOL) | - inPerformance |
Returns YES if receiver's status is not MK_inactive. | |
Protected Attributes | |
MKConductor * | conductor |
MKPerformerStatus | status |
int | performCount |
double | timeShift |
double | duration |
double | time |
double | nextPerform |
NSMutableArray * | noteSenders |
id | delegate |
Each subclass of MKPerformer implements the perform method to define how it obtains and performs MKNotes.
During a performance, a MKPerformer receives a series of perform messages. In its implementation of perform, a MKPerformer subclass must set the nextPerform variable. nextPerform indicates the number of beats to wait before the next perform message is sent. The messages are sent by the MKPerformer's MKConductor. Every MKPerformer is managed by a MKConductor; unless you set its MKConductor explicitly, through the setConductor: method, a MKPerformer is managed by the defaultConductor.
A MKPerformer contains a NSArray of MKNoteSenders, objects that send MKNotes (to MKNoteReceivers) during a performance. MKPerformer subclasses should implement the init method to create and add some number of MKNoteSenders to a newly created instance. As part of its perform method, a MKPerformer typically creates or otherwise obtains a MKNote (for example, by reading it from a MKPart or a scorefile) and sends it by invoking MKNoteSender's sendNote: method.
To use a MKPerformer in a performance, you must first send it the activate message. activate invokes the activateSelf method and then schedules the first perform message request with the MKConductor. activateSelf can be overridden in a subclass to provide further initialization of the MKPerformer. The performance begins when the MKConductor class receives the startPerformance message. It's legal to activate a MKPerformer after the performance has started.
Sending the deactivate message removes the MKPerformer from the performance and invokes the deactivateSelf method. This method can be overridden to implement any necessary finalization, such as freeing contained objects.
During a performance, a MKPerformer can be stopped and restarted by sending it the pause and resume messages, respectively. perform messages destined for a paused MKPerformer are delayed until the object is resumed.
You can shift a MKPerformer's performance timing by setting its timeShift variable. timeShift, measured in beats, is added to the initial setting of nextPerform. If the value of timeShift is negative, the MKPerformer's MKNotes are sent earlier than otherwise expected; this is particularly useful for a MKPerformer that's performing MKNotes starting from the middle of a MKPart or MKScore. A positive timeShift delays the performance of a MKNote.
You can also set a MKPerformer's maximum duration. A MKPerformer is automatically deactivated if its performance extends beyond duration beats.
A MKPerformer has a status, represented as one of the following MKPerformerStatus values:
Status | Meaning |
MK_inactive | A deactivated or not-yet-activated MKPerformer. |
MK_active | An activated, unpaused MKPerformer. |
MK_paused | The MKPerformer is activated but currently paused. |
Some messages can only be sent to an inactive (MK_inactive) MKPerformer. A MKPerformer's status can be queried with the status message.
If you subclass MKPerformer, some care is required to make sure that it synchronizes correctly to MIDI time code. To make your own MKPerformer subclass synchronize, you need to support a simple informal protocol called MKPerformer Time Code Protocol, which is described in the next section.
This is an informal protocol, required if a MKPerformer subclass is to synchronize correctly with incoming MIDI time code.
There are three parts to this protocol.
Here is an example of a simple, but complete, Time Code-conforming MKPerfomer. This example is a simplified version of the MusicKit MKPartPerformer:
#import <MusicKit/MusicKit.h> #import "MyPartPerformer.h" @implementation MyPartPerformer: MKPerformer { id part; // MKPart over which we're sequencing. double firstTimeTag; // Required by Time Code Protocol. int currentIndex; // Index of nextNote }
- (NSArray *) noteSenders |
Creates and returns a NSArray containing the receiver's MKNoteSenders.
- (BOOL) isNoteSenderPresent: | (MKNoteSender *) | aNoteSender |
Returns YES if aNoteSender is a member of the receiver's MKNoteSender NSArray.
aNoteSender | is an id. |
- (id) disconnectNoteSenders |
Sends -disconnectAllReceivers to each of the object's MKNoteSenders.
- (id) releaseNoteSenders |
Disconnects and releases the receiver's MKNoteSenders.
- (id) removeNoteSenders |
Removes the receiver's MKNoteSenders (but doesn't free them).
- (MKNoteSender *) noteSender |
Returns the first MKNoteSender in the receiver's NSArray.
- (MKNoteSender *) removeNoteSender: | (MKNoteSender *) | aNoteSender |
Removes aNoteSender from the receiver.
aNoteSender | is an MKNoteSender instance. |
- (MKNoteSender *) addNoteSender: | (MKNoteSender *) | aNoteSender |
Adds aNoteSender to the recevier.
aNoteSender | is an MKNoteSender instance. |
- (BOOL) setConductor: | (MKConductor *) | aConductor |
Sets the receiver's MKConductor to aConductor.
The receiver must be inactive.
aConductor | is an MKConductor instance. |
- (MKConductor *) conductor |
- (id) activateSelf |
You never invoke this method directly; it's invoked automatically from the activate method.
A subclass can implement this method to perform pre-performance activities. In particular, if the subclass needs to alter the initial nextPerform value, it should be done here. If activateSelf returns nil, the receiver is deactivated. The default does nothing and returns the receiver.
Reimplemented in MKFilePerformer, MKMTCPerformer, and MKPartPerformer.
- (id) perform |
This is a subclass responsibility expected to send a MKNote and then set the value of nextPerform.
Reimplemented in MKFilePerformer, MKMTCPerformer, and MKPartPerformer.
- (id) setTimeShift: | (double) | timeShift |
Shifts the receiver's performance time by timeShift beats.
timeShift | is a double. |
- (id) setDuration: | (double) | dur |
Sets the receiver's maximum performance duration to dur in beats.
dur | is a double. |
- (double) timeShift |
Returns the receiver's time shift value.
- (double) duration |
Returns the receiver's duration value.
- (int) status |
Returns the receiver's status.
- (int) performCount |
Returns the number of perform messages the receiver has recieved in the current performance.
- (id) activate |
If the receiver isn't inactive, immediately returns the receiver; if its duration is less than or equal to 0.0, immediately returns nil.
- (void) deactivate |
If the receiver's status is inactive, this does nothing and immediately returns the receiver.
Otherwise removes the receiver from the performance, invokes deactivateSelf, and sets the receiver's status to MK_inactive. Also sends [delegate hasDeactivated:self];
Returns the receiver.
Reimplemented in MKFilePerformer, MKMTCPerformer, and MKPartPerformer.
- (id) init |
Initializes the receiver.
Reimplemented in MKFilePerformer, MKMTCPerformer, MKPartPerformer, and MKScorefilePerformer.
- (id) pause |
Suspends the receiver's performance and returns the receiver.
Reimplemented in MKMTCPerformer.
- (id) pauseFor: | (double) | beats |
Like pause, but also enqueues a resume message to be sent the specified number of beats into the future.
beats | is a double. |
- (id) resume |
Resumes the receiver's performance and returns the receiver.
Reimplemented in MKMTCPerformer.
- (id) copyWithZone: | (NSZone *) | zone |
Creates and returns an initialised, inactive MKPerformer as a copy of the receiver.
Reimplemented in MKFilePerformer, MKPartPerformer, and MKScorefilePerformer.
- (double) time |
Returns the time, in beats, that the receiver last received the perform message.
- (id) setFirstTimeTag: | (double) | v |
Implements an informal protocol for firstTimeTag/lastTimeTag.
Does nothing in this abstract class.
Reimplemented in MKFilePerformer, MKMTCPerformer, and MKPartPerformer.
- (id) setLastTimeTag: | (double) | v |
Implements an informal protocol for firstTimeTag/lastTimeTag.
Does nothing in this abstract class.
Reimplemented in MKFilePerformer, MKMTCPerformer, and MKPartPerformer.
- (double) firstTimeTag |
Returns the first time tag in beats. Returns 0.
Reimplemented in MKFilePerformer, MKMTCPerformer, and MKPartPerformer.
- (double) lastTimeTag |
Returns the last time tag in beats.
Returns MK_ENDOFTIME.
Reimplemented in MKFilePerformer, MKMTCPerformer, and MKPartPerformer.
- (void) setDelegate: | (id) | object |
Assigns a delegate to receive messages described in MKPerformerDelegate.h.
The object is not retained.
object | The receiving delegate object. |
- (id) delegate |
Returns the receiver's delegate, if any.
- (id) rescheduleBy: | (double) | aTimeIncrement |
Shifts the MKPerformer's next scheduled invocation of perform by aTimeIncrement.
aTimeIncrement | is a double. |
- (id) rescheduleAtTime: | (double) | aTime |
Shifts the MKPerformer's next scheduled invocation of perform to time, which is in the receiver's MKConductor's time base.
aTime | is a double. |
- (void) encodeWithCoder: | (NSCoder *) | aCoder |
You never send this message directly.
Archives noteSender array, timeShift, and duration. Also optionally archives conductor and delegate.
Reimplemented in MKFilePerformer, MKPartPerformer, and MKScorefilePerformer.
- (id) initWithCoder: | (NSCoder *) | aDecoder |
You never send this message directly.
Note that the status of an unarchived MKPerformer is always MK_inactive.
Reimplemented in MKFilePerformer, MKPartPerformer, and MKScorefilePerformer.
- (BOOL) inPerformance |
Returns YES if receiver's status is not MK_inactive.
- (MKConductor*) conductor [protected] |
The object's MKConductor.
- (MKPerformerStatus) status [protected] |
The object's status.
- (int) performCount [protected] |
Number of times the object has received perform messages.
- (double) timeShift [protected] |
Performance offset time in beats.
- (double) duration [protected] |
Maximum performance duration in beats.
- (double) time [protected] |
The object's notion of the current time. The time in beats of the current invocation of perform, if any, otherwise, the time in beats of the last invocation of perform.
- (double) nextPerform [protected] |
The next time in beats until the object will send a MKNote by sending a perform message.
- (NSMutableArray*) noteSenders [protected] |
The object's collection of MKNoteSenders.
- (id) delegate [protected] |
The object's delegate, if any.