Simple synth plugin source code example

Hi,

I am looking for a simple synth example plugin, like simple_synth.lua, but a LV2 one.

If I understand correctly, this is made by C++ code (and I ask LV2 but not VST3 because, if I understand correctly, LV2 is a few better for Ardour).

Is this source code please available ?

Thanks :slight_smile:

1 Like

Try this one instead:

Seablade

1 Like

I would recommend looking at a plugin framework like Distrho which takes care of all sorts of stuff for you, like for example being able to compile the same sound engine as LV2, VST, CLAP, or whatever.

It’s what I use for peacock - peacock-8 synth plugin which has source available at gordonjcp/peacock - git.gjcp.net: Yes well okay then although it’s not an especially simple example. There are good examples for Distrho though.

I’m more than happy to chat about how to get it all working and what I’ve run into trying to get it all together, but I’m far easier to get in #ardour or #lad on IRC :wink:

1 Like

Thanks!

I downloaded these files in order to rebuild the same plugin under another name (it’s a first step).

But I am not very used to Python and waf is new for me.

I wonder what is the shortest and safest way to have and use waf on my laptop (debian trixie).

Can I have some advice, please?

Sadly it has been a long time since I have used WAF, but my memory is it wasn’t a huge bear, it did have some quirks but it wasn’t nearly as bad as scons that it replaced in that department. All that being said, for something as simple as that plugin, I would bet you could rebuild a build system for it with standard make files relatively quickly.

WAF and other similar build systems really come into their own when dealing with very complicated builds like Ardour.

 Seablade

For this plugin you really just need

gcc --shared -o reasonablesynth.so -fPIC `pkg-config --cflags lv2` rsynth.c lv2.c

Yet, for the whole thing you need a LV2 bundle a plugin-name.lv2 folder that contains the plugin binary, a manifest file and a plugin-description (both .ttl files).

–

If you are new to plugin dev and tempted to use some LLM assistance, I’d highly recommend to use FAUST. It has a huge library of DSP (filters, synths, reverbs…) and Dr. Julius Orion “Faust” Smith III poured all his knowledge into Claude lately. By indirection you can be certain that FAUST generated code is realtime safe, and you can directly generated LV2, VST3 etc from it. There is also an online IDE to do so: https://faustide.grame.fr/

It is even be a good idea if you don’t want AI assistance. Learning FAUST from scratch can be a bit mind bending, but there is a good online community too.

3 Likes

Gonna second this. I have some programming experience, but no DSP knowledge from an implementation standpoint, and yes FAUST is exactly my plan for if I go this route at all with LLMs.

Seablade

Thank, I compiled it under another name (ak-synth-1.so) after changing some paths in lv2.c

// #include <lv2/lv2plug.in/ns/lv2core/lv2.h>
#include <lv2/core/lv2.h>
// #include <lv2/lv2plug.in/ns/ext/atom/atom.h>
#include <lv2/atom/atom.h>
// #include <lv2/lv2plug.in/ns/ext/urid/urid.h>
#include <lv2/urid/urid.h>
// #include <lv2/lv2plug.in/ns/ext/midi/midi.h>
#include <lv2/midi/midi.h>

But is seems it generates a conflict with ReasonableSynth, through my files ak-synth-1.ttl and manifest.ttl : impossible to find ReasonableSynth if I put these two files in the folder /usr/lib/lv2/ak-synth-1.lv2/

And look the picture of its MIDI outputs : it is an input on the place of an output.

01

And it’s no sound for the moment. Is it please some advice for me?

root@k0:/usr/lib/x86_64-linux-gnu/pkgconfig# cat /usr/lib/lv2/ak-synth-1.lv2/manifest.ttl 
@prefix lv2:  <http://lv2plug.in/ns/lv2core#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<https://community.ardour.org/node/7596>
	a lv2:Plugin ;
	lv2:binary <ak-synth-1@LIB_EXT@>  ;
	rdfs:seeAlso <ak-synth-1.ttl> .
root@k0:/usr/lib/x86_64-linux-gnu/pkgconfig# cat /usr/lib/lv2/ak-synth-1.lv2/ak-synth-1.ttl 
@prefix atom:  <http://lv2plug.in/ns/ext/atom#> .
@prefix doap:  <http://usefulinc.com/ns/doap#> .
@prefix foaf:  <http://xmlns.com/foaf/0.1/> .
@prefix lv2:   <http://lv2plug.in/ns/lv2core#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix pg:    <http://lv2plug.in/ns/ext/port-groups#> .
@prefix urid:  <http://lv2plug.in/ns/ext/urid#> .

<http://ardour.org/credits.html>
	a foaf:Person ;
	foaf:name "Ardour Community" ;
	foaf:homepage <http://ardour.org/> .

<https://community.ardour.org/node/7596>
	a lv2:Plugin, lv2:InstrumentPlugin, doap:Project;
	doap:license <http://usefulinc.com/doap/licenses/gpl> ;
	doap:maintainer <http://ardour.org/credits.html> ;
	doap:name "ak synth 1";
	lv2:optionalFeature lv2:hardRTCapable ;
	lv2:requiredFeature urid:map ;
	rdfs:comment """A simple synthesizer with no controls at all but a reasonable sound instead. Note that this synth does not respond to any Control or Program Messages. Its main purpose is to act as sensible default on new installations until other plugins are installed.""" ;
	lv2:port
	[
		a atom:AtomPort ,
			lv2:InputPort ;
		atom:bufferType atom:Sequence ;
		atom:supports <http://lv2plug.in/ns/ext/midi#MidiEvent> ;
		lv2:index 0 ;
		lv2:symbol "MidiIn" ;
		lv2:name "MIDI Input" ;
	],
	[
		a lv2:AudioPort ,
			lv2:OutputPort ;
		lv2:index 1 ;
		lv2:symbol "outL" ;
		lv2:name "Left output" ;
		lv2:designation pg:left ;
	],
	[
		a lv2:AudioPort ,
			lv2:OutputPort ;
		lv2:index 2 ;
		lv2:symbol "outR" ;
		lv2:name "Right Output" ;
		lv2:designation pg:right ;
	]
	.

