[][src]Module lv2rs_atom::sequence

Atom tuple with time stamps for every contained atom.

A sequence is basically a tuple, but every contained atom is marked with the time stamp. This way, these atoms, now called "events", can be matched to frames in audio slices and processed with accurate timing. However, these time stamps can be given either in frames, which correspond to elements in an audio data slice, or in beats, a more abstract, tempo-independent way of describing timing.

When writing a sequence, you have to pass over the time unit the sequence should. However, after it was initialized, a sequence does not contain any atoms. These have to be pushed to the sequence using the SequenceWritingFrame 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 atoms is done by iterating through all atoms one by one. Iterators are produced by the iter method.

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<Tuple>,
    out_port: AtomOutputPort<Tuple>,
    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_atom::<i32>(&42, &mut self.urids).unwrap();
            frame.push_atom::<f32>(&17.0, &mut self.urids).unwrap();
        }

        let i32_urid = self.urids.map(<i32 as AtomBody>::get_uri());
        let f32_urid = self.urids.map(<f32 as AtomBody>::get_uri());

        // Reading.
        let tuple = unsafe { self.in_port.get_atom_body(&mut self.urids) }.unwrap();
        for sub_atom in tuple.iter() {
            match unsafe { sub_atom.get_body::<i32>(&mut self.urids) } {
                Ok(integer) => {
                    assert_eq!(42, *integer);
                    continue
                }
                Err(_) => (),
            }
            match unsafe { sub_atom.get_body::<f32>(&mut self.urids) } {
                Ok(float) => {
                    assert_eq!(17.0, *float);
                    continue
                }
                Err(_) => (),
            }
            panic!("Unknown property in object!");
        }
    }
}

// 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

SequenceHeader

The header of a sequence.

Enums

TimeStamp

Nice handle for time stamps.

TimeUnit

Nice handle for the time unit.

Traits

SequenceWritingFrame

Extension for WritingFrame and WritingFrameExt for vectors.

Type Definitions

Sequence

Atom tuple with time stamps for every contained atom.