Revert "case insensitive ".dll" for VST plugins - fixes #6285"
[ardour.git] / libs / ardour / vst_info_file.cc
index a0426edad1bac8d40f7b27ef4f0abd1e9c5f9fb6..2d68421103d0d14930f8ff9d5925ba333d39540f 100644 (file)
 #include <stddef.h>
 #include <stdio.h>
 #include <string.h>
-#include <libgen.h>
 
 #include <glib.h>
 #include <glib/gstdio.h>
 #include <glibmm.h>
 
+#include "pbd/error.h"
 
-#ifdef VST_SCANNER_APP
-#define errormsg cerr
-#define warningmsg cerr
-#define endmsg endl
-#else
+#ifndef VST_SCANNER_APP
 #include "ardour/plugin_manager.h" // scanner_bin_path
 #include "ardour/rc_configuration.h"
 #include "ardour/system_exec.h"
-#include "pbd/error.h"
-#define errormsg PBD::error
-#define warningmsg PBD::warning
 #endif
 
 #include "ardour/filesystem_paths.h"
@@ -103,7 +96,8 @@ vstfx_cache_file (const char* dllpath, int personal, const char *ext)
 {
        string dir;
        if (personal) {
-               dir = get_personal_vst_blacklist_dir();
+               dir = get_personal_vst_info_cache_dir();
+               // TODO prefix path relative to scan-root to avoid duplicates
        } else {
                dir = Glib::path_get_dirname (std::string(dllpath));
        }
@@ -116,7 +110,16 @@ vstfx_cache_file (const char* dllpath, int personal, const char *ext)
 static string
 vstfx_blacklist_path (const char* dllpath, int personal)
 {
-       return vstfx_cache_file(dllpath, personal, EXT_BLACKLIST);
+       string dir;
+       if (personal) {
+               dir = get_personal_vst_blacklist_dir();
+       } else {
+               dir = Glib::path_get_dirname (std::string(dllpath));
+       }
+
+       stringstream s;
+       s << PFX_DOTFILE << Glib::path_get_basename (dllpath) << EXT_BLACKLIST;
+       return Glib::build_filename (dir, s.str ());
 }
 
 static string
@@ -125,12 +128,13 @@ vstfx_infofile_path (const char* dllpath, int personal)
        return vstfx_cache_file(dllpath, personal, EXT_INFOFILE);
 }
 
+#ifndef VST_SCANNER_APP
 static string
 vstfx_errorfile_path (const char* dllpath, int personal)
 {
        return vstfx_cache_file(dllpath, personal, EXT_ERRORFILE);
 }
-
+#endif
 
 
 /* *** MEMORY MANAGEMENT *** */
@@ -224,6 +228,12 @@ vstfx_load_info_block(FILE* fp, VSTInfo *info)
                info->wantMidi = 1;
        }
 
+       if ((info->numParams) == 0) {
+               info->ParamNames = NULL;
+               info->ParamLabels = NULL;
+               return true;
+       }
+
        if ((info->ParamNames = (char **) malloc(sizeof(char*)*info->numParams)) == 0) {
                return false;
        }
@@ -330,7 +340,7 @@ vstfx_write_info_file (FILE* fp, vector<VSTInfo *> *infos)
        } else if (infos->size() == 1) {
                vstfx_write_info_block(fp, infos->front());
        } else {
-               errormsg << "Zero plugins in VST." << endmsg; // XXX here? rather make this impossible before if it ain't already.
+               PBD::error << "Zero plugins in VST." << endmsg; // XXX here? rather make this impossible before if it ain't already.
        }
 }
 
@@ -380,10 +390,16 @@ static FILE *
 vstfx_blacklist_file (const char *dllpath)
 {
        FILE *f;
-       if ((f = fopen (vstfx_blacklist_path (dllpath, 0).c_str(), "w"))) {
+       if ((f = fopen (vstfx_blacklist_path (dllpath, 0).c_str(), "wb"))) {
+#ifndef NDEBUG
+       PBD::info << "Blacklisted VST: '" << vstfx_blacklist_path (dllpath, 0) << "'" << endmsg;
+#endif
                return f;
        }
-       return fopen (vstfx_blacklist_path (dllpath, 1).c_str(), "w");
+#ifndef NDEBUG
+       PBD::info << "Blacklisted VST: '" << vstfx_blacklist_path (dllpath, 1) << "'" << endmsg;
+#endif
+       return fopen (vstfx_blacklist_path (dllpath, 1).c_str(), "wb");
 }
 
 /** mark plugin as blacklisted */
@@ -483,7 +499,10 @@ vstfx_infofile_create (const char* dllpath, int personal)
        }
 
        string const path = vstfx_infofile_path (dllpath, personal);
