lv2peg

lv2peg is a program that generates C header files from Turtle files containing LV2 plugin data. This is useful for keeping the RDF data and your source code synchronised while you are working on the plugin and maybe changing things like port types and ranges.

Here is an example of what a header file produced by lv2peg can look like:

#ifndef lv_peg_example_peg
#define lv_peg_example_peg


#ifndef PEG_STRUCT
#define PEG_STRUCT
typedef struct {
  float min;
  float max;
  float default_value;
  char toggled;
  char integer;
  char logarithmic;
} peg_data_t;
#endif

/* <http://ll-plugins.nongnu.org/lv2/example/sine> */

static const char p_uri[] = "http://ll-plugins.nongnu.org/lv2/example/sine";

enum p_port_enum {
  p_freq,
  p_amp,
  p_output,
  p_n_ports
};

static const peg_data_t p_ports[] = {
  { 0, 880, 440, 0, 0, 0 }, 
  { 0, 1, 1, 0, 0, 0 }, 
  { -3.40282e+38, 3.40282e+38, -3.40282e+38, 0, 0, 0 }, 
};


#endif /* lv_peg_example_peg */
      

This header was generated from the following RDF data:

@prefix lv2:  <http://lv2plug.in/ns/lv2core#>.
@prefix doap: <http://usefulinc.com/ns/doap#>.
@prefix ll: <http://ll-plugins.nongnu.org/lv2/namespace#>.


<http://ll-plugins.nongnu.org/lv2/example/sine>
  a lv2:Plugin;
  lv2:binary <sine.so>;
  doap:name "Sine";
  doap:license <http://usefulinc.com/doap/licenses/gpl>;
  ll:pegName "p";

  lv2:port [
    a lv2:ControlPort, lv2:InputPort;
    lv2:index 0;
    lv2:symbol "freq";
    lv2:name "Frequency";
    lv2:minimum 0;
    lv2:maximum 880;
    lv2:default 440;
  ],

  [
    a lv2:ControlPort, lv2:InputPort;
    lv2:index 1;
    lv2:symbol "amp";
    lv2:name "Amplitude";
    lv2:minimum 0;
    lv2:maximum 1;
    lv2:default 1;
  ],

  [
    a lv2:AudioPort, lv2:OutputPort;
    lv2:index 2;
    lv2:symbol "output";
    lv2:name "Output";
  ].

      

By including the generated file in the source code for your plugin and setting up your build system to regenerate it when the RDF file changes, you can change the port indices, the ranges and default values, the plugin URI etc without having to update your code manually.