Generic LV2 export¶
Status: Prototype for 0.1.0. Design: decision 0281; LV2 choices: decision 0283. The support matrix separates macOS, Linux and Windows evidence (see also limits).
One LV2 module (ravet_lv2), one UI module (ravet_lv2_ui) and a Turtle
generator (ravet_lv2_turtle) are written once against the product table
RavetPlugin.h. The sources are
in crates/ravet-plugin/lv2. A bundle contains:
| File | Content |
|---|---|
ravet_lv2.{so,dylib,dll} |
The generic DSP module (lv2_descriptor) |
ravet_lv2_ui.{so,dylib,dll} |
The generic UI module (lv2ui_descriptor), when the bundle has a UI |
ravet_product.{so,dylib,dll} |
The product library, renamed; it exports ravet_plugin_v1 |
manifest.ttl, plugin.ttl |
Generated from the product's table at build time |
LV2-SDK-LICENSE.txt, RAVET-LICENSE.txt, RAVET-LICENSING.md |
Notices (added by the bundle script) |
Both modules find their own directory at run time (dladdr or
GetModuleFileNameW) and load ravet_product from it. The product library is
never unloaded.
Build a bundle¶
The LV2 headers are external and never vendored. Use the official source
release (it has include/lv2/... and COPYING), or any flat tree with
lv2/core/lv2.h, such as the one JUCE ships:
git clone --depth 1 --branch v1.18.10 https://gitlab.com/lv2/lv2.git target/sdks/lv2
CARGO_BUILD_JOBS=2 python3 scripts/bundle-lv2.py --plugin delay --sdk target/sdks/lv2
--plugin delay builds examples/delay-plugin, --plugin generic the gain
plug-in (examples/gain-plugin) and --plugin mock the C++ test table only;
--crate <package> selects any product crate. The script builds the crate with
Cargo, configures and builds crates/ravet-plugin/lv2 with CMake, runs its
tests with CTest, copies the bundle to target/lv2/<name>.lv2 (for example
ravet_delay.lv2) with notices, signs the three binaries ad hoc on macOS and runs
lv2_validate when it is installed. It installs nothing. --plugin gain,
performance and note-routing still select the 0.0.1 references below.
The same build without the script:
cargo build --release --locked -p ravet-delay-plugin
cmake -S crates/ravet-plugin/lv2 -B target/lv2/generic-ravet_delay -DCMAKE_BUILD_TYPE=Release \
-DRAVET_LV2_SDK="$PWD/target/sdks/lv2" \
-DRAVET_PLUGIN_LIBRARY="$PWD/target/release/libravet_delay_plugin.so" \
-DRAVET_LV2_BUNDLE_NAME=ravet_delay
cmake --build target/lv2/generic-ravet_delay --parallel 2
ctest --test-dir target/lv2/generic-ravet_delay --output-on-failure
The bundle is then in target/lv2/generic-ravet_delay/bundles/ravet_delay.lv2.
The library is libravet_delay_plugin.dylib on macOS and ravet_delay_plugin.dll
on Windows. Options: RAVET_LV2_LICENSE=<URI> writes doap:license;
RAVET_LV2_UI ships and declares the UI (default on; the bundle scripts pass
it explicitly; see the UI). The product must be built with the native feature of
ravet-plugin, as the examples are. Turtle is generated by loading the built
library, so it is generated for the platform the bundle is built for. A Windows
cross-build (--target windows, below) runs the Windows generator under Wine
through CMAKE_CROSSCOMPILING_EMULATOR; there is no other cross-compilation.
Generated metadata and ports¶
lv2:URI is the product's lv2_uri (by default urn:<plug-in ID>). The class
is lv2:Plugin for effects, plus lv2:InstrumentPlugin or lv2:MIDIPlugin.
doap:name and doap:maintainer (vendor and URL) come from the product, and
version a.b.c becomes lv2:minorVersion a × 1000 + b and lv2:microVersion
c. urid:map, options:options and bufsz:boundedBlockLength are optional
features; state:interface is provided.
LV2 has one fixed port set per URI, so the adapter uses the product's preferred (first) layout only. Other layouts are not exported. Ports, in index order:
| Ports | Symbols | Notes |
|---|---|---|
| Audio inputs, then outputs | in_1…, out_1… |
Named Left/Right for two channels |
| Atom input | events_in |
Always present. Supports time:Position, and midi:MidiEvent when the product takes notes. lv2:control designation, connection optional |
| Atom output | midi_out |
Only when the product emits notes. Connection optional |
| Control output | latency |
lv2:latency designation, integer frames |
| One control port per parameter | the parameter key | Declaration order |
Parameter ports carry the physical minimum, maximum and default. Port properties follow the parameter:
- the bypass parameter becomes the
enabledport with thelv2:enableddesignation, inverted: enabled 1 is bypass off; - one step from 0 to 1 is
lv2:toggled; - 2–64 steps are
lv2:enumeration, with a scale point per value labelled by the product'svalue_to_text; integer-spaced steps are alsolv2:integer; more steps becomepprops:rangeSteps; - logarithmic scale is
pprops:logarithmic; non-automatable parameters arepprops:notAutomatic; hidden onespprops:notOnGUI; - read-only parameters are control outputs, written after each block;
- units map to the LV2 units vocabulary (dB, Hz, kHz, ms, s, %, bpm, semitones,
cents and others); any other unit string becomes a custom
units:Unit.
Port symbols come from parameter keys and stay stable; port indices follow declaration order. Inserting, removing or reordering parameters therefore changes the indices of later ports, which hosts that store indices instead of symbols would misassign. Add parameters at the end, and keep a removed parameter as a hidden read-only entry if released sessions must keep loading (see the 0.1.0 upgrade notes).
A key that is not a valid LV2 symbol, or that clashes with a fixed symbol,
becomes p<host ID>. The same code computes the layout at build time and at
run time, so Turtle and the module always agree.
Processing¶
- Controls. A control port whose value changed since the last block (every
connected port on the first block) becomes a
RAVET_NATIVE_PARAMETER_VALUEevent at offset 0 with the parameter's host ID and physical value. The table clamps and snaps it and writes it to its cache, so state saved afterwards includes it, as withset_value. Nonfinite port values are ignored. - Blocks. The adapter prepares the table with the host's
bufsz:maxBlockLength(or nominal length, else 4,096 frames, at most 65,536) and splits longerruncalls. Zero-frame runs still deliver control changes. Disconnected audio inputs read silence; disconnected outputs are discarded. - MIDI. With note input, MIDI events of one to three bytes become
RAVET_NATIVE_MIDIevents at their frame, relative to the sub-block. SysEx, running status, wrong lengths and bad data bytes are skipped. Events beyond 1,024 per sub-block are dropped. With note output, the product's MIDI and note events are written tomidi_outat their absolute frame, as far as the host buffer allows. - Transport. Each
time:Positionupdates the fields it contains (frame, speed, beat, bar, bar beat, beats per bar, beat unit, tempo; any numeric Atom type). A position inside a block splits the block there. Between positions, the adapter advances frame and beats while the speed is nonzero, as LV2 hosts send positions only on changes. The processor gets playing state, sample and beat positions, tempo, a signature (integral beats per bar and beat unit) and the bar. Recording, loop and pre-roll are unknown in LV2, so those DETAILS flags stay false and must not be read as host facts. Without any position, transport is unknown (null). - Latency. The
latencyport reportstiming().latency_samplesafter every block, so a change reaches the host at the next block. - Faults. When the table rejects or fails a block, that sub-block's outputs are silenced. Denormals are flushed inside the table.
run does not allocate, lock or block; buffers are sized at instantiation and
activation. Activation prepares the table; deactivation calls deactivate.
State¶
state:interface saves the product's whole state envelope (save_state) as
one atom:Chunk property, urn:ravet:lv2:state, flagged POD and portable.
Restore calls load_state, which applies all values or none and accepts
earlier versions and the product's import format. A wrong type is
LV2_STATE_ERR_BAD_TYPE, a rejected envelope LV2_STATE_ERR_UNKNOWN; a
missing property leaves values unchanged, because the control ports carry them.
Without urid:map, save and restore return LV2_STATE_ERR_NO_FEATURE.
Hosts also store control port values. After a restore, the port values present at the next block are taken as given, so ports still holding pre-restore values do not undo it; any later port change wins.
UI¶
The UI is an X11UI on Linux and other Unix systems, a CocoaUI on macOS and a
WindowsUI on Windows. It requires ui:parent and ui:idleInterface, and uses
ui:resize and ui:touch when offered. It opens the product's web editor with
editor_open inside the host's parent view, reports the editor size through
ui:resize, and forwards host resizes to editor_resize for resizable
editors.
The UI never accesses the DSP instance. Hosts may run UIs out of process, and
instance-access is not universal, so the UI creates its own mirror
instance of the product table that is never prepared or processed:
- host to UI:
port_eventon a parameter port callsset_valueon the mirror, which the editor shows (editor_idleruns on every UI idle call); - UI to host: each idle call drains the mirror's
take_edits. Values go to the host through the UI write function on the same control port (float protocol); begin/end becomeui:touchgrabs. The DSP instance then sees an ordinary control port change.
Because of this, the editor sees parameter values only. Product messages that need the processor, telemetry and product extra state are not available in the LV2 editor.
The table hosts editors in Cocoa views on macOS, HWNDs on Windows and X11
windows on Linux (decision 0293),
so product bundles declare ui:CocoaUI, ui:WindowsUI or ui:X11UI on every
platform (RAVET_LV2_UI, default on). Products without an editor still get no
UI. The UI's idle interface calls editor_idle, which pumps GTK on Linux. The
Delay's UI ran in REAPER 7.82 on Linux (X11, inside REAPER's non-XEmbed child
window) and Windows 11 (see work status); no other LV2 host
was available, and hosts built on GTK 2 or GTK 4 (Ardour, for example) are
refused by the Linux web view.
Linux build and validation¶
# Tools: cmake, a C++17 compiler, Rust; optional lilv (lv2ls, lv2info, lv2apply,
# lilv-0 development files), lv2_validate (sord), lv2lint, jalv.
git clone --depth 1 --branch v1.18.10 https://gitlab.com/lv2/lv2.git target/sdks/lv2
CARGO_BUILD_JOBS=2 python3 scripts/bundle-lv2.py --plugin mock --sdk target/sdks/lv2
CARGO_BUILD_JOBS=2 python3 scripts/bundle-lv2.py --plugin delay --sdk target/sdks/lv2
CARGO_BUILD_JOBS=2 python3 scripts/bundle-lv2.py --plugin generic --sdk target/sdks/lv2
mkdir -p target/lv2-path
ln -sfn "$PWD/target/lv2/ravet_delay.lv2" "$PWD/target/lv2/ravet_generic.lv2" target/lv2-path/
export LV2_PATH="$PWD/target/lv2-path:/usr/lib/lv2"
lv2ls
lv2info urn:org.ravet.delay
lv2_validate target/lv2/ravet_delay.lv2/manifest.ttl target/lv2/ravet_delay.lv2/plugin.ttl
lv2lint urn:org.ravet.delay
lv2apply -c gain 0.5 -i stereo.wav -o out.wav urn:org.ravet.gain-generic
lv2apply -c sync 0 -c time 100 -c mix 100 -c feedback 0 -i impulse.wav -o echo.wav urn:org.ravet.delay
jalv.gtk3 urn:org.ravet.delay
lv2apply hosts plug-ins without any features: the adapter then runs without
urid:map, ignoring the Atom ports and state. For a DAW such as REAPER, link
or copy the bundles into ~/.lv2 and rescan. Expected CTest output is
ravet_lv2_mock_contracts, ravet_lv2_mock_aux_contracts (a mock with a
sidechain and an auxiliary output), ravet_lv2_mock_turtle_unchanged (the
plain mock's Turtle against a golden file), ravet_<name>_smoke and, with lilv
development files, ravet_lv2_mock_lilv, ravet_lv2_mock_aux_lilv and
ravet_<name>_lilv, all passing.
Windows cross-build¶
# Linux with cargo-xwin, clang-cl and Wine (see plugin-export.md):
python3 scripts/bundle-lv2.py --plugin delay --sdk target/sdks/lv2 --target windows
# Bundle: target/lv2/windows/ravet_delay.lv2 (ravet_lv2.dll, ravet_product.dll)
# Contract tool: target/lv2/windows/generic-ravet_delay/ravet_lv2_contracts.exe
The Turtle generator and the contract tests run under Wine; lv2_validate on
the build machine checks the generated Turtle, which matches the Linux bundle's
apart from the .dll binary name and CRLF line endings. The lilv host check is
skipped (the build machine's lilv cannot load Windows modules). To check on
Windows, copy the bundles and ravet_lv2_contracts.exe there and run
ravet_lv2_contracts.exe ravet_lv2_mock.lv2 ravet_lv2.dll ravet_lv2_ui.dll --mock
and ravet_lv2_contracts.exe ravet_delay.lv2 ravet_lv2.dll -. A native Windows
build (MSVC) has not been run.
Tests¶
ravet_lv2_contracts --mockloads the packaged mock bundle as a minimal host: descriptor and Turtle/port agreement, the first-block parameter events, inverted bypass, the stepped parameter and latency port, a read-only output, chunking at the host's maximum block, timed MIDI in and out (with SysEx and bad data skipped),time:Positiontransport with extrapolation and a mid-block split, state save/restore (one Chunk; the restore beats stale ports; later port changes win; wrong type and corrupt data rejected), zero-frame runs, a disconnected input, re-activation, running withouturid:map, and the UI's mirror, edits, touch and resize.- Without
--mock, the same tool smoke-tests a real product: descriptor and Turtle agreement, processing, state round trip, and (on macOS) opening the real editor in anNSView, idling and resizing. ravet_lv2_lilv_hostchecks the bundle through lilv: discovery,lilv_plugin_verify, latency and enabled designations, UI discovery, processing and a state round trip through lilv's state API.scripts/tests/test_lv2_generic.pycovers the bundle script.
The mock product (mock/mock_plugin.cpp) is a small C++ table — gain, bypass,
a four-value stepped mode, a read-only level, stereo and mono, notes in and
out — with a test probe. Any adapter can test against it.
Limits of the generic export¶
- One port set: the first layout only, f32. Auxiliary
buses are extra audio ports
after every existing port (
aux<B>_in_<C>,aux<B>_out_<C>, optional; sidechain inputs carrylv2:isSideChain). Each direction of each bus is a port group (aux<B>_in/aux<B>_out, mono or stereo groups with channel designations; wider buses have none), and sidechain groups arepg:sideChainOfa main group (main_in, ormain_outwithout main inputs) declared only for products with a sidechain. Products without auxiliary buses get no port-group metadata. Buses are always present; a disconnected port is the only inactive state (silent input; each disconnected output gets its own scratch channel). Port and group symbols take precedence over parameter keys and follow bus order, so reordering a product's buses breaks saved host connections. - MIDI 1 short messages only; no SysEx, MIDI 2 or note expressions. At most 1,024 events per sub-block reach the processor.
- Transport is extrapolated between host positions; tempo ramps, loops and recording state are not reported.
- No
lv2:hardRTCapable, presets orrsz:minimumSizedeclaration; port groups only for auxiliary buses and the main group a sidechain refers to. - The LV2 editor shows parameter values only (mirror instance). The X11 widget
is found as the parent's newest child window, because
editor_opendoes not return it. - Evidence: macOS arm64 — the contracts, the lilv checks,
lv2_validateandlv2applyrenders; Linux x86_64 — the contracts, lilv checks andlv2_validate; Windows 11 x64 (cross-built) — the contracts run natively andlv2_validateof its Turtle. Counts are in work status. lv2lint was not available on either machine. Subsequent REAPER 7.82 Delay renders/readback/project recall on macOS, Linux and Windows are recorded in the support matrix; those runs do not check the editor.