Chris@4
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@5
|
2 /*
|
Chris@5
|
3 Copyright (c) 2016 Queen Mary, University of London
|
Chris@5
|
4
|
Chris@5
|
5 Permission is hereby granted, free of charge, to any person
|
Chris@5
|
6 obtaining a copy of this software and associated documentation
|
Chris@5
|
7 files (the "Software"), to deal in the Software without
|
Chris@5
|
8 restriction, including without limitation the rights to use, copy,
|
Chris@5
|
9 modify, merge, publish, distribute, sublicense, and/or sell copies
|
Chris@5
|
10 of the Software, and to permit persons to whom the Software is
|
Chris@5
|
11 furnished to do so, subject to the following conditions:
|
Chris@5
|
12
|
Chris@5
|
13 The above copyright notice and this permission notice shall be
|
Chris@5
|
14 included in all copies or substantial portions of the Software.
|
Chris@5
|
15
|
Chris@5
|
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
Chris@5
|
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
Chris@5
|
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
Chris@5
|
19 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
Chris@5
|
20 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
|
Chris@5
|
21 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
Chris@5
|
22 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
Chris@5
|
23
|
Chris@5
|
24 Except as contained in this notice, the names of the Centre for
|
Chris@5
|
25 Digital Music and Queen Mary, University of London shall not be
|
Chris@5
|
26 used in advertising or otherwise to promote the sale, use or other
|
Chris@5
|
27 dealings in this Software without prior written authorization.
|
Chris@5
|
28 */
|
Chris@4
|
29
|
Chris@4
|
30 #include "knownplugins.h"
|
Chris@4
|
31
|
Chris@4
|
32 #include <sstream>
|
Chris@4
|
33
|
Chris@4
|
34 using namespace std;
|
Chris@4
|
35
|
Chris@4
|
36 #if defined(_WIN32)
|
Chris@4
|
37 #define PATH_SEPARATOR ';'
|
Chris@4
|
38 #else
|
Chris@4
|
39 #define PATH_SEPARATOR ':'
|
Chris@4
|
40 #endif
|
Chris@4
|
41
|
Chris@4
|
42 KnownPlugins::KnownPlugins() :
|
Chris@4
|
43 m_candidates("./helper") //!!!??? wot to do
|
Chris@4
|
44 {
|
Chris@4
|
45 m_known = {
|
Chris@4
|
46 {
|
Chris@4
|
47 VampPlugin,
|
Chris@4
|
48 {
|
Chris@4
|
49 "vamp",
|
Chris@4
|
50 expandConventionalPath(VampPlugin, "VAMP_PATH"),
|
Chris@4
|
51 "vampGetPluginDescriptor"
|
Chris@4
|
52 },
|
Chris@4
|
53 }, {
|
Chris@4
|
54 LADSPAPlugin,
|
Chris@4
|
55 {
|
Chris@4
|
56 "ladspa",
|
Chris@4
|
57 expandConventionalPath(LADSPAPlugin, "LADSPA_PATH"),
|
Chris@4
|
58 "ladspa_descriptor"
|
Chris@4
|
59 },
|
Chris@4
|
60 }, {
|
Chris@4
|
61 DSSIPlugin,
|
Chris@4
|
62 {
|
Chris@4
|
63 "dssi",
|
Chris@4
|
64 expandConventionalPath(DSSIPlugin, "DSSI_PATH"),
|
Chris@4
|
65 "dssi_descriptor"
|
Chris@4
|
66 }
|
Chris@4
|
67 }
|
Chris@4
|
68 };
|
Chris@4
|
69
|
Chris@4
|
70 for (const auto &k: m_known) {
|
Chris@4
|
71 m_candidates.scan(k.second.tag, k.second.path, k.second.descriptor);
|
Chris@4
|
72 }
|
Chris@4
|
73 }
|
Chris@4
|
74
|
Chris@4
|
75 string
|
Chris@4
|
76 KnownPlugins::getDefaultPath(PluginType type)
|
Chris@4
|
77 {
|
Chris@4
|
78 switch (type) {
|
Chris@4
|
79
|
Chris@4
|
80 #if defined(_WIN32)
|
Chris@4
|
81
|
Chris@4
|
82 case VampPlugin:
|
Chris@4
|
83 return "%ProgramFiles%\\Vamp Plugins";
|
Chris@4
|
84 case LADSPAPlugin:
|
Chris@4
|
85 return "%ProgramFiles%\\LADSPA Plugins;%ProgramFiles%\\Audacity\\Plug-Ins";
|
Chris@4
|
86 case DSSIPlugin:
|
Chris@4
|
87 return "%ProgramFiles%\\DSSI Plugins";
|
Chris@4
|
88
|
Chris@4
|
89 #elif defined(__APPLE__)
|
Chris@4
|
90
|
Chris@4
|
91 case VampPlugin:
|
Chris@4
|
92 return "$HOME/Library/Audio/Plug-Ins/Vamp:/Library/Audio/Plug-Ins/Vamp";
|
Chris@4
|
93 case LADSPAPlugin:
|
Chris@4
|
94 return "$HOME/Library/Audio/Plug-Ins/LADSPA:/Library/Audio/Plug-Ins/LADSPA";
|
Chris@4
|
95 case DSSIPlugin:
|
Chris@4
|
96 return "$HOME/Library/Audio/Plug-Ins/DSSI:/Library/Audio/Plug-Ins/DSSI";
|
Chris@4
|
97
|
Chris@4
|
98 #else /* Linux, BSDs, etc */
|
Chris@4
|
99
|
Chris@4
|
100 case VampPlugin:
|
Chris@4
|
101 return "$HOME/vamp:$HOME/.vamp:/usr/local/lib/vamp:/usr/lib/vamp";
|
Chris@4
|
102 case LADSPAPlugin:
|
Chris@4
|
103 return "$HOME/ladspa:$HOME/.ladspa:/usr/local/lib/ladspa:/usr/lib/ladspa";
|
Chris@4
|
104 case DSSIPlugin:
|
Chris@4
|
105 return "$HOME/dssi:$HOME/.dssi:/usr/local/lib/dssi:/usr/lib/dssi";
|
Chris@4
|
106 #endif
|
Chris@4
|
107 }
|
Chris@4
|
108
|
Chris@4
|
109 throw logic_error("unknown or unhandled plugin type");
|
Chris@4
|
110 }
|
Chris@4
|
111
|
Chris@4
|
112 vector<string>
|
Chris@4
|
113 KnownPlugins::expandConventionalPath(PluginType type, string var)
|
Chris@4
|
114 {
|
Chris@4
|
115 vector<string> pathList;
|
Chris@4
|
116 string path;
|
Chris@4
|
117
|
Chris@4
|
118 char *cpath = getenv(var.c_str());
|
Chris@4
|
119 if (cpath) path = cpath;
|
Chris@4
|
120
|
Chris@4
|
121 if (path == "") {
|
Chris@4
|
122
|
Chris@4
|
123 path = getDefaultPath(type);
|
Chris@4
|
124
|
Chris@4
|
125 if (path != "") {
|
Chris@4
|
126
|
Chris@4
|
127 char *home = getenv("HOME");
|
Chris@4
|
128 if (home) {
|
Chris@4
|
129 string::size_type f;
|
Chris@4
|
130 while ((f = path.find("$HOME")) != string::npos &&
|
Chris@4
|
131 f < path.length()) {
|
Chris@4
|
132 path.replace(f, 5, home);
|
Chris@4
|
133 }
|
Chris@4
|
134 }
|
Chris@4
|
135
|
Chris@4
|
136 #ifdef _WIN32
|
Chris@4
|
137 char *pfiles = getenv("ProgramFiles");
|
Chris@4
|
138 if (!pfiles) pfiles = "C:\\Program Files";
|
Chris@4
|
139 {
|
Chris@4
|
140 string::size_type f;
|
Chris@4
|
141 while ((f = path.find("%ProgramFiles%")) != string::npos &&
|
Chris@4
|
142 f < path.length()) {
|
Chris@4
|
143 path.replace(f, 14, pfiles);
|
Chris@4
|
144 }
|
Chris@4
|
145 }
|
Chris@4
|
146 #endif
|
Chris@4
|
147 }
|
Chris@4
|
148 }
|
Chris@4
|
149
|
Chris@4
|
150 string::size_type index = 0, newindex = 0;
|
Chris@4
|
151
|
Chris@4
|
152 while ((newindex = path.find(PATH_SEPARATOR, index)) < path.size()) {
|
Chris@4
|
153 pathList.push_back(path.substr(index, newindex - index).c_str());
|
Chris@4
|
154 index = newindex + 1;
|
Chris@4
|
155 }
|
Chris@4
|
156
|
Chris@4
|
157 pathList.push_back(path.substr(index));
|
Chris@4
|
158
|
Chris@4
|
159 return pathList;
|
Chris@4
|
160 }
|
Chris@4
|
161
|
Chris@4
|
162 string
|
Chris@4
|
163 KnownPlugins::getFailureReport() const
|
Chris@4
|
164 {
|
Chris@4
|
165 vector<PluginCandidates::FailureRec> failures;
|
Chris@4
|
166
|
Chris@4
|
167 for (auto t: getKnownPluginTypes()) {
|
Chris@4
|
168 auto ff = m_candidates.getFailedLibrariesFor(getTagFor(t));
|
Chris@4
|
169 failures.insert(failures.end(), ff.begin(), ff.end());
|
Chris@4
|
170 }
|
Chris@4
|
171
|
Chris@4
|
172 if (failures.empty()) return "";
|
Chris@4
|
173
|
Chris@4
|
174 int n = failures.size();
|
Chris@4
|
175 int i = 0;
|
Chris@4
|
176
|
Chris@4
|
177 ostringstream os;
|
Chris@4
|
178
|
Chris@4
|
179 os << "<ul>";
|
Chris@4
|
180 for (auto f: failures) {
|
Chris@4
|
181 os << "<li>" + f.library;
|
Chris@4
|
182 if (f.message != "") {
|
Chris@4
|
183 os << " (" + f.message + ")";
|
Chris@4
|
184 } else {
|
Chris@4
|
185 os << " (unknown error)";
|
Chris@4
|
186 }
|
Chris@4
|
187 os << "</li>";
|
Chris@4
|
188
|
Chris@4
|
189 if (n > 10) {
|
Chris@4
|
190 if (++i == 5) {
|
Chris@4
|
191 os << "<li>(... and " << (n - i) << " further failures)</li>";
|
Chris@4
|
192 break;
|
Chris@4
|
193 }
|
Chris@4
|
194 }
|
Chris@4
|
195 }
|
Chris@4
|
196 os << "</ul>";
|
Chris@4
|
197
|
Chris@4
|
198 return os.str();
|
Chris@4
|
199 }
|