prepare standalone VST scanner tool.. part one
[ardour.git] / libs / ardour / vst_info_file.cc
1 /*
2     Copyright (C) 2012-2014 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
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.
23  */
24
25 #include <iostream>
26 #include <cassert>
27
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <unistd.h>
31 #include <errno.h>
32
33 #include <stdlib.h>
34 #include <stddef.h>
35 #include <stdio.h>
36 #include <string.h>
37 #include <libgen.h>
38
39 #include <glib.h>
40 #include <glib/gstdio.h>
41 #include <glibmm.h>
42
43 #include "pbd/error.h"
44
45 #include "ardour/filesystem_paths.h"
46 #include "ardour/linux_vst_support.h"
47 #include "ardour/vst_info_file.h"
48
49 #define MAX_STRING_LEN 256
50
51 using namespace std;
52
53 // TODO: make static parts of this file re-usable for standalone app
54 // TODO: namespace public API into ARDOUR, ::Session or ::PluginManager
55 //       consolidate vstfx_get_info_lx() and vstfx_get_info_fst()
56
57 /* prototypes */
58 #ifdef WINDOWS_VST_SUPPORT
59 #include <fst.h>
60 static bool
61 vstfx_instantiate_and_get_info_fst (const char* dllpath, vector<VSTInfo*> *infos, int uniqueID);
62 #endif
63
64 #ifdef LXVST_SUPPORT
65 static bool vstfx_instantiate_and_get_info_lx (const char* dllpath, vector<VSTInfo*> *infos, int uniqueID);
66 #endif
67
68 static int vstfx_current_loading_id = 0;
69
70 static char *
71 read_string (FILE *fp)
72 {
73         char buf[MAX_STRING_LEN];
74
75         if (!fgets (buf, MAX_STRING_LEN, fp)) {
76                 return 0;
77         }
78
79         if (strlen(buf) < MAX_STRING_LEN) {
80                 if (strlen (buf)) {
81                         buf[strlen(buf)-1] = 0;
82                 }
83                 return strdup (buf);
84         } else {
85                 return 0;
86         }
87 }
88
89 /** Read an integer value from a line in fp into n,
90  *  @return true on failure, false on success.
91  */
92 static bool
93 read_int (FILE* fp, int* n)
94 {
95         char buf[MAX_STRING_LEN];
96
97         char* p = fgets (buf, MAX_STRING_LEN, fp);
98         if (p == 0) {
99                 return true;
100         }
101
102         return (sscanf (p, "%d", n) != 1);
103 }
104
105 static void
106 vstfx_free_info (VSTInfo *info)
107 {
108         for (int i = 0; i < info->numParams; i++) {
109                 free (info->ParamNames[i]);
110                 free (info->ParamLabels[i]);
111         }
112
113         free (info->name);
114         free (info->creator);
115         free (info->Category);
116         free (info->ParamNames);
117         free (info->ParamLabels);
118         free (info);
119 }
120
121 static void
122 vstfx_clear_info_list (vector<VSTInfo *> *infos)
123 {
124         for (vector<VSTInfo *>::iterator i = infos->begin(); i != infos->end(); ++i) {
125                 vstfx_free_info(*i);
126         }
127         infos->clear();
128 }
129
130 static bool
131 vstfx_load_info_block(FILE* fp, VSTInfo *info)
132 {
133         if ((info->name = read_string(fp)) == 0) return false;
134         if ((info->creator = read_string(fp)) == 0) return false;
135         if (read_int (fp, &info->UniqueID)) return false;
136         if ((info->Category = read_string(fp)) == 0) return false;
137         if (read_int (fp, &info->numInputs)) return false;
138         if (read_int (fp, &info->numOutputs)) return false;
139         if (read_int (fp, &info->numParams)) return false;
140         if (read_int (fp, &info->wantMidi)) return false;
141         if (read_int (fp, &info->hasEditor)) return false;
142         if (read_int (fp, &info->canProcessReplacing)) return false;
143
144         if ((info->ParamNames = (char **) malloc(sizeof(char*)*info->numParams)) == 0) {
145                 return false;
146         }
147
148         for (int i = 0; i < info->numParams; ++i) {
149                 if ((info->ParamNames[i] = read_string(fp)) == 0) return false;
150         }
151
152         if ((info->ParamLabels = (char **) malloc(sizeof(char*)*info->numParams)) == 0) {
153                 return false;
154         }
155
156         for (int i = 0; i < info->numParams; ++i) {
157                 if ((info->ParamLabels[i] = read_string(fp)) == 0) {
158                         return false;
159                 }
160         }
161         return true;
162 }
163
164 static bool
165 vstfx_load_info_file (FILE* fp, vector<VSTInfo*> *infos)
166 {
167         VSTInfo *info;
168         if ((info = (VSTInfo*) calloc (1, sizeof (VSTInfo))) == 0) {
169                 return false;
170         }
171         if (vstfx_load_info_block(fp, info)) {
172                 if (strncmp (info->Category, "Shell", 5)) {
173                         infos->push_back(info);
174                 } else {
175                         int plugin_cnt = 0;
176                         vstfx_free_info(info);
177                         if (read_int (fp, &plugin_cnt)) {
178                                 for (int i = 0; i < plugin_cnt; i++) {
179                                         if ((info = (VSTInfo*) calloc (1, sizeof (VSTInfo))) == 0) {
180                                                 vstfx_clear_info_list(infos);
181                                                 return false;
182                                         }
183                                         if (vstfx_load_info_block(fp, info)) {
184                                                 infos->push_back(info);
185                                         } else {
186                                                 vstfx_free_info(info);
187                                                 vstfx_clear_info_list(infos);
188                                                 return false;
189                                         }
190                                 }
191                         } else {
192                                 return false; /* Bad file */
193                         }
194                 }
195                 return true;
196         }
197         vstfx_free_info(info);
198         vstfx_clear_info_list(infos);
199         return false;
200 }
201
202 static void
203 vstfx_write_info_block (FILE* fp, VSTInfo *info)
204 {
205         assert (info);
206         assert (fp);
207
208         fprintf (fp, "%s\n", info->name);
209         fprintf (fp, "%s\n", info->creator);
210         fprintf (fp, "%d\n", info->UniqueID);
211         fprintf (fp, "%s\n", info->Category);
212         fprintf (fp, "%d\n", info->numInputs);
213         fprintf (fp, "%d\n", info->numOutputs);
214         fprintf (fp, "%d\n", info->numParams);
215         fprintf (fp, "%d\n", info->wantMidi);
216         fprintf (fp, "%d\n", info->hasEditor);
217         fprintf (fp, "%d\n", info->canProcessReplacing);
218
219         for (int i = 0; i < info->numParams; i++) {
220                 fprintf (fp, "%s\n", info->ParamNames[i]);
221         }
222
223         for (int i = 0; i < info->numParams; i++) {
224                 fprintf (fp, "%s\n", info->ParamLabels[i]);
225         }
226 }
227
228 static void
229 vstfx_write_info_file (FILE* fp, vector<VSTInfo *> *infos)
230 {
231         assert(infos);
232         assert(fp);
233
234         if (infos->size() > 1) {
235                 vector<VSTInfo *>::iterator x = infos->begin();
236                 /* write out the shell info first along with count of the number of
237                  * plugins contained in this shell
238                  */
239                 vstfx_write_info_block(fp, *x);
240                 fprintf( fp, "%d\n", (int)infos->size() - 1 );
241                 ++x;
242                 /* Now write out the info for each plugin */
243                 for (; x != infos->end(); ++x) {
244                         vstfx_write_info_block(fp, *x);
245                 }
246         } else if (infos->size() == 1) {
247                 vstfx_write_info_block(fp, infos->front());
248         } else {
249                 PBD::error << "Zero plugins in VST." << endmsg; // XXX here? rather make this impossible before if it ain't already.
250         }
251 }
252
253 static string
254 vstfx_blacklist_path (const char* dllpath, int personal)
255 {
256         string dir;
257         if (personal) {
258                 dir = get_personal_vst_blacklist_dir();
259         } else {
260                 dir = Glib::path_get_dirname (std::string(dllpath));
261         }
262
263         stringstream s;
264         s << "." << Glib::path_get_basename (dllpath) << ".fsb";
265         return Glib::build_filename (dir, s.str ());
266 }
267
268 /* return true if plugin is blacklisted or has an invalid file extension */
269 static bool
270 vstfx_blacklist_stat (const char *dllpath, int personal)
271 {
272         if (strstr (dllpath, ".so" ) == 0 && strstr(dllpath, ".dll") == 0) {
273                 return true;
274         }
275         string const path = vstfx_blacklist_path (dllpath, personal);
276
277         if (Glib::file_test (path, Glib::FileTest (Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR))) {
278                 struct stat dllstat;
279                 struct stat fsbstat;
280
281                 if (stat (dllpath, &dllstat) == 0 && stat (path.c_str(), &fsbstat) == 0) {
282                         if (dllstat.st_mtime > fsbstat.st_mtime) {
283                                 /* plugin is newer than blacklist file */
284                                 return true;
285                         }
286                 }
287                 /* stat failed or plugin is older than blacklist file */
288                 return true;
289         }
290         /* blacklist file does not exist */
291         return false;
292 }
293
294 static bool
295 vstfx_check_blacklist (const char *dllpath)
296 {
297         if (vstfx_blacklist_stat(dllpath, 0)) return true;
298         if (vstfx_blacklist_stat(dllpath, 1)) return true;
299         return false;
300 }
301
302 static FILE *
303 vstfx_blacklist_file (const char *dllpath)
304 {
305         FILE *f;
306         if ((f = fopen (vstfx_blacklist_path (dllpath, 0).c_str(), "w"))) {
307                 return f;
308         }
309         return fopen (vstfx_blacklist_path (dllpath, 1).c_str(), "w");
310 }
311
312 static bool
313 vstfx_blacklist (const char *dllpath)
314 {
315         FILE *f = vstfx_blacklist_file(dllpath);
316         if (f) {
317                 fclose(f);
318                 return true;
319         }
320         return false;
321 }
322
323 static void
324 vstfx_un_blacklist (const char *dllpath)
325 {
326         ::g_unlink(vstfx_blacklist_path (dllpath, 0).c_str());
327         ::g_unlink(vstfx_blacklist_path (dllpath, 1).c_str());
328 }
329
330 static string
331 vstfx_infofile_path (const char* dllpath, int personal)
332 {
333         string dir;
334         if (personal) {
335                 dir = get_personal_vst_info_cache_dir();
336         } else {
337                 dir = Glib::path_get_dirname (std::string(dllpath));
338         }
339
340         stringstream s;
341         s << "." << Glib::path_get_basename (dllpath) << ".fsi";
342         return Glib::build_filename (dir, s.str ());
343 }
344
345 static char *
346 vstfx_infofile_stat (const char *dllpath, struct stat* statbuf, int personal)
347 {
348         if (strstr (dllpath, ".so" ) == 0 && strstr(dllpath, ".dll") == 0) {
349                 return 0;
350         }
351
352         string const path = vstfx_infofile_path (dllpath, personal);
353
354         if (Glib::file_test (path, Glib::FileTest (Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR))) {
355
356                 struct stat dllstat;
357
358                 if (stat (dllpath, &dllstat) == 0) {
359                         if (stat (path.c_str(), statbuf) == 0) {
360                                 if (dllstat.st_mtime <= statbuf->st_mtime) {
361                                         /* plugin is older than info file */
362                                         return strdup (path.c_str ());
363                                 }
364                         }
365                 }
366         }
367
368         return 0;
369 }
370
371
372 static FILE *
373 vstfx_infofile_for_read (const char* dllpath)
374 {
375         struct stat own_statbuf;
376         struct stat sys_statbuf;
377         FILE *rv = NULL;
378
379         char* own_info = vstfx_infofile_stat (dllpath, &own_statbuf, 1);
380         char* sys_info = vstfx_infofile_stat (dllpath, &sys_statbuf, 0);
381
382         if (own_info) {
383                 if (sys_info) {
384                         if (own_statbuf.st_mtime <= sys_statbuf.st_mtime) {
385                                 /* system info file is newer, use it */
386                                 rv = g_fopen (sys_info, "rb");
387                         }
388                 } else {
389                         rv = g_fopen (own_info, "rb");
390                 }
391         } else if (sys_info) {
392                 rv = g_fopen (sys_info, "rb");
393         }
394         free(own_info);
395         free(sys_info);
396
397         return rv;
398 }
399
400 static FILE *
401 vstfx_infofile_create (const char* dllpath, int personal)
402 {
403         if (strstr (dllpath, ".so" ) == 0 && strstr(dllpath, ".dll") == 0) {
404                 return 0;
405         }
406
407         string const path = vstfx_infofile_path (dllpath, personal);
408         return fopen (path.c_str(), "w");
409 }
410
411 static FILE *
412 vstfx_infofile_for_write (const char* dllpath)
413 {
414         FILE* f;
415
416         if ((f = vstfx_infofile_create (dllpath, 0)) == 0) {
417                 f = vstfx_infofile_create (dllpath, 1);
418         }
419
420         return f;
421 }
422
423 static
424 int vstfx_can_midi (VSTState* vstfx)
425 {
426         AEffect* plugin = vstfx->plugin;
427
428         int const vst_version = plugin->dispatcher (plugin, effGetVstVersion, 0, 0, 0, 0.0f);
429
430         if (vst_version >= 2) {
431                 /* should we send it VST events (i.e. MIDI) */
432
433                 if ((plugin->flags & effFlagsIsSynth) || (plugin->dispatcher (plugin, effCanDo, 0, 0,(void*) "receiveVstEvents", 0.0f) > 0)) {
434                         return -1;
435                 }
436         }
437
438         return false;
439 }
440
441 static VSTInfo*
442 vstfx_parse_vst_state (VSTState* vstfx)
443 {
444         assert (vstfx);
445
446         VSTInfo* info = (VSTInfo*) malloc (sizeof (VSTInfo));
447         if (!info) {
448                 return 0;
449         }
450
451         /*We need to init the creator because some plugins
452           fail to implement getVendorString, and so won't stuff the
453           string with any name*/
454
455         char creator[65] = "Unknown\0";
456
457         AEffect* plugin = vstfx->plugin;
458
459         info->name = strdup (vstfx->handle->name);
460
461         /*If the plugin doesn't bother to implement GetVendorString we will
462           have pre-stuffed the string with 'Unkown' */
463
464         plugin->dispatcher (plugin, effGetVendorString, 0, 0, creator, 0);
465
466         /*Some plugins DO implement GetVendorString, but DON'T put a name in it
467           so if its just a zero length string we replace it with 'Unknown' */
468
469         if (strlen(creator) == 0) {
470                 info->creator = strdup ("Unknown");
471         } else {
472                 info->creator = strdup (creator);
473         }
474
475
476         switch (plugin->dispatcher (plugin, effGetPlugCategory, 0, 0, 0, 0))
477         {
478                 case kPlugCategEffect:         info->Category = strdup ("Effect"); break;
479                 case kPlugCategSynth:          info->Category = strdup ("Synth"); break;
480                 case kPlugCategAnalysis:       info->Category = strdup ("Anaylsis"); break;
481                 case kPlugCategMastering:      info->Category = strdup ("Mastering"); break;
482                 case kPlugCategSpacializer:    info->Category = strdup ("Spacializer"); break;
483                 case kPlugCategRoomFx:         info->Category = strdup ("RoomFx"); break;
484                 case kPlugSurroundFx:          info->Category = strdup ("SurroundFx"); break;
485                 case kPlugCategRestoration:    info->Category = strdup ("Restoration"); break;
486                 case kPlugCategOfflineProcess: info->Category = strdup ("Offline"); break;
487                 case kPlugCategShell:          info->Category = strdup ("Shell"); break;
488                 case kPlugCategGenerator:      info->Category = strdup ("Generator"); break;
489                 default:                       info->Category = strdup ("Unknown"); break;
490         }
491
492         info->UniqueID = plugin->uniqueID;
493
494         info->numInputs = plugin->numInputs;
495         info->numOutputs = plugin->numOutputs;
496         info->numParams = plugin->numParams;
497         info->wantMidi = vstfx_can_midi(vstfx);
498         info->hasEditor = plugin->flags & effFlagsHasEditor ? true : false;
499         info->canProcessReplacing = plugin->flags & effFlagsCanReplacing ? true : false;
500         info->ParamNames = (char **) malloc(sizeof(char*)*info->numParams);
501         info->ParamLabels = (char **) malloc(sizeof(char*)*info->numParams);
502
503         for (int i = 0; i < info->numParams; ++i) {
504                 char name[64];
505                 char label[64];
506
507                 /* Not all plugins give parameters labels as well as names */
508
509                 strcpy (name, "No Name");
510                 strcpy (label, "No Label");
511
512                 plugin->dispatcher (plugin, effGetParamName, i, 0, name, 0);
513                 info->ParamNames[i] = strdup(name);
514
515                 //NOTE: 'effGetParamLabel' is no longer defined in vestige headers
516                 //plugin->dispatcher (plugin, effGetParamLabel, i, 0, label, 0);
517                 info->ParamLabels[i] = strdup(label);
518         }
519         return info;
520 }
521
522 static void
523 vstfx_info_from_plugin (const char *dllpath, VSTState* vstfx, vector<VSTInfo *> *infos, int type)
524 {
525         assert(vstfx);
526         VSTInfo *info;
527
528         if ((info = vstfx_parse_vst_state(vstfx))) {
529                 infos->push_back(info);
530 #if 1
531                 /* If this plugin is a Shell and we are not already inside a shell plugin
532                  * read the info for all of the plugins contained in this shell.
533                  */
534                 if (!strncmp (info->Category, "Shell", 5)
535                     && vstfx->handle->plugincnt == 1) {
536                         int id;
537                         vector< pair<int, string> > ids;
538                         AEffect *plugin = vstfx->plugin;
539                         string path = vstfx->handle->path;
540
541                         do {
542                                 char name[65] = "Unknown\0";
543                                 id = plugin->dispatcher (plugin, effShellGetNextPlugin, 0, 0, name, 0);
544                                 ids.push_back(std::make_pair(id, name));
545                         } while ( id != 0 );
546
547                         switch(type) {
548 #ifdef WINDOWS_VST_SUPPORT
549                                 case 1: fst_close(vstfx); break;
550 #endif
551 #ifdef LXVST_SUPPORT
552                                 case 2: vstfx_close (vstfx); break;
553 #endif
554                                 default: assert(0); break;
555                         }
556
557                         for (vector< pair<int, string> >::iterator x = ids.begin(); x != ids.end(); ++x) {
558                                 id = (*x).first;
559                                 if (id == 0) continue;
560                                 /* recurse vstfx_get_info() */
561
562                                 bool ok;
563                                 switch (type) { // TODO use lib ardour's type
564 #ifdef WINDOWS_VST_SUPPORT
565                                         case 1:  ok = vstfx_instantiate_and_get_info_fst(dllpath, infos, id); break;
566 #endif
567 #ifdef LXVST_SUPPORT
568                                         case 2:  ok = vstfx_instantiate_and_get_info_lx(dllpath, infos, id); break;
569 #endif
570                                         default: ok = false;
571                                 }
572                                 if (ok) {
573                                         // One shell (some?, all?) does not report the actual plugin name
574                                         // even after the shelled plugin has been instantiated.
575                                         // Replace the name of the shell with the real name.
576                                         info = infos->back();
577                                         free (info->name);
578
579                                         if ((*x).second.length() == 0) {
580                                                 info->name = strdup("Unknown");
581                                         }
582                                         else {
583                                                 info->name = strdup ((*x).second.c_str());
584                                         }
585                                 }
586                         }
587                 }
588 #endif
589         }
590 }
591
592 /* A simple 'dummy' audiomaster callback which should be ok,
593    we will only be instantiating the plugin in order to get its info
594 */
595
596 static intptr_t
597 simple_master_callback (AEffect *, int32_t opcode, int32_t, intptr_t, void *ptr, float)
598 {
599         const char* vstfx_can_do_strings[] = {
600                 "supportShell",
601                 "shellCategory"
602         };
603         const int vstfx_can_do_string_count = 2;
604
605         if (opcode == audioMasterVersion) {
606                 return 2400;
607         }
608         else if (opcode == audioMasterCanDo) {
609                 for (int i = 0; i < vstfx_can_do_string_count; i++) {
610                         if (! strcmp(vstfx_can_do_strings[i], (const char*)ptr)) {
611                                 return 1;
612                         }
613                 }
614                 return 0;
615         }
616         else if (opcode == audioMasterCurrentId) {
617                 return vstfx_current_loading_id;
618         }
619         else {
620                 return 0;
621         }
622 }
623
624 static bool
625 vstfx_get_info_from_file(const char* dllpath, vector<VSTInfo*> *infos)
626 {
627         FILE* infofile;
628         bool rv = false;
629         if ((infofile = vstfx_infofile_for_read (dllpath)) != 0) {
630                 rv = vstfx_load_info_file(infofile, infos);
631                 fclose (infofile);
632                 if (!rv) {
633                         PBD::warning << "Cannot get LinuxVST information form " << dllpath << ": info file load failed." << endmsg;
634                 }
635         }
636         return rv;
637 }
638
639 #ifdef LXVST_SUPPORT
640 static bool
641 vstfx_instantiate_and_get_info_lx (
642                 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
643 {
644         VSTHandle* h;
645         VSTState* vstfx;
646         if (!(h = vstfx_load(dllpath))) {
647                 PBD::warning << "Cannot get LinuxVST information from " << dllpath << ": load failed." << endmsg;
648                 return false;
649         }
650
651         vstfx_current_loading_id = uniqueID;
652
653         if (!(vstfx = vstfx_instantiate(h, simple_master_callback, 0))) {
654                 vstfx_unload(h);
655                 PBD::warning << "Cannot get LinuxVST information from " << dllpath << ": instantiation failed." << endmsg;
656                 return false;
657         }
658
659         vstfx_current_loading_id = 0;
660
661         vstfx_info_from_plugin(dllpath, vstfx, infos, 2);
662
663         vstfx_close (vstfx);
664         vstfx_unload (h);
665         return true;
666 }
667 #endif
668
669 #ifdef WINDOWS_VST_SUPPORT
670 static bool
671 vstfx_instantiate_and_get_info_fst (
672                 const char* dllpath, vector<VSTInfo*> *infos, int uniqueID)
673 {
674         VSTHandle* h;
675         VSTState* vstfx;
676         if(!(h = fst_load(dllpath))) {
677                 PBD::warning << "Cannot get Windows VST information from " << dllpath << ": load failed." << endmsg;
678                 return false;
679         }
680
681         vstfx_current_loading_id = uniqueID;
682
683         if(!(vstfx = fst_instantiate(h, simple_master_callback, 0))) {
684                 fst_unload(&h);
685                 vstfx_current_loading_id = 0;
686                 PBD::warning << "Cannot get Windows VST information from " << dllpath << ": instantiation failed." << endmsg;
687                 return false;
688         }
689         vstfx_current_loading_id = 0;
690
691         vstfx_info_from_plugin(dllpath, vstfx, infos, 1);
692
693         fst_close(vstfx);
694         //fst_unload(&h); // XXX -> fst_close()
695         return true;
696 }
697 #endif
698
699 static vector<VSTInfo *> *
700 vstfx_get_info (const char* dllpath, int type)
701 {
702         FILE* infofile;
703         vector<VSTInfo*> *infos = new vector<VSTInfo*>;
704
705         if (vstfx_check_blacklist(dllpath)) {
706                 return infos;
707         }
708
709         if (vstfx_get_info_from_file(dllpath, infos)) {
710                 return infos;
711         }
712
713         bool ok;
714         /* blacklist in case instantiation fails */
715         vstfx_blacklist(dllpath);
716
717         switch (type) { // TODO use lib ardour's type
718 #ifdef WINDOWS_VST_SUPPORT
719                 case 1:  ok = vstfx_instantiate_and_get_info_fst(dllpath, infos, 0); break;
720 #endif
721 #ifdef LXVST_SUPPORT
722                 case 2:  ok = vstfx_instantiate_and_get_info_lx(dllpath, infos, 0); break;
723 #endif
724                 default: ok = false;
725         }
726
727         if (!ok) {
728                 return infos;
729         }
730
731         /* remove from blacklist */
732         vstfx_un_blacklist(dllpath);
733
734         /* crate cache/whitelist */
735         infofile = vstfx_infofile_for_write (dllpath);
736         if (!infofile) {
737                 PBD::warning << "Cannot cache VST information for " << dllpath << ": cannot create new FST info file." << endmsg;
738                 return infos;
739         } else {
740                 vstfx_write_info_file (infofile, infos);
741                 fclose (infofile);
742         }
743         return infos;
744 }
745
746 /* *** public API *** */
747
748 void
749 vstfx_free_info_list (vector<VSTInfo *> *infos)
750 {
751         for (vector<VSTInfo *>::iterator i = infos->begin(); i != infos->end(); ++i) {
752                 vstfx_free_info(*i);
753         }
754         delete infos;
755 }
756
757 string
758 get_personal_vst_blacklist_dir() {
759         string dir = Glib::build_filename (ARDOUR::user_cache_directory(), "fst_blacklist");
760         /* if the directory doesn't exist, try to create it */
761         if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
762                 if (g_mkdir (dir.c_str (), 0700)) {
763                         PBD::error << "Cannt create VST cache folder '" << dir << "'" << endmsg;
764                         //exit(1);
765                 }
766         }
767         return dir;
768 }
769
770 string
771 get_personal_vst_info_cache_dir() {
772         string dir = Glib::build_filename (ARDOUR::user_cache_directory(), "fst_info");
773         /* if the directory doesn't exist, try to create it */
774         if (!Glib::file_test (dir, Glib::FILE_TEST_IS_DIR)) {
775                 if (g_mkdir (dir.c_str (), 0700)) {
776                         PBD::error << "Cannt create VST info folder '" << dir << "'" << endmsg;
777                         //exit(1);
778                 }
779         }
780         return dir;
781 }
782
783 #ifdef LXVST_SUPPORT
784 vector<VSTInfo *> *
785 vstfx_get_info_lx (char* dllpath)
786 {
787         return vstfx_get_info(dllpath, 2);
788 }
789 #endif
790
791 #ifdef WINDOWS_VST_SUPPORT
792 vector<VSTInfo *> *
793 vstfx_get_info_fst (char* dllpath)
794 {
795         return vstfx_get_info(dllpath, 1);
796 }
797 #endif