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