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