Fix broken whitespace. I'd apologize for the compile times if it was my fault :D
[ardour.git] / libs / ardour / plugin_manager.cc
index 22e649e03e00b66b28c0ae7c8f339ea32817cab9..8221f7b46e7988b354d38b81df9abe3cf688f030 100644 (file)
@@ -21,7 +21,6 @@
 #include "libardour-config.h"
 #endif
 
-#define __STDC_FORMAT_MACROS 1
 #include <stdint.h>
 
 #include <sys/types.h>
@@ -40,6 +39,7 @@
 #include <glibmm/miscutils.h>
 
 #include "pbd/pathscanner.h"
+#include "pbd/whitespace.h"
 
 #include "ardour/ladspa.h"
 #include "ardour/session.h"
@@ -48,8 +48,7 @@
 #include "ardour/ladspa_plugin.h"
 #include "ardour/filesystem_paths.h"
 
-#ifdef HAVE_SLV2
-#include <slv2/slv2.h>
+#ifdef LV2_SUPPORT
 #include "ardour/lv2_plugin.h"
 #endif
 
@@ -134,18 +133,20 @@ PluginManager::PluginManager ()
                ladspa_plugin_whitelist.push_back (2150); // tap pitch shifter
        }
 
-#ifdef HAVE_SLV2
-       _lv2_world = new LV2World();
-#endif
-
        BootMessage (_("Discovering Plugins"));
 }
 
+
+PluginManager::~PluginManager()
+{
+}
+
+
 void
 PluginManager::refresh ()
 {
        ladspa_refresh ();
-#ifdef HAVE_SLV2
+#ifdef LV2_SUPPORT
        lv2_refresh ();
 #endif
 #ifdef VST_SUPPORT
@@ -156,6 +157,8 @@ PluginManager::refresh ()
 #ifdef HAVE_AUDIOUNITS
        au_refresh ();
 #endif
+
+       PluginListChanged (); /* EMIT SIGNAL */
 }
 
 void
@@ -178,7 +181,7 @@ PluginManager::ladspa_refresh ()
        /* 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 '/'s too.
+        * already contain them. Check for trailing G_DIR_SEPARATOR too.
         */
 
        int i;
@@ -189,7 +192,7 @@ PluginManager::ladspa_refresh ()
                                case ':' :
                                case '\0':
                                        continue;
