Revert "case insensitive ".dll" for VST plugins - fixes #6285"
[ardour.git] / libs / ardour / vst_info_file.cc
index 90076815b37a75ca36585e7d3fbee7e3712ae5e1..2d68421103d0d14930f8ff9d5925ba333d39540f 100644 (file)
@@ -34,7 +34,6 @@
 #include <stddef.h>
 #include <stdio.h>
 #include <string.h>
-#include <libgen.h>
 
 #include <glib.h>
 #include <glib/gstdio.h>
@@ -43,8 +42,9 @@
 #include "pbd/error.h"
 
 #ifndef VST_SCANNER_APP
-#include "pbd/system_exec.h"
 #include "ardour/plugin_manager.h" // scanner_bin_path
+#include "ardour/rc_configuration.h"
+#include "ardour/system_exec.h"
 #endif
 
 #include "ardour/filesystem_paths.h"
@@ -53,7 +53,7 @@
 #include "ardour/vst_info_file.h"
 
 #define MAX_STRING_LEN 256
-#define PLUGIN_SCAN_TIMEOUT (600) // in deciseconds
+#define PLUGIN_SCAN_TIMEOUT (Config->get_vst_scan_timeout()) // in deciseconds
 
 
 /* CACHE FILE PATHS */
@@ -96,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));
        }
@@ -109,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
@@ -118,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 *** */
@@ -217,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;
        }
@@ -373,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 */
@@ -476,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
@@ -527,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;
                }
        }
@@ -545,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;
                }
@@ -609,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);
 
@@ -699,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 );
@@ -906,7 +943,7 @@ vstfx_get_info (const char* dllpath, enum ARDOUR::PluginType type, enum VSTScanM
                argp[2] = 0;
 
                set_error_log(dllpath);
-               PBD::SystemExec scanner (scanner_bin_path, argp);
+               ARDOUR::SystemExec scanner (scanner_bin_path, argp);
                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 */)) {
@@ -915,7 +952,15 @@ vstfx_get_info (const char* dllpath, enum ARDOUR::PluginType type, enum VSTScanM
                        return infos;
                } else {
                        int timeout = PLUGIN_SCAN_TIMEOUT;
-                       while (scanner.is_running() && --timeout) {
+                       bool no_timeout = (timeout <= 0);
+                       ARDOUR::PluginScanTimeout(timeout);
+                       while (scanner.is_running() && (no_timeout || timeout > 0)) {
+                               if (!no_timeout && !ARDOUR::PluginManager::instance().no_timeout()) {
+                                       if (timeout%5 == 0) {
+                                               ARDOUR::PluginScanTimeout(timeout);
+                                       }
+                                       --timeout;
+                               }
                                ARDOUR::GUIIdle();
                                Glib::usleep (100000);