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