• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: audiounit instrument with cocoa view
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: audiounit instrument with cocoa view


  • Subject: Re: audiounit instrument with cocoa view
  • From: ben kamen <email@hidden>
  • Date: Wed, 22 Jun 2011 14:49:21 -0700

here are the steps that seem to be the minimum for starting up with a cocoa view.  this uses the AUInstrumentBase (not the EffectBase...but it should be really similar)  i will probably miss something, so please add corrections.  

1.  create your new audio unit. 
2.  select the project and choose "add target" and choose "framework & library" > bundle.
3.  in your new target, create
a.  a new .xib (view) file
b.  a subclass of NSView, with 
in the header
i.  an private instance variable of type "AudioUnit" named "mAU"
ii.  the method -(void)setAU:(AudioUnit)inAU;
in the source
i. - (void)setAU:(AudioUnit)inAU{mAU = inAU;}

c.  a viewFactory class (just copy it from the filter demo project)
i.  rename the class and IBOutlet in the header to match the view class you just created 
ii. in the source, change the name of the bundle (after "loadNibNamed" to your AU bundle name)
iii.  and update the class names to reflect your view class, not the filterview class

4. in your .xib, set the class of your view to be the view class you created. 
5. set the .xib file's owner to be your viewfactory class. 
6. connect the "uiFreshlyLoadedView" outlet of the file's owner to the .xib view
7.  in you audio unit class header add two methods:
virtual OSStatus            GetProperty( AudioUnitPropertyID inID,
                                            AudioUnitScope inScope,
                                            AudioUnitElement inElement,
                                            void * outData );
  
virtual OSStatus              GetPropertyInfo (AudioUnitPropertyID inID,
                                                AudioUnitScope inScope,
                                                 AudioUnitElement inElement,
                                                 UInt32 & outDataSize,
                                                 Boolean & outWritable);



8. in the audio unit source implement those methods (replace YourAudioUnit with your audio unit, replace the bundle name with the bundle id of your AU, insert the name of yourViewBundle, and the name of yourViewFactory.


OSStatus YourAudioUnit::GetPropertyInfo (AudioUnitPropertyID inID,
                                              AudioUnitScope inScope,
                                              AudioUnitElement inElement,
                                              UInt32 & outDataSize,
                                              Boolean & outWritable)
{
    //printf("\tstart get prop info");
if (inScope == kAudioUnitScope_Global)
{
switch (inID)
{
case kAudioUnitProperty_CocoaUI:
outWritable = false;
                printf("settingOutdataSize");
outDataSize = sizeof (AudioUnitCocoaViewInfo);
                printf("%i",outDataSize);
return noErr;


}


return AUInstrumentBase::GetPropertyInfo (inID, inScope, inElement, outDataSize, outWritable);
}
    return noErr;
}



OSStatus YourAudioUnit::GetProperty( AudioUnitPropertyID inID,
                                                    AudioUnitScope inScope,
                                                    AudioUnitElement inElement,
                                                    void * outData )
{
if (inScope == kAudioUnitScope_Global) 
{
switch (inID) 
{
case kAudioUnitProperty_CocoaUI:
{
// Look for a resource in the main bundle by name and type.
CFBundleRef bundle = CFBundleGetBundleWithIdentifier( CFSTR("your.audio.unit.bundle") );


if (bundle == NULL) {
                    printf("bundle didn't load");
                    return fnfErr;

                    

                }                
CFURLRef bundleURL = CFBundleCopyResourceURL( bundle, 
                                                             CFSTR("yourViewBundle"), 
                                                             CFSTR("bundle"), 
                                                             NULL);

                

                if (bundleURL == NULL){
                    return fnfErr;
                    printf("bundleURL didn't work");    

                    

                }
                if(bundleURL){

                    

                    printf("ok");
                }

                

                

                CFStringRef className = CFSTR("yourViewFactory"); // name of the main class that implements the AUCocoaUIBase protocol
                
AudioUnitCocoaViewInfo cocoaInfo;
cocoaInfo.mCocoaAUViewBundleLocation = bundleURL;
cocoaInfo.mCocoaAUViewClass[0] = className;


*((AudioUnitCocoaViewInfo *)outData) = cocoaInfo;


return noErr;

                

}
}
}

    

    

return AUInstrumentBase::GetProperty (inID, inScope, inElement, outData);
}


9.  in your AU build settings, add your view bundle as a target dependency and add a "copy bundle resources" stage and add your bundle there as well. 

10.  build and hope it works.... 

ben
 _______________________________________________
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

  • Prev by Date: Re: audiounit instrument with cocoa view
  • Next by Date: User-land CoreAudio driver timing problem
  • Previous by thread: Re: audiounit instrument with cocoa view
  • Next by thread: Re: audiounit instrument with cocoa view
  • Index(es):
    • Date
    • Thread