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