MKTimbre Class Reference

The MusicKit supports a Timbre Data Base. Each element in the data base is a MKTimbre. More...

#import <MKTimbre.h>

List of all members.

Public Member Functions

(id) - init
 Initialize timbre to be a new anonymous timbre.
(id) - copyWithZone:
(id) - addWaveTable:forFreq:
 Add the specified MKWaveTable/frequency pair.
(id) - removeWaveTable:
 Removes the given MKWaveTable and its corresponding frequency.
(MKWaveTable *) - waveTableForFreq:
 Returns the MKWaveTable object corresponding to the specified freq, if any.
(double) - freqForWaveTable:
 Returns the freq corresponding to the specified freq, if any.
(MKWaveTable *) - waveTableAt:
 Returns the MKWaveTable object corresponding to the specified index, if any.
(double) - freqAt:
 Returns the freq corresponding to the specified index, if any.
(id) - setTimbreName:
 if successful or nil if newName is already in use.
(void) - dealloc
 Frees receiver and removes it from Data Base. Frees WaveTables.
(void) - removeAllObjects
 Empties the MKWaveTable and freqs NSArrays.
(NSString *) - timbreName
 Returns timbreName.
(NSMutableArray *) - waveTables
 Returns waveTables object.
(NSMutableArray *) - freqs
 Returns freqs.
(MKWaveTable *) - MKWaveTableForTimbreKey
 Extracts the timbre name from timbreKey (by removing leading and trailing numbers) and looks up that name in the Data Base.

Static Public Member Functions

(id) + newTimbre:
 Retrieve timbre if it exists, otherwise create it and install it in Data Base.
(NSDictionary *) + timbres
 Returns the timbre data base, a NSDictionary mapping names to MKTimbres.

Protected Attributes

NSString * timbreName
NSMutableArray * freqs
NSMutableArray * waveTables


Detailed Description

The MusicKit supports a Timbre Data Base. Each element in the data base is a MKTimbre.

Each MKTimbre maps a timbre name to a NSArray of MKWaveTable objects and a parallel list of frequencies for those MKWaveTables. The Data Base is initialized with an extensive set of timbres. These timbres may be removed or modified, additional timbres may be added, etc.

The waveTables List is a List object of WaveTables sorted according to frequency. The table that corresponds to the lowest frequency is first in the List. freqs is a NSMutableArray object containing the frequencies corresponding to each MKWaveTable. The timbreName may be any string, but should not have a number in it and should not be longer than MK_MAXTIMBRENAMELEN, which is defined in MKTimbre.h.

You normally create or retrieve an MKTimbre with +newTimbre:, passing the name of the timbre you want. If that timbre exists, it is retrieved, otherwise it is created and installed in the Data Base. Alternatively, you can create a new anonymous timbre with +alloc and init. In this case, the timbre is not put in the Data Base until its name is set with setTimbreName:. setTimbreName: can also be used to change the name of a timbre that is already in the Data Base. timbreName may be used to retrieve the name of an MKTimbre. An anonymous timbre has a name field of NULL.

The MusicKit MKSynthPatches use the Data Base by passing it a "timbre key". A timbre key is a timbre name with an optional integer appended to it and an optional 0 or 1 prepended to it. The trailing number in a timbre key specifies a particular table (1-based). A leading 0 or 1 specifies use of the freq0 or freq1 parameter, respectively, to determine the appropriate MKWaveTable. For convenience in supporting this functionality in your own MKSynthPatch subclasses, we provide the function MKWaveTableForTimbreKey (MKTimbre).

The Data Base is stored in a HashTable object that maps names to MKTimbre objects. This HashTable can be retrieved by the +timbres method. See <objc/HashTable.h> for how to enumerate the objects in a HashTable.

An individual timbre can be written to an archive file. Alternatively, the entire database can be saved to an archive file using the +timbres method to retrieve the database and then archiving that object.

See also:
MKWaveTable, MKPartials, MKSamples, SynthPatchLibrary.rtf

