[−][src]Module lv2rs_atom::scalar
Scalar (number-like) atoms
There are several scalar atoms:
i32
i64
f32
f64
bool
URID
They all have in common that they are statically sized (which is something special among atoms)
and that they can be written in one piece; Once they are initialized, they are completed and
need no further amendments. Therefore, their behaviour is abstracted to another trait,
ScalarAtomBody
, which features a standard implementation of
AtomBody
for every type that implements it. Therefore, writing
and reading scalar atoms is pretty straight foreward:
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<f32>, out_port: AtomOutputPort<f32>, urids: CachedMap, } impl Plugin { /// Simulated `run` method. fn run(&mut self) { // Writing. unsafe { self.out_port.write_atom_body(&42.0f32, &mut self.urids) }.unwrap(); // Reading. let float = unsafe { self.in_port.get_atom_body(&mut self.urids) }.unwrap(); assert_eq!(42.0, *float); } } // 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();
Traits
ScalarAtomBody | Abstraction over scalar (number-like) atoms. |
Type Definitions
URID | Type for describing URIDs. |