lv2_core/lib.rs
1//! Implementation of the core LV2 specification
2//!
3//! This crate forms the foundation of the LV2 experience for Rust: It contains the plugin trait and ports, as well as means to retrieve features from the host and to extend the interface of the plugin.
4//!
5//! # Example
6//!
7//! ```
8//! // Import everything we need.
9//! use lv2_core::prelude::*;
10//! use urid::*;
11//!
12//! // The input and output ports are defined by a struct which implements the `PortCollection` trait.
13//! // In this case, there is an input control port for the gain of the amplification, an input audio
14//! // port and an output audio port.
15//! #[derive(PortCollection)]
16//! struct Ports {
17//! gain: InputPort<Control>,
18//! input: InputPort<Audio>,
19//! output: OutputPort<Audio>,
20//! }
21//!
22//! // The plugin struct. In this case, we don't need any data and therefore, this struct is empty.
23//! //
24//! // LV2 uses URIs to identify types. This association is expressed via the `UriBound` trait,
25//! // which tells the framework that the type `Amp` is identified by the given URI. The usual
26//! // way to implement this trait is to use the `uri` attribute.
27//! #[uri("urn:rust-lv2-book:eg-amp-rs")]
28//! struct Amp;
29//!
30//! // The implementation of the `Plugin` trait, which turns `Amp` into a plugin.
31//! impl Plugin for Amp {
32//! // Tell the framework which ports this plugin has.
33//! type Ports = Ports;
34//!
35//! // We don't need any special host features; We can leave them out.
36//! type InitFeatures = ();
37//! type AudioFeatures = ();
38//!
39//! // Create a new instance of the plugin; Trivial in this case.
40//! fn new(_plugin_info: &PluginInfo, _features: &mut ()) -> Option<Self> {
41//! Some(Self)
42//! }
43//!
44//! // Process a chunk of audio. The audio ports are dereferenced to slices, which the plugin
45//! // iterates over.
46//! fn run(&mut self, ports: &mut Ports, _features: &mut (), _: u32) {
47//! let coef = if *(ports.gain) > -90.0 {
48//! 10.0_f32.powf(*(ports.gain) * 0.05)
49//! } else {
50//! 0.0
51//! };
52//!
53//! for (in_frame, out_frame) in Iterator::zip(ports.input.iter(), ports.output.iter_mut()) {
54//! *out_frame = in_frame * coef;
55//! }
56//! }
57//! }
58//! ```
59extern crate lv2_sys as sys;
60
61pub mod extension;
62pub mod feature;
63pub mod plugin;
64pub mod port;
65pub mod prelude;