#import <MKPart.h>
Public Member Functions | |
(id) | - sort |
Causes the MKPart to sort itself if it's currently unsorted. | |
(BOOL) | - isSorted |
Returns YES if the MKPart's MKNotes are currently guaranteed to be in time tag order, otherwise returns NO. | |
(id) | - combineNotes |
Creates and adds a single noteDur for each noteOn/noteOff pair in the MKPart. | |
(id) | - splitNotes |
Splits the MKPart's noteDurs into noteOn/noteOff pairs. | |
(id) | - addToScore: |
Moves the MKPart from its present MKScore, if any, to aScore. | |
(id) | - removeFromScore |
Removes the MKPart from its present MKScore. | |
(id) | - init |
Initializes the object. This should be invoked when alloc'ing a new MKPart. | |
(void) | - dealloc |
Deallocates ivars. | |
(id) | - releaseNotes |
Removes and frees the MKPart's MKNotes and its info MKNote. | |
(id) | - releaseSelfOnly |
THIS IS DEPRECATED. DO NOT USE. EXPECT IT TO BE REMOVED SOON. | |
(id) | - firstTimeTag:lastTimeTag: |
Creates and returns a NSMutableArray of the MKPart's MKNotes that have time tag values between firstTimeTag and lastTimeTag, inclusive. | |
(MKPart *) | - addNote: |
Moves aNote from its present MKPart to the receiving MKPart. | |
(MKNote *) | - addNoteCopy: |
Adds a copy of aNote to the MKPart. | |
(MKNote *) | - removeNote: |
Removes aNote from the MKPart. | |
(id) | - removeNotes: |
Removes all the MKNotes the MKPart has in common with aNoteList. | |
(void) | - removeAllNotes |
Deletes all MKNotes within this part. | |
(id) | - addNoteCopies:timeShift: |
Copies each MKNote in aNoteList (which should be a NSMutableArray object) adds shift to each new MKNote's time tag, then adds the new MKNotes to the MKPart by repeatedly invoking addNote:. | |
(id) | - addNotes:timeShift: |
Moves each MKNote in aNoteList from its present MKPart to the receiving MKPart, adding shift to each MKNote's time tag in the process. | |
(id) | - shiftTime: |
Shifts the MKPart's contents by adding shift to each of the MKNotes' time tags. | |
(id) | - scaleTime: |
Scales the MKPart's contents by multiplying scale to each of the MKNotes' time tags and durations. | |
(unsigned) | - noteCount |
Returns the number of MKNotes in the MKPart (not counting the info MKNote). | |
(BOOL) | - containsNote: |
Returns YES if the MKPart contains aNote, otherwise returns NO. | |
(BOOL) | - hasSoundingNotes |
Returns YES if the MKPart contains any MK_noteDur or MK_noteOn notes. | |
(BOOL) | - isEmpty |
Returns YES if the MKPart contains no MKNotes (not including the info MKNote), otherwise returns NO. | |
(MKNote *) | - atTime: |
Returns the (first) MKNote in the MKPart that has a time tag of timeTag, or nil if none. | |
(MKNote *) | - atOrAfterTime: |
Returns the first MKNote with a time tag equal to or greater than timeTag, or nil if none. | |
(MKNote *) | - atOrBeforeTime: |
Returns the first MKNote with a time tag equal to or less than timeTag, or nil if none. | |
(MKNote *) | - nth: |
Returns the nth MKNote (0-based), or nil if n is out of bounds (negative or greater than the MKPart's MKNote count). | |
(MKNote *) | - atOrAfterTime:nth: |
Returns the nth MKNote (zero-based) in the MKPart that has a time tag equal to or greater than timeTag, or nil if none. | |
(MKNote *) | - atTime:nth: |
Returns the nth MKNote (zero-based) in the MKPart that has a time tag of timeTag, or nil if none. | |
(MKNote *) | - next: |
Returns the MKNote immediately following aNote, or nil if aNote isn't a member of the MKPart, or if it's the last MKNote in the MKPart. | |
(double) | - earliestNoteTime |
Returns the time of the earliest note in the part. | |
(id) | - copyWithZone: |
This is the same as copy, but the new MKNote is allocated in aZone. | |
(id) | - copy |
Creates and returns a new MKPart as a copy of the receiving MKPart. | |
(NSArray *) | - notes |
Creates and returns a NSArray of the MKPart's MKNotes in time order. | |
(NSMutableArray *) | - notesNoCopy |
Returns the NSMutableArray object that contains the MKPart's MKNotes. | |
(MKScore *) | - score |
Returns the MKScore the MKPart is a member of, or nil if none. | |
(MKNote *) | - infoNote |
Returns the MKPart's info MKNote. | |
(void) | - setInfoNote: |
Sets the MKPart's info MKNote to a copy of aNote. | |
(NSString *) | - partName |
Return the name of the receiver. | |
(void) | - setPartName: |
Assigns the name of the receiver. | |
Static Public Member Functions | |
(MKPart *) | + part |
Returns a newly allocated, initialized and autoreleased MKPart. | |
(id) | + partWithName: |
Returns a newly allocated, initialized and autoreleased MKPart with the given name. | |
Protected Attributes | |
MKScore * | score |
NSMutableArray * | notes |
MKNote * | info |
unsigned int | noteCount |
BOOL | isSorted |
A MKPart is a timeTag-ordered collection of MKNotes that can be edited performed, and realized. MKParts are typically grouped together in a MKScore.
A MKNote can belong to only one MKPart at a time, and a MKPart to only one MKScore. When you add a MKNote to a MKPart, it's automatically removed from its old MKPart. Similarly, adding a MKPart to a MKScore removes it from its previous MKScore.
You can add MKNotes to a MKPart either by invoking one of MKPart's addNote: methods, or by “recording” them with a MKPartRecorder, a type of MKInstrument that realizes MKNotes by adding copies of them to a specified MKPart. Any number of MKPartRecorders can simultaneously record into the same MKPart. A MKPart is added to a MKScore through MKPart's addToScore: method (or the equivalent MKScore method addPart:).
Within a MKPart, MKNotes are ordered by their time tag values, lowest to highest. To move a MKNote within a MKPart, you simply change the MKNote's time tag (through MKNote's setTimeTag: method). For efficiency, a MKPart sorts itself only when its MKNotes are retrieved or when a MKNote is moved within the MKPart (or removed altogether). In other words, adding a MKNote to a MKPart won't cause the MKPart to sort itself; but keep in mind that since adding a MKNote to a MKPart automatically removes it from its current MKPart, the act will cause the moved-from MKPart to sort itself. You can force a MKPart to sort itself by sending it a sortmessage.
A MKPart can be a source of MKNotes in a performance through association with a MKPartPerformer. During a performance, the MKPartPerformer reads the MKNotes in the MKPart, performing them in order. While you shouldn't free a MKPart or any of its MKNotes while an associated MKPartPerformer is active, you can add MKNotes to and remove MKNotes from the MKPart at any time without affecting the MKPartPerformer's performance.
A MKPart can be performed using a MKPartPerformer and can 'record' notes by using a MKPartRecorder. You must not free a MKPart or any of the MKNotes in a MKPart while there are any MKPartPerformers using the MKPart. It is ok to record to a part and perform that part at the same time because the MKPartPerformer takes a snap-shot of the MKPart when the MKPartPerformer is activated.
A MKPartPerformer creates its own NSMutableArray of the MKPart's MKNotes when it receives the setPart: message (but keep in mind that it doesn't make copies of the MKNotes themselves); changes to the MKPart made during a performance won't affect the MKPartPerformer. This allows a MKPart to be performed by a MKPartPerformer and used for recording by a MKPartRecorder at the same time.
To each MKPart you can give an info MKNote, a sort of header for the MKPart that can contain any amount and type of information. Info MKNotes are typically used to describe a performance setup; for example, an info MKNote might contain, as a parameter, the name of the MKSynthPatch subclass on which the MKNotes in the MKPart are meant to be synthesized. When the MKPart's MKScore is written to a scorefile, the info MKNote is written in the file's header; this is in distinction to the MKPart's other MKNotes, which make up the body of the scorefile. (To store a MKPart in a scorefile you must first add it to a MKScore and then write the MKScore.)
Keep in mind that a MKPart's info MKNote must be interpreted by your application if it is to have any effect. A few parameters defined by the MusicKit are designed specifically to be used in a MKPart's info MKNote. These are listed in the description of the setInfo: method, below. The info MKNote is stored separately from the MKNotes in the body of the MKPart; most of the MKNote-accessing methods, such as empty, nth:, and next:, don't apply to the info MKNote. The exceptions - the methods that do affect the info MKNote - are so noted in their descriptions below.
MKParts are commonly given string name identifiers, through the MKNameObject() C function. The most important use of a MKPart's name is to identify the MKPart in a scorefile.
MKParts are automatically created by the MusicKit in a number of circumstances, such as when reading a MKScorefile. The function MKSetPartClass() allows you to specify that your own subclass of MKPart be used when MKParts are automatically created. You retrieve the MKPart class with MKGetPartClass().
Editing a MKPart refers generally to adding and removing MKNotes, not to changing the contents of the MKNotes themselves (although some methods do both; see splitNotes and combineNotes). MKNotes are ordered within the MKPart by their timeTag values. To move a MKNote within a MKPart, you simply change its timeTag by sending it the appropriate message (see the MKNote class). This effectively removes the MKNote from its MKPart, changes the timeTag, and then adds it back to its MKPart.
The MKNotes in a MKPart are stored in a NSArray object. The NSArray is only sorted when necessary. In particular, the NSArray is sorted, if necessary, when an access method is invoked. The access methods are:
firstTimeTag: (double) firstTimeTag lastTimeTag: (double) lastTimeTag;
atTime: (double) timeTag;
atOrAfterTime: (double) timeTag;
nth: (unsigned) n;
atOrAfterTime: (double) timeTag nth: (unsigned) n;
atTime: (double) timeTag nth: (unsigned) n;
next: (MKNote *) aNote;
notes;
Other methods that cause a sort, if necessary, are:
combineNotes;
removeNotes: (NSArray *) aList;
removeNote: (MKNote *) aNote;
Methods that may alter the NSArray such that its MKNotes are no longer sorted are the following:
addNoteCopies: (NSArray *) aList timeShift: (double) shift;
addNotes: (NSArray *) aList timeShift: (double) shift;
addNote: (MKNote *) aNote;
addNoteCopy: (MKNote *) aNote;
splitNotes;
This scheme works well for most cases. However, there are situations where it can be problematic. For example:
for (i = 0; i < 100; i++) {
[aPart addNote: anArray[i]];
[aPart removeNote: anotherArray[i]];
}
In this case, the MKPart will be sorted each time removeNote: is called, causing N-squared behavior. You can get around this by first adding all the notes using addNotes: and then removing all the notes using removeNotes:.
In some cases, you may find it most convenient to remove the MKNotes from the MKPart, modify them in your own data structure, and then reinsert them into the MKPart.
You can explicitly trigger a sort (if needed) by sending the -sort message. This is useful if you ever subclass MKPart.
To get a sorted copy of the NSArray of notes use the -notes method. To get the NSArray of notes itself, use the -notesNoCopy method. -notesNoCopy does not guarantee the MKNotes are sorted. If you want to examine the MKNotes in-place sorted, first send -sort, then -notesNoCopy.
You can find out if the NSArray is currently sorted by the -isSorted method.
+ (MKPart *) part |
+ (id) partWithName: | (NSString *) | partName |
- (id) sort |
- (BOOL) isSorted |
Returns YES if the MKPart's MKNotes are currently guaranteed to be in time tag order, otherwise returns NO.
- (id) combineNotes |
Creates and adds a single noteDur for each noteOn/noteOff pair in the MKPart.
- (id) splitNotes |
Splits the MKPart's noteDurs into noteOn/noteOff pairs.
- (id) addToScore: | (MKScore *) | newScore |
Moves the MKPart from its present MKScore, if any, to aScore.
newScore | is an MKScore instance. |
- (id) removeFromScore |
Removes the MKPart from its present MKScore.
- (id) init |
- (id) releaseNotes |
Removes and frees the MKPart's MKNotes and its info MKNote.
- (id) releaseSelfOnly |
THIS IS DEPRECATED. DO NOT USE. EXPECT IT TO BE REMOVED SOON.
- (id) firstTimeTag: | (double) | firstTimeTag | ||
lastTimeTag: | (double) | lastTimeTag | ||
Creates and returns a NSMutableArray of the MKPart's MKNotes that have time tag values between firstTimeTag and lastTimeTag, inclusive.
firstTimeTag | is a double. | |
lastTimeTag | is a double. |
Moves aNote from its present MKPart to the receiving MKPart.
aNote | is an MKNote. |
Adds a copy of aNote to the MKPart.
aNote | is an MKNote. |
Removes aNote from the MKPart.
aNote | is an MKNote. |
- (id) removeNotes: | (NSArray *) | aNoteList |
Removes all the MKNotes the MKPart has in common with aNoteList.
aNoteList | is an NSArray instance. |
- (id) addNoteCopies: | (NSArray *) | aNoteList | ||
timeShift: | (double) | shift | ||
Copies each MKNote in aNoteList (which should be a NSMutableArray object) adds shift to each new MKNote's time tag, then adds the new MKNotes to the MKPart by repeatedly invoking addNote:.
aNoteList | is an NSArray instance. | |
shift | is a double. |
- (id) addNotes: | (NSArray *) | aNoteList | ||
timeShift: | (double) | shift | ||
Moves each MKNote in aNoteList from its present MKPart to the receiving MKPart, adding shift to each MKNote's time tag in the process.
aNoteList | is an NSArray instance. | |
shift | is a double. |
- (id) shiftTime: | (double) | shift |
- (id) scaleTime: | (double) | scale |
Scales the MKPart's contents by multiplying scale to each of the MKNotes' time tags and durations.
scale | is a double. |
- (unsigned) noteCount |
- (BOOL) containsNote: | (MKNote *) | aNote |
- (BOOL) hasSoundingNotes |
- (BOOL) isEmpty |
- (MKNote *) atTime: | (double) | timeTag |
Returns the (first) MKNote in the MKPart that has a time tag of timeTag, or nil if none.
timeTag | is a double. |
- (MKNote *) atOrAfterTime: | (double) | timeTag |
Returns the first MKNote with a time tag equal to or greater than timeTag, or nil if none.
timeTag | is a double. |
- (MKNote *) atOrBeforeTime: | (double) | timeTag |
- (MKNote *) nth: | (unsigned) | n |
- (MKNote *) atOrAfterTime: | (double) | timeTag | ||
nth: | (unsigned) | n | ||
Returns the nth MKNote (zero-based) in the MKPart that has a time tag equal to or greater than timeTag, or nil if none.
timeTag | is a double. | |
n | is an unsigned. |
- (MKNote *) atTime: | (double) | timeTag | ||
nth: | (unsigned) | n | ||
Returns the nth MKNote (zero-based) in the MKPart that has a time tag of timeTag, or nil if none.
timeTag | is a double. | |
n | is an unsigned. |
Returns the MKNote immediately following aNote, or nil if aNote isn't a member of the MKPart, or if it's the last MKNote in the MKPart.
aNote | is an MKNote instance. |
- (double) earliestNoteTime |
Returns the time of the earliest note in the part.
Returns 0.0 if there are no notes in the part.
- (id) copyWithZone: | (NSZone *) | zone |
- (id) copy |
- (NSArray *) notes |
Creates and returns a NSArray of the MKPart's MKNotes in time order.
- (NSMutableArray *) notesNoCopy |
Returns the MKScore the MKPart is a member of, or nil if none.
- (MKNote *) infoNote |
- (void) setInfoNote: | (MKNote *) | aNote |
Sets the MKPart's info MKNote to a copy of aNote.
aNote | is an MKNote. The info MKNote can be given information (as parameters) that helps define how the MKPart should be interpreted; in particular, special MusicKit parameters (more accurately, parameter tags) are by convention used in a MKPart info MKNote. Listed below, these parameters pertain to the manner in which the MKNotes in the MKPart are synthesized, although as with any MKNote, the info MKNote's parameters must be read and applied by some other object (or your application) in order for them to have an effect. Keep in mind that the info MKNote is be no means restricted to containing only these parameters: |
Parameter Tag | Expected Value | Typical Use |
MK_synthPatch | MKSynthPatch subclass | Argument to MKSynthInstrument's setSynthPatchClass: method. |
MK_synthPatchCount | integer | Argument to MKSynthInstrument's setSynthPatchCount: method. |
MK_midiChan | integer | Argument to MKMidi's channelNoteReceiver: method. |
MK_track | integer | Automatically set when a midifile is read into a MKScore. |
The info MKNote is stored separately from the MKPart's main body of MKNotes; methods such as empty don't affect it.
- (NSString *) partName |
Return the name of the receiver.
- (void) setPartName: | (NSString *) | newPartName |
Assigns the name of the receiver.
newPartName | An NSString for the new name of the part. The part name is used when reading and writing parts to a Scorefile. |
- (NSMutableArray*) notes [protected] |
NSArray of MKNotes.
- (BOOL) isSorted [protected] |
YES if the receiver is sorted.