Mercurial > hg > vamp-plugin-load-checker
comparison knownplugins.cpp @ 4:6f891a9c6434
Make checker with hard-coded knowledge about various plugin types and paths; fix some process management problems
author | Chris Cannam |
---|---|
date | Wed, 13 Apr 2016 12:00:07 +0100 |
parents | |
children | 74064d6f5e07 |
comparison
equal
deleted
inserted
replaced
3:3bae396cf8e0 | 4:6f891a9c6434 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 #include "knownplugins.h" | |
4 | |
5 #include <sstream> | |
6 | |
7 using namespace std; | |
8 | |
9 #if defined(_WIN32) | |
10 #define PATH_SEPARATOR ';' | |
11 #else | |
12 #define PATH_SEPARATOR ':' | |
13 #endif | |
14 | |
15 KnownPlugins::KnownPlugins() : | |
16 m_candidates("./helper") //!!!??? wot to do | |
17 { | |
18 m_known = { | |
19 { | |
20 VampPlugin, | |
21 { | |
22 "vamp", | |
23 expandConventionalPath(VampPlugin, "VAMP_PATH"), | |
24 "vampGetPluginDescriptor" | |
25 }, | |
26 }, { | |
27 LADSPAPlugin, | |
28 { | |
29 "ladspa", | |
30 expandConventionalPath(LADSPAPlugin, "LADSPA_PATH"), | |
31 "ladspa_descriptor" | |
32 }, | |
33 }, { | |
34 DSSIPlugin, | |
35 { | |
36 "dssi", | |
37 expandConventionalPath(DSSIPlugin, "DSSI_PATH"), | |
38 "dssi_descriptor" | |
39 } | |
40 } | |
41 }; | |
42 | |
43 for (const auto &k: m_known) { | |
44 m_candidates.scan(k.second.tag, k.second.path, k.second.descriptor); | |
45 } | |
46 } | |
47 | |
48 string | |
49 KnownPlugins::getDefaultPath(PluginType type) | |
50 { | |
51 switch (type) { | |
52 | |
53 #if defined(_WIN32) | |
54 | |
55 case VampPlugin: | |
56 return "%ProgramFiles%\\Vamp Plugins"; | |
57 case LADSPAPlugin: | |
58 return "%ProgramFiles%\\LADSPA Plugins;%ProgramFiles%\\Audacity\\Plug-Ins"; | |
59 case DSSIPlugin: | |
60 return "%ProgramFiles%\\DSSI Plugins"; | |
61 | |
62 #elif defined(__APPLE__) | |
63 | |
64 case VampPlugin: | |
65 return "$HOME/Library/Audio/Plug-Ins/Vamp:/Library/Audio/Plug-Ins/Vamp"; | |
66 case LADSPAPlugin: | |
67 return "$HOME/Library/Audio/Plug-Ins/LADSPA:/Library/Audio/Plug-Ins/LADSPA"; | |
68 case DSSIPlugin: | |
69 return "$HOME/Library/Audio/Plug-Ins/DSSI:/Library/Audio/Plug-Ins/DSSI"; | |
70 | |
71 #else /* Linux, BSDs, etc */ | |
72 | |
73 case VampPlugin: | |
74 return "$HOME/vamp:$HOME/.vamp:/usr/local/lib/vamp:/usr/lib/vamp"; | |
75 case LADSPAPlugin: | |
76 return "$HOME/ladspa:$HOME/.ladspa:/usr/local/lib/ladspa:/usr/lib/ladspa"; | |
77 case DSSIPlugin: | |
78 return "$HOME/dssi:$HOME/.dssi:/usr/local/lib/dssi:/usr/lib/dssi"; | |
79 #endif | |
80 } | |
81 | |
82 throw logic_error("unknown or unhandled plugin type"); | |
83 } | |
84 | |
85 vector<string> | |
86 KnownPlugins::expandConventionalPath(PluginType type, string var) | |
87 { | |
88 vector<string> pathList; | |
89 string path; | |
90 | |
91 char *cpath = getenv(var.c_str()); | |
92 if (cpath) path = cpath; | |
93 | |
94 if (path == "") { | |
95 | |
96 path = getDefaultPath(type); | |
97 | |
98 if (path != "") { | |
99 | |
100 char *home = getenv("HOME"); | |
101 if (home) { | |
102 string::size_type f; | |
103 while ((f = path.find("$HOME")) != string::npos && | |
104 f < path.length()) { | |
105 path.replace(f, 5, home); | |
106 } | |
107 } | |
108 | |
109 #ifdef _WIN32 | |
110 char *pfiles = getenv("ProgramFiles"); | |
111 if (!pfiles) pfiles = "C:\\Program Files"; | |
112 { | |
113 string::size_type f; | |
114 while ((f = path.find("%ProgramFiles%")) != string::npos && | |
115 f < path.length()) { | |
116 path.replace(f, 14, pfiles); | |
117 } | |
118 } | |
119 #endif | |
120 } | |
121 } | |
122 | |
123 string::size_type index = 0, newindex = 0; | |
124 | |
125 while ((newindex = path.find(PATH_SEPARATOR, index)) < path.size()) { | |
126 pathList.push_back(path.substr(index, newindex - index).c_str()); | |
127 index = newindex + 1; | |
128 } | |
129 | |
130 pathList.push_back(path.substr(index)); | |
131 | |
132 return pathList; | |
133 } | |
134 | |
135 string | |
136 KnownPlugins::getFailureReport() const | |
137 { | |
138 vector<PluginCandidates::FailureRec> failures; | |
139 | |
140 for (auto t: getKnownPluginTypes()) { | |
141 auto ff = m_candidates.getFailedLibrariesFor(getTagFor(t)); | |
142 failures.insert(failures.end(), ff.begin(), ff.end()); | |
143 } | |
144 | |
145 if (failures.empty()) return ""; | |
146 | |
147 int n = failures.size(); | |
148 int i = 0; | |
149 | |
150 ostringstream os; | |
151 | |
152 os << "<ul>"; | |
153 for (auto f: failures) { | |
154 os << "<li>" + f.library; | |
155 if (f.message != "") { | |
156 os << " (" + f.message + ")"; | |
157 } else { | |
158 os << " (unknown error)"; | |
159 } | |
160 os << "</li>"; | |
161 | |
162 if (n > 10) { | |
163 if (++i == 5) { | |
164 os << "<li>(... and " << (n - i) << " further failures)</li>"; | |
165 break; | |
166 } | |
167 } | |
168 } | |
169 os << "</ul>"; | |
170 | |
171 return os.str(); | |
172 } |