• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

examples/H07-May-2022-4,3243,407

.gitignoreH A D18-Jan-201859 87

COPYINGH A D18-Jan-201834.3 KiB675553

COPYING.LESSERH A D18-Jan-20187.5 KiB166128

MakefileH A D03-May-202210.3 KiB313176

README.mdH A D18-Jan-201845.7 KiB923740

config.guessH A D18-Jan-201845 KiB1,5811,358

faust2lv2H A D18-Jan-201813.5 KiB379292

lv2-manifest-static-template.ttlH A D18-Jan-20181.1 KiB3325

lv2-manifest-template.ttlH A D18-Jan-20181.1 KiB3224

lv2.cppH A D18-Jan-201861.6 KiB2,0811,653

lv2qtgui.hH A D18-Jan-20181.2 KiB6345

lv2ui-manifest-static-template.ttlH A D18-Jan-20181.2 KiB3829

lv2ui-manifest-template.ttlH A D18-Jan-20181.2 KiB3728

lv2ui.cppH A D18-Jan-201856.3 KiB1,9671,524

README.md

1
2faust-lv2
3=========
4
5Albert Gräf <aggraef@gmail.com>, 2017-01-01
6
7This project provides an [LV2][] plugin architecture for the [Faust][]
8programming language. The package contains the Faust architecture and
9templates for the needed LV2 manifest (ttl) files, a collection of sample
10plugins written in Faust, and a generic GNU Makefile as well as a shell script
11to compile plugins using the architecture.
12
13[Faust]: http://faust.grame.fr/
14[LV2]: http://lv2plug.in/
15
16faust-lv2 is free and open source software. The latest source can be found in
17the git repository at https://bitbucket.org/agraef/faust-lv2. In the downloads
18section of this site you can also find released tarballs along with my
19faust-lv2 paper for the 2013 Linux Audio Conference. Please use the issue
20tracker for bug reports and requests. You're also invited to join one of
21Grame's [Faust mailing lists][] to discuss faust-lv2 or Faust in general.
22
23[Faust online compiler]: http://faust.grame.fr/onlinecompiler/
24[Faust mailing lists]: http://sourceforge.net/p/faudiostream/mailman
25
26**Note:** Various versions of the faust-lv2 architecture have been included in
27the official Faust distribution since Faust 0.9.58. If you want to make sure
28that you have the latest faust-lv2 installed, you can also add the
29architecture and the faust2lv2 compilation script to an existing Faust
30installation by running `make install-faust` from this package, see
31"Installation" below for details. Moreover, faust-lv2 is also available as a
32target architecture in the [Faust online compiler][], so you can compile your
33Faust dsps as LV2 plugins even without installing any additional
34software. Please head over to the [Faust][] website to learn more.
35
36Copying
37=======
38
39Copyright (c) 2012-2017 by Albert Gräf <aggraef@gmail.com>
40Copyright (c) 2015-2016 of the Faust/Qt support by Roman Svidler
41
42This document is available under the GNU [FDL][] (Free Documentation License).
43
44faust-lv2 is distributed under the GNU [LGPL][] (Lesser General Public
45License) v3+. Please see the included COPYING and COPYING.LESSER files for
46details.
47
48[FDL]: http://www.gnu.org/copyleft/fdl.html
49[LGPL]: http://www.gnu.org/copyleft/lgpl.html
50
51Overview
52========
53
54The aim of this project is to provide a full-featured LV2 implementation of
55Faust plugins which supports both effect and instrument plugins. [Faust][] is
56Grame's functional signal processing language. [LV2][] is the new open-source
57audio and MIDI plugin standard for Linux and other Unix-like systems,
58successor of the venerable LADSPA standard.
59
60faust-lv2 is the first (and, at the time of this writing, still the only) LV2
61implementation for Faust. It was also the first Faust architecture to provide
62full support for both effect processors and polyphonic synths with automatic
63voice allocation, which makes it really easy to create great working LV2
64plugins ready to be used in popular LV2 hosts such as Ardour and Qtractor.
65
66faust-lv2 has also been ported to Steinberg's VST plugin standard which, at
67the time of this writing, is still the prevalent cross-platform plugin
68architecture for commercial DAW software. Please check the author's
69[faust-vst] project for details. Both faust-lv2 and faust-vst provide exactly
70the same set of features, so a simple recompile suffices to port your plugins
71from LV2 to VST and vice versa. This makes it possible to use the same Faust
72plugins with a variety of both open-source and commercial DAW software on both
73Linux and Mac OS X. (Windows support is still on the TODO list at this time,
74but porting should be a piece of cake and contributions are welcome!)
75
76[faust-vst]: https://bitbucket.org/agraef/faust-vst
77
78The main items in the faust-lv2 package are the Faust architecture lv2.cpp and
79the faust2lv2 compilation script which are used to compile LV2 plugins with
80the Faust compiler. Custom Faust-generated Qt GUIs are implemented by the
81lv2ui.cpp architecture and the accompanying lv2qtgui.h header file. All these
82items should be included in recent Faust versions, but you can also install
83them from the faust-lv2 package if necessary. The package also includes some
84sample Faust dsps, as well as a generic GNU Makefile showing how to automatize
85the build process.
86
87Supported Hosts
88---------------
89
90LV2 is fully supported by the popular open-source DAWs [Ardour][] (on both
91Linux and Mac OS X) and [Qtractor][] (Linux only). LV2 plugins can also be run
92in Miller Puckette's [Pd][] through the author's [lv2plugin~][] external.
93Stand-alone hosts such as [Jalv][] and [Carla][] can be used to interface with
94other software which doesn't support LV2 out of the box. Note that Carla,
95which runs on both Linux and Mac OS X, is also available as a VST plugin which
96can be used to host LV2 plugins in commercial DAWs which only support VST
97plugins natively.
98
99[Ardour]: http://ardour.org/
100[Qtractor]: http://qtractor.sourceforge.net/
101[Pd]: http://puredata.info/
102[Carla]: http://kxstudio.linuxaudio.org/Applications:Carla
103[Jalv]: http://drobilla.net/software/jalv/
104[lv2plugin~]: https://bitbucket.org/agraef/pd-lv2plugin
105
106The current release has been tested and is known to work with [Ardour][],
107[Qtractor][], [Carla][], [Jalv][] and [lv2plugin~][]. We generally recommend
108using hosts based on Dave Robillard's LV2 host library [lilv][], which should
109be readily available in most Linux distributions. All plugin hosts mentioned
110above (except Carla) will work with this library if it is available on your
111system.
112
113[lilv]: http://drobilla.net/software/lilv/
114
115Features
116--------
117
118All plugins created with lv2.cpp provide the following basic features:
119
120* Audio inputs and outputs of the Faust dsp are made available as LV2 audio
121  input and output ports.
122
123* Faust controls are made available as LV2 control ports with the proper
124  label, initial value, range and (if supported by the host) step size. Both
125  "active" (input) and "passive" (output) Faust controls are supported and
126  mapped to the corresponding LV2 input and output ports. (The control outputs
127  a.k.a. passive Faust controls seem to work with most LV2 hosts nowadays;
128  [Qtractor][] is the only notable exception.)
129
130* If the dsp defines any controls with corresponding MIDI mappings
131  (`midi:ctrl` attributes in the Faust source), the plugin also provides an
132  LV2 MIDI input port and interprets incoming MIDI controller messages
133  accordingly. This feature can also be disabled by setting `FAUST_MIDICC=0`
134  when compiling the C++ source; just uncomment the corresponding line in the
135  Makefile, or invoke faust2lv2 with the `-nomidicc` option. (Disabling this
136  option *may* occasionally be useful if the MIDI cc processing gets in the
137  way of a host's own MIDI mapping and automation facilities. But normally you
138  shouldn't have to worry about this, since it is always up to the LV2 host to
139  decide whether it sends MIDI controller data to the plugin or not.) Also
140  note that for instrument plugins certain MIDI controllers have a predefined
141  meaning and hence cannot be assigned using the `midi:ctrl` attribute, see
142  below.
143
144* Plugin name, version, description, author and license information provided
145  as meta data in the Faust source is translated to the corresponding fields
146  in the LV2 manifest of the plugin. This can also be disabled with the
147  corresponding macro (`FAUST_META=0`) or with faust2lv2's `-nometa` option,
148  if you'd rather like to provide this information yourself by editing the
149  static manifest.
150
151* The global `nvoices` meta data key can be used to indicate that the plugin
152  is actually an instrument (synthesizer) rather than an audio (effect)
153  plugin. It also specifies the maximum number of "voices" (i.e., the amount
154  of polyphony) of the synth. See "Instrument Plugins" below for details.
155
156The architecture also recognizes the following Faust control meta data and
157sets up the LV2 control port properties accordingly. Note that some of these
158properties rely on extensions which may not be supported by all LV2 hosts.
159Also note that all of these can be disabled with `FAUST_META=0` or the
160`-nometa` option. Please refer to the LV2 documentation for a closer
161description of the corresponding LV2 properties.
162
163*   The `unit` attribute (e.g., `[unit:Hz]`) in the Faust source is
164    translated to a corresponding LV2 `unit` attribute. The host may then
165    display this information in its GUI rendering of the plugin controls.
166
167*   LV2 scale points can be set with the `lv2:scalePoint` (or `lv2:scalepoint`)
168    attribute on the Faust side. The value of this attribute in the Faust
169    source takes the form of a list of pairs of descriptive labels and
170    corresponding values, for instance:
171
172        toggle = button("trigger [lv2:scalepoint on 1 off 0]");
173
174    The host may then display the given scale points with descriptive labels
175    in its GUI, or in the form of a dropdown list, menu, radio control or some
176    similar widget.
177
178*   The `lv2:integer` attribute in the Faust source is translated to the
179    `lv2:integer` LV2 port property, so that the control may be shown as an
180    integer-only field in the host's GUI.
181
182*   The `lv2:reportsLatency` attribute in the Faust source is translated to
183    the `lv2:reportsLatency` LV2 port property, also adding the
184    `lv2:designation lv2:latency` property to the port, so that the control
185    may be used by the host to compensate for the latency of a plugin (if the
186    host supports this). Note that this only works with passive (output) Faust
187    controls, and that it is the responsibility of the programmer to specify
188    the proper values for the control.
189
190*   The `lv2:hidden` or `lv2:notOnGUI` attribute maps to the LV2 `notOnGUI`
191    port property, so that hosts honoring this property may suppress the
192    display of this control in their GUI.
193
194GUI Support
195-----------
196
197Many LV2 hosts offer an option to display a generic GUI for the control
198elements of an LV2 plugin, which will also work with all plugins created with
199the lv2.cpp architecture. [Ardour][], [Carla][] and [Qtractor][] all do a
200reasonably good job at this. The hierarchical layout of GUI controls
201prescribed by the Faust source is lost in the generic plugin GUIs, but the GUI
202elements should still be shown in the right order at least. Moreover, as
203described above, faust-lv2 supports a few LV2 GUI hints as Faust meta data,
204which can be used to "style" GUI elements in various ways (such as proper
205rendering of integer and radio- or menu-style controls). This will make the
206generic GUIs work pretty well in most host applications.
207
208However, as of version 1.0, faust-lv2 also includes experimental support for
209custom plugin GUIs, which are generated using the generic Qt GUI support
210implemented by the Faust library (faustqt.h et al, included in recent Faust
211versions). These *will* respect the hierarchical group layout of GUI controls
212prescribed by the Faust source, as well as various `style` hints in the
213control meta data (please check the *Faust Quick Reference* for details on
214this). The custom Qt GUIs are compiled as separate modules created from the
215lv2ui.cpp architecture. They also employ special manifest templates which
216include the required data describing the plugin GUI and linking it to its
217plugin.
218
219To improve cross-platform compatibility, custom GUIs are *not* built by
220default in the present version, but it's easy to enable this by using the
221`gui=1` setting with the Makefile or by invoking the faust2lv2 script with the
222`-gui` option. In addition, you may have to pick the desired Qt version by
223specifying the corresponding qmake executable, using either the `qmake`
224variable of the Makefile, or by setting the `QMAKE` environment variable with
225the faust2lv2 script. (Please check the "Installation" and "Using the Build
226Script" sections below for examples.)
227
228Custom GUIs also optionally offer the same kind of built-in OSC and HTTP
229support as the stand-alone Faust architectures, which allows a plugin to be
230controlled via the OSC (Open Sound Control) and HTTP protocols (i.e., through
231an OSC device or a web browser). This is enabled with the appropriate options
232in the Makefile and the faust2lv2 script. (Note that the OSC and web servers
233of a plugin are currently tied to its Qt GUI and will thus only be available
234as long as the GUI remains open in the host application.) Please check the
235sections "OSC support" and "HTTP support" in the *Faust Quick Reference*
236manual for details.
237
238The custom GUIs require an LV2 host which supports the [LV2 UI extension][]
239and is capable of managing Qt4 or Qt5 plugin GUIs. At the time of this
240writing, Ardour still requires Qt4, while recent versions of Qtractor support
241Qt5. Carla will work with either Qt version. The custom Faust GUIs work fine
242with all of these on Linux. On Mac OS X, only Ardour and Carla support LV2 at
243present, and neither seem to work with the custom Faust GUIs yet, so you'll
244have to go with the generic host-generated GUIs for now.
245
246[LV2 UI extension]: http://lv2plug.in/ns/extensions/ui/
247
248Instrument Plugins
249------------------
250
251The lv2.cpp architecture can also be used to create instrument plugins, which
252provide the necessary logic to drive a polyphonic synth with automatic voice
253allocation. The easiest way to specify this is to include the following kind
254of meta data in the Faust source:
255
256    declare nvoices "16";
257
258The given number specifies the desired maximum number of voices. (This value
259can also be configured manually by setting the `NVOICES` macro when compiling
260the C++ source of the plugin, but usually it will be much more convenient to
261have this information in the dsp source.) The plugin will manage that many
262instances of the Faust dsp. The *actual* number of voices can then be changed
263dynamically from 1 to the `nvoices` value with a special `Polyphony` control
264provided by the plugin. In the current implementation, this control defaults
265to half the total number of voices available.
266
267**NOTE:** To make this work, the Faust dsp must be able to function as a
268monophonic synth which provides controls labeled `freq`, `gain` and `gate` to
269set the pitch (frequency in Hz), velocity (normalized to the 0-1 range) and
270gate (0/1 signal used to trigger the envelop) of a note, respectively. Voice
271allocation is then handled automatically by the architecture. The controls can
272be under any path in the dsp's group hierachy. But note that only a single
273instance of each of these control variables will be used to control each
274voice, so it's best to have all of these in a single group (often the toplevel
275group of a dsp) in order to avoid confusion. Please check the Faust sources in
276the examples folder for sample instruments (.dsp files containing the
277`nvoices` declaration) which show how to implement such synth units in Faust;
278examples/organ.dsp is a good one for starters since it is quite simple.
279
280Instrument plugins always provide a MIDI input port and interpret incoming
281MIDI note and pitch bend messages, as well as a number of General MIDI
282standard controller and sysex messages, as detailed below. By default, the
283synth units have a pitch bend range of +/- 2 semitones (General MIDI default)
284and are tuned in equal temperament with A4 at 440 Hz. These defaults can be
285adjusted as needed using some of the controller and sysex messages described
286below.
287
288* The "all notes off" (123) and "all sounds off" (120) MIDI controllers stop
289  sounding notes on the corresponding MIDI channel.
290
291* The "all controllers off" (121) MIDI controller resets the current RPN and
292  data entry controllers on the corresponding MIDI channel (see below).
293
294* The registered parameters (RPNs) 0 (pitch bend range), 1 (channel fine
295  tuning) and 2 (channel coarse tuning) can be used to set the pitch bend
296  range and fine/coarse master tuning on the corresponding MIDI channel in the
297  usual way, employing a combination of the RPN (101, 100) and data entry
298  controller pairs (6 and 38, as well as 96 and 97). Please check Jeff Glatt's
299  [MIDI specification][] for details.
300
301* Universal realtime and non-realtime scale/octave tuning messages following
302  the [MIDI Tuning Standard][] (MTS) can be used to set the synth to a given
303  octave-based tuning specified as cent offsets relative to equal temperament,
304  which is repeated in every octave of the MIDI note range 0..127. Please
305  check "MTS Support" below for further details.
306
307[MIDI specification]: http://www.blitter.com/~russtopia/MIDI/~jglatt/tech/midispec.htm
308[MIDI Tuning Standard]: http://www.midi.org/techspecs/midituning.php
309
310These special features may seem a little arcane, but they are utilized by some
311DAW and MIDI player software (especially the "all notes off" and "all sounds
312off" controllers). Also, the tuning capabilities come in handy when
313experimenting with historical temperaments and microtonality.
314
315MTS Support
316-----------
317
318The general format of the supported MTS messages is as follows (using
319hexadecimal notation):
320
321    f0 7f/7e <device-id> 08 08/09 bb bb bb tt ... tt f7
322
323Note that the `f0 7f` and `f0 7e` headers are used to denote a universal
324realtime and non-realtime sysex message, respectively, and the final `f7` byte
325terminates the message. Both types of messages will take effect immediately,
326but the realtime form will also change the frequencies of already sounding
327notes. The device id can be any 7-bit value from `00` to `7f` and will be
328ignored, so that the unit will always respond to these messages, no matter
329which device id is specified. The following `08` id denotes an MTS message,
330followed either by the `08` subid to denote 1-byte, or the `09` subid to
331denote 2-byte encoding (see below).
332
333The lv2.cpp architecture keeps track of separate tunings for different MIDI
334channels. The three `bb` bytes together specify the bitmask of MIDI channels
335the message applies to, most significant byte first; the bitmask `03 7f 7f`
336thus sets the tuning for all MIDI channels, while the bitmask `00 00 01` only
337affects the tuning of the first MIDI channel. (Note that bits 3..7 of the most
338significant byte aren't used right now, but are reserved by MTS for future
339use, so you shouldn't set these unless you know what you're doing.)
340
341The `tt` bytes specify the tuning itself, as a sequence of 12 tuning offsets
342for the notes `C`, `C#`, `D`, etc., thru `B`. In the one-byte encoding (subid
343`08`), each tuning offset is a 7 bit value in the range `00..7f`, with `00`,
344`40` and `7f` denoting -64, 0 and +63 cents, respectively. Thus equal
345temperament is specified using twelve `40` bytes, and a quarter comma meantone
346tuning could be denoted, e.g., as `4a 32 43 55 3d 4e 36 47 2f 40 51 39`. The
347two-byte encoding (subid `09`) works in a similar fashion, but provides both
348an extended range and better resolution. Here each tuning offset is specified
349as a 14 bit value encoded as two data bytes (most significant byte first),
350mapping the range 0..16384 to -100..+100 cents with the center value 8192
351(`40 00`) denoting 0 cents. Please check the MMA's [MIDI Tuning Standard][]
352document for details.
353
354Tuning Control
355--------------
356
357Note that in order to utilize MTS sysex messages, your LV2 host needs to be
358able to receive and/or store sysex messages and pass them on to LV2 plugins.
359Not all LV2 hosts implement this feature at this time, so the lv2.cpp
360architecture also provides an alternative way to select a tuning through a
361special `Tuning` control which allows you to choose a tuning from a collection
362of MTS sysex files determined at load time. (This feature can also be disabled
363with the `-DFAUST_MTS=0` option in the Makefile, or the `-notuning` option of
364the faust2lv2 script.)
365
366You then just need to drop some MTS sysex (.syx) files into the
367~/.faust/tuning folder. If this folder is present and contains some MTS sysex
368files in the right format, then the `Tuning` control becomes available on all
369faust-lv2 instrument plugins which have been compiled with this option. The
370control usually takes the form of a slider which shows the current tuning
371number along with the basename of the corresponding sysex file. The tunings
372are numbered in alphabetic order starting at 1; a slider value of 0 denotes
373the default tuning (equal temperament). Changing the slider value in the
374control GUI adjusts the tuning in real-time.
375
376**NOTE:** Instead of ~/.faust you can also name a different "home" folder by
377setting the FAUST_HOME environment variable accordingly. In addition, on Mac
378OS X the ~/Library/Faust/Tuning folder will also be searched for tunings if
379~/.faust/tuning doesn't exist or contains no valid sysex files.
380
381This controller-based method for changing the tuning will of course become
382rather unwieldy if you need to work with a large number of different tunings.
383On the other hand, it also offers the advantage that the tuning becomes an
384automatable parameter which can be recorded and played back by hosts which
385provide control automation (your favorite DAW probably does). The amount of
386data in the octave-based tunings is rather small and the data is stored in
387main memory at load time. Thus changing tunings is not an expensive operation,
388and perfectly feasible also in real-time operation.
389
390Another gotcha is that the tuning control will work best with dynamic
391manifests (see below), in which case the tuning control is configured
392dynamically at load time. Otherwise the control will be configured at compile
393time, i.e., when the plugin's static manifest is created, so a recompile of
394all instrument plugins will be in order any time the contents of the tuning
395folder changes. (In this case it's probably better to employ the
396`-DFAUST_MTS=0` option to completely disable the tuning control when compiling
397the plugins.)
398
399Dynamic Manifests
400-----------------
401
402Plugins created with lv2.cpp also support the [dynamic manifest extension][],
403so that all requisite information about the plugin's name, author, ports,
404etc. can be included in the plugin module itself. To provide better
405compatibility with current LV2 hosts, which often don't have this extension
406enabled, this feature isn't used by default in the provided Makefile. But you
407can select it by uncommenting the corresponding option in the Makefile, see
408the corresponding remarks under "Static and Dynamic Manifests" below for
409details.
410
411Build Requirements
412------------------
413
414To compile this package (or any Faust source using the included LV2
415architecture), you'll need [GNU make][], the [GNU C++ compiler][] and the
416[Boost][] headers, as well as recent versions of the [Faust][] compiler and
417[LV2][]. You'll also need [Qt][] version 4 or 5 to build the custom plugin
418GUIs (this is optional).
419
420[GNU C++ compiler]: http://gcc.gnu.org
421[GNU make]: http://www.gnu.org/software/make
422[Boost]: http://www.boost.org
423[Qt]: http://www.qt.io
424
425Note that the examples still use the "old" a.k.a. "legacy" Faust library
426modules, so they should work out of the box with both "old" Faust versions (up
427to 0.9.85) and later ones featuring the "new" Faust library (anything after
4280.9.85, including current git sources).
429
430Installation
431============
432
433Please review the build requirements above and check that you have all the
434necessary third-party software installed. To compile the sample Faust plugins,
435simply run `make` in the source directory. The compiled LV2 plugins will end
436up in the lv2/faust.lv2 directory, ready to be run with your favourite LV2
437host.
438
439By default, `make` will build plugins *without* custom plugin GUIs. Use `make
440gui=1` if you want these. This requires [Qt][], and you may also have to set
441the path to the qmake executable of the Qt version that you want to use. Qt5
442is usually the default on recent Linux systems. If you want to use Qt4 instead
443(this is required to make the GUIs work with Ardour, for instance) then
444something like the following should do the trick:
445
446    make gui=1 qmake=/usr/lib/qt4/bin/qmake
447
448You can also run `make install` to install the the sample plugins in the
449system-wide LV2 directory (/usr/local/lib/lv2 by default). You need to do this
450as root, e.g., via `sudo`, if you're installing into system directories.
451Package maintainers may want to add something like `DESTDIR=/buildroot` and
452`prefix=/usr` to the `make install` command to install into a staging
453directory and change the installation prefix.
454
455**NOTE:** The installation step is optional. If you just want to try the
456plugins with your favourite LV2 host after compilation, it should be enough to
457set your LV2_PATH environment variable (or configure your LV2 host) so that
458the host includes the generated faust-lv2/lv2 directory in its LV2 plugin
459search path.
460
461There are a number of compilation options which can be changed by setting the
462appropriate variables in the Makefile, please check the Makefile for
463details. In particular, the installation prefix can be changed with the
464`prefix` variable, and you can also use the `lv2libdir` variable to set the
465LV2 installation path in a direct fashion. In addition, you can change the
466default name `faust.lv2` of the plugin directory with the `bundledir`
467variable. Moreover, it is possible to build and install the plugins in
468separate bundles (one per plugin) by running make with the following targets:
469
470    make split-bundles
471    make install-split
472
473The plugins will then be found in separate directories named after the plugin
474(`amp.lv2` for the `amp.dsp` plugin etc.) so that you can also cherry-pick
475the plugins that you want.
476
477Static and Dynamic Manifests
478----------------------------
479
480By default, faust-lv2 uses static "manifests" (ttl files generated at compile
481time, cf. "The Manifest" below) for the plugins; this offers the best
482compatibility with existing LV2 hosts.
483
484[dynamic manifest extension]: http://lv2plug.in/ns/ext/dynmanifest/
485
486It is also possible to compile the plugins for LV2's [dynamic manifest
487extension][] which allows most of the manifest to be included in the plugin
488module itself. This is selected by uncommenting the corresponding line reading
489`dyn-manifests = 1` in the Makefile, or by adding this setting to the make
490command:
491
492    make dyn-manifests=1
493
494This option considerably speeds up the build process, and is also recommended
495when making use of dynamic features such as the MTS tuning control. But it
496requires that the LV2 host supports the dynamic manifest extension. Many LV2
497hosts do *not* support this out of the box, hence this isn't the default right
498now. If you want to go that route, we recommend using hosts based on the
499[lilv][] library, such as Ardour and Qtractor. You'll also have to make sure
500that lilv was configured with `--dyn-manifest` in order to enable the dynamic
501manifest extension.
502
503Installing the Build Script and the Architectures
504-------------------------------------------------
505
506Finally, to compile your own plugins you may want to have the latest
507architecture files and faust2lv2 build script installed. If you have a recent
508Faust version from git on your system, then most likely you already have
509these. Otherwise, you can add them to your existing Faust installation with:
510
511    make install-faust
512
513(You may want to specify the `prefix` variable to point the Makefile to the
514Faust installation prefix, usually either /usr or /usr/local. But this isn't
515mandatory. The faust2lv2 script will try to locate Faust and the faust-lv2
516architecture files in some common locations, and you can also set the
517`FAUSTINC` and `FAUSTLIB` environment variables to point faust2lv2 to the
518proper locations if needed.)
519
520The faust2lv2 script doesn't offer all the options you have when using the
521Makefile or compiling plugins manually, but it covers most common use cases
522and in any case it's currently the easiest way to create a self-contained LV2
523bundle from a single Faust source. Please check the following section for
524detailed usage instructions.
525
526Using the Build Script
527======================
528
529The distribution includes the faust2lv2 script which runs the Faust compiler
530for you and handles all steps necessary to create a working LV2 bundle in an
531automatic fashion. You can create an LV2 bundle for a plugin in the Faust
532source file myplugin.dsp simply as follows:
533
534    faust2lv2 myplugin.dsp
535
536If the plugin is supposed to become an instrument but the dsp source doesn't
537contain the `nvoices` declaration (or if you want to override the value given
538there), just add the `-nvoices` option to the command line, e.g.:
539
540    faust2lv2 -nvoices 16 myplugin.dsp
541
542(Conversely, `-nvoices 0` can be used to turn an instrument into an ordinary
543effect, so that you can run the synth in a manual fashion by explicitly
544operating the `freq`, `gain` and `gate` controls through the GUI or automation
545facilities provided by the LV2 host.)
546
547The resulting LV2 bundle myplugin.lv2 will be created in the current working
548directory, ready to be moved to your LV2 plugin directory. The script also
549recognizes a few additional options which let you configure some aspects of
550the resulting LV2 bundle. Please run `faust2lv2 -h` or `faust2lv2 -help` for a
551brief summary of all supported options. Currently the most important of these
552are:
553
554* `-dyn-manifest` tells the script to create a plugin with dynamic manifests;
555  the default is to use static manifests. See "Static and Dynamic Manifests"
556  above for details on this option and when you may want to use it.
557
558* `-gui` builds a custom GUI along with the plugin and also adjusts the
559  manifest accordingly. This requires Qt version 4 or 5 (you'll typically use
560  Qt4 for Ardour, Qt5 for the other hosts). By default, Qt5 will be preferred
561  if it is found; the `-qt4` or `-qt5` option can be used to override the
562  default choice (this also implies `-gui`). The script tries to locate
563  `qmake` in some common locations. You can also set the path to the `qmake`
564  executable explicitly using the `QMAKE` environment variable if this doesn't
565  work.
566
567* The `-gui` option can also be combined with the `-osc`, `-httpd` and
568  `-qrcode` options to add support for the built-in OSC and HTTP interfaces,
569  as described in the *Faust Quick Reference*.
570
571* `-uri-prefix URI` sets the prefix of the plugin URI to the given option
572  value. The plugin URI is used by LV2 plugin hosts to uniquely identify a
573  plugin, see the LV2 documentation or "Compiling The C++ Source" below for
574  details.
575
576For instance, the following options enable dynamic manifests and set the URI
577prefix of the compiled plugin:
578
579    faust2lv2 -dyn-manifest -uri-prefix "http://somewhere.org/plugins" \
580      myplugin.dsp
581
582And here is how you invoke faust2lv2 in order to add a custom GUI:
583
584    faust2lv2 -gui myplugin.dsp
585
586The script will look for a suitable `qmake` executable in some common
587locations. Exactly which `qmake` will be chosen is displayed as the default
588value of the `QMAKE` environment variable if you run `faust2lv2 -h`. If
589`qmake` cannot be found then you'll have to set this variable accordingly,
590e.g.:
591
592    QMAKE=/usr/lib/qt4/bin/qmake faust2lv2 -gui myplugin.dsp
593
594When using the `-gui` option, you may also want to add `-osc` and/or `-httpd`
595for Faust's built-in OSC and HTTP support:
596
597    faust2lv2 -gui -osc -httpd myplugin.dsp
598
599This will let you control the plugin with OSC devices and/or through a web
600browser, as described in the *Faust Quick Reference* manual. The `-httpd`
601option can also be combined with `-qrcode` to have the plugin GUI pop up a
602window with the plugin's URL and the corresponding QR code which is
603convenient, e.g., to open the plugin's web interface on your smartphone. Note
604that in the current implementation each plugin instance gets its own
605dynamically assigned URL, which is active only as long as the plugin GUI is
606open. The same also holds for the OSC port assigned when using the `-osc`
607option to compile a plugin. Please check the corresponding sections of the
608*Faust Quick Reference* manual for details.
609
610Please note that the faust2lv2 script only lets you create an individual
611plugin bundle from a single Faust source at present. If that is all you need
612then you can stop reading now. But if you want to create plugin libraries as
613single bundles or if you need more control over the build process then you'll
614have to use the provided Makefile or compile the plugins manually. To these
615ends, the next section breaks down the compilation process into different
616steps and discusses each of these in turn. (Exactly the same steps are also
617invoked automatically in the Makefile and the faust2lv2 script.)
618
619Using the LV2 Architecture in your own Faust Programs
620=====================================================
621
622The options you have to build LV2 plugins from your own Faust sources are the
623following, from easiest to hardest:
624
625* Use the [Faust online compiler][]. Dead-easy. You don't even need to install
626  Faust, just grab the compiled plugin and run with it. You need a working
627  Internet connection, however, and the online compiler needs to be up and
628  running.
629
630* Use the faust2lv2 script. See "Using the Build Script" above. Basic usage is
631  very easy, just run `faust2lv2 myplugin.dsp` and drop the resulting
632  myplugin.lv2 folder into your LV2 plugin directory. (The same script is also
633  used by the [Faust online compiler][].)
634
635* Drop your Faust sources into the examples folder and rerun `make` (or `make
636  split-bundles`). Then move the resulting faust.lv2 (or myplugin.lv2) folder
637  into your LV2 plugin directory.
638
639* Create your own build system based on the generic Makefile. This may require
640  some hand-editing of the variables in the Makefile (URI prefixes and such),
641  but is usually quite straightforward. You might want to do this if you'd
642  like to distribute your own plugin bundle in source form.
643
644* Roll your own build system or script. This is not for the faint of heart and
645  requires some detailed knowledge about the build process (which will be
646  provided in the remainder of this section, starting at "Compiling the Faust
647  Source").
648
649Compiling the Faust Source
650--------------------------
651
652Basic usage of the architecture file is as with any other Faust architecture,
653i.e., you simply specify the architecture with Faust's `-a` option. E.g.:
654
655    faust -a lv2.cpp -cn myplugin myplugin.dsp -o myplugin.cpp
656
657Note the use of Faust's `-cn` (class name) option. This isn't strictly
658necessary, but it sets a reasonable default for the plugin URI which is used
659to identify the plugin (see below for a more detailed explanation of this). If
660you do not specify this option, Faust will use the default class name
661`mydsp`.
662
663You should now have the C++ source of the plugin in the current directory. To
664create an actual LV2 plugin from the C++ source, you'll have to go through the
665following steps:
666
667* compile the plugin source to a shared module
668* create an LV2 "manifest" for the plugin
669* create an LV2 "bundle" containing the plugin module and its manifest
670
671We now take a closer look at these steps so that you get a good understanding
672of the build process. This will enable you to handle more complex use cases,
673diagnose problems, customize scripts and Makefile, and even come up with your
674own build system if the need arises.
675
676Compiling the C++ Source
677------------------------
678
679After running the dsp source through the Faust compiler, the resulting C++
680source file for the plugin must be compiled to a shared module, using your
681favourite C++ compiler. For instance, using gcc under Linux:
682
683    g++ -shared myplugin.cpp -o myplugin.so
684
685Add `-fPIC` and other compilation options such as `-O3` as needed. To make
686this work, you'll need to have the [LV2][] framework installed, so that the
687required LV2 header files are available. The instrument part of the
688architecture also needs some of the header files of the [Boost][] C++ library,
689so you should have at least the headers from that project installed as well.
690
691To create a working plugin, you may also have to modify the URI of the
692plugin. As already mentioned, the URI ("uniform resource identifier",
693cf. [RFC3986][] and [RFC1630][]) serves as a global name which is used to
694identify the plugin and differentiate it from other installed LV2 plugins,
695hence this name must be unique. For instance, the URI might be the actual URL
696of the website where the plugin may be downloaded, or it may just be an
697abstract name using one of the available URI schemes.
698
699[RFC3986]: http://tools.ietf.org/html/rfc3986
700[RFC1630]: http://tools.ietf.org/html/rfc1630
701
702In order to support dynamic manifests, the URI needs to be included in the
703plugin source. The LV2 architecture thus contains a definition for the plugin
704URI. By default the URI `https://faustlv2.bitbucket.io/myplugin` will be used,
705where `myplugin` is the actual class name of the plugin as set with Faust's
706`-cn` option discussed above. Of course, you will want to change this when
707compiling your own plugins.
708
709There are some macro definitions which can be adjusted on the `g++` command
710line to change the URI according to your needs:
711
712* `URI_PREFIX` specifies the prefix of the URI to which the class name of
713  the plugin will be appended.
714
715* `PLUGIN_URI` specifies the entire URI. This overrides the URI no matter
716  what `URI_PREFIX` value and class name have been specified.
717
718These values must be given as double-quoted strings. For instance, if the
719class name `myplugin` has been set with the Faust `-cn` option, then it's
720usually sufficient to just change the URI prefix, e.g., as follows:
721
722    g++ -shared -DURI_PREFIX='"http://somewhere.org/plugins"' \
723      myplugin.cpp -o myplugin.so
724
725If you really need to adjust the entire plugin URI, you can also compile the
726plugin with:
727
728    g++ -shared -DPLUGIN_URI='"http://somewhere.org/plugins/myplugin"' \
729      myplugin.cpp -o myplugin.so
730
731In either case, the plugin URI given here must match the URI specified in the
732manifest of the plugin, see "The Manifest" below.
733
734The Manifest
735------------
736
737With the steps described in the previous subsections the compilation of the
738plugin is now essentially complete. However, LV2 also requires that you
739prepare a manifest.ttl file for the plugin, as explained in the LV2
740documentation. The manifest is read by LV2 hosts to discover which plugins are
741available and how they can be loaded. You could prepare the manifest files by
742hand, but for non-trivial plugins this will be very error-prone and thus is
743*not* recommended. Therefore faust-lv2 comes with some templates which can be
744used to create the manifest files in a more or less automatic fashion, as
745explained below.
746
747A minimal manifest *must* at least include the URI of the plugin and the name
748of the binary (shared module) from which the plugin can be loaded. If your LV2
749host supports the [dynamic manifest extension][] (see the corresponding
750remarks under "Static and Dynamic Manifests"), this is in fact all that is
751needed, since the remaining information (human-readable name, author and
752license of the plugin, port information, etc.) can be provided by the plugin
753module itself.
754
755[Turtle]: http://www.w3.org/TeamSubmission/turtle/
756
757Manifest files are so-called RDF files written in [Turtle][] syntax, which
758customarily have the .ttl filename extension. You can find a template for a
759minimal manifest in the lv2-manifest-template.ttl file which is included in
760the faust-lv2 distribution. This file can be edited by hand or, e.g., with the
761sed program to replace the placeholders `@uri@`, `@name@` and `@dllext@` with
762the URI, basename and the (OS-specific) filename extension of the plugin
763module. For instance:
764
765    sed -e 's?@uri@?http://somewhere.org/plugins/myplugin?g' \
766      -e 's?@name@?myplugin?g' -e 's?@dllext@?.so?g' \
767      < lv2-manifest-template.ttl > manifest.ttl
768
769The plugin URI must match what was set when compiling the plugin, see
770"Compiling the C++ Source" above. Here's how the created manifest might look
771like:
772
773    @prefix doap: <http://usefulinc.com/ns/doap#> .
774    @prefix foaf: <http://xmlns.com/foaf/0.1/> .
775    @prefix lv2:  <http://lv2plug.in/ns/lv2core#> .
776    @prefix dman: <http://lv2plug.in/ns/ext/dynmanifest#> .
777
778    <http://somewhere.org/plugins/myplugin/manifest>
779        lv2:binary <myplugin.so> ;
780        a dman:DynManifest .
781
782This is all that's needed for the dynamic manifest case. If your LV2 host does
783*not* support the [dynamic manifest extension][] (many LV2 hosts currently
784don't, at least not out of the box), a static manifest will be needed in the
785form of a ttl file which includes all the requisite information about the
786plugin. Instead of lv2-manifest-template.ttl you should use
787lv2-manifest-static-template.ttl in this case. Replacing the `@uri@` et al
788placeholders in this file works the same as above. This will give you
789something like:
790
791    @prefix doap: <http://usefulinc.com/ns/doap#> .
792    @prefix foaf: <http://xmlns.com/foaf/0.1/> .
793    @prefix lv2:  <http://lv2plug.in/ns/lv2core#> .
794    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
795
796    <http://somewhere.org/plugins/myplugin>
797        a lv2:Plugin ;
798        lv2:binary <myplugin.so> ;
799        rdfs:seeAlso <myplugin.ttl> .
800
801Note that the static manifest refers to an additional .ttl file with the same
802basename as the plugin module which contains all the additional information
803about plugin name, ports etc. You can create this file from the same C++
804source as the plugin module itself, by compiling the source to an executable
805which, when run, simply prints the dynamic manifest of the plugin to standard
806output, from where it can be redirected into the ttl file. After creating the
807ttl file, the executable is no longer needed and can be deleted. For instance:
808
809    g++ myplugin.cpp -o myplugin
810    ./myplugin > myplugin.ttl
811    rm myplugin
812
813You should add to the `g++` command all options that may be needed to compile
814the plugin. In particular, the same symbol definitions which set the plugin
815URI will be needed as described under "Compiling the C++ Source".
816
817LV2 Bundles
818-----------
819
820Finally, shared module and manifest are packaged together as an *LV2 bundle*,
821a directory which customarily has the .lv2 extension. For dynamic manifests,
822this can be done as follows:
823
824    mkdir myplugin.lv2
825    cp myplugin.so manifest.ttl myplugin.lv2
826
827If you use a static manifest, as described in the previous subsection, you
828must also copy the generated ttl file to this directory:
829
830    cp myplugin.ttl myplugin.lv2
831
832You can then set up LV2_PATH to point to the parent directory of the
833myplugin.lv2 folder, or copy the folder to some directory on your LV2_PATH to
834have the plugin recognized by your LV2 host.
835
836Bundling of Plugin Libraries
837----------------------------
838
839If you have more than one Faust plugin, you can simply repeat the steps
840described above for each plugin to be compiled. However, in this case you also
841have the option to create a single bundle from the entire plugin collection.
842To these ends, just concatenate all the manifest.ttl files of the individual
843plugins to one big manifest.ttl file. Then place this file along with all the
844plugin modules (and, in the case of static manifests, the corresponding .ttl
845file for each plugin) into a single folder. (This is also the way that the
846distributed Makefile packages the plugins unless the `split-bundle` make
847target is used, cf. "Installation".)
848
849For instance, suppose that we have three plugins `amp`, `chorus` and
850`freeverb` in corresponding .lv2 subdirectories, then we can bundle them
851together in a single folder, say, `faust.lv2`, as follows:
852
853    mkdir faust.lv2
854    for plugin in amp chorus freeverb; do
855      cat $plugin.lv2/manifest.ttl >> faust.lv2/manifest.ttl
856      cp $plugin.lv2/$plugin.so $plugin.lv2/$plugin.ttl faust.lv2
857    done
858
859Creating a Plugin GUI
860---------------------
861
862To keep things simple, we've only discussed how to create plugins without
863custom GUIs. Adding a plugin GUI involves translating the Faust source with
864the lv2ui.cpp architecture in lieu of lv2.cpp and compiling the resulting C++
865source to a separate GUI module using the Qt build tool (qmake). You'll also
866have to adjust the manifest so that the LV2 host knows about the plugin GUI
867and links it to the proper plugin. The precise steps are all rather
868straightforward, but involve a few technicalities, because qmake needs to be
869used in order to support Qt's signal/slot mechanism. The gory details can be
870found in the provided Makefile or the faust2lv2 script.
871
872Automatizing the Build Process
873------------------------------
874
875The above steps needed to build and install a working LV2 plugin or an entire
876plugin collection from Faust source can of course be automatized, using any
877build tool of your choice. In fact the entire faust-lv2 package is just one
878big example which illustrates how to do this with GNU make or with the
879included build script. Using the explanation of the manual build process above
880you should now be able to customize the provided Makefile and the faust2lv2
881script for your own purposes.
882
883Future Work
884===========
885
886The LV2 plugin implementation of the Faust LV2 architecture is fully
887functional and reasonably complete already. But of course there are ways in
888which it can be further improved. Some useful and interesting directions for
889future research and development are pointed out below.
890
891* Add improvements for smoother playback. In particular, the polyphony control
892  of instruments is fairly disruptive right now, as it simply resets all
893  voices each time the control changes. Another idea would be to do fully
894  dynamic voice allocation so that the polyphony control wouldn't be needed at
895  all. Also, it would be useful to implement crossfading to prevent clicks
896  when a plugin is activated or deactivated.
897
898* (As suggested on the Faust mailing list:) Add support for alternative voice
899  allocation and control models such as [MPE][] (Multidimensional Polyphonic
900  Expression). MPE is used by some of the latest MIDI hardware and also has
901  support in some DAWs already.
902
903* Add support for the [LV2 Time][] extension. This extension provides
904  transport information such as current position, tempo and meter to a plugin,
905  which is useful for plugins which need to synchronize their beats and/or
906  tempo with the host.
907
908* Implement MIDI mapping for passive Faust controls. This data is already
909  available in the control output ports, but now that most DAWs fully support
910  MIDI routing with plugins, it might be handy to also have the data as MIDI
911  output for some use cases.
912
913* Port the architecture to other targets (Audio Units, Pd and Max come to
914  mind) and GUI toolkits. The existing architecture already has an abstract
915  plugin class at its core which gets rid of most of the plugin API specifics.
916  In the end, it should even be possible to unify all these to a single
917  architecture which works with *all* these plugin APIs (this is a long-term
918  project, though, so don't hold your breath just yet).
919
920[LV2 Time]: http://lv2plug.in/ns/ext/time/
921[LV2 UI]: http://lv2plug.in/ns/extensions/ui/
922[MPE]: http://expressiveness.org/2015/04/24/midi-specifications-for-multidimensional-polyphonic-expression-mpe
923