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
59 /* CACHE FILE PATHS */
60 #define EXT_BLACKLIST ".fsb"
61 #define EXT_ERRORFILE ".err"
62 #define EXT_INFOFILE ".fsi"
64 #ifdef PLATFORM_WINDOWS
65 #define PFX_DOTFILE ""
67 #define PFX_DOTFILE "."
72 #ifndef VST_SCANNER_APP
77 #ifdef WINDOWS_VST_SUPPORT
80 vstfx_instantiate_and_get_info_fst (const char* dllpath, vector<VSTInfo*> *infos, int uniqueID);
84 static bool vstfx_instantiate_and_get_info_lx (const char* dllpath, vector<VSTInfo*> *infos, int uniqueID);
87 /* ID for shell plugins */
88 static int vstfx_current_loading_id = 0;
92 /* *** CACHE FILE PATHS *** */
95 vstfx_cache_file (const char* dllpath, int personal, const char *ext)
99 dir = get_personal_vst_info_cache_dir();
100 // TODO prefix path relative to scan-root to avoid duplicates
102 dir = Glib::path_get_dirname (std::string(dllpath));
106 s << PFX_DOTFILE << Glib::path_get_basename (dllpath) << ext;
107 return Glib::build_filename (dir, s.str ());
111 vstfx_blacklist_path (const char* dllpath, int personal)
115 dir = get_personal_vst_blacklist_dir();
117 dir = Glib::path_get_dirname (std::string(dllpath));
121 s << PFX_DOTFILE << Glib::path_get_basename (dllpath) << EXT_BLACKLIST;
122 return Glib::build_filename (dir, s.str ());
126 vstfx_infofile_path (const char* dllpath, int personal)
128 return vstfx_cache_file(dllpath, personal, EXT_INFOFILE);
131 #ifndef VST_SCANNER_APP
133 vstfx_errorfile_path (const char* dllpath, int personal)
135 return vstfx_cache_file(dllpath, personal, EXT_ERRORFILE);
140 /* *** MEMORY MANAGEMENT *** */
142 /** cleanup single allocated VSTInfo */
144 vstfx_free_info (VSTInfo *info)
146 for (int i = 0; i < info->numParams; i++) {
147 free (info->ParamNames[i]);
148 free (info->ParamLabels[i]);
152 free (info->creator);
153 free (info->Category);
154 free (info->ParamNames);
155 free (info->ParamLabels);
161 vstfx_clear_info_list (vector<VSTInfo *> *infos)
163 for (vector<VSTInfo *>::iterator i = infos->begin(); i != infos->end(); ++i) {
171 /* *** CACHE FILE I/O *** */
173 /** Helper function to read a line from the cache file
174 * @return newly allocated string of NULL
177 read_string (FILE *fp)
179 char buf[MAX_STRING_LEN];
181 if (!fgets (buf, MAX_STRING_LEN, fp)) {
185 if (strlen(buf) < MAX_STRING_LEN) {
187 buf[strlen(buf)-1] = 0;
195 /** Read an integer value from a line in fp into n,
196 * @return true on failure, false on success.
199 read_int (FILE* fp, int* n)
201 char buf[MAX_STRING_LEN];
203 char* p = fgets (buf, MAX_STRING_LEN, fp);
208 return (sscanf (p, "%d", n) != 1);
211 /** parse a plugin-block from the cache info file */
213 vstfx_load_info_block(FILE* fp, VSTInfo *info)
215 if ((info->name = read_string(fp)) == 0) return false;
216 if ((info->creator = read_string(fp)) == 0) return false;
217 if (read_int (fp, &info->UniqueID)) return false;
218 if ((info->Category = read_string(fp)) == 0) return false;
219 if (read_int (fp, &info->numInputs)) return false;
220 if (read_int (fp, &info->numOutputs)) return false;
221 if (read_int (fp, &info->numParams)) return false;
222 if (read_int (fp, &info->wantMidi)) return false;
223 if (read_int (fp, &info->hasEditor)) return false;
224 if (read_int (fp, &info->canProcessReplacing)) return false;
226 /* backwards compatibility with old .fsi files */
227 if (info->wantMidi == -1) {
231 if ((info->numParams) == 0) {
232 info->ParamNames = NULL;
233 info->ParamLabels = NULL;
237 if ((info->ParamNames = (char **) malloc(sizeof(char*)*info->numParams)) == 0) {
241 for (int i = 0; i < info->numParams; ++i) {
242 if ((info->ParamNames[i] = read_string(fp)) == 0) return false;
245 if ((info->ParamLabels = (char **) malloc(sizeof(char*)*info->numParams)) == 0) {
249 for (int i = 0; i < info->numParams; ++i) {
250 if ((info->ParamLabels[i] = read_string(fp)) == 0) {
257 /** parse all blocks in a cache info file */
259 vstfx_load_info_file (FILE* fp, vector<VSTInfo*> *infos)
262 if ((info = (VSTInfo*) calloc (1, sizeof (VSTInfo))) == 0) {
265 if (vstfx_load_info_block(fp, info)) {
266 if (strncmp (info->Category, "Shell", 5)) {
267 infos->push_back(info);
270 vstfx_free_info(info);
271 if (!read_int (fp, &plugin_cnt)) {
272 for (int i = 0; i < plugin_cnt; i++) {
273 if ((info = (VSTInfo*) calloc (1, sizeof (VSTInfo))) == 0) {
274 vstfx_clear_info_list(infos);
277 if (vstfx_load_info_block(fp, info)) {
278 infos->push_back(info);
280 vstfx_free_info(info);
281 vstfx_clear_info_list(infos);
286 return false; /* Bad file */
291 vstfx_free_info(info);
292 vstfx_clear_info_list(infos);
297 vstfx_write_info_block (FILE* fp, VSTInfo *info)
302 fprintf (fp, "%s\n", info->name);
303 fprintf (fp, "%s\n", info->creator);
304 fprintf (fp, "%d\n", info->UniqueID);
305 fprintf (fp, "%s\n", info->Category);
306 fprintf (fp, "%d\n", info->numInputs);
307 fprintf (fp, "%d\n", info->numOutputs);
308 fprintf (fp, "%d\n", info->numParams);
309 fprintf (fp, "%d\n", info->wantMidi);
310 fprintf (fp, "%d\n", info->hasEditor);
311 fprintf (fp, "%d\n", info->canProcessReplacing);
313 for (int i = 0; i < info->numParams; i++) {
314 fprintf (fp, "%s\n", info->ParamNames[i]);
317 for (int i = 0; i < info->numParams; i++) {
318 fprintf (fp, "%s\n", info->ParamLabels[i]);
323 vstfx_write_info_file (FILE* fp, vector<VSTInfo *> *infos)
328 if (infos->size() > 1) {
329 vector<VSTInfo *>::iterator x = infos->begin();
330 /* write out the shell info first along with count of the number of
331 * plugins contained in this shell
333 vstfx_write_info_block(fp, *x);
334 fprintf( fp, "%d\n", (int)infos->size() - 1 );
336 /* Now write out the info for each plugin */
337 for (; x != infos->end(); ++x) {
338 vstfx_write_info_block(fp, *x);
340 } else if (infos->size() == 1) {
341 vstfx_write_info_block(fp, infos->front());
343 PBD::error << "Zero plugins in VST." << endmsg; // XXX here? rather make this impossible before if it ain't already.
348 /* *** CACHE AND BLACKLIST MANAGEMENT *** */
350 /* return true if plugin is blacklisted or has an invalid file extension */
352 vstfx_blacklist_stat (const char *dllpath, int personal)
354 const size_t slen = strlen (dllpath);
356 (slen <= 3 || g_ascii_strcasecmp (&dllpath[slen-3], ".so"))
358 (slen <= 4 || g_ascii_strcasecmp (&dllpath[slen-4], ".dll"))
363 string const path = vstfx_blacklist_path (dllpath, personal);
365 if (Glib::file_test (path, Glib::FileTest (Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR))) {
369 if (stat (dllpath, &dllstat) == 0 && stat (path.c_str(), &fsbstat) == 0) {
370 if (dllstat.st_mtime > fsbstat.st_mtime) {
371 /* plugin is newer than blacklist file */
375 /* stat failed or plugin is older than blacklist file */
378 /* blacklist file does not exist */
382 /* return true if plugin is blacklisted, checks both personal
383 * and global folder */
385 vstfx_check_blacklist (const char *dllpath)
387 if (vstfx_blacklist_stat(dllpath, 0)) return true;
388 if (vstfx_blacklist_stat(dllpath, 1)) return true;
392 /* create blacklist file, preferably in same folder as the
393 * plugin, fall back to personal folder in $HOME
396 vstfx_blacklist_file (const char *dllpath)
399 if ((f = fopen (vstfx_blacklist_path (dllpath, 0).c_str(), "wb"))) {
401 PBD::info << "Blacklisted VST: '" << vstfx_blacklist_path (dllpath, 0) << "'" << endmsg;
406 PBD::info << "Blacklisted VST: '" << vstfx_blacklist_path (dllpath, 1) << "'" << endmsg;
408 return fopen (vstfx_blacklist_path (dllpath, 1).c_str(), "wb");
411 /** mark plugin as blacklisted */
413 vstfx_blacklist (const char *dllpath)
415 FILE *f = vstfx_blacklist_file(dllpath);
423 /** mark plugin as not blacklisted */
425 vstfx_un_blacklist (const char *dllpath)
427 ::g_unlink(vstfx_blacklist_path (dllpath, 0).c_str());
428 ::g_unlink(vstfx_blacklist_path (dllpath, 1).c_str());
431 /** remove info file from cache */
433 vstfx_remove_infofile (const char *dllpath)
435 ::g_unlink(vstfx_infofile_path (dllpath, 0).c_str());
436 ::g_unlink(vstfx_infofile_path (dllpath, 1).c_str());
439 /** helper function, check if cache is newer than plugin
440 * @return path to cache file */
442 vstfx_infofile_stat (const char *dllpath, struct stat* statbuf, int personal)
444 const size_t slen = strlen (dllpath);
446 (slen <= 3 || g_ascii_strcasecmp (&dllpath[slen-3], ".so"))
448 (slen <= 4 || g_ascii_strcasecmp (&dllpath[slen-4], ".dll"))
453 string const path = vstfx_infofile_path (dllpath, personal);
455 if (Glib::file_test (path, Glib::FileTest (Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR))) {
459 if (stat (dllpath, &dllstat) == 0) {
460 if (stat (path.c_str(), statbuf) == 0) {
461 if (dllstat.st_mtime <= statbuf->st_mtime) {
462 /* plugin is older than info file */
463 return strdup (path.c_str ());
472 /** cache file for given plugin
473 * @return FILE of the .fsi cache if found and up-to-date*/
475 vstfx_infofile_for_read (const char* dllpath)
477 struct stat own_statbuf;
478 struct stat sys_statbuf;
481 char* own_info = vstfx_infofile_stat (dllpath, &own_statbuf, 1);
482 char* sys_info = vstfx_infofile_stat (dllpath, &sys_statbuf, 0);
486 if (own_statbuf.st_mtime <= sys_statbuf.st_mtime) {
487 /* system info file is newer, use it */
488 rv = g_fopen (sys_info, "rb");
491 rv = g_fopen (own_info, "rb");
493 } else if (sys_info) {
494 rv = g_fopen (sys_info, "rb");
502 /** helper function for \ref vstfx_infofile_for_write
503 * abstract global and personal cache folders
506 vstfx_infofile_create (const char* dllpath, int personal)
508 const size_t slen = strlen (dllpath);
510 (slen <= 3 || g_ascii_strcasecmp (&dllpath[slen-3], ".so"))
512 (slen <= 4 || g_ascii_strcasecmp (&dllpath[slen-4], ".dll"))
517 string const path = vstfx_infofile_path (dllpath, personal);
519 PBD::info << "Creating VST cache file " << path << endmsg;
521 return fopen (path.c_str(), "wb");
524 /** newly created cache file for given plugin
525 * @return FILE for the .fsi cache, NULL if neither personal,
526 * nor global cache folder is writable */
528 vstfx_infofile_for_write (const char* dllpath)
532 if ((f = vstfx_infofile_create (dllpath, 0)) == 0) {
533 f = vstfx_infofile_create (dllpath, 1);
539 /** check if cache-file exists, is up-to-date and parse cache file
540 * @param infos [return] loaded plugin info
541 * @return true if .fsi cache was read successfully, false otherwise
544 vstfx_get_info_from_file(const char* dllpath, vector<VSTInfo*> *infos)
548 if ((infofile = vstfx_infofile_for_read (dllpath)) != 0) {
549 rv = vstfx_load_info_file(infofile, infos);
552 PBD::warning << "Cannot get VST information form " << dllpath << ": info file load failed." << endmsg;
560 /* *** VST system-under-test methods *** */
563 bool vstfx_midi_input (VSTState* vstfx)
565 AEffect* plugin = vstfx->plugin;
567 int const vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, 0, 0.0f);
569 if (vst_version >= 2) {
570 /* should we send it VST events (i.e. MIDI) */
572 if ((plugin->flags & effFlagsIsSynth) || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("receiveVstEvents"), 0.0f) > 0)) {
581 bool vstfx_midi_output (VSTState* vstfx)
583 AEffect* plugin = vstfx->plugin;
585 int const vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, 0, 0.0f);
587 if (vst_version >= 2) {
588 /* should we send it VST events (i.e. MIDI) */
590 if ( (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("sendVstEvents"), 0.0f) > 0)
591 || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("sendVstMidiEvent"), 0.0f) > 0)
600 /** simple 'dummy' audiomaster callback to instantiate the plugin
601 * and query information
604 simple_master_callback (AEffect *, int32_t opcode, int32_t, intptr_t, void *ptr, float)
606 const char* vstfx_can_do_strings[] = {
612 "receiveVstMidiEvent",
617 const int vstfx_can_do_string_count = 9;
619 if (opcode == audioMasterVersion) {
622 else if (opcode == audioMasterCanDo) {
623 for (int i = 0; i < vstfx_can_do_string_count; i++) {
624 if (! strcmp(vstfx_can_do_strings[i], (const char*)ptr)) {
630 else if (opcode == audioMasterCurrentId) {
631 return vstfx_current_loading_id;
639 /** main plugin query and test function */
641 vstfx_parse_vst_state (VSTState* vstfx)
645 VSTInfo* info = (VSTInfo*) malloc (sizeof (VSTInfo));
650 /*We need to init the creator because some plugins
651 fail to implement getVendorString, and so won't stuff the
652 string with any name*/
654 char creator[65] = "Unknown";
657 AEffect* plugin = vstfx->plugin;
660 plugin->dispatcher (plugin, effGetEffectName, 0, 0, name, 0);
662 if (strlen(name) == 0) {
663 plugin->dispatcher (plugin, effGetProductString, 0, 0, name, 0);
666 if (strlen(name) == 0) {
667 info->name = strdup (vstfx->handle->name);
669 info->name = strdup (name);
672 /*If the plugin doesn't bother to implement GetVendorString we will
673 have pre-stuffed the string with 'Unknown' */
675 plugin->dispatcher (plugin, effGetVendorString, 0, 0, creator, 0);
677 /*Some plugins DO implement GetVendorString, but DON'T put a name in it
678 so if its just a zero length string we replace it with 'Unknown' */
680 if (strlen(creator) == 0) {
681 info->creator = strdup ("Unknown");
683 info->creator = strdup (creator);
687 switch (plugin->dispatcher (plugin, effGetPlugCategory, 0, 0, 0, 0))
689 case kPlugCategEffect: info->Category = strdup ("Effect"); break;
690 case kPlugCategSynth: info->Category = strdup ("Synth"); break;
691 case kPlugCategAnalysis: info->Category = strdup ("Anaylsis"); break;
692 case kPlugCategMastering: info->Category = strdup ("Mastering"); break;
693 case kPlugCategSpacializer: info->Category = strdup ("Spacializer"); break;
694 case kPlugCategRoomFx: info->Category = strdup ("RoomFx"); break;
695 case kPlugSurroundFx: info->Category = strdup ("SurroundFx"); break;
696 case kPlugCategRestoration: info->Category = strdup ("Restoration"); break;
697 case kPlugCategOfflineProcess: info->Category = strdup ("Offline"); break;
698 case kPlugCategShell: info->Category = strdup ("Shell"); break;
699 case kPlugCategGenerator: info->Category = strdup ("Generator"); break;
700 default: info->Category = strdup ("Unknown"); break;
703 info->UniqueID = plugin->uniqueID;
705 info->numInputs = plugin->numInputs;
706 info->numOutputs = plugin->numOutputs;
707 info->numParams = plugin->numParams;
708 info->wantMidi = (vstfx_midi_input(vstfx) ? 1 : 0) | (vstfx_midi_output(vstfx) ? 2 : 0);
709 info->hasEditor = plugin->flags & effFlagsHasEditor ? true : false;
710 info->canProcessReplacing = plugin->flags & effFlagsCanReplacing ? true : false;
711 info->ParamNames = (char **) malloc(sizeof(char*)*info->numParams);
712 info->ParamLabels = (char **) malloc(sizeof(char*)*info->numParams);
714 for (int i = 0; i < info->numParams; ++i) {
718 /* Not all plugins give parameters labels as well as names */
720 strcpy (name, "No Name");
721 strcpy (label, "No Label");
723 plugin->dispatcher (plugin, effGetParamName, i, 0, name, 0);
724 info->ParamNames[i] = strdup(name);
726 //NOTE: 'effGetParamLabel' is no longer defined in vestige headers
727 //plugin->dispatcher (plugin, effGetParamLabel, i, 0, label, 0);
728 info->ParamLabels[i] = strdup(label);
733 /** wrapper around \ref vstfx_parse_vst_state,
734 * iterate over plugins in shell, translate VST-info into ardour VSTState
737 vstfx_info_from_plugin (const char *dllpath, VSTState* vstfx, vector<VSTInfo *> *infos, enum ARDOUR::PluginType type)
742 if (!(info = vstfx_parse_vst_state(vstfx))) {
746 infos->push_back(info);
747 #if 1 // shell-plugin support
748 /* If this plugin is a Shell and we are not already inside a shell plugin
749 * read the info for all of the plugins contained in this shell.
751 if (!strncmp (info->Category, "Shell", 5)
752 && vstfx->handle->plugincnt == 1) {
754 vector< pair<int, string> > ids;
755 AEffect *plugin = vstfx->plugin;
758 char name[65] = "Unknown";
759 id = plugin->dispatcher (plugin, effShellGetNextPlugin, 0, 0, name, 0);
760 ids.push_back(std::make_pair(id, name));
764 #ifdef WINDOWS_VST_SUPPORT
765 case ARDOUR::Windows_VST: fst_close(vstfx); break;
768 case ARDOUR::LXVST: vstfx_close (vstfx); break;
770 default: assert(0); break;
773 for (vector< pair<int, string> >::iterator x = ids.begin(); x != ids.end(); ++x) {
775 if (id == 0) continue;
776 /* recurse vstfx_get_info() */
780 #ifdef WINDOWS_VST_SUPPORT
781 case ARDOUR::Windows_VST: ok = vstfx_instantiate_and_get_info_fst(dllpath, infos, id); break;
784 case ARDOUR::LXVST: ok = vstfx_instantiate_and_get_info_lx(dllpath, infos, id); break;
789 // One shell (some?, all?) does not report the actual plugin name
790 // even after the shelled plugin has been instantiated.
791 // Replace the name of the shell with the real name.
792 info = infos->back();
795 if ((*x).second.length() == 0) {
796 info->name = strdup("Unknown");
799 info->name = strdup ((*x).second.c_str());
805 #ifdef WINDOWS_VST_SUPPORT
806 case ARDOUR::Windows_VST: fst_close(vstfx); break;
809 case ARDOUR::LXVST: vstfx_close (vstfx); break;
811 default: assert(0); break;
819 /* *** TOP-LEVEL PLUGIN INSTANTIATION FUNCTIONS *** */
823 vstfx_instantiate_and_get_info_lx (
824 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
828 if (!(h = vstfx_load(dllpath))) {
829 PBD::warning << "Cannot get LinuxVST information from " << dllpath << ": load failed." << endmsg;
833 vstfx_current_loading_id = uniqueID;
835 if (!(vstfx = vstfx_instantiate(h, simple_master_callback, 0))) {
837 PBD::warning << "Cannot get LinuxVST information from " << dllpath << ": instantiation failed." << endmsg;
841 vstfx_current_loading_id = 0;
843 vstfx_info_from_plugin(dllpath, vstfx, infos, ARDOUR::LXVST);
850 #ifdef WINDOWS_VST_SUPPORT
852 vstfx_instantiate_and_get_info_fst (
853 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
857 if(!(h = fst_load(dllpath))) {
858 PBD::warning << "Cannot get Windows VST information from " << dllpath << ": load failed." << endmsg;
862 vstfx_current_loading_id = uniqueID;
864 if(!(vstfx = fst_instantiate(h, simple_master_callback, 0))) {
866 vstfx_current_loading_id = 0;
867 PBD::warning << "Cannot get Windows VST information from " << dllpath << ": instantiation failed." << endmsg;
870 vstfx_current_loading_id = 0;
872 vstfx_info_from_plugin(dllpath, vstfx, infos, ARDOUR::Windows_VST);
880 /* *** ERROR LOGGING *** */
881 #ifndef VST_SCANNER_APP
883 static FILE * _errorlog_fd = 0;
884 static char * _errorlog_dll = 0;
886 static void parse_scanner_output (std::string msg, size_t /*len*/)
888 if (!_errorlog_fd && !_errorlog_dll) {
889 PBD::error << "VST scanner: " << msg;
894 if (!(_errorlog_fd = fopen(vstfx_errorfile_path(_errorlog_dll, 0).c_str(), "w"))) {
895 if (!(_errorlog_fd = fopen(vstfx_errorfile_path(_errorlog_dll, 1).c_str(), "w"))) {
896 PBD::error << "Cannot create plugin error-log for plugin " << _errorlog_dll;
898 _errorlog_dll = NULL;
904 fprintf (_errorlog_fd, "%s\n", msg.c_str());
906 PBD::error << "VST scanner: " << msg;
911 set_error_log (const char* dllpath) {
912 assert(!_errorlog_fd);
913 assert(!_errorlog_dll);
914 _errorlog_dll = strdup(dllpath);
920 fclose(_errorlog_fd);
930 /* *** THE MAIN FUNCTION THAT USES ALL OF THE ABOVE :) *** */
932 static vector<VSTInfo *> *
933 vstfx_get_info (const char* dllpath, enum ARDOUR::PluginType type, enum VSTScanMode mode)
936 vector<VSTInfo*> *infos = new vector<VSTInfo*>;
938 if (vstfx_check_blacklist(dllpath)) {
942 if (vstfx_get_info_from_file(dllpath, infos)) {
946 #ifndef VST_SCANNER_APP
947 std::string scanner_bin_path = ARDOUR::PluginManager::scanner_bin_path;
949 if (mode == VST_SCAN_CACHE_ONLY) {
950 /* never scan explicitly, use cache only */
953 else if (mode == VST_SCAN_USE_APP && scanner_bin_path != "") {
954 /* use external scanner app */
956 char **argp= (char**) calloc(3,sizeof(char*));
957 argp[0] = strdup(scanner_bin_path.c_str());
958 argp[1] = strdup(dllpath);
961 set_error_log(dllpath);
962 ARDOUR::SystemExec scanner (scanner_bin_path, argp);
963 PBD::ScopedConnectionList cons;
964 scanner.ReadStdout.connect_same_thread (cons, boost::bind (&parse_scanner_output, _1 ,_2));
965 if (scanner.start (2 /* send stderr&stdout via signal */)) {
966 PBD::error << "Cannot launch VST scanner app '" << scanner_bin_path << "': "<< strerror(errno) << endmsg;
970 int timeout = PLUGIN_SCAN_TIMEOUT;
971 bool no_timeout = (timeout <= 0);
972 ARDOUR::PluginScanTimeout(timeout);
973 while (scanner.is_running() && (no_timeout || timeout > 0)) {
974 if (!no_timeout && !ARDOUR::PluginManager::instance().no_timeout()) {
975 if (timeout%5 == 0) {
976 ARDOUR::PluginScanTimeout(timeout);
981 Glib::usleep (100000);
983 if (ARDOUR::PluginManager::instance().cancelled()) {
984 // remove info file (might be incomplete)
985 vstfx_remove_infofile(dllpath);
986 // remove temporary blacklist file (scan incomplete)
987 vstfx_un_blacklist(dllpath);
996 /* re-read index (generated by external scanner) */
997 vstfx_clear_info_list(infos);
998 if (!vstfx_check_blacklist(dllpath)) {
999 vstfx_get_info_from_file(dllpath, infos);
1003 /* else .. instantiate and check in in ardour process itself */
1005 (void) mode; // unused parameter
1009 /* blacklist in case instantiation fails */
1010 vstfx_blacklist(dllpath);
1013 #ifdef WINDOWS_VST_SUPPORT
1014 case ARDOUR::Windows_VST: ok = vstfx_instantiate_and_get_info_fst(dllpath, infos, 0); break;
1016 #ifdef LXVST_SUPPORT
1017 case ARDOUR::LXVST: ok = vstfx_instantiate_and_get_info_lx(dllpath, infos, 0); break;
1019 default: ok = false;
1026 /* remove from blacklist */
1027 vstfx_un_blacklist(dllpath);
1029 /* crate cache/whitelist */
1030 infofile = vstfx_infofile_for_write (dllpath);
1032 PBD::warning << "Cannot cache VST information for " << dllpath << ": cannot create new FST info file." << endmsg;
1035 vstfx_write_info_file (infofile, infos);
1043 /* *** public API *** */
1046 vstfx_free_info_list (vector<VSTInfo *> *infos)
1048 for (vector<VSTInfo *>::iterator i = infos->begin(); i != infos->end(); ++i) {
1049 vstfx_free_info(*i);
1055 get_personal_vst_blacklist_dir() {
1056 string dir = Glib::build_filename (ARDOUR::user_cache_directory(), "fst_blacklist");
1057 /* if the directory doesn't exist, try to create it */
1058 if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
1059 if (g_mkdir (dir.c_str (), 0700)) {
1060 PBD::error << "Cannot create VST blacklist folder '" << dir << "'" << endmsg;
1068 get_personal_vst_info_cache_dir() {
1069 string dir = Glib::build_filename (ARDOUR::user_cache_directory(), "fst_info");
1070 /* if the directory doesn't exist, try to create it */
1071 if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
1072 if (g_mkdir (dir.c_str (), 0700)) {
1073 PBD::error << "Cannot create VST info folder '" << dir << "'" << endmsg;
1080 #ifdef LXVST_SUPPORT
1082 vstfx_get_info_lx (char* dllpath, enum VSTScanMode mode)
1084 return vstfx_get_info(dllpath, ARDOUR::LXVST, mode);
1088 #ifdef WINDOWS_VST_SUPPORT
1090 vstfx_get_info_fst (char* dllpath, enum VSTScanMode mode)
1092 return vstfx_get_info(dllpath, ARDOUR::Windows_VST, mode);
1096 #ifndef VST_SCANNER_APP