With this patch the functionality of the LadspaPluginExplorer has been moved
to the RunTimeProcessingLibraryLoader, and any instance of
LadspaPluginExplorer has been removed from the NetworkEditor.
So now the loading of ladspa plugins it's done in RT as CLAM plugins do.


TODO:
- remove commented code lines from NE
- remove LadspaPluginExplorer files
Index: NetworkEditor/src/ProcessingTree.cxx
===================================================================
--- NetworkEditor/src/ProcessingTree.cxx	(revision 10585)
+++ NetworkEditor/src/ProcessingTree.cxx	(working copy)
@@ -24,10 +24,12 @@
 #include <QtGui/QHeaderView>
 #include <iostream> 
 
+/*
 #ifdef USE_LADSPA
 #	include <CLAM/LadspaPluginsExplorer.hxx> 
 //#	include <CLAM/LadspaWrapperCreator.hxx>
 #endif
+*/
 #include <CLAM/ProcessingFactory.hxx> 
 
 namespace NetworkGUI
@@ -196,10 +198,11 @@
 			item->setIcon(0, QIcon(":/icons/images/processing.png"));
 		}
 	}
-	
+/*	
 #ifdef USE_LADSPA
 	CLAM::LadspaPluginsExplorer::ExploreStandardPaths();
 #endif //USE_LADSPA
+*/
 
 // TODO: Ladspa is still work in progress 
 
Index: CLAM/src/Processing/Plugins/RunTimeProcessingLibraryLoader.cxx
===================================================================
--- CLAM/src/Processing/Plugins/RunTimeProcessingLibraryLoader.cxx	(revision 10585)
+++ CLAM/src/Processing/Plugins/RunTimeProcessingLibraryLoader.cxx	(working copy)
@@ -8,6 +8,11 @@
 #include <iostream>
 #include <string>
 #include <vector>
+#ifdef USE_LADSPA
+	#include <CLAM/ProcessingFactory.hxx>
+	#include <CLAM/LadspaWrapperCreator.hxx>
+	#include <ladspa.h>
+#endif
 
 class RunTimeProcessingLibraryLoader
 {
@@ -64,6 +69,48 @@
 		}
 		closedir(dir);
 	}
+	
+	void loadLibrariesFromPathLADSPA(const std::string & path)
+	{
+		std::cerr << "[LADSPA] Looking at path '" << path << "'" << std::endl;
+		DIR* dir = opendir(path.c_str());
+		if (!dir)
+		{
+			std::cerr << "[LADSPA] warning: could not open CLAM plugins dir: " << path << std::endl;
+			return;
+		}
+		while ( struct dirent * dirEntry = readdir(dir) )
+		{
+			std::string pluginFilename(dirEntry->d_name);
+			if(pluginFilename == "." || pluginFilename == "..")
+				continue;
+			LADSPA_Descriptor_Function descriptorTable = 0;
+			std::string pluginFullFilename(path + std::string("/") + pluginFilename);
+			void* handle = FullyLoadLibrary(pluginFullFilename);
+			descriptorTable = (LADSPA_Descriptor_Function)dlsym(handle, "ladspa_descriptor");
+			if (!descriptorTable)
+			{
+				std::cout << "[LADSPA] warning: trying to open non ladspa plugin: " << pluginFullFilename << std::endl;
+				continue;
+			}
+			//std::cout << "[LADSPA] \topened plugin: " << pluginFullFilename << std::endl;
+			CLAM::ProcessingFactory& factory = CLAM::ProcessingFactory::GetInstance();
+			for (unsigned long i=0; descriptorTable(i); i++)
+			{
+				LADSPA_Descriptor* descriptor = (LADSPA_Descriptor*)descriptorTable(i);
+				std::ostringstream oss;
+				oss << descriptor->Label << i;
+				factory.AddCreatorWarningRepetitions(oss.str(), 
+						new CLAM::LadspaWrapperCreator(pluginFullFilename, 
+							i, 
+							oss.str()));
+				factory.AddAttribute(oss.str(), "category", "LADSPA");
+				factory.AddAttribute(oss.str(), "description", descriptor->Name);
+				//std::cout << "[LADSPA] added \"" << plugin.factoryID << "\" to the Factory" << std::endl;
+			}
+		}
+		closedir(dir);	
+	}
 public:
 	std::vector<std::string> splitPathVariable(const std::string & pathVariable)
 	{
@@ -91,20 +138,37 @@
 			"/opt/lib/clam",
 			0
 		};
+		const char * standardPathsLADSPA[] = 
+		{
+			"/usr/local/lib/ladspa",
+			"/usr/lib/ladspa",
+			0
+		};
 		const char * envPath = getenv("CLAM_PLUGIN_PATH");
+		const char * envPathLADSPA = getenv("LADSPA_PATH");
 		const char * envHome = getenv("HOME");
 		std::string path = envPath ? envPath : "";
-		if (envHome) 
+		std::string pathLADSPA = envPathLADSPA ? envPathLADSPA : "";
+		if (envHome)
+		{	
 			path += std::string(path.empty()? "":pathSeparator) + envHome + "/.clam/plugins";
+			pathLADSPA += std::string(pathLADSPA.empty()? "":pathSeparator) + envHome + "/.ladspa";
+		}
 		for (const char ** standardPath=standardPaths; *standardPath; standardPath++)
 			path += std::string(path.empty()? "":pathSeparator) + *standardPath;
-
 		std::vector <std::string> environmentPaths = splitPathVariable(path);
 		for (unsigned i=0; i<environmentPaths.size(); i++)
 			loadLibrariesFromPath(environmentPaths[i]);
+
+		for (const char ** standardPathLADSPA=standardPathsLADSPA; *standardPathLADSPA; standardPathLADSPA++)
+			pathLADSPA += std::string(pathLADSPA.empty()? "":pathSeparator) + *standardPathLADSPA;
+		std::vector <std::string> environmentPathsLADSPA = splitPathVariable(pathLADSPA);
+		for (unsigned i=0; i<environmentPathsLADSPA.size(); i++)
+			loadLibrariesFromPathLADSPA(environmentPathsLADSPA[i]);
 	}
 };
 
+
 const char * RunTimeProcessingLibraryLoader::pathSeparator = 
 	#ifdef WIN32
 		";";
_______________________________________________
Clam-devel mailing list
Clam-devel@llistes.projectes.lafarga.org
https://llistes.projectes.lafarga.org/cgi-bin/mailman/listinfo/clam-devel

Reply via email to