add another conditional to decide if we should merge disk MIDI data into input MIDI...
[ardour.git] / libs / fst / scanner.cc
1 /*
2  * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <vector>
23
24 #ifdef COMPILER_MSVC
25 #include <sys/utime.h>
26 #else
27 #include <utime.h>
28 #endif
29
30 #include <glib.h>
31
32 #include "pbd/pbd.h"
33 #include "pbd/transmitter.h"
34 #include "pbd/receiver.h"
35
36 #ifdef __MINGW64__
37 #define NO_OLDNAMES // no backwards compat _pid_t, conflict with w64 pthread/sched
38 #endif
39
40 #include "ardour/filesystem_paths.h"
41 #ifdef LXVST_SUPPORT
42 #include "ardour/linux_vst_support.h"
43 #endif
44 #include "ardour/vst_info_file.h"
45
46 /* make stupid waf happy.
47  * waf cannot build multiple variants of .o object files from the same
48  * source using different wscripts.. it mingles e.g.
49  * build/libs/ardour/vst_info_file.cc.1.o for
50  * both lib/ardour/wscript and lib/fst/wscript
51  *
52  * ...but waf does track include dependencies.
53  */
54 #include "../ardour/vst_info_file.cc"
55 #ifdef LXVST_SUPPORT
56 #include "../ardour/linux_vst_support.cc"
57 #endif
58 #ifdef MACVST_SUPPORT
59 #include "../ardour/mac_vst_support.cc"
60 #endif
61 #include "../ardour/filesystem_paths.cc"
62 #include "../ardour/directory_names.cc"
63
64 #include "../ardour/vst_state.cc"
65
66 #ifdef LXVST_SUPPORT
67 void
68 vstfx_destroy_editor (VSTState* /*vstfx*/) { }
69 #endif
70
71 using namespace PBD;
72
73 class DummyReceiver : public Receiver {
74         protected:
75                 void receive (Transmitter::Channel chn, const char * str) {
76                         const char *prefix = "";
77                         switch (chn) {
78                                 case Transmitter::Error:
79                                         prefix = "[ERROR]: ";
80                                         break;
81                                 case Transmitter::Info:
82                                         /* ignore */
83                                         return;
84                                 case Transmitter::Warning:
85                                         prefix = "[WARNING]: ";
86                                         break;
87                                 case Transmitter::Fatal:
88                                         prefix = "[FATAL]: ";
89                                         break;
90                                 case Transmitter::Throw:
91                                         abort ();
92                         }
93
94                         std::cerr << prefix << str << std::endl;
95
96                         if (chn == Transmitter::Fatal) {
97                                 ::exit (EXIT_FAILURE);
98                         }
99                 }
100 };
101
102 DummyReceiver dummy_receiver;
103
104 int main (int argc, char **argv) {
105         char *dllpath = NULL;
106         if (argc == 3 && !strcmp("-f", argv[1])) {
107                 dllpath = argv[2];
108                 const size_t slen = strlen (dllpath);
109                 if (
110                                 (slen > 3 && 0 == g_ascii_strcasecmp (&dllpath[slen-3], ".so"))
111                                 ||
112                                 (slen > 4 && 0 == g_ascii_strcasecmp (&dllpath[slen-4], ".dll"))
113                    ) {
114                         vstfx_remove_infofile(dllpath);
115                         vstfx_un_blacklist(dllpath);
116                 }
117
118         }
119         else if (argc != 2) {
120                 fprintf(stderr, "usage: %s [-f] <vst>\n", argv[0]);
121                 return EXIT_FAILURE;
122         } else {
123                 dllpath = argv[1];
124         }
125
126         PBD::init();
127
128         dummy_receiver.listen_to (error);
129         dummy_receiver.listen_to (info);
130         dummy_receiver.listen_to (fatal);
131         dummy_receiver.listen_to (warning);
132
133         std::vector<VSTInfo *> *infos = 0;
134
135         const size_t slen = strlen (dllpath);
136         if (0) { }
137 #ifdef LXVST_SUPPORT
138         else if (slen > 3 && 0 == g_ascii_strcasecmp (&dllpath[slen-3], ".so")) {
139                 infos = vstfx_get_info_lx(dllpath);
140         }
141 #endif
142
143 #ifdef WINDOWS_VST_SUPPORT
144         else if (slen > 4 && 0 == g_ascii_strcasecmp (&dllpath[slen-4], ".dll")) {
145                 infos = vstfx_get_info_fst(dllpath);
146         }
147 #endif
148
149 #ifdef MACVST_SUPPORT
150         else if (slen > 4 && 0 == g_ascii_strcasecmp (&dllpath[slen-4], ".vst")) {
151                 infos = vstfx_get_info_mac(dllpath);
152         }
153 #endif
154         else {
155                 fprintf(stderr, "'%s' is not a supported VST plugin.\n", dllpath);
156         }
157
158         PBD::cleanup();
159
160         if (!infos || infos->empty()) {
161                 return EXIT_FAILURE;
162         } else {
163                 return EXIT_SUCCESS;
164         }
165 }