CLAM-Development  1.4.0
RunTimeFaustLibraryLoader.hxx
Go to the documentation of this file.
1 #ifndef RunTimeFaustLibraryLoader_hxx
2 #define RunTimeFaustLibraryLoader_hxx
3 
4 #include <dirent.h>
6 
8 #include <ladspa.h>
9 
10 
12 {
13 
14 public:
15  virtual void Load() const
16  {
17  std::string examplesDir = CompletePathFor("examples/ladspadir");
18  LoadLibrariesFromPath(examplesDir);
19  RunTimeLibraryLoader::Load(); // needed??
20  }
21  void LoadPlugin(const std::string & pluginFullPath) const
22  {
23  LoadLibrariesFromPath(pluginFullPath);
24  }
25 
26  // overload as workaround of Load() overload and path issues
27  virtual std::list<std::string> GetUsedLibraries()
28  {
29  std::list<std::string> loadedLibraries=LoadedLibraries();
30  LoadedLibraries().clear();
31  return loadedLibraries;
32  }
33 protected:
34 
35  virtual const bool needReleaseHandlerOnReload() const {return false; }
36  void SetupLibrary(void* handle, const std::string & pluginFullFilename) const
37  {
38  LADSPA_Descriptor_Function descriptorTable = 0;
39  descriptorTable = (LADSPA_Descriptor_Function)GetSymbol(handle, "ladspa_descriptor");
40  if (!descriptorTable)
41  {
42 // std::cout << "[FAUST-LADSPA Plugin] Warning: trying to open non ladspa plugin: " << pluginFullFilename << std::endl;
43  return;
44  }
45 
46  LoadedLibraries().push_back(pluginFullFilename);
48  for (unsigned long i=0; descriptorTable(i); i++)
49  {
50  LADSPA_Descriptor* descriptor = (LADSPA_Descriptor*)descriptorTable(i);
51  std::ostringstream oss;
52  oss << descriptor->Label << i;
53  factory.AddCreatorWarningRepetitions(oss.str(),
54  new CLAM::LadspaWrapperCreator(pluginFullFilename,
55  i,
56  oss.str()));
57  factory.AddAttribute(oss.str(), "category", "FAUST");
58  factory.AddAttribute(oss.str(), "description", descriptor->Name);
59  factory.AddAttribute(oss.str(), "library", pluginFullFilename);
60 
61  std::string pluginName=descriptor->Label;
62  const std::string diagramMainSufix=".dsp-svg/process.svg";
63  std::string svgFileDir = CompletePathFor( "examples/" + pluginName + diagramMainSufix);
64  if (svgFileDir != "")
65  {
66  factory.AddAttribute(oss.str(), "faust_diagram", svgFileDir);
67  }
68  if (!factory.AttributeExists(oss.str(), "embedded_svg"))
69  factory.AddAttribute(oss.str(), "embedded_svg", ":icons/images/faustlogo.svg");
70  if (!factory.AttributeExists(oss.str(), "icon"))
71  factory.AddAttribute(oss.str(), "icon", "faustlogo.svg");
72  std::string sourcePath=CompletePathFor( "examples/"+pluginName+".dsp");
73  if (sourcePath != "")
74  factory.AddAttribute(oss.str(), "faust_source_file", sourcePath);
75  }
76  if (ReleaseLibraryHandler(handle, pluginFullFilename))
77  {
78  std::cout<<"[FAUST-LADSPA] error unloading library handle of: " << pluginFullFilename<<std::endl;
79  std::cout<<LibraryLoadError()<<std::endl;
80  }
81  }
82 
83  const char ** standardPaths() const
84  {
85  static const char * result[] =
86  {
87 /* "/usr/share/doc/faust",
88  "/usr/local/share/doc/faust",*/
89  0
90  };
91  return result;
92  }
93 
94  const char * homePath() const { return "/.faust"; }
95  const char * pathEnvironmentVar() const { return "CLAM_FAUST_PATH"; }
96  const char * libraryType() const { return "LADSPA"; }
97 private:
98  static std::list<std::string> & LoadedLibraries()
99  {
100  static std::list<std::string> sLoadedLibraries;
101  return sLoadedLibraries;
102  }
103 };
104 
105 #endif // RunTimeFaustLibraryLoader_hxx
106 
107