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