Have you changed the URI in lv2.c to match to what you set it to in the .ttl files?

You cannot use https://community.ardour.org/node/7596 which is the Unique [Resource] Identifier for the plugin that comes with Ardour.

1 Like

Thanks, I changed this to:

#define RSY_URI "ak-synth-1"
or
<ak-synth-1>

But now I have a new problem when I insert my plugin:
lilv_plugin_instantiate(): error: No plugin <file:///usr/lib/lv2/ak-synth-1.lv2/ak-synth-1> in <file:///usr/lib/lv2/ak-synth-1.lv2/ak-synth-1.so>

I looked the code but have no idea what to do, can I have a new advice?

Did you rename reasonablesynth.ttl to ak-synth-1.ttl ?

You obviously need to change both the manifest.ttl and ak-synth-1.ttl to contain <ak-synth-1>

And you need to modify

lv2:binary <reasonablesynth@LIB_EXT@>  ;
rdfs:seeAlso <reasonablesynth.ttl>

in manifest.ttl to

 lv2:binary <ak-synth-1.so>  ;
 rdfs:seeAlso <ak-synth-1.ttl>

and make sure you have both ttl-files in /usr/lib/lv2/ak-synth-1.lv2/

After actually having tested this myself it seems like you can’t have just a name in the RSY_URI and the other instances.
If you prefix it with urn: you should be able to run it. I.e.
#define RSY_URI "urn:ak-synth-1" and <urn:ak-synth-1> in ak-synth-1.ttl , manifest.ttl and lv2.c

2 Likes

Yes, the URI URI needs to be a valid URI. e.g. urn:ak-synth-1 as peder suggested.

1 Like

Thanks, that works!

I am now trying to add a first input control on the synth window. So, I added, to ak-synth-1.ttl, in lv2:port:

[
	a lv2:InputPort ,
		lv2:ControlPort ;
	lv2:index 3 ;
	lv2:symbol "param1" ;
	lv2:name "Parametre 1" ;
	lv2:default 440.0 ;
	lv2:minimum 20.0 ;
	lv2:maximum 20000.0 ;
]

That works; I have a slider in the synth window, but how can I please access to my new parameter param1?

If I understand correctly, I have to change, in lv2.c, the switch ((PortIndex)port) part, but how can I do that? And how to access this value in rsynth.c? Can I have some advice?

And did I choose the right method?

music@k0:~/step-1/01$ cat ak-synth-1.ttl 
@prefix atom:  <http://lv2plug.in/ns/ext/atom#> .
@prefix doap:  <http://usefulinc.com/ns/doap#> .
@prefix foaf:  <http://xmlns.com/foaf/0.1/> .
@prefix lv2:   <http://lv2plug.in/ns/lv2core#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix pg:    <http://lv2plug.in/ns/ext/port-groups#> .
@prefix urid:  <http://lv2plug.in/ns/ext/urid#> .

<http://ardour.org/credits.html>
	a foaf:Person ;
	foaf:name "Ardour Community" ;
	foaf:homepage <http://ardour.org/> .

<urn:ak-synth-1>
	a lv2:Plugin, lv2:InstrumentPlugin, doap:Project;
	doap:license <http://usefulinc.com/doap/licenses/gpl> ;
	doap:maintainer <http://ardour.org/credits.html> ;
	doap:name "ak synth 1";
	lv2:optionalFeature lv2:hardRTCapable ;
	lv2:requiredFeature urid:map ;
	rdfs:comment """A simple synthesizer with no controls at all but a reasonable sound instead. Note that this synth does not respond to any Control or Program Messages. Its main purpose is to act as sensible default on new installations until other plugins are installed.""" ;
	lv2:port
	[
		a atom:AtomPort ,
			lv2:InputPort ;
		atom:bufferType atom:Sequence ;
		atom:supports <http://lv2plug.in/ns/ext/midi#MidiEvent> ;
		lv2:index 0 ;
		lv2:symbol "MidiIn" ;
		lv2:name "MIDI Input" ;
	],
	[
		a lv2:AudioPort ,
			lv2:OutputPort ;
		lv2:index 1 ;
		lv2:symbol "outL" ;
		lv2:name "Left output" ;
		lv2:designation pg:left ;
	],
	[
		a lv2:AudioPort ,
			lv2:OutputPort ;
		lv2:index 2 ;
		lv2:symbol "outR" ;
		lv2:name "Right Output" ;
		lv2:designation pg:right ;
	],
	[
		a lv2:InputPort ,
			lv2:ControlPort ;
		lv2:index 3 ;
		lv2:symbol "param1" ;
		lv2:name "Parametre 1" ;
		lv2:default 440.0 ;
		lv2:minimum 20.0 ;
		lv2:maximum 20000.0 ;
	]
	.
music@k0:~/step-1/01$ gcc --shared -o ak-synth-1.so -fPIC `pkg-config --cflags lv2` rsynth.c lv2.c

I found what I need for my param1; all ok here :slight_smile: