comparison plugin/FeatureExtractionPluginFactory.cpp @ 686:b4a8d8221eaf debug-output

Remove most toStdString calls (no longer needed, with debug header)
author Chris Cannam
date Thu, 12 May 2011 17:31:24 +0100
parents d7f3dfe6f9a4
children 06f13a3b9e9e
comparison
equal deleted inserted replaced
685:99222d4bfc78 686:b4a8d8221eaf
94 94
95 factory = instance("vamp"); 95 factory = instance("vamp");
96 if (factory) { 96 if (factory) {
97 std::vector<QString> tmp = factory->getPluginIdentifiers(); 97 std::vector<QString> tmp = factory->getPluginIdentifiers();
98 for (size_t i = 0; i < tmp.size(); ++i) { 98 for (size_t i = 0; i < tmp.size(); ++i) {
99 // std::cerr << "identifier: " << tmp[i].toStdString() << std::endl; 99 // std::cerr << "identifier: " << tmp[i] << std::endl;
100 rv.push_back(tmp[i]); 100 rv.push_back(tmp[i]);
101 } 101 }
102 } 102 }
103 103
104 // Plugins can change the locale, revert it to default. 104 // Plugins can change the locale, revert it to default.
128 for (unsigned int j = 0; j < pluginDir.count(); ++j) { 128 for (unsigned int j = 0; j < pluginDir.count(); ++j) {
129 129
130 QString soname = pluginDir.filePath(pluginDir[j]); 130 QString soname = pluginDir.filePath(pluginDir[j]);
131 131
132 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 132 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
133 std::cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: trying potential library " << soname.toStdString() << std::endl; 133 std::cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: trying potential library " << soname << std::endl;
134 #endif 134 #endif
135 135
136 void *libraryHandle = DLOPEN(soname, RTLD_LAZY | RTLD_LOCAL); 136 void *libraryHandle = DLOPEN(soname, RTLD_LAZY | RTLD_LOCAL);
137 137
138 if (!libraryHandle) { 138 if (!libraryHandle) {
139 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to load library " << soname.toStdString() << ": " << DLERROR() << std::endl; 139 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to load library " << soname << ": " << DLERROR() << std::endl;
140 continue; 140 continue;
141 } 141 }
142 142
143 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 143 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
144 std::cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: It's a library all right, checking for descriptor" << std::endl; 144 std::cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: It's a library all right, checking for descriptor" << std::endl;
146 146
147 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction) 147 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction)
148 DLSYM(libraryHandle, "vampGetPluginDescriptor"); 148 DLSYM(libraryHandle, "vampGetPluginDescriptor");
149 149
150 if (!fn) { 150 if (!fn) {
151 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: No descriptor function in " << soname.toStdString() << std::endl; 151 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: No descriptor function in " << soname << std::endl;
152 if (DLCLOSE(libraryHandle) != 0) { 152 if (DLCLOSE(libraryHandle) != 0) {
153 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to unload library " << soname.toStdString() << std::endl; 153 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to unload library " << soname << std::endl;
154 } 154 }
155 continue; 155 continue;
156 } 156 }
157 157
158 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 158 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
192 192
193 QString id = PluginIdentifier::createIdentifier 193 QString id = PluginIdentifier::createIdentifier
194 ("vamp", soname, descriptor->identifier); 194 ("vamp", soname, descriptor->identifier);
195 rv.push_back(id); 195 rv.push_back(id);
196 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 196 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
197 std::cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: Found plugin id " << id.toStdString() << " at index " << index << std::endl; 197 std::cerr << "FeatureExtractionPluginFactory::getPluginIdentifiers: Found plugin id " << id << " at index " << index << std::endl;
198 #endif 198 #endif
199 ++index; 199 ++index;
200 } 200 }
201 } 201 }
202 202
203 if (DLCLOSE(libraryHandle) != 0) { 203 if (DLCLOSE(libraryHandle) != 0) {
204 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to unload library " << soname.toStdString() << std::endl; 204 std::cerr << "WARNING: FeatureExtractionPluginFactory::getPluginIdentifiers: Failed to unload library " << soname << std::endl;
205 } 205 }
206 } 206 }
207 } 207 }
208 208
209 generateTaxonomy(); 209 generateTaxonomy();
216 { 216 {
217 QString file = ""; 217 QString file = "";
218 218
219 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 219 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
220 std::cerr << "FeatureExtractionPluginFactory::findPluginFile(\"" 220 std::cerr << "FeatureExtractionPluginFactory::findPluginFile(\""
221 << soname.toStdString() << "\", \"" << inDir.toStdString() << "\")" 221 << soname << "\", \"" << inDir << "\")"
222 << std::endl; 222 << std::endl;
223 #endif 223 #endif
224 224
225 if (inDir != "") { 225 if (inDir != "") {
226 226
233 233
234 if (QFileInfo(file).exists() && QFileInfo(file).isFile()) { 234 if (QFileInfo(file).exists() && QFileInfo(file).isFile()) {
235 235
236 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 236 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
237 std::cerr << "FeatureExtractionPluginFactory::findPluginFile: " 237 std::cerr << "FeatureExtractionPluginFactory::findPluginFile: "
238 << "found trivially at " << file.toStdString() << std::endl; 238 << "found trivially at " << file << std::endl;
239 #endif 239 #endif
240 240
241 return file; 241 return file;
242 } 242 }
243 243
245 file = dir.filePath(dir[j]); 245 file = dir.filePath(dir[j]);
246 if (QFileInfo(file).baseName() == QFileInfo(soname).baseName()) { 246 if (QFileInfo(file).baseName() == QFileInfo(soname).baseName()) {
247 247
248 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 248 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
249 std::cerr << "FeatureExtractionPluginFactory::findPluginFile: " 249 std::cerr << "FeatureExtractionPluginFactory::findPluginFile: "
250 << "found \"" << soname.toStdString() << "\" at " << file.toStdString() << std::endl; 250 << "found \"" << soname << "\" at " << file << std::endl;
251 #endif 251 #endif
252 252
253 return file; 253 return file;
254 } 254 }
255 } 255 }
266 QFileInfo fi(soname); 266 QFileInfo fi(soname);
267 267
268 if (fi.isAbsolute() && fi.exists() && fi.isFile()) { 268 if (fi.isAbsolute() && fi.exists() && fi.isFile()) {
269 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 269 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
270 std::cerr << "FeatureExtractionPluginFactory::findPluginFile: " 270 std::cerr << "FeatureExtractionPluginFactory::findPluginFile: "
271 << "found trivially at " << soname.toStdString() << std::endl; 271 << "found trivially at " << soname << std::endl;
272 #endif 272 #endif
273 return soname; 273 return soname;
274 } 274 }
275 275
276 if (fi.isAbsolute() && fi.absolutePath() != "") { 276 if (fi.isAbsolute() && fi.absolutePath() != "") {
309 int index = 0; 309 int index = 0;
310 310
311 QString type, soname, label; 311 QString type, soname, label;
312 PluginIdentifier::parseIdentifier(identifier, type, soname, label); 312 PluginIdentifier::parseIdentifier(identifier, type, soname, label);
313 if (type != "vamp") { 313 if (type != "vamp") {
314 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Wrong factory for plugin type " << type.toStdString() << std::endl; 314 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Wrong factory for plugin type " << type << std::endl;
315 return 0; 315 return 0;
316 } 316 }
317 317
318 QString found = findPluginFile(soname); 318 QString found = findPluginFile(soname);
319 319
320 if (found == "") { 320 if (found == "") {
321 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Failed to find library file " << soname.toStdString() << std::endl; 321 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Failed to find library file " << soname << std::endl;
322 return 0; 322 return 0;
323 } else if (found != soname) { 323 } else if (found != soname) {
324 324
325 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 325 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
326 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Given library name was " << soname.toStdString() << ", found at " << found.toStdString() << std::endl; 326 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Given library name was " << soname << ", found at " << found << std::endl;
327 std::cerr << soname.toStdString() << " -> " << found.toStdString() << std::endl; 327 std::cerr << soname << " -> " << found << std::endl;
328 #endif 328 #endif
329 329
330 } 330 }
331 331
332 soname = found; 332 soname = found;
333 333
334 void *libraryHandle = DLOPEN(soname, RTLD_LAZY | RTLD_LOCAL); 334 void *libraryHandle = DLOPEN(soname, RTLD_LAZY | RTLD_LOCAL);
335 335
336 if (!libraryHandle) { 336 if (!libraryHandle) {
337 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Failed to load library " << soname.toStdString() << ": " << DLERROR() << std::endl; 337 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Failed to load library " << soname << ": " << DLERROR() << std::endl;
338 return 0; 338 return 0;
339 } 339 }
340 340
341 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction) 341 VampGetPluginDescriptorFunction fn = (VampGetPluginDescriptorFunction)
342 DLSYM(libraryHandle, "vampGetPluginDescriptor"); 342 DLSYM(libraryHandle, "vampGetPluginDescriptor");
343 343
344 if (!fn) { 344 if (!fn) {
345 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: No descriptor function in " << soname.toStdString() << std::endl; 345 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: No descriptor function in " << soname << std::endl;
346 goto done; 346 goto done;
347 } 347 }
348 348
349 while ((descriptor = fn(VAMP_API_VERSION, index))) { 349 while ((descriptor = fn(VAMP_API_VERSION, index))) {
350 if (label == descriptor->identifier) break; 350 if (label == descriptor->identifier) break;
351 ++index; 351 ++index;
352 } 352 }
353 353
354 if (!descriptor) { 354 if (!descriptor) {
355 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Failed to find plugin \"" << label.toStdString() << "\" in library " << soname.toStdString() << std::endl; 355 std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Failed to find plugin \"" << label << "\" in library " << soname << std::endl;
356 goto done; 356 goto done;
357 } 357 }
358 358
359 plugin = new Vamp::PluginHostAdapter(descriptor, inputSampleRate); 359 plugin = new Vamp::PluginHostAdapter(descriptor, inputSampleRate);
360 360
368 //!!! need to dlclose() when plugins from a given library are unloaded 368 //!!! need to dlclose() when plugins from a given library are unloaded
369 369
370 done: 370 done:
371 if (!rv) { 371 if (!rv) {
372 if (DLCLOSE(libraryHandle) != 0) { 372 if (DLCLOSE(libraryHandle) != 0) {
373 std::cerr << "WARNING: FeatureExtractionPluginFactory::instantiatePlugin: Failed to unload library " << soname.toStdString() << std::endl; 373 std::cerr << "WARNING: FeatureExtractionPluginFactory::instantiatePlugin: Failed to unload library " << soname << std::endl;
374 } 374 }
375 } 375 }
376 376
377 // std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Instantiated plugin " << label.toStdString() << " from library " << soname.toStdString() << ": descriptor " << descriptor << ", rv "<< rv << ", label " << rv->getName() << ", outputs " << rv->getOutputDescriptors().size() << std::endl; 377 // std::cerr << "FeatureExtractionPluginFactory::instantiatePlugin: Instantiated plugin " << label << " from library " << soname << ": descriptor " << descriptor << ", rv "<< rv << ", label " << rv->getName() << ", outputs " << rv->getOutputDescriptors().size() << std::endl;
378 378
379 return rv; 379 return rv;
380 } 380 }
381 381
382 void 382 void
414 414
415 for (size_t i = 0; i < path.size(); ++i) { 415 for (size_t i = 0; i < path.size(); ++i) {
416 416
417 QDir dir(path[i], "*.cat"); 417 QDir dir(path[i], "*.cat");
418 418
419 // std::cerr << "LADSPAPluginFactory::generateFallbackCategories: directory " << path[i].toStdString() << " has " << dir.count() << " .cat files" << std::endl; 419 // std::cerr << "LADSPAPluginFactory::generateFallbackCategories: directory " << path[i] << " has " << dir.count() << " .cat files" << std::endl;
420 for (unsigned int j = 0; j < dir.count(); ++j) { 420 for (unsigned int j = 0; j < dir.count(); ++j) {
421 421
422 QFile file(path[i] + "/" + dir[j]); 422 QFile file(path[i] + "/" + dir[j]);
423 423
424 // std::cerr << "LADSPAPluginFactory::generateFallbackCategories: about to open " << (path[i].toStdString() + "/" + dir[j].toStdString()) << std::endl; 424 // std::cerr << "LADSPAPluginFactory::generateFallbackCategories: about to open " << (path[i].toStdString() + "/" + dir[j].toStdString()) << std::endl;
428 QTextStream stream(&file); 428 QTextStream stream(&file);
429 QString line; 429 QString line;
430 430
431 while (!stream.atEnd()) { 431 while (!stream.atEnd()) {
432 line = stream.readLine(); 432 line = stream.readLine();
433 // std::cerr << "line is: \"" << line.toStdString() << "\"" << std::endl; 433 // std::cerr << "line is: \"" << line << "\"" << std::endl;
434 QString id = PluginIdentifier::canonicalise 434 QString id = PluginIdentifier::canonicalise
435 (line.section("::", 0, 0)); 435 (line.section("::", 0, 0));
436 QString cat = line.section("::", 1, 1); 436 QString cat = line.section("::", 1, 1);
437 m_taxonomy[id] = cat; 437 m_taxonomy[id] = cat;
438 // std::cerr << "FeatureExtractionPluginFactory: set id \"" << id.toStdString() << "\" to cat \"" << cat.toStdString() << "\"" << std::endl; 438 // std::cerr << "FeatureExtractionPluginFactory: set id \"" << id << "\" to cat \"" << cat << "\"" << std::endl;
439 } 439 }
440 } 440 }
441 } 441 }
442 } 442 }
443 } 443 }