merged with 2.0-ongoing changes 2582-2605 (not thoroughly tested but it compiles...
[ardour.git] / libs / ardour / plugin_manager.cc
index 4be9b194688fa0865d58c0bc306b51f800f0746f..dac8a9eead4060f752df94daa4c69e4587a38ee0 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2000-2004 Paul Davis 
+    Copyright (C) 2000-2006 Paul Davis 
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
+#define __STDC_FORMAT_MACROS 1
+#include <stdint.h>
+
 #include <sys/types.h>
 #include <cstdio>
 #include <lrdf.h>
 #include <ardour/plugin_manager.h>
 #include <ardour/plugin.h>
 #include <ardour/ladspa_plugin.h>
+
+#ifdef VST_SUPPORT
 #include <ardour/vst_plugin.h>
+#endif
 
 #include <pbd/error.h>
 #include <pbd/stl_delete.h>
 
-#ifdef HAVE_COREAUDIO
-#include <CoreServices/CoreServices.h>
-#include <AudioUnit/AudioUnit.h>
-#endif // HAVE_COREAUDIO
-
 #include "i18n.h"
 
 using namespace ARDOUR;
@@ -53,8 +53,7 @@ using namespace PBD;
 
 PluginManager* PluginManager::_manager = 0;
 
-PluginManager::PluginManager (AudioEngine& e)
-       : _engine (e)
+PluginManager::PluginManager ()
 {
        char* s;
        string lrdf_path;
@@ -86,7 +85,6 @@ PluginManager::PluginManager (AudioEngine& e)
        }
 
        refresh ();
-
        if (_manager == 0) {
                _manager = this;
        }
@@ -101,23 +99,15 @@ PluginManager::refresh ()
                vst_refresh ();
        }
 #endif // VST_SUPPORT
-
-#ifdef HAVE_COREAUDIO
-       au_discover ();
-#endif // HAVE_COREAUDIO
 }
 
 void
 PluginManager::ladspa_refresh ()
 {
-       for (std::list<PluginInfo*>::iterator i = _ladspa_plugin_info.begin(); i != _ladspa_plugin_info.end(); ++i) {
-               delete *i;
-       }
-
        _ladspa_plugin_info.clear ();
 
        if (ladspa_path.length() == 0) {
-               ladspa_path = "/usr/local/lib/ladspa:/usr/lib/ladspa";
+               ladspa_path = "/usr/local/lib64/ladspa:/usr/local/lib/ladspa:/usr/lib64/ladspa:/usr/lib/ladspa:/Library/Audio/Plug-Ins/LADSPA";
        }
 
        ladspa_discover_from_path (ladspa_path);
@@ -234,7 +224,6 @@ PluginManager::add_lrdf_data (const string &path)
 int 
 PluginManager::ladspa_discover (string path)
 {
-       PluginInfo *info;
        void *module;
        const LADSPA_Descriptor *descriptor;
        LADSPA_Descriptor_Function dfunc;
@@ -259,23 +248,24 @@ PluginManager::ladspa_discover (string path)
                        break;
                }
 
-               info = new PluginInfo;
+               PluginInfoPtr info(new LadspaPluginInfo);
                info->name = descriptor->Name;
                info->category = get_ladspa_category(descriptor->UniqueID);
+               info->creator = descriptor->Maker;
                info->path = path;
                info->index = i;
-               info->n_inputs = 0;
-               info->n_outputs = 0;
-               info->type = PluginInfo::LADSPA;
+               info->n_inputs = ChanCount();
+               info->n_outputs = ChanCount();
+               info->type = ARDOUR::LADSPA;
                info->unique_id = descriptor->UniqueID;
                
                for (uint32_t n=0; n < descriptor->PortCount; ++n) {
                        if ( LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[n]) ) {
                                if ( LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[n]) ) {
-                                       info->n_inputs++;
+                                       info->n_inputs.set_audio(info->n_inputs.n_audio() + 1);
                                }
                                else if ( LADSPA_IS_PORT_OUTPUT (descriptor->PortDescriptors[n]) ) {
-                                       info->n_outputs++;
+                                       info->n_outputs.set_audio(info->n_outputs.n_audio() + 1);
                                }
                        }
                }
@@ -289,85 +279,6 @@ PluginManager::ladspa_discover (string path)
        return 0;
 }
 
-boost::shared_ptr<Plugin>
-PluginManager::load (Session& session, PluginInfo *info)
-{
-       void *module;
-
-       try {
-               boost::shared_ptr<Plugin> plugin;
-
-               if (info->type == PluginInfo::VST) {
-
-#ifdef VST_SUPPORT                     
-                       if (Config->get_use_vst()) {
-                               FSTHandle* handle;
-                               
-                               if ((handle = fst_load (info->path.c_str())) == 0) {
-                                       error << string_compose(_("VST: cannot load module from \"%1\""), info->path) << endmsg;
-                               } else {
-                                       plugin.reset (new VSTPlugin (_engine, session, handle));
-                               }
-                       } else {
-                               error << _("You asked ardour to not use any VST plugins") << endmsg;
-                       }
-#else // !VST_SUPPORT
-                       error << _("This version of ardour has no support for VST plugins") << endmsg;
-                       return boost::shared_ptr<Plugin> ((Plugin*) 0);
-#endif // !VST_SUPPORT
-                               
-               } else {
-
-                       if ((module = dlopen (info->path.c_str(), RTLD_NOW)) == 0) {
-                               error << string_compose(_("LADSPA: cannot load module from \"%1\""), info->path) << endmsg;
-                               error << dlerror() << endmsg;
-                       } else {
-                               plugin.reset (new LadspaPlugin (module, _engine, session, info->index, session.frame_rate()));
-                       }
-               }
-
-               plugin->set_info(*info);
-               return plugin;
-       }
-
-       catch (failed_constructor &err) {
-               return boost::shared_ptr<Plugin> ((Plugin*) 0);
-       }
-}
-
-boost::shared_ptr<Plugin>
-ARDOUR::find_plugin(Session& session, string name, long unique_id, PluginInfo::Type type)
-{
-       PluginManager *mgr = PluginManager::the_manager();
-       list<PluginInfo *>::iterator i;
-       list<PluginInfo *>* plugs = 0;
-
-       switch (type) {
-       case PluginInfo::LADSPA:
-               plugs = &mgr->ladspa_plugin_info();
-               break;
-       case PluginInfo::VST:
-               plugs = &mgr->vst_plugin_info();
-               unique_id = 0; // VST plugins don't have a unique id.
-               break;
-       case PluginInfo::AudioUnit:
-               plugs = &mgr->au_plugin_info();
-               unique_id = 0;
-               break;
-       default:
-               return boost::shared_ptr<Plugin> ((Plugin *) 0);
-       }
-
-       for (i = plugs->begin(); i != plugs->end(); ++i) {
-               if ((name == "" || (*i)->name == name) &&
-                       (unique_id == 0 || (*i)->unique_id == unique_id)) {     
-                       return mgr->load (session, *i);
-               }
-       }
-       
-       return boost::shared_ptr<Plugin> ((Plugin*) 0);
-}
-
 string
 PluginManager::get_ladspa_category (uint32_t plugin_id)
 {
@@ -376,7 +287,7 @@ PluginManager::get_ladspa_category (uint32_t plugin_id)
 
        snprintf(buf, sizeof(buf), "%s%" PRIu32, LADSPA_BASE, plugin_id);
        pattern.subject = buf;
-       pattern.predicate = RDF_TYPE;
+       pattern.predicate = (char*)RDF_TYPE;
        pattern.object = 0;
        pattern.object_type = lrdf_uri;
 
@@ -387,7 +298,7 @@ PluginManager::get_ladspa_category (uint32_t plugin_id)
        }
 
        pattern.subject = matches1->object;
-       pattern.predicate = LADSPA_BASE "hasLabel";
+       pattern.predicate = (char*)LADSPA_BASE "hasLabel";
        pattern.object = 0;
        pattern.object_type = lrdf_literal;
 
@@ -409,10 +320,6 @@ PluginManager::get_ladspa_category (uint32_t plugin_id)
 void
 PluginManager::vst_refresh ()
 {
-       for (std::list<PluginInfo*>::iterator i = _vst_plugin_info.begin(); i != _vst_plugin_info.end(); ++i) {
-               delete *i;
-       }
-
        _vst_plugin_info.clear ();
 
        if (vst_path.length() == 0) {
@@ -436,7 +343,7 @@ PluginManager::add_vst_directory (string path)
 static bool vst_filter (const string& str, void *arg)
 {
        /* Not a dotfile, has a prefix before a period, suffix is "dll" */
-       
+
        return str[0] != '.' && (str.length() > 4 && str.find (".dll") == (str.length() - 4));
 }
 
@@ -466,9 +373,9 @@ int
 PluginManager::vst_discover (string path)
 {
        FSTInfo* finfo;
-       PluginInfo* info;
 
        if ((finfo = fst_get_info (const_cast<char *> (path.c_str()))) == 0) {
+               warning << "Cannot get VST information from " << path << endmsg;
                return -1;
        }
 
@@ -478,7 +385,7 @@ PluginManager::vst_discover (string path)
                        << endl;
        }
        
-       info = new PluginInfo;
+       PluginInfoPtr info(new VSTPluginInfo);
 
        /* what a goddam joke freeware VST is */
 
@@ -490,10 +397,11 @@ PluginManager::vst_discover (string path)
 
        info->category = "VST";
        info->path = path;
+       // need to set info->creator but FST doesn't provide it
        info->index = 0;
        info->n_inputs = finfo->numInputs;
        info->n_outputs = finfo->numOutputs;
-       info->type = PluginInfo::VST;
+       info->type = ARDOUR::VST;
        
        _vst_plugin_info.push_back (info);
        fst_free_info (finfo);
@@ -502,101 +410,3 @@ PluginManager::vst_discover (string path)
 }
 
 #endif // VST_SUPPORT
-
-#ifdef HAVE_COREAUDIO
-
-int
-PluginManager::au_discover ()
-{
-       int mNumUnits = 0;
-       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;
-
-       for (int i = 0; i < numTypes; ++i) {
-               if (i == 1) {
-                       desc.componentType = kAudioUnitType_MusicEffect;
-               } else {
-                       desc.componentType = kAudioUnitType_Effect;
-               }
-
-               int n = CountComponents (&desc);
-
-               mNumUnits += n;
-       }
-       cout << "Number of AU plugins: " << mNumUnits << endl;
-
-       ComponentDescription* mCompDescs = new ComponentDescription[mNumUnits];
-
-       int n = 0;
-       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);
-                       mCompDescs[n++] = temp;
-                       comp = FindNextComponent (comp, &desc);
-               }
-       }
-
-       for (int i = 0; i < mNumUnits; ++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, &(mCompDescs[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(mCompDescs[i].componentType);
-                       CFStringRef compSubTypeString = UTCreateStringForOSType(mCompDescs[i].componentSubType);
-                       CFStringRef compManufacturerString = UTCreateStringForOSType(mCompDescs[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);
-               cout << realname << endl;       
-       }
-
-       delete[] mCompDescs;
-
-       return 0;
-}
-
-#endif // HAVE_COREAUDIO
-