-       return fopen (path.c_str(), "w");
+#ifndef NDEBUG
+       PBD::info << "Creating VST cache file " << path << endmsg;
+#endif
+       return fopen (path.c_str(), "wb");
 }
 
 /** newly created cache file for given plugin
@@ -514,7 +533,7 @@ vstfx_get_info_from_file(const char* dllpath, vector<VSTInfo*> *infos)
                rv = vstfx_load_info_file(infofile, infos);
                fclose (infofile);
                if (!rv) {
-                       warningmsg << "Cannot get VST information form " << dllpath << ": info file load failed." << endmsg;
+                       PBD::warning << "Cannot get VST information form " << dllpath << ": info file load failed." << endmsg;
                }
        }
        return rv;
@@ -534,7 +553,7 @@ bool vstfx_midi_input (VSTState* vstfx)
        if (vst_version >= 2) {
                /* should we send it VST events (i.e. MIDI) */
 
-               if ((plugin->flags & effFlagsIsSynth) || (plugin->dispatcher (plugin, effCanDo, 0, 0,(void*) "receiveVstEvents", 0.0f) > 0)) {
+               if ((plugin->flags & effFlagsIsSynth) || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("receiveVstEvents"), 0.0f) > 0)) {
                        return true;
                }
        }
@@ -552,8 +571,8 @@ bool vstfx_midi_output (VSTState* vstfx)
        if (vst_version >= 2) {
                /* should we send it VST events (i.e. MIDI) */
 
-               if (   (plugin->dispatcher (plugin, effCanDo, 0, 0,(void*) "sendVstEvents", 0.0f) > 0)
-                               || (plugin->dispatcher (plugin, effCanDo, 0, 0,(void*) "sendVstMidiEvent", 0.0f) > 0)
+               if (   (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("sendVstEvents"), 0.0f) > 0)
+                      || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("sendVstMidiEvent"), 0.0f) > 0)
                         ) {
                        return true;
                }
@@ -616,14 +635,26 @@ vstfx_parse_vst_state (VSTState* vstfx)
          fail to implement getVendorString, and so won't stuff the
          string with any name*/
 
-       char creator[65] = "Unknown\0";
+       char creator[65] = "Unknown";
+       char name[65] = "";
 
        AEffect* plugin = vstfx->plugin;
 
-       info->name = strdup (vstfx->handle->name);
+
+       plugin->dispatcher (plugin, effGetEffectName, 0, 0, name, 0);
+
+       if (strlen(name) == 0) {
+               plugin->dispatcher (plugin, effGetProductString, 0, 0, name, 0);
+       }
+
+       if (strlen(name) == 0) {
+               info->name = strdup (vstfx->handle->name);
+       } else {
+               info->name = strdup (name);
+       }
 
        /*If the plugin doesn't bother to implement GetVendorString we will
-         have pre-stuffed the string with 'Unkown' */
+         have pre-stuffed the string with 'Unknown' */
 
        plugin->dispatcher (plugin, effGetVendorString, 0, 0, creator, 0);
 
