Re: GetParameterValueStrings requires fixed, compile time strings?
Re: GetParameterValueStrings requires fixed, compile time strings?
- Subject: Re: GetParameterValueStrings requires fixed, compile time strings?
- From: Marc Poirier <email@hidden>
- Date: Tue, 8 Apr 2003 16:02:47 +0200 (CEST)
>
I'm implementing plugin automation using AUBase parameters.
>
The function GetParameterValueStrings is called for indexed
>
parameters to get the names of each possible value of the parameter.
>
Apple's example shows that this function should fill in a pointer to
>
CFArrayRef containing CFStringRef objects. The CFStringRef are
>
created by the CFSTR function.
>
>
Problem is that, as I understand CFStringRef, these objects can only
>
be created at compile time, like the string literals they replace.
>
However my values are dynamically created at runtime.
>
>
Is there a way to create these strings at runtime?
Certainly. CFSTR is a nice convenience macro and it let's you forget
about keeping track of your strings and releasing them when you're done,
but it's most certainly not the only way. Here are some snippets from my
code where I create and release these at runtime (this is kind of pseudo
code, note I have a special parameter class so you can't just copy and
paste this code, you'll have to look and see conceptually what I'm
demonstrating here):
this is a member of my parameter class:
CFStringRef *valueCFStrings;
when creating a parameter (an instance of my parameter class):
valueCFStrings = NULL;
in the parameter destructor:
if (valueCFStrings != NULL)
{
for (long i=0; i < numAllocatedValueStrings; i++)
{
if (valueCFStrings[i] != NULL)
CFRelease(valueCFStrings[i]);
valueCFStrings[i] = NULL;
}
free(valueCFStrings);
}
valueCFStrings = NULL;
setup:
valueCFStrings = (CFStringRef*) malloc(numAllocatedValueStrings *
sizeof(CFStringRef));
for (long i=0; i < numAllocatedValueStrings; i++)
valueCFStrings[i] = NULL;
set value string:
// release the old CFString if one has already been created
if (valueCFStrings[arrayIndex] != NULL)
CFRelease(valueCFStrings[arrayIndex]);
// convert the incoming text to a CFString
valueCFStrings[arrayIndex] =
CFStringCreateWithCString(kCFAllocatorDefault,
inText, CFStringGetSystemEncoding());
and then in the actual plugin class itself:
ComponentResult DfxPlugin::GetParameterValueStrings(AudioUnitScope
inScope,
AudioUnitParameterID inParameterID, CFArrayRef *outStrings)
{
if (param[inParameterID].valueCFStrings != NULL)
{
// in case the min is not 0, get the total count of items in the array
long numStrings = param[inParameterID].max -
param[inParameterID].min + 1;
// create a CFArray of the strings (the host will destroy the CFArray)
*outStrings = CFArrayCreate(kCFAllocatorDefault,
(const void**)(param[inParameterID].valueCFStrings),
numStrings, NULL);
return noErr;
}
return kAudioUnitErr_InvalidProperty;
}
So the relevant thing to pick out of there if you want to just look this
stuff up yourself and ignore my example code is that I've used
CFStringCreateWithCString to create CFStrings at runtime from non
compile-time-constant C strings, I used CFRelease to deallocate those at
the end of the plugin lifetime, and I've used CFArrayCreate to create the
CFArray of those in GetParameterValueStrings.
Good luck,
Marc
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.