Use ARDOUR::ladspa_search_path and PBD::find_matching_files to find LADSPA modules
authorPaul Davis <paul@linuxaudiosystems.com>
Mon, 15 Jul 2013 16:38:03 +0000 (12:38 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Mon, 15 Jul 2013 16:38:03 +0000 (12:38 -0400)
libs/ardour/ardour/plugin_manager.h
libs/ardour/ladspa_search_path.cc
libs/ardour/plugin_manager.cc

index a7a57036905a110d722cea3ee8c4359a8e652843..2464368ae7b84b31bbd47ac09f4532178961beaf 100644 (file)
@@ -51,7 +51,6 @@ class PluginManager : public boost::noncopyable {
 
        void refresh ();
 
-       int add_ladspa_directory (std::string dirpath);
        int add_windows_vst_directory (std::string dirpath);
        int add_lxvst_directory (std::string dirpath);
 
@@ -103,7 +102,6 @@ class PluginManager : public boost::noncopyable {
 
        std::map<uint32_t, std::string> rdf_type;
 
-       std::string ladspa_path;
        std::string windows_vst_path;
        std::string lxvst_path;
 
@@ -127,7 +125,6 @@ class PluginManager : public boost::noncopyable {
        int lxvst_discover_from_path (std::string path);
        int lxvst_discover (std::string path);
 
-       int ladspa_discover_from_path (std::string path);
        int ladspa_discover (std::string path);
 
        std::string get_ladspa_category (uint32_t id);
index 7b675d081d1b8285ec20be53db1fcba859ad1502..6ecc1557a3a7c011c84bc1b2d8af327976b39b66 100644 (file)
@@ -19,6 +19,8 @@
 
 #include <glibmm/miscutils.h>
 
+#include "pbd/pathexpand.h"
+
 #include "ardour/ladspa_search_path.h"
 #include "ardour/directory_names.h"
 #include "ardour/filesystem_paths.h"
@@ -46,6 +48,10 @@ ladspa_search_path ()
        spath.push_back ("/usr/local/lib/ladspa");
        spath.push_back ("/usr/lib64/ladspa");
        spath.push_back ("/usr/lib/ladspa");
+#endif
+
+#ifdef __APPLE__
+       spath.push_back (expand_path ("~/Library/Audio/Plug-Ins/LADSPA"));
        spath.push_back ("/Library/Audio/Plug-Ins/LADSPA");
 #endif
 
index 6ea0292872f11c9abe6fc38c0a8582f45062dc48..8d4e6258767617cc3b427bf74fb042c3f2bad457 100644 (file)
 #endif //LXVST_SUPPORT
 
 #include <glibmm/miscutils.h>
+#include <glibmm/pattern.h>
 
 #include "pbd/pathscanner.h"
 #include "pbd/whitespace.h"
+#include "pbd/file_utils.h"
 
 #include "ardour/debug.h"
 #include "ardour/filesystem_paths.h"
 #include "ardour/plugin_manager.h"
 #include "ardour/rc_configuration.h"
 
+#ifdef SearchPath
+#undef SearchPath
+#endif
+
+#include "ardour/ladspa_search_path.h"
+
 #ifdef LV2_SUPPORT
 #include "ardour/lv2_plugin.h"
 #endif
@@ -79,6 +87,8 @@
 
 #include "i18n.h"
 
+#include "ardour/debug.h"
+
 using namespace ARDOUR;
 using namespace PBD;
 using namespace std;
@@ -128,10 +138,6 @@ PluginManager::PluginManager ()
        }
 #endif /* Native LinuxVST support*/
 
-       if ((s = getenv ("LADSPA_PATH"))) {
-               ladspa_path = s;
-       }
-
        if ((s = getenv ("VST_PATH"))) {
                windows_vst_path = s;
        } else if ((s = getenv ("VST_PLUGINS"))) {
@@ -200,91 +206,38 @@ PluginManager::refresh ()
 void
 PluginManager::ladspa_refresh ()
 {
-       if (_ladspa_plugin_info)
+       if (_ladspa_plugin_info) {
                _ladspa_plugin_info->clear ();
-       else
+       } else {
                _ladspa_plugin_info = new ARDOUR::PluginInfoList ();
-
-       static const char *standard_paths[] = {
-               "/usr/local/lib64/ladspa",
-               "/usr/local/lib/ladspa",
-               "/usr/lib64/ladspa",
-               "/usr/lib/ladspa",
-               "/Library/Audio/Plug-Ins/LADSPA",
-               ""
-       };
+       }
 
        /* allow LADSPA_PATH to augment, not override standard locations */
 
        /* Only add standard locations to ladspa_path if it doesn't
         * already contain them. Check for trailing G_DIR_SEPARATOR too.
         */
+       
+       vector<string> ladspa_modules;
 
-       int i;
-       for (i = 0; standard_paths[i][0]; i++) {
-               size_t found = ladspa_path.find(standard_paths[i]);
-               if (found != ladspa_path.npos) {
-                       switch (ladspa_path[found + strlen(standard_paths[i])]) {
-                               case ':' :
-                               case '\0':
-                                       continue;
-                               case G_DIR_SEPARATOR :
-                                       if (ladspa_path[found + strlen(standard_paths[i]) + 1] == ':' ||
-                                           ladspa_path[found + strlen(standard_paths[i]) + 1] == '\0') {
-                                               continue;
-                                       }
-                       }
-               }
-               if (!ladspa_path.empty())
-                       ladspa_path += ":";
-
-               ladspa_path += standard_paths[i];
-
-       }
-
-       DEBUG_TRACE (DEBUG::PluginManager, string_compose ("LADSPA: search along: [%1]\n", ladspa_path));
-
-       ladspa_discover_from_path (ladspa_path);
-}
-
-
-int
-PluginManager::add_ladspa_directory (string path)
-{
-       if (ladspa_discover_from_path (path) == 0) {
-               ladspa_path += ':';
-               ladspa_path += path;
-               return 0;
-       }
-       return -1;
-}
-
-static bool ladspa_filter (const string& str, void */*arg*/)
-{
-       /* Not a dotfile, has a prefix before a period, suffix is "so" */
-
-       return str[0] != '.' && (str.length() > 3 && str.find (".so") == (str.length() - 3));
-}
+       DEBUG_TRACE (DEBUG::PluginManager, string_compose ("LADSPA: search along: [%1]\n", ladspa_search_path().to_string()));
 
-int
-PluginManager::ladspa_discover_from_path (string /*path*/)
-{
-       PathScanner scanner;
-       vector<string *> *plugin_objects;
-       vector<string *>::iterator x;
-       int ret = 0;
+       Glib::PatternSpec so_extension_pattern("*.so");
+       Glib::PatternSpec dylib_extension_pattern("*.dylib");
+       Glib::PatternSpec dll_extension_pattern("*.dll");
 
-       plugin_objects = scanner (ladspa_path, ladspa_filter, 0, false, true);
+       find_matching_files_in_search_path (ladspa_search_path (),
+                                           so_extension_pattern, ladspa_modules);
 
-       if (plugin_objects) {
-               for (x = plugin_objects->begin(); x != plugin_objects->end (); ++x) {
-                       ladspa_discover (**x);
-               }
+       find_matching_files_in_search_path (ladspa_search_path (),
+                                           dylib_extension_pattern, ladspa_modules);
+       find_matching_files_in_search_path (ladspa_search_path (),
+                                           dll_extension_pattern, ladspa_modules);
 
-               vector_delete (plugin_objects);
+       for (vector<std::string>::iterator i = ladspa_modules.begin(); i != ladspa_modules.end(); ++i) {
+               ladspa_discover (*i);
        }
-
-       return ret;
 }
 
 static bool rdf_filter (const string &str, void* /*arg*/)
@@ -370,6 +323,8 @@ PluginManager::add_lrdf_data (const string &path)
 int
 PluginManager::ladspa_discover (string path)
 {
+       DEBUG_TRACE (DEBUG::PluginManager, string_compose ("Checking for LADSPA plugin at %1\n", path));
+
        Glib::Module module(path);
        const LADSPA_Descriptor *descriptor;
        LADSPA_Descriptor_Function dfunc;
@@ -390,6 +345,8 @@ PluginManager::ladspa_discover (string path)
 
        dfunc = (LADSPA_Descriptor_Function)func;
 
+       DEBUG_TRACE (DEBUG::PluginManager, string_compose ("LADSPA plugin found at %1\n", path));
+
        for (uint32_t i = 0; ; ++i) {
                if ((descriptor = dfunc (i)) == 0) {
                        break;
@@ -443,6 +400,8 @@ PluginManager::ladspa_discover (string path)
                if(!found){
                    _ladspa_plugin_info->push_back (info);
                }
+
+               DEBUG_TRACE (DEBUG::PluginManager, string_compose ("Found LADSPA plugin, name: %1, Inputs: %2, Outputs: %3\n", info->name, info->n_inputs, info->n_outputs));
        }
 
 // GDB WILL NOT LIKE YOU IF YOU DO THIS