Re: AudioUnitHosting menu patch
Re: AudioUnitHosting menu patch
- Subject: Re: AudioUnitHosting menu patch
- From: Bill Stewart <email@hidden>
- Date: Mon, 11 Aug 2003 10:51:53 -0700
Nice look! I've added this to the SDK -
There's one thing you might want to do...
You should always lock handles before you dereference them - probably
doesn't matter in this case, but its a good habit to get into as the
memory that a handle points to can move on you (and locking will stop
that from occuring) - then its safe to derefence it.
On Sunday, August 10, 2003, at 11:22 AM, Marc Poirier wrote:
Hi. I was having a hard time with AudioUnitHosting's menu and all of
my
dozens of AUs with non-printable sub-type codes, so I changed the menu
to
list the component name string rather than the component description
codes. For anyone interested in making the same change, I figured I
might
as well share my changes:
void AudioUnitHosting::BuildMenuList (XControl& theControl)
{
MenuRef menu = GetControlPopupMenuHandle (theControl.MacControl());
// clean the old items out
DeleteMenuItems (menu, 1, GetControlMaximum
(theControl.MacControl()));
for (int i = 0; i < mNumUnits; ++i)
{
// Marc-style menu item
bool menuItemWasAdded = false;
Component auComponent = FindNextComponent(NULL, &(mCompDescs[i]));
if (auComponent != NULL)
{
ComponentDescription desc2;
Handle nameHandle = NewHandle(sizeof(void*));
OSErr err0r = GetComponentInfo(auComponent, &desc2, nameHandle,
NULL, NULL);
if (err0r == noErr)
{
if (nameHandle != NULL)
{
HLock (nameHandle);
ConstStr255Param nameString = (ConstStr255Param) (*nameHandle);
if (nameString != NULL)
{
AppendMenuItemText(menu, nameString);
menuItemWasAdded = true;
}
}
}
DisposeHandle(nameHandle);
}
// if Marc-style fails, do the original way
if (!menuItemWasAdded)
{
// make a pascal style string, count byte at zero
char menuStr[32];
char* p = menuStr;
p++;
p += sprintf (p, "%4.4s - ", (char*)&(mCompDescs[i].componentType));
p += sprintf (p, "%4.4s - ",
(char*)&(mCompDescs[i].componentManufacturer));
p += sprintf (p, "%4.4s", (char*)&(mCompDescs[i].componentSubType));
menuStr[0] = (p - menuStr - 1);
AppendMenuItemText (menu, (ConstStr255Param)menuStr);
}
}
SetControlMaximum (theControl.MacControl(), mNumUnits);
}
_______________________________________________
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.