Example #1
0
    def generate_license(self):
        lic = self.plugin_get_first_value_as_string(self.ns_doap.license)

        if not lic:
            prj = self.plugin.get_value(self.ns_lv2core.project).get_first()
            if prj.me is not None:
                licsnode = lilv.lilv_world_get(
                    self.world.me,
                    prj.me,
                    self.ns_doap.license.me,
                    None
                )
                if licsnode is not None:
                    lic = lilv.lilv_node_as_string(licsnode)
                del licsnode
            del prj

        if not lic:
            self.errors.append("plugin license is missing")

        elif lic.startswith(self.bundleuri):
            lic = lic.replace(self.bundleuri, "", 1)
            self.warnings.append("plugin license entry is a local path instead of a string")

        return lic
Example #2
0
    def generate_license(self):
        lic = self.plugin_get_first_value_as_string(self.ns_doap.license)

        if not lic:
            prj = self.plugin.get_value(self.ns_lv2core.project).get_first()
            if prj.me is not None:
                licsnode = lilv.lilv_world_get(self.world.me, prj.me,
                                               self.ns_doap.license.me, None)
                if licsnode is not None:
                    lic = lilv.lilv_node_as_string(licsnode)
                del licsnode
            del prj

        if not lic:
            self.errors.append("plugin license is missing")

        elif lic.startswith(self.bundleuri):
            lic = lic.replace(self.bundleuri, "", 1)
            self.warnings.append(
                "plugin license entry is a local path instead of a string")

        return lic
