extern crate libc;
#[macro_use] extern crate bitflags;
extern crate vec_map;
#[doc(hidden)]
pub mod ffi;
use ffi::ladspa_h;
#[doc(hidden)]
pub use ffi::ladspa_descriptor;
use std::cell::{RefCell, RefMut};
use std::default::Default;
#[allow(improper_ctypes)]
extern {
pub fn get_ladspa_descriptor(index: u64) -> Option<PluginDescriptor>;
}
pub type Data = f32;
pub struct PluginDescriptor {
pub unique_id: u64,
pub label: &'static str,
pub properties: Properties,
pub name: &'static str,
pub maker: &'static str,
pub copyright: &'static str,
pub ports: Vec<Port>,
pub new: fn(desc: &PluginDescriptor, sample_rate: u64) -> Box<Plugin + Send>,
}
#[derive(Copy, Clone, Default)]
pub struct Port {
pub name: &'static str,
pub desc: PortDescriptor,
pub hint: Option<ControlHint>,
pub default: Option<DefaultValue>,
pub lower_bound: Option<Data>,
pub upper_bound: Option<Data>,
}
#[derive(Copy, Clone)]
pub enum PortDescriptor {
Invalid = 0,
AudioInput = (ladspa_h::PORT_AUDIO | ladspa_h::PORT_INPUT) as isize,
AudioOutput = (ladspa_h::PORT_AUDIO | ladspa_h::PORT_OUTPUT) as isize,
ControlInput = (ladspa_h::PORT_CONTROL | ladspa_h::PORT_INPUT) as isize,
ControlOutput = (ladspa_h::PORT_CONTROL | ladspa_h::PORT_OUTPUT) as isize,
}
impl Default for PortDescriptor {
fn default() -> PortDescriptor {
PortDescriptor::Invalid
}
}
bitflags!(
#[doc="Represents the special properties a control port may hold. These are merely hints as to the
use of the port and may be completely ignored by the host. For audio ports, use ```CONTROL_HINT_NONE```.
To attach multiple properties, bitwise-or them together.
See documentation for the constants beginning with HINT_ for the more information."]
pub flags ControlHint: i32 {
#[doc="Indicates that this is a toggled port. Toggled ports may only have default values
of zero or one, although the host may send any value, where <= 0 is false and > 0 is true."]
const HINT_TOGGLED = ::ffi::ladspa_h::HINT_TOGGLED,
#[doc="Indicates that all values related to the port will be multiplied by the sample rate by
the host before passing them to your plugin. This includes the lower and upper bounds. If you
want an upper bound of 22050 with this property and a sample rate of 44100, set the upper bound
to 0.5"]
const HINT_SAMPLE_RATE = ::ffi::ladspa_h::HINT_SAMPLE_RATE,
#[doc="Indicates that the data passed through this port would be better represented on a
logarithmic scale"]
const HINT_LOGARITHMIC = ::ffi::ladspa_h::HINT_LOGARITHMIC,
#[doc="Indicates that the data passed through this port should be represented as integers. Bounds
may be interpreted exclusively depending on the host"]
const HINT_INTEGER = ::ffi::ladspa_h::HINT_INTEGER,
}
);
#[derive(Copy, Clone)]
pub enum DefaultValue {
Minimum = ladspa_h::HINT_DEFAULT_MINIMUM as isize,
Low = ladspa_h::HINT_DEFAULT_LOW as isize,
Middle = ladspa_h::HINT_DEFAULT_MIDDLE as isize,
High = ladspa_h::HINT_DEFAULT_HIGH as isize,
Maximum = ladspa_h::HINT_DEFAULT_MAXIMUM as isize,
Value0 = ladspa_h::HINT_DEFAULT_0 as isize,
Value1 = ladspa_h::HINT_DEFAULT_1 as isize,
Value100 = ladspa_h::HINT_DEFAULT_100 as isize,
Value440 = ladspa_h::HINT_DEFAULT_440 as isize,
}
pub struct PortConnection<'a> {
pub port: Port,
pub data: PortData<'a>,
}
pub enum PortData<'a> {
AudioInput(&'a [Data]),
AudioOutput(RefCell<&'a mut [Data]>),
ControlInput(&'a Data),
ControlOutput(RefCell<&'a mut Data>),
}
unsafe impl<'a> Sync for PortData<'a> { }
impl<'a> PortConnection<'a> {
pub fn unwrap_audio(&'a self) -> &'a [Data] {
if let PortData::AudioInput(ref data) = self.data {
data
} else {
panic!("PortConnection::unwrap_audio called on a non audio input port!")
}
}
pub fn unwrap_audio_mut(&'a self) -> RefMut<'a, &'a mut [Data]> {
if let PortData::AudioOutput(ref data) = self.data {
data.borrow_mut()
} else {
panic!("PortConnection::unwrap_audio_mut called on a non audio output port!")
}
}
pub fn unwrap_control(&'a self) -> &'a Data {
if let PortData::ControlInput(data) = self.data {
data
} else {
panic!("PortConnection::unwrap_control called on a non control input port!")
}
}
pub fn unwrap_control_mut(&'a self) -> RefMut<'a, &'a mut Data> {
if let PortData::ControlOutput(ref data) = self.data {
data.borrow_mut()
} else {
panic!("PortConnection::unwrap_control called on a non control output port!")
}
}
}
bitflags!(
#[doc="Represents the special properties a LADSPA plugin can have.
To attach multiple properties, bitwise-or them together, for example
```PROP_REALTIME | PROP_INPLACE_BROKEN```.
See documentation for the constants beginning with PROP_ for the more information."]
pub flags Properties: i32 {
#[doc="No properties."]
const PROP_NONE = 0,
#[doc="Indicates that the plugin has a realtime dependency so it's output may not be cached."]
const PROP_REALTIME = ::ffi::ladspa_h::PROPERTY_REALTIME,
#[doc="Indicates that the plugin will not function correctly if the input and output audio
data has the same memory location. This could be an issue if you copy input to output
then refer back to previous values of the input as they will be overwritten. It is
recommended that you avoid using this flag if possible as it can decrease the speed of
the plugin."]
const PROP_INPLACE_BROKEN = ::ffi::ladspa_h::PROPERTY_INPLACE_BROKEN,
#[doc="Indicates that the plugin is capable of running not only in a conventional host but
also in a 'hard real-time' environment. To qualify for this the plugin must
satisfy all of the following:
* The plugin must not use malloc(), free() or other heap memory
management within its run() function. All new
memory used in run() must be managed via the stack. These
restrictions only apply to the run() function.
* The plugin will not attempt to make use of any library
functions with the exceptions of functions in the ANSI standard C
and C maths libraries, which the host is expected to provide.
* The plugin will not access files, devices, pipes, sockets, IPC
or any other mechanism that might result in process or thread
blocking.
* The plugin will take an amount of time to execute a run()
call approximately of form (A+B*SampleCount) where A
and B depend on the machine and host in use. This amount of time
may not depend on input signals or plugin state. The host is left
the responsibility to perform timings to estimate upper bounds for
A and B."]
const PROP_HARD_REALTIME_CAPABLE = ::ffi::ladspa_h::PROPERTY_HARD_RT_CAPABLE,
}
);
pub trait Plugin {
fn activate(&mut self) { }
fn run<'a>(&mut self, sample_count: usize, ports: &[&'a PortConnection<'a>]);
fn deactivate(&mut self) { }
}