Added LADSPA_PATH to ardev_common.sh
[ardour.git] / libs / ardour / audio_unit.cc
index 5d7e7ae90c9bd156004f41caf302f453f46c5908..52cfc187afe20d7bfe941ef0bffa1587419e7e30 100644 (file)
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
 */
+
+#include <ardour/audio_unit.h>
+#include <ardour/utils.h>
+
+#include <CoreServices/CoreServices.h>
+#include <AudioUnit/AudioUnit.h>
+
+using namespace ARDOUR;
+
+PluginInfoList
+AUPluginInfo::discover ()
+{
+       PluginInfoList plugs;
+
+       int numTypes = 2;    // this magic number was retrieved from the apple AUHost example.
+
+       ComponentDescription desc;
+       desc.componentFlags = 0;
+       desc.componentFlagsMask = 0;
+       desc.componentSubType = 0;
+       desc.componentManufacturer = 0;
+
+       vector<ComponentDescription> vCompDescs;
+
+       for (int i = 0; i < numTypes; ++i) {
+               if (i == 1) {
+                       desc.componentType = kAudioUnitType_MusicEffect;
+               } else {
+                       desc.componentType = kAudioUnitType_Effect;
+               }
+
+               Component comp = 0;
+
+               comp = FindNextComponent (NULL, &desc);
+               while (comp != NULL) {
+                       ComponentDescription temp;
+                       GetComponentInfo (comp, &temp, NULL, NULL, NULL);
+                       vCompDescs.push_back(temp);
+                       comp = FindNextComponent (comp, &desc);
+               }
+       }
+
+       for (unsigned int i = 0; i < vCompDescs.size(); ++i) {
+
+               // the following large block is just for determining the name of the plugin.
+               CFStringRef itemName = NULL;
+               // Marc Poirier -style item name
+               Component auComponent = FindNextComponent (0, &(vCompDescs[i]));
+               if (auComponent != NULL) {
+                       ComponentDescription dummydesc;
+                       Handle nameHandle = NewHandle(sizeof(void*));
+                       if (nameHandle != NULL) {
+                               OSErr err = GetComponentInfo(auComponent, &dummydesc, nameHandle, NULL, NULL);
+                               if (err == noErr) {
+                                       ConstStr255Param nameString = (ConstStr255Param) (*nameHandle);
+                                       if (nameString != NULL) {
+                                               itemName = CFStringCreateWithPascalString(kCFAllocatorDefault, nameString, CFStringGetSystemEncoding());
+                                       }
+                               }
+                               DisposeHandle(nameHandle);
+                       }
+               }
+
+               // if Marc-style fails, do the original way
+               if (itemName == NULL) {
+                       CFStringRef compTypeString = UTCreateStringForOSType(vCompDescs[i].componentType);
+                       CFStringRef compSubTypeString = UTCreateStringForOSType(vCompDescs[i].componentSubType);
+                       CFStringRef compManufacturerString = UTCreateStringForOSType(vCompDescs[i].componentManufacturer);
+
+                       itemName = CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@ - %@ - %@"), 
+                               compTypeString, compManufacturerString, compSubTypeString);
+
+                       if (compTypeString != NULL)
+                               CFRelease(compTypeString);
+                       if (compSubTypeString != NULL)
+                               CFRelease(compSubTypeString);
+                       if (compManufacturerString != NULL)
+                               CFRelease(compManufacturerString);
+               }
+               string realname = CFStringRefToStdString(itemName);
+
+               AUPluginInfoPtr plug(new AUPluginInfo);
+               plug->name = realname;
+               plug->type = PluginInfo::AudioUnit;
+               plug->n_inputs = 0;
+               plug->n_outputs = 0;
+               plug->category = "AudioUnit";
+
+               plugs.push_back(plug);
+       }
+
+       return plugs;
+}