Skip to content

Instantly share code, notes, and snippets.

@SpotlightKid
Last active November 8, 2019 01:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SpotlightKid/cb5ad53666f820bf101178c81efbe0a0 to your computer and use it in GitHub Desktop.
Save SpotlightKid/cb5ad53666f820bf101178c81efbe0a0 to your computer and use it in GitHub Desktop.
List all preset URIs of an LV2 plugin with the given URI
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""List all preset URIs of an LV2 plugin with the given URI."""
import sys
import lilv
PRESET_NS = 'http://lv2plug.in/ns/ext/presets'
RDFS_NS = 'http://www.w3.org/2000/01/rdf-schema'
def main(args=None):
args = sys.argv[1:] if args is None else args
if args:
plugin_uri = args[0]
else:
return "Usage: lv2-list-plugin-presets <plugin URI>"
world = lilv.World()
world.load_all()
preset_ns = lilv.Namespace(world, PRESET_NS)
rdfs_ns = lilv.Namespace(world, RDFS_NS)
plugins = world.get_all_plugins()
plugin_uri = world.new_uri(plugin_uri)
if plugin_uri is None or plugin_uri not in plugins:
return "Plugin with URI '%s' not found" % plugin_uri
plugin = plugins[plugin_uri]
presets = plugin.get_related(getattr(preset_ns, '#Preset'))
preset_list = []
for preset in presets:
res = world.load_resource(preset)
labels = world.find_nodes(preset, getattr(rdfs_ns, '#label'), None)
if labels:
label = str(labels[0])
else:
label = str(preset)
print("Preset '&s' has no rdfs:label" % preset, file=sys.stderr)
preset_list.append((label, str(preset)))
for preset in sorted(preset_list):
print("%s: %s" % preset)
if __name__ == '__main__':
sys.exit(main() or 0)
@SpotlightKid
Copy link
Author

Further updates to the script will happen here: https://github.com/SpotlightKid/jack-audio-tools/tree/master/lv2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment