Hiya,

I'm having a hard time finding the plugins I want when using Ardour,
particularly since the majority of plugins I have installed don't
provide categories via RDF.

So, hoping this is useful to others, attached is a minimal RDF for the
CAPS suite, which I use a lot.

This was generated by a quick python script, also attached; I just
hand-edited the output to change the plugin types from UnknownPlugin.
Wasn't sure what to do with the pan plugin.

I also haven't bothered to figure out what to do with all the stuff 
about ports, and ardour doesn't seem to need it anyway, so this version
of the script doesn't handle that.   (Hey Steve, what's all that port
info in your rdfs used for?)

-- 

Paul Winkler
http://www.slinkp.com

Attachment: caps.rdf
Description: application/rdf

from cgi import escape
import os

HEADER = """<?xml version='1.0' encoding='ISO-8859-1'?>
<!DOCTYPE rdf:RDF [
        <!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
        <!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#'>
        <!ENTITY dc 'http://purl.org/dc/elements/1.1/'>
        <!ENTITY ladspa 'http://ladspa.org/ontology#'>
]>
<rdf:RDF xmlns:rdf='&rdf;'
         xmlns:rdfs='&rdfs;'
         xmlns:dc='&dc;'
         xmlns:ladspa='&ladspa;'>
"""

FOOTER = """
</rdf:RDF>
"""

plugin_template='''
  <ladspa:UnknownPlugin rdf:about="&ladspa;%(Plugin Unique ID)s">
    <dc:creator>%(Maker)s</dc:creator>
    <dc:rights>%(Copyright)s</dc:rights>
    <dc:title>%(Plugin Name)s</dc:title>
  </ladspa:UnknownPlugin>
'''

def find_plugin(filename):
    path = os.environ.get('LADSPA_PATH', '/usr/lib/ladspa').split(':')
    for p in path:
        maybe_file = os.path.join(p, filename)
        if os.path.exists(maybe_file):
            return maybe_file
    raise IOError, "Didn't find %s on path %s" % (filename, path)

def split_vals(line):
    try:
        label, val = line.split(':', 1)
    except ValueError:
        # we don't handle port information for now.
        return ()
    val = val.strip('\'" ')
    val = escape(val, 1)
    return label, val

def parse_plugin(astr):
    # icky quick hack
    lines = astr.split('\n')
    pairs = [split_vals(line) for line in lines]
    pairs = [p for p in pairs if p]
    info = dict(pairs)
    return info

def parse_plugins(path):
    info_str = os.popen('analyseplugin %s' % path).read()
    plugin_strings = info_str.split('\n\n')
    plugin_infos = [parse_plugin(s) for s in plugin_strings]
    plugin_infos = [i for i in plugin_infos if i]
    return plugin_infos

def make_rdf(parsed):
    plugins_rdf = [HEADER]
    # Sort by ID.
    sortable = [(d['Plugin Unique ID'], d) for d in parsed]
    parsed = [t[1] for t in sorted(sortable)]
    for info in parsed:
        plugin_template % info
    plugins_rdf.extend([plugin_template % info for info in parsed])
    plugins_rdf.append(FOOTER)
    return '\n'.join(plugins_rdf)


if __name__ == '__main__':
    where = find_plugin('caps.so')  # XXX make it a parameter
    parsed = parse_plugins(where)
    print make_rdf(parsed)

Reply via email to