summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-09-05 02:23:25 -0400
committerDavid Robillard <d@drobilla.net>2016-09-05 02:23:25 -0400
commitc9a93f83de23c657e40b5f689c9faaa3b3c8828d (patch)
treed82e18e54f04e94fc07f9bfdaf32b8fd71cd6c9d
parent5be277f5d9d2bbfa58028fb7522da4781450d6c4 (diff)
downloadlilv-c9a93f83de23c657e40b5f689c9faaa3b3c8828d.tar.gz
lilv-c9a93f83de23c657e40b5f689c9faaa3b3c8828d.tar.bz2
lilv-c9a93f83de23c657e40b5f689c9faaa3b3c8828d.zip
Add new hand-crafted Python bindings
New bindings are Pythonic, supporting iteration, DWIM type conversion, pretty printing, and so on, where possible. Updated test suite covers 100% of binding code. Which is to say: add real Python bindings. As far as the Lilv API itself is concerned, you can do everything via Python. However, more work is needed to make fancy wrappers for parts of LV2 itself (MIDI, URI map, etc) to be able to run advanced plugins.
-rw-r--r--NEWS4
-rwxr-xr-xbindings/python/lv2_apply.py39
-rw-r--r--bindings/test/bindings_test_plugin.ttl.in15
-rw-r--r--bindings/test/python/test_api.py310
-rw-r--r--wscript16
5 files changed, 294 insertions, 90 deletions
diff --git a/NEWS b/NEWS
index db82cb9..9fc97f9 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,6 @@
lilv (0.22.1) unstable;
+ * Add new hand-crafted Pythonic bindings with full test coverage
* Add lv2apply utility for applying plugins to audio files
* Add lilv_state_set_metadata() for adding state banks/comments/etc
(based on patch from Hanspeter Portner)
@@ -14,11 +15,10 @@ lilv (0.22.1) unstable;
* Fix loading dyn-manifest from bundles with spaces in their path
* Check lv2:binary predicate for UIs
* Add LILV_URI_ATOM_PORT and LILV_URI_CV_PORT defines
- * Fix Python bindings
* Fix documentation installation
* Fix outdated comment references to lilv_uri_to_path()
- -- David Robillard <d@drobilla.net> Sun, 04 Sep 2016 15:43:02 -0400
+ -- David Robillard <d@drobilla.net> Mon, 05 Sep 2016 02:22:39 -0400
lilv (0.22.0) stable;
diff --git a/bindings/python/lv2_apply.py b/bindings/python/lv2_apply.py
index 1cd906d..4c7d9b4 100755
--- a/bindings/python/lv2_apply.py
+++ b/bindings/python/lv2_apply.py
@@ -41,8 +41,8 @@ class WavFile(object):
data = [(i - float(range/2)) / float(range/2) for i in data]
channels = []
- for i in xrange(self.nchannels):
- channels.append([data[j] for j in xrange(0, len(data), self.nchannels) ])
+ for i in range(self.nchannels):
+ channels.append([data[j] for j in range(0, len(data), self.nchannels) ])
return channels
@@ -57,6 +57,7 @@ def main():
# Initialise Lilv
world = lilv.World()
+ ns = world.ns
world.load_all()
plugin_uri = sys.argv[1]
@@ -65,19 +66,14 @@ def main():
# Find plugin
plugin_uri_node = world.new_uri(plugin_uri)
- plugin = world.get_all_plugins().get_by_uri(plugin_uri_node)
- if not plugin:
- print("Unknown plugin `%s'\n" % plugin_uri)
+ plugins = world.get_all_plugins()
+ if plugin_uri_node not in plugins:
+ print("Unknown plugin `%s'" % plugin_uri)
sys.exit(1)
- lv2_InputPort = world.new_uri(lilv.LILV_URI_INPUT_PORT)
- lv2_OutputPort = world.new_uri(lilv.LILV_URI_OUTPUT_PORT)
- lv2_AudioPort = world.new_uri(lilv.LILV_URI_AUDIO_PORT)
- lv2_ControlPort = world.new_uri(lilv.LILV_URI_CONTROL_PORT)
- lv2_default = world.new_uri("http://lv2plug.in/ns/lv2core#default")
-
- n_audio_in = plugin.get_num_ports_of_class(lv2_InputPort, lv2_AudioPort)
- n_audio_out = plugin.get_num_ports_of_class(lv2_OutputPort, lv2_AudioPort)
+ plugin = plugins[plugin_uri_node]
+ n_audio_in = plugin.get_num_ports_of_class(ns.lv2.InputPort, ns.lv2.AudioPort)
+ n_audio_out = plugin.get_num_ports_of_class(ns.lv2.OutputPort, ns.lv2.AudioPort)
if n_audio_out == 0:
print("Plugin has no audio outputs\n")
sys.exit(1)
@@ -120,22 +116,21 @@ def main():
control_output_buffers = []
for index in range(plugin.get_num_ports()):
port = plugin.get_port_by_index(index)
- if port.is_a(lv2_InputPort):
- if port.is_a(lv2_AudioPort):
+ if port.is_a(ns.lv2.InputPort):
+ if port.is_a(ns.lv2.AudioPort):
audio_input_buffers.append(numpy.array(channels[len(audio_input_buffers)], numpy.float32))
instance.connect_port(index, audio_input_buffers[-1])
- elif port.is_a(lv2_ControlPort):
- #if port.has_property(lv2_default): # Doesn't seem to work
- default = lilv.lilv_node_as_float(lilv.lilv_nodes_get_first(port.get_value(lv2_default)))
+ elif port.is_a(ns.lv2.ControlPort):
+ default = float(port.get(ns.lv2.default))
control_input_buffers.append(numpy.array([default], numpy.float32))
instance.connect_port(index, control_input_buffers[-1])
else:
raise ValueError("Unhandled port type")
- elif port.is_a(lv2_OutputPort):
- if port.is_a(lv2_AudioPort):
+ elif port.is_a(ns.lv2.OutputPort):
+ if port.is_a(ns.lv2.AudioPort):
audio_output_buffers.append(numpy.array([0] * wav_in.nframes, numpy.float32))
instance.connect_port(index, audio_output_buffers[-1])
- elif port.is_a(lv2_ControlPort):
+ elif port.is_a(ns.lv2.ControlPort):
control_output_buffers.append(numpy.array([0], numpy.float32))
instance.connect_port(index, control_output_buffers[-1])
else:
@@ -156,7 +151,7 @@ def main():
# Write output file in chunks to stop memory usage getting out of hand:
CHUNK_SIZE = 8192
for chunk in numpy.array_split(data, CHUNK_SIZE):
- wav_out.writeframes(wave.struct.pack("%u%s" % (len(chunk), wav_in.struct_fmt_code), *chunk))
+ wav_out.writeframes(wave.struct.pack("%u%s" % (len(chunk), wav_in.struct_fmt_code), *chunk.astype(int)))
wav_out.close()
diff --git a/bindings/test/bindings_test_plugin.ttl.in b/bindings/test/bindings_test_plugin.ttl.in
index a703432..e8323d5 100644
--- a/bindings/test/bindings_test_plugin.ttl.in
+++ b/bindings/test/bindings_test_plugin.ttl.in
@@ -16,18 +16,27 @@
@prefix doap: <http://usefulinc.com/ns/doap#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix lv2: <http://lv2plug.in/ns/lv2core#> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ui: <http://lv2plug.in/ns/extensions/ui#> .
<http://example.org/lilv-bindings-test-plugin>
a lv2:Plugin ;
doap:name "Lilv Bindings Test" ;
doap:license <http://opensource.org/licenses/isc> ;
+ lv2:optionalFeature lv2:hardRTCapable ;
+ ui:ui <http://example.org/lilv-bindings-test-plugin-ui> ;
lv2:port [
a lv2:InputPort ,
lv2:ControlPort ;
lv2:index 0 ;
lv2:symbol "input" ;
- lv2:name "Input"
+ lv2:name "Input" ;
+ lv2:default 0.5 ;
+ lv2:minimum 0.0 ;
+ lv2:maximum 1.0 ;
+ lv2:scalePoint [ rdfs:label "off" ; rdf:value 0.0 ] ;
+ lv2:scalePoint [ rdfs:label "on" ; rdf:value 1.0 ] ;
] , [
a lv2:OutputPort ,
lv2:ControlPort ;
@@ -47,3 +56,7 @@
lv2:symbol "audio_output" ;
lv2:name "Audio Output" ;
] .
+
+<http://example.org/lilv-bindings-test-plugin-ui>
+ a ui:GtkUI ;
+ ui:binary <TODO> .
diff --git a/bindings/test/python/test_api.py b/bindings/test/python/test_api.py
index 655abba..f594013 100644
--- a/bindings/test/python/test_api.py
+++ b/bindings/test/python/test_api.py
@@ -1,3 +1,4 @@
+# Copyright 2016 David Robillard <d@drobilla.net>
# Copyright 2013 Kaspar Emanuel <kaspar.emanuel@gmail.com>
#
# Permission to use, copy, modify, and/or distribute this software for any
@@ -12,73 +13,278 @@
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
-from lilv import *
+import lilv
import unittest
import os
+location = "file://" + os.getcwd() + "/bindings/bindings_test_plugin.lv2/"
+
+class NodeTests(unittest.TestCase):
+ def setUp(self):
+ self.world = lilv.World()
+ def testNodes(self):
+ aint = self.world.new_int(1)
+ aint2 = self.world.new_int(1)
+ aint3 = self.world.new_int(3)
+ afloat = self.world.new_float(2.0)
+ atrue = self.world.new_bool(True)
+ afalse = self.world.new_bool(False)
+ auri = self.world.new_uri("http://example.org")
+ afile = self.world.new_file_uri(None, "/foo/bar")
+ astring = self.world.new_string("hello")
+ self.assertEqual(auri.get_turtle_token(), '<http://example.org>')
+ self.assertTrue(aint.is_int())
+ self.assertTrue(afloat.is_float())
+ self.assertTrue(auri.is_uri())
+ self.assertTrue(astring.is_string())
+ self.assertTrue(astring.is_literal())
+ self.assertFalse(auri.is_blank())
+ self.assertTrue(int(aint) == 1)
+ self.assertTrue(float(afloat) == 2.0)
+ self.assertTrue(bool(atrue))
+ self.assertFalse(bool(afalse))
+ self.assertEqual(afile.get_path(), "/foo/bar")
+ self.assertTrue(aint == aint2)
+ self.assertTrue(aint != aint3)
+ self.assertTrue(aint != afloat)
+ with self.assertRaises(ValueError):
+ int(atrue)
+ with self.assertRaises(ValueError):
+ float(aint)
+ with self.assertRaises(ValueError):
+ bool(astring)
+
class UriTests(unittest.TestCase):
def setUp(self):
- self.world = lilv_world_new()
- lilv_world_load_all(self.world)
+ self.world = lilv.World()
+ self.world.load_all();
def testInvalidURI(self):
- self.uri = lilv_new_uri(self.world, "invalid_uri")
- self.assertIsNone(self.uri)
- def testInvalidURI2(self):
- self.uri = lilv_new_uri(self.world, "invalid_uri")
- self.assertFalse( lilv_node_is_uri(self.uri) )
+ self.plugin_uri = self.world.new_uri("invalid_uri")
+ self.assertIsNone(self.plugin_uri)
def testNonExistentURI(self):
- self.uri = lilv_new_uri(self.world, "exist:does_not")
- plugins = lilv_world_get_all_plugins(self.world)
- self.plugin = lilv_plugins_get_by_uri(plugins, self.uri)
- self.assertIsNone(self.plugin)
+ self.plugin_uri = self.world.new_uri("exist:does_not")
+ self.plugin = self.world.get_all_plugins().get_by_uri(self.plugin_uri)
+ self.assertEqual(self.plugin, None)
def testPortTypes(self):
- self.uri = lilv_new_uri(self.world, LILV_URI_INPUT_PORT)
- self.assertIsNotNone(self.uri)
+ self.assertIsNotNone(self.world.new_uri(lilv.LILV_URI_INPUT_PORT))
def testPortTypes2(self):
- self.uri = lilv_new_uri(self.world, LILV_URI_OUTPUT_PORT)
- self.assertIsNotNone(self.uri)
+ self.assertIsNotNone(self.world.new_uri(lilv.LILV_URI_OUTPUT_PORT))
def testPortTypes3(self):
- self.uri = lilv_new_uri(self.world, LILV_URI_AUDIO_PORT)
- self.assertIsNotNone(self.uri)
+ self.assertIsNotNone(self.world.new_uri(lilv.LILV_URI_AUDIO_PORT))
def testPortTypes4(self):
- self.uri = lilv_new_uri(self.world, LILV_URI_CONTROL_PORT)
- self.assertIsNotNone(self.uri)
+ self.assertIsNotNone(self.world.new_uri(lilv.LILV_URI_CONTROL_PORT))
+
+class PluginClassTests(unittest.TestCase):
+ def setUp(self):
+ self.world = lilv.World()
+ def testPluginClasses(self):
+ pclass = self.world.get_plugin_class()
+ self.assertIsNotNone(pclass)
+ self.assertIsNone(pclass.get_parent_uri())
+ self.assertIsNotNone(pclass.get_uri())
+ self.assertIsNotNone(pclass.get_label())
+ self.assertEqual(str(pclass.get_uri()), str(pclass))
+ for i in pclass.get_children():
+ self.assertIsNotNone(i)
+ self.assertIsNotNone(i.get_uri())
+ self.assertIsNotNone(i.get_label())
+
+class PluginClassesTests(unittest.TestCase):
+ def setUp(self):
+ self.world = lilv.World()
+ self.world.load_all()
+ def testPluginClasses(self):
+ classes = self.world.get_plugin_classes()
+ pclass = self.world.get_plugin_class()
+ self.assertIsNotNone(classes)
+ self.assertIsNotNone(pclass)
+ self.assertTrue(pclass in classes)
+ self.assertTrue(pclass.get_uri() in classes)
+ self.assertGreater(len(classes), 1)
+ self.assertIsNotNone(classes[0])
+ self.assertIsNotNone(classes[pclass.get_uri()])
+
+class LoadTests(unittest.TestCase):
+ def setUp(self):
+ self.world = lilv.World()
+ self.bundle_uri = self.world.new_uri(location)
+ self.world.load_specifications()
+ self.world.load_plugin_classes()
def tearDown(self):
- lilv_node_free(self.uri)
- lilv_world_free(self.world)
+ del self.world
+ def testLoadUnload(self):
+ self.world.load_bundle(self.bundle_uri)
+ plugins = self.world.get_all_plugins()
+ plugin = plugins.get(plugins.begin())
+ self.world.load_resource(plugin)
+ self.world.unload_resource(plugin)
+ self.world.unload_bundle(self.bundle_uri)
class PluginTests(unittest.TestCase):
def setUp(self):
- self.world = lilv_world_new()
- location = "file://" + os.getcwd() + "/bindings/bindings_test_plugin.lv2/"
- self.plugin_uri = lilv_new_uri(self.world, location)
- self.assertIsNotNone(self.plugin_uri, "Invalid URI: '" + location + "'")
- lilv_world_load_bundle(self.world, self.plugin_uri)
- self.plugins = lilv_world_get_all_plugins(self.world)
- self.plugin = lilv_plugins_get(self.plugins, lilv_plugins_begin(self.plugins))
+ self.world = lilv.World()
+ self.world.set_option(lilv.OPTION_FILTER_LANG, self.world.new_bool(True))
+ self.bundle_uri = self.world.new_uri(location)
+ self.assertIsNotNone(self.bundle_uri, "Invalid URI: '" + location + "'")
+ self.world.load_bundle(self.bundle_uri)
+ self.plugins = self.world.get_all_plugins()
+ self.plugin = self.plugins.get(self.plugins.begin())
+ self.assertTrue(self.plugin.verify())
+ self.assertTrue(self.plugin in self.plugins)
+ self.assertTrue(self.plugin.get_uri() in self.plugins)
+ self.assertEqual(self.plugins[self.plugin.get_uri()], self.plugin)
self.assertIsNotNone(self.plugin, msg="Test plugin not found at location: '" + location + "'")
- self.assertEqual(location, lilv_node_as_string(lilv_plugin_get_bundle_uri(self.plugin)))
- self.instance = lilv_plugin_instantiate(self.plugin, 48000, None)
+ self.assertEqual(location, str(self.plugin.get_bundle_uri()))
+ self.plugin_uri = self.plugin.get_uri()
+ self.assertEqual(self.plugin.get_uri(), self.plugin_uri, "URI equality broken")
+ self.instance = lilv.Instance(self.plugin, 48000, None)
self.assertIsNotNone(self.instance)
- self.lv2_InputPort = lilv_new_uri(self.world, LILV_URI_INPUT_PORT)
- self.lv2_OutputPort = lilv_new_uri(self.world, LILV_URI_OUTPUT_PORT)
- self.lv2_AudioPort = lilv_new_uri(self.world, LILV_URI_AUDIO_PORT)
- self.lv2_ControlPort = lilv_new_uri(self.world, LILV_URI_CONTROL_PORT)
+ self.lv2_InputPort = self.world.new_uri(lilv.LILV_URI_INPUT_PORT)
+ self.lv2_OutputPort = self.world.new_uri(lilv.LILV_URI_OUTPUT_PORT)
+ self.lv2_AudioPort = self.world.new_uri(lilv.LILV_URI_AUDIO_PORT)
+ self.lv2_ControlPort = self.world.new_uri(lilv.LILV_URI_CONTROL_PORT)
+ def testGetters(self):
+ self.assertIsNotNone(self.plugin.get_bundle_uri())
+ self.assertGreater(len(self.plugin.get_data_uris()), 0)
+ self.assertIsNotNone(self.plugin.get_library_uri())
+ self.assertTrue(self.plugin.get_name().is_string())
+ self.assertTrue(self.plugin.get_class().get_uri().is_uri())
+ self.assertEqual(len(self.plugin.get_value(self.world.ns.doap.license)), 1)
+ licenses = self.plugin.get_value(self.world.ns.doap.license)
+ features = self.plugin.get_value(self.world.ns.lv2.optionalFeature)
+ self.assertEqual(len(licenses), 1)
+ self.assertTrue(licenses[0] in licenses)
+ with self.assertRaises(IndexError):
+ self.assertIsNone(licenses[len(licenses)])
+ self.assertEqual(len(licenses) + len(features),
+ len(licenses.merge(features)))
+ self.assertEqual(licenses.get(licenses.begin()), self.world.new_uri('http://opensource.org/licenses/isc'))
+ self.assertEqual(licenses[0], licenses.get(licenses.begin()))
+ self.assertTrue(self.plugin.has_feature(self.world.ns.lv2.hardRTCapable))
+ self.assertEqual(len(self.plugin.get_supported_features()), 1)
+ self.assertEqual(len(self.plugin.get_optional_features()), 1)
+ self.assertEqual(len(self.plugin.get_required_features()), 0)
+ self.assertFalse(self.plugin.has_extension_data(self.world.new_uri('http://example.org/nope')))
+ self.assertEqual(len(self.plugin.get_extension_data()), 0)
+ self.assertEqual(len(self.plugin.get_extension_data()), 0)
+ self.assertFalse(self.plugin.has_latency())
+ self.assertIsNone(self.plugin.get_latency_port_index())
def testPorts(self):
- n = lilv_plugin_get_num_ports_of_class(self.plugin, self.lv2_InputPort, self.lv2_AudioPort)
- self.assertEqual(n, 1)
- def testPorts2(self):
- n = lilv_plugin_get_num_ports_of_class(self.plugin, self.lv2_OutputPort, self.lv2_AudioPort)
- self.assertEqual(n, 1)
- def testPorts3(self):
- n = lilv_plugin_get_num_ports_of_class(self.plugin, self.lv2_OutputPort, self.lv2_ControlPort)
- self.assertEqual(n, 1)
- def testPorts4(self):
- n = lilv_plugin_get_num_ports_of_class(self.plugin, self.lv2_InputPort, self.lv2_ControlPort)
- self.assertEqual(n, 1)
- def tearDown(self):
- lilv_node_free(self.lv2_InputPort)
- lilv_node_free(self.lv2_OutputPort)
- lilv_node_free(self.lv2_AudioPort)
- lilv_node_free(self.plugin_uri)
- lilv_world_free(self.world)
+ self.assertEqual(self.plugin.get_num_ports(), 4)
+ self.assertIsNotNone(self.plugin.get_port(0))
+ self.assertIsNotNone(self.plugin.get_port(1))
+ self.assertIsNotNone(self.plugin.get_port(2))
+ self.assertIsNotNone(self.plugin.get_port(3))
+ self.assertIsNone(self.plugin.get_port_by_index(4))
+ self.assertIsNotNone(self.plugin.get_port("input"))
+ self.assertIsNotNone(self.plugin.get_port("output"))
+ self.assertIsNotNone(self.plugin.get_port("audio_input"))
+ self.assertIsNotNone(self.plugin.get_port("audio_output"))
+ self.assertIsNone(self.plugin.get_port_by_symbol("nonexistent"))
+ self.assertIsNone(self.plugin.get_port_by_designation(self.world.ns.lv2.InputPort, self.world.ns.lv2.control))
+ self.assertIsNone(self.plugin.get_project())
+ self.assertIsNone(self.plugin.get_author_name())
+ self.assertIsNone(self.plugin.get_author_email())
+ self.assertIsNone(self.plugin.get_author_homepage())
+ self.assertFalse(self.plugin.is_replaced())
+ self.assertEqual(0, len(self.plugin.get_related(self.world.new_uri("http://example.org/Type"))))
+ self.assertEqual(1, self.plugin.get_num_ports_of_class(self.lv2_InputPort, self.lv2_AudioPort))
+ port = self.plugin.get_port("input")
+ self.assertTrue(port.get_node().is_blank())
+ self.assertEqual(0, port.get(self.world.ns.lv2.index))
+ self.assertEqual(1, len(port.get_value(self.world.ns.lv2.symbol)))
+ self.assertEqual(port.get_value(self.world.ns.lv2.symbol)[0], "input")
+ self.assertFalse(port.has_property(self.world.ns.lv2.latency))
+ self.assertFalse(port.supports_event(self.world.ns.midi.MidiEvent))
+ self.assertEqual(0, port.get_index())
+ self.assertEqual("input", port.get_symbol())
+ self.assertEqual("Input", port.get_name())
+ self.assertEqual([self.world.ns.lv2.ControlPort, self.world.ns.lv2.InputPort],
+ list(port.get_classes()))
+ self.assertTrue(port.is_a(self.world.ns.lv2.ControlPort))
+ self.assertFalse(port.is_a(self.world.ns.lv2.AudioPort))
+ self.assertEquals((0.5, 0.0, 1.0), port.get_range())
+ self.assertEquals(0, len(port.get_properties()))
+ def testScalePoints(self):
+ port = self.plugin.get_port("input")
+ points = port.get_scale_points()
+ self.assertEqual(points[0].get_label(), "off")
+ self.assertEqual(points[0].get_value(), 0.0)
+ self.assertEqual(points[1].get_label(), "on")
+ self.assertEqual(points[1].get_value(), 1.0)
+ def testPortCount(self):
+ self.assertEqual(1, self.plugin.get_num_ports_of_class(self.lv2_OutputPort, self.lv2_AudioPort))
+ self.assertEqual(1, self.plugin.get_num_ports_of_class(self.lv2_OutputPort, self.lv2_ControlPort))
+ self.assertEqual(1, self.plugin.get_num_ports_of_class(self.lv2_InputPort, self.lv2_AudioPort))
+ self.assertEqual(1, self.plugin.get_num_ports_of_class(self.lv2_InputPort, self.lv2_ControlPort))
+
+class QueryTests(unittest.TestCase):
+ def setUp(self):
+ self.world = lilv.World()
+ self.world.load_all()
+ self.bundle_uri = self.world.new_uri(location)
+ self.world.load_bundle(self.bundle_uri)
+ self.plugins = self.world.get_all_plugins()
+ self.plugin = self.plugins.get(self.plugins.begin())
+ def testNamespaces(self):
+ self.assertEqual(self.world.ns.lv2, "http://lv2plug.in/ns/lv2core#")
+ self.assertEqual(self.world.ns.lv2.Plugin, "http://lv2plug.in/ns/lv2core#Plugin")
+ def testQuery(self):
+ self.assertTrue(self.world.ask(None,
+ self.world.ns.rdf.type,
+ self.world.ns.lv2.Plugin))
+ self.assertLess(0, len(self.world.find_nodes(None,
+ self.world.ns.rdf.type,
+ self.world.ns.lv2.Plugin)))
+ self.assertEqual(self.plugin.get_uri(), self.world.get(None,
+ self.world.ns.rdf.type,
+ self.world.ns.lv2.Plugin))
+
+class InstanceTests(unittest.TestCase):
+ def setUp(self):
+ self.world = lilv.World()
+ self.bundle_uri = self.world.new_uri(location)
+ self.world.load_bundle(self.bundle_uri)
+ self.plugins = self.world.get_all_plugins()
+ self.plugin = self.plugins[0]
+ self.instance = lilv.Instance(self.plugin, 48000)
+ self.assertEqual(self.plugin.get_uri(), self.instance.get_uri())
+ self.assertIsNone(self.instance.get_extension_data(self.world.new_uri("http://example.org/ext")))
+ self.assertIsNone(self.instance.get_extension_data("http://example.org/ext"))
+ def testRun(self):
+ import numpy
+ n_samples = 100
+ buf = numpy.zeros(n_samples)
+ with self.assertRaises(Exception):
+ self.instance.connect_port(0, "hello")
+ self.instance.connect_port(0, None)
+ self.instance.connect_port(0, None)
+ self.instance.connect_port(2, buf)
+ self.instance.connect_port(3, buf)
+ self.instance.activate()
+ self.instance.run(n_samples)
+ self.instance.deactivate()
+
+class UITests(unittest.TestCase):
+ def setUp(self):
+ self.world = lilv.World()
+ self.bundle_uri = self.world.new_uri(location)
+ self.world.load_bundle(self.bundle_uri)
+ self.plugins = self.world.get_all_plugins()
+ self.plugin = self.plugins[0]
+ def testUI(self):
+ uis = self.plugin.get_uis()
+ ui_uri = self.world.new_uri('http://example.org/lilv-bindings-test-plugin-ui')
+ self.assertEqual(1, len(uis))
+ self.assertEqual(str(uis[0]), str(ui_uri))
+ self.assertEqual(uis[0], str(ui_uri))
+ self.assertEqual(uis[0].get_uri(), ui_uri)
+ self.assertEqual(uis[0].get_bundle_uri(), self.bundle_uri)
+ self.assertEqual(uis[0].get_binary_uri(), str(self.bundle_uri) + "TODO")
+ self.assertEqual(uis[uis[0].get_uri()], uis[0])
+ self.assertTrue(uis[0].is_a(self.world.ns.ui.GtkUI))
+ self.assertTrue(uis[0] in uis)
+ self.assertTrue(uis[0].get_uri() in uis)
+ self.assertEqual([self.world.ns.ui.GtkUI], list(uis[0].get_classes()))
+ for ui in uis:
+ print(ui)
diff --git a/wscript b/wscript
index 6f2aac1..a2eb45b 100644
--- a/wscript
+++ b/wscript
@@ -64,7 +64,6 @@ def configure(conf):
if Options.options.bindings:
try:
- conf.load('swig')
conf.load('python')
conf.load('compiler_cxx')
conf.check_python_headers()
@@ -352,7 +351,7 @@ def build(bld):
if bld.is_defined('LILV_PYTHON'):
# Copy Python unittest files
- for i in [ 'test_api.py', 'test_api_mm.py' ]:
+ for i in [ 'test_api.py' ]:
bld(features = 'subst',
is_copy = True,
source = 'bindings/test/python/' + i,
@@ -413,16 +412,7 @@ def build(bld):
if bld.is_defined('LILV_PYTHON'):
# Python Wrapper
- obj = bld(features = 'cxx cxxshlib pyext',
- source = 'bindings/lilv.i',
- target = 'bindings/_lilv',
- includes = ['..'],
- swig_flags = '-c++ -python %s -Wall -I.. -llilv -features autodoc=1' %
- ("-py3" if sys.version_info >= (3,0,0) else ""),
- use = 'liblilv')
- autowaf.use_lib(bld, obj, 'LILV')
-
- bld.install_files('${PYTHONDIR}', bld.path.ant_glob('bindings/lilv.py'))
+ bld.install_files('${PYTHONDIR}', 'bindings/python/lilv.py')
bld.add_post_fun(autowaf.run_ldconfig)
if bld.env.DOCS:
@@ -444,7 +434,7 @@ def test(ctx):
autowaf.pre_test(ctx, APPNAME)
if ctx.is_defined('LILV_PYTHON'):
os.environ['LD_LIBRARY_PATH'] = os.getcwd()
- autowaf.run_tests(ctx, 'Python ' + APPNAME, ['python -m unittest discover bindings/'])
+ autowaf.run_tests(ctx, APPNAME, ['python -m unittest discover bindings/'])
os.environ['PATH'] = 'test' + os.pathsep + os.getenv('PATH')
Logs.pprint('GREEN', '')