1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860
|
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
/*
Sonic Visualiser
An audio file viewer and annotation editor.
Centre for Digital Music, Queen Mary, University of London.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version. See the file
COPYING included with this distribution for more information.
*/
/*
This is a modified version of a source file from the
Rosegarden MIDI and audio sequencer and notation editor.
This file copyright 2000-2006 Chris Cannam and Richard Bown.
*/
#include "LADSPAPluginFactory.h"
#include <iostream>
#include <QDir>
#include <QFile>
#include <QTextStream>
#include <cmath>
#include "LADSPAPluginInstance.h"
#include "PluginIdentifier.h"
#include "system/System.h"
#include "base/Preferences.h"
#include "base/Profiler.h"
//#define DEBUG_LADSPA_PLUGIN_FACTORY 1
#ifdef HAVE_LRDF
#include "lrdf.h"
#endif // HAVE_LRDF
using std::string;
namespace sv {
LADSPAPluginFactory::LADSPAPluginFactory()
{
#ifdef HAVE_LRDF
lrdf_init();
#endif
}
LADSPAPluginFactory::~LADSPAPluginFactory()
{
unloadUnusedLibraries();
#ifdef HAVE_LRDF
lrdf_cleanup();
#endif // HAVE_LRDF
}
const std::vector<QString> &
LADSPAPluginFactory::getPluginIdentifiers() const
{
return m_identifiers;
}
QString
LADSPAPluginFactory::getPluginLibraryPath(QString identifier)
{
return m_libraries[identifier];
}
void
LADSPAPluginFactory::enumeratePlugins(std::vector<QString> &list)
{
Profiler profiler("LADSPAPluginFactory::enumeratePlugins");
for (std::vector<QString>::iterator i = m_identifiers.begin();
i != m_identifiers.end(); ++i) {
const LADSPA_Descriptor *descriptor = getLADSPADescriptor(*i);
if (!descriptor) {
SVCERR << "WARNING: LADSPAPluginFactory::enumeratePlugins: couldn't get descriptor for identifier " << *i << endl;
continue;
}
list.push_back(*i);
list.push_back(descriptor->Name);
list.push_back(QString("%1").arg(descriptor->UniqueID));
list.push_back(descriptor->Label);
list.push_back(descriptor->Maker);
list.push_back(descriptor->Copyright);
list.push_back("false"); // is synth
list.push_back("false"); // is grouped
if (m_taxonomy.find(*i) != m_taxonomy.end() && m_taxonomy[*i] != "") {
// SVCERR << "LADSPAPluginFactory: cat for " << *i << " found in taxonomy as " << m_taxonomy[descriptor->UniqueID] << endl;
list.push_back(m_taxonomy[*i]);
} else {
list.push_back("");
// SVCERR << "LADSPAPluginFactory: cat for " << *i << " not found (despite having " << m_fallbackCategories.size() << " fallbacks)" << endl;
}
list.push_back(QString("%1").arg(descriptor->PortCount));
for (int p = 0; p < (int)descriptor->PortCount; ++p) {
int type = 0;
if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[p])) {
type |= PortType::Control;
} else {
type |= PortType::Audio;
}
if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[p])) {
type |= PortType::Input;
} else {
type |= PortType::Output;
}
list.push_back(QString("%1").arg(p));
list.push_back(descriptor->PortNames[p]);
list.push_back(QString("%1").arg(type));
list.push_back(QString("%1").arg(getPortDisplayHint(descriptor, p)));
list.push_back(QString("%1").arg(getPortMinimum(descriptor, p)));
list.push_back(QString("%1").arg(getPortMaximum(descriptor, p)));
list.push_back(QString("%1").arg(getPortDefault(descriptor, p)));
}
}
unloadUnusedLibraries();
}
RealTimePluginDescriptor
LADSPAPluginFactory::getPluginDescriptor(QString identifier) const
{
std::map<QString, RealTimePluginDescriptor>::const_iterator i =
m_rtDescriptors.find(identifier);
if (i != m_rtDescriptors.end()) {
return i->second;
}
return {};
}
float
LADSPAPluginFactory::getPortMinimum(const LADSPA_Descriptor *descriptor, int port)
{
LADSPA_PortRangeHintDescriptor d =
descriptor->PortRangeHints[port].HintDescriptor;
float minimum = 0.f;
if (LADSPA_IS_HINT_BOUNDED_BELOW(d)) {
float lb = descriptor->PortRangeHints[port].LowerBound;
minimum = lb;
} else if (LADSPA_IS_HINT_BOUNDED_ABOVE(d)) {
float ub = descriptor->PortRangeHints[port].UpperBound;
minimum = std::min(0.f, ub - 1.f);
}
if (LADSPA_IS_HINT_SAMPLE_RATE(d)) {
minimum = float(minimum * m_sampleRate);
}
if (LADSPA_IS_HINT_LOGARITHMIC(d)) {
if (minimum == 0.f) minimum = 1.f;
}
return minimum;
}
float
LADSPAPluginFactory::getPortMaximum(const LADSPA_Descriptor *descriptor, int port)
{
LADSPA_PortRangeHintDescriptor d =
descriptor->PortRangeHints[port].HintDescriptor;
float maximum = 1.f;
if (LADSPA_IS_HINT_BOUNDED_ABOVE(d)) {
float ub = descriptor->PortRangeHints[port].UpperBound;
maximum = ub;
} else {
float lb = descriptor->PortRangeHints[port].LowerBound;
maximum = lb + 1.f;
}
if (LADSPA_IS_HINT_SAMPLE_RATE(d)) {
maximum = float(maximum * m_sampleRate);
}
return maximum;
}
float
LADSPAPluginFactory::getPortDefault(const LADSPA_Descriptor *descriptor, int port)
{
float minimum = getPortMinimum(descriptor, port);
float maximum = getPortMaximum(descriptor, port);
float deft;
if (m_portDefaults.find(descriptor->UniqueID) !=
m_portDefaults.end()) {
if (m_portDefaults[descriptor->UniqueID].find(port) !=
m_portDefaults[descriptor->UniqueID].end()) {
deft = m_portDefaults[descriptor->UniqueID][port];
if (deft < minimum) deft = minimum;
if (deft > maximum) deft = maximum;
return deft;
}
}
LADSPA_PortRangeHintDescriptor d =
descriptor->PortRangeHints[port].HintDescriptor;
bool logarithmic = LADSPA_IS_HINT_LOGARITHMIC(d);
float logmin = 0, logmax = 0;
if (logarithmic) {
float thresh = powf(10, -10);
if (minimum < thresh) logmin = -10;
else logmin = log10f(minimum);
if (maximum < thresh) logmax = -10;
else logmax = log10f(maximum);
}
// SVDEBUG << "LADSPAPluginFactory::getPortDefault: hint = " << d << endl;
if (!LADSPA_IS_HINT_HAS_DEFAULT(d)) {
deft = minimum;
} else if (LADSPA_IS_HINT_DEFAULT_MINIMUM(d)) {
deft = minimum;
} else if (LADSPA_IS_HINT_DEFAULT_LOW(d)) {
if (logarithmic) {
deft = powf(10, logmin * 0.75f + logmax * 0.25f);
} else {
deft = minimum * 0.75f + maximum * 0.25f;
}
} else if (LADSPA_IS_HINT_DEFAULT_MIDDLE(d)) {
if (logarithmic) {
deft = powf(10, logmin * 0.5f + logmax * 0.5f);
} else {
deft = minimum * 0.5f + maximum * 0.5f;
}
} else if (LADSPA_IS_HINT_DEFAULT_HIGH(d)) {
if (logarithmic) {
deft = powf(10, logmin * 0.25f + logmax * 0.75f);
} else {
deft = minimum * 0.25f + maximum * 0.75f;
}
} else if (LADSPA_IS_HINT_DEFAULT_MAXIMUM(d)) {
deft = maximum;
} else if (LADSPA_IS_HINT_DEFAULT_0(d)) {
deft = 0.0;
} else if (LADSPA_IS_HINT_DEFAULT_1(d)) {
deft = 1.0;
} else if (LADSPA_IS_HINT_DEFAULT_100(d)) {
deft = 100.0;
} else if (LADSPA_IS_HINT_DEFAULT_440(d)) {
// deft = 440.0;
deft = (float)Preferences::getInstance()->getTuningFrequency();
} else {
deft = minimum;
}
//!!! No -- the min and max have already been multiplied by the rate,
//so it would happen twice if we did it here -- and e.g. DEFAULT_440
//doesn't want to be multiplied by the rate either
// if (LADSPA_IS_HINT_SAMPLE_RATE(d)) {
// deft *= m_sampleRate;
// }
return deft;
}
float
LADSPAPluginFactory::getPortQuantization(const LADSPA_Descriptor *descriptor, int port)
{
int displayHint = getPortDisplayHint(descriptor, port);
if (displayHint & PortHint::Toggled) {
return float(lrintf(getPortMaximum(descriptor, port)) -
lrintf(getPortMinimum(descriptor, port)));
}
if (displayHint & PortHint::Integer) {
return 1.0;
}
return 0.0;
}
int
LADSPAPluginFactory::getPortDisplayHint(const LADSPA_Descriptor *descriptor, int port)
{
LADSPA_PortRangeHintDescriptor d =
descriptor->PortRangeHints[port].HintDescriptor;
int hint = PortHint::NoHint;
if (LADSPA_IS_HINT_TOGGLED(d)) hint |= PortHint::Toggled;
if (LADSPA_IS_HINT_INTEGER(d)) hint |= PortHint::Integer;
if (LADSPA_IS_HINT_LOGARITHMIC(d)) hint |= PortHint::Logarithmic;
return hint;
}
std::shared_ptr<RealTimePluginInstance>
LADSPAPluginFactory::instantiatePlugin(QString identifier,
int instrument,
int position,
sv_samplerate_t sampleRate,
int blockSize,
int channels)
{
Profiler profiler("LADSPAPluginFactory::instantiatePlugin");
const LADSPA_Descriptor *descriptor = getLADSPADescriptor(identifier);
if (descriptor) {
auto instance =
std::shared_ptr<RealTimePluginInstance>
(new LADSPAPluginInstance
(this, instrument, identifier, position,
sampleRate, blockSize, channels, descriptor));
m_instances.insert(instance);
#ifdef DEBUG_LADSPA_PLUGIN_FACTORY
SVDEBUG << "LADSPAPluginFactory::instantiatePlugin("
<< identifier << ": now have " << m_instances.size() << " instances" << endl;
#endif
return instance;
}
return nullptr;
}
const LADSPA_Descriptor *
LADSPAPluginFactory::getLADSPADescriptor(QString identifier)
{
QString type, soname, label;
PluginIdentifier::parseIdentifier(identifier, type, soname, label);
if (m_libraryHandles.find(soname) == m_libraryHandles.end()) {
loadLibrary(soname);
if (m_libraryHandles.find(soname) == m_libraryHandles.end()) {
SVCERR << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: loadLibrary failed for " << soname << endl;
return nullptr;
}
}
void *libraryHandle = m_libraryHandles[soname];
LADSPA_Descriptor_Function fn = (LADSPA_Descriptor_Function)
DLSYM(libraryHandle, "ladspa_descriptor");
if (!fn) {
SVCERR << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: No descriptor function in library " << soname << endl;
return nullptr;
}
const LADSPA_Descriptor *descriptor = nullptr;
int index = 0;
while ((descriptor = fn(index))) {
if (descriptor->Label == label) return descriptor;
++index;
}
SVCERR << "WARNING: LADSPAPluginFactory::getLADSPADescriptor: No such plugin as " << label << " in library " << soname << endl;
return nullptr;
}
void
LADSPAPluginFactory::loadLibrary(QString soName)
{
void *libraryHandle = DLOPEN(soName, RTLD_NOW);
if (libraryHandle) {
m_libraryHandles[soName] = libraryHandle;
SVDEBUG << "LADSPAPluginFactory::loadLibrary: Loaded library \"" << soName << "\"" << endl;
return;
}
if (QFileInfo(soName).exists()) {
DLERROR();
SVCERR << "LADSPAPluginFactory::loadLibrary: Library \"" << soName << "\" exists, but failed to load it" << endl;
return;
}
std::vector<QString> pathList = getPluginPath();
QString fileName = QFile(soName).fileName();
QString base = QFileInfo(soName).baseName();
for (std::vector<QString>::iterator i = pathList.begin();
i != pathList.end(); ++i) {
#ifdef DEBUG_LADSPA_PLUGIN_FACTORY
SVDEBUG << "Looking at: " << (*i) << endl;
#endif
QDir dir(*i, PLUGIN_GLOB,
QDir::Name | QDir::IgnoreCase,
QDir::Files | QDir::Readable);
if (QFileInfo(dir.filePath(fileName)).exists()) {
#ifdef DEBUG_LADSPA_PLUGIN_FACTORY
SVDEBUG << "Loading: " << fileName << endl;
#endif
libraryHandle = DLOPEN(dir.filePath(fileName), RTLD_NOW);
if (libraryHandle) {
m_libraryHandles[soName] = libraryHandle;
return;
}
}
for (unsigned int j = 0; j < dir.count(); ++j) {
QString file = dir.filePath(dir[j]);
if (QFileInfo(file).baseName() == base) {
#ifdef DEBUG_LADSPA_PLUGIN_FACTORY
SVDEBUG << "Loading: " << file << endl;
#endif
libraryHandle = DLOPEN(file, RTLD_NOW);
if (libraryHandle) {
m_libraryHandles[soName] = libraryHandle;
return;
}
}
}
}
SVCERR << "LADSPAPluginFactory::loadLibrary: Failed to locate plugin library \"" << soName << "\"" << endl;
}
void
LADSPAPluginFactory::unloadLibrary(QString soName)
{
LibraryHandleMap::iterator li = m_libraryHandles.find(soName);
if (li != m_libraryHandles.end()) {
// SVDEBUG << "unloading " << soname << endl;
DLCLOSE(m_libraryHandles[soName]);
m_libraryHandles.erase(li);
}
}
void
LADSPAPluginFactory::unloadUnusedLibraries()
{
std::set<std::weak_ptr<RealTimePluginInstance>,
std::owner_less<std::weak_ptr<RealTimePluginInstance>>> toRemove;
std::set<QString> soNamesInUse;
for (auto wp: m_instances) {
if (auto p = wp.lock()) {
QString itype, isoname, ilabel;
PluginIdentifier::parseIdentifier(p->getPluginIdentifier(),
itype, isoname, ilabel);
soNamesInUse.insert(isoname);
} else {
toRemove.insert(wp);
}
}
for (auto wp: toRemove) {
m_instances.erase(wp);
}
std::vector<QString> toUnload;
for (auto i = m_libraryHandles.begin();
i != m_libraryHandles.end(); ++i) {
if (soNamesInUse.find(i->first) == soNamesInUse.end()) {
toUnload.push_back(i->first);
}
}
for (auto soname: toUnload) {
if (soname != PluginIdentifier::BUILTIN_PLUGIN_SONAME) {
unloadLibrary(soname);
}
}
}
// It is only later, after they've gone,
// I realize they have delivered a letter.
// It's a letter from my wife. "What are you doing
// there?" my wife asks. "Are you drinking?"
// I study the postmark for hours. Then it, too, begins to fade.
// I hope someday to forget all this.
std::vector<QString>
LADSPAPluginFactory::getPluginPath()
{
std::vector<QString> pathList;
string path;
(void)getEnvUtf8("LADSPA_PATH", path);
if (path == "") {
path = DEFAULT_LADSPA_PATH;
string home;
if (getEnvUtf8("HOME", home)) {
string::size_type f;
while ((f = path.find("$HOME")) != string::npos &&
f < path.length()) {
path.replace(f, 5, home);
}
}
#ifdef _WIN32
string pfiles;
if (!getEnvUtf8("ProgramFiles", pfiles)) {
pfiles = "C:\\Program Files";
}
string::size_type f;
while ((f = path.find("%ProgramFiles%")) != string::npos &&
f < path.length()) {
path.replace(f, 14, pfiles);
}
#endif
}
string::size_type index = 0, newindex = 0;
while ((newindex = path.find(PATH_SEPARATOR, index)) < path.size()) {
pathList.push_back(path.substr(index, newindex - index).c_str());
index = newindex + 1;
}
pathList.push_back(path.substr(index).c_str());
return pathList;
}
std::vector<QString>
LADSPAPluginFactory::getLRDFPath(QString &baseUri)
{
std::vector<QString> lrdfPaths;
#ifdef HAVE_LRDF
std::vector<QString> pathList = getPluginPath();
lrdfPaths.push_back("/usr/local/share/ladspa/rdf");
lrdfPaths.push_back("/usr/share/ladspa/rdf");
for (std::vector<QString>::iterator i = pathList.begin();
i != pathList.end(); ++i) {
lrdfPaths.push_back(*i + "/rdf");
}
baseUri = LADSPA_BASE;
#else
baseUri = "";
#endif
return lrdfPaths;
}
void
LADSPAPluginFactory::discoverPlugins()
{
Profiler profiler("LADSPAPluginFactory::discoverPlugins");
std::vector<QString> pathList = getPluginPath();
// SVDEBUG << "LADSPAPluginFactory::discoverPlugins - "
// << "discovering plugins; path is ";
// for (std::vector<QString>::iterator i = pathList.begin();
// i != pathList.end(); ++i) {
// SVDEBUG << "[" << i-<< "] ";
// }
// SVDEBUG << endl;
#ifdef HAVE_LRDF
// read the description files
//
QString baseUri;
std::vector<QString> lrdfPaths = getLRDFPath(baseUri);
bool haveSomething = false;
for (size_t i = 0; i < lrdfPaths.size(); ++i) {
QDir dir(lrdfPaths[i], "*.rdf;*.rdfs");
for (unsigned int j = 0; j < dir.count(); ++j) {
if (!lrdf_read_file(QString("file:" + lrdfPaths[i] + "/" + dir[j]).toStdString().c_str())) {
// SVCERR << "LADSPAPluginFactory: read RDF file " << (lrdfPaths[i] + "/" + dir[j]) << endl;
haveSomething = true;
}
}
}
if (haveSomething) {
generateTaxonomy(baseUri + "Plugin", "");
}
#endif // HAVE_LRDF
generateFallbackCategories();
auto candidates =
PluginScan::getInstance()->getCandidateLibrariesFor(getPluginType());
for (auto c: candidates) {
discoverPluginsFrom(c.libraryPath);
}
}
void
LADSPAPluginFactory::discoverPluginsFrom(QString soname)
{
void *libraryHandle = DLOPEN(soname, RTLD_LAZY);
if (!libraryHandle) {
SVCERR << "WARNING: LADSPAPluginFactory::discoverPlugins: couldn't load plugin library "
<< soname << " - " << DLERROR() << endl;
return;
}
LADSPA_Descriptor_Function fn = (LADSPA_Descriptor_Function)
DLSYM(libraryHandle, "ladspa_descriptor");
if (!fn) {
SVCERR << "WARNING: LADSPAPluginFactory::discoverPlugins: No descriptor function in " << soname << endl;
return;
}
const LADSPA_Descriptor *descriptor = nullptr;
int index = 0;
while ((descriptor = fn(index))) {
RealTimePluginDescriptor rtd;
rtd.name = descriptor->Name;
rtd.label = descriptor->Label;
rtd.maker = descriptor->Maker;
rtd.copyright = descriptor->Copyright;
rtd.category = "";
rtd.isSynth = false;
rtd.parameterCount = 0;
rtd.audioInputPortCount = 0;
rtd.audioOutputPortCount = 0;
rtd.controlOutputPortCount = 0;
QString identifier = PluginIdentifier::createIdentifier
("ladspa", soname, descriptor->Label);
#ifdef HAVE_LRDF
char *def_uri = nullptr;
lrdf_defaults *defs = nullptr;
if (m_lrdfTaxonomy[descriptor->UniqueID] != "") {
m_taxonomy[identifier] = m_lrdfTaxonomy[descriptor->UniqueID];
// SVCERR << "set id \"" << identifier << "\" to cat \"" << m_taxonomy[identifier] << "\" from LRDF" << endl;
// cout << identifier << "::" << m_taxonomy[identifier] << endl;
}
QString category = m_taxonomy[identifier];
if (category == "") {
string name = rtd.name;
if (name.length() > 4 &&
name.substr(name.length() - 4) == " VST") {
category = "VST effects";
m_taxonomy[identifier] = category;
}
}
rtd.category = category.toStdString();
// SVCERR << "Plugin id is " << descriptor->UniqueID
// << ", category is \"" << (category ? category : QString("(none)"))
// << "\", name is " << descriptor->Name
// << ", label is " << descriptor->Label
// << endl;
def_uri = lrdf_get_default_uri(descriptor->UniqueID);
if (def_uri) {
defs = lrdf_get_setting_values(def_uri);
}
unsigned int controlPortNumber = 1;
for (int i = 0; i < (int)descriptor->PortCount; i++) {
if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[i])) {
if (def_uri && defs) {
for (unsigned int j = 0; j < defs->count; j++) {
if (defs->items[j].pid == controlPortNumber) {
// SVCERR << "Default for this port (" << defs->items[j].pid << ", " << defs->items[j].label << ") is " << defs->items[j].value << "; applying this to port number " << i << " with name " << descriptor->PortNames[i] << endl;
m_portDefaults[descriptor->UniqueID][i] =
defs->items[j].value;
}
}
}
++controlPortNumber;
}
}
#endif // HAVE_LRDF
for (int i = 0; i < (int)descriptor->PortCount; i++) {
if (LADSPA_IS_PORT_CONTROL(descriptor->PortDescriptors[i])) {
if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[i])) {
++rtd.parameterCount;
} else {
if (strcmp(descriptor->PortNames[i], "latency") &&
strcmp(descriptor->PortNames[i], "_latency")) {
++rtd.controlOutputPortCount;
rtd.controlOutputPortNames.push_back
(descriptor->PortNames[i]);
}
}
} else {
if (LADSPA_IS_PORT_INPUT(descriptor->PortDescriptors[i])) {
++rtd.audioInputPortCount;
} else if (LADSPA_IS_PORT_OUTPUT(descriptor->PortDescriptors[i])) {
++rtd.audioOutputPortCount;
}
}
}
m_identifiers.push_back(identifier);
m_libraries[identifier] = soname;
m_rtDescriptors[identifier] = rtd;
++index;
}
if (DLCLOSE(libraryHandle) != 0) {
SVCERR << "WARNING: LADSPAPluginFactory::discoverPlugins - can't unload " << libraryHandle << endl;
return;
}
}
void
LADSPAPluginFactory::generateFallbackCategories()
{
std::vector<QString> pluginPath = getPluginPath();
std::vector<QString> path;
for (size_t i = 0; i < pluginPath.size(); ++i) {
if (pluginPath[i].contains("/lib/")) {
QString p(pluginPath[i]);
path.push_back(p);
p.replace("/lib/", "/share/");
path.push_back(p);
// SVDEBUG << "LADSPAPluginFactory::generateFallbackCategories: path element " << p << endl;
}
path.push_back(pluginPath[i]);
// SVDEBUG << "LADSPAPluginFactory::generateFallbackCategories: path element " << pluginPath[i] << endl;
}
for (size_t i = 0; i < path.size(); ++i) {
QDir dir(path[i], "*.cat");
// SVDEBUG << "LADSPAPluginFactory::generateFallbackCategories: directory " << path[i] << " has " << dir.count() << " .cat files" << endl;
for (unsigned int j = 0; j < dir.count(); ++j) {
QFile file(path[i] + "/" + dir[j]);
// SVDEBUG << "LADSPAPluginFactory::generateFallbackCategories: about to open " << (path[i]+ "/" + dir[j]) << endl;
if (file.open(QIODevice::ReadOnly)) {
// cerr << "...opened" << endl;
QTextStream stream(&file);
QString line;
while (!stream.atEnd()) {
line = stream.readLine();
// cerr << "line is: \"" << line << "\"" << endl;
QString id = PluginIdentifier::canonicalise
(line.section("::", 0, 0));
QString cat = line.section("::", 1, 1);
m_taxonomy[id] = cat;
// cerr << "set id \"" << id << "\" to cat \"" << cat << "\"" << endl;
}
}
}
}
}
void
LADSPAPluginFactory::generateTaxonomy(QString uri, QString base)
{
#ifdef HAVE_LRDF
lrdf_uris *uris = lrdf_get_instances(uri.toStdString().c_str());
if (uris != nullptr) {
for (unsigned int i = 0; i < uris->count; ++i) {
m_lrdfTaxonomy[lrdf_get_uid(uris->items[i])] = base;
}
lrdf_free_uris(uris);
}
uris = lrdf_get_subclasses(uri.toStdString().c_str());
if (uris != nullptr) {
for (unsigned int i = 0; i < uris->count; ++i) {
char *label = lrdf_get_label(uris->items[i]);
generateTaxonomy(uris->items[i],
base + (base.length() > 0 ? " > " : "") + label);
}
lrdf_free_uris(uris);
}
#else
// avoid unused parameter
(void)uri;
(void)base;
#endif
}
QString
LADSPAPluginFactory::getPluginCategory(QString identifier)
{
return m_taxonomy[identifier];
}
} // end namespace sv
|