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();
101 dir = Glib::path_get_dirname (std::string(dllpath));
105 s << PFX_DOTFILE << Glib::path_get_basename (dllpath) << ext;
106 return Glib::build_filename (dir, s.str ());
110 vstfx_blacklist_path (const char* dllpath, int personal)
114 dir = get_personal_vst_blacklist_dir();
116 dir = Glib::path_get_dirname (std::string(dllpath));
120 s << PFX_DOTFILE << Glib::path_get_basename (dllpath) << EXT_BLACKLIST;
121 return Glib::build_filename (dir, s.str ());
125 vstfx_infofile_path (const char* dllpath, int personal)
127 return vstfx_cache_file(dllpath, personal, EXT_INFOFILE);
130 #ifndef VST_SCANNER_APP
132 vstfx_errorfile_path (const char* dllpath, int personal)
134 return vstfx_cache_file(dllpath, personal, EXT_ERRORFILE);
139 /* *** MEMORY MANAGEMENT *** */
141 /** cleanup single allocated VSTInfo */
143 vstfx_free_info (VSTInfo *info)
145 for (int i = 0; i < info->numParams; i++) {
146 free (info->ParamNames[i]);
147 free (info->ParamLabels[i]);
151 free (info->creator);
152 free (info->Category);
153 free (info->ParamNames);
154 free (info->ParamLabels);
160 vstfx_clear_info_list (vector<VSTInfo *> *infos)
162 for (vector<VSTInfo *>::iterator i = infos->begin(); i != infos->end(); ++i) {
170 /* *** CACHE FILE I/O *** */
172 /** Helper function to read a line from the cache file
173 * @return newly allocated string of NULL
176 read_string (FILE *fp)
178 char buf[MAX_STRING_LEN];
180 if (!fgets (buf, MAX_STRING_LEN, fp)) {
184 if (strlen(buf) < MAX_STRING_LEN) {
186 buf[strlen(buf)-1] = 0;
194 /** Read an integer value from a line in fp into n,
195 * @return true on failure, false on success.
198 read_int (FILE* fp, int* n)
200 char buf[MAX_STRING_LEN];
202 char* p = fgets (buf, MAX_STRING_LEN, fp);
207 return (sscanf (p, "%d", n) != 1);
210 /** parse a plugin-block from the cache info file */
212 vstfx_load_info_block(FILE* fp, VSTInfo *info)
214 if ((info->name = read_string(fp)) == 0) return false;
215 if ((info->creator = read_string(fp)) == 0) return false;
216 if (read_int (fp, &info->UniqueID)) return false;
217 if ((info->Category = read_string(fp)) == 0) return false;
218 if (read_int (fp, &info->numInputs)) return false;
219 if (read_int (fp, &info->numOutputs)) return false;
220 if (read_int (fp, &info->numParams)) return false;
221 if (read_int (fp, &info->wantMidi)) return false;
222 if (read_int (fp, &info->hasEditor)) return false;
223 if (read_int (fp, &info->canProcessReplacing)) return false;
225 /* backwards compatibility with old .fsi files */
226 if (info->wantMidi == -1) {
230 if ((info->numParams) == 0) {
231 info->ParamNames = NULL;
232 info->ParamLabels = NULL;
236 if ((info->ParamNames = (char **) malloc(sizeof(char*)*info->numParams)) == 0) {
240 for (int i = 0; i < info->numParams; ++i) {
241 if ((info->ParamNames[i] = read_string(fp)) == 0) return false;
244 if ((info->ParamLabels = (char **) malloc(sizeof(char*)*info->numParams)) == 0) {
248 for (int i = 0; i < info->numParams; ++i) {
249 if ((info->ParamLabels[i] = read_string(fp)) == 0) {
256 /** parse all blocks in a cache info file */
258 vstfx_load_info_file (FILE* fp, vector<VSTInfo*> *infos)
261 if ((info = (VSTInfo*) calloc (1, sizeof (VSTInfo))) == 0) {
264 if (vstfx_load_info_block(fp, info)) {
265 if (strncmp (info->Category, "Shell", 5)) {
266 infos->push_back(info);
269 vstfx_free_info(info);
270 if (!read_int (fp, &plugin_cnt)) {
271 for (int i = 0; i < plugin_cnt; i++) {
272 if ((info = (VSTInfo*) calloc (1, sizeof (VSTInfo))) == 0) {
273 vstfx_clear_info_list(infos);
276 if (vstfx_load_info_block(fp, info)) {
277 infos->push_back(info);
279 vstfx_free_info(info);
280 vstfx_clear_info_list(infos);
285 return false; /* Bad file */
290 vstfx_free_info(info);
291 vstfx_clear_info_list(infos);
296 vstfx_write_info_block (FILE* fp, VSTInfo *info)
301 fprintf (fp, "%s\n", info->name);
302 fprintf (fp, "%s\n", info->creator);
303 fprintf (fp, "%d\n", info->UniqueID);
304 fprintf (fp, "%s\n", info->Category);
305 fprintf (fp, "%d\n", info->numInputs);
306 fprintf (fp, "%d\n", info->numOutputs);
307 fprintf (fp, "%d\n", info->numParams);
308 fprintf (fp, "%d\n", info->wantMidi);
309 fprintf (fp, "%d\n", info->hasEditor);
310 fprintf (fp, "%d\n", info->canProcessReplacing);
312 for (int i = 0; i < info->numParams; i++) {
313 fprintf (fp, "%s\n", info->ParamNames[i]);
316 for (int i = 0; i < info->numParams; i++) {
317 fprintf (fp, "%s\n", info->ParamLabels[i]);
322 vstfx_write_info_file (FILE* fp, vector<VSTInfo *> *infos)
327 if (infos->size() > 1) {
328 vector<VSTInfo *>::iterator x = infos->begin();
329 /* write out the shell info first along with count of the number of
330 * plugins contained in this shell
332 vstfx_write_info_block(fp, *x);
333 fprintf( fp, "%d\n", (int)infos->size() - 1 );
335 /* Now write out the info for each plugin */
336 for (; x != infos->end(); ++x) {
337 vstfx_write_info_block(fp, *x);
339 } else if (infos->size() == 1) {
340 vstfx_write_info_block(fp, infos->front());
342 PBD::error << "Zero plugins in VST." << endmsg; // XXX here? rather make this impossible before if it ain't already.
347 /* *** CACHE AND BLACKLIST MANAGEMENT *** */
349 /* return true if plugin is blacklisted or has an invalid file extension */
351 vstfx_blacklist_stat (const char *dllpath, int personal)
353 if (strstr (dllpath, ".so" ) == 0 && strstr(dllpath, ".dll") == 0) {
356 string const path = vstfx_blacklist_path (dllpath, personal);
358 if (Glib::file_test (path, Glib::FileTest (Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR))) {
362 if (stat (dllpath, &dllstat) == 0 && stat (path.c_str(), &fsbstat) == 0) {
363 if (dllstat.st_mtime > fsbstat.st_mtime) {
364 /* plugin is newer than blacklist file */
368 /* stat failed or plugin is older than blacklist file */
371 /* blacklist file does not exist */
375 /* return true if plugin is blacklisted, checks both personal
376 * and global folder */
378 vstfx_check_blacklist (const char *dllpath)
380 if (vstfx_blacklist_stat(dllpath, 0)) return true;
381 if (vstfx_blacklist_stat(dllpath, 1)) return true;
385 /* create blacklist file, preferably in same folder as the
386 * plugin, fall back to personal folder in $HOME
389 vstfx_blacklist_file (const char *dllpath)
392 if ((f = fopen (vstfx_blacklist_path (dllpath, 0).c_str(), "wb"))) {
394 PBD::info << "Blacklisted VST: '" << vstfx_blacklist_path (dllpath, 0) << "'" << endmsg;
399 PBD::info << "Blacklisted VST: '" << vstfx_blacklist_path (dllpath, 1) << "'" << endmsg;
401 return fopen (vstfx_blacklist_path (dllpath, 1).c_str(), "wb");
404 /** mark plugin as blacklisted */
406 vstfx_blacklist (const char *dllpath)
408 FILE *f = vstfx_blacklist_file(dllpath);
416 /** mark plugin as not blacklisted */
418 vstfx_un_blacklist (const char *dllpath)
420 ::g_unlink(vstfx_blacklist_path (dllpath, 0).c_str());
421 ::g_unlink(vstfx_blacklist_path (dllpath, 1).c_str());
424 /** remove info file from cache */
426 vstfx_remove_infofile (const char *dllpath)
428 ::g_unlink(vstfx_infofile_path (dllpath, 0).c_str());
429 ::g_unlink(vstfx_infofile_path (dllpath, 1).c_str());
432 /** helper function, check if cache is newer than plugin
433 * @return path to cache file */
435 vstfx_infofile_stat (const char *dllpath, struct stat* statbuf, int personal)
437 if (strstr (dllpath, ".so" ) == 0 && strstr(dllpath, ".dll") == 0) {
441 string const path = vstfx_infofile_path (dllpath, personal);
443 if (Glib::file_test (path, Glib::FileTest (Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR))) {
447 if (stat (dllpath, &dllstat) == 0) {
448 if (stat (path.c_str(), statbuf) == 0) {
449 if (dllstat.st_mtime <= statbuf->st_mtime) {
450 /* plugin is older than info file */
451 return strdup (path.c_str ());
460 /** cache file for given plugin
461 * @return FILE of the .fsi cache if found and up-to-date*/
463 vstfx_infofile_for_read (const char* dllpath)
465 struct stat own_statbuf;
466 struct stat sys_statbuf;
469 char* own_info = vstfx_infofile_stat (dllpath, &own_statbuf, 1);
470 char* sys_info = vstfx_infofile_stat (dllpath, &sys_statbuf, 0);
474 if (own_statbuf.st_mtime <= sys_statbuf.st_mtime) {
475 /* system info file is newer, use it */
476 rv = g_fopen (sys_info, "rb");
479 rv = g_fopen (own_info, "rb");
481 } else if (sys_info) {
482 rv = g_fopen (sys_info, "rb");
490 /** helper function for \ref vstfx_infofile_for_write
491 * abstract global and personal cache folders
494 vstfx_infofile_create (const char* dllpath, int personal)
496 if (strstr (dllpath, ".so" ) == 0 && strstr(dllpath, ".dll") == 0) {
500 string const path = vstfx_infofile_path (dllpath, personal);
502 PBD::info << "Creating VST cache file " << path << endmsg;
504 return fopen (path.c_str(), "wb");
507 /** newly created cache file for given plugin
508 * @return FILE for the .fsi cache, NULL if neither personal,
509 * nor global cache folder is writable */
511 vstfx_infofile_for_write (const char* dllpath)
515 if ((f = vstfx_infofile_create (dllpath, 0)) == 0) {
516 f = vstfx_infofile_create (dllpath, 1);
522 /** check if cache-file exists, is up-to-date and parse cache file
523 * @param infos [return] loaded plugin info
524 * @return true if .fsi cache was read successfully, false otherwise
527 vstfx_get_info_from_file(const char* dllpath, vector<VSTInfo*> *infos)
531 if ((infofile = vstfx_infofile_for_read (dllpath)) != 0) {
532 rv = vstfx_load_info_file(infofile, infos);
535 PBD::warning << "Cannot get VST information form " << dllpath << ": info file load failed." << endmsg;
543 /* *** VST system-under-test methods *** */
546 bool vstfx_midi_input (VSTState* vstfx)
548 AEffect* plugin = vstfx->plugin;
550 int const vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, 0, 0.0f);
552 if (vst_version >= 2) {
553 /* should we send it VST events (i.e. MIDI) */
555 if ((plugin->flags & effFlagsIsSynth) || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("receiveVstEvents"), 0.0f) > 0)) {
564 bool vstfx_midi_output (VSTState* vstfx)
566 AEffect* plugin = vstfx->plugin;
568 int const vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, 0, 0.0f);
570 if (vst_version >= 2) {
571 /* should we send it VST events (i.e. MIDI) */
573 if ( (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("sendVstEvents"), 0.0f) > 0)
574 || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("sendVstMidiEvent"), 0.0f) > 0)
583 /** simple 'dummy' audiomaster callback to instantiate the plugin
584 * and query information
587 simple_master_callback (AEffect *, int32_t opcode, int32_t, intptr_t, void *ptr, float)
589 const char* vstfx_can_do_strings[] = {
595 "receiveVstMidiEvent",
600 const int vstfx_can_do_string_count = 9;
602 if (opcode == audioMasterVersion) {
605 else if (opcode == audioMasterCanDo) {
606 for (int i = 0; i < vstfx_can_do_string_count; i++) {
607 if (! strcmp(vstfx_can_do_strings[i], (const char*)ptr)) {
613 else if (opcode == audioMasterCurrentId) {
614 return vstfx_current_loading_id;
622 /** main plugin query and test function */
624 vstfx_parse_vst_state (VSTState* vstfx)
628 VSTInfo* info = (VSTInfo*) malloc (sizeof (VSTInfo));
633 /*We need to init the creator because some plugins
634 fail to implement getVendorString, and so won't stuff the
635 string with any name*/
637 char creator[65] = "Unknown";
640 AEffect* plugin = vstfx->plugin;
643 plugin->dispatcher (plugin, effGetEffectName, 0, 0, name, 0);
645 if (strlen(name) == 0) {
646 plugin->dispatcher (plugin, effGetProductString, 0, 0, name, 0);
649 if (strlen(name) == 0) {
650 info->name = strdup (vstfx->handle->name);
652 info->name = strdup (name);
655 /*If the plugin doesn't bother to implement GetVendorString we will
656 have pre-stuffed the string with 'Unknown' */
658 plugin->dispatcher (plugin, effGetVendorString, 0, 0, creator, 0);
660 /*Some plugins DO implement GetVendorString, but DON'T put a name in it
661 so if its just a zero length string we replace it with 'Unknown' */
663 if (strlen(creator) == 0) {
664 info->creator = strdup ("Unknown");
666 info->creator = strdup (creator);
670 switch (plugin->dispatcher (plugin, effGetPlugCategory, 0, 0, 0, 0))
672 case kPlugCategEffect: info->Category = strdup ("Effect"); break;
673 case kPlugCategSynth: info->Category = strdup ("Synth"); break;
674 case kPlugCategAnalysis: info->Category = strdup ("Anaylsis"); break;
675 case kPlugCategMastering: info->Category = strdup ("Mastering"); break;
676 case kPlugCategSpacializer: info->Category = strdup ("Spacializer"); break;
677 case kPlugCategRoomFx: info->Category = strdup ("RoomFx"); break;
678 case kPlugSurroundFx: info->Category = strdup ("SurroundFx"); break;
679 case kPlugCategRestoration: info->Category = strdup ("Restoration"); break;
680 case kPlugCategOfflineProcess: info->Category = strdup ("Offline"); break;
681 case kPlugCategShell: info->Category = strdup ("Shell"); break;
682 case kPlugCategGenerator: info->Category = strdup ("Generator"); break;
683 default: info->Category = strdup ("Unknown"); break;
686 info->UniqueID = plugin->uniqueID;
688 info->numInputs = plugin->numInputs;
689 info->numOutputs = plugin->numOutputs;
690 info->numParams = plugin->numParams;
691 info->wantMidi = (vstfx_midi_input(vstfx) ? 1 : 0) | (vstfx_midi_output(vstfx) ? 2 : 0);
692 info->hasEditor = plugin->flags & effFlagsHasEditor ? true : false;
693 info->canProcessReplacing = plugin->flags & effFlagsCanReplacing ? true : false;
694 info->ParamNames = (char **) malloc(sizeof(char*)*info->numParams);
695 info->ParamLabels = (char **) malloc(sizeof(char*)*info->numParams);
697 for (int i = 0; i < info->numParams; ++i) {
701 /* Not all plugins give parameters labels as well as names */
703 strcpy (name, "No Name");
704 strcpy (label, "No Label");
706 plugin->dispatcher (plugin, effGetParamName, i, 0, name, 0);
707 info->ParamNames[i] = strdup(name);
709 //NOTE: 'effGetParamLabel' is no longer defined in vestige headers
710 //plugin->dispatcher (plugin, effGetParamLabel, i, 0, label, 0);
711 info->ParamLabels[i] = strdup(label);
716 /** wrapper around \ref vstfx_parse_vst_state,
717 * iterate over plugins in shell, translate VST-info into ardour VSTState
720 vstfx_info_from_plugin (const char *dllpath, VSTState* vstfx, vector<VSTInfo *> *infos, enum ARDOUR::PluginType type)
725 if (!(info = vstfx_parse_vst_state(vstfx))) {
729 infos->push_back(info);
730 #if 1 // shell-plugin support
731 /* If this plugin is a Shell and we are not already inside a shell plugin
732 * read the info for all of the plugins contained in this shell.
734 if (!strncmp (info->Category, "Shell", 5)
735 && vstfx->handle->plugincnt == 1) {
737 vector< pair<int, string> > ids;
738 AEffect *plugin = vstfx->plugin;
741 char name[65] = "Unknown";
742 id = plugin->dispatcher (plugin, effShellGetNextPlugin, 0, 0, name, 0);
743 ids.push_back(std::make_pair(id, name));
747 #ifdef WINDOWS_VST_SUPPORT
748 case ARDOUR::Windows_VST: fst_close(vstfx); break;
751 case ARDOUR::LXVST: vstfx_close (vstfx); break;
753 default: assert(0); break;
756 for (vector< pair<int, string> >::iterator x = ids.begin(); x != ids.end(); ++x) {
758 if (id == 0) continue;
759 /* recurse vstfx_get_info() */
763 #ifdef WINDOWS_VST_SUPPORT
764 case ARDOUR::Windows_VST: ok = vstfx_instantiate_and_get_info_fst(dllpath, infos, id); break;
767 case ARDOUR::LXVST: ok = vstfx_instantiate_and_get_info_lx(dllpath, infos, id); break;
772 // One shell (some?, all?) does not report the actual plugin name
773 // even after the shelled plugin has been instantiated.
774 // Replace the name of the shell with the real name.
775 info = infos->back();
778 if ((*x).second.length() == 0) {
779 info->name = strdup("Unknown");
782 info->name = strdup ((*x).second.c_str());
788 #ifdef WINDOWS_VST_SUPPORT
789 case ARDOUR::Windows_VST: fst_close(vstfx); break;
792 case ARDOUR::LXVST: vstfx_close (vstfx); break;
794 default: assert(0); break;
802 /* *** TOP-LEVEL PLUGIN INSTANTIATION FUNCTIONS *** */
806 vstfx_instantiate_and_get_info_lx (
807 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
811 if (!(h = vstfx_load(dllpath))) {
812 PBD::warning << "Cannot get LinuxVST information from " << dllpath << ": load failed." << endmsg;
816 vstfx_current_loading_id = uniqueID;
818 if (!(vstfx = vstfx_instantiate(h, simple_master_callback, 0))) {
820 PBD::warning << "Cannot get LinuxVST information from " << dllpath << ": instantiation failed." << endmsg;
824 vstfx_current_loading_id = 0;
826 vstfx_info_from_plugin(dllpath, vstfx, infos, ARDOUR::LXVST);
833 #ifdef WINDOWS_VST_SUPPORT
835 vstfx_instantiate_and_get_info_fst (
836 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
840 if(!(h = fst_load(dllpath))) {
841 PBD::warning << "Cannot get Windows VST information from " << dllpath << ": load failed." << endmsg;
845 vstfx_current_loading_id = uniqueID;
847 if(!(vstfx = fst_instantiate(h, simple_master_callback, 0))) {
849 vstfx_current_loading_id = 0;
850 PBD::warning << "Cannot get Windows VST information from " << dllpath << ": instantiation failed." << endmsg;
853 vstfx_current_loading_id = 0;
855 vstfx_info_from_plugin(dllpath, vstfx, infos, ARDOUR::Windows_VST);
863 /* *** ERROR LOGGING *** */
864 #ifndef VST_SCANNER_APP
866 static FILE * _errorlog_fd = 0;
867 static char * _errorlog_dll = 0;
869 static void parse_scanner_output (std::string msg, size_t /*len*/)
871 if (!_errorlog_fd && !_errorlog_dll) {
872 PBD::error << "VST scanner: " << msg;
877 if (!(_errorlog_fd = fopen(vstfx_errorfile_path(_errorlog_dll, 0).c_str(), "w"))) {
878 if (!(_errorlog_fd = fopen(vstfx_errorfile_path(_errorlog_dll, 1).c_str(), "w"))) {
879 PBD::error << "Cannot create plugin error-log for plugin " << _errorlog_dll;
881 _errorlog_dll = NULL;
887 fprintf (_errorlog_fd, "%s\n", msg.c_str());
889 PBD::error << "VST scanner: " << msg;
894 set_error_log (const char* dllpath) {
895 assert(!_errorlog_fd);
896 assert(!_errorlog_dll);
897 _errorlog_dll = strdup(dllpath);
903 fclose(_errorlog_fd);
913 /* *** THE MAIN FUNCTION THAT USES ALL OF THE ABOVE :) *** */
915 static vector<VSTInfo *> *
916 vstfx_get_info (const char* dllpath, enum ARDOUR::PluginType type, enum VSTScanMode mode)
919 vector<VSTInfo*> *infos = new vector<VSTInfo*>;
921 if (vstfx_check_blacklist(dllpath)) {
925 if (vstfx_get_info_from_file(dllpath, infos)) {
929 #ifndef VST_SCANNER_APP
930 std::string scanner_bin_path = ARDOUR::PluginManager::scanner_bin_path;
932 if (mode == VST_SCAN_CACHE_ONLY) {
933 /* never scan explicitly, use cache only */
936 else if (mode == VST_SCAN_USE_APP && scanner_bin_path != "") {
937 /* use external scanner app */
939 char **argp= (char**) calloc(3,sizeof(char*));
940 argp[0] = strdup(scanner_bin_path.c_str());
941 argp[1] = strdup(dllpath);
944 set_error_log(dllpath);
945 ARDOUR::SystemExec scanner (scanner_bin_path, argp);
946 PBD::ScopedConnectionList cons;
947 scanner.ReadStdout.connect_same_thread (cons, boost::bind (&parse_scanner_output, _1 ,_2));
948 if (scanner.start (2 /* send stderr&stdout via signal */)) {
949 PBD::error << "Cannot launch VST scanner app '" << scanner_bin_path << "': "<< strerror(errno) << endmsg;
953 int timeout = PLUGIN_SCAN_TIMEOUT;
954 bool no_timeout = (timeout <= 0);
955 ARDOUR::PluginScanTimeout(timeout);
956 while (scanner.is_running() && (no_timeout || timeout > 0)) {
957 if (!no_timeout && !ARDOUR::PluginManager::instance().no_timeout()) {
958 if (timeout%5 == 0) {
959 ARDOUR::PluginScanTimeout(timeout);
964 Glib::usleep (100000);
966 if (ARDOUR::PluginManager::instance().cancelled()) {
967 // remove info file (might be incomplete)
968 vstfx_remove_infofile(dllpath);
969 // remove temporary blacklist file (scan incomplete)
970 vstfx_un_blacklist(dllpath);
979 /* re-read index (generated by external scanner) */
980 vstfx_clear_info_list(infos);
981 if (!vstfx_check_blacklist(dllpath)) {
982 vstfx_get_info_from_file(dllpath, infos);
986 /* else .. instantiate and check in in ardour process itself */
988 (void) mode; // unused parameter
992 /* blacklist in case instantiation fails */
993 vstfx_blacklist(dllpath);
996 #ifdef WINDOWS_VST_SUPPORT
997 case ARDOUR::Windows_VST: ok = vstfx_instantiate_and_get_info_fst(dllpath, infos, 0); break;
1000 case ARDOUR::LXVST: ok = vstfx_instantiate_and_get_info_lx(dllpath, infos, 0); break;
1002 default: ok = false;
1009 /* remove from blacklist */
1010 vstfx_un_blacklist(dllpath);
1012 /* crate cache/whitelist */
1013 infofile = vstfx_infofile_for_write (dllpath);
1015 PBD::warning << "Cannot cache VST information for " << dllpath << ": cannot create new FST info file." << endmsg;
1018 vstfx_write_info_file (infofile, infos);
1026 /* *** public API *** */
1029 vstfx_free_info_list (vector<VSTInfo *> *infos)
1031 for (vector<VSTInfo *>::iterator i = infos->begin(); i != infos->end(); ++i) {
1032 vstfx_free_info(*i);
1038 get_personal_vst_blacklist_dir() {
1039 string dir = Glib::build_filename (ARDOUR::user_cache_directory(), "fst_blacklist");
1040 /* if the directory doesn't exist, try to create it */
1041 if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
1042 if (g_mkdir (dir.c_str (), 0700)) {
1043 PBD::error << "Cannot create VST blacklist folder '" << dir << "'" << endmsg;
1051 get_personal_vst_info_cache_dir() {
1052 string dir = Glib::build_filename (ARDOUR::user_cache_directory(), "fst_info");
1053 /* if the directory doesn't exist, try to create it */
1054 if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
1055 if (g_mkdir (dir.c_str (), 0700)) {
1056 PBD::error << "Cannot create VST info folder '" << dir << "'" << endmsg;
1063 #ifdef LXVST_SUPPORT
1065 vstfx_get_info_lx (char* dllpath, enum VSTScanMode mode)
1067 return vstfx_get_info(dllpath, ARDOUR::LXVST, mode);
1071 #ifdef WINDOWS_VST_SUPPORT
1073 vstfx_get_info_fst (char* dllpath, enum VSTScanMode mode)
1075 return vstfx_get_info(dllpath, ARDOUR::Windows_VST, mode);
1079 #ifndef VST_SCANNER_APP