@@ -706,10 +737,9 @@ vstfx_info_from_plugin (const char *dllpath, VSTState* vstfx, vector<VSTInfo *>
                int id;
                vector< pair<int, string> > ids;
                AEffect *plugin = vstfx->plugin;
-               string path = vstfx->handle->path;
 
                do {
-                       char name[65] = "Unknown\0";
+                       char name[65] = "Unknown";
                        id = plugin->dispatcher (plugin, effShellGetNextPlugin, 0, 0, name, 0);
                        ids.push_back(std::make_pair(id, name));
                } while ( id != 0 );
@@ -780,7 +810,7 @@ vstfx_instantiate_and_get_info_lx (
        VSTHandle* h;
        VSTState* vstfx;
        if (!(h = vstfx_load(dllpath))) {
-               warningmsg << "Cannot get LinuxVST information from " << dllpath << ": load failed." << endmsg;
+               PBD::warning << "Cannot get LinuxVST information from " << dllpath << ": load failed." << endmsg;
                return false;
        }
 
@@ -788,7 +818,7 @@ vstfx_instantiate_and_get_info_lx (
 
        if (!(vstfx = vstfx_instantiate(h, simple_master_callback, 0))) {
                vstfx_unload(h);
-               warningmsg << "Cannot get LinuxVST information from " << dllpath << ": instantiation failed." << endmsg;
+               PBD::warning << "Cannot get LinuxVST information from " << dllpath << ": instantiation failed." << endmsg;
                return false;
        }
 
@@ -809,7 +839,7 @@ vstfx_instantiate_and_get_info_fst (
        VSTHandle* h;
        VSTState* vstfx;
        if(!(h = fst_load(dllpath))) {
-               warningmsg << "Cannot get Windows VST information from " << dllpath << ": load failed." << endmsg;
+               PBD::warning << "Cannot get Windows VST information from " << dllpath << ": load failed." << endmsg;
                return false;
        }
 
@@ -818,7 +848,7 @@ vstfx_instantiate_and_get_info_fst (
        if(!(vstfx = fst_instantiate(h, simple_master_callback, 0))) {
                fst_unload(&h);
                vstfx_current_loading_id = 0;
-               warningmsg << "Cannot get Windows VST information from " << dllpath << ": instantiation failed." << endmsg;
+               PBD::warning << "Cannot get Windows VST information from " << dllpath << ": instantiation failed." << endmsg;
                return false;
        }
        vstfx_current_loading_id = 0;
@@ -840,14 +870,14 @@ static char * _errorlog_dll = 0;
 static void parse_scanner_output (std::string msg, size_t /*len*/)
 {
        if (!_errorlog_fd && !_errorlog_dll) {
-               errormsg << "VST scanner: " << msg;
+               PBD::error << "VST scanner: " << msg;
                return;
        }
 
        if (!_errorlog_fd) {
                if (!(_errorlog_fd = fopen(vstfx_errorfile_path(_errorlog_dll, 0).c_str(), "w"))) {
                        if (!(_errorlog_fd = fopen(vstfx_errorfile_path(_errorlog_dll, 1).c_str(), "w"))) {
-                               errormsg << "Cannot create plugin error-log for plugin " << _errorlog_dll;
+                               PBD::error << "Cannot create plugin error-log for plugin " << _errorlog_dll;
                                free(_errorlog_dll);
                                _errorlog_dll = NULL;
                        }
@@ -857,7 +887,7 @@ static void parse_scanner_output (std::string msg, size_t /*len*/)
        if (_errorlog_fd) {
                fprintf (_errorlog_fd, "%s\n", msg.c_str());
        } else {
-               errormsg << "VST scanner: " << msg;
+               PBD::error << "VST scanner: " << msg;
        }
 }
 
@@ -917,7 +947,7 @@ vstfx_get_info (const char* dllpath, enum ARDOUR::PluginType type, enum VSTScanM
                PBD::ScopedConnectionList cons;
                scanner.ReadStdout.connect_same_thread (cons, boost::bind (&parse_scanner_output, _1 ,_2));
                if (scanner.start (2 /* send stderr&stdout via signal */)) {
-                       errormsg << "Cannot launch VST scanner app '" << scanner_bin_path << "': "<< strerror(errno) << endmsg;
+                       PBD::error << "Cannot launch VST scanner app '" << scanner_bin_path << "': "<< strerror(errno) << endmsg;
                        close_error_log();
                        return infos;
                } else {
@@ -983,7 +1013,7 @@ vstfx_get_info (const char* dllpath, enum ARDOUR::PluginType type, enum VSTScanM
        /* crate cache/whitelist */
        infofile = vstfx_infofile_for_write (dllpath);
        if (!infofile) {
-               warningmsg << "Cannot cache VST information for " << dllpath << ": cannot create new FST info file." << endmsg;
+               PBD::warning << "Cannot cache VST information for " << dllpath << ": cannot create new FST info file." << endmsg;
                return infos;
        } else {
                vstfx_write_info_file (infofile, infos);
@@ -1011,7 +1041,7 @@ get_personal_vst_blacklist_dir() {
        /* if the directory doesn't exist, try to create it */
        if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
                if (g_mkdir (dir.c_str (), 0700)) {
-                       errormsg << "Cannot create VST blacklist folder '" << dir << "'" << endmsg;
+                       PBD::error << "Cannot create VST blacklist folder '" << dir << "'" << endmsg;
                        //exit(1);
                }
        }
@@ -1024,7 +1054,7 @@ get_personal_vst_info_cache_dir() {
        /* if the directory doesn't exist, try to create it */
        if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
                if (g_mkdir (dir.c_str (), 0700)) {
-                       errormsg << "Cannot create VST info folder '" << dir << "'" << endmsg;
+                       PBD::error << "Cannot create VST info folder '" << dir << "'" << endmsg;
                        //exit(1);
                }
        }