Skip to content

Instantly share code, notes, and snippets.

@ventosus
Last active January 4, 2019 23:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ventosus/ad122810f5b34cfcaf8d to your computer and use it in GitHub Desktop.
Save ventosus/ad122810f5b34cfcaf8d to your computer and use it in GitHub Desktop.
LV2 discovery by plugin class
#include <stdio.h>
#include <lilv/lilv.h>
int
main(int argc, char **argv)
{
LilvWorld *world = lilv_world_new();
if(world)
{
lilv_world_load_all(world);
const LilvPlugins *plugins = lilv_world_get_all_plugins(world);
if(plugins)
{
LILV_FOREACH(plugins, itr, plugins)
{
const LilvPlugin *plugin = lilv_plugins_get(plugins, itr);
if(plugin)
{
const LilvPluginClass *class = lilv_plugin_get_class(plugin);
const LilvNode *uri = lilv_plugin_get_uri(plugin);
LilvNode *name = lilv_plugin_get_name(plugin);
if(class && uri && name)
{
const LilvNode *label = lilv_plugin_class_get_label(class);
printf("%s,%s,%s\n",
lilv_node_as_string(label),
lilv_node_as_string(name),
lilv_node_as_uri(uri));
lilv_node_free(name);
}
}
}
}
lilv_world_free(world);
}
return 0;
}
all: list
lv2_class: lv2_class.c
gcc -std=gnu99 -O3 -o $@ $< $(shell pkg-config --cflags --libs lilv-0)
list: lv2_class
./$< \
| sort \
| sed 's/,/\n/g' \
| zenity \
--list --hide-column=3 --print-column=ALL \
--title='LV2 Plugins' \
--column=Type --column=Name --column=URI
@yPhil-gh
Copy link

Hi, thanks a lot!

I must be missing some libraries, I get this error but I installed everything lilv-related..?

⚡ make                       
gcc -O3 -o lv2_class lv2_class.c -I/usr/include/serd-0 -I/usr/include/sord-0 -I/usr/include/sratom-0 -I/usr/include/lilv-0  -llilv-0 -ldl -lsratom-0 -lsord-0 -lserd-0  
In file included from lv2_class.c:2:0:
lv2_class.c: In function ‘main’:
/usr/include/lilv-0/lilv/lilv.h:327:2: error: ‘for’ loop initial declarations are only allowed in C99 mode
  for (LilvIter* (iter) = lilv_ ## colltype ## _begin(collection); \
  ^
lv2_class.c:15:4: note: in expansion of macro ‘LILV_FOREACH’
    LILV_FOREACH(plugins, itr, plugins)
    ^
/usr/include/lilv-0/lilv/lilv.h:327:2: note: use option -std=c99 or -std=gnu99 to compile your code
  for (LilvIter* (iter) = lilv_ ## colltype ## _begin(collection); \
  ^
lv2_class.c:15:4: note: in expansion of macro ‘LILV_FOREACH’
    LILV_FOREACH(plugins, itr, plugins)
    ^
make: *** [lv2_class] Error 1

@ventosus
Copy link
Author

Your compiler defaults to C90 mode, lilv needs at least C99.

use
gcc -std=gnu99 -O3...
or
gcc -std=gnu11 -O3 ...

@yPhil-gh
Copy link

That did it :)

@conradjones
Copy link

naming a variable class ? doesn't compile for me with clang because of that,

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