Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

792 lines
20KB

  1. //
  2. // LADSPAInfo.C - Class for indexing information on LADSPA Plugins
  3. //
  4. // Copyleft (C) 2002 Mike Rawes <myk@waxfrenzy.org>
  5. //
  6. // This program is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU General Public License as published by
  8. // the Free Software Foundation; either version 2 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // This program is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU General Public License
  17. // along with this program; if not, write to the Free Software
  18. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. //
  20. // #include <config.h>
  21. #include <vector>
  22. #include <string>
  23. #include <list>
  24. #include <map>
  25. #include <iostream>
  26. #include <sstream>
  27. #include <algorithm>
  28. #include <stdio.h>
  29. #include <cstring>
  30. #include <cstdlib>
  31. #include <sys/types.h>
  32. #include <sys/stat.h>
  33. #include <dirent.h>
  34. #include <dlfcn.h>
  35. #include <ladspa.h>
  36. #define HAVE_LIBLRDF 1
  37. #ifdef HAVE_LIBLRDF
  38. #include <lrdf.h>
  39. #endif
  40. #include "LADSPAInfo.h"
  41. using namespace std;
  42. LADSPAInfo::LADSPAInfo(bool override,
  43. const char *path_list)
  44. {
  45. if (strlen(path_list) > 0) {
  46. m_ExtraPaths = strdup(path_list);
  47. } else {
  48. m_ExtraPaths = NULL;
  49. }
  50. m_LADSPAPathOverride = override;
  51. RescanPlugins();
  52. }
  53. LADSPAInfo::~LADSPAInfo()
  54. {
  55. CleanUp();
  56. }
  57. void
  58. LADSPAInfo::RescanPlugins(void)
  59. {
  60. // Clear out what we've got
  61. CleanUp();
  62. if (!m_LADSPAPathOverride) {
  63. // Get $LADPSA_PATH, if available
  64. char *ladspa_path = getenv("LADSPA_PATH");
  65. if (ladspa_path) {
  66. ScanPathList(ladspa_path, &LADSPAInfo::ExaminePluginLibrary);
  67. } else {
  68. cerr << "WARNING: LADSPA_PATH environment variable not set" << endl;
  69. cerr << " Assuming /usr/lib/ladspa:/usr/local/lib/ladspa" << endl;
  70. ScanPathList("/usr/lib/ladspa:/usr/local/lib/ladspa", &LADSPAInfo::ExaminePluginLibrary);
  71. }
  72. }
  73. // Check any supplied extra paths
  74. if (m_ExtraPaths) {
  75. ScanPathList(m_ExtraPaths, &LADSPAInfo::ExaminePluginLibrary);
  76. }
  77. // Do we have any plugins now?
  78. if (m_Plugins.size() == 0) {
  79. cerr << "WARNING: No plugins found" << endl;
  80. } else {
  81. cerr << m_Plugins.size() << " plugins found in " << m_Libraries.size() << " libraries" << endl;
  82. #ifdef HAVE_LIBLRDF
  83. // Got some plugins. Now search for RDF data
  84. lrdf_init();
  85. char *rdf_path = getenv("LADSPA_RDF_PATH");
  86. if (rdf_path) {
  87. // Examine rdf info
  88. ScanPathList(rdf_path, &LADSPAInfo::ExamineRDFFile);
  89. } else {
  90. cerr << "WARNING: LADSPA_RDF_PATH environment variable not set" << endl;
  91. cerr << " Assuming /usr/share/ladspa/rdf:/usr/local/share/ladspa/rdf" << endl;
  92. // Examine rdf info
  93. ScanPathList("/usr/share/ladspa/rdf:/usr/local/share/ladspa/rdf", &LADSPAInfo::ExamineRDFFile);
  94. }
  95. MetadataRDFDescend(LADSPA_BASE "Plugin", 0);
  96. // See which plugins were not added to an rdf group, and add them
  97. // all into the top level 'LADSPA' one
  98. list<unsigned long> rdf_p;
  99. // Get indices of plugins added to groups
  100. for (vector<RDFURIInfo>::iterator ri = m_RDFURIs.begin(); ri != m_RDFURIs.end(); ri++) {
  101. rdf_p.insert(rdf_p.begin(), ri->Plugins.begin(), ri->Plugins.end());
  102. }
  103. // Add all uncategorized plugins to top level group, subclassed by their
  104. // library's basename.
  105. rdf_p.unique();
  106. rdf_p.sort();
  107. unsigned long last_p = 0;
  108. for (list<unsigned long>::iterator p = rdf_p.begin(); p != rdf_p.end(); p++) {
  109. if ((*p - last_p) > 1) {
  110. for (unsigned long i = last_p + 1; i < *p; i++) {
  111. // URI 0 is top-level "LADSPA" group
  112. m_RDFURIs[0].Plugins.push_back(i);
  113. }
  114. }
  115. last_p = *p;
  116. }
  117. while (++last_p < m_Plugins.size()) {
  118. // URI 0 is top-level "LADSPA" group
  119. m_RDFURIs[0].Plugins.push_back(last_p);
  120. }
  121. lrdf_cleanup();
  122. #else
  123. // No RDF. Add all plugins to top-level group
  124. RDFURIInfo ri;
  125. ri.URI = "";
  126. ri.Label = "LADSPA";
  127. m_RDFURIs.push_back(ri);
  128. m_RDFLabelLookup["LADSPA"] = 0;
  129. for (unsigned long i = 0; i < m_Plugins.size(); i++) {
  130. // Add plugin index
  131. m_RDFURIs[0].Plugins.push_back(i);
  132. }
  133. #endif
  134. }
  135. }
  136. void
  137. LADSPAInfo::UnloadAllLibraries(void)
  138. {
  139. // Blank descriptors
  140. for (vector<PluginInfo>::iterator i = m_Plugins.begin();
  141. i != m_Plugins.end(); i++) {
  142. if (i->Descriptor) i->Descriptor = NULL;
  143. }
  144. // Unload DLLs,
  145. for (vector<LibraryInfo>::iterator i = m_Libraries.begin();
  146. i != m_Libraries.end(); i++) {
  147. if (i->Handle) {
  148. dlclose(i->Handle);
  149. i->Handle = NULL;
  150. }
  151. i->RefCount = 0;
  152. }
  153. }
  154. const LADSPA_Descriptor *
  155. LADSPAInfo::GetDescriptorByID(unsigned long unique_id)
  156. {
  157. if (m_IDLookup.find(unique_id) == m_IDLookup.end()) {
  158. cerr << "LADSPA Plugin ID " << unique_id << " not found!" << endl;
  159. return NULL;
  160. }
  161. // Got plugin index
  162. unsigned long plugin_index = m_IDLookup[unique_id];
  163. PluginInfo *pi = &(m_Plugins[plugin_index]);
  164. LibraryInfo *li = &(m_Libraries[pi->LibraryIndex]);
  165. if (!(pi->Descriptor)) {
  166. LADSPA_Descriptor_Function desc_func = GetDescriptorFunctionForLibrary(pi->LibraryIndex);
  167. if (desc_func) pi->Descriptor = desc_func(pi->Index);
  168. }
  169. if (pi->Descriptor) {
  170. // Success, so increment ref counter for library
  171. li->RefCount++;
  172. }
  173. return pi->Descriptor;
  174. }
  175. void
  176. LADSPAInfo::DiscardDescriptorByID(unsigned long unique_id)
  177. {
  178. if (m_IDLookup.find(unique_id) == m_IDLookup.end()) {
  179. cerr << "LADSPA Plugin ID " << unique_id << " not found!" << endl;
  180. } else {
  181. // Get plugin index
  182. unsigned long plugin_index = m_IDLookup[unique_id];
  183. PluginInfo *pi = &(m_Plugins[plugin_index]);
  184. LibraryInfo *li = &(m_Libraries[pi->LibraryIndex]);
  185. pi->Descriptor = NULL;
  186. // Decrement reference counter for library, and unload if last
  187. if (li->RefCount > 0) {
  188. li->RefCount--;
  189. if (li->RefCount == 0) {
  190. // Unload library
  191. dlclose(li->Handle);
  192. li->Handle = NULL;
  193. }
  194. }
  195. }
  196. }
  197. // ****************************************************************************
  198. // ** SSM Specific Functions **
  199. // ****************************************************************************
  200. unsigned long
  201. LADSPAInfo::GetIDFromFilenameAndLabel(std::string filename,
  202. std::string label)
  203. {
  204. bool library_loaded = false;
  205. if (m_FilenameLookup.find(filename) == m_FilenameLookup.end()) {
  206. cerr << "LADSPA Library " << filename << " not found!" << endl;
  207. return 0;
  208. }
  209. unsigned long library_index = m_FilenameLookup[filename];
  210. if (!(m_Libraries[library_index].Handle)) library_loaded = true;
  211. LADSPA_Descriptor_Function desc_func = GetDescriptorFunctionForLibrary(library_index);
  212. if (!desc_func) {
  213. return 0;
  214. }
  215. // Search for label in library
  216. const LADSPA_Descriptor *desc;
  217. for (unsigned long i = 0; (desc = desc_func(i)) != NULL; i++) {
  218. string l = desc->Label;
  219. if (l == label) {
  220. // If we had to load the library, unload it
  221. unsigned long id = desc->UniqueID;
  222. if (library_loaded) {
  223. dlclose(m_Libraries[library_index].Handle);
  224. m_Libraries[library_index].Handle = NULL;
  225. }
  226. return id;
  227. }
  228. }
  229. cerr << "Plugin " << label << " not found in library " << filename << endl;
  230. return 0;
  231. }
  232. const vector<LADSPAInfo::PluginEntry>
  233. LADSPAInfo::GetMenuList(void)
  234. {
  235. m_SSMMenuList.clear();
  236. DescendGroup("", "LADSPA", 1);
  237. return m_SSMMenuList;
  238. }
  239. unsigned long
  240. LADSPAInfo::GetPluginListEntryByID(unsigned long unique_id)
  241. {
  242. unsigned long j = 0;
  243. for (vector<PluginEntry>::iterator i = m_SSMMenuList.begin();
  244. i != m_SSMMenuList.end(); i++, j++) {
  245. if (i->UniqueID == unique_id) return j;
  246. }
  247. return m_SSMMenuList.size();
  248. }
  249. // ****************************************************************************
  250. // ** Private Member Functions **
  251. // ****************************************************************************
  252. // Build a list of plugins by group, suitable for SSM LADSPA Plugin drop-down
  253. // The top-level "LADSPA" group is not included
  254. void
  255. LADSPAInfo::DescendGroup(string prefix,
  256. const string group,
  257. unsigned int depth)
  258. {
  259. list<string> groups = GetSubGroups(group);
  260. if (prefix.length() > 0) {
  261. // Add an explicit '/' as we're creating sub-menus from groups
  262. prefix += "/";
  263. }
  264. for (list<string>::iterator g = groups.begin(); g != groups.end(); g++) {
  265. string name;
  266. // Escape '/' and '|' characters
  267. unsigned int x = g->find_first_of("/|");
  268. if (x == string::npos) {
  269. name = *g;
  270. } else {
  271. unsigned int last_x = 0;
  272. while (x < string::npos) {
  273. name += g->substr(last_x, x - last_x) + '\\' + (*g)[x];
  274. last_x = x + 1;
  275. x = g->find_first_of("/|", x + 1);
  276. }
  277. name += g->substr(last_x, x - last_x);
  278. }
  279. DescendGroup(prefix + name, *g, depth + 1);
  280. }
  281. if (m_RDFLabelLookup.find(group) != m_RDFLabelLookup.end()) {
  282. unsigned long uri_index = m_RDFLabelLookup[group];
  283. // Create group for unclassified plugins
  284. if (prefix.length() == 0) {
  285. prefix = "Unclassified/";
  286. depth = depth + 1;
  287. }
  288. // Temporary list (for sorting the plugins by name)
  289. list<PluginEntry> plugins;
  290. for (vector<unsigned long>::iterator p = m_RDFURIs[uri_index].Plugins.begin();
  291. p != m_RDFURIs[uri_index].Plugins.end(); p++) {
  292. PluginInfo *pi = &(m_Plugins[*p]);
  293. string name;
  294. // Escape '/' and '|' characters
  295. unsigned int x = pi->Name.find_first_of("/|");
  296. if (x == string::npos) {
  297. name = pi->Name;
  298. } else {
  299. unsigned int last_x = 0;
  300. while (x < string::npos) {
  301. name += pi->Name.substr(last_x, x - last_x) + '\\' + pi->Name[x];
  302. last_x = x + 1;
  303. x = pi->Name.find_first_of("/|", x + 1);
  304. }
  305. name += pi->Name.substr(last_x, x - last_x);
  306. }
  307. PluginEntry pe;
  308. pe.Depth = depth;
  309. pe.UniqueID = pi->UniqueID;
  310. pe.Name = prefix + name;
  311. plugins.push_back(pe);
  312. }
  313. plugins.sort();
  314. // Deal with duplicates by numbering them
  315. for (list<PluginEntry>::iterator i = plugins.begin();
  316. i != plugins.end(); ) {
  317. string name = i->Name;
  318. i++;
  319. unsigned long n = 2;
  320. while ((i != plugins.end()) && (i->Name == name)) {
  321. stringstream s;
  322. s << n;
  323. i->Name = name + " (" + s.str() + ")";
  324. n++;
  325. i++;
  326. }
  327. }
  328. // Add all ordered entries to the Menu List
  329. // This ensures that plugins appear after groups
  330. for (list<PluginEntry>::iterator p = plugins.begin(); p != plugins.end(); p++) {
  331. m_SSMMenuList.push_back(*p);
  332. }
  333. }
  334. }
  335. // Get list of groups that are within given group. The root group is
  336. // always "LADSPA"
  337. list<string>
  338. LADSPAInfo::GetSubGroups(const string group)
  339. {
  340. list<string> groups;
  341. unsigned long uri_index;
  342. if (m_RDFLabelLookup.find(group) == m_RDFLabelLookup.end()) {
  343. return groups;
  344. } else {
  345. uri_index = m_RDFLabelLookup[group];
  346. }
  347. for (vector<unsigned long>::iterator sg = m_RDFURIs[uri_index].Children.begin();
  348. sg != m_RDFURIs[uri_index].Children.end(); sg++) {
  349. groups.push_back(m_RDFURIs[*sg].Label);
  350. }
  351. groups.sort();
  352. return groups;
  353. }
  354. // Unload any loaded DLLs and clear vectors etc
  355. void
  356. LADSPAInfo::CleanUp(void)
  357. {
  358. m_MaxInputPortCount = 0;
  359. m_IDLookup.clear();
  360. m_Plugins.clear();
  361. // Unload loaded dlls
  362. for (vector<LibraryInfo>::iterator i = m_Libraries.begin();
  363. i != m_Libraries.end(); i++) {
  364. if (i->Handle) dlclose(i->Handle);
  365. }
  366. m_Libraries.clear();
  367. m_Paths.clear();
  368. m_RDFURILookup.clear();
  369. m_RDFURIs.clear();
  370. if (m_ExtraPaths) {
  371. free(m_ExtraPaths);
  372. m_ExtraPaths = NULL;
  373. }
  374. }
  375. // Given a colon-separated list of paths, examine the contents of each
  376. // path, examining any regular files using the given member function,
  377. // which currently can be:
  378. //
  379. // ExaminePluginLibrary - add plugin library info from plugins
  380. // ExamineRDFFile - add plugin information from .rdf/.rdfs files
  381. void
  382. LADSPAInfo::ScanPathList(const char *path_list,
  383. void (LADSPAInfo::*ExamineFunc)(const string,
  384. const string))
  385. {
  386. const char *start;
  387. const char *end;
  388. int extra;
  389. char *path;
  390. string basename;
  391. DIR *dp;
  392. struct dirent *ep;
  393. struct stat sb;
  394. // This does the same kind of thing as strtok, but strtok won't
  395. // like the const
  396. start = path_list;
  397. while (*start != '\0') {
  398. while (*start == ':') start++;
  399. end = start;
  400. while (*end != ':' && *end != '\0') end++;
  401. if (end - start > 0) {
  402. extra = (*(end - 1) == '/') ? 0 : 1;
  403. path = (char *)malloc(end - start + 1 + extra);
  404. if (path) {
  405. strncpy(path, start, end - start);
  406. if (extra == 1) path[end - start] = '/';
  407. path[end - start + extra] = '\0';
  408. dp = opendir(path);
  409. if (!dp) {
  410. cerr << "WARNING: Could not open path " << path << endl;
  411. } else {
  412. while ((ep = readdir(dp))) {
  413. // Stat file to get type
  414. basename = ep->d_name;
  415. if (!stat((path + basename).c_str(), &sb)) {
  416. // We only want regular files
  417. if (S_ISREG(sb.st_mode)) (*this.*ExamineFunc)(path, basename);
  418. }
  419. }
  420. closedir(dp);
  421. }
  422. free(path);
  423. }
  424. }
  425. start = end;
  426. }
  427. }
  428. // Check given file is a valid LADSPA Plugin library
  429. //
  430. // If so, add path, library and plugin info
  431. // to the m_Paths, m_Libraries and m_Plugins vectors.
  432. //
  433. void
  434. LADSPAInfo::ExaminePluginLibrary(const string path,
  435. const string basename)
  436. {
  437. void *handle;
  438. LADSPA_Descriptor_Function desc_func;
  439. const LADSPA_Descriptor *desc;
  440. string fullpath = path + basename;
  441. // We're not executing any code, so be lazy about resolving symbols
  442. handle = dlopen(fullpath.c_str(), RTLD_LAZY);
  443. if (!handle) {
  444. cerr << "WARNING: File " << fullpath
  445. << " could not be examined" << endl;
  446. cerr << "dlerror() output:" << endl;
  447. cerr << dlerror() << endl;
  448. } else {
  449. // It's a DLL, so now see if it's a LADSPA plugin library
  450. desc_func = (LADSPA_Descriptor_Function)dlsym(handle,
  451. "ladspa_descriptor");
  452. if (!desc_func) {
  453. // Is DLL, but not a LADSPA one
  454. cerr << "WARNING: DLL " << fullpath
  455. << " has no ladspa_descriptor function" << endl;
  456. cerr << "dlerror() output:" << endl;
  457. cerr << dlerror() << endl;
  458. } else {
  459. // Got ladspa_descriptor, so we can now get plugin info
  460. bool library_added = false;
  461. unsigned long i = 0;
  462. desc = desc_func(i);
  463. while (desc) {
  464. // First, check that it's not a dupe
  465. if (m_IDLookup.find(desc->UniqueID) != m_IDLookup.end()) {
  466. unsigned long plugin_index = m_IDLookup[desc->UniqueID];
  467. unsigned long library_index = m_Plugins[plugin_index].LibraryIndex;
  468. unsigned long path_index = m_Libraries[library_index].PathIndex;
  469. cerr << "WARNING: Duplicated Plugin ID ("
  470. << desc->UniqueID << ") found:" << endl;
  471. cerr << " Plugin " << m_Plugins[plugin_index].Index
  472. << " in library: " << m_Paths[path_index]
  473. << m_Libraries[library_index].Basename
  474. << " [First instance found]" << endl;
  475. cerr << " Plugin " << i << " in library: " << fullpath
  476. << " [Duplicate not added]" << endl;
  477. } else {
  478. if (CheckPlugin(desc)) {
  479. // Add path if not already added
  480. unsigned long path_index;
  481. vector<string>::iterator p = find(m_Paths.begin(), m_Paths.end(), path);
  482. if (p == m_Paths.end()) {
  483. path_index = m_Paths.size();
  484. m_Paths.push_back(path);
  485. } else {
  486. path_index = p - m_Paths.begin();
  487. }
  488. // Add library info if not already added
  489. if (!library_added) {
  490. LibraryInfo li;
  491. li.PathIndex = path_index;
  492. li.Basename = basename;
  493. li.RefCount = 0;
  494. li.Handle = NULL;
  495. m_Libraries.push_back(li);
  496. library_added = true;
  497. }
  498. // Add plugin info
  499. PluginInfo pi;
  500. pi.LibraryIndex = m_Libraries.size() - 1;
  501. pi.Index = i;
  502. pi.UniqueID = desc->UniqueID;
  503. pi.Label = desc->Label;
  504. pi.Name = desc->Name;
  505. pi.Descriptor = NULL;
  506. m_Plugins.push_back(pi);
  507. // Find number of input ports
  508. unsigned long in_port_count = 0;
  509. for (unsigned long p = 0; p < desc->PortCount; p++) {
  510. if (LADSPA_IS_PORT_INPUT(desc->PortDescriptors[p])) {
  511. in_port_count++;
  512. }
  513. }
  514. if (in_port_count > m_MaxInputPortCount) {
  515. m_MaxInputPortCount = in_port_count;
  516. }
  517. // Add to index
  518. m_IDLookup[desc->UniqueID] = m_Plugins.size() - 1;
  519. } else {
  520. cerr << "WARNING: Plugin " << desc->UniqueID << " not added" << endl;
  521. }
  522. }
  523. desc = desc_func(++i);
  524. }
  525. }
  526. dlclose(handle);
  527. }
  528. }
  529. #ifdef HAVE_LIBLRDF
  530. // Examine given RDF plugin meta-data file
  531. void
  532. LADSPAInfo::ExamineRDFFile(const std::string path,
  533. const std::string basename)
  534. {
  535. string fileuri = "file://" + path + basename;
  536. if (lrdf_read_file(fileuri.c_str())) {
  537. cerr << "WARNING: File " << path + basename << " could not be parsed [Ignored]" << endl;
  538. }
  539. }
  540. // Recursively add rdf information for plugins that have been
  541. // found from scanning LADSPA_PATH
  542. void
  543. LADSPAInfo::MetadataRDFDescend(const char * uri,
  544. unsigned long parent)
  545. {
  546. unsigned long this_uri_index;
  547. // Check URI not already added
  548. if (m_RDFURILookup.find(uri) == m_RDFURILookup.end()) {
  549. // Not found
  550. RDFURIInfo ri;
  551. ri.URI = uri;
  552. if (ri.URI == LADSPA_BASE "Plugin") {
  553. // Add top level group as "LADSPA"
  554. // This will always happen, even if there are no .rdf files read by liblrdf
  555. // or if there is no liblrdf support
  556. ri.Label = "LADSPA";
  557. } else {
  558. char * label = lrdf_get_label(uri);
  559. if (label) {
  560. ri.Label = label;
  561. } else {
  562. ri.Label = "(No label)";
  563. }
  564. }
  565. // Add any instances found
  566. lrdf_uris * instances = lrdf_get_instances(uri);
  567. if (instances) {
  568. for (long j = 0; j < instances->count; j++) {
  569. unsigned long uid = lrdf_get_uid(instances->items[j]);
  570. if (m_IDLookup.find(uid) != m_IDLookup.end()) {
  571. ri.Plugins.push_back(m_IDLookup[uid]);
  572. }
  573. }
  574. }
  575. lrdf_free_uris(instances);
  576. m_RDFURIs.push_back(ri);
  577. this_uri_index = m_RDFURIs.size() - 1;
  578. m_RDFURILookup[ri.URI] = this_uri_index;
  579. m_RDFLabelLookup[ri.Label] = this_uri_index;
  580. } else {
  581. // Already added
  582. this_uri_index = m_RDFURILookup[uri];
  583. }
  584. // Only add parent - child info if this uri is NOT the first (root) uri
  585. if (this_uri_index > 0) {
  586. m_RDFURIs[this_uri_index].Parents.push_back(parent);
  587. m_RDFURIs[parent].Children.push_back(this_uri_index);
  588. }
  589. lrdf_uris * uris = lrdf_get_subclasses(uri);
  590. if (uris) {
  591. for (long i = 0; i < uris->count; i++) {
  592. MetadataRDFDescend(uris->items[i], this_uri_index);
  593. }
  594. }
  595. lrdf_free_uris(uris);
  596. }
  597. #endif
  598. bool
  599. LADSPAInfo::CheckPlugin(const LADSPA_Descriptor *desc)
  600. {
  601. #define test(t, m) { \
  602. if (!(t)) { \
  603. cerr << m << endl; \
  604. return false; \
  605. } \
  606. }
  607. test(desc->instantiate, "WARNING: Plugin has no instatiate function");
  608. test(desc->connect_port, "WARNING: Warning: Plugin has no connect_port funciton");
  609. test(desc->run, "WARNING: Plugin has no run function");
  610. test(!(desc->run_adding != 0 && desc->set_run_adding_gain == 0),
  611. "WARNING: Plugin has run_adding but no set_run_adding_gain");
  612. test(!(desc->run_adding == 0 && desc->set_run_adding_gain != 0),
  613. "WARNING: Plugin has set_run_adding_gain but no run_adding");
  614. test(desc->cleanup, "WARNING: Plugin has no cleanup function");
  615. test(!LADSPA_IS_INPLACE_BROKEN(desc->Properties),
  616. "WARNING: Plugin cannot use in place processing");
  617. test(desc->PortCount, "WARNING: Plugin has no ports");
  618. return true;
  619. }
  620. LADSPA_Descriptor_Function
  621. LADSPAInfo::GetDescriptorFunctionForLibrary(unsigned long library_index)
  622. {
  623. LibraryInfo *li = &(m_Libraries[library_index]);
  624. if (!(li->Handle)) {
  625. // Need full path
  626. string fullpath = m_Paths[li->PathIndex];
  627. fullpath.append(li->Basename);
  628. // Immediate symbol resolution, as plugin code is likely to be executed
  629. li->Handle = dlopen(fullpath.c_str(), RTLD_NOW);
  630. if (!(li->Handle)) {
  631. // Plugin library changed since last path scan
  632. cerr << "WARNING: Plugin library " << fullpath << " cannot be loaded" << endl;
  633. cerr << "Rescan of plugins recommended" << endl;
  634. cerr << "dlerror() output:" << endl;
  635. cerr << dlerror() << endl;
  636. return NULL;
  637. }
  638. }
  639. // Got handle so now verify that it's a LADSPA plugin library
  640. const LADSPA_Descriptor_Function desc_func = (LADSPA_Descriptor_Function)dlsym(li->Handle,
  641. "ladspa_descriptor");
  642. if (!desc_func) {
  643. // Is DLL, but not a LADSPA one (changed since last path scan?)
  644. cerr << "WARNING: DLL " << m_Paths[li->PathIndex] << li->Basename
  645. << " has no ladspa_descriptor function" << endl;
  646. cerr << "Rescan of plugins recommended" << endl;
  647. cerr << "dlerror() output:" << endl;
  648. cerr << dlerror() << endl;
  649. // Unload library
  650. dlclose(li->Handle);
  651. return NULL;
  652. }
  653. return desc_func;
  654. }