CLAM-Development
1.1
|
00001 #ifndef RunTimeFaustLibraryLoader_hxx 00002 #define RunTimeFaustLibraryLoader_hxx 00003 00004 #ifdef WIN32 00005 #include <windows.h> 00006 #undef GetClassName 00007 #else 00008 #include <dlfcn.h> 00009 #endif 00010 #include <dirent.h> 00011 #include "RunTimeLibraryLoader.hxx" 00012 00013 #include "LadspaWrapperCreator.hxx" 00014 #include <ladspa.h> 00015 00016 00017 class RunTimeFaustLibraryLoader : public RunTimeLibraryLoader 00018 { 00019 00020 public: 00021 virtual void Load() const 00022 { 00023 std::string examplesDir = CompletePathFor("examples/ladspadir"); 00024 LoadLibrariesFromPath(examplesDir); 00025 //std::cout<<"[FAUST-LADSPA Plugin] \tload of RunTimeFaustLibraryLoader"<<std::endl; 00026 RunTimeLibraryLoader::Load(); // needed?? 00027 } 00028 void LoadPlugin(const std::string & pluginFullPath) const 00029 { 00030 LoadLibrariesFromPath(pluginFullPath); 00031 } 00032 00033 // overload as workaround of Load() overload and path issues 00034 virtual const std::list<std::string> GetUsedLibraries() 00035 { 00036 const std::list<std::string> loadedLibraries=LoadedLibraries(); 00037 LoadedLibraries().clear(); 00038 return loadedLibraries; 00039 } 00040 protected: 00041 00042 virtual const bool needReleaseHandlerOnReload() const {return false; } 00043 void SetupLibrary(void* handle, const std::string & pluginFullFilename) const 00044 { 00045 LADSPA_Descriptor_Function descriptorTable = 0; 00046 descriptorTable = (LADSPA_Descriptor_Function)dlsym(handle, "ladspa_descriptor"); 00047 if (!descriptorTable) 00048 { 00049 // std::cout << "[FAUST-LADSPA Plugin] Warning: trying to open non ladspa plugin: " << pluginFullFilename << std::endl; 00050 return; 00051 } 00052 00053 LoadedLibraries().push_back(pluginFullFilename); 00054 CLAM::ProcessingFactory& factory = CLAM::ProcessingFactory::GetInstance(); 00055 for (unsigned long i=0; descriptorTable(i); i++) 00056 { 00057 LADSPA_Descriptor* descriptor = (LADSPA_Descriptor*)descriptorTable(i); 00058 std::ostringstream oss; 00059 oss << descriptor->Label << i; 00060 factory.AddCreatorWarningRepetitions(oss.str(), 00061 new CLAM::LadspaWrapperCreator(pluginFullFilename, 00062 i, 00063 oss.str())); 00064 factory.AddAttribute(oss.str(), "category", "FAUST"); 00065 factory.AddAttribute(oss.str(), "description", descriptor->Name); 00066 factory.AddAttribute(oss.str(), "library", pluginFullFilename); 00067 00068 std::string pluginName=descriptor->Label; 00069 const std::string diagramMainSufix=".dsp-svg/process.svg"; 00070 std::string svgFileDir = CompletePathFor( "examples/" + pluginName + diagramMainSufix); 00071 if (svgFileDir != "") 00072 { 00073 factory.AddAttribute(oss.str(), "faust_diagram", svgFileDir); 00074 //std::cout << "[FAUST-LADSPA Plugin] Using diagram: " << svgFileDir << std::endl; 00075 } 00076 if (!factory.AttributeExists(oss.str(), "embedded_svg")) 00077 factory.AddAttribute(oss.str(), "embedded_svg", ":icons/images/faustlogo.svg"); 00078 if (!factory.AttributeExists(oss.str(), "icon")) 00079 factory.AddAttribute(oss.str(), "icon", "faustlogo.svg"); 00080 std::string sourcePath=CompletePathFor( "examples/"+pluginName+".dsp"); 00081 if (sourcePath != "") 00082 factory.AddAttribute(oss.str(), "faust_source_file", sourcePath); 00083 } 00084 if (ReleaseLibraryHandler(handle, pluginFullFilename)) 00085 { 00086 std::cout<<"[FAUST-LADSPA] error unloading library handle of: " << pluginFullFilename<<std::endl; 00087 std::cout<<LibraryLoadError()<<std::endl; 00088 } 00089 } 00090 00091 const char ** standardPaths() const 00092 { 00093 static const char * result[] = 00094 { 00095 /* "/usr/share/doc/faust", 00096 "/usr/local/share/doc/faust",*/ 00097 0 00098 }; 00099 return result; 00100 } 00101 00102 const char * homePath() const { return "/.faust"; } 00103 const char * pathEnvironmentVar() const { return "CLAM_FAUST_PATH"; } 00104 const char * libraryType() const { return "LADSPA"; } 00105 private: 00106 static std::list<std::string> & LoadedLibraries() 00107 { 00108 static std::list<std::string> sLoadedLibraries; 00109 return sLoadedLibraries; 00110 } 00111 }; 00112 00113 #endif // RunTimeFaustLibraryLoader_hxx 00114 00115