From e0c959ea40eb1e644b021117de7902b22948fca9 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 4 May 2011 17:36:46 +0000 Subject: Fix python bindings. git-svn-id: http://svn.drobilla.net/lad/trunk/lilv@3249 a436a847-0d15-0410-975c-d299462d15a1 --- lilv/lilvmm.hpp | 86 +++++++++++++++++++++++------------------------- swig/lilv.i | 20 +++-------- swig/python/lv2_apply.py | 2 +- 3 files changed, 48 insertions(+), 60 deletions(-) diff --git a/lilv/lilvmm.hpp b/lilv/lilvmm.hpp index e021a02..be6f000 100644 --- a/lilv/lilvmm.hpp +++ b/lilv/lilvmm.hpp @@ -107,12 +107,15 @@ struct PluginClass { const LilvPluginClass* me; }; -#define LILV_WRAP_COLL(CT, ET, prefix) \ +#define LILV_WRAP_COLL(CT, ET, prefix) \ struct CT { \ inline CT(const Lilv ## CT* c_obj) : me(c_obj) {} \ LILV_WRAP_CONVERSION(const Lilv ## CT); \ LILV_WRAP0(unsigned, prefix, size); \ LILV_WRAP1(const ET, prefix, get, LilvIter*, i); \ + LILV_WRAP0(LilvIter*, prefix, begin); \ + LILV_WRAP1(LilvIter*, prefix, next, LilvIter*, i); \ + LILV_WRAP1(bool, prefix, is_end, LilvIter*, i); \ const Lilv ## CT* me; \ }; \ @@ -120,49 +123,6 @@ LILV_WRAP_COLL(PluginClasses, PluginClass, plugin_classes); LILV_WRAP_COLL(ScalePoints, ScalePoint, scale_points); LILV_WRAP_COLL(Nodes, Node, nodes); -struct Plugins { - inline Plugins(const LilvPlugins* c_obj) : me(c_obj) {} - LILV_WRAP_CONVERSION(const LilvPlugins); - - const LilvPlugins* me; -}; - -struct World { - inline World() : me(lilv_world_new()) {} - inline ~World() { /*lilv_world_free(me);*/ } - - inline LilvNode* new_uri(const char* uri) { - return lilv_new_uri(me, uri); - } - inline LilvNode* new_string(const char* str) { - return lilv_new_string(me, str); - } - inline LilvNode* new_int(int val) { - return lilv_new_int(me, val); - } - inline LilvNode* new_float(float val) { - return lilv_new_float(me, val); - } - inline LilvNode* new_bool(bool val) { - return lilv_new_bool(me, val); - } - inline Nodes find_nodes(const LilvNode* subject, - const LilvNode* predicate, - const LilvNode* object) { - return lilv_world_find_nodes(me, subject, predicate, object); - } - - LILV_WRAP2_VOID(world, set_option, const char*, uri, LilvNode*, value); - LILV_WRAP0_VOID(world, free); - LILV_WRAP0_VOID(world, load_all); - LILV_WRAP1_VOID(world, load_bundle, LilvNode*, bundle_uri); - LILV_WRAP0(const LilvPluginClass*, world, get_plugin_class); - LILV_WRAP0(const LilvPluginClasses*, world, get_plugin_classes); - LILV_WRAP0(Plugins, world, get_all_plugins); - - LilvWorld* me; -}; - struct Port { inline Port(const LilvPlugin* p, const LilvPort* c_obj) : parent(p), me(c_obj) @@ -239,6 +199,8 @@ struct Plugin { const LilvPlugin* me; }; +LILV_WRAP_COLL(Plugins, Plugin, plugins); + struct Instance { inline Instance(Plugin plugin, double sample_rate) { // TODO: features @@ -264,6 +226,42 @@ struct Instance { LilvInstance* me; }; +struct World { + inline World() : me(lilv_world_new()) {} + inline ~World() { /*lilv_world_free(me);*/ } + + inline LilvNode* new_uri(const char* uri) { + return lilv_new_uri(me, uri); + } + inline LilvNode* new_string(const char* str) { + return lilv_new_string(me, str); + } + inline LilvNode* new_int(int val) { + return lilv_new_int(me, val); + } + inline LilvNode* new_float(float val) { + return lilv_new_float(me, val); + } + inline LilvNode* new_bool(bool val) { + return lilv_new_bool(me, val); + } + inline Nodes find_nodes(const LilvNode* subject, + const LilvNode* predicate, + const LilvNode* object) { + return lilv_world_find_nodes(me, subject, predicate, object); + } + + LILV_WRAP2_VOID(world, set_option, const char*, uri, LilvNode*, value); + LILV_WRAP0_VOID(world, free); + LILV_WRAP0_VOID(world, load_all); + LILV_WRAP1_VOID(world, load_bundle, LilvNode*, bundle_uri); + LILV_WRAP0(const LilvPluginClass*, world, get_plugin_class); + LILV_WRAP0(const LilvPluginClasses*, world, get_plugin_classes); + LILV_WRAP0(Plugins, world, get_all_plugins); + + LilvWorld* me; +}; + } /* namespace Lilv */ #endif /* LILV_LILVMM_HPP */ diff --git a/swig/lilv.i b/swig/lilv.i index 0d7c83c..958f9f0 100644 --- a/swig/lilv.i +++ b/swig/lilv.i @@ -15,15 +15,12 @@ namespace Lilv { class Iterator(object): def __init__(self, plugins): self.plugins = plugins - self.index = 0 + self.iter = plugins.begin() - def __iter__(self): - return self - def next(self): - self.index += 1 - if self.index < lilv_plugins_size(self.plugins.me): - return Plugin(lilv_plugins_get_at(self.plugins.me, self.index)) + self.iter = self.plugins.next(self.iter) + if not self.plugins.is_end(self.iter): + return self.plugins.get(self.iter) else: raise StopIteration @@ -34,14 +31,7 @@ namespace Lilv { %extend Node { %pythoncode %{ def __str__(self): - return lilv_value_get_turtle_token(self.me) -%} -}; - -%extend World { -%pythoncode %{ - def get_plugin(self, uri_str): - return Plugin(lilv_world_get_plugin_by_uri_string(self.me, uri_str)) + return self.get_turtle_token() %} }; diff --git a/swig/python/lv2_apply.py b/swig/python/lv2_apply.py index 736311f..98d6f75 100755 --- a/swig/python/lv2_apply.py +++ b/swig/python/lv2_apply.py @@ -21,7 +21,7 @@ world = lilv.World() world.load_all() # Find plugin -plugin = world.get_plugin(plugin_uri) +plugin = world.get_all_plugins.get_by_uri(plugin_uri) if not plugin: print "Unknown plugin `%s'\n" % plugin_uri sys.exit(1) -- cgit v1.2.1