Re: AUPresets in Logic
Re: AUPresets in Logic
- Subject: Re: AUPresets in Logic
- From: Bill Stewart <email@hidden>
- Date: Thu, 03 Oct 2002 11:01:44 -0700
on 3/10/02 6:20 AM, Marc Poirier wrote:
>
Hey, has anyone successfully implemented presets in an Audio Unit and
>
gotten them to work in Logic? I am having severe crashing and bogus data
>
problems, but I'm not sure whether it's the fault of Logic or my fault for
>
doing something wrong in GetPresets.
>
>
What's happeningis that, when I choose a preset number from the plugin
>
window menu in Logic, Logic calls AUBase::DispatchSetProperty with
>
kAudioUnitProperty_CurrentPreset as the selector. Looking at that part of
>
AUBase's code, we see:
>
>
case kAudioUnitProperty_CurrentPreset:
>
{
>
require(inScope == kAudioUnitScope_Global, InvalidScope);
>
AUPreset & newPreset = *(AUPreset *)inData;
>
>
if (newPreset.presetNumber >= 0)
>
CRASH HAPPENS HERE
The MatrixReverb makes sure the preset number if >= 0 is valid - if not it
returns an invalid property error.
The Reverb also Sets the default FactoryPreset in its constructor calling
SetAFactoryPreset method in AUBase with the default preset number...
If you use our Reverb with these calls does it crash for you?
>
So as soon as the inData is accessed as an AUPreset, a crash occurs.
>
Sometimes it can be accessed and I can print out the value of
>
newPreset.presetNumber and it's something crazy like -1609364160, so
>
clearly this data being passed in is bogus, either the inData pointer
>
itself or what it points to. If the data is being squeezed right out of
>
what I return from GetPresets, then it's probably my fault, but if not,
>
then it's probably Logic's fault. So anyway, I'm wondering if anyone has
>
had success, then I'll know that it's probably my fault.
>
>
So... if it is my fault and anyone cares to be so kind as to take a look
>
and tell me what I'm doing wrong... :)
>
>
// presets[].name is a C string
>
// numPresets is how many presets my plugin has
>
ComponentResult DfxPlugin::GetPresets(CFArrayRef *outData) const
>
{
>
AUPreset aupresets[numPresets];
>
for (long i=0; i < numPresets; i++)
>
{
>
aupresets[i].presetNumber = i;
>
aupresets[i].presetName = CFStringCreateWithCString(NULL,
>
presets[i].name, kCFStringEncodingMacRoman);
>
}
We do this this way:
First - static const data for the presets:
static const int kNumRoomPresets = 7;
static const AUPreset sRoomPresets[kNumRoomPresets] =
{
{ kReverbRoomType_SmallRoom, CFSTR("Small Room") },
{ kReverbRoomType_MediumRoom, CFSTR("Medium Room") },
{ kReverbRoomType_LargeRoom, CFSTR("Large Room") },
...
Then:
>
*outData = CFArrayCreate(NULL, (const void**)(&aupresets),
>
numPresets, NULL);
>
>
for (long i=0; i < numPresets; i++)
>
CFRelease(aupresets[i].presetName);
>
>
return noErr;
>
}
ComponentResult AUMatrixReverb::GetPresets ( CFArrayRef *
outData) const
{
CFMutableArrayRef theArray = CFArrayCreateMutable (NULL,
kNumRoomPresets, NULL);
for (int i = 0; i < kNumRoomPresets; ++i)
CFArrayAppendValue (theArray, &sRoomPresets[i]);
*outData = (CFArrayRef)theArray;
return noErr;
}
You need a MutableArray because you're going to be adding contents to it...
You certainly don't want to be releasing an element of the array and the
CFSTR macro is kind of neat, as it interns the string directly.
>
I might be messing up some CoreFoundation stuff (I'm still trying to
>
figure out when I need to release things and when I don't), but I tried
>
not releasing aupresets[i].presetName at the end and that did not help,
>
and I tried making aupresets[] a class member so that it would live
>
through the whole plugin instance, and that didn't help either.
>
Bill
>
Any help or insights or other experiences would be appreciated!
>
>
Thanks,
>
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.
--
mailto:email@hidden
tel: +1 408 974 4056
__________________________________________________________________________
"Much human ingenuity has gone into finding the ultimate Before.
The current state of knowledge can be summarized thus:
In the beginning, there was nothing, which exploded" - Terry Pratchett
__________________________________________________________________________
_______________________________________________
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.