Example #3
0
def get_pedalboard_info(bundle):
    # lilv wants the last character as the separator
    if not bundle.endswith(os.sep):
        bundle += os.sep

    # Create our own unique lilv world
    # We'll load a single bundle and get all plugins from it
    world = lilv.World()

    # this is needed when loading specific bundles instead of load_all
    # (these functions are not exposed via World yet)
    lilv.lilv_world_load_specifications(world.me)
    lilv.lilv_world_load_plugin_classes(world.me)

    # convert bundle string into a lilv node
    bundlenode = lilv.lilv_new_file_uri(world.me, None, bundle)

    # load the bundle
    world.load_bundle(bundlenode)

    # free bundlenode, no longer needed
    lilv.lilv_node_free(bundlenode)

    # get all plugins in the bundle
    plugins = world.get_all_plugins()

    # make sure the bundle includes 1 and only 1 plugin (the pedalboard)
    if plugins.size() != 1:
        raise Exception('get_info_from_lv2_bundle(%s) - bundle has 0 or > 1 plugin'.format(bundle))

    # no indexing in python-lilv yet, just get the first item
    plugin = None
    for p in plugins:
        plugin = p
        break

    if plugin is None:
        raise Exception('get_info_from_lv2_bundle(%s) - failed to get plugin, you are using an old lilv!'.format(bundle))

    # define the needed stuff
    rdf = NS(lilv.LILV_NS_RDF, world)
    ingen = NS('http://drobilla.net/ns/ingen#', world)
    lv2core = NS(lilv.LILV_NS_LV2, world)
    modpedal = NS("http://portalmod.com/ns/modpedal#", world)

    # check if the plugin is a pedalboard
    def fill_in_type(node):
        return node.as_string()
    plugin_types = [i for i in LILV_FOREACH(plugin.get_value(rdf.type_), fill_in_type)]

    if "http://portalmod.com/ns/modpedal#Pedalboard" not in plugin_types:
        raise Exception('get_info_from_lv2_bundle(%s) - plugin has no mod:Pedalboard type'.format(bundle))

    # let's get all the info now
    ingenarcs   = []
    ingenblocks = []

    info = {
        'name':   plugin.get_value(modpedal.name).get_first().as_string(),
        'author': plugin.get_author_name().as_string() or '', # Might be empty
        'uri':    plugin.get_uri().as_string(),
        'hardware': {
            # we save this info later
            'audio': {
                'ins': 0,
                'outs': 0
             },
            'cv': {
                'ins': 0,
                'outs': 0
             },
            'midi': {
                'ins': 0,
                'outs': 0
             }
        },
        'size': {
            'width':  plugin.get_value(modpedal.width).get_first().as_int(),
            'height': plugin.get_value(modpedal.height).get_first().as_int(),
        },
        'screenshot': os.path.basename(plugin.get_value(modpedal.screenshot).get_first().as_string()),
        'thumbnail':  os.path.basename(plugin.get_value(modpedal.thumbnail).get_first().as_string()),
        'connections': [], # we save this info later
        'plugins':     []  # we save this info later
    }

    # connections
    arcs = plugin.get_value(ingen.arc)
    it = arcs.begin()
    while not arcs.is_end(it):
        arc = arcs.get(it)
        it  = arcs.next(it)

        if arc.me is None:
            continue

        head = lilv.lilv_world_get(world.me, arc.me, ingen.head.me, None)
        tail = lilv.lilv_world_get(world.me, arc.me, ingen.tail.me, None)

        if head is None or tail is None:
            continue

        ingenarcs.append({
            "source": lilv.lilv_node_as_string(tail).replace("file://","",1).replace(bundle,"",1),
            "target": lilv.lilv_node_as_string(head).replace("file://","",1).replace(bundle,"",1)
        })

    # hardware ports
    handled_port_uris = []
    ports = plugin.get_value(lv2core.port)
    it = ports.begin()
    while not ports.is_end(it):
        port = ports.get(it)
        it   = ports.next(it)

        if port.me is None:
            continue

        # check if we already handled this port
        port_uri = port.as_uri()
        if port_uri in handled_port_uris:
            continue
        handled_port_uris.append(port_uri)

        # get types
        port_types = lilv.lilv_world_find_nodes(world.me, port.me, rdf.type_.me, None)

        if port_types is None:
            continue

        portDir  = "" # input or output
        portType = "" # atom, audio or cv

        it2 = lilv.lilv_nodes_begin(port_types)
        while not lilv.lilv_nodes_is_end(port_types, it2):
            port_type = lilv.lilv_nodes_get(port_types, it2)
            it2 = lilv.lilv_nodes_next(port_types, it2)

            if port_type is None:
                continue

            port_type_uri = lilv.lilv_node_as_uri(port_type)

            if port_type_uri == "http://lv2plug.in/ns/lv2core#InputPort":
                portDir = "input"
            elif port_type_uri == "http://lv2plug.in/ns/lv2core#OutputPort":
                portDir = "output"
            elif port_type_uri == "http://lv2plug.in/ns/lv2core#AudioPort":
                portType = "audio"
            elif port_type_uri == "http://lv2plug.in/ns/lv2core#CVPort":
                portType = "cv"
            elif port_type_uri == "http://lv2plug.in/ns/ext/atom#AtomPort":
                portType = "atom"

        if not (portDir or portType):
            continue

        if portType == "audio":
            if portDir == "input":
                info['hardware']['audio']['ins'] += 1
            else:
                info['hardware']['audio']['outs'] += 1

        elif portType == "atom":
            if portDir == "input":
                info['hardware']['midi']['ins'] += 1
            else:
                info['hardware']['midi']['outs'] += 1

        elif portType == "cv":
            if portDir == "input":
                info['hardware']['cv']['ins'] += 1
            else:
                info['hardware']['cv']['outs'] += 1

    # plugins
    blocks = plugin.get_value(ingen.block)
    it = blocks.begin()
    while not blocks.is_end(it):
        block = blocks.get(it)
        it    = blocks.next(it)

        if block.me is None:
            continue

        protouri1 = lilv.lilv_world_get(world.me, block.me, lv2core.prototype.me, None)
        protouri2 = lilv.lilv_world_get(world.me, block.me, ingen.prototype.me, None)

        if protouri1 is not None:
            proto = protouri1
        elif protouri2 is not None:
            proto = protouri2
        else:
            continue

        uri = lilv.lilv_node_as_uri(proto)

        ingenblocks.append({
            "uri": uri,
            "x": lilv.lilv_node_as_float(lilv.lilv_world_get(world.me, block.me, ingen.canvasX.me, None)),
            "y": lilv.lilv_node_as_float(lilv.lilv_world_get(world.me, block.me, ingen.canvasY.me, None))
        })

    info['connections'] = ingenarcs
    info['plugins']     = ingenblocks

    return info
Example #4
0
 def lv2homepage(self, maintainer):
     return lilv.lilv_world_get(self.world.me, maintainer,
                                self.ns_foaf.homepage.me, None)
Example #5
0
 def lv2maintaner(self, prj):
     return lilv.lilv_world_get(self.world.me, prj.me,
                                self.ns_doap.maintainer.me, None)
Example #6
0
def get_info_from_lv2_bundle(bundle):
    # lilv wants the last character as the separator
    if not bundle.endswith(os.sep):
        bundle += os.sep

    # Create our own unique lilv world
    # We'll load a single bundle and get all plugins from it
    world = lilv.World()

    # this is needed when loading specific bundles instead of load_all
    # (these functions are not exposed via World yet)
    lilv.lilv_world_load_specifications(world.me)
    lilv.lilv_world_load_plugin_classes(world.me)

    # convert bundle string into a lilv node
    bundlenode = lilv.lilv_new_file_uri(world.me, None, bundle)

    # load the bundle
    world.load_bundle(bundlenode)

    # free bundlenode, no longer needed
    lilv.lilv_node_free(bundlenode)

    # get all plugins in the bundle
    plugins = world.get_all_plugins()

    # make sure the bundle includes 1 and only 1 plugin (the pedalboard)
    if plugins.size() != 1:
        raise Exception('get_info_from_lv2_bundle(%s) - bundle has 0 or > 1 plugin'.format(bundle))

    # no indexing in python-lilv yet, just get the first item
    plugin = None
    for p in plugins:
        plugin = p
        break

    if plugin is None:
        raise Exception('get_info_from_lv2_bundle(%s) - failed to get plugin, you are using an old lilv!'.format(bundle))

    # handy class to get lilv nodes from. copied from lv2.py in mod-ui
    class NS(object):
        def __init__(self, base):
            self.base = base
            self._cache = {}

        def __getattr__(self, attr):
            if attr not in self._cache:
                self._cache[attr] = lilv.Node(world.new_uri(self.base+attr))
            return self._cache[attr]

    # define the needed stuff
    NS_lv2core       = NS('http://lv2plug.in/ns/lv2core#')
    NS_lv2core_proto = NS_lv2core.prototype

    NS_modgui       = NS('http://moddevices.com/ns/modgui#')
    NS_modgui_thumb = NS_modgui.thumbnail

    NS_ingen           = NS('http://drobilla.net/ns/ingen#')
    NS_ingen_block     = NS_ingen.block
    NS_ingen_prototype = NS_ingen.prototype

    # check if the plugin has modgui:thumnail, if not it's probably not a real pedalboard
    thumbnail_check = plugin.get_value(NS_modgui_thumb).get_first()

    if thumbnail_check.me is None:
        raise Exception('get_info_from_lv2_bundle(%s) - plugin has no modgui:thumbnail'.format(bundle))

    # let's get all the info now
    ingenplugins = []

    info = {
        'name':      plugin.get_name().as_string(),
        #'author':    plugin.get_author_name().as_string() or '', # Might be empty
        #'uri':       plugin.get_uri().as_string(),
        'thumbnail': os.path.basename(thumbnail_check.as_string()),
        'plugins':   [] # we save this info later
    }

    blocks = plugin.get_value(NS_ingen_block)

    it = blocks.begin()
    while not blocks.is_end(it):
        block = blocks.get(it)
        it    = blocks.next(it)

        if block.me is None:
            continue

        protouri1 = lilv.lilv_world_get(world.me, block.me, NS_lv2core_proto.me, None)
        protouri2 = lilv.lilv_world_get(world.me, block.me, NS_ingen_prototype.me, None)

        if protouri1 is not None:
            ingenplugins.append(lilv.lilv_node_as_uri(protouri1))
        elif protouri2 is not None:
            ingenplugins.append(lilv.lilv_node_as_uri(protouri2))

    info['plugins'] = ingenplugins

    return info
Example #7
0
def get_pedalboard_info(bundle):
    # lilv wants the last character as the separator
    bundle = os.path.abspath(bundle)
    if not bundle.endswith(os.sep):
        bundle += os.sep

    # Create our own unique lilv world
    # We'll load a single bundle and get all plugins from it
    world = lilv.World()

    # this is needed when loading specific bundles instead of load_all
    # (these functions are not exposed via World yet)
    lilv.lilv_world_load_specifications(world.me)
    lilv.lilv_world_load_plugin_classes(world.me)

    # convert bundle string into a lilv node
    bundlenode = lilv.lilv_new_file_uri(world.me, None, bundle)

    # load the bundle
    world.load_bundle(bundlenode)

    # free bundlenode, no longer needed
    lilv.lilv_node_free(bundlenode)

    # get all plugins in the bundle
    plugins = world.get_all_plugins()

    # make sure the bundle includes 1 and only 1 plugin (the pedalboard)
    if plugins.size() != 1:
        raise Exception(
            'get_pedalboard_info(%s) - bundle has 0 or > 1 plugin'.format(
                bundle))

    # no indexing in python-lilv yet, just get the first item
    plugin = None
    for p in plugins:
        plugin = p
        break

    if plugin is None:
        raise Exception(
            'get_pedalboard_info(%s) - failed to get plugin, you are using an old lilv!'
            .format(bundle))

    # define the needed stuff
    ns_rdf = NS(world, lilv.LILV_NS_RDF)
    ns_lv2core = NS(world, lilv.LILV_NS_LV2)
    ns_ingen = NS(world, "http://drobilla.net/ns/ingen#")
    ns_modpedal = NS(world, "http://moddevices.com/ns/modpedal#")

    # check if the plugin is a pedalboard
    def fill_in_type(node):
        return node.as_string()

    plugin_types = [
        i for i in LILV_FOREACH(plugin.get_value(ns_rdf.type_), fill_in_type)
    ]

    if "http://moddevices.com/ns/modpedal#Pedalboard" not in plugin_types:
        raise Exception(
            'get_pedalboard_info(%s) - plugin has no mod:Pedalboard type'.
            format(bundle))

    # let's get all the info now
    ingenarcs = []
    ingenblocks = []

    info = {
        'name':
        plugin.get_name().as_string(),
        'uri':
        plugin.get_uri().as_string(),
        'author':
        plugin.get_author_name().as_string() or "",  # Might be empty
        'hardware': {
            # we save this info later
            'audio': {
                'ins': 0,
                'outs': 0
            },
            'cv': {
                'ins': 0,
                'outs': 0
            },
            'midi': {
                'ins': 0,
                'outs': 0
            }
        },
        'size': {
            'width': plugin.get_value(ns_modpedal.width).get_first().as_int(),
            'height':
            plugin.get_value(ns_modpedal.height).get_first().as_int(),
        },
        'screenshot':
        os.path.basename(
            plugin.get_value(ns_modpedal.screenshot).get_first().as_string()
            or ""),
        'thumbnail':
        os.path.basename(
            plugin.get_value(ns_modpedal.thumbnail).get_first().as_string()
            or ""),
        'connections': [],  # we save this info later
        'plugins': []  # we save this info later
    }

    # connections
    arcs = plugin.get_value(ns_ingen.arc)
    it = arcs.begin()
    while not arcs.is_end(it):
        arc = arcs.get(it)
        it = arcs.next(it)

        if arc.me is None:
            continue

        head = lilv.lilv_world_get(world.me, arc.me, ns_ingen.head.me, None)
        tail = lilv.lilv_world_get(world.me, arc.me, ns_ingen.tail.me, None)

        if head is None or tail is None:
            continue

        ingenarcs.append({
            "source":
            lilv.lilv_uri_to_path(lilv.lilv_node_as_string(tail)).replace(
                bundle, "", 1),
            "target":
            lilv.lilv_uri_to_path(lilv.lilv_node_as_string(head)).replace(
                bundle, "", 1)
        })

    # hardware ports
    handled_port_uris = []
    ports = plugin.get_value(ns_lv2core.port)
    it = ports.begin()
    while not ports.is_end(it):
        port = ports.get(it)
        it = ports.next(it)

        if port.me is None:
            continue

        # check if we already handled this port
        port_uri = port.as_uri()
        if port_uri in handled_port_uris:
            continue
        if port_uri.endswith("/control_in") or port_uri.endswith(
                "/control_out"):
            continue
        handled_port_uris.append(port_uri)

        # get types
        port_types = lilv.lilv_world_find_nodes(world.me, port.me,
                                                ns_rdf.type_.me, None)

        if port_types is None:
            continue

        portDir = ""  # input or output
        portType = ""  # atom, audio or cv

        it2 = lilv.lilv_nodes_begin(port_types)
        while not lilv.lilv_nodes_is_end(port_types, it2):
            port_type = lilv.lilv_nodes_get(port_types, it2)
            it2 = lilv.lilv_nodes_next(port_types, it2)

            if port_type is None:
                continue

            port_type_uri = lilv.lilv_node_as_uri(port_type)

            if port_type_uri == "http://lv2plug.in/ns/lv2core#InputPort":
                portDir = "input"
            elif port_type_uri == "http://lv2plug.in/ns/lv2core#OutputPort":
                portDir = "output"
            elif port_type_uri == "http://lv2plug.in/ns/lv2core#AudioPort":
                portType = "audio"
            elif port_type_uri == "http://lv2plug.in/ns/lv2core#CVPort":
                portType = "cv"
            elif port_type_uri == "http://lv2plug.in/ns/ext/atom#AtomPort":
                portType = "atom"

        if not (portDir or portType):
            continue

        if portType == "audio":
            if portDir == "input":
                info['hardware']['audio']['ins'] += 1
            else:
                info['hardware']['audio']['outs'] += 1

        elif portType == "atom":
            if portDir == "input":
                info['hardware']['midi']['ins'] += 1
            else:
                info['hardware']['midi']['outs'] += 1

        elif portType == "cv":
            if portDir == "input":
                info['hardware']['cv']['ins'] += 1
            else:
                info['hardware']['cv']['outs'] += 1

    # plugins
    blocks = plugin.get_value(ns_ingen.block)
    it = blocks.begin()
    while not blocks.is_end(it):
        block = blocks.get(it)
        it = blocks.next(it)

        if block.me is None:
            continue

        protouri1 = lilv.lilv_world_get(world.me, block.me,
                                        ns_lv2core.prototype.me, None)
        protouri2 = lilv.lilv_world_get(world.me, block.me,
                                        ns_ingen.prototype.me, None)

        if protouri1 is not None:
            proto = protouri1
        elif protouri2 is not None:
            proto = protouri2
        else:
            continue

        instance = lilv.lilv_uri_to_path(lilv.lilv_node_as_string(
            block.me)).replace(bundle, "", 1)
        uri = lilv.lilv_node_as_uri(proto)

        enabled = lilv.lilv_world_get(world.me, block.me, ns_ingen.enabled.me,
                                      None)
        minorver = lilv.lilv_world_get(world.me, block.me,
                                       ns_lv2core.minorVersion.me, None)
        microver = lilv.lilv_world_get(world.me, block.me,
                                       ns_lv2core.microVersion.me, None)

        ingenblocks.append({
            "instance":
            instance,
            "uri":
            uri,
            "x":
            lilv.lilv_node_as_float(
                lilv.lilv_world_get(world.me, block.me, ns_ingen.canvasX.me,
                                    None)),
            "y":
            lilv.lilv_node_as_float(
                lilv.lilv_world_get(world.me, block.me, ns_ingen.canvasY.me,
                                    None)),
            "enabled":
            lilv.lilv_node_as_bool(enabled) if enabled is not None else False,
            "minorVersion":
            lilv.lilv_node_as_int(minorver) if minorver else 0,
            "microVersion":
            lilv.lilv_node_as_int(microver) if microver else 0,
        })

    info['connections'] = ingenarcs
    info['plugins'] = ingenblocks

    return info