-                               case '/' :
+                               case G_DIR_SEPARATOR :
                                        if (ladspa_path[found + strlen(standard_paths[i]) + 1] == ':' ||
                                            ladspa_path[found + strlen(standard_paths[i]) + 1] == '\0') {
                                                continue;
@@ -299,13 +302,12 @@ PluginManager::add_lrdf_data (const string &path)
        PathScanner scanner;
        vector<string *>* rdf_files;
        vector<string *>::iterator x;
-       string uri;
 
        rdf_files = scanner (path, rdf_filter, 0, true, true);
 
        if (rdf_files) {
                for (x = rdf_files->begin(); x != rdf_files->end (); ++x) {
-                       uri = "file://" + **x;
+                       const string uri(string("file://") + **x);
 
                        if (lrdf_read_file(uri.c_str())) {
                                warning << "Could not parse rdf file: " << uri << endmsg;
@@ -432,15 +434,41 @@ PluginManager::get_ladspa_category (uint32_t plugin_id)
        string label = matches2->object;
        lrdf_free_statements(matches2);
 
-       return label;
+       /* Kludge LADSPA class names to be singular and match LV2 class names.
+          This avoids duplicate plugin menus for every class, which is necessary
+          to make the plugin category menu at all usable, but is obviously a
+          filthy kludge.
+
+          In the short term, lrdf could be updated so the labels match and a new
+          release made. To support both specs, we should probably be mapping the
+          URIs to the same category in code and perhaps tweaking that hierarchy
+          dynamically to suit the user. Personally, I (drobilla) think that time
+          is better spent replacing the little-used LRDF.
+
+          In the longer term, we will abandon LRDF entirely in favour of LV2 and
+          use that class hierarchy. Aside from fixing this problem properly, that
+          will also allow for translated labels. SWH plugins have been LV2 for
+          ages; TAP needs porting. I don't know of anything else with LRDF data.
+       */
+       if (label == "Utilities") {
+               return "Utility";
+       } else if (label == "Pitch shifters") {
+               return "Pitch Shifter";
+       } else if (label != "Dynamics" && label != "Chorus"
+                  &&label[label.length() - 1] == 's'
+                  && label[label.length() - 2] != 's') {
+               return label.substr(0, label.length() - 1);
+       } else {
+               return label;
+       }
 }
 
-#ifdef HAVE_SLV2
+#ifdef LV2_SUPPORT
 void
 PluginManager::lv2_refresh ()
 {
        delete _lv2_plugin_info;
-       _lv2_plugin_info = LV2PluginInfo::discover(_lv2_world);
+       _lv2_plugin_info = LV2PluginInfo::discover();
 }
 #endif
 
@@ -547,6 +575,7 @@ PluginManager::vst_discover (string path)
        info->index = 0;
        info->n_inputs.set_audio (finfo->numInputs);
        info->n_outputs.set_audio (finfo->numOutputs);
+       info->n_inputs.set_midi (finfo->wantMidi ? 1 : 0);
        info->type = ARDOUR::VST;
 
        _vst_plugin_info->push_back (info);
@@ -598,7 +627,7 @@ PluginManager::save_statuses ()
                        break;
                }
 
-               ofs << ' ' << (*i).unique_id << ' ';
+               ofs << ' ';
 
                switch ((*i).status) {
                case Normal:
@@ -612,6 +641,8 @@ PluginManager::save_statuses ()
                        break;
                }
 
+               ofs << ' ';
+               ofs << (*i).unique_id;;
                ofs << endl;
        }
 
@@ -630,10 +661,11 @@ PluginManager::load_statuses ()
        }
 
        std::string stype;
-       std::string id;
        std::string sstatus;
+       std::string id;
        PluginType type;
        PluginStatusType status;
+       char buf[1024];
 
        while (ifs) {
 
@@ -642,15 +674,31 @@ PluginManager::load_statuses ()
                        break;
 
                }
-               ifs >> id;
+
+               ifs >> sstatus;
                if (!ifs) {
                        break;
+
                }
 
-               ifs >> sstatus;
+               /* rest of the line is the plugin ID */
+
+               ifs.getline (buf, sizeof (buf), '\n');
                if (!ifs) {
                        break;
+               }
 
+               if (sstatus == "Normal") {
+                       status = Normal;
+               } else if (sstatus == "Favorite") {
+                       status = Favorite;
+               } else if (sstatus == "Hidden") {
+                       status = Hidden;
+               } else {
+                       error << string_compose (_("unknown plugin status type \"%1\" - all entries ignored"), sstatus)
+                                 << endmsg;
+                       statuses.clear ();
+                       break;
                }
 
                if (stype == "LADSPA") {
@@ -666,18 +714,9 @@ PluginManager::load_statuses ()
                              << endmsg;
                        continue;
                }
-               if (sstatus == "Normal") {
-                       status = Normal;
-               } else if (sstatus == "Favorite") {
-                       status = Favorite;
-               } else if (sstatus == "Hidden") {
-                       status = Hidden;
-               } else {
-                       error << string_compose (_("unknown plugin status type \"%1\" - ignored"), stype)
-                             << endmsg;
-                       continue;
-               }
 
+               id = buf;
+               strip_whitespace_edges (id);
                set_status (type, id, status);
        }
 
@@ -721,7 +760,7 @@ PluginManager::ladspa_plugin_info ()
 ARDOUR::PluginInfoList&
 PluginManager::lv2_plugin_info ()
 {
-#ifdef HAVE_SLV2
+#ifdef LV2_SUPPORT
        if (!_lv2_plugin_info)
                lv2_refresh();
        return *_lv2_plugin_info;