Functions | |
int | MKHighestPar (void) |
Returns the parameter tag of the highest numbered parameter. | |
NSHashEnumerator * | MKInitParameterIteration (MKNote *aNote) |
Query for a MKNote's parameters. | |
int | MKNextParameter (MKNote *aNote, NSHashEnumerator *iterationState) |
Retrieve the next parameter. | |
BOOL | MKIsNoteParPresent (MKNote *aNote, int par) |
Query for a MKNote's parameters. |
int MKHighestPar | ( | void | ) |
Returns the parameter tag of the highest numbered parameter.
This can be used, for example, to print the names of all known parameters as follows:
for (i = 0; i <= MKHighestPar(); i++) printf([MKNote parNameForTag: i]);
NSHashEnumerator* MKInitParameterIteration | ( | MKNote * | aNote | ) |
Query for a MKNote's parameters.
MKInitParameterIteration() and MKNextParameter() work together to return, one by one, the full complement of a MKNote's parameter identifiers. MKInitParameterIteration() primes its MKNote argument for successive calls to MKNextParameter(), each of which retrieves the next parameter in the MKNote. When all the parameters have been visited, MKNextParameter() returns the value MK_noPar. The pointer returned by MKInitParameterIteration() must be passed as the iterationState argument to MKNextParameter(). Keep in mind that MKNextParameter() returns parameter identifiers; you still must retrieve the value of the parameter. An example for your delight:
// Initialize the iteration state for the desired MKNote. void *aState = MKInitParameterIteration(aNote); int par;
// Get the parameters until the MKNote is exhausted. while ((par = MKNextParameter(aNote, aState)) != MK_noPar) { // Operate on the parameters of interest. switch (par) { case MK_freq: // Get the value of MK_freq and apply it. ... break; case MK_amp: // Get the value of MK_amp and apply it. ... break; default: // Ignore all other parameters. break; } }
In essence, this example and the example shown in MKIsNoteParPresent() do the same thing: They find and operate on parameters of interest. Which methodology to adopt - whether to test for the existence of particular parameters as in the first example, or to retrieve the identifiers of all present parameters as in the second - depends on how “saturated” the MKNote is with interesting parameters. If you only want a couple of parameters then it's generally more efficient to call MKIsNoteParPresent() for each of them. However, if you're interested in most - or what you assume to be most - of a MKNote's parameters (as is usually the case for a reasonably sophisticated MKSynthPatch, for example), then it's probably faster to iterate over all the parameters through MKNextParameter().
aNote | is a MKNote instance. |
BOOL MKIsNoteParPresent | ( | MKNote * | aNote, | |
int | par | |||
) |
Query for a MKNote's parameters.
MKIsNoteParPresent() returns YES or NO as the parameter par within the MKNote aNote is or isn't present; a parameter is considered present only if it's been given a value. The function is equivalent to MKNote's isParPresent: method. Unless the mere existence of the parameter is significant, you would follow a call to MKIsNoteParPresent() with a parameter value retrieval function, such as MKGetNoteParAsDouble():
double freq;
// Get the value of MK_freq only if the parameter has been set. if (MKIsNoteParPresent(aNote, MK_freq)) { freq = MKGetParAsDouble(aNote, MK_freq); ... // do something with freq. }
aNote | is a MKNote instance. | |
par | is an int. |
int MKNextParameter | ( | MKNote * | aNote, | |
NSHashEnumerator * | iterationState | |||
) |
Retrieve the next parameter.
MKInitParameterIteration() and MKNextParameter() work together to return, one by one, the full complement of a MKNote's parameter identifiers. MKInitParameterIteration() primes its MKNote argument for successive calls to MKNextParameter(), each of which retrieves the next parameter in the MKNote. When all the parameters have been visited, MKNextParameter() returns the value MK_noPar. The pointer returned by MKInitParameterIteration() must be passed as the iterationState argument to MKNextParameter(). Keep in mind that MKNextParameter() returns parameter identifiers; you still must retrieve the value of the parameter. It is illegal to reference aState after MKNextParameter() has returned MK_noPar.
aNote | is a Note. | |
iterationState | is a NSHashEnumerator *. |