comparison plugin/NativeVampPluginFactory.cpp @ 1830:5f8fbbde08ff audio-source-refactor

Use shared_ptr for plugin instances throughout
author Chris Cannam
date Fri, 20 Mar 2020 16:30:33 +0000
parents 5750b9e60818
children
comparison
equal deleted inserted replaced
1829:51fd27fbce9a 1830:5f8fbbde08ff
295 295
296 return ""; 296 return "";
297 } 297 }
298 } 298 }
299 299
300 Vamp::Plugin * 300 std::shared_ptr<Vamp::Plugin>
301 NativeVampPluginFactory::instantiatePlugin(QString identifier, 301 NativeVampPluginFactory::instantiatePlugin(QString identifier,
302 sv_samplerate_t inputSampleRate) 302 sv_samplerate_t inputSampleRate)
303 { 303 {
304 Profiler profiler("NativeVampPluginFactory::instantiatePlugin"); 304 Profiler profiler("NativeVampPluginFactory::instantiatePlugin");
305 305
306 Vamp::Plugin *rv = nullptr; 306 std::shared_ptr<Vamp::Plugin> rv = nullptr;
307 Vamp::PluginHostAdapter *plugin = nullptr; 307 Vamp::PluginHostAdapter *plugin = nullptr;
308 308
309 const VampPluginDescriptor *descriptor = nullptr; 309 const VampPluginDescriptor *descriptor = nullptr;
310 int index = 0; 310 int index = 0;
311 311
361 361
362 plugin = new Vamp::PluginHostAdapter(descriptor, float(inputSampleRate)); 362 plugin = new Vamp::PluginHostAdapter(descriptor, float(inputSampleRate));
363 363
364 if (plugin) { 364 if (plugin) {
365 m_handleMap[plugin] = libraryHandle; 365 m_handleMap[plugin] = libraryHandle;
366 rv = new PluginDeletionNotifyAdapter(plugin, this); 366 rv = std::shared_ptr<Vamp::Plugin>
367 (new PluginDeletionNotifyAdapter(plugin, this));
367 } 368 }
368 369
369 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE 370 #ifdef DEBUG_PLUGIN_SCAN_AND_INSTANTIATE
370 if (rv) { 371 if (rv) {
371 SVCERR << "NativeVampPluginFactory::instantiatePlugin: Instantiated plugin " << label << " from library " << soname << ": descriptor " << descriptor << ", rv "<< rv << ", label " << rv->getName() << ", outputs " << rv->getOutputDescriptors().size() << endl; 372 SVCERR << "NativeVampPluginFactory::instantiatePlugin: Instantiated plugin " << label << " from library " << soname << ": descriptor " << descriptor << ", rv "<< rv << ", label " << rv->getName() << ", outputs " << rv->getOutputDescriptors().size() << endl;
382 383
383 return rv; 384 return rv;
384 } 385 }
385 386
386 void 387 void
387 NativeVampPluginFactory::pluginDeleted(Vamp::Plugin *plugin) 388 NativeVampPluginFactory::pluginDeleted(Vamp::Plugin* plugin)
388 { 389 {
389 void *handle = m_handleMap[plugin]; 390 void *handle = m_handleMap[plugin];
390 if (!handle) return; 391 if (!handle) return;
391 392
392 m_handleMap.erase(plugin); 393 m_handleMap.erase(plugin);
478 std::vector<std::string> catlist; 479 std::vector<std::string> catlist;
479 for (auto s: getPluginCategory(identifier).split(" > ")) { 480 for (auto s: getPluginCategory(identifier).split(" > ")) {
480 catlist.push_back(s.toStdString()); 481 catlist.push_back(s.toStdString());
481 } 482 }
482 483
483 Vamp::Plugin *p = instantiatePlugin(identifier, 44100); 484 std::shared_ptr<Vamp::Plugin> p = instantiatePlugin(identifier, 44100);
484 if (!p) return {}; 485 if (!p) return {};
485 486
486 auto psd = piper_vamp::PluginStaticData::fromPlugin(pluginKey, 487 auto psd = piper_vamp::PluginStaticData::fromPlugin(pluginKey,
487 catlist, 488 catlist,
488 p); 489 p.get());
489 490
490 delete p;
491
492 m_pluginData[identifier] = psd; 491 m_pluginData[identifier] = psd;
493 return psd; 492 return psd;
494 } 493 }
495 494