changeset 32:13eae6cc6bac

* Add a function to look up the Vamp plugin path for the current platform. * Add make install stage and pkgconfig files. (This bit is rather Linux-specific.)
author cannam
date Mon, 31 Jul 2006 16:12:37 +0000
parents 0e7aa8fabd76
children 909fe32e2c3c
files Makefile README host/vamp-simple-host.cpp vamp-sdk/PluginBase.h vamp-sdk/PluginHostAdapter.cpp vamp-sdk/PluginHostAdapter.h vamp-sdk/vamp-sdk.pc.in vamp/vamp.pc.in
diffstat 8 files changed, 140 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Wed May 17 16:41:37 2006 +0000
+++ b/Makefile	Mon Jul 31 16:12:37 2006 +0000
@@ -11,20 +11,33 @@
 
 ### Start of user-serviceable parts
 
+# Locations for "make install".  This will need quite a bit of 
+# editing for non-Linux platforms.  Of course you don't necessarily
+# have to use "make install".
+#
+INSTALL_PREFIX		:= /usr/local
+INSTALL_API_HEADERS	:= $(INSTALL_PREFIX)/include/vamp/
+INSTALL_SDK_HEADERS	:= $(INSTALL_PREFIX)/include/vamp-sdk/
+INSTALL_SDK_LIBS	:= $(INSTALL_PREFIX)/lib/
+INSTALL_SDK_LIBNAME	:= libvamp-sdk.so.0.9.5
+INSTALL_SDK_LINK_ABI	:= libvamp-sdk.so.0
+INSTALL_SDK_LINK_DEV	:= libvamp-sdk.so
+INSTALL_PKGCONFIG	:= $(INSTALL_PREFIX)/lib/pkgconfig/
+
 # Compile flags
 #
 CXXFLAGS	:= $(CXXFLAGS) -g -Wall -I$(SDKDIR) -I$(APIDIR) -I.
 
 # Libraries required for the host at link time
 #
-HOST_LIBS	= -Lvamp-sdk -lvamp-sdk -lsndfile -ldl
+HOST_LIBS	= vamp-sdk/libvamp-sdk.a -lsndfile -ldl
 
 # Libraries required for the plugin.  Note that we can (and actively
 # want to) statically link libstdc++, because our plugin exposes only
 # a C API so there are no boundary compatibility problems.
 #
-PLUGIN_LIBS	= -Lvamp-sdk -lvamp-sdk
-#PLUGIN_LIBS	= -Lvamp-sdk -lvamp-sdk $(shell g++ -print-file-name=libstdc++.a)
+PLUGIN_LIBS	= vamp-sdk/libvamp-sdk.a
+#PLUGIN_LIBS	= vamp-sdk/libvamp-sdk.a $(shell g++ -print-file-name=libstdc++.a)
 
 # Flags required to tell the compiler to link to a dynamically loadable object
 #
@@ -40,6 +53,7 @@
 
 ### End of user-serviceable parts
 
+
 API_HEADERS	= \
 		$(APIDIR)/vamp.h
 
@@ -55,9 +69,12 @@
 		$(SDKDIR)/PluginHostAdapter.o \
 		$(SDKDIR)/RealTime.o
 
-SDK_TARGET	= \
+SDK_STATIC	= \
 		$(SDKDIR)/libvamp-sdk.a
 
+SDK_DYNAMIC	= \
+		$(SDKDIR)/libvamp-sdk.so
+
 PLUGIN_HEADERS	= \
 		$(EXAMPLEDIR)/SpectralCentroid.h \
 		$(EXAMPLEDIR)/ZeroCrossing.h
@@ -79,11 +96,14 @@
 HOST_TARGET	= \
 		$(HOSTDIR)/vamp-simple-host
 
-all:		$(SDK_TARGET) $(PLUGIN_TARGET) $(HOST_TARGET) test
+all:		$(SDK_STATIC) $(SDK_DYNAMIC) $(PLUGIN_TARGET) $(HOST_TARGET) test
 
-$(SDK_TARGET):	$(SDK_OBJECTS) $(API_HEADERS) $(SDK_HEADERS)
+$(SDK_STATIC):	$(SDK_OBJECTS) $(API_HEADERS) $(SDK_HEADERS)
 		$(AR) r $@ $(SDK_OBJECTS)
 
+$(SDK_DYNAMIC):	$(SDK_OBJECTS) $(API_HEADERS) $(SDK_HEADERS)
+		$(CXX) $(LDFLAGS) $(PLUGIN_LDFLAGS) -o $@ $(SDK_OBJECTS)
+
 $(PLUGIN_TARGET):	$(PLUGIN_OBJECTS) $(SDK_TARGET) $(PLUGIN_HEADERS)
 		$(CXX) $(LDFLAGS) $(PLUGIN_LDFLAGS) -o $@ $(PLUGIN_OBJECTS) $(PLUGIN_LIBS)
 
@@ -96,7 +116,23 @@
 clean:		
 		rm -f $(SDK_OBJECTS) $(PLUGIN_OBJECTS) $(HOST_OBJECTS)
 
+install:	$(SDK_STATIC) $(SDK_DYNAMIC) $(PLUGIN_TARGET) $(HOST_TARGET)
+		mkdir -p $(INSTALL_API_HEADERS)
+		mkdir -p $(INSTALL_SDK_HEADERS)
+		mkdir -p $(INSTALL_SDK_LIBS)
+		mkdir -p $(INSTALL_PKGCONFIG)
+		cp $(API_HEADERS) $(INSTALL_API_HEADERS)
+		cp $(SDK_HEADERS) $(INSTALL_SDK_HEADERS)
+		cp $(SDK_STATIC) $(INSTALL_SDK_LIBS)
+		cp $(SDK_DYNAMIC) $(INSTALL_SDK_LIBS)/$(INSTALL_SDK_LIBNAME)
+		rm -f $(INSTALL_SDK_LIBS)/$(INSTALL_SDK_LINK_ABI)
+		ln -s $(INSTALL_SDK_LIBNAME) $(INSTALL_SDK_LIBS)/$(INSTALL_SDK_LINK_ABI)
+		rm -f $(INSTALL_SDK_LIBS)/$(INSTALL_SDK_LINK_DEV)
+		ln -s $(INSTALL_SDK_LINK_ABI) $(INSTALL_SDK_LIBS)/$(INSTALL_SDK_LINK_DEV)
+		sed "s,%PREFIX%,$(INSTALL_PREFIX)," vamp/vamp.pc.in > $(INSTALL_PKGCONFIG)/vamp.pc
+		sed "s,%PREFIX%,$(INSTALL_PREFIX)," vamp-sdk/vamp-sdk.pc.in > $(INSTALL_PKGCONFIG)/vamp-sdk.pc
+
 distclean:	clean
-		rm -f $(SDK_TARGET) $(PLUGIN_TARGET) $(HOST_TARGET) *~ */*~
+		rm -f $(SDK_STATIC) $(SDK_DYNAMIC) $(PLUGIN_TARGET) $(HOST_TARGET) *~ */*~
 
 
--- a/README	Wed May 17 16:41:37 2006 +0000
+++ b/README	Mon Jul 31 16:12:37 2006 +0000
@@ -87,6 +87,14 @@
 it to process a complete audio file, with its default parameters.
 Requires libsndfile.
 
+The Vamp API doesn't officially specify how to load plugin libraries
+or where to find them.  However, good practice for a host is to use
+the Vamp path returned by Vamp::PluginHostAdapter::getPluginPath() and
+search each directory in this path for .so, .dll or .dylib files
+(depending on platform), loading each one and testing for the
+vampGetPluginDescriptor function to enumerate the plugins in this
+object.  The example host has some code that may help.
+
 
 Building the SDK
 ================
--- a/host/vamp-simple-host.cpp	Wed May 17 16:41:37 2006 +0000
+++ b/host/vamp-simple-host.cpp	Mon Jul 31 16:12:37 2006 +0000
@@ -49,6 +49,7 @@
 using std::cerr;
 using std::endl;
 using std::string;
+using std::vector;
 
 void printFeatures(int, int, int, Vamp::Plugin::FeatureSet);
 void transformInput(float *, size_t);
@@ -70,6 +71,13 @@
 
     cerr << endl << argv[0] << ": Running..." << endl;
 
+    cerr << endl << "Vamp path is set to:" << endl;
+    vector<string> path = Vamp::PluginHostAdapter::getPluginPath();
+    for (size_t i = 0; i < path.size(); ++i) {
+        cerr << "\t" << path[i] << endl;
+    }
+    cerr << "(This program doesn't use the path; just printing it for information)" << endl << endl;
+
     string soname = argv[1];
     string plugname = "";
     string wavname;
@@ -115,12 +123,6 @@
 
         if (plugin.getName() == plugname) plugnumber = index;
         
-        cerr << "(testing overlap...)" << endl;
-        {
-            Vamp::PluginHostAdapter otherPlugin(descriptor, 48000);
-            cerr << "(other plugin reports min " << otherPlugin.getMinChannelCount() << " channels)" << endl;
-        }
-
         ++index;
     }
 
--- a/vamp-sdk/PluginBase.h	Wed May 17 16:41:37 2006 +0000
+++ b/vamp-sdk/PluginBase.h	Mon Jul 31 16:12:37 2006 +0000
@@ -40,7 +40,7 @@
 #include <string>
 #include <vector>
 
-#define VAMP_SDK_VERSION "0.9"
+#define VAMP_SDK_VERSION "0.9.5"
 
 namespace Vamp {
 
--- a/vamp-sdk/PluginHostAdapter.cpp	Wed May 17 16:41:37 2006 +0000
+++ b/vamp-sdk/PluginHostAdapter.cpp	Mon Jul 31 16:12:37 2006 +0000
@@ -57,6 +57,62 @@
     if (m_handle) m_descriptor->cleanup(m_handle);
 }
 
+std::vector<std::string>
+PluginHostAdapter::getPluginPath()
+{
+    std::vector<std::string> path;
+    std::string envPath;
+
+    char *cpath = getenv("VAMP_PATH");
+    if (cpath) envPath = cpath;
+
+#ifdef _WIN32
+#define PATH_SEPARATOR ';'
+#define DEFAULT_VAMP_PATH "%ProgramFiles%\\Vamp Plugins"
+#else
+#define PATH_SEPARATOR ':'
+#ifdef __APPLE__
+#define DEFAULT_VAMP_PATH "/Library/Audio/Plug-Ins/Vamp/:$HOME/Library/Audio/Plug-Ins/Vamp"
+#else
+#define DEFAULT_VAMP_PATH "/usr/local/lib/vamp:/usr/lib/vamp:$HOME/vamp:$HOME/.vamp"
+#endif
+#endif
+
+    if (envPath == "") {
+        envPath = DEFAULT_VAMP_PATH;
+        char *chome = getenv("HOME");
+        if (chome) {
+            std::string home(chome);
+            std::string::size_type f;
+            while ((f = envPath.find("$HOME")) != std::string::npos &&
+                    f < envPath.length()) {
+                envPath.replace(f, 5, home);
+            }
+        }
+#ifdef _WIN32
+        char *cpfiles = getenv("ProgramFiles");
+        if (!cpfiles) cpfiles = "C:\\Program Files";
+        std::string pfiles(cpfiles);
+        std::string::size_type f;
+        while ((f = envPath.find("%ProgramFiles%")) != std::string::npos &&
+               f < envPath.length()) {
+            envPath.replace(f, 14, pfiles);
+        }
+#endif
+    }
+
+    std::string::size_type index = 0, newindex = 0;
+
+    while ((newindex = envPath.find(PATH_SEPARATOR, index)) < envPath.size()) {
+	path.push_back(envPath.substr(index, newindex - index));
+	index = newindex + 1;
+    }
+    
+    path.push_back(envPath.substr(index));
+
+    return path;
+}
+
 bool
 PluginHostAdapter::initialise(size_t channels,
                               size_t stepSize,
--- a/vamp-sdk/PluginHostAdapter.h	Wed May 17 16:41:37 2006 +0000
+++ b/vamp-sdk/PluginHostAdapter.h	Mon Jul 31 16:12:37 2006 +0000
@@ -41,6 +41,8 @@
 
 #include "Plugin.h"
 
+#include <vector>
+
 namespace Vamp {
 
 class PluginHostAdapter : public Plugin
@@ -49,6 +51,8 @@
     PluginHostAdapter(const VampPluginDescriptor *descriptor,
                       float inputSampleRate);
     virtual ~PluginHostAdapter();
+    
+    static std::vector<std::string> getPluginPath();
 
     bool initialise(size_t channels, size_t stepSize, size_t blockSize);
     void reset();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vamp-sdk/vamp-sdk.pc.in	Mon Jul 31 16:12:37 2006 +0000
@@ -0,0 +1,10 @@
+prefix=%PREFIX%
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include
+
+Name: vamp-sdk
+Version: 0.9.5
+Description: Development libraries for Vamp audio analysis plugin API
+Libs: -L${libdir} -lvamp-sdk
+Cflags: -I${includedir} 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vamp/vamp.pc.in	Mon Jul 31 16:12:37 2006 +0000
@@ -0,0 +1,10 @@
+prefix=%PREFIX%
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=${prefix}/include
+
+Name: vamp
+Version: 0.9
+Description: An API for audio analysis and feature extraction plugins
+Libs: 
+Cflags: -I${includedir}