Exemple #1
0
uint32
LV2Module::getMidiPort() const
{
   for (uint32 i = 0; i < getNumPorts(); ++i)
   {
       const LilvPort* port (getPort (i));
       if ((lilv_port_is_a (plugin, port, world.lv2_AtomPort) || lilv_port_is_a (plugin, port, world.lv2_EventPort))&&
           lilv_port_is_a (plugin, port, world.lv2_InputPort) &&
           lilv_port_supports_event (plugin, port, world.midi_MidiEvent))
           return i;
   }

   return LV2UI_INVALID_PORT_INDEX;
}
Exemple #2
0
uint32
LV2Module::getNotifyPort() const
{
    for (uint32 i = 0; i < numPorts; ++i)
    {
        const LilvPort* port (getPort (i));
        if (lilv_port_is_a (plugin, port, world.lv2_AtomPort) &&
            lilv_port_is_a (plugin, port, world.lv2_OutputPort) &&
            lilv_port_supports_event (plugin, port, world.midi_MidiEvent))
        {
            return i;
        }
    }
    
    return LV2UI_INVALID_PORT_INDEX;
}
Exemple #3
0
PortType
LV2Module::getPortType (uint32 i) const
{
   const LilvPort* port (lilv_plugin_get_port_by_index (plugin, i));

   if (lilv_port_is_a (plugin, port, world.lv2_AudioPort))
       return PortType::Audio;
   else if (lilv_port_is_a (plugin, port, world.lv2_AtomPort))
       return PortType::Atom;
   else if (lilv_port_is_a (plugin, port, world.lv2_ControlPort))
       return PortType::Control;
   else if (lilv_port_is_a (plugin, port, world.lv2_CVPort))
       return PortType::CV;
   else if (lilv_port_is_a (plugin, port, world.lv2_EventPort))
       return PortType::Event;

   return PortType::Unknown;
}
Exemple #4
0
void
LV2Module::init()
{
    // create and set default port values
    priv->mins.allocate (numPorts, true);
    priv->maxes.allocate (numPorts, true);
    priv->defaults.allocate (numPorts, true);
    priv->values.allocate (numPorts, true);
    lilv_plugin_get_port_ranges_float (plugin, priv->mins, priv->maxes, priv->defaults);
    
    // initialize each port
    for (uint32 p = 0; p < numPorts; ++p)
    {
        const LilvPort* port (lilv_plugin_get_port_by_index (plugin, p));
        const bool isInput (lilv_port_is_a (plugin, port, world.lv2_InputPort));
        priv->channels.addPort (getPortType (p), p, isInput);
        priv->values [p] = priv->defaults [p];
    }
}
Exemple #5
0
LV2Effect::LV2Effect(const LilvPlugin *data,
                     const std::set<wxString> & categories)
:  mValid(true),
   mCategories(categories),
   mMidiInput(0),
   mLatencyPortIndex(-1)
{
   
   // We don't support any features at all, so if the plugin requires
   // any we skip it.
   LilvNodes *req = lilv_plugin_get_required_features(data);
   size_t nFeatures = lilv_nodes_size(req);
   lilv_nodes_free(req);
   if (nFeatures > 0)
   {
      mValid = false;
      return;
   }

   mData = data;
   pluginName = GetString(lilv_plugin_get_name(mData), true);

   fInBuffer = NULL;
   fOutBuffer = NULL;
   
   mLength = 0;

   // Allocate buffers for the port indices and the default control values
   int numPorts = lilv_plugin_get_num_ports(mData);
   float *minimumValues = new float [numPorts];
   float *maximumValues = new float [numPorts];
   float *defaultValues = new float [numPorts];

   // Retrieve the port ranges for all ports (some values may be NaN)
   lilv_plugin_get_port_ranges_float(mData, minimumValues, 
                                     maximumValues, defaultValues);

   // Get info about all ports
   for (int i = 0; i < numPorts; i++)
   {
      const LilvPort *port = lilv_plugin_get_port_by_index(mData, i);
      LV2Port internalPort;
      internalPort.mIndex = lilv_port_get_index(mData, port);

      // Get the port name
      LilvNode *tmpName = lilv_port_get_name(mData, port);
      internalPort.mName = GetString(tmpName);
      lilv_node_free(tmpName);

      // Get the scale points
      LilvScalePoints* points = lilv_port_get_scale_points(mData, port);
      LILV_FOREACH(scale_points, j, points)
      {
         const LilvScalePoint *point = lilv_scale_points_get(points, j);

         internalPort.mScaleValues.Add(lilv_node_as_float(lilv_scale_point_get_value(point)));
         internalPort.mScaleLabels.Add(GetString(lilv_scale_point_get_label(point)));
      }
      lilv_scale_points_free(points);

      // Get the groups
      LilvNodes *groups = lilv_port_get_value(mData, port, gPortGroup);
      if (groups)
      {
         LilvNode *group = lilv_nodes_get_first(groups);
         wxString uri = GetString(group);

         wxString label;
         const LilvNode *name = lilv_world_get(gWorld, group, gName, NULL);
         if (name)
         {
            label = GetString(name);
         }
         else
         {
            // Shouldn't happen, but provide something
            label = uri;
         }
         lilv_nodes_free(groups);

         // Check for new group
         if (mPortGroups.find(uri) == mPortGroups.end())
         {
            mPortGroups[uri] = LV2PortGroup(label);
         }
#if 0
         // Get subgroup
         //
         // LLL:  This isn't right...must find or construct a plugin with
         //       subgroups.
         LilvNodes *subgroup = lilv_node_get_value(mData, port, gSubGroupOf);
         if (subgroups)
         {
            LilvNode *subgroup = lilv_nodes_get_first(subgroups);
            wxString uri = GetString(subgroup);
            const LilvNode *subgroup = lilv_world_get(gWorld, group, gSubGroupOf, NULL);
            wxString label = GetString(name);
            lilv_nodes_free(subgroup);
         }
         else
#endif
         {
            mRootGroup.AddSubGroup(mPortGroups[uri]);
         }
         mPortGroups[uri].AddParameter(i);

      }
      else
      {
         mRootGroup.AddParameter(i);
      }

      // Get the port type
      if (lilv_port_is_a(mData, port, gAudioPortClass))
      {
         if (lilv_port_is_a(mData, port, gInputPortClass))
         {
            mAudioInputs.Add(internalPort);
         }
         else if (lilv_port_is_a(mData, port, gOutputPortClass))
         {
            mAudioOutputs.Add(internalPort);
         }
      }
      else if (lilv_port_is_a(mData, port, gControlPortClass) &&
               lilv_port_is_a(mData, port, gInputPortClass))
      {
         internalPort.mControlBuffer = float(1.0);
         internalPort.mMin = minimumValues[i];
         internalPort.mMax = maximumValues[i];
         internalPort.mDefault = defaultValues[i];
         if (isfinite(defaultValues[i]))
         {
            internalPort.mControlBuffer = defaultValues[i];
         }
         else if (isfinite(minimumValues[i]))
         {
            internalPort.mControlBuffer = minimumValues[i];
         }
         else if (isfinite(maximumValues[i]))
         {
            internalPort.mControlBuffer = maximumValues[i];
         }

         if (lilv_port_has_property(mData, port, gPortToggled))
         {
            internalPort.mToggle = true;
         }
         else if (lilv_port_has_property(mData, port, gPortIsInteger))
         {
            internalPort.mInteger = true;
         }
         else if (lilv_port_has_property(mData, port, gPortIsSampleRate))
         {
            internalPort.mSampleRate = true;
         }
         else if (lilv_port_has_property(mData, port, gPortIsEnumeration))
         {
            internalPort.mEnumeration = true;
         }

         mControlInputs.Add(internalPort);
      }
      else if (lilv_port_is_a(mData, port, gControlPortClass) &&
               lilv_port_is_a(mData, port, gOutputPortClass))
      {
         // If there is more than one latency port, the plugin is invalid
         if (lilv_port_has_property(mData, port, gPortIsLatency))
         {
            if (mLatencyPortIndex >= 0)
            {
               mValid = false;
               continue;
            }
            mLatencyPortIndex = i;
         }
         else if (!lilv_port_has_property(mData, port, gPortIsOptional))
         {
            mControlOutputs.Add(internalPort);
         }
      }
      else if (lilv_port_is_a(mData, port, gMidiPortClass) &&
               lilv_port_is_a(mData, port, gInputPortClass))
      {
         // If there is more than one MIDI input port, the plugin is invalid
         if (mMidiInput)
         {
            mValid = false;
            continue;
         }
         mMidiInput = new LV2Port(internalPort);
      }
      else
      {
         // Unknown port type, we set the invalid flag
 //        mValid = false;
      }
   }
   
   delete [] minimumValues;
   delete [] maximumValues;
   delete [] defaultValues;
   
   // MIDI synths may not have any audio inputs.
   if (mMidiInput && mAudioInputs.GetCount() > 0)
   {
      mValid = false;
   }
   
   // Determine whether the plugin is a generator, effect or analyser 
   // depending on the number of ports of each type (not completely accurate,
   // but works most of the time)
   int flags = PLUGIN_EFFECT;
   if (mAudioInputs.GetCount() == 0)
   {
      flags |= INSERT_EFFECT;
   }
   else if (mAudioOutputs.GetCount() == 0)
   {
      flags |= ANALYZE_EFFECT;
   }
   else
   {
      flags |= PROCESS_EFFECT;
   }

   SetEffectFlags(flags);
}
static GParamSpec *
gst_lv2_filter_class_get_param_spec (GstLV2FilterClass * klass, gint portnum)
{
    LilvPlugin *lv2plugin = klass->plugin;
    const LilvPort *port = lilv_plugin_get_port_by_index (lv2plugin, portnum);
    LilvNode *lv2def, *lv2min, *lv2max;
    GParamSpec *ret;
    gchar *name, *nick;
    gint perms;
    gfloat lower = 0.0f, upper = 1.0f, def = 0.0f;

    nick = gst_lv2_filter_class_get_param_nick (klass, port);
    name = gst_lv2_filter_class_get_param_name (klass, port);

    GST_DEBUG ("%s trying port %s : %s",
               lilv_node_as_string (lilv_plugin_get_uri (lv2plugin)), name, nick);

    perms = G_PARAM_READABLE;
    if (lilv_port_is_a (lv2plugin, port, input_class))
        perms |= G_PARAM_WRITABLE | G_PARAM_CONSTRUCT;
    if (lilv_port_is_a (lv2plugin, port, control_class))
        perms |= GST_PARAM_CONTROLLABLE;

    if (lilv_port_has_property (lv2plugin, port, toggled_prop)) {
        ret = g_param_spec_boolean (name, nick, nick, FALSE, perms);
        goto done;
    }

    lilv_port_get_range (lv2plugin, port, &lv2def, &lv2min, &lv2max);

    if (lv2def)
        def = lilv_node_as_float (lv2def);
    if (lv2min)
        lower = lilv_node_as_float (lv2min);
    if (lv2max)
        upper = lilv_node_as_float (lv2max);

    lilv_node_free (lv2def);
    lilv_node_free (lv2min);
    lilv_node_free (lv2max);

    if (def < lower) {
        GST_WARNING ("%s has lower bound %f > default %f",
                     lilv_node_as_string (lilv_plugin_get_uri (lv2plugin)), lower, def);
        lower = def;
    }

    if (def > upper) {
        GST_WARNING ("%s has upper bound %f < default %f",
                     lilv_node_as_string (lilv_plugin_get_uri (lv2plugin)), upper, def);
        upper = def;
    }

    if (lilv_port_has_property (lv2plugin, port, integer_prop))
        ret = g_param_spec_int (name, nick, nick, lower, upper, def, perms);
    else
        ret = g_param_spec_float (name, nick, nick, lower, upper, def, perms);

done:
    g_free (name);
    g_free (nick);

    return ret;
}
static void
gst_lv2_filter_base_init (gpointer g_class)
{
    GstLV2FilterClass *klass = (GstLV2FilterClass *) g_class;
    GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
    LilvPlugin *lv2plugin;
    LilvNode *val;
    /* FIXME Handle channels positionning
     * GstAudioChannelPosition position = GST_AUDIO_CHANNEL_POSITION_INVALID; */
    guint j, in_pad_index = 0, out_pad_index = 0;
    gchar *longname, *author;

    lv2plugin = (LilvPlugin *) g_type_get_qdata (G_OBJECT_CLASS_TYPE (klass),
                descriptor_quark);

    g_assert (lv2plugin);

    GST_INFO ("base_init %p, plugin %s", g_class,
              lilv_node_get_turtle_token (lilv_plugin_get_uri (lv2plugin)));

    klass->in_group.ports = g_array_new (FALSE, TRUE, sizeof (GstLV2FilterPort));
    klass->out_group.ports = g_array_new (FALSE, TRUE, sizeof (GstLV2FilterPort));
    klass->control_in_ports =
        g_array_new (FALSE, TRUE, sizeof (GstLV2FilterPort));
    klass->control_out_ports =
        g_array_new (FALSE, TRUE, sizeof (GstLV2FilterPort));

    /* find ports and groups */
    for (j = 0; j < lilv_plugin_get_num_ports (lv2plugin); j++) {
        const LilvPort *port = lilv_plugin_get_port_by_index (lv2plugin, j);
        const gboolean is_input = lilv_port_is_a (lv2plugin, port, input_class);
        struct _GstLV2FilterPort desc = { j, 0, };
        LilvNodes *lv2group = lilv_port_get (lv2plugin, port, group_pred);

        if (lv2group) {
            /* port is part of a group */
            const gchar *group_uri = lilv_node_as_uri (lv2group);
            GstLV2FilterGroup *group =
                is_input ? &klass->in_group : &klass->out_group;

            if (group->uri == NULL) {
                group->uri = g_strdup (group_uri);
                group->pad = is_input ? in_pad_index++ : out_pad_index++;
                group->ports = g_array_new (FALSE, TRUE, sizeof (GstLV2FilterPort));
            }

            /* FIXME Handle channels positionning
               position = GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT;
               sub_values = lilv_port_get_value (lv2plugin, port, has_role_pred);
               if (lilv_nodes_size (sub_values) > 0) {
               LilvNode *role = lilv_nodes_get_at (sub_values, 0);
               position = gst_lv2_filter_role_to_position (role);
               }
               lilv_nodes_free (sub_values);

               if (position != GST_AUDIO_CHANNEL_POSITION_INVALID) {
               desc.position = position;
               } */

            g_array_append_val (group->ports, desc);
        } else {
            /* port is not part of a group, or it is part of a group but that group
             * is illegal so we just ignore it */
            if (lilv_port_is_a (lv2plugin, port, audio_class)) {

                desc.pad = is_input ? in_pad_index++ : out_pad_index++;
                if (is_input)
                    g_array_append_val (klass->in_group.ports, desc);
                else
                    g_array_append_val (klass->out_group.ports, desc);
            } else if (lilv_port_is_a (lv2plugin, port, control_class)) {
                if (is_input)
                    g_array_append_val (klass->control_in_ports, desc);
                else
                    g_array_append_val (klass->control_out_ports, desc);
            } else {
                /* unknown port type */
                GST_INFO ("unhandled port %d", j);
                continue;
            }
        }
    }
    gst_lv2_filter_type_class_add_pad_templates (klass);

    val = lilv_plugin_get_name (lv2plugin);
    if (val) {
        longname = g_strdup (lilv_node_as_string (val));
        lilv_node_free (val);
    } else {
        longname = g_strdup ("no description available");
    }
    val = lilv_plugin_get_author_name (lv2plugin);
    if (val) {
        author = g_strdup (lilv_node_as_string (val));
        lilv_node_free (val);
    } else {
        author = g_strdup ("no author available");
    }

    gst_element_class_set_metadata (element_class, longname,
                                    "Filter/Effect/Audio/LV2", longname, author);
    g_free (longname);
    g_free (author);

    klass->plugin = lv2plugin;
}
Exemple #8
0
bool
LV2Module::isPortOutput (uint32 index) const
{
   return lilv_port_is_a (plugin, getPort (index), world.lv2_OutputPort);
}
Exemple #9
0
LILV_API
LilvState*
lilv_state_new_from_instance(const LilvPlugin*          plugin,
                             LilvInstance*              instance,
                             LV2_URID_Map*              map,
                             const char*                file_dir,
                             const char*                copy_dir,
                             const char*                link_dir,
                             const char*                save_dir,
                             LilvGetPortValueFunc       get_value,
                             void*                      user_data,
                             uint32_t                   flags,
                             const LV2_Feature *const * features)
{
	const LV2_Feature** sfeatures = NULL;
	LilvWorld* const    world     = plugin->world;
	LilvState* const    state     = (LilvState*)malloc(sizeof(LilvState));
	memset(state, '\0', sizeof(LilvState));
	state->plugin_uri = lilv_node_duplicate(lilv_plugin_get_uri(plugin));
	state->abs2rel    = zix_tree_new(false, abs_cmp, NULL, path_rel_free);
	state->rel2abs    = zix_tree_new(false, rel_cmp, NULL, NULL);
	state->file_dir   = file_dir ? absolute_dir(file_dir) : NULL;
	state->copy_dir   = copy_dir ? absolute_dir(copy_dir) : NULL;
	state->link_dir   = link_dir ? absolute_dir(link_dir) : NULL;
	state->dir        = save_dir ? absolute_dir(save_dir) : NULL;
	state->atom_Path  = map->map(map->handle, LV2_ATOM__Path);

	LV2_State_Map_Path  pmap          = { state, abstract_path, absolute_path };
	LV2_Feature         pmap_feature  = { LV2_STATE__mapPath, &pmap };
	LV2_State_Make_Path pmake         = { state, make_path };
	LV2_Feature         pmake_feature = { LV2_STATE__makePath, &pmake };
	features = sfeatures = add_features(features, &pmap_feature,
	                                    save_dir ? &pmake_feature : NULL);

	// Store port values
	if (get_value) {
		LilvNode* lv2_ControlPort = lilv_new_uri(world, LILV_URI_CONTROL_PORT);
		LilvNode* lv2_InputPort   = lilv_new_uri(world, LILV_URI_INPUT_PORT);
		for (uint32_t i = 0; i < plugin->num_ports; ++i) {
			const LilvPort* const port = plugin->ports[i];
			if (lilv_port_is_a(plugin, port, lv2_ControlPort)
			    && lilv_port_is_a(plugin, port, lv2_InputPort)) {
				uint32_t size, type;
				const char* sym   = lilv_node_as_string(port->symbol);
				const void* value = get_value(sym, user_data, &size, &type);
				append_port_value(state, sym, value, size, type);
			}
		}
		lilv_node_free(lv2_ControlPort);
		lilv_node_free(lv2_InputPort);
	}

	// Store properties
	const LV2_Descriptor*      desc  = instance->lv2_descriptor;
	const LV2_State_Interface* iface = (desc->extension_data)
		? (LV2_State_Interface*)desc->extension_data(LV2_STATE__interface)
		: NULL;

	if (iface) {
		LV2_State_Status st = iface->save(
			instance->lv2_handle, store_callback, state, flags, features);
		if (st) {
			LILV_ERRORF("Error saving plugin state: %s\n", state_strerror(st));
			free(state->props);
			state->props     = NULL;
			state->num_props = 0;
		} else {
			qsort(state->props, state->num_props, sizeof(Property), property_cmp);
		}
	}

	qsort(state->values, state->num_values, sizeof(PortValue), value_cmp);

	free(sfeatures);
	return state;
}
Exemple #10
0
Lv2Plugin::Lv2Plugin(const LilvPlugin *plugin, LilvInstance *instance,
                     const Lv2Constants &uris, Lv2Worker *worker) :
    plugin(plugin), instance(instance), midiOutputCount(0),
    controlConnections(4), newControlMappingsQueue(16), worker(worker)
{
    // audio inputs
    audioInputCount = lilv_plugin_get_num_ports_of_class(plugin, uris.lv2AudioPort, uris.lv2InputPort, 0);
    audioInputIndex = new uint32_t[audioInputCount];
    audioInput = new AudioConnector[audioInputCount];

    // audio outputs
    audioOutputCount = lilv_plugin_get_num_ports_of_class(plugin, uris.lv2AudioPort, uris.lv2OutputPort, 0);
    audioOutputIndex = new uint32_t[audioOutputCount];
    audioOutput = new AudioConnection*[audioOutputCount];
    for(uint32_t i = 0; i < audioOutputCount; i++) {
        audioOutput[i] = new AudioConnection(this);
        audioOutput[i]->clear();
    }

    // initialize port structures
    uint32_t numPorts = lilv_plugin_get_num_ports(plugin);
    uint32_t audioInputCounter = 0;
    uint32_t audioOutputCounter = 0;
    for(uint32_t i = 0; i < numPorts; i++) {
        const LilvPort *port = lilv_plugin_get_port_by_index(plugin, i);
        if(lilv_port_is_a(plugin, port, uris.lv2AudioPort)) {
            if(lilv_port_is_a(plugin, port, uris.lv2InputPort)) {
                audioInputIndex[audioInputCounter++] = i;
            }
            else if(lilv_port_is_a(plugin, port, uris.lv2OutputPort)) {
                audioOutputIndex[audioOutputCounter++] = i;
            }
        } else if(lilv_port_is_a(plugin, port, uris.lv2ControlPort)
                  && lilv_port_is_a(plugin, port, uris.lv2InputPort)) {
            // get control name
            const LilvNode* symbol = lilv_port_get_symbol(plugin, port);
            std::string portName(lilv_node_as_string(symbol));

            // create, connect and hash new control port object
            Lv2ControlPort *newPort = new Lv2ControlPort();
            LilvNode *dfault, *minimum, *maximum;
            lilv_port_get_range(plugin, port, &dfault, &minimum, &maximum);
            newPort->dfault = dfault ? lilv_node_as_float(dfault) : 0;
            newPort->minimum = lilv_node_as_float(minimum);
            newPort->maximum = lilv_node_as_float(maximum);
            lilv_instance_connect_port(instance, i, &(newPort->value));
            controlMap[portName] = newPort;

        } else if(lilv_port_is_a(plugin, port, uris.lv2AtomPort)) {
            // is it a MIDI/atom input?
            LilvNodes *atomBufferType = lilv_port_get_value(plugin, port, uris.lv2AtomBufferType);
            LilvNodes* atomSupports = lilv_port_get_value(plugin, port, uris.lv2AtomSupports);
            if (lilv_port_is_a(plugin, port, uris.lv2InputPort) &&
                    lilv_nodes_contains(atomBufferType, uris.lv2AtomSequence)
                    && lilv_nodes_contains(atomSupports, uris.lv2MidiEvent)) {
                // create new inputs and connect to atom sequence location
                Lv2MidiInput *newAtomPort = new Lv2MidiInput();
                lilv_instance_connect_port(instance, i, newAtomPort->getAtomSequence());
                midiInputList.add(newAtomPort);
            }
            else if (lilv_port_is_a(plugin, port, uris.lv2OutputPort)) {
                //atomSequence->atom.type = Lv2PluginFactory::instance()->uridMapper.uriToId(LV2_ATOM__Sequence);
                Lv2MidiOutput *midiOutput = new Lv2MidiOutput(this);
                lilv_instance_connect_port(instance, i, midiOutput->getAtomSequence());
                midiOutputList.add(midiOutput);
                midiOutputCount++;
            }
            else {
                // warn
                std::cout << "!!! unknown atom port at index " << i << ": " << lilv_node_as_string(lilv_port_get_name(plugin, port)) << std::endl;
            }
            lilv_nodes_free(atomSupports);
            lilv_nodes_free(atomBufferType);
        } else {
            lilv_instance_connect_port(instance, i, NULL);
            std::cout << "!!! unknown port at index " << i << ": " << lilv_node_as_string(lilv_port_get_name(plugin, port)) << std::endl;
        }
    }
}
Exemple #11
0
static double
bench(const LilvPlugin* p, uint32_t sample_count, uint32_t block_size)
{
	URITable uri_table;
	uri_table_init(&uri_table);

	LV2_URID_Map       map           = { &uri_table, uri_table_map };
	LV2_Feature        map_feature   = { LV2_URID_MAP_URI, &map };
	LV2_URID_Unmap     unmap         = { &uri_table, uri_table_unmap };
	LV2_Feature        unmap_feature = { LV2_URID_UNMAP_URI, &unmap };
	const LV2_Feature* features[]    = { &map_feature, &unmap_feature, NULL };

	float* const buf = (float*)calloc(block_size * 2, sizeof(float));
	float* const in  = buf;
	float* const out = buf + block_size;
	if (!buf) {
		fprintf(stderr, "Out of memory\n");
		return 0.0;
	}

	LV2_Atom_Sequence seq = {
		{ sizeof(LV2_Atom_Sequence_Body),
		  uri_table_map(&uri_table, LV2_ATOM__Sequence) },
		{ 0, 0 } };

	const char* uri      = lilv_node_as_string(lilv_plugin_get_uri(p));
	LilvNodes*  required = lilv_plugin_get_required_features(p);
	LILV_FOREACH(nodes, i, required) {
		const LilvNode* feature = lilv_nodes_get(required, i);
		if (!lilv_node_equals(feature, urid_map)) {
			fprintf(stderr, "<%s> requires feature <%s>, skipping\n",
			        uri, lilv_node_as_uri(feature));
			free(buf);
			uri_table_destroy(&uri_table);
			return 0.0;
		}
	}

	LilvInstance* instance = lilv_plugin_instantiate(p, 48000.0, features);
	if (!instance) {
		fprintf(stderr, "Failed to instantiate <%s>\n",
		        lilv_node_as_uri(lilv_plugin_get_uri(p)));
		free(buf);
		uri_table_destroy(&uri_table);
		return 0.0;
	}

	float* controls = (float*)calloc(
		lilv_plugin_get_num_ports(p), sizeof(float));
	lilv_plugin_get_port_ranges_float(p, NULL, NULL, controls);

	const uint32_t n_ports = lilv_plugin_get_num_ports(p);
	for (uint32_t index = 0; index < n_ports; ++index) {
		const LilvPort* port = lilv_plugin_get_port_by_index(p, index);
		if (lilv_port_is_a(p, port, lv2_ControlPort)) {
			lilv_instance_connect_port(instance, index, &controls[index]);
		} else if (lilv_port_is_a(p, port, lv2_AudioPort) ||
		           lilv_port_is_a(p, port, lv2_CVPort)) {
			if (lilv_port_is_a(p, port, lv2_InputPort)) {
				lilv_instance_connect_port(instance, index, in);
			} else if (lilv_port_is_a(p, port, lv2_OutputPort)) {
				lilv_instance_connect_port(instance, index, out);
			} else {
				fprintf(stderr, "<%s> port %d neither input nor output, skipping\n",
				        uri, index);
				lilv_instance_free(instance);
				free(buf);
				free(controls);
				uri_table_destroy(&uri_table);
				return 0.0;
			}
		} else if (lilv_port_is_a(p, port, atom_AtomPort)) {
			lilv_instance_connect_port(instance, index, &seq);
		} else {
			fprintf(stderr, "<%s> port %d has unknown type, skipping\n",
			        uri, index);
			lilv_instance_free(instance);
			free(buf);
			free(controls);
			uri_table_destroy(&uri_table);
			return 0.0;
		}
	}

	lilv_instance_activate(instance);

	struct timespec ts = bench_start();
	for (uint32_t i = 0; i < (sample_count / block_size); ++i) {
		lilv_instance_run(instance, block_size);
	}
	const double elapsed = bench_end(&ts);

	lilv_instance_deactivate(instance);
	lilv_instance_free(instance);

	uri_table_destroy(&uri_table);

	if (full_output) {
		printf("%d %d ", block_size, sample_count);
	}
	printf("%lf %s\n", elapsed, uri);

	free(buf);
	free(controls);
	return elapsed;
}