2 Copyright (C) 2012-2014 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file libs/ardour/vst_info_file.cc
21 * @brief Code to manage info files containing cached information about a plugin.
22 * e.g. its name, creator etc.
28 #include <sys/types.h>
39 #include <glib/gstdio.h>
42 #include "pbd/error.h"
44 #ifndef VST_SCANNER_APP
45 #include "ardour/plugin_manager.h" // scanner_bin_path
46 #include "ardour/rc_configuration.h"
47 #include "ardour/system_exec.h"
50 #include "ardour/filesystem_paths.h"
51 #include "ardour/linux_vst_support.h"
52 #include "ardour/plugin_types.h"
53 #include "ardour/vst_info_file.h"
55 #define MAX_STRING_LEN 256
56 #define PLUGIN_SCAN_TIMEOUT (Config->get_vst_scan_timeout()) // in deciseconds
58 #ifdef PLATFORM_WINDOWS
59 #define PFX_DOTFILE ""
61 #define PFX_DOTFILE "."
66 #ifndef VST_SCANNER_APP
71 #ifdef WINDOWS_VST_SUPPORT
74 vstfx_instantiate_and_get_info_fst (const char* dllpath, vector<VSTInfo*> *infos, int uniqueID);
78 static bool vstfx_instantiate_and_get_info_lx (const char* dllpath, vector<VSTInfo*> *infos, int uniqueID);
81 /* ID for shell plugins */
82 static int vstfx_current_loading_id = 0;
86 /* *** CACHE FILE PATHS *** */
89 vstfx_cache_file (const char* dllpath, int personal, const char *ext)
93 dir = get_personal_vst_info_cache_dir();
94 // TODO prefix path relative to scan-root to avoid duplicates
96 dir = Glib::path_get_dirname (std::string(dllpath));
100 s << PFX_DOTFILE << Glib::path_get_basename (dllpath) << ext;
101 return Glib::build_filename (dir, s.str ());
105 vstfx_blacklist_path (const char* dllpath, int personal)
109 dir = get_personal_vst_blacklist_dir();
111 dir = Glib::path_get_dirname (std::string(dllpath));
115 s << PFX_DOTFILE << Glib::path_get_basename (dllpath) << VST_EXT_BLACKLIST;
116 return Glib::build_filename (dir, s.str ());
120 vstfx_infofile_path (const char* dllpath, int personal)
122 return vstfx_cache_file(dllpath, personal, VST_EXT_INFOFILE);
125 #ifndef VST_SCANNER_APP
127 vstfx_errorfile_path (const char* dllpath, int personal)
129 return vstfx_cache_file(dllpath, personal, VST_EXT_ERRORFILE);
134 /* *** MEMORY MANAGEMENT *** */
136 /** cleanup single allocated VSTInfo */
138 vstfx_free_info (VSTInfo *info)
140 for (int i = 0; i < info->numParams; i++) {
141 free (info->ParamNames[i]);
142 free (info->ParamLabels[i]);
146 free (info->creator);
147 free (info->Category);
148 free (info->ParamNames);
149 free (info->ParamLabels);
155 vstfx_clear_info_list (vector<VSTInfo *> *infos)
157 for (vector<VSTInfo *>::iterator i = infos->begin(); i != infos->end(); ++i) {
165 /* *** CACHE FILE I/O *** */
167 /** Helper function to read a line from the cache file
168 * @return newly allocated string of NULL
171 read_string (FILE *fp)
173 char buf[MAX_STRING_LEN];
175 if (!fgets (buf, MAX_STRING_LEN, fp)) {
179 if (strlen(buf) < MAX_STRING_LEN) {
181 buf[strlen(buf)-1] = 0;
189 /** Read an integer value from a line in fp into n,
190 * @return true on failure, false on success.
193 read_int (FILE* fp, int* n)
195 char buf[MAX_STRING_LEN];
197 char* p = fgets (buf, MAX_STRING_LEN, fp);
202 return (sscanf (p, "%d", n) != 1);
205 /** parse a plugin-block from the cache info file */
207 vstfx_load_info_block(FILE* fp, VSTInfo *info)
209 if ((info->name = read_string(fp)) == 0) return false;
210 if ((info->creator = read_string(fp)) == 0) return false;
211 if (read_int (fp, &info->UniqueID)) return false;
212 if ((info->Category = read_string(fp)) == 0) return false;
213 if (read_int (fp, &info->numInputs)) return false;
214 if (read_int (fp, &info->numOutputs)) return false;
215 if (read_int (fp, &info->numParams)) return false;
216 if (read_int (fp, &info->wantMidi)) return false;
217 if (read_int (fp, &info->hasEditor)) return false;
218 if (read_int (fp, &info->canProcessReplacing)) return false;
220 /* backwards compatibility with old .fsi files */
221 if (info->wantMidi == -1) {
225 if ((info->numParams) == 0) {
226 info->ParamNames = NULL;
227 info->ParamLabels = NULL;
231 if ((info->ParamNames = (char **) malloc(sizeof(char*)*info->numParams)) == 0) {
235 for (int i = 0; i < info->numParams; ++i) {
236 if ((info->ParamNames[i] = read_string(fp)) == 0) return false;
239 if ((info->ParamLabels = (char **) malloc(sizeof(char*)*info->numParams)) == 0) {
243 for (int i = 0; i < info->numParams; ++i) {
244 if ((info->ParamLabels[i] = read_string(fp)) == 0) {
251 /** parse all blocks in a cache info file */
253 vstfx_load_info_file (FILE* fp, vector<VSTInfo*> *infos)
256 if ((info = (VSTInfo*) calloc (1, sizeof (VSTInfo))) == 0) {
259 if (vstfx_load_info_block(fp, info)) {
260 if (strncmp (info->Category, "Shell", 5)) {
261 infos->push_back(info);
264 vstfx_free_info(info);
265 if (!read_int (fp, &plugin_cnt)) {
266 for (int i = 0; i < plugin_cnt; i++) {
267 if ((info = (VSTInfo*) calloc (1, sizeof (VSTInfo))) == 0) {
268 vstfx_clear_info_list(infos);
271 if (vstfx_load_info_block(fp, info)) {
272 infos->push_back(info);
274 vstfx_free_info(info);
275 vstfx_clear_info_list(infos);
280 return false; /* Bad file */
285 vstfx_free_info(info);
286 vstfx_clear_info_list(infos);
291 vstfx_write_info_block (FILE* fp, VSTInfo *info)
296 fprintf (fp, "%s\n", info->name);
297 fprintf (fp, "%s\n", info->creator);
298 fprintf (fp, "%d\n", info->UniqueID);
299 fprintf (fp, "%s\n", info->Category);
300 fprintf (fp, "%d\n", info->numInputs);
301 fprintf (fp, "%d\n", info->numOutputs);
302 fprintf (fp, "%d\n", info->numParams);
303 fprintf (fp, "%d\n", info->wantMidi);
304 fprintf (fp, "%d\n", info->hasEditor);
305 fprintf (fp, "%d\n", info->canProcessReplacing);
307 for (int i = 0; i < info->numParams; i++) {
308 fprintf (fp, "%s\n", info->ParamNames[i]);
311 for (int i = 0; i < info->numParams; i++) {
312 fprintf (fp, "%s\n", info->ParamLabels[i]);
317 vstfx_write_info_file (FILE* fp, vector<VSTInfo *> *infos)
322 if (infos->size() > 1) {
323 vector<VSTInfo *>::iterator x = infos->begin();
324 /* write out the shell info first along with count of the number of
325 * plugins contained in this shell
327 vstfx_write_info_block(fp, *x);
328 fprintf( fp, "%d\n", (int)infos->size() - 1 );
330 /* Now write out the info for each plugin */
331 for (; x != infos->end(); ++x) {
332 vstfx_write_info_block(fp, *x);
334 } else if (infos->size() == 1) {
335 vstfx_write_info_block(fp, infos->front());
337 PBD::error << "Zero plugins in VST." << endmsg; // XXX here? rather make this impossible before if it ain't already.
342 /* *** CACHE AND BLACKLIST MANAGEMENT *** */
344 /* return true if plugin is blacklisted or has an invalid file extension */
346 vstfx_blacklist_stat (const char *dllpath, int personal)
348 const size_t slen = strlen (dllpath);
350 (slen <= 3 || g_ascii_strcasecmp (&dllpath[slen-3], ".so"))
352 (slen <= 4 || g_ascii_strcasecmp (&dllpath[slen-4], ".dll"))
357 string const path = vstfx_blacklist_path (dllpath, personal);
359 if (Glib::file_test (path, Glib::FileTest (Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR))) {
363 if (stat (dllpath, &dllstat) == 0 && stat (path.c_str(), &fsbstat) == 0) {
364 if (dllstat.st_mtime > fsbstat.st_mtime) {
365 /* plugin is newer than blacklist file */
369 /* stat failed or plugin is older than blacklist file */
372 /* blacklist file does not exist */
376 /* return true if plugin is blacklisted, checks both personal
377 * and global folder */
379 vstfx_check_blacklist (const char *dllpath)
381 if (vstfx_blacklist_stat(dllpath, 0)) return true;
382 if (vstfx_blacklist_stat(dllpath, 1)) return true;
386 /* create blacklist file, preferably in same folder as the
387 * plugin, fall back to personal folder in $HOME
390 vstfx_blacklist_file (const char *dllpath)
393 if ((f = fopen (vstfx_blacklist_path (dllpath, 0).c_str(), "wb"))) {
395 PBD::info << "Blacklisted VST: '" << vstfx_blacklist_path (dllpath, 0) << "'" << endmsg;
400 PBD::info << "Blacklisted VST: '" << vstfx_blacklist_path (dllpath, 1) << "'" << endmsg;
402 return fopen (vstfx_blacklist_path (dllpath, 1).c_str(), "wb");
405 /** mark plugin as blacklisted */
407 vstfx_blacklist (const char *dllpath)
409 FILE *f = vstfx_blacklist_file(dllpath);
417 /** mark plugin as not blacklisted */
419 vstfx_un_blacklist (const char *dllpath)
421 ::g_unlink(vstfx_blacklist_path (dllpath, 0).c_str());
422 ::g_unlink(vstfx_blacklist_path (dllpath, 1).c_str());
425 /** remove info file from cache */
427 vstfx_remove_infofile (const char *dllpath)
429 ::g_unlink(vstfx_infofile_path (dllpath, 0).c_str());
430 ::g_unlink(vstfx_infofile_path (dllpath, 1).c_str());
433 /** helper function, check if cache is newer than plugin
434 * @return path to cache file */
436 vstfx_infofile_stat (const char *dllpath, struct stat* statbuf, int personal)
438 const size_t slen = strlen (dllpath);
440 (slen <= 3 || g_ascii_strcasecmp (&dllpath[slen-3], ".so"))
442 (slen <= 4 || g_ascii_strcasecmp (&dllpath[slen-4], ".dll"))
447 string const path = vstfx_infofile_path (dllpath, personal);
449 if (Glib::file_test (path, Glib::FileTest (Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR))) {
453 if (stat (dllpath, &dllstat) == 0) {
454 if (stat (path.c_str(), statbuf) == 0) {
455 if (dllstat.st_mtime <= statbuf->st_mtime) {
456 /* plugin is older than info file */
457 return strdup (path.c_str ());
466 /** cache file for given plugin
467 * @return FILE of the .fsi cache if found and up-to-date*/
469 vstfx_infofile_for_read (const char* dllpath)
471 struct stat own_statbuf;
472 struct stat sys_statbuf;
475 char* own_info = vstfx_infofile_stat (dllpath, &own_statbuf, 1);
476 char* sys_info = vstfx_infofile_stat (dllpath, &sys_statbuf, 0);
480 if (own_statbuf.st_mtime <= sys_statbuf.st_mtime) {
481 /* system info file is newer, use it */
482 rv = g_fopen (sys_info, "rb");
485 rv = g_fopen (own_info, "rb");
487 } else if (sys_info) {
488 rv = g_fopen (sys_info, "rb");
496 /** helper function for \ref vstfx_infofile_for_write
497 * abstract global and personal cache folders
500 vstfx_infofile_create (const char* dllpath, int personal)
502 const size_t slen = strlen (dllpath);
504 (slen <= 3 || g_ascii_strcasecmp (&dllpath[slen-3], ".so"))
506 (slen <= 4 || g_ascii_strcasecmp (&dllpath[slen-4], ".dll"))
511 string const path = vstfx_infofile_path (dllpath, personal);
513 PBD::info << "Creating VST cache file " << path << endmsg;
515 return fopen (path.c_str(), "wb");
518 /** newly created cache file for given plugin
519 * @return FILE for the .fsi cache, NULL if neither personal,
520 * nor global cache folder is writable */
522 vstfx_infofile_for_write (const char* dllpath)
526 if ((f = vstfx_infofile_create (dllpath, 0)) == 0) {
527 f = vstfx_infofile_create (dllpath, 1);
533 /** check if cache-file exists, is up-to-date and parse cache file
534 * @param infos [return] loaded plugin info
535 * @return true if .fsi cache was read successfully, false otherwise
538 vstfx_get_info_from_file(const char* dllpath, vector<VSTInfo*> *infos)
542 if ((infofile = vstfx_infofile_for_read (dllpath)) != 0) {
543 rv = vstfx_load_info_file(infofile, infos);
546 PBD::warning << "Cannot get VST information form " << dllpath << ": info file load failed." << endmsg;
554 /* *** VST system-under-test methods *** */
557 bool vstfx_midi_input (VSTState* vstfx)
559 AEffect* plugin = vstfx->plugin;
561 int const vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, 0, 0.0f);
563 if (vst_version >= 2) {
564 /* should we send it VST events (i.e. MIDI) */
566 if ((plugin->flags & effFlagsIsSynth) || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("receiveVstEvents"), 0.0f) > 0)) {
575 bool vstfx_midi_output (VSTState* vstfx)
577 AEffect* plugin = vstfx->plugin;
579 int const vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, 0, 0.0f);
581 if (vst_version >= 2) {
582 /* should we send it VST events (i.e. MIDI) */
584 if ( (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("sendVstEvents"), 0.0f) > 0)
585 || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("sendVstMidiEvent"), 0.0f) > 0)
594 /** simple 'dummy' audiomaster callback to instantiate the plugin
595 * and query information
598 simple_master_callback (AEffect *, int32_t opcode, int32_t, intptr_t, void *ptr, float)
600 const char* vstfx_can_do_strings[] = {
606 "receiveVstMidiEvent",
611 const int vstfx_can_do_string_count = 9;
613 if (opcode == audioMasterVersion) {
616 else if (opcode == audioMasterCanDo) {
617 for (int i = 0; i < vstfx_can_do_string_count; i++) {
618 if (! strcmp(vstfx_can_do_strings[i], (const char*)ptr)) {
624 else if (opcode == audioMasterCurrentId) {
625 return vstfx_current_loading_id;
633 /** main plugin query and test function */
635 vstfx_parse_vst_state (VSTState* vstfx)
639 VSTInfo* info = (VSTInfo*) malloc (sizeof (VSTInfo));
644 /*We need to init the creator because some plugins
645 fail to implement getVendorString, and so won't stuff the
646 string with any name*/
648 char creator[65] = "Unknown";
651 AEffect* plugin = vstfx->plugin;
654 plugin->dispatcher (plugin, effGetEffectName, 0, 0, name, 0);
656 if (strlen(name) == 0) {
657 plugin->dispatcher (plugin, effGetProductString, 0, 0, name, 0);
660 if (strlen(name) == 0) {
661 info->name = strdup (vstfx->handle->name);
663 info->name = strdup (name);
666 /*If the plugin doesn't bother to implement GetVendorString we will
667 have pre-stuffed the string with 'Unknown' */
669 plugin->dispatcher (plugin, effGetVendorString, 0, 0, creator, 0);
671 /*Some plugins DO implement GetVendorString, but DON'T put a name in it
672 so if its just a zero length string we replace it with 'Unknown' */
674 if (strlen(creator) == 0) {
675 info->creator = strdup ("Unknown");
677 info->creator = strdup (creator);
681 switch (plugin->dispatcher (plugin, effGetPlugCategory, 0, 0, 0, 0))
683 case kPlugCategEffect: info->Category = strdup ("Effect"); break;
684 case kPlugCategSynth: info->Category = strdup ("Synth"); break;
685 case kPlugCategAnalysis: info->Category = strdup ("Anaylsis"); break;
686 case kPlugCategMastering: info->Category = strdup ("Mastering"); break;
687 case kPlugCategSpacializer: info->Category = strdup ("Spacializer"); break;
688 case kPlugCategRoomFx: info->Category = strdup ("RoomFx"); break;
689 case kPlugSurroundFx: info->Category = strdup ("SurroundFx"); break;
690 case kPlugCategRestoration: info->Category = strdup ("Restoration"); break;
691 case kPlugCategOfflineProcess: info->Category = strdup ("Offline"); break;
692 case kPlugCategShell: info->Category = strdup ("Shell"); break;
693 case kPlugCategGenerator: info->Category = strdup ("Generator"); break;
694 default: info->Category = strdup ("Unknown"); break;
697 info->UniqueID = plugin->uniqueID;
699 info->numInputs = plugin->numInputs;
700 info->numOutputs = plugin->numOutputs;
701 info->numParams = plugin->numParams;
702 info->wantMidi = (vstfx_midi_input(vstfx) ? 1 : 0) | (vstfx_midi_output(vstfx) ? 2 : 0);
703 info->hasEditor = plugin->flags & effFlagsHasEditor ? true : false;
704 info->canProcessReplacing = plugin->flags & effFlagsCanReplacing ? true : false;
705 info->ParamNames = (char **) malloc(sizeof(char*)*info->numParams);
706 info->ParamLabels = (char **) malloc(sizeof(char*)*info->numParams);
708 for (int i = 0; i < info->numParams; ++i) {
712 /* Not all plugins give parameters labels as well as names */
714 strcpy (name, "No Name");
715 strcpy (label, "No Label");
717 plugin->dispatcher (plugin, effGetParamName, i, 0, name, 0);
718 info->ParamNames[i] = strdup(name);
720 //NOTE: 'effGetParamLabel' is no longer defined in vestige headers
721 //plugin->dispatcher (plugin, effGetParamLabel, i, 0, label, 0);
722 info->ParamLabels[i] = strdup(label);
727 /** wrapper around \ref vstfx_parse_vst_state,
728 * iterate over plugins in shell, translate VST-info into ardour VSTState
731 vstfx_info_from_plugin (const char *dllpath, VSTState* vstfx, vector<VSTInfo *> *infos, enum ARDOUR::PluginType type)
736 if (!(info = vstfx_parse_vst_state(vstfx))) {
740 infos->push_back(info);
741 #if 1 // shell-plugin support
742 /* If this plugin is a Shell and we are not already inside a shell plugin
743 * read the info for all of the plugins contained in this shell.
745 if (!strncmp (info->Category, "Shell", 5)
746 && vstfx->handle->plugincnt == 1) {
748 vector< pair<int, string> > ids;
749 AEffect *plugin = vstfx->plugin;
752 char name[65] = "Unknown";
753 id = plugin->dispatcher (plugin, effShellGetNextPlugin, 0, 0, name, 0);
754 ids.push_back(std::make_pair(id, name));
758 #ifdef WINDOWS_VST_SUPPORT
759 case ARDOUR::Windows_VST: fst_close(vstfx); break;
762 case ARDOUR::LXVST: vstfx_close (vstfx); break;
764 default: assert(0); break;
767 for (vector< pair<int, string> >::iterator x = ids.begin(); x != ids.end(); ++x) {
769 if (id == 0) continue;
770 /* recurse vstfx_get_info() */
774 #ifdef WINDOWS_VST_SUPPORT
775 case ARDOUR::Windows_VST: ok = vstfx_instantiate_and_get_info_fst(dllpath, infos, id); break;
778 case ARDOUR::LXVST: ok = vstfx_instantiate_and_get_info_lx(dllpath, infos, id); break;
783 // One shell (some?, all?) does not report the actual plugin name
784 // even after the shelled plugin has been instantiated.
785 // Replace the name of the shell with the real name.
786 info = infos->back();
789 if ((*x).second.length() == 0) {
790 info->name = strdup("Unknown");
793 info->name = strdup ((*x).second.c_str());
799 #ifdef WINDOWS_VST_SUPPORT
800 case ARDOUR::Windows_VST: fst_close(vstfx); break;
803 case ARDOUR::LXVST: vstfx_close (vstfx); break;
805 default: assert(0); break;
813 /* *** TOP-LEVEL PLUGIN INSTANTIATION FUNCTIONS *** */
817 vstfx_instantiate_and_get_info_lx (
818 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
822 if (!(h = vstfx_load(dllpath))) {
823 PBD::warning << "Cannot get LinuxVST information from " << dllpath << ": load failed." << endmsg;
827 vstfx_current_loading_id = uniqueID;
829 if (!(vstfx = vstfx_instantiate(h, simple_master_callback, 0))) {
831 PBD::warning << "Cannot get LinuxVST information from " << dllpath << ": instantiation failed." << endmsg;
835 vstfx_current_loading_id = 0;
837 vstfx_info_from_plugin(dllpath, vstfx, infos, ARDOUR::LXVST);
844 #ifdef WINDOWS_VST_SUPPORT
846 vstfx_instantiate_and_get_info_fst (
847 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
851 if(!(h = fst_load(dllpath))) {
852 PBD::warning << "Cannot get Windows VST information from " << dllpath << ": load failed." << endmsg;
856 vstfx_current_loading_id = uniqueID;
858 if(!(vstfx = fst_instantiate(h, simple_master_callback, 0))) {
860 vstfx_current_loading_id = 0;
861 PBD::warning << "Cannot get Windows VST information from " << dllpath << ": instantiation failed." << endmsg;
864 vstfx_current_loading_id = 0;
866 vstfx_info_from_plugin(dllpath, vstfx, infos, ARDOUR::Windows_VST);
874 /* *** ERROR LOGGING *** */
875 #ifndef VST_SCANNER_APP
877 static FILE * _errorlog_fd = 0;
878 static char * _errorlog_dll = 0;
880 static void parse_scanner_output (std::string msg, size_t /*len*/)
882 if (!_errorlog_fd && !_errorlog_dll) {
883 PBD::error << "VST scanner: " << msg;
888 if (!(_errorlog_fd = fopen(vstfx_errorfile_path(_errorlog_dll, 0).c_str(), "w"))) {
889 if (!(_errorlog_fd = fopen(vstfx_errorfile_path(_errorlog_dll, 1).c_str(), "w"))) {
890 PBD::error << "Cannot create plugin error-log for plugin " << _errorlog_dll;
892 _errorlog_dll = NULL;
898 fprintf (_errorlog_fd, "%s\n", msg.c_str());
900 PBD::error << "VST scanner: " << msg;
905 set_error_log (const char* dllpath) {
906 assert(!_errorlog_fd);
907 assert(!_errorlog_dll);
908 _errorlog_dll = strdup(dllpath);
914 fclose(_errorlog_fd);
924 /* *** THE MAIN FUNCTION THAT USES ALL OF THE ABOVE :) *** */
926 static vector<VSTInfo *> *
927 vstfx_get_info (const char* dllpath, enum ARDOUR::PluginType type, enum VSTScanMode mode)
930 vector<VSTInfo*> *infos = new vector<VSTInfo*>;
932 if (vstfx_check_blacklist(dllpath)) {
936 if (vstfx_get_info_from_file(dllpath, infos)) {
940 #ifndef VST_SCANNER_APP
941 std::string scanner_bin_path = ARDOUR::PluginManager::scanner_bin_path;
943 if (mode == VST_SCAN_CACHE_ONLY) {
944 /* never scan explicitly, use cache only */
947 else if (mode == VST_SCAN_USE_APP && scanner_bin_path != "") {
948 /* use external scanner app */
950 char **argp= (char**) calloc(3,sizeof(char*));
951 argp[0] = strdup(scanner_bin_path.c_str());
952 argp[1] = strdup(dllpath);
955 set_error_log(dllpath);
956 ARDOUR::SystemExec scanner (scanner_bin_path, argp);
957 PBD::ScopedConnectionList cons;
958 scanner.ReadStdout.connect_same_thread (cons, boost::bind (&parse_scanner_output, _1 ,_2));
959 if (scanner.start (2 /* send stderr&stdout via signal */)) {
960 PBD::error << "Cannot launch VST scanner app '" << scanner_bin_path << "': "<< strerror(errno) << endmsg;
964 int timeout = PLUGIN_SCAN_TIMEOUT;
965 bool no_timeout = (timeout <= 0);
966 ARDOUR::PluginScanTimeout(timeout);
967 while (scanner.is_running() && (no_timeout || timeout > 0)) {
968 if (!no_timeout && !ARDOUR::PluginManager::instance().no_timeout()) {
969 if (timeout%5 == 0) {
970 ARDOUR::PluginScanTimeout(timeout);
975 Glib::usleep (100000);
977 if (ARDOUR::PluginManager::instance().cancelled()) {
978 // remove info file (might be incomplete)
979 vstfx_remove_infofile(dllpath);
980 // remove temporary blacklist file (scan incomplete)
981 vstfx_un_blacklist(dllpath);
990 /* re-read index (generated by external scanner) */
991 vstfx_clear_info_list(infos);
992 if (!vstfx_check_blacklist(dllpath)) {
993 vstfx_get_info_from_file(dllpath, infos);
997 /* else .. instantiate and check in in ardour process itself */
999 (void) mode; // unused parameter
1003 /* blacklist in case instantiation fails */
1004 vstfx_blacklist(dllpath);
1007 #ifdef WINDOWS_VST_SUPPORT
1008 case ARDOUR::Windows_VST: ok = vstfx_instantiate_and_get_info_fst(dllpath, infos, 0); break;
1010 #ifdef LXVST_SUPPORT
1011 case ARDOUR::LXVST: ok = vstfx_instantiate_and_get_info_lx(dllpath, infos, 0); break;
1013 default: ok = false;
1020 /* remove from blacklist */
1021 vstfx_un_blacklist(dllpath);
1023 /* crate cache/whitelist */
1024 infofile = vstfx_infofile_for_write (dllpath);
1026 PBD::warning << "Cannot cache VST information for " << dllpath << ": cannot create new FST info file." << endmsg;
1029 vstfx_write_info_file (infofile, infos);
1037 /* *** public API *** */
1040 vstfx_free_info_list (vector<VSTInfo *> *infos)
1042 for (vector<VSTInfo *>::iterator i = infos->begin(); i != infos->end(); ++i) {
1043 vstfx_free_info(*i);
1049 get_personal_vst_blacklist_dir() {
1050 string dir = Glib::build_filename (ARDOUR::user_cache_directory(), "fst_blacklist");
1051 /* if the directory doesn't exist, try to create it */
1052 if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
1053 if (g_mkdir (dir.c_str (), 0700)) {
1054 PBD::error << "Cannot create VST blacklist folder '" << dir << "'" << endmsg;
1062 get_personal_vst_info_cache_dir() {
1063 string dir = Glib::build_filename (ARDOUR::user_cache_directory(), "fst_info");
1064 /* if the directory doesn't exist, try to create it */
1065 if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
1066 if (g_mkdir (dir.c_str (), 0700)) {
1067 PBD::error << "Cannot create VST info folder '" << dir << "'" << endmsg;
1074 #ifdef LXVST_SUPPORT
1076 vstfx_get_info_lx (char* dllpath, enum VSTScanMode mode)
1078 return vstfx_get_info(dllpath, ARDOUR::LXVST, mode);
1082 #ifdef WINDOWS_VST_SUPPORT
1084 vstfx_get_info_fst (char* dllpath, enum VSTScanMode mode)
1086 return vstfx_get_info(dllpath, ARDOUR::Windows_VST, mode);
1090 #ifndef VST_SCANNER_APP