Revert "case insensitive ".dll" for VST plugins - fixes #6285"
[ardour.git] / libs / ardour / vst_info_file.cc
index 34e1b0ed0c0b0707fcb2bc721596cd8b0ae5342b..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 */
 #define EXT_ERRORFILE ".err"
 #define EXT_INFOFILE  ".fsi"
 
+#ifdef PLATFORM_WINDOWS
+#define PFX_DOTFILE   ""
+#else
 #define PFX_DOTFILE   "."
+#endif
 
 
 using namespace std;
+#ifndef VST_SCANNER_APP
+namespace ARDOUR {
+#endif
 
 /* prototypes */
 #ifdef WINDOWS_VST_SUPPORT
@@ -89,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));
        }
@@ -102,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
@@ -111,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 *** */
@@ -210,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;
        }
@@ -244,7 +268,7 @@ vstfx_load_info_file (FILE* fp, vector<VSTInfo*> *infos)
                } else {
                        int plugin_cnt = 0;
                        vstfx_free_info(info);
-                       if (read_int (fp, &plugin_cnt)) {
+                       if (!read_int (fp, &plugin_cnt)) {
                                for (int i = 0; i < plugin_cnt; i++) {
                                        if ((info = (VSTInfo*) calloc (1, sizeof (VSTInfo))) == 0) {
                                                vstfx_clear_info_list(infos);
@@ -366,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 */
@@ -469,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
@@ -520,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;
                }
        }
@@ -538,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;
                }
@@ -555,10 +588,17 @@ static intptr_t
 simple_master_callback (AEffect *, int32_t opcode, int32_t, intptr_t, void *ptr, float)
 {
        const char* vstfx_can_do_strings[] = {
+               "supplyIdle",
+               "sendVstTimeInfo",
+               "sendVstEvents",
+               "sendVstMidiEvent",
+               "receiveVstEvents",
+               "receiveVstMidiEvent",
                "supportShell",
-               "shellCategory"
+               "shellCategory",
+               "shellCategorycurID"
        };
-       const int vstfx_can_do_string_count = 2;
+       const int vstfx_can_do_string_count = 9;
 
        if (opcode == audioMasterVersion) {
                return 2400;
@@ -595,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);
 
@@ -685,20 +737,19 @@ 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 );
 
                switch(type) {
 #ifdef WINDOWS_VST_SUPPORT
-                       case 1: fst_close(vstfx); break;
+                       case ARDOUR::Windows_VST: fst_close(vstfx); break;
 #endif
 #ifdef LXVST_SUPPORT
-                       case 2: vstfx_close (vstfx); break;
+                       case ARDOUR::LXVST: vstfx_close (vstfx); break;
 #endif
                        default: assert(0); break;
                }
@@ -733,6 +784,16 @@ vstfx_info_from_plugin (const char *dllpath, VSTState* vstfx, vector<VSTInfo *>
                                }
                        }
                }
+       } else {
+               switch(type) {
+#ifdef WINDOWS_VST_SUPPORT
+                       case ARDOUR::Windows_VST: fst_close(vstfx); break;
+#endif
+#ifdef LXVST_SUPPORT
+                       case ARDOUR::LXVST: vstfx_close (vstfx); break;
+#endif
+                       default: assert(0); break;
+               }
        }
 #endif
 }
@@ -765,7 +826,6 @@ vstfx_instantiate_and_get_info_lx (
 
        vstfx_info_from_plugin(dllpath, vstfx, infos, ARDOUR::LXVST);
 
-       vstfx_close (vstfx);
        vstfx_unload (h);
        return true;
 }
@@ -795,8 +855,6 @@ vstfx_instantiate_and_get_info_fst (
 
        vstfx_info_from_plugin(dllpath, vstfx, infos, ARDOUR::Windows_VST);
 
-       fst_close(vstfx);
-       //fst_unload(&h); // XXX -> fst_close()
        return true;
 }
 #endif
@@ -885,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 */)) {
@@ -894,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);
 
@@ -1010,3 +1076,7 @@ vstfx_get_info_fst (char* dllpath, enum VSTScanMode mode)
        return vstfx_get_info(dllpath, ARDOUR::Windows_VST, mode);
 }
 #endif
+
+#ifndef VST_SCANNER_APP
+} // namespace
+#endif