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 info->isInstrument = (info->wantMidi & 4) ? 1 : 0;
317 info->isInstrument |= info->numInputs == 0 && info->numOutputs > 0 && 1 == (info->wantMidi & 1);
318 if (!strcmp (info->Category, "Instrument")) {
319 info->isInstrument = 1;
322 if ((info->numParams) == 0) {
323 info->ParamNames = NULL;
324 info->ParamLabels = NULL;
328 if ((info->ParamNames = (char **) malloc (sizeof (char*) * info->numParams)) == 0) {
332 for (int i = 0; i < info->numParams; ++i) {
333 if ((info->ParamNames[i] = read_string (fp)) == 0) return false;
336 if ((info->ParamLabels = (char **) malloc (sizeof (char*) * info->numParams)) == 0) {
340 for (int i = 0; i < info->numParams; ++i) {
341 if ((info->ParamLabels[i] = read_string (fp)) == 0) {
348 /** parse all blocks in a cache info file */
350 vstfx_load_info_file (FILE* fp, vector<VSTInfo*> *infos)
353 if ((info = (VSTInfo*) calloc (1, sizeof (VSTInfo))) == 0) {
356 if (vstfx_load_info_block (fp, info)) {
357 if (strncmp (info->Category, "Shell", 5)) {
358 infos->push_back (info);
361 vstfx_free_info (info);
362 if (!read_int (fp, &plugin_cnt)) {
363 for (int i = 0; i < plugin_cnt; i++) {
364 if ((info = (VSTInfo*) calloc (1, sizeof (VSTInfo))) == 0) {
365 vstfx_clear_info_list (infos);
368 if (vstfx_load_info_block (fp, info)) {
369 infos->push_back (info);
371 vstfx_free_info (info);
372 vstfx_clear_info_list (infos);
377 return false; /* Bad file */
382 vstfx_free_info (info);
383 vstfx_clear_info_list (infos);
388 vstfx_write_info_block (FILE* fp, VSTInfo *info)
393 fprintf (fp, "%s\n", info->name);
394 fprintf (fp, "%s\n", info->creator);
395 fprintf (fp, "%d\n", info->UniqueID);
396 fprintf (fp, "%s\n", info->Category);
397 fprintf (fp, "%d\n", info->numInputs);
398 fprintf (fp, "%d\n", info->numOutputs);
399 fprintf (fp, "%d\n", info->numParams);
400 fprintf (fp, "%d\n", info->wantMidi | (info->isInstrument ? 4 : 0));
401 fprintf (fp, "%d\n", info->hasEditor);
402 fprintf (fp, "%d\n", info->canProcessReplacing);
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 /* should we send it VST events (i.e. MIDI) */
535 if ((plugin->flags & effFlagsIsSynth)
536 || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("receiveVstEvents"), 0.0f) > 0)
537 || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("receiveVstMidiEvents"), 0.0f) > 0)
546 bool vstfx_midi_output (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->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("sendVstEvents"), 0.0f) > 0)
556 || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("sendVstMidiEvent"), 0.0f) > 0)
565 /** simple 'dummy' audiomaster callback to instantiate the plugin
566 * and query information
569 simple_master_callback (AEffect *, int32_t opcode, int32_t, intptr_t, void *ptr, float)
571 const char* vstfx_can_do_strings[] = {
577 "receiveVstMidiEvent",
582 const int vstfx_can_do_string_count = 9;
584 if (opcode == audioMasterVersion) {
587 else if (opcode == audioMasterCanDo) {
588 for (int i = 0; i < vstfx_can_do_string_count; i++) {
589 if (! strcmp (vstfx_can_do_strings[i], (const char*)ptr)) {
595 else if (opcode == audioMasterCurrentId) {
596 return vstfx_current_loading_id;
604 /** main plugin query and test function */
606 vstfx_parse_vst_state (VSTState* vstfx)
610 VSTInfo* info = (VSTInfo*) malloc (sizeof (VSTInfo));
615 /* We need to init the creator because some plugins
616 * fail to implement getVendorString, and so won't stuff the
617 * string with any name */
619 char creator[65] = "Unknown";
622 AEffect* plugin = vstfx->plugin;
625 plugin->dispatcher (plugin, effGetEffectName, 0, 0, name, 0);
627 if (strlen (name) == 0) {
628 plugin->dispatcher (plugin, effGetProductString, 0, 0, name, 0);
631 if (strlen (name) == 0) {
632 info->name = strdup (vstfx->handle->name);
634 info->name = strdup (name);
637 /*If the plugin doesn't bother to implement GetVendorString we will
638 * have pre-stuffed the string with 'Unknown' */
640 plugin->dispatcher (plugin, effGetVendorString, 0, 0, creator, 0);
642 /* Some plugins DO implement GetVendorString, but DON'T put a name in it
643 * so if its just a zero length string we replace it with 'Unknown' */
645 if (strlen (creator) == 0) {
646 info->creator = strdup ("Unknown");
648 info->creator = strdup (creator);
652 switch (plugin->dispatcher (plugin, effGetPlugCategory, 0, 0, 0, 0))
654 case kPlugCategEffect: info->Category = strdup ("Effect"); break;
655 case kPlugCategSynth: info->Category = strdup ("Instrument"); break;
656 case kPlugCategAnalysis: info->Category = strdup ("Analyser"); break;
657 case kPlugCategMastering: info->Category = strdup ("Mastering"); break;
658 case kPlugCategSpacializer: info->Category = strdup ("Spatial"); break;
659 case kPlugCategRoomFx: info->Category = strdup ("RoomFx"); break;
660 case kPlugSurroundFx: info->Category = strdup ("SurroundFx"); break;
661 case kPlugCategRestoration: info->Category = strdup ("Restoration"); break;
662 case kPlugCategOfflineProcess: info->Category = strdup ("Offline"); break;
663 case kPlugCategShell: info->Category = strdup ("Shell"); break;
664 case kPlugCategGenerator: info->Category = strdup ("Generator"); break;
665 default: info->Category = strdup ("Unknown"); break;
668 info->UniqueID = plugin->uniqueID;
670 info->numInputs = plugin->numInputs;
671 info->numOutputs = plugin->numOutputs;
672 info->numParams = plugin->numParams;
673 info->wantMidi = (vstfx_midi_input (vstfx) ? 1 : 0) | (vstfx_midi_output (vstfx) ? 2 : 0);
674 info->hasEditor = plugin->flags & effFlagsHasEditor ? true : false;
675 info->isInstrument = (plugin->flags & effFlagsIsSynth) ? 1 : 0;
676 info->canProcessReplacing = plugin->flags & effFlagsCanReplacing ? true : false;
677 info->ParamNames = (char **) malloc (sizeof (char*)*info->numParams);
678 info->ParamLabels = (char **) malloc (sizeof (char*)*info->numParams);
681 if (info->hasEditor) {
682 /* we only support Cocoa UIs (just like Reaper) */
683 info->hasEditor = (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("hasCockosViewAsConfig"), 0.0f) & 0xffff0000) == 0xbeef0000;
687 for (int i = 0; i < info->numParams; ++i) {
688 char name[VestigeMaxLabelLen];
689 char label[VestigeMaxLabelLen];
691 /* Not all plugins give parameters labels as well as names */
693 strcpy (name, "No Name");
694 strcpy (label, "No Label");
696 plugin->dispatcher (plugin, effGetParamName, i, 0, name, 0);
697 info->ParamNames[i] = strdup (name);
699 //NOTE: 'effGetParamLabel' is no longer defined in vestige headers
700 //plugin->dispatcher (plugin, effGetParamLabel, i, 0, label, 0);
701 info->ParamLabels[i] = strdup (label);
706 /** wrapper around \ref vstfx_parse_vst_state,
707 * iterate over plugins in shell, translate VST-info into ardour VSTState
710 vstfx_info_from_plugin (const char *dllpath, VSTState* vstfx, vector<VSTInfo *> *infos, enum ARDOUR::PluginType type)
715 if (!(info = vstfx_parse_vst_state (vstfx))) {
719 infos->push_back (info);
720 #if 1 // shell-plugin support
721 /* If this plugin is a Shell and we are not already inside a shell plugin
722 * read the info for all of the plugins contained in this shell.
724 if (!strncmp (info->Category, "Shell", 5)
725 && vstfx->handle->plugincnt == 1) {
727 vector< pair<int, string> > ids;
728 AEffect *plugin = vstfx->plugin;
731 char name[65] = "Unknown";
732 id = plugin->dispatcher (plugin, effShellGetNextPlugin, 0, 0, name, 0);
733 ids.push_back (std::make_pair (id, name));
737 #ifdef WINDOWS_VST_SUPPORT
738 case ARDOUR::Windows_VST:
747 #ifdef MACVST_SUPPORT
749 mac_vst_close (vstfx);
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:
766 ok = vstfx_instantiate_and_get_info_fst (dllpath, infos, id);
771 ok = vstfx_instantiate_and_get_info_lx (dllpath, infos, id);
774 #ifdef MACVST_SUPPORT
776 ok = vstfx_instantiate_and_get_info_mac (dllpath, infos, id);
784 // One shell (some?, all?) does not report the actual plugin name
785 // even after the shelled plugin has been instantiated.
786 // Replace the name of the shell with the real name.
787 info = infos->back ();
790 if ((*x).second.length () == 0) {
791 info->name = strdup ("Unknown");
794 info->name = strdup ((*x).second.c_str ());
800 #ifdef WINDOWS_VST_SUPPORT
801 case ARDOUR::Windows_VST:
810 #ifdef MACVST_SUPPORT
812 mac_vst_close (vstfx);
825 /* *** TOP-LEVEL PLUGIN INSTANTIATION FUNCTIONS *** */
829 vstfx_instantiate_and_get_info_lx (
830 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
834 if (!(h = vstfx_load (dllpath))) {
835 PBD::warning << string_compose (_("Cannot get LinuxVST information from '%1': load failed."), dllpath) << endmsg;
839 vstfx_current_loading_id = uniqueID;
841 if (!(vstfx = vstfx_instantiate (h, simple_master_callback, 0))) {
843 PBD::warning << string_compose (_("Cannot get LinuxVST information from '%1': instantiation failed."), dllpath) << endmsg;
847 vstfx_current_loading_id = 0;
849 vstfx_info_from_plugin (dllpath, vstfx, infos, ARDOUR::LXVST);
856 #ifdef WINDOWS_VST_SUPPORT
858 vstfx_instantiate_and_get_info_fst (
859 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
863 if (!(h = fst_load (dllpath))) {
864 PBD::warning << string_compose (_("Cannot get Windows VST information from '%1': load failed."), dllpath) << endmsg;
868 vstfx_current_loading_id = uniqueID;
870 if (!(vstfx = fst_instantiate (h, simple_master_callback, 0))) {
872 vstfx_current_loading_id = 0;
873 PBD::warning << string_compose (_("Cannot get Windows VST information from '%1': instantiation failed."), dllpath) << endmsg;
876 vstfx_current_loading_id = 0;
878 vstfx_info_from_plugin (dllpath, vstfx, infos, ARDOUR::Windows_VST);
884 #ifdef MACVST_SUPPORT
886 vstfx_instantiate_and_get_info_mac (
887 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
889 printf("vstfx_instantiate_and_get_info_mac %s\n", dllpath);
892 if (!(h = mac_vst_load (dllpath))) {
893 PBD::warning << string_compose (_("Cannot get MacVST information from '%1': load failed."), dllpath) << endmsg;
897 vstfx_current_loading_id = uniqueID;
899 if (!(vstfx = mac_vst_instantiate (h, simple_master_callback, 0))) {
901 PBD::warning << string_compose (_("Cannot get MacVST information from '%1': instantiation failed."), dllpath) << endmsg;
905 vstfx_current_loading_id = 0;
907 vstfx_info_from_plugin (dllpath, vstfx, infos, ARDOUR::MacVST);
914 /* *** ERROR LOGGING *** */
915 #ifndef VST_SCANNER_APP
917 static FILE * _errorlog_fd = 0;
918 static char * _errorlog_dll = 0;
920 static void parse_scanner_output (std::string msg, size_t /*len*/)
922 if (!_errorlog_fd && !_errorlog_dll) {
923 PBD::error << "VST scanner: " << msg;
929 if (!(_errorlog_fd = g_fopen (vstfx_errorfile_path (_errorlog_dll).c_str (), "w"))) {
930 PBD::error << "Cannot create plugin error-log for plugin " << _errorlog_dll;
931 free (_errorlog_dll);
932 _errorlog_dll = NULL;
938 fprintf (_errorlog_fd, "%s\n", msg.c_str ());
939 } else if (_errorlog_dll) {
940 PBD::error << "VST '" << _errorlog_dll << "': " << msg;
942 PBD::error << "VST scanner: " << msg;
947 set_error_log (const char* dllpath) {
948 assert (!_errorlog_fd);
949 assert (!_errorlog_dll);
950 _errorlog_dll = strdup (dllpath);
956 fclose (_errorlog_fd);
959 free (_errorlog_dll);
966 /* *** the main function that uses all of the above *** */
968 static vector<VSTInfo *> *
969 vstfx_get_info (const char* dllpath, enum ARDOUR::PluginType type, enum VSTScanMode mode)
972 vector<VSTInfo*> *infos = new vector<VSTInfo*>;
974 if (vst_is_blacklisted (dllpath)) {
978 if (vstfx_get_info_from_file (dllpath, infos)) {
982 #ifndef VST_SCANNER_APP
983 std::string scanner_bin_path = ARDOUR::PluginManager::scanner_bin_path;
985 if (mode == VST_SCAN_CACHE_ONLY) {
986 /* never scan explicitly, use cache only */
989 else if (mode == VST_SCAN_USE_APP && scanner_bin_path != "") {
990 /* use external scanner app */
992 char **argp= (char**) calloc (3,sizeof (char*));
993 argp[0] = strdup (scanner_bin_path.c_str ());
994 argp[1] = strdup (dllpath);
997 set_error_log (dllpath);
998 ARDOUR::SystemExec scanner (scanner_bin_path, argp);
999 PBD::ScopedConnectionList cons;
1000 scanner.ReadStdout.connect_same_thread (cons, boost::bind (&parse_scanner_output, _1 ,_2));
1001 if (scanner.start (2 /* send stderr&stdout via signal */)) {
1002 PBD::error << string_compose (_("Cannot launch VST scanner app '%1': %2"), scanner_bin_path, strerror (errno)) << endmsg;
1006 int timeout = PLUGIN_SCAN_TIMEOUT;
1007 bool no_timeout = (timeout <= 0);
1008 ARDOUR::PluginScanTimeout (timeout);
1009 while (scanner.is_running () && (no_timeout || timeout > 0)) {
1010 if (!no_timeout && !ARDOUR::PluginManager::instance ().no_timeout ()) {
1011 if (timeout%5 == 0) {
1012 ARDOUR::PluginScanTimeout (timeout);
1017 Glib::usleep (100000);
1019 if (ARDOUR::PluginManager::instance ().cancelled ()) {
1020 // remove info file (might be incomplete)
1021 vstfx_remove_infofile (dllpath);
1022 // remove temporary blacklist file (scan incomplete)
1023 vstfx_un_blacklist (dllpath);
1024 scanner.terminate ();
1029 scanner.terminate ();
1032 /* re-read index (generated by external scanner) */
1033 vstfx_clear_info_list (infos);
1034 if (!vst_is_blacklisted (dllpath)) {
1035 vstfx_get_info_from_file (dllpath, infos);
1039 /* else .. instantiate and check in in ardour process itself */
1041 (void) mode; // unused parameter
1045 /* blacklist in case instantiation fails */
1046 vstfx_blacklist (dllpath);
1049 #ifdef WINDOWS_VST_SUPPORT
1050 case ARDOUR::Windows_VST:
1051 ok = vstfx_instantiate_and_get_info_fst (dllpath, infos, 0);
1054 #ifdef LXVST_SUPPORT
1056 ok = vstfx_instantiate_and_get_info_lx (dllpath, infos, 0);
1059 #ifdef MACVST_SUPPORT
1060 case ARDOUR::MacVST:
1061 ok = vstfx_instantiate_and_get_info_mac (dllpath, infos, 0);
1073 /* remove from blacklist */
1074 vstfx_un_blacklist (dllpath);
1076 /* crate cache/whitelist */
1077 infofile = vstfx_infofile_for_write (dllpath);
1079 PBD::warning << string_compose (_("Cannot cache VST information for '%1': cannot create cache file."), dllpath) << endmsg;
1082 vstfx_write_info_file (infofile, infos);
1085 /* In some cases the .dll may have a modification time in the future,
1086 * (e.g. unzip a VST plugin: .zip files don't include timezones)
1088 string const fsipath = vstfx_infofile_path (dllpath);
1091 if (g_stat (dllpath, &dllstat) == 0 && g_stat (fsipath.c_str (), &fsistat) == 0) {
1093 utb.actime = fsistat.st_atime;
1094 utb.modtime = std::max (dllstat.st_mtime, fsistat.st_mtime);
1095 g_utime (fsipath.c_str (), &utb);
1102 /* *** public API *** */
1105 vstfx_free_info_list (vector<VSTInfo *> *infos)
1107 for (vector<VSTInfo *>::iterator i = infos->begin (); i != infos->end (); ++i) {
1108 vstfx_free_info (*i);
1113 #ifdef LXVST_SUPPORT
1115 vstfx_get_info_lx (char* dllpath, enum VSTScanMode mode)
1117 return vstfx_get_info (dllpath, ARDOUR::LXVST, mode);
1121 #ifdef MACVST_SUPPORT
1123 vstfx_get_info_mac (char* dllpath, enum VSTScanMode mode)
1125 return vstfx_get_info (dllpath, ARDOUR::MacVST, mode);
1129 #ifdef WINDOWS_VST_SUPPORT
1131 vstfx_get_info_fst (char* dllpath, enum VSTScanMode mode)
1133 return vstfx_get_info (dllpath, ARDOUR::Windows_VST, mode);
1137 #ifndef VST_SCANNER_APP