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 if (strstr (dllpath, ".so" ) == 0 && strstr(dllpath, ".dll") == 0) {
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 if (strstr (dllpath, ".so" ) == 0 && strstr(dllpath, ".dll") == 0) {
442 string const path = vstfx_infofile_path (dllpath, personal);
444 if (Glib::file_test (path, Glib::FileTest (Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR))) {
448 if (stat (dllpath, &dllstat) == 0) {
449 if (stat (path.c_str(), statbuf) == 0) {
450 if (dllstat.st_mtime <= statbuf->st_mtime) {
451 /* plugin is older than info file */
452 return strdup (path.c_str ());
461 /** cache file for given plugin
462 * @return FILE of the .fsi cache if found and up-to-date*/
464 vstfx_infofile_for_read (const char* dllpath)
466 struct stat own_statbuf;
467 struct stat sys_statbuf;
470 char* own_info = vstfx_infofile_stat (dllpath, &own_statbuf, 1);
471 char* sys_info = vstfx_infofile_stat (dllpath, &sys_statbuf, 0);
475 if (own_statbuf.st_mtime <= sys_statbuf.st_mtime) {
476 /* system info file is newer, use it */
477 rv = g_fopen (sys_info, "rb");
480 rv = g_fopen (own_info, "rb");
482 } else if (sys_info) {
483 rv = g_fopen (sys_info, "rb");
491 /** helper function for \ref vstfx_infofile_for_write
492 * abstract global and personal cache folders
495 vstfx_infofile_create (const char* dllpath, int personal)
497 if (strstr (dllpath, ".so" ) == 0 && strstr(dllpath, ".dll") == 0) {
501 string const path = vstfx_infofile_path (dllpath, personal);
503 PBD::info << "Creating VST cache file " << path << endmsg;
505 return fopen (path.c_str(), "wb");
508 /** newly created cache file for given plugin
509 * @return FILE for the .fsi cache, NULL if neither personal,
510 * nor global cache folder is writable */
512 vstfx_infofile_for_write (const char* dllpath)
516 if ((f = vstfx_infofile_create (dllpath, 0)) == 0) {
517 f = vstfx_infofile_create (dllpath, 1);
523 /** check if cache-file exists, is up-to-date and parse cache file
524 * @param infos [return] loaded plugin info
525 * @return true if .fsi cache was read successfully, false otherwise
528 vstfx_get_info_from_file(const char* dllpath, vector<VSTInfo*> *infos)
532 if ((infofile = vstfx_infofile_for_read (dllpath)) != 0) {
533 rv = vstfx_load_info_file(infofile, infos);
536 PBD::warning << "Cannot get VST information form " << dllpath << ": info file load failed." << endmsg;
544 /* *** VST system-under-test methods *** */
547 bool vstfx_midi_input (VSTState* vstfx)
549 AEffect* plugin = vstfx->plugin;
551 int const vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, 0, 0.0f);
553 if (vst_version >= 2) {
554 /* should we send it VST events (i.e. MIDI) */
556 if ((plugin->flags & effFlagsIsSynth) || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("receiveVstEvents"), 0.0f) > 0)) {
565 bool vstfx_midi_output (VSTState* vstfx)
567 AEffect* plugin = vstfx->plugin;
569 int const vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, 0, 0.0f);
571 if (vst_version >= 2) {
572 /* should we send it VST events (i.e. MIDI) */
574 if ( (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("sendVstEvents"), 0.0f) > 0)
575 || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("sendVstMidiEvent"), 0.0f) > 0)
584 /** simple 'dummy' audiomaster callback to instantiate the plugin
585 * and query information
588 simple_master_callback (AEffect *, int32_t opcode, int32_t, intptr_t, void *ptr, float)
590 const char* vstfx_can_do_strings[] = {
596 "receiveVstMidiEvent",
601 const int vstfx_can_do_string_count = 9;
603 if (opcode == audioMasterVersion) {
606 else if (opcode == audioMasterCanDo) {
607 for (int i = 0; i < vstfx_can_do_string_count; i++) {
608 if (! strcmp(vstfx_can_do_strings[i], (const char*)ptr)) {
614 else if (opcode == audioMasterCurrentId) {
615 return vstfx_current_loading_id;
623 /** main plugin query and test function */
625 vstfx_parse_vst_state (VSTState* vstfx)
629 VSTInfo* info = (VSTInfo*) malloc (sizeof (VSTInfo));
634 /*We need to init the creator because some plugins
635 fail to implement getVendorString, and so won't stuff the
636 string with any name*/
638 char creator[65] = "Unknown";
641 AEffect* plugin = vstfx->plugin;
644 plugin->dispatcher (plugin, effGetEffectName, 0, 0, name, 0);
646 if (strlen(name) == 0) {
647 plugin->dispatcher (plugin, effGetProductString, 0, 0, name, 0);
650 if (strlen(name) == 0) {
651 info->name = strdup (vstfx->handle->name);
653 info->name = strdup (name);
656 /*If the plugin doesn't bother to implement GetVendorString we will
657 have pre-stuffed the string with 'Unknown' */
659 plugin->dispatcher (plugin, effGetVendorString, 0, 0, creator, 0);
661 /*Some plugins DO implement GetVendorString, but DON'T put a name in it
662 so if its just a zero length string we replace it with 'Unknown' */
664 if (strlen(creator) == 0) {
665 info->creator = strdup ("Unknown");
667 info->creator = strdup (creator);
671 switch (plugin->dispatcher (plugin, effGetPlugCategory, 0, 0, 0, 0))
673 case kPlugCategEffect: info->Category = strdup ("Effect"); break;
674 case kPlugCategSynth: info->Category = strdup ("Synth"); break;
675 case kPlugCategAnalysis: info->Category = strdup ("Anaylsis"); break;
676 case kPlugCategMastering: info->Category = strdup ("Mastering"); break;
677 case kPlugCategSpacializer: info->Category = strdup ("Spacializer"); break;
678 case kPlugCategRoomFx: info->Category = strdup ("RoomFx"); break;
679 case kPlugSurroundFx: info->Category = strdup ("SurroundFx"); break;
680 case kPlugCategRestoration: info->Category = strdup ("Restoration"); break;
681 case kPlugCategOfflineProcess: info->Category = strdup ("Offline"); break;
682 case kPlugCategShell: info->Category = strdup ("Shell"); break;
683 case kPlugCategGenerator: info->Category = strdup ("Generator"); break;
684 default: info->Category = strdup ("Unknown"); break;
687 info->UniqueID = plugin->uniqueID;
689 info->numInputs = plugin->numInputs;
690 info->numOutputs = plugin->numOutputs;
691 info->numParams = plugin->numParams;
692 info->wantMidi = (vstfx_midi_input(vstfx) ? 1 : 0) | (vstfx_midi_output(vstfx) ? 2 : 0);
693 info->hasEditor = plugin->flags & effFlagsHasEditor ? true : false;
694 info->canProcessReplacing = plugin->flags & effFlagsCanReplacing ? true : false;
695 info->ParamNames = (char **) malloc(sizeof(char*)*info->numParams);
696 info->ParamLabels = (char **) malloc(sizeof(char*)*info->numParams);
698 for (int i = 0; i < info->numParams; ++i) {
702 /* Not all plugins give parameters labels as well as names */
704 strcpy (name, "No Name");
705 strcpy (label, "No Label");
707 plugin->dispatcher (plugin, effGetParamName, i, 0, name, 0);
708 info->ParamNames[i] = strdup(name);
710 //NOTE: 'effGetParamLabel' is no longer defined in vestige headers
711 //plugin->dispatcher (plugin, effGetParamLabel, i, 0, label, 0);
712 info->ParamLabels[i] = strdup(label);
717 /** wrapper around \ref vstfx_parse_vst_state,
718 * iterate over plugins in shell, translate VST-info into ardour VSTState
721 vstfx_info_from_plugin (const char *dllpath, VSTState* vstfx, vector<VSTInfo *> *infos, enum ARDOUR::PluginType type)
726 if (!(info = vstfx_parse_vst_state(vstfx))) {
730 infos->push_back(info);
731 #if 1 // shell-plugin support
732 /* If this plugin is a Shell and we are not already inside a shell plugin
733 * read the info for all of the plugins contained in this shell.
735 if (!strncmp (info->Category, "Shell", 5)
736 && vstfx->handle->plugincnt == 1) {
738 vector< pair<int, string> > ids;
739 AEffect *plugin = vstfx->plugin;
742 char name[65] = "Unknown";
743 id = plugin->dispatcher (plugin, effShellGetNextPlugin, 0, 0, name, 0);
744 ids.push_back(std::make_pair(id, name));
748 #ifdef WINDOWS_VST_SUPPORT
749 case ARDOUR::Windows_VST: fst_close(vstfx); break;
752 case ARDOUR::LXVST: vstfx_close (vstfx); break;
754 default: assert(0); break;
757 for (vector< pair<int, string> >::iterator x = ids.begin(); x != ids.end(); ++x) {
759 if (id == 0) continue;
760 /* recurse vstfx_get_info() */
764 #ifdef WINDOWS_VST_SUPPORT
765 case ARDOUR::Windows_VST: ok = vstfx_instantiate_and_get_info_fst(dllpath, infos, id); break;
768 case ARDOUR::LXVST: ok = vstfx_instantiate_and_get_info_lx(dllpath, infos, id); break;
773 // One shell (some?, all?) does not report the actual plugin name
774 // even after the shelled plugin has been instantiated.
775 // Replace the name of the shell with the real name.
776 info = infos->back();
779 if ((*x).second.length() == 0) {
780 info->name = strdup("Unknown");
783 info->name = strdup ((*x).second.c_str());
789 #ifdef WINDOWS_VST_SUPPORT
790 case ARDOUR::Windows_VST: fst_close(vstfx); break;
793 case ARDOUR::LXVST: vstfx_close (vstfx); break;
795 default: assert(0); break;
803 /* *** TOP-LEVEL PLUGIN INSTANTIATION FUNCTIONS *** */
807 vstfx_instantiate_and_get_info_lx (
808 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
812 if (!(h = vstfx_load(dllpath))) {
813 PBD::warning << "Cannot get LinuxVST information from " << dllpath << ": load failed." << endmsg;
817 vstfx_current_loading_id = uniqueID;
819 if (!(vstfx = vstfx_instantiate(h, simple_master_callback, 0))) {
821 PBD::warning << "Cannot get LinuxVST information from " << dllpath << ": instantiation failed." << endmsg;
825 vstfx_current_loading_id = 0;
827 vstfx_info_from_plugin(dllpath, vstfx, infos, ARDOUR::LXVST);
834 #ifdef WINDOWS_VST_SUPPORT
836 vstfx_instantiate_and_get_info_fst (
837 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
841 if(!(h = fst_load(dllpath))) {
842 PBD::warning << "Cannot get Windows VST information from " << dllpath << ": load failed." << endmsg;
846 vstfx_current_loading_id = uniqueID;
848 if(!(vstfx = fst_instantiate(h, simple_master_callback, 0))) {
850 vstfx_current_loading_id = 0;
851 PBD::warning << "Cannot get Windows VST information from " << dllpath << ": instantiation failed." << endmsg;
854 vstfx_current_loading_id = 0;
856 vstfx_info_from_plugin(dllpath, vstfx, infos, ARDOUR::Windows_VST);
864 /* *** ERROR LOGGING *** */
865 #ifndef VST_SCANNER_APP
867 static FILE * _errorlog_fd = 0;
868 static char * _errorlog_dll = 0;
870 static void parse_scanner_output (std::string msg, size_t /*len*/)
872 if (!_errorlog_fd && !_errorlog_dll) {
873 PBD::error << "VST scanner: " << msg;
878 if (!(_errorlog_fd = fopen(vstfx_errorfile_path(_errorlog_dll, 0).c_str(), "w"))) {
879 if (!(_errorlog_fd = fopen(vstfx_errorfile_path(_errorlog_dll, 1).c_str(), "w"))) {
880 PBD::error << "Cannot create plugin error-log for plugin " << _errorlog_dll;
882 _errorlog_dll = NULL;
888 fprintf (_errorlog_fd, "%s\n", msg.c_str());
890 PBD::error << "VST scanner: " << msg;
895 set_error_log (const char* dllpath) {
896 assert(!_errorlog_fd);
897 assert(!_errorlog_dll);
898 _errorlog_dll = strdup(dllpath);
904 fclose(_errorlog_fd);
914 /* *** THE MAIN FUNCTION THAT USES ALL OF THE ABOVE :) *** */
916 static vector<VSTInfo *> *
917 vstfx_get_info (const char* dllpath, enum ARDOUR::PluginType type, enum VSTScanMode mode)
920 vector<VSTInfo*> *infos = new vector<VSTInfo*>;
922 if (vstfx_check_blacklist(dllpath)) {
926 if (vstfx_get_info_from_file(dllpath, infos)) {
930 #ifndef VST_SCANNER_APP
931 std::string scanner_bin_path = ARDOUR::PluginManager::scanner_bin_path;
933 if (mode == VST_SCAN_CACHE_ONLY) {
934 /* never scan explicitly, use cache only */
937 else if (mode == VST_SCAN_USE_APP && scanner_bin_path != "") {
938 /* use external scanner app */
940 char **argp= (char**) calloc(3,sizeof(char*));
941 argp[0] = strdup(scanner_bin_path.c_str());
942 argp[1] = strdup(dllpath);
945 set_error_log(dllpath);
946 ARDOUR::SystemExec scanner (scanner_bin_path, argp);
947 PBD::ScopedConnectionList cons;
948 scanner.ReadStdout.connect_same_thread (cons, boost::bind (&parse_scanner_output, _1 ,_2));
949 if (scanner.start (2 /* send stderr&stdout via signal */)) {
950 PBD::error << "Cannot launch VST scanner app '" << scanner_bin_path << "': "<< strerror(errno) << endmsg;
954 int timeout = PLUGIN_SCAN_TIMEOUT;
955 bool no_timeout = (timeout <= 0);
956 ARDOUR::PluginScanTimeout(timeout);
957 while (scanner.is_running() && (no_timeout || timeout > 0)) {
958 if (!no_timeout && !ARDOUR::PluginManager::instance().no_timeout()) {
959 if (timeout%5 == 0) {
960 ARDOUR::PluginScanTimeout(timeout);
965 Glib::usleep (100000);
967 if (ARDOUR::PluginManager::instance().cancelled()) {
968 // remove info file (might be incomplete)
969 vstfx_remove_infofile(dllpath);
970 // remove temporary blacklist file (scan incomplete)
971 vstfx_un_blacklist(dllpath);
980 /* re-read index (generated by external scanner) */
981 vstfx_clear_info_list(infos);
982 if (!vstfx_check_blacklist(dllpath)) {
983 vstfx_get_info_from_file(dllpath, infos);
987 /* else .. instantiate and check in in ardour process itself */
989 (void) mode; // unused parameter
993 /* blacklist in case instantiation fails */
994 vstfx_blacklist(dllpath);
997 #ifdef WINDOWS_VST_SUPPORT
998 case ARDOUR::Windows_VST: ok = vstfx_instantiate_and_get_info_fst(dllpath, infos, 0); break;
1000 #ifdef LXVST_SUPPORT
1001 case ARDOUR::LXVST: ok = vstfx_instantiate_and_get_info_lx(dllpath, infos, 0); break;
1003 default: ok = false;
1010 /* remove from blacklist */
1011 vstfx_un_blacklist(dllpath);
1013 /* crate cache/whitelist */
1014 infofile = vstfx_infofile_for_write (dllpath);
1016 PBD::warning << "Cannot cache VST information for " << dllpath << ": cannot create new FST info file." << endmsg;
1019 vstfx_write_info_file (infofile, infos);
1027 /* *** public API *** */
1030 vstfx_free_info_list (vector<VSTInfo *> *infos)
1032 for (vector<VSTInfo *>::iterator i = infos->begin(); i != infos->end(); ++i) {
1033 vstfx_free_info(*i);
1039 get_personal_vst_blacklist_dir() {
1040 string dir = Glib::build_filename (ARDOUR::user_cache_directory(), "fst_blacklist");
1041 /* if the directory doesn't exist, try to create it */
1042 if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
1043 if (g_mkdir (dir.c_str (), 0700)) {
1044 PBD::error << "Cannot create VST blacklist folder '" << dir << "'" << endmsg;
1052 get_personal_vst_info_cache_dir() {
1053 string dir = Glib::build_filename (ARDOUR::user_cache_directory(), "fst_info");
1054 /* if the directory doesn't exist, try to create it */
1055 if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
1056 if (g_mkdir (dir.c_str (), 0700)) {
1057 PBD::error << "Cannot create VST info folder '" << dir << "'" << endmsg;
1064 #ifdef LXVST_SUPPORT
1066 vstfx_get_info_lx (char* dllpath, enum VSTScanMode mode)
1068 return vstfx_get_info(dllpath, ARDOUR::LXVST, mode);
1072 #ifdef WINDOWS_VST_SUPPORT
1074 vstfx_get_info_fst (char* dllpath, enum VSTScanMode mode)
1076 return vstfx_get_info(dllpath, ARDOUR::Windows_VST, mode);
1080 #ifndef VST_SCANNER_APP