[][src]Module lv2rs_atom::vector

Homogenous array of sized atoms.

A vector is the LV2 equivalent of a slice: It has a variable length, but it does only contain one type of item, which has to be sized.

When initialized, a vector does not contain any items. These items have to be pushed or appended to the vector using the VectorWritingFrame trait. Every writing frame implements this trait via a blanket implementation and the trait is included in the crate's prelude. You can, therefore, act as if the extended methods were normal methods of a writing frame.

Reading the vector is done using these methods:

An example:

extern crate lv2rs_atom as atom;
extern crate lv2rs_urid as urid;

use atom::prelude::*;
use atom::ports::*;
use urid::{CachedMap, debug::DebugMap};
use std::ffi::CStr;

pub struct Plugin {
    in_port: AtomInputPort<Vector<f32>>,
    out_port: AtomOutputPort<Vector<f32>>,
    urids: CachedMap,
}

impl Plugin {
    /// Simulated `run` method.
    fn run(&mut self) {
        // Writing
        {
            let mut frame =
                unsafe { self.out_port.write_atom_body(&(), &mut self.urids) }.unwrap();
            frame.push(0.0).unwrap();
            frame.append(&[1.0, 2.0, 3.0, 4.0]).unwrap();
        }

        // Reading.
        let vector = unsafe { self.in_port.get_atom_body(&mut self.urids) }.unwrap();
        assert_eq!([0.0, 1.0, 2.0, 3.0, 4.0], vector.as_slice());
    }
}

// Getting a debug URID map.
let mut debug_map = DebugMap::new();
let mut urids = unsafe {debug_map.create_cached_map()};

// Creating the plugin.
let mut plugin = Plugin {
    in_port: AtomInputPort::new(),
    out_port: AtomOutputPort::new(),
    urids: urids,
};

// Creating the atom space.
let mut atom_space = vec![0u8; 256];
let atom = unsafe { (atom_space.as_mut_ptr() as *mut Atom).as_mut() }.unwrap();
*(atom.mut_size()) = 256 - 8;

// Connecting the ports.
plugin.in_port.connect_port(atom as &Atom);
plugin.out_port.connect_port(atom);

// Calling `run`.
plugin.run();

Structs

VectorHeader

The body header of a vector.

Traits

VectorWritingFrame

Extension for WritingFrame and WritingFrameExt for vectors.

Type Definitions

Vector

A homogenous array of sized atoms.