comparison vamp-stubber/stubber.cpp @ 237:5ba2749f2024

Avoid emitting duplicate plugins (where duplicate libraries are installed)
author Chris Cannam <cannam@all-day-breakfast.com>
date Tue, 13 Jun 2017 10:06:44 +0100
parents 87ab11fdcfec
children 0664784566d8
comparison
equal deleted inserted replaced
236:903f217e0ca7 237:5ba2749f2024
173 "using piper_vamp_js::PiperPluginLibrary;\n" 173 "using piper_vamp_js::PiperPluginLibrary;\n"
174 "\n" 174 "\n"
175 "static std::string soname(\"" << soname << "\");\n" 175 "static std::string soname(\"" << soname << "\");\n"
176 "\n"; 176 "\n";
177 177
178 bool first = true; 178 // The same plugin key may appear more than once in the available
179 // list, if the same plugin is installed in more than one location
180 // on the Vamp path. To avoid emitting its wrapper definition
181 // multiple times, we need to keep a record of which ones we've
182 // emitted for each stage
183 set<string> emitted;
179 184
180 for (const auto &plugin: resp.available) { 185 for (const auto &plugin: resp.available) {
181 PlausibleMetadata pm = inventPlausibleMetadata(plugin.pluginKey); 186
187 string key = plugin.pluginKey;
188 if (emitted.find(key) != emitted.end()) {
189 continue;
190 }
191
192 PlausibleMetadata pm = inventPlausibleMetadata(key);
182 cout << "static PiperAdapter<" 193 cout << "static PiperAdapter<"
183 << pm.className 194 << pm.className
184 << "> // replace with the actual Vamp plugin class name for \"" 195 << "> // replace with the actual Vamp plugin class name for \""
185 << plugin.basic.identifier << "\" plugin\n" << pm.adapterName 196 << plugin.basic.identifier << "\" plugin\n" << pm.adapterName
186 << "(\n soname,\n "; 197 << "(\n soname,\n ";
187 198
188 string catString = "{ "; 199 string catString = "{ ";
189 first = true; 200 bool first = true;
190 for (auto c: plugin.category) { 201 for (auto c: plugin.category) {
191 if (!first) catString += ", "; 202 if (!first) catString += ", ";
192 catString += "\"" + c + "\""; 203 catString += "\"" + c + "\"";
193 first = false; 204 first = false;
194 } 205 }
208 << desc.typeURI << "\" }\n }"; 219 << desc.typeURI << "\" }\n }";
209 first = false; 220 first = false;
210 } 221 }
211 cout << "\n }\n"; 222 cout << "\n }\n";
212 cout << " );\n\n"; 223 cout << " );\n\n";
224 emitted.insert(key);
213 } 225 }
214 226
215 cout << "static PiperPluginLibrary library({\n "; 227 cout << "static PiperPluginLibrary library({\n ";
216 first = true; 228 emitted.clear();
217 for (const auto &plugin: resp.available) { 229 for (const auto &plugin: resp.available) {
218 PlausibleMetadata pm = inventPlausibleMetadata(plugin.pluginKey); 230
219 if (!first) { 231 string key = plugin.pluginKey;
232 if (emitted.find(key) != emitted.end()) {
233 continue;
234 }
235
236 PlausibleMetadata pm = inventPlausibleMetadata(key);
237 if (!emitted.empty()) {
220 cout << ",\n "; 238 cout << ",\n ";
221 } 239 }
222 cout << "&" << pm.adapterName; 240 cout << "&" << pm.adapterName;
223 first = false; 241 emitted.insert(key);
224 } 242 }
225 cout << "\n});\n\n"; 243 cout << "\n});\n\n";
226 cout << "PIPER_EXPORT_LIBRARY(library);\n" << endl; 244 cout << "PIPER_EXPORT_LIBRARY(library);\n" << endl;
227 } 245 }
228 246