Member Function Documentation

+ (id) newTimbre: (NSString *)  name  

Retrieve timbre if it exists, otherwise create it and install it in Data Base.

Parameters:
name is an NSString.
Returns:
Returns an id.

- (id) init  

Initialize timbre to be a new anonymous timbre.

Returns:
Returns an id.

- (id) copyWithZone: (NSZone *)  zone  

Abrief Copy timbre from specified zone.

The new timbre is "anonymous", i.e. it's name is NULL.

- (id) addWaveTable: (MKWaveTable *)  obj
forFreq: (double)  freq 

Add the specified MKWaveTable/frequency pair.

For speed, no check is made as to whether the given MKWaveTable is already present. If you're not sure, send removeWaveTable: first.

Parameters:
obj is a MKWaveTable *.
freq is a double.
Returns:
Returns self.

- (id) removeWaveTable: (MKWaveTable *)  obj  

Removes the given MKWaveTable and its corresponding frequency.

Returns nil if the obj is not found, otherwise self.

Parameters:
obj is a MKWaveTable *.
Returns:
Returns self.

- (MKWaveTable *) waveTableForFreq: (double)  freq  

Returns the MKWaveTable object corresponding to the specified freq, if any.

Parameters:
freq is a double.
Returns:
Returns an MKWaveTable instance.

- (double) freqForWaveTable: (MKWaveTable *)  obj  

Returns the freq corresponding to the specified freq, if any.

Returns MK_NODVAL if none.

Parameters:
obj is a MKWaveTable *.
Returns:
Returns a double.

- (MKWaveTable *) waveTableAt: (int)  index  

Returns the MKWaveTable object corresponding to the specified index, if any.

Index is zero-based.

Parameters:
index is an int.
Returns:
Returns an MKWaveTable instance.

- (double) freqAt: (int)  index  

Returns the freq corresponding to the specified index, if any.

Otherwise, returns MK_NODVAL. Index is zero-based.

Parameters:
index is an int.
Returns:
Returns a double.

+ (NSDictionary *) timbres  

Returns the timbre data base, a NSDictionary mapping names to MKTimbres.

The table is not copied. You should not free it or alter it. To delete a MKTimbre, first find the MKTimbre and then send it the free or freeSelfOnly message.

Returns:
Returns an NSDictionary.

- (id) setTimbreName: (NSString *)  newName  

if successful or nil if newName is already in use.

Parameters:
newName is a NSString instance.
Returns:
Returns self.

- (NSString *) timbreName  

Returns timbreName.

The string is not copied and should not be altered or freed.

Returns:
Returns an NSString.

- (NSMutableArray *) waveTables  

Returns waveTables object.

The NSMutableArray is not copied and should not be altered.

Returns:
Returns an NSMutableArray.

- (NSMutableArray *) freqs  

Returns freqs.

freqs NSMutableArray is not copied.

Returns:
Returns an NSMutableArray.

- (MKWaveTable*) MKWaveTableForTimbreKey (NSString *)  timbreKey
(double)  freq0
(double)  freq1 

Extracts the timbre name from timbreKey (by removing leading and trailing numbers) and looks up that name in the Data Base.

If there is a no timbre with that name, returns nil. Otherwise, looks for a trailing number in the timbreKey. If there is one, uses this as a 1-based index into the List of WaveTables and returns that MKWaveTable. Otherwise, looks for a 0 or 1 prepended to the timbreKey. If there is one, uses this to determine whether freq0 or freq1 is to be used to chose the MKWaveTable. If no number is prepended, uses freq1. Returns the MKWaveTable with frequency greater than or equal to the specified frequency.


Member Data Documentation

- (NSString*) timbreName [protected]

Name of this timbre

- (NSMutableArray*) freqs [protected]

Array object of frequencies

- (NSMutableArray*) waveTables [protected]

Array object of MKWaveTables


The documentation for this class was generated from the following file:

Generated on Sat Dec 5 17:01:16 2009 for MusicKit by  doxygen 1.5.6