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>
38 #include "pbd/gstdio_compat.h"
41 #include "pbd/error.h"
42 #include "pbd/compose.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/mac_vst_support.h"
53 #include "ardour/plugin_types.h"
54 #include "ardour/vst_info_file.h"
59 #define MAX_STRING_LEN 256
60 #define PLUGIN_SCAN_TIMEOUT (Config->get_vst_scan_timeout()) // in deciseconds
63 #ifndef VST_SCANNER_APP
68 #ifdef WINDOWS_VST_SUPPORT
71 vstfx_instantiate_and_get_info_fst (const char* dllpath, vector<VSTInfo*> *infos, int uniqueID);
75 static bool vstfx_instantiate_and_get_info_lx (const char* dllpath, vector<VSTInfo*> *infos, int uniqueID);
79 static bool vstfx_instantiate_and_get_info_mac (const char* dllpath, vector<VSTInfo*> *infos, int uniqueID);
82 /* ID for shell plugins */
83 static int vstfx_current_loading_id = 0;
85 /* *** CACHE FILE PATHS *** */
88 get_vst_info_cache_dir () {
89 string dir = Glib::build_filename (ARDOUR::user_cache_directory (), "vst");
90 /* if the directory doesn't exist, try to create it */
91 if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
92 if (g_mkdir (dir.c_str (), 0700)) {
93 PBD::fatal << "Cannot create VST info folder '" << dir << "'" << endmsg;
100 vstfx_infofile_path (const char* dllpath)
105 sha1_write (&s, (const uint8_t *) dllpath, strlen (dllpath));
106 sha1_result_hash (&s, hash);
107 return Glib::build_filename (get_vst_info_cache_dir (), std::string (hash) + std::string (VST_EXT_INFOFILE));
111 /* *** VST Blacklist *** */
113 static void vstfx_read_blacklist (std::string &bl) {
114 FILE * blacklist_fd = NULL;
117 string fn = Glib::build_filename (ARDOUR::user_cache_directory (), VST_BLACKLIST);
119 if (!Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) {
123 if (! (blacklist_fd = g_fopen (fn.c_str (), "rb"))) {
127 while (!feof (blacklist_fd)) {
129 size_t s = fread (buf, sizeof(char), 1024, blacklist_fd);
130 if (ferror (blacklist_fd)) {
131 PBD::error << string_compose (_("error reading VST Blacklist file %1 (%2)"), fn, strerror (errno)) << endmsg;
140 ::fclose (blacklist_fd);
143 /** mark plugin as blacklisted */
144 static void vstfx_blacklist (const char *id)
146 string fn = Glib::build_filename (ARDOUR::user_cache_directory (), VST_BLACKLIST);
147 FILE * blacklist_fd = NULL;
148 if (! (blacklist_fd = g_fopen (fn.c_str (), "a"))) {
149 PBD::error << string_compose (_("Cannot append to VST blacklist for '%1'"), id) << endmsg;
152 assert (NULL == strchr (id, '\n'));
153 fprintf (blacklist_fd, "%s\n", id);
154 ::fclose (blacklist_fd);
157 /** mark plugin as not blacklisted */
158 static void vstfx_un_blacklist (const char *idcs)
161 string fn = Glib::build_filename (ARDOUR::user_cache_directory (), VST_BLACKLIST);
162 if (!Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) {
163 PBD::warning << _("Expected VST Blacklist file does not exist.") << endmsg;
168 vstfx_read_blacklist (bl);
170 ::g_unlink (fn.c_str ());
172 assert (!Glib::file_test (fn, Glib::FILE_TEST_EXISTS));
173 assert (id.find ("\n") == string::npos);
175 id += "\n"; // add separator
176 const size_t rpl = bl.find (id);
177 if (rpl != string::npos) {
178 bl.replace (rpl, id.size (), "");
184 FILE * blacklist_fd = NULL;
185 if (! (blacklist_fd = g_fopen (fn.c_str (), "w"))) {
186 PBD::error << _("Cannot open VST blacklist.") << endmsg;;
189 fprintf (blacklist_fd, "%s", bl.c_str ());
190 ::fclose (blacklist_fd);
193 /* return true if plugin is blacklisted */
194 static bool vst_is_blacklisted (const char *idcs)
196 // TODO ideally we'd also check if the VST has been updated since blacklisting
198 string fn = Glib::build_filename (ARDOUR::user_cache_directory (), VST_BLACKLIST);
199 if (!Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) {
204 vstfx_read_blacklist (bl);
206 assert (id.find ("\n") == string::npos);
208 id += "\n"; // add separator
209 const size_t rpl = bl.find (id);
210 if (rpl != string::npos) {
218 /* *** MEMORY MANAGEMENT *** */
220 /** cleanup single allocated VSTInfo */
222 vstfx_free_info (VSTInfo *info)
224 for (int i = 0; i < info->numParams; i++) {
225 free (info->ParamNames[i]);
226 free (info->ParamLabels[i]);
230 free (info->creator);
231 free (info->Category);
232 free (info->ParamNames);
233 free (info->ParamLabels);
239 vstfx_clear_info_list (vector<VSTInfo *> *infos)
241 for (vector<VSTInfo *>::iterator i = infos->begin (); i != infos->end (); ++i) {
242 vstfx_free_info (*i);
248 /* *** CACHE FILE I/O *** */
250 /** Helper function to read a line from the cache file
251 * @return newly allocated string of NULL
254 read_string (FILE *fp)
256 char buf[MAX_STRING_LEN];
258 if (!fgets (buf, MAX_STRING_LEN, fp)) {
262 if (strlen (buf) < MAX_STRING_LEN) {
264 buf[strlen (buf)-1] = 0;
272 /** Read an integer value from a line in fp into n,
273 * @return true on failure, false on success.
276 read_int (FILE* fp, int* n)
278 char buf[MAX_STRING_LEN];
280 char* p = fgets (buf, MAX_STRING_LEN, fp);
285 return (sscanf (p, "%d", n) != 1);
288 /** parse a plugin-block from the cache info file */
290 vstfx_load_info_block (FILE* fp, VSTInfo *info)
292 if ((info->name = read_string (fp)) == 0) return false;
293 if ((info->creator = read_string (fp)) == 0) return false;
294 if (read_int (fp, &info->UniqueID)) return false;
295 if ((info->Category = read_string (fp)) == 0) return false;
296 if (read_int (fp, &info->numInputs)) return false;
297 if (read_int (fp, &info->numOutputs)) return false;
298 if (read_int (fp, &info->numParams)) return false;
299 if (read_int (fp, &info->wantMidi)) return false;
300 if (read_int (fp, &info->hasEditor)) return false;
301 if (read_int (fp, &info->canProcessReplacing)) return false;
303 /* backwards compatibility with old .fsi files */
304 if (info->wantMidi == -1) {
308 // TODO read isInstrument -- effFlagsIsSynth
309 info->isInstrument = info->numInputs == 0 && info->numOutputs > 0 && 1 == (info->wantMidi & 1);
310 if (!strcmp (info->Category, "Synth")) {
311 info->isInstrument = true;
314 if ((info->numParams) == 0) {
315 info->ParamNames = NULL;
316 info->ParamLabels = NULL;
320 if ((info->ParamNames = (char **) malloc (sizeof (char*) * info->numParams)) == 0) {
324 for (int i = 0; i < info->numParams; ++i) {
325 if ((info->ParamNames[i] = read_string (fp)) == 0) return false;
328 if ((info->ParamLabels = (char **) malloc (sizeof (char*) * info->numParams)) == 0) {
332 for (int i = 0; i < info->numParams; ++i) {
333 if ((info->ParamLabels[i] = read_string (fp)) == 0) {
340 /** parse all blocks in a cache info file */
342 vstfx_load_info_file (FILE* fp, vector<VSTInfo*> *infos)
345 if ((info = (VSTInfo*) calloc (1, sizeof (VSTInfo))) == 0) {
348 if (vstfx_load_info_block (fp, info)) {
349 if (strncmp (info->Category, "Shell", 5)) {
350 infos->push_back (info);
353 vstfx_free_info (info);
354 if (!read_int (fp, &plugin_cnt)) {
355 for (int i = 0; i < plugin_cnt; i++) {
356 if ((info = (VSTInfo*) calloc (1, sizeof (VSTInfo))) == 0) {
357 vstfx_clear_info_list (infos);
360 if (vstfx_load_info_block (fp, info)) {
361 infos->push_back (info);
363 vstfx_free_info (info);
364 vstfx_clear_info_list (infos);
369 return false; /* Bad file */
374 vstfx_free_info (info);
375 vstfx_clear_info_list (infos);
380 vstfx_write_info_block (FILE* fp, VSTInfo *info)
385 fprintf (fp, "%s\n", info->name);
386 fprintf (fp, "%s\n", info->creator);
387 fprintf (fp, "%d\n", info->UniqueID);
388 fprintf (fp, "%s\n", info->Category);
389 fprintf (fp, "%d\n", info->numInputs);
390 fprintf (fp, "%d\n", info->numOutputs);
391 fprintf (fp, "%d\n", info->numParams);
392 fprintf (fp, "%d\n", info->wantMidi);
393 fprintf (fp, "%d\n", info->hasEditor);
394 fprintf (fp, "%d\n", info->canProcessReplacing);
395 // TODO write isInstrument in a backwards compat way
397 for (int i = 0; i < info->numParams; i++) {
398 fprintf (fp, "%s\n", info->ParamNames[i]);
401 for (int i = 0; i < info->numParams; i++) {
402 fprintf (fp, "%s\n", info->ParamLabels[i]);
407 vstfx_write_info_file (FILE* fp, vector<VSTInfo *> *infos)
412 if (infos->size () > 1) {
413 vector<VSTInfo *>::iterator x = infos->begin ();
414 /* write out the shell info first along with count of the number of
415 * plugins contained in this shell
417 vstfx_write_info_block (fp, *x);
418 fprintf (fp, "%d\n", (int)infos->size () - 1 );
420 /* Now write out the info for each plugin */
421 for (; x != infos->end (); ++x) {
422 vstfx_write_info_block (fp, *x);
424 } else if (infos->size () == 1) {
425 vstfx_write_info_block (fp, infos->front ());
427 PBD::warning << _("VST object file contains no plugins.") << endmsg;
432 /* *** CACHE MANAGEMENT *** */
434 /** remove info file from cache */
436 vstfx_remove_infofile (const char *dllpath)
438 ::g_unlink (vstfx_infofile_path (dllpath).c_str ());
441 /** cache file for given plugin
442 * @return FILE of the .fsi cache if found and up-to-date*/
444 vstfx_infofile_for_read (const char* dllpath)
446 const size_t slen = strlen (dllpath);
448 (slen <= 3 || g_ascii_strcasecmp (&dllpath[slen-3], ".so"))
450 (slen <= 4 || g_ascii_strcasecmp (&dllpath[slen-4], ".vst"))
452 (slen <= 4 || g_ascii_strcasecmp (&dllpath[slen-4], ".dll"))
457 string const path = vstfx_infofile_path (dllpath);
459 if (Glib::file_test (path, Glib::FileTest (Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR))) {
463 if (g_stat (dllpath, &dllstat) == 0) {
464 if (g_stat (path.c_str (), &fsistat) == 0) {
465 if (dllstat.st_mtime <= fsistat.st_mtime) {
466 /* plugin is older than info file */
467 return g_fopen (path.c_str (), "rb");
471 PBD::warning << string_compose (_("Ignored VST plugin which is newer than cache: '%1' (cache: '%2')"), dllpath, path) << endmsg;
472 PBD::info << _("Re-Scan Plugins (Preferences > Plugins) to update the cache, also make sure your system-time is set correctly.") << endmsg;
477 /** newly created cache file for given plugin
478 * @return FILE for the .fsi cache or NULL on error
481 vstfx_infofile_for_write (const char* dllpath)
483 const size_t slen = strlen (dllpath);
485 (slen <= 3 || g_ascii_strcasecmp (&dllpath[slen-3], ".so"))
487 (slen <= 4 || g_ascii_strcasecmp (&dllpath[slen-4], ".vst"))
489 (slen <= 4 || g_ascii_strcasecmp (&dllpath[slen-4], ".dll"))
494 string const path = vstfx_infofile_path (dllpath);
495 return g_fopen (path.c_str (), "wb");
498 /** check if cache-file exists, is up-to-date and parse cache file
499 * @param infos [return] loaded plugin info
500 * @return true if .fsi cache was read successfully, false otherwise
503 vstfx_get_info_from_file (const char* dllpath, vector<VSTInfo*> *infos)
507 if ((infofile = vstfx_infofile_for_read (dllpath)) != 0) {
508 rv = vstfx_load_info_file (infofile, infos);
511 PBD::warning << string_compose (_("Cannot get VST information for '%1': failed to load cache file."), dllpath) << endmsg;
519 /* *** VST system-under-test methods *** */
522 bool vstfx_midi_input (VSTState* vstfx)
524 AEffect* plugin = vstfx->plugin;
526 int const vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, 0, 0.0f);
528 if (vst_version >= 2) {
529 /* should we send it VST events (i.e. MIDI) */
531 if ((plugin->flags & effFlagsIsSynth)
532 || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("receiveVstEvents"), 0.0f) > 0)
533 || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("receiveVstMidiEvents"), 0.0f) > 0)
543 bool vstfx_midi_output (VSTState* vstfx)
545 AEffect* plugin = vstfx->plugin;
547 int const vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, 0, 0.0f);
549 if (vst_version >= 2) {
550 /* should we send it VST events (i.e. MIDI) */
552 if ( (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("sendVstEvents"), 0.0f) > 0)
553 || (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("sendVstMidiEvent"), 0.0f) > 0)
562 /** simple 'dummy' audiomaster callback to instantiate the plugin
563 * and query information
566 simple_master_callback (AEffect *, int32_t opcode, int32_t, intptr_t, void *ptr, float)
568 const char* vstfx_can_do_strings[] = {
574 "receiveVstMidiEvent",
579 const int vstfx_can_do_string_count = 9;
581 if (opcode == audioMasterVersion) {
584 else if (opcode == audioMasterCanDo) {
585 for (int i = 0; i < vstfx_can_do_string_count; i++) {
586 if (! strcmp (vstfx_can_do_strings[i], (const char*)ptr)) {
592 else if (opcode == audioMasterCurrentId) {
593 return vstfx_current_loading_id;
601 /** main plugin query and test function */
603 vstfx_parse_vst_state (VSTState* vstfx)
607 VSTInfo* info = (VSTInfo*) malloc (sizeof (VSTInfo));
612 /* We need to init the creator because some plugins
613 * fail to implement getVendorString, and so won't stuff the
614 * string with any name */
616 char creator[65] = "Unknown";
619 AEffect* plugin = vstfx->plugin;
622 plugin->dispatcher (plugin, effGetEffectName, 0, 0, name, 0);
624 if (strlen (name) == 0) {
625 plugin->dispatcher (plugin, effGetProductString, 0, 0, name, 0);
628 if (strlen (name) == 0) {
629 info->name = strdup (vstfx->handle->name);
631 info->name = strdup (name);
634 /*If the plugin doesn't bother to implement GetVendorString we will
635 * have pre-stuffed the string with 'Unknown' */
637 plugin->dispatcher (plugin, effGetVendorString, 0, 0, creator, 0);
639 /* Some plugins DO implement GetVendorString, but DON'T put a name in it
640 * so if its just a zero length string we replace it with 'Unknown' */
642 if (strlen (creator) == 0) {
643 info->creator = strdup ("Unknown");
645 info->creator = strdup (creator);
649 switch (plugin->dispatcher (plugin, effGetPlugCategory, 0, 0, 0, 0))
651 case kPlugCategEffect: info->Category = strdup ("Effect"); break;
652 case kPlugCategSynth: info->Category = strdup ("Instrument"); break;
653 case kPlugCategAnalysis: info->Category = strdup ("Analyser"); break;
654 case kPlugCategMastering: info->Category = strdup ("Mastering"); break;
655 case kPlugCategSpacializer: info->Category = strdup ("Spatial"); break;
656 case kPlugCategRoomFx: info->Category = strdup ("RoomFx"); break;
657 case kPlugSurroundFx: info->Category = strdup ("SurroundFx"); break;
658 case kPlugCategRestoration: info->Category = strdup ("Restoration"); break;
659 case kPlugCategOfflineProcess: info->Category = strdup ("Offline"); break;
660 case kPlugCategShell: info->Category = strdup ("Shell"); break;
661 case kPlugCategGenerator: info->Category = strdup ("Generator"); break;
662 default: info->Category = strdup ("Unknown"); break;
665 info->UniqueID = plugin->uniqueID;
667 info->numInputs = plugin->numInputs;
668 info->numOutputs = plugin->numOutputs;
669 info->numParams = plugin->numParams;
670 info->wantMidi = (vstfx_midi_input (vstfx) ? 1 : 0) | (vstfx_midi_output (vstfx) ? 2 : 0);
671 info->hasEditor = plugin->flags & effFlagsHasEditor ? true : false;
672 info->isInstrument = (plugin->flags & effFlagsIsSynth) ? 1 : 0;
673 info->canProcessReplacing = plugin->flags & effFlagsCanReplacing ? true : false;
674 info->ParamNames = (char **) malloc (sizeof (char*)*info->numParams);
675 info->ParamLabels = (char **) malloc (sizeof (char*)*info->numParams);
678 if (info->hasEditor) {
679 /* we only support Cocoa UIs (just like Reaper) */
680 info->hasEditor = (plugin->dispatcher (plugin, effCanDo, 0, 0, const_cast<char*> ("hasCockosViewAsConfig"), 0.0f) & 0xffff0000) == 0xbeef0000;
684 for (int i = 0; i < info->numParams; ++i) {
685 char name[VestigeMaxLabelLen];
686 char label[VestigeMaxLabelLen];
688 /* Not all plugins give parameters labels as well as names */
690 strcpy (name, "No Name");
691 strcpy (label, "No Label");
693 plugin->dispatcher (plugin, effGetParamName, i, 0, name, 0);
694 info->ParamNames[i] = strdup (name);
696 //NOTE: 'effGetParamLabel' is no longer defined in vestige headers
697 //plugin->dispatcher (plugin, effGetParamLabel, i, 0, label, 0);
698 info->ParamLabels[i] = strdup (label);
703 /** wrapper around \ref vstfx_parse_vst_state,
704 * iterate over plugins in shell, translate VST-info into ardour VSTState
707 vstfx_info_from_plugin (const char *dllpath, VSTState* vstfx, vector<VSTInfo *> *infos, enum ARDOUR::PluginType type)
712 if (!(info = vstfx_parse_vst_state (vstfx))) {
716 infos->push_back (info);
717 #if 1 // shell-plugin support
718 /* If this plugin is a Shell and we are not already inside a shell plugin
719 * read the info for all of the plugins contained in this shell.
721 if (!strncmp (info->Category, "Shell", 5)
722 && vstfx->handle->plugincnt == 1) {
724 vector< pair<int, string> > ids;
725 AEffect *plugin = vstfx->plugin;
728 char name[65] = "Unknown";
729 id = plugin->dispatcher (plugin, effShellGetNextPlugin, 0, 0, name, 0);
730 ids.push_back (std::make_pair (id, name));
734 #ifdef WINDOWS_VST_SUPPORT
735 case ARDOUR::Windows_VST:
744 #ifdef MACVST_SUPPORT
746 mac_vst_close (vstfx);
754 for (vector< pair<int, string> >::iterator x = ids.begin (); x != ids.end (); ++x) {
756 if (id == 0) continue;
757 /* recurse vstfx_get_info() */
761 #ifdef WINDOWS_VST_SUPPORT
762 case ARDOUR::Windows_VST:
763 ok = vstfx_instantiate_and_get_info_fst (dllpath, infos, id);
768 ok = vstfx_instantiate_and_get_info_lx (dllpath, infos, id);
771 #ifdef MACVST_SUPPORT
773 ok = vstfx_instantiate_and_get_info_mac (dllpath, infos, id);
781 // One shell (some?, all?) does not report the actual plugin name
782 // even after the shelled plugin has been instantiated.
783 // Replace the name of the shell with the real name.
784 info = infos->back ();
787 if ((*x).second.length () == 0) {
788 info->name = strdup ("Unknown");
791 info->name = strdup ((*x).second.c_str ());
797 #ifdef WINDOWS_VST_SUPPORT
798 case ARDOUR::Windows_VST:
807 #ifdef MACVST_SUPPORT
809 mac_vst_close (vstfx);
822 /* *** TOP-LEVEL PLUGIN INSTANTIATION FUNCTIONS *** */
826 vstfx_instantiate_and_get_info_lx (
827 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
831 if (!(h = vstfx_load (dllpath))) {
832 PBD::warning << string_compose (_("Cannot get LinuxVST information from '%1': load failed."), dllpath) << endmsg;
836 vstfx_current_loading_id = uniqueID;
838 if (!(vstfx = vstfx_instantiate (h, simple_master_callback, 0))) {
840 PBD::warning << string_compose (_("Cannot get LinuxVST information from '%1': instantiation failed."), dllpath) << endmsg;
844 vstfx_current_loading_id = 0;
846 vstfx_info_from_plugin (dllpath, vstfx, infos, ARDOUR::LXVST);
853 #ifdef WINDOWS_VST_SUPPORT
855 vstfx_instantiate_and_get_info_fst (
856 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
860 if (!(h = fst_load (dllpath))) {
861 PBD::warning << string_compose (_("Cannot get Windows VST information from '%1': load failed."), dllpath) << endmsg;
865 vstfx_current_loading_id = uniqueID;
867 if (!(vstfx = fst_instantiate (h, simple_master_callback, 0))) {
869 vstfx_current_loading_id = 0;
870 PBD::warning << string_compose (_("Cannot get Windows VST information from '%1': instantiation failed."), dllpath) << endmsg;
873 vstfx_current_loading_id = 0;
875 vstfx_info_from_plugin (dllpath, vstfx, infos, ARDOUR::Windows_VST);
881 #ifdef MACVST_SUPPORT
883 vstfx_instantiate_and_get_info_mac (
884 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
886 printf("vstfx_instantiate_and_get_info_mac %s\n", dllpath);
889 if (!(h = mac_vst_load (dllpath))) {
890 PBD::warning << string_compose (_("Cannot get MacVST information from '%1': load failed."), dllpath) << endmsg;
894 vstfx_current_loading_id = uniqueID;
896 if (!(vstfx = mac_vst_instantiate (h, simple_master_callback, 0))) {
898 PBD::warning << string_compose (_("Cannot get MacVST information from '%1': instantiation failed."), dllpath) << endmsg;
902 vstfx_current_loading_id = 0;
904 vstfx_info_from_plugin (dllpath, vstfx, infos, ARDOUR::MacVST);
911 /* *** ERROR LOGGING *** */
912 #ifndef VST_SCANNER_APP
914 static FILE * _errorlog_fd = 0;
915 static char * _errorlog_dll = 0;
917 static void parse_scanner_output (std::string msg, size_t /*len*/)
919 if (!_errorlog_fd && !_errorlog_dll) {
920 PBD::error << "VST scanner: " << msg;
926 if (!(_errorlog_fd = g_fopen (vstfx_errorfile_path (_errorlog_dll).c_str (), "w"))) {
927 PBD::error << "Cannot create plugin error-log for plugin " << _errorlog_dll;
928 free (_errorlog_dll);
929 _errorlog_dll = NULL;
935 fprintf (_errorlog_fd, "%s\n", msg.c_str ());
936 } else if (_errorlog_dll) {
937 PBD::error << "VST '" << _errorlog_dll << "': " << msg;
939 PBD::error << "VST scanner: " << msg;
944 set_error_log (const char* dllpath) {
945 assert (!_errorlog_fd);
946 assert (!_errorlog_dll);
947 _errorlog_dll = strdup (dllpath);
953 fclose (_errorlog_fd);
956 free (_errorlog_dll);
963 /* *** the main function that uses all of the above *** */
965 static vector<VSTInfo *> *
966 vstfx_get_info (const char* dllpath, enum ARDOUR::PluginType type, enum VSTScanMode mode)
969 vector<VSTInfo*> *infos = new vector<VSTInfo*>;
971 if (vst_is_blacklisted (dllpath)) {
975 if (vstfx_get_info_from_file (dllpath, infos)) {
979 #ifndef VST_SCANNER_APP
980 std::string scanner_bin_path = ARDOUR::PluginManager::scanner_bin_path;
982 if (mode == VST_SCAN_CACHE_ONLY) {
983 /* never scan explicitly, use cache only */
986 else if (mode == VST_SCAN_USE_APP && scanner_bin_path != "") {
987 /* use external scanner app */
989 char **argp= (char**) calloc (3,sizeof (char*));
990 argp[0] = strdup (scanner_bin_path.c_str ());
991 argp[1] = strdup (dllpath);
994 set_error_log (dllpath);
995 ARDOUR::SystemExec scanner (scanner_bin_path, argp);
996 PBD::ScopedConnectionList cons;
997 scanner.ReadStdout.connect_same_thread (cons, boost::bind (&parse_scanner_output, _1 ,_2));
998 if (scanner.start (2 /* send stderr&stdout via signal */)) {
999 PBD::error << string_compose (_("Cannot launch VST scanner app '%1': %2"), scanner_bin_path, strerror (errno)) << endmsg;
1003 int timeout = PLUGIN_SCAN_TIMEOUT;
1004 bool no_timeout = (timeout <= 0);
1005 ARDOUR::PluginScanTimeout (timeout);
1006 while (scanner.is_running () && (no_timeout || timeout > 0)) {
1007 if (!no_timeout && !ARDOUR::PluginManager::instance ().no_timeout ()) {
1008 if (timeout%5 == 0) {
1009 ARDOUR::PluginScanTimeout (timeout);
1014 Glib::usleep (100000);
1016 if (ARDOUR::PluginManager::instance ().cancelled ()) {
1017 // remove info file (might be incomplete)
1018 vstfx_remove_infofile (dllpath);
1019 // remove temporary blacklist file (scan incomplete)
1020 vstfx_un_blacklist (dllpath);
1021 scanner.terminate ();
1026 scanner.terminate ();
1029 /* re-read index (generated by external scanner) */
1030 vstfx_clear_info_list (infos);
1031 if (!vst_is_blacklisted (dllpath)) {
1032 vstfx_get_info_from_file (dllpath, infos);
1036 /* else .. instantiate and check in in ardour process itself */
1038 (void) mode; // unused parameter
1042 /* blacklist in case instantiation fails */
1043 vstfx_blacklist (dllpath);
1046 #ifdef WINDOWS_VST_SUPPORT
1047 case ARDOUR::Windows_VST:
1048 ok = vstfx_instantiate_and_get_info_fst (dllpath, infos, 0);
1051 #ifdef LXVST_SUPPORT
1053 ok = vstfx_instantiate_and_get_info_lx (dllpath, infos, 0);
1056 #ifdef MACVST_SUPPORT
1057 case ARDOUR::MacVST:
1058 ok = vstfx_instantiate_and_get_info_mac (dllpath, infos, 0);
1070 /* remove from blacklist */
1071 vstfx_un_blacklist (dllpath);
1073 /* crate cache/whitelist */
1074 infofile = vstfx_infofile_for_write (dllpath);
1076 PBD::warning << string_compose (_("Cannot cache VST information for '%1': cannot create cache file."), dllpath) << endmsg;
1079 vstfx_write_info_file (infofile, infos);
1086 /* *** public API *** */
1089 vstfx_free_info_list (vector<VSTInfo *> *infos)
1091 for (vector<VSTInfo *>::iterator i = infos->begin (); i != infos->end (); ++i) {
1092 vstfx_free_info (*i);
1097 #ifdef LXVST_SUPPORT
1099 vstfx_get_info_lx (char* dllpath, enum VSTScanMode mode)
1101 return vstfx_get_info (dllpath, ARDOUR::LXVST, mode);
1105 #ifdef MACVST_SUPPORT
1107 vstfx_get_info_mac (char* dllpath, enum VSTScanMode mode)
1109 return vstfx_get_info (dllpath, ARDOUR::MacVST, mode);
1113 #ifdef WINDOWS_VST_SUPPORT
1115 vstfx_get_info_fst (char* dllpath, enum VSTScanMode mode)
1117 return vstfx_get_info (dllpath, ARDOUR::Windows_VST, mode);
1121 #ifndef VST_SCANNER_APP