File: plugins.rst

package info (click to toggle)
lilv 0.26.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,336 kB
  • sloc: ansic: 11,764; python: 1,698; cpp: 349; makefile: 160; sh: 70
file content (94 lines) | stat: -rw-r--r-- 2,505 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
..
   Copyright 2020-2022 David Robillard <d@drobilla.net>
   SPDX-License-Identifier: ISC

.. default-domain:: c
.. highlight:: c

#######
Plugins
#######

After bundles are loaded,
all discovered plugins can be accessed via :func:`lilv_world_get_all_plugins`:

.. code-block:: c

   LilvPlugins* plugins = lilv_world_get_all_plugins(world);

:struct:`LilvPlugins` is a collection of plugins that can be accessed by index or plugin URI.
The convenicne macro :macro:`LILV_FOREACH` is provided to make iterating over collections simple.
For example, to print the URI of every plugin:

.. code-block:: c

   LILV_FOREACH (plugins, i, list) {
     const LilvPlugin* p = lilv_plugins_get(list, i);
       printf("%s\n", lilv_node_as_uri(lilv_plugin_get_uri(p)));
     }
   }

More typically,
you want to load a specific plugin,
which can be done with :func:`lilv_plugins_get_by_uri`:

.. code-block:: c

   LilvNode* plugin_uri = lilv_new_uri(world, "http://example.org/Osc");

   const LilvPlugin* plugin = lilv_plugins_get_by_uri(list, plugin_uri);

:struct:`LilvPlugin` has various accessors that can be used to get information about the plugin.
See the :doc:`API reference <api/lilv_plugin>` for details.

*********
Instances
*********

:struct:`LilvPlugin` only represents the data of the plugin,
it does not load or access the actual plugin code.
To do that, you must instantiate a plugin to create :struct:`LilvInstance`:

.. code-block:: c

   LilvInstance* instance = lilv_plugin_instantiate(plugin, 48000.0, NULL);

Connecting Ports
================

Before running a plugin instance, its ports must be connected to some data.
This is done with :func:`lilv_instance_connect_port`.
Assuming the plugins has two control input ports and one audio output port,
in that order:

.. code-block:: c

   float control_in_1 = 0.0f;
   float control_in_2 = 0.0f;

   float audio_out[128];

   lilv_instance_connect_port(instance, 0, &control_in_1);
   lilv_instance_connect_port(instance, 1, &control_in_2);
   lilv_instance_connect_port(instance, 2, &audio_out);

Processing Data
===============

Once the ports are connected, the instance can be activated and run:

.. code-block:: c

   lilv_instance_activate(instance);

   lilv_instance_run(instance, 128);
   // Copy buffers around and probably run several times here...

   lilv_instance_deactivate(instance);

Once you are done with an instance,
it can be destroyed with :func:`lilv_instance_free`:

.. code-block:: c

   lilv_instance_free(instance);