18f4048cbbbb26f1713c61693b4583ad9a2517c0
[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 #include "../ardour/vst_state.cc"
41
42 #ifdef LXVST_SUPPORT
43 void
44 vstfx_destroy_editor (VSTState* /*vstfx*/) { }
45 #endif
46
47 using namespace PBD;
48
49 class DummyReceiver : public Receiver {
50         protected:
51                 void receive (Transmitter::Channel chn, const char * str) {
52                         const char *prefix = "";
53                         switch (chn) {
54                                 case Transmitter::Error:
55                                         prefix = "[ERROR]: ";
56                                         break;
57                                 case Transmitter::Info:
58                                         /* ignore */
59                                         return;
60                                 case Transmitter::Warning:
61                                         prefix = "[WARNING]: ";
62                                         break;
63                                 case Transmitter::Fatal:
64                                         prefix = "[FATAL]: ";
65                                         break;
66                                 case Transmitter::Throw:
67                                         abort ();
68                         }
69
70                         std::cerr << prefix << str << std::endl;
71
72                         if (chn == Transmitter::Fatal) {
73                                 ::exit (1);
74                         }
75                 }
76 };
77
78 DummyReceiver dummy_receiver;
79
80 int main (int argc, char **argv) {
81         char *dllpath = NULL;
82         if (argc == 3 && !strcmp("-f", argv[1])) {
83                 dllpath = argv[2];
84                 const size_t slen = strlen (dllpath);
85                 if (
86                                 (slen > 3 && 0 == g_ascii_strcasecmp (&dllpath[slen-3], ".so"))
87                                 ||
88                                 (slen > 4 && 0 == g_ascii_strcasecmp (&dllpath[slen-4], ".dll"))
89                    ) {
90                         vstfx_remove_infofile(dllpath);
91                         vstfx_un_blacklist(dllpath);
92                 }
93
94         }
95         else if (argc != 2) {
96                 fprintf(stderr, "usage: %s [-f] <vst>\n", argv[0]);
97                 return EXIT_FAILURE;
98         } else {
99                 dllpath = argv[1];
100         }
101
102         PBD::init();
103
104         dummy_receiver.listen_to (error);
105         dummy_receiver.listen_to (info);
106         dummy_receiver.listen_to (fatal);
107         dummy_receiver.listen_to (warning);
108
109         std::vector<VSTInfo *> *infos = 0;
110
111         const size_t slen = strlen (dllpath);
112         if (0) { }
113 #ifdef LXVST_SUPPORT
114         else if (slen > 3 && 0 == g_ascii_strcasecmp (&dllpath[slen-3], ".so")) {
115                 infos = vstfx_get_info_lx(dllpath);
116         }
117 #endif
118
119 #ifdef WINDOWS_VST_SUPPORT
120         else if (slen > 4 && 0 == g_ascii_strcasecmp (&dllpath[slen-4], ".dll")) {
121                 infos = vstfx_get_info_fst(dllpath);
122         }
123 #endif
124
125 #ifdef MACVST_SUPPORT
126         else if (slen > 4 && 0 == g_ascii_strcasecmp (&dllpath[slen-4], ".vst")) {
127                 infos = vstfx_get_info_mac(dllpath);
128         }
129 #endif
130         else {
131                 fprintf(stderr, "'%s' is not a supported VST plugin.\n", dllpath);
132         }
133
134         PBD::cleanup();
135
136         if (!infos || infos->empty()) {
137                 return EXIT_FAILURE;
138         } else {
139                 return EXIT_SUCCESS;
140         }
141 }