Merge branch 'cairocanvas'
[ardour.git] / libs / fst / scanner.cc
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <vector>
5
6 #include "pbd/pbd.h"
7 #include "pbd/transmitter.h"
8 #include "pbd/receiver.h"
9
10 #ifdef __MINGW64__
11 #define NO_OLDNAMES // no backwards compat _pid_t, conflict with w64 pthread/sched
12 #endif
13
14 #include "ardour/filesystem_paths.h"
15 #ifdef LXVST_SUPPORT
16 #include "ardour/linux_vst_support.h"
17 #endif
18 #include "ardour/vst_info_file.h"
19
20 /* make stupid waf happy.
21  * waf cannot build multiple variants of .o object files from the same
22  * source using different wscripts.. it mingles e.g.
23  * build/libs/ardour/vst_info_file.cc.1.o for
24  * both lib/ardour/wscript and lib/fst/wscript
25  *
26  * ...but waf does track include dependencies.
27  */
28 #include "../ardour/vst_info_file.cc"
29 #ifdef LXVST_SUPPORT
30 #include "../ardour/linux_vst_support.cc"
31 #endif
32 #include "../ardour/filesystem_paths.cc"
33 #include "../ardour/directory_names.cc"
34
35
36 #ifdef LXVST_SUPPORT
37 void
38 vstfx_destroy_editor (VSTState* /*vstfx*/) { }
39 #endif
40
41 using namespace PBD;
42
43 class DummyReceiver : public Receiver {
44         protected:
45                 void receive (Transmitter::Channel chn, const char * str) {
46                         const char *prefix = "";
47                         switch (chn) {
48                                 case Transmitter::Error:
49                                         prefix = "[ERROR]: ";
50                                         break;
51                                 case Transmitter::Info:
52                                         /* ignore */
53                                         return;
54                                 case Transmitter::Warning:
55                                         prefix = "[WARNING]: ";
56                                         break;
57                                 case Transmitter::Fatal:
58                                         prefix = "[FATAL]: ";
59                                         break;
60                                 case Transmitter::Throw:
61                                         abort ();
62                         }
63
64                         std::cerr << prefix << str << std::endl;
65
66                         if (chn == Transmitter::Fatal) {
67                                 ::exit (1);
68                         }
69                 }
70 };
71
72 DummyReceiver dummy_receiver;
73
74 int main (int argc, char **argv) {
75         char *dllpath = NULL;
76         if (argc == 3 && !strcmp("-f", argv[1])) {
77                 dllpath = argv[2];
78                 if (strstr (dllpath, ".so" ) || strstr(dllpath, ".dll")) {
79                         vstfx_remove_infofile(dllpath);
80                         vstfx_un_blacklist(dllpath);
81                 }
82
83         }
84         else if (argc != 2) {
85                 fprintf(stderr, "usage: %s [-f] <vst>\n", argv[0]);
86                 return EXIT_FAILURE;
87         } else {
88                 dllpath = argv[1];
89         }
90
91         PBD::init();
92
93         dummy_receiver.listen_to (error);
94         dummy_receiver.listen_to (info);
95         dummy_receiver.listen_to (fatal);
96         dummy_receiver.listen_to (warning);
97
98         std::vector<VSTInfo *> *infos = 0;
99
100         if (0) { }
101 #ifdef LXVST_SUPPORT
102         else if (strstr (dllpath, ".so")) {
103                 infos = vstfx_get_info_lx(dllpath);
104         }
105 #endif
106
107 #ifdef WINDOWS_VST_SUPPORT
108         else if (strstr (dllpath, ".dll")) {
109                 infos = vstfx_get_info_fst(dllpath);
110         }
111 #endif
112         else {
113                 fprintf(stderr, "'%s' is not a supported VST plugin.\n", dllpath);
114         }
115
116         PBD::cleanup();
117
118         if (!infos || infos->empty()) {
119                 return EXIT_FAILURE;
120         } else {
121                 return EXIT_SUCCESS;
122         }
123 }