Re: How to get bundle for pAudioUnit (in Objective-C)?
Re: How to get bundle for pAudioUnit (in Objective-C)?
- Subject: Re: How to get bundle for pAudioUnit (in Objective-C)?
- From: Howard Moon <email@hidden>
- Date: Mon, 7 Feb 2011 15:19:31 -0800
>>> I know how to get an NSBundle for an Application, but how do I get an AudioUnit's bundle? If I use the same code as in an app, [NSBundle mainBundle], then I get the bundle for the host application, not my AudioUnit.
>>>
>>> I'm modifying the uiViewForAudioUnit function so that the first time it is called (which I can tell because a certain member is not yet initialized), I want to load the contents of a file in the Resources folder of my bundle. But using mainBundle gives me the host (Logic) bundle location, not my AU's bundle. I've been looking for an hour now, and can't find how to get the bundle for the passed-in AudioUnit (inAU) parameter.
>>>
>>
>> I've figured out a way to get the bundle, but my Objective-C isn't too good yet, obviously. When I do the following, I get the contents of the file loaded into my member string, but I'm getting access violations, especially if I instantiate a second instance of the AudioUnit. Here's the code I added to my uiViewForAudioUnit:
>>
>> if (!xmlViewHierarchy)
>> {
>> NSBundle* auBundle = [NSBundle bundleForClass:[MyAUCocoaViewFactory self]];
>> NSString* pathToXML= [[auBundle resourcePath] stringByAppendingPathComponent:@"MyTestData.xml"];
>> xmlViewHierarchy = [NSString stringWithContentsOfFile:pathToXML encoding:NSUTF8StringEncoding error:NULL];
>> }
>>
>> I'm setting xmlViewHierarchy in an override of init for my view factory (just after calling super init), and releasing it in dealloc (just before calling super dealloc).
>>
>> I'm missing something basic, but I'm not sure what it is. Do I need to release the pathToXML or auBundle variables here? Anything else?
>>
>
> I changed "self" to "class" in the call to bundleForClass:, which also works (and is apparently what is *really* supposed to be passed there), and also added [pathToXML release]; at the end of that block, but I still get EXC_BAD_ACCESS at some point after this code runs.
>
I solved it! Apparently, my C++ background is messing with my ability to do Objective-C properly. I had defined the init and dealloc members in my header file, thinking that (as in C++) you need to put them in the header file whenever you want to override them. I commented out the header file declarations, leaving only the new implementations in my .mm file, and now it works fine!
So, I guess my Objective-C lesson for the day is to NOT re-define functions that I'm going to override!
Thanks anyway, and sorry for the noise...
-Howard
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden