From 985fa3a938241a763794c2d445fc5ab26efd6686 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 31 Jul 2007 05:43:43 +0000 Subject: Added experimental Python bindings via swig. Fixed building from slv2 directory. git-svn-id: http://svn.drobilla.net/lad/slv2@660 a436a847-0d15-0410-975c-d299462d15a1 --- Makefile.am | 4 +-- configure.ac | 20 ++++++++++-- src/slv2_internal.h | 2 +- swig/Makefile.am | 12 +++++++ swig/lv2_list.py | 10 ++++++ swig/slv2.i | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 135 insertions(+), 6 deletions(-) create mode 100644 swig/Makefile.am create mode 100755 swig/lv2_list.py create mode 100644 swig/slv2.i diff --git a/Makefile.am b/Makefile.am index c06c8a3..5ac646b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -12,8 +12,8 @@ dist-check-doxygen: @false endif -SUBDIRS = src slv2 utils hosts data $(DOC_DIR) -DIST_SUBDIRS = src slv2 utils hosts data doc +SUBDIRS = src slv2 utils hosts data $(DOC_DIR) swig +DIST_SUBDIRS = src slv2 utils hosts data doc swig pkgconfigdir = $(libdir)/pkgconfig pkgconfig_DATA = libslv2.pc diff --git a/configure.ac b/configure.ac index c5c9319..c5c7282 100644 --- a/configure.ac +++ b/configure.ac @@ -23,6 +23,7 @@ AC_CONFIG_AUX_DIR([config]) AC_CONFIG_SRCDIR([src/plugin.c]) AC_CONFIG_SRCDIR([slv2/plugin.h]) AC_CONFIG_SRCDIR([utils/lv2_list.c]) +AC_CONFIG_SRCDIR([swig/slv2.i]) AC_CONFIG_HEADER([config/config.h]) AM_INIT_AUTOMAKE @@ -41,11 +42,9 @@ AC_SUBST(SLV2_CFLAGS) AC_SUBST(SLV2_LIBS) CONFIG_H_PATH="$builddir/config/config.h" -AC_SUBST(CONFIG_H_PATH) -AC_DEFINE(CONFIG_H_PATH, ["$CONFIG_H_PATH"], [Absolute location of config.h for this build]) # Checks for compiler -AC_PROG_CC_C_0 +AC_PROG_CC # Library building stuff AC_PROG_LIBTOOL @@ -73,6 +72,16 @@ if test "$strict" = "yes"; then CXXFLAGS="$CFLAGS -ansi -pedantic -Wall -Wextra -Wconversion -Winit-self" fi +# SWiG bindings +bindings="no" +AC_ARG_ENABLE(bindings, + [AS_HELP_STRING(--enable-bindings, [Build language bindings via SWIG (false)])], + [bindings="$enableval"]) +if test "$bindings" = "yes"; then + AC_CHECK_PROGS(SWIG, swig) +fi +AM_CONDITIONAL(WITH_SWIG, [test "$bindings" = "yes"]) + # Check for RAPTOR #PKG_CHECK_MODULES(RAPTOR, raptor >= 0.21) @@ -117,12 +126,17 @@ if test $HAVE_DOXYGEN = "false"; then fi AM_CONDITIONAL(HAVE_DOXYGEN, $HAVE_DOXYGEN) +# Bolt on a few specific flags to CFLAGS that should always be used +CXXFLAGS="$CXXFLAGS -ansi -pipe -fmessage-length=999 -DCONFIG_H_PATH=\\\"$CONFIG_H_PATH\\\"" +CFLAGS="$CFLAGS -std=c99 -pipe -fmessage-length=999 -DCONFIG_H_PATH=\\\"$CONFIG_H_PATH\\\"" + # Write output files AC_CONFIG_FILES([Makefile]) AC_CONFIG_FILES([src/Makefile]) AC_CONFIG_FILES([slv2/Makefile]) AC_CONFIG_FILES([utils/Makefile]) AC_CONFIG_FILES([hosts/Makefile]) +AC_CONFIG_FILES([swig/Makefile]) AC_CONFIG_FILES([data/Makefile]) AC_CONFIG_FILES([libslv2.pc]) AC_CONFIG_FILES([doc/Makefile]) diff --git a/src/slv2_internal.h b/src/slv2_internal.h index e2a6ee1..f7999e9 100644 --- a/src/slv2_internal.h +++ b/src/slv2_internal.h @@ -119,7 +119,7 @@ struct _SLV2PluginClass { SLV2PluginClass slv2_plugin_class_new(SLV2World world, const char* parent_uri, const char* uri, const char* label); -void slv2_plugin_class_free(SLV2PluginClass class); +void slv2_plugin_class_free(SLV2PluginClass plugin_class); diff --git a/swig/Makefile.am b/swig/Makefile.am new file mode 100644 index 0000000..6c12b26 --- /dev/null +++ b/swig/Makefile.am @@ -0,0 +1,12 @@ +EXTRA_DIST = slv2.i lv2_list.py + +if WITH_SWIG +all: + swig -Wall -python slv2.i + gcc -fPIC -shared -I/usr/include/python2.4 slv2_wrap.c ../src/.libs/libslv2.so -o _slv2.so +endif + +clean: + rm *.c + rm *.so + rm *.o diff --git a/swig/lv2_list.py b/swig/lv2_list.py new file mode 100755 index 0000000..0f6e248 --- /dev/null +++ b/swig/lv2_list.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import slv2; + +w = slv2.World() +w.load_all() + +plugins = w.get_all_plugins() + +for i in range(0, plugins.size()): + print plugins[i].uri() diff --git a/swig/slv2.i b/swig/slv2.i new file mode 100644 index 0000000..b044310 --- /dev/null +++ b/swig/slv2.i @@ -0,0 +1,93 @@ +%module slv2 +%{ +#include "../slv2/plugin.h" +#include "../slv2/pluginclass.h" +#include "../slv2/pluginclasses.h" +#include "../slv2/plugininstance.h" +#include "../slv2/plugins.h" +#include "../slv2/port.h" +#include "../slv2/slv2.h" +#include "../slv2/types.h" +#include "../slv2/value.h" +#include "../slv2/values.h" +#include "../slv2/world.h" +typedef struct { SLV2World me; } World; +typedef struct { SLV2World world; SLV2Plugins me; } Plugins; +typedef struct { SLV2World world; SLV2Plugin me; } Plugin; +%} + +%include "../slv2/plugin.h" +%include "../slv2/pluginclass.h" +%include "../slv2/pluginclasses.h" +%include "../slv2/plugininstance.h" +%include "../slv2/plugins.h" +%include "../slv2/port.h" +%include "../slv2/slv2.h" +%include "../slv2/types.h" +%include "../slv2/value.h" +%include "../slv2/values.h" +%include "../slv2/world.h" + +typedef struct { SLV2Plugin me; } Plugin; +%extend Plugin { + Plugin(SLV2Plugin p) { + Plugin* ret = malloc(sizeof(Plugin)); + ret->me = p; + return ret; + } + + ~Plugin() { + /* FIXME: free SLV2Plugin? */ + free($self); + } + + char* name() { return slv2_plugin_get_name($self->me); } + const char* uri() { return slv2_plugin_get_uri($self->me); } +}; + +typedef struct { SLV2Plugins me; } Plugins; +%extend Plugins { + Plugins(SLV2World w, SLV2Plugins p) { + Plugins* ret = malloc(sizeof(Plugins)); + ret->world = w; + ret->me = p; + return ret; + } + + ~Plugins() { + slv2_plugins_free($self->world, $self->me); + free($self); + } + + inline unsigned size() const { return slv2_plugins_size($self->me); } + inline unsigned __len__() const { return slv2_plugins_size($self->me); } + + Plugin* __getitem__(unsigned i) { + if (i < slv2_plugins_size($self->me)) + return new_Plugin(slv2_plugins_get_at($self->me, i)); + else + return NULL; + } +}; + +typedef struct { SLV2World me; } World; +%extend World { + World() { + World* ret = malloc(sizeof(World)); + ret->me = slv2_world_new(); + return ret; + } + + ~World() { + slv2_world_free($self->me); + free($self); + } + /*World() { $self->me = slv2_world_new(); } + ~World() { slv2_world_free($self->me); }*/ + + void load_all() { slv2_world_load_all($self->me); } + void load_bundle(const char* path) { slv2_world_load_bundle($self->me, path); } + Plugins* get_all_plugins() { return new_Plugins($self->me, slv2_world_get_all_plugins($self->me)); } +}; + + -- cgit v1.2.1