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.
27 #include <sys/types.h>
30 #include <sys/utime.h>
45 #include "pbd/gstdio_compat.h"
48 #include "pbd/error.h"
49 #include "pbd/compose.h"
51 #ifndef VST_SCANNER_APP
52 #include "ardour/plugin_manager.h" // scanner_bin_path
53 #include "ardour/rc_configuration.h"
54 #include "ardour/system_exec.h"
57 #include "ardour/filesystem_paths.h"
58 #include "ardour/linux_vst_support.h"
59 #include "ardour/mac_vst_support.h"
60 #include "ardour/plugin_types.h"
61 #include "ardour/vst_info_file.h"
66 #define MAX_STRING_LEN 256
67 #define PLUGIN_SCAN_TIMEOUT (Config->get_vst_scan_timeout()) // in deciseconds
70 #ifndef VST_SCANNER_APP
75 #ifdef WINDOWS_VST_SUPPORT
78 vstfx_instantiate_and_get_info_fst (const char* dllpath, vector<VSTInfo*> *infos, int uniqueID);
82 static bool vstfx_instantiate_and_get_info_lx (const char* dllpath, vector<VSTInfo*> *infos, int uniqueID);
86 static bool vstfx_instantiate_and_get_info_mac (const char* dllpath, vector<VSTInfo*> *infos, int uniqueID);
89 /* ID for shell plugins */
90 static int vstfx_current_loading_id = 0;
92 /* *** CACHE FILE PATHS *** */
95 get_vst_info_cache_dir () {
96 string dir = Glib::build_filename (ARDOUR::user_cache_directory (), "vst");
97 /* if the directory doesn't exist, try to create it */
98 if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
99 if (g_mkdir (dir.c_str (), 0700)) {
100 PBD::fatal << "Cannot create VST info folder '" << dir << "'" << endmsg;
107 vstfx_infofile_path (const char* dllpath)
112 sha1_write (&s, (const uint8_t *) dllpath, strlen (dllpath));
113 sha1_result_hash (&s, hash);
114 return Glib::build_filename (get_vst_info_cache_dir (), std::string (hash) + std::string (VST_EXT_INFOFILE));
118 /* *** VST Blacklist *** */
120 static void vstfx_read_blacklist (std::string &bl) {
121 FILE * blacklist_fd = NULL;
124 string fn = Glib::build_filename (ARDOUR::user_cache_directory (), VST_BLACKLIST);
126 if (!Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) {
130 if (! (blacklist_fd = g_fopen (fn.c_str (), "rb"))) {
134 while (!feof (blacklist_fd)) {
136 size_t s = fread (buf, sizeof(char), 1024, blacklist_fd);
137 if (ferror (blacklist_fd)) {
138 PBD::error << string_compose (_("error reading VST Blacklist file %1 (%2)"), fn, strerror (errno)) << endmsg;
147 ::fclose (blacklist_fd);
150 /** mark plugin as blacklisted */
151 static void vstfx_blacklist (const char *id)
153 string fn = Glib::build_filename (ARDOUR::user_cache_directory (), VST_BLACKLIST);
154 FILE * blacklist_fd = NULL;
155 if (! (blacklist_fd = g_fopen (fn.c_str (), "a"))) {
156 PBD::error << string_compose (_("Cannot append to VST blacklist for '%1'"), id) << endmsg;
159 assert (NULL == strchr (id, '\n'));
160 fprintf (blacklist_fd, "%s\n", id);
161 ::fclose (blacklist_fd);
164 /** mark plugin as not blacklisted */
165 static void vstfx_un_blacklist (const char *idcs)
168 string fn = Glib::build_filename (ARDOUR::user_cache_directory (), VST_BLACKLIST);
169 if (!Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) {
170 PBD::warning << _("Expected VST Blacklist file does not exist.") << endmsg;
175 vstfx_read_blacklist (bl);
177 ::g_unlink (fn.c_str ());
179 assert (!Glib::file_test (fn, Glib::FILE_TEST_EXISTS));
180 assert (id.find ("\n") == string::npos);
182 id += "\n"; // add separator
183 const size_t rpl = bl.find (id);
184 if (rpl != string::npos) {
185 bl.replace (rpl, id.size (), "");
191 FILE * blacklist_fd = NULL;
192 if (! (blacklist_fd = g_fopen (fn.c_str (), "w"))) {
193 PBD::error << _("Cannot open VST blacklist.") << endmsg;;
196 fprintf (blacklist_fd, "%s", bl.c_str ());
197 ::fclose (blacklist_fd);
200 /* return true if plugin is blacklisted */
201 static bool vst_is_blacklisted (const char *idcs)
203 // TODO ideally we'd also check if the VST has been updated since blacklisting
205 string fn = Glib::build_filename (ARDOUR::user_cache_directory (), VST_BLACKLIST);
206 if (!Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) {
211 vstfx_read_blacklist (bl);
213 assert (id.find ("\n") == string::npos);
215 id += "\n"; // add separator
216 const size_t rpl = bl.find (id);
217 if (rpl != string::npos) {
225 /* *** MEMORY MANAGEMENT *** */
227 /** cleanup single allocated VSTInfo */
229 vstfx_free_info (VSTInfo *info)
231 for (int i = 0; i < info->numParams; i++) {
232 free (info->ParamNames[i]);
233 free (info->ParamLabels[i]);
237 free (info->creator);
238 free (info->Category);
239 free (info->ParamNames);
240 free (info->ParamLabels);
246 vstfx_clear_info_list (vector<VSTInfo *> *infos)
248 for (vector<VSTInfo *>::iterator i = infos->begin (); i != infos->end (); ++i) {
249 vstfx_free_info (*i);
255 /* *** CACHE FILE I/O *** */
257 /** Helper function to read a line from the cache file
258 * @return newly allocated string of NULL
261 read_string (FILE *fp)
263 char buf[MAX_STRING_LEN];
265 if (!fgets (buf, MAX_STRING_LEN, fp)) {
270 /* strip lash char here: '\n',
271 * since VST-params cannot be longer than 127 chars.
273 buf[strlen (buf)-1] = 0;
279 /** Read an integer value from a line in fp into n,
280 * @return true on failure, false on success.
283 read_int (FILE* fp, int* n)
285 char buf[MAX_STRING_LEN];
287 char* p = fgets (buf, MAX_STRING_LEN, fp);
292 return (sscanf (p, "%d", n) != 1);
295 /** parse a plugin-block from the cache info file */
297 vstfx_load_info_block (FILE* fp, VSTInfo *info)
299 if ((info->name = read_string (fp)) == 0) return false;
300 if ((info->creator = read_string (fp)) == 0) return false;
301 if (read_int (fp, &info->UniqueID)) return false;
302 if ((info->Category = read_string (fp)) == 0) return false;
303 if (read_int (fp, &info->numInputs)) return false;
304 if (read_int (fp, &info->numOutputs)) return false;
305 if (read_int (fp, &info->numParams)) return false;
306 if (read_int (fp, &info->wantMidi)) return false;
307 if (read_int (fp, &info->hasEditor)) return false;
308 if (read_int (fp, &info->canProcessReplacing)) return false;
310 /* backwards compatibility with old .fsi files */
311 if (info->wantMidi == -1) {
315 // TODO read isInstrument -- effFlagsIsSynth
316 info->isInstrument = info->numInputs == 0 && info->numOutputs > 0 && 1 == (info->wantMidi & 1);
317 if (!strcmp (info->Category, "Instrument")) {
318 info->isInstrument = true;
321 if ((info->numParams) == 0) {
322 info->ParamNames = NULL;
323 info->ParamLabels = NULL;
327 if ((info->ParamNames = (char **) malloc (sizeof (char*) * info->numParams)) == 0) {
331 for (int i = 0; i < info->numParams; ++i) {
332 if ((info->ParamNames[i] = read_string (fp)) == 0) return false;
335 if ((info->ParamLabels = (char **) malloc (sizeof (char*) * info->numParams)) == 0) {
339 for (int i = 0; i < info->numParams; ++i) {
340 if ((info->ParamLabels[i] = read_string (fp)) == 0) {
347 /** parse all blocks in a cache info file */
349 vstfx_load_info_file (FILE* fp, vector<VSTInfo*> *infos)
352 if ((info = (VSTInfo*) calloc (1, sizeof (VSTInfo))) == 0) {
355 if (vstfx_load_info_block (fp, info)) {
356 if (strncmp (info->Category, "Shell", 5)) {
357 infos->push_back (info);
360 vstfx_free_info (info);
361 if (!read_int (fp, &plugin_cnt)) {
362 for (int i = 0; i < plugin_cnt; i++) {
363 if ((info = (VSTInfo*) calloc (1, sizeof (VSTInfo))) == 0) {
364 vstfx_clear_info_list (infos);
367 if (vstfx_load_info_block (fp, info)) {
368 infos->push_back (info);
370 vstfx_free_info (info);
371 vstfx_clear_info_list (infos);
376 return false; /* Bad file */
381 vstfx_free_info (info);
382 vstfx_clear_info_list (infos);
387 vstfx_write_info_block (FILE* fp, VSTInfo *info)
392 fprintf (fp, "%s\n", info->name);
393 fprintf (fp, "%s\n", info->creator);
394 fprintf (fp, "%d\n", info->UniqueID);
395 fprintf (fp, "%s\n", info->Category);
396 fprintf (fp, "%d\n", info->numInputs);
397 fprintf (fp, "%d\n", info->numOutputs);
398 fprintf (fp, "%d\n", info->numParams);
399 fprintf (fp, "%d\n", info->wantMidi);
400 fprintf (fp, "%d\n", info->hasEditor);
401 fprintf (fp, "%d\n", info->canProcessReplacing);
402 // TODO write isInstrument in a backwards compat way
404 for (int i = 0; i < info->numParams; i++) {
405 fprintf (fp, "%s\n", info->ParamNames[i]);
408 for (int i = 0; i < info->numParams; i++) {
409 fprintf (fp, "%s\n", info->ParamLabels[i]);
414 vstfx_write_info_file (FILE* fp, vector<VSTInfo *> *infos)
419 if (infos->size () > 1) {
420 vector<VSTInfo *>::iterator x = infos->begin ();
421 /* write out the shell info first along with count of the number of
422 * plugins contained in this shell
424 vstfx_write_info_block (fp, *x);
425 fprintf (fp, "%d\n", (int)infos->size () - 1 );
427 /* Now write out the info for each plugin */
428 for (; x != infos->end (); ++x) {
429 vstfx_write_info_block (fp, *x);
431 } else if (infos->size () == 1) {
432 vstfx_write_info_block (fp, infos->front ());
434 PBD::warning << _("VST object file contains no plugins.") << endmsg;
439 /* *** CACHE MANAGEMENT *** */
441 /** remove info file from cache */
443 vstfx_remove_infofile (const char *dllpath)
445 ::g_unlink (vstfx_infofile_path (dllpath).c_str ());
448 /** cache file for given plugin
449 * @return FILE of the .fsi cache if found and up-to-date*/
451 vstfx_infofile_for_read (const char* dllpath)
453 const size_t slen = strlen (dllpath);
455 (slen <= 3 || g_ascii_strcasecmp (&dllpath[slen-3], ".so"))
457 (slen <= 4 || g_ascii_strcasecmp (&dllpath[slen-4], ".vst"))
459 (slen <= 4 || g_ascii_strcasecmp (&dllpath[slen-4], ".dll"))
464 string const path = vstfx_infofile_path (dllpath);
466 if (Glib::file_test (path, Glib::FileTest (Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR))) {
470 if (g_stat (dllpath, &dllstat) == 0) {
471 if (g_stat (path.c_str (), &fsistat) == 0) {
472 if (dllstat.st_mtime <= fsistat.st_mtime) {
473 /* plugin is older than info file */
474 return g_fopen (path.c_str (), "rb");
478 PBD::warning << string_compose (_("Ignored VST plugin which is newer than cache: '%1' (cache: '%2')"), dllpath, path) << endmsg;
479 PBD::info << _("Re-Scan Plugins (Preferences > Plugins) to update the cache, also make sure your system-time is set correctly.") << endmsg;
484 /** newly created cache file for given plugin
485 * @return FILE for the .fsi cache or NULL on error
488 vstfx_infofile_for_write (const char* dllpath)
490 const size_t slen = strlen (dllpath);
492 (slen <= 3 || g_ascii_strcasecmp (&dllpath[slen-3], ".so"))
494 (slen <= 4 || g_ascii_strcasecmp (&dllpath[slen-4], ".vst"))
496 (slen <= 4 || g_ascii_strcasecmp (&dllpath[slen-4], ".dll"))
501 string const path = vstfx_infofile_path (dllpath);
502 return g_fopen (path.c_str (), "wb");
505 /** check if cache-file exists, is up-to-date and parse cache file
506 * @param infos [return] loaded plugin info
507 * @return true if .fsi cache was read successfully, false otherwise
510 vstfx_get_info_from_file (const char* dllpath, vector<VSTInfo*> *infos)
514 if ((infofile = vstfx_infofile_for_read (dllpath)) != 0) {
515 rv = vstfx_load_info_file (infofile, infos);
518 PBD::warning << string_compose (_("Cannot get VST information for '%1': failed to load cache file."), dllpath) << endmsg;
526 /* *** VST system-under-test methods *** */
529 bool vstfx_midi_input (VSTState* vstfx)
531 AEffect* plugin = vstfx->plugin;
533 int const vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, 0, 0.0f);
535 if (vst_version >= 2) {
536 /* should we send it VST events (i.e. MIDI) */
538 if ((plugin->flags & effFlagsIsSynth)
539 || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("receiveVstEvents"), 0.0f) > 0)
540 || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("receiveVstMidiEvents"), 0.0f) > 0)
550 bool vstfx_midi_output (VSTState* vstfx)
552 AEffect* plugin = vstfx->plugin;
554 int const vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, 0, 0.0f);
556 if (vst_version >= 2) {
557 /* should we send it VST events (i.e. MIDI) */
559 if ( (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("sendVstEvents"), 0.0f) > 0)
560 || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("sendVstMidiEvent"), 0.0f) > 0)
569 /** simple 'dummy' audiomaster callback to instantiate the plugin
570 * and query information
573 simple_master_callback (AEffect *, int32_t opcode, int32_t, intptr_t, void *ptr, float)
575 const char* vstfx_can_do_strings[] = {
581 "receiveVstMidiEvent",
586 const int vstfx_can_do_string_count = 9;
588 if (opcode == audioMasterVersion) {
591 else if (opcode == audioMasterCanDo) {
592 for (int i = 0; i < vstfx_can_do_string_count; i++) {
593 if (! strcmp (vstfx_can_do_strings[i], (const char*)ptr)) {
599 else if (opcode == audioMasterCurrentId) {
600 return vstfx_current_loading_id;
608 /** main plugin query and test function */
610 vstfx_parse_vst_state (VSTState* vstfx)
614 VSTInfo* info = (VSTInfo*) malloc (sizeof (VSTInfo));
619 /* We need to init the creator because some plugins
620 * fail to implement getVendorString, and so won't stuff the
621 * string with any name */
623 char creator[65] = "Unknown";
626 AEffect* plugin = vstfx->plugin;
629 plugin->dispatcher (plugin, effGetEffectName, 0, 0, name, 0);
631 if (strlen (name) == 0) {
632 plugin->dispatcher (plugin, effGetProductString, 0, 0, name, 0);
635 if (strlen (name) == 0) {
636 info->name = strdup (vstfx->handle->name);
638 info->name = strdup (name);
641 /*If the plugin doesn't bother to implement GetVendorString we will
642 * have pre-stuffed the string with 'Unknown' */
644 plugin->dispatcher (plugin, effGetVendorString, 0, 0, creator, 0);
646 /* Some plugins DO implement GetVendorString, but DON'T put a name in it
647 * so if its just a zero length string we replace it with 'Unknown' */
649 if (strlen (creator) == 0) {
650 info->creator = strdup ("Unknown");
652 info->creator = strdup (creator);
656 switch (plugin->dispatcher (plugin, effGetPlugCategory, 0, 0, 0, 0))
658 case kPlugCategEffect: info->Category = strdup ("Effect"); break;
659 case kPlugCategSynth: info->Category = strdup ("Instrument"); break;
660 case kPlugCategAnalysis: info->Category = strdup ("Analyser"); break;
661 case kPlugCategMastering: info->Category = strdup ("Mastering"); break;
662 case kPlugCategSpacializer: info->Category = strdup ("Spatial"); break;
663 case kPlugCategRoomFx: info->Category = strdup ("RoomFx"); break;
664 case kPlugSurroundFx: info->Category = strdup ("SurroundFx"); break;
665 case kPlugCategRestoration: info->Category = strdup ("Restoration"); break;
666 case kPlugCategOfflineProcess: info->Category = strdup ("Offline"); break;
667 case kPlugCategShell: info->Category = strdup ("Shell"); break;
668 case kPlugCategGenerator: info->Category = strdup ("Generator"); break;
669 default: info->Category = strdup ("Unknown"); break;
672 info->UniqueID = plugin->uniqueID;
674 info->numInputs = plugin->numInputs;
675 info->numOutputs = plugin->numOutputs;
676 info->numParams = plugin->numParams;
677 info->wantMidi = (vstfx_midi_input (vstfx) ? 1 : 0) | (vstfx_midi_output (vstfx) ? 2 : 0);
678 info->hasEditor = plugin->flags & effFlagsHasEditor ? true : false;
679 info->isInstrument = (plugin->flags & effFlagsIsSynth) ? 1 : 0;
680 info->canProcessReplacing = plugin->flags & effFlagsCanReplacing ? true : false;
681 info->ParamNames = (char **) malloc (sizeof (char*)*info->numParams);
682 info->ParamLabels = (char **) malloc (sizeof (char*)*info->numParams);
685 if (info->hasEditor) {
686 /* we only support Cocoa UIs (just like Reaper) */
687 info->hasEditor = (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("hasCockosViewAsConfig"), 0.0f) & 0xffff0000) == 0xbeef0000;
691 for (int i = 0; i < info->numParams; ++i) {
692 char name[VestigeMaxLabelLen];
693 char label[VestigeMaxLabelLen];
695 /* Not all plugins give parameters labels as well as names */
697 strcpy (name, "No Name");
698 strcpy (label, "No Label");
700 plugin->dispatcher (plugin, effGetParamName, i, 0, name, 0);
701 info->ParamNames[i] = strdup (name);
703 //NOTE: 'effGetParamLabel' is no longer defined in vestige headers
704 //plugin->dispatcher (plugin, effGetParamLabel, i, 0, label, 0);
705 info->ParamLabels[i] = strdup (label);
710 /** wrapper around \ref vstfx_parse_vst_state,
711 * iterate over plugins in shell, translate VST-info into ardour VSTState
714 vstfx_info_from_plugin (const char *dllpath, VSTState* vstfx, vector<VSTInfo *> *infos, enum ARDOUR::PluginType type)
719 if (!(info = vstfx_parse_vst_state (vstfx))) {
723 infos->push_back (info);
724 #if 1 // shell-plugin support
725 /* If this plugin is a Shell and we are not already inside a shell plugin
726 * read the info for all of the plugins contained in this shell.
728 if (!strncmp (info->Category, "Shell", 5)
729 && vstfx->handle->plugincnt == 1) {
731 vector< pair<int, string> > ids;
732 AEffect *plugin = vstfx->plugin;
735 char name[65] = "Unknown";
736 id = plugin->dispatcher (plugin, effShellGetNextPlugin, 0, 0, name, 0);
737 ids.push_back (std::make_pair (id, name));
741 #ifdef WINDOWS_VST_SUPPORT
742 case ARDOUR::Windows_VST:
751 #ifdef MACVST_SUPPORT
753 mac_vst_close (vstfx);
761 for (vector< pair<int, string> >::iterator x = ids.begin (); x != ids.end (); ++x) {
763 if (id == 0) continue;
764 /* recurse vstfx_get_info() */
768 #ifdef WINDOWS_VST_SUPPORT
769 case ARDOUR::Windows_VST:
770 ok = vstfx_instantiate_and_get_info_fst (dllpath, infos, id);
775 ok = vstfx_instantiate_and_get_info_lx (dllpath, infos, id);
778 #ifdef MACVST_SUPPORT
780 ok = vstfx_instantiate_and_get_info_mac (dllpath, infos, id);
788 // One shell (some?, all?) does not report the actual plugin name
789 // even after the shelled plugin has been instantiated.
790 // Replace the name of the shell with the real name.
791 info = infos->back ();
794 if ((*x).second.length () == 0) {
795 info->name = strdup ("Unknown");
798 info->name = strdup ((*x).second.c_str ());
804 #ifdef WINDOWS_VST_SUPPORT
805 case ARDOUR::Windows_VST:
814 #ifdef MACVST_SUPPORT
816 mac_vst_close (vstfx);
829 /* *** TOP-LEVEL PLUGIN INSTANTIATION FUNCTIONS *** */
833 vstfx_instantiate_and_get_info_lx (
834 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
838 if (!(h = vstfx_load (dllpath))) {
839 PBD::warning << string_compose (_("Cannot get LinuxVST information from '%1': load failed."), dllpath) << endmsg;
843 vstfx_current_loading_id = uniqueID;
845 if (!(vstfx = vstfx_instantiate (h, simple_master_callback, 0))) {
847 PBD::warning << string_compose (_("Cannot get LinuxVST information from '%1': instantiation failed."), dllpath) << endmsg;
851 vstfx_current_loading_id = 0;
853 vstfx_info_from_plugin (dllpath, vstfx, infos, ARDOUR::LXVST);
860 #ifdef WINDOWS_VST_SUPPORT
862 vstfx_instantiate_and_get_info_fst (
863 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
867 if (!(h = fst_load (dllpath))) {
868 PBD::warning << string_compose (_("Cannot get Windows VST information from '%1': load failed."), dllpath) << endmsg;
872 vstfx_current_loading_id = uniqueID;
874 if (!(vstfx = fst_instantiate (h, simple_master_callback, 0))) {
876 vstfx_current_loading_id = 0;
877 PBD::warning << string_compose (_("Cannot get Windows VST information from '%1': instantiation failed."), dllpath) << endmsg;
880 vstfx_current_loading_id = 0;
882 vstfx_info_from_plugin (dllpath, vstfx, infos, ARDOUR::Windows_VST);
888 #ifdef MACVST_SUPPORT
890 vstfx_instantiate_and_get_info_mac (
891 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
893 printf("vstfx_instantiate_and_get_info_mac %s\n", dllpath);
896 if (!(h = mac_vst_load (dllpath))) {
897 PBD::warning << string_compose (_("Cannot get MacVST information from '%1': load failed."), dllpath) << endmsg;
901 vstfx_current_loading_id = uniqueID;
903 if (!(vstfx = mac_vst_instantiate (h, simple_master_callback, 0))) {
905 PBD::warning << string_compose (_("Cannot get MacVST information from '%1': instantiation failed."), dllpath) << endmsg;
909 vstfx_current_loading_id = 0;
911 vstfx_info_from_plugin (dllpath, vstfx, infos, ARDOUR::MacVST);
918 /* *** ERROR LOGGING *** */
919 #ifndef VST_SCANNER_APP
921 static FILE * _errorlog_fd = 0;
922 static char * _errorlog_dll = 0;
924 static void parse_scanner_output (std::string msg, size_t /*len*/)
926 if (!_errorlog_fd && !_errorlog_dll) {
927 PBD::error << "VST scanner: " << msg;
933 if (!(_errorlog_fd = g_fopen (vstfx_errorfile_path (_errorlog_dll).c_str (), "w"))) {
934 PBD::error << "Cannot create plugin error-log for plugin " << _errorlog_dll;
935 free (_errorlog_dll);
936 _errorlog_dll = NULL;
942 fprintf (_errorlog_fd, "%s\n", msg.c_str ());
943 } else if (_errorlog_dll) {
944 PBD::error << "VST '" << _errorlog_dll << "': " << msg;
946 PBD::error << "VST scanner: " << msg;
951 set_error_log (const char* dllpath) {
952 assert (!_errorlog_fd);
953 assert (!_errorlog_dll);
954 _errorlog_dll = strdup (dllpath);
960 fclose (_errorlog_fd);
963 free (_errorlog_dll);
970 /* *** the main function that uses all of the above *** */
972 static vector<VSTInfo *> *
973 vstfx_get_info (const char* dllpath, enum ARDOUR::PluginType type, enum VSTScanMode mode)
976 vector<VSTInfo*> *infos = new vector<VSTInfo*>;
978 if (vst_is_blacklisted (dllpath)) {
982 if (vstfx_get_info_from_file (dllpath, infos)) {
986 #ifndef VST_SCANNER_APP
987 std::string scanner_bin_path = ARDOUR::PluginManager::scanner_bin_path;
989 if (mode == VST_SCAN_CACHE_ONLY) {
990 /* never scan explicitly, use cache only */
993 else if (mode == VST_SCAN_USE_APP && scanner_bin_path != "") {
994 /* use external scanner app */
996 char **argp= (char**) calloc (3,sizeof (char*));
997 argp[0] = strdup (scanner_bin_path.c_str ());
998 argp[1] = strdup (dllpath);
1001 set_error_log (dllpath);
1002 ARDOUR::SystemExec scanner (scanner_bin_path, argp);
1003 PBD::ScopedConnectionList cons;
1004 scanner.ReadStdout.connect_same_thread (cons, boost::bind (&parse_scanner_output, _1 ,_2));
1005 if (scanner.start (2 /* send stderr&stdout via signal */)) {
1006 PBD::error << string_compose (_("Cannot launch VST scanner app '%1': %2"), scanner_bin_path, strerror (errno)) << endmsg;
1010 int timeout = PLUGIN_SCAN_TIMEOUT;
1011 bool no_timeout = (timeout <= 0);
1012 ARDOUR::PluginScanTimeout (timeout);
1013 while (scanner.is_running () && (no_timeout || timeout > 0)) {
1014 if (!no_timeout && !ARDOUR::PluginManager::instance ().no_timeout ()) {
1015 if (timeout%5 == 0) {
1016 ARDOUR::PluginScanTimeout (timeout);
1021 Glib::usleep (100000);
1023 if (ARDOUR::PluginManager::instance ().cancelled ()) {
1024 // remove info file (might be incomplete)
1025 vstfx_remove_infofile (dllpath);
1026 // remove temporary blacklist file (scan incomplete)
1027 vstfx_un_blacklist (dllpath);
1028 scanner.terminate ();
1033 scanner.terminate ();
1036 /* re-read index (generated by external scanner) */
1037 vstfx_clear_info_list (infos);
1038 if (!vst_is_blacklisted (dllpath)) {
1039 vstfx_get_info_from_file (dllpath, infos);
1043 /* else .. instantiate and check in in ardour process itself */
1045 (void) mode; // unused parameter
1049 /* blacklist in case instantiation fails */
1050 vstfx_blacklist (dllpath);
1053 #ifdef WINDOWS_VST_SUPPORT
1054 case ARDOUR::Windows_VST:
1055 ok = vstfx_instantiate_and_get_info_fst (dllpath, infos, 0);
1058 #ifdef LXVST_SUPPORT
1060 ok = vstfx_instantiate_and_get_info_lx (dllpath, infos, 0);
1063 #ifdef MACVST_SUPPORT
1064 case ARDOUR::MacVST:
1065 ok = vstfx_instantiate_and_get_info_mac (dllpath, infos, 0);
1077 /* remove from blacklist */
1078 vstfx_un_blacklist (dllpath);
1080 /* crate cache/whitelist */
1081 infofile = vstfx_infofile_for_write (dllpath);
1083 PBD::warning << string_compose (_("Cannot cache VST information for '%1': cannot create cache file."), dllpath) << endmsg;
1086 vstfx_write_info_file (infofile, infos);
1089 /* In some cases the .dll may have a modification time in the future,
1090 * (e.g. unzip a VST plugin: .zip files don't include timezones)
1092 string const fsipath = vstfx_infofile_path (dllpath);
1095 if (g_stat (dllpath, &dllstat) == 0 && g_stat (fsipath.c_str (), &fsistat) == 0) {
1097 utb.actime = fsistat.st_atime;
1098 utb.modtime = std::max (dllstat.st_mtime, fsistat.st_mtime);
1099 g_utime (fsipath.c_str (), &utb);
1106 /* *** public API *** */
1109 vstfx_free_info_list (vector<VSTInfo *> *infos)
1111 for (vector<VSTInfo *>::iterator i = infos->begin (); i != infos->end (); ++i) {
1112 vstfx_free_info (*i);
1117 #ifdef LXVST_SUPPORT
1119 vstfx_get_info_lx (char* dllpath, enum VSTScanMode mode)
1121 return vstfx_get_info (dllpath, ARDOUR::LXVST, mode);
1125 #ifdef MACVST_SUPPORT
1127 vstfx_get_info_mac (char* dllpath, enum VSTScanMode mode)
1129 return vstfx_get_info (dllpath, ARDOUR::MacVST, mode);
1133 #ifdef WINDOWS_VST_SUPPORT
1135 vstfx_get_info_fst (char* dllpath, enum VSTScanMode mode)
1137 return vstfx_get_info (dllpath, ARDOUR::Windows_VST, mode);
1141 #ifndef VST_SCANNER_APP