summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Arndt <chris@chrisarndt.de>2019-10-15 15:13:54 +0200
committerDavid Robillard <d@drobilla.net>2019-11-09 20:17:10 +0100
commita4b3ca86ea28835a038d8458f06fa10af324952c (patch)
treeb109699c458f07f382d8bc792e8caa438974db50
parent8db73b7d0ff6fb1d14794da26e8ea656aab78d4a (diff)
downloadlilv-a4b3ca86ea28835a038d8458f06fa10af324952c.tar.gz
lilv-a4b3ca86ea28835a038d8458f06fa10af324952c.tar.bz2
lilv-a4b3ca86ea28835a038d8458f06fa10af324952c.zip
Add example Python script to list plugin presets
-rw-r--r--AUTHORS5
-rwxr-xr-xbindings/python/lv2_list_presets.py46
2 files changed, 50 insertions, 1 deletions
diff --git a/AUTHORS b/AUTHORS
index 3cea4ab..94baa22 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -8,4 +8,7 @@ Dynamic manifest support:
Stefano D'Angelo
Plugin execution via Python bindings:
- Kaspar Emanuel <kaspar.emanuel@gmail.com> \ No newline at end of file
+ Kaspar Emanuel <kaspar.emanuel@gmail.com>
+
+Python preset script:
+ Christopher Arndt <chris@chrisarndt.de>
diff --git a/bindings/python/lv2_list_presets.py b/bindings/python/lv2_list_presets.py
new file mode 100755
index 0000000..561e3f8
--- /dev/null
+++ b/bindings/python/lv2_list_presets.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import sys
+import lilv
+
+
+NS_PRESETS = "http://lv2plug.in/ns/ext/presets#"
+
+
+def print_presets(uri):
+ """Print all presets of an LV2 plugin to stdout."""
+
+ world = lilv.World()
+ world.load_all()
+ world.ns.presets = lilv.Namespace(world, NS_PRESETS)
+ plugins = world.get_all_plugins()
+ plugin = plugins[uri]
+ presets = plugin.get_related(world.ns.presets.Preset)
+
+ preset_list = []
+ for preset in presets:
+ world.load_resource(preset)
+ labels = world.find_nodes(preset, world.ns.rdfs.label, None)
+ label = str(labels[0]) if len(labels) > 0 else ""
+
+ if not label:
+ sys.stderr.write("warning: Preset <%s> has no label\n" % preset)
+
+ preset_list.append((str(preset), str(label)))
+
+ for preset in sorted(preset_list):
+ print('<%s> "%s"' % preset)
+
+
+if __name__ == "__main__":
+ if len(sys.argv) != 2:
+ sys.stderr.write("Usage: %s PLUGIN_URI\n" % (sys.argv[0]))
+ sys.exit(1)
+
+ try:
+ print_presets(sys.argv[1])
+ except ValueError as e:
+ sys.stderr.write("error: %s\n" % e)
+ except KeyError as e:
+ sys.stderr.write("error: %s\n" % str(e).strip("'"))