Struct Map

Source
pub struct Map { /* private fields */ }
Expand description

A directional connection between multiple signals. Changes to input signals will affect output signals.

§Examples

Create a map between two signals:

use std::thread;
use std::time::Duration;
use libmapper_rs::graph::Map;
use libmapper_rs::signal::Signal;
fn create_map(sig_a: &Signal, sig_b: &Signal) -> Map {
  let map = Map::create(sig_a, sig_b);
  loop {
    if map.is_ready() {
     break;
    }
   thread::sleep(Duration::from_millis(10));
  }
  map
}

Implementations§

Source§

impl Map

Source

pub fn create(src: &Signal, dst: &Signal) -> Map

Create a new map between two signals. This does not actually create the map in the graph, push must be called to let the rest of the graph know about the map.

Examples found in repository?
examples/maps.rs (line 18)
5pub fn main() {
6    let dev = Device::create("rustmapper");
7    loop {
8        dev.poll_and_block(Duration::from_millis(10));
9        if dev.is_ready() {
10            break;
11        }
12    }
13
14    println!("Device became ready!");
15    let mut sig_a =
16        dev.create_signal::<i32>("output", libmapper_rs::constants::mpr_dir::MPR_DIR_OUT);
17    let sig_b = dev.create_signal::<i32>("input", libmapper_rs::constants::mpr_dir::MPR_DIR_IN);
18    let map = Map::create(&sig_a, &sig_b);
19    map.push();
20    loop {
21        dev.poll_and_block(Duration::from_millis(100));
22        if map.is_ready() {
23            break;
24        }
25    }
26    println!("Map created!");
27    for i in 0..100 {
28        sig_a.set_value_single(&i).unwrap();
29        dev.poll_and_block(Duration::from_millis(10));
30        let val = sig_b
31            .get_value_single::<i32>()
32            .expect("Signal didn't send!");
33        println!("Sent: {}, Received: {}", i, val.0);
34        assert_eq!(i, val.0)
35    }
36}
Source

pub fn push(&self)

Publish this map to the distributed graph. After calling this function and once is_ready returns true, the map is active.

Examples found in repository?
examples/maps.rs (line 19)
5pub fn main() {
6    let dev = Device::create("rustmapper");
7    loop {
8        dev.poll_and_block(Duration::from_millis(10));
9        if dev.is_ready() {
10            break;
11        }
12    }
13
14    println!("Device became ready!");
15    let mut sig_a =
16        dev.create_signal::<i32>("output", libmapper_rs::constants::mpr_dir::MPR_DIR_OUT);
17    let sig_b = dev.create_signal::<i32>("input", libmapper_rs::constants::mpr_dir::MPR_DIR_IN);
18    let map = Map::create(&sig_a, &sig_b);
19    map.push();
20    loop {
21        dev.poll_and_block(Duration::from_millis(100));
22        if map.is_ready() {
23            break;
24        }
25    }
26    println!("Map created!");
27    for i in 0..100 {
28        sig_a.set_value_single(&i).unwrap();
29        dev.poll_and_block(Duration::from_millis(10));
30        let val = sig_b
31            .get_value_single::<i32>()
32            .expect("Signal didn't send!");
33        println!("Sent: {}, Received: {}", i, val.0);
34        assert_eq!(i, val.0)
35    }
36}
Source

pub fn is_ready(&self) -> bool

Returns true once the map has been published and is active. Otherwise, returns false.

Examples found in repository?
examples/maps.rs (line 22)
5pub fn main() {
6    let dev = Device::create("rustmapper");
7    loop {
8        dev.poll_and_block(Duration::from_millis(10));
9        if dev.is_ready() {
10            break;
11        }
12    }
13
14    println!("Device became ready!");
15    let mut sig_a =
16        dev.create_signal::<i32>("output", libmapper_rs::constants::mpr_dir::MPR_DIR_OUT);
17    let sig_b = dev.create_signal::<i32>("input", libmapper_rs::constants::mpr_dir::MPR_DIR_IN);
18    let map = Map::create(&sig_a, &sig_b);
19    map.push();
20    loop {
21        dev.poll_and_block(Duration::from_millis(100));
22        if map.is_ready() {
23            break;
24        }
25    }
26    println!("Map created!");
27    for i in 0..100 {
28        sig_a.set_value_single(&i).unwrap();
29        dev.poll_and_block(Duration::from_millis(10));
30        let val = sig_b
31            .get_value_single::<i32>()
32            .expect("Signal didn't send!");
33        println!("Sent: {}, Received: {}", i, val.0);
34        assert_eq!(i, val.0)
35    }
36}
Source

pub fn release(self)

Destroy the map, severing the connection between the signals.

Source

pub fn set_expr(&self, expression: &str)

Set the expression used to map the values from the source(s) to the destination.

This is a helper function wrapping MapperObject::set_property_str

Trait Implementations§

Auto Trait Implementations§

§

impl Freeze for Map

§

impl RefUnwindSafe for Map

§

impl !Send for Map

§

impl !Sync for Map

§

impl Unpin for Map

§

impl UnwindSafe for Map

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<A> MapperObject for A
where A: AsMprObject,

Source§

fn get_type(&self) -> mpr_type

Get the mpr_type representing this object
Source§

fn set_property<T>(&self, property: mpr_prop, value: T)
where T: MappableType,

Set a property on this object to a numerical value
Source§

fn set_property_str(&self, property: mpr_prop, value: &str)

Set a property on this object to a string value
Source§

fn get_property<T>(&self, property: mpr_prop) -> Result<T, PropertyError>
where T: MappableType + Copy,

Get the value of a property by it’s key from this object. If the property does not exist, or if the type is not matched, this function will return an error.
Source§

fn get_property_str(&self, property: mpr_prop) -> Result<String, PropertyError>

Get the value of a string property by it’s key from this object. If the property does not exist, or if the type is not matched, this function will return an error.
Source§

fn set_custom_property<T>(&self, property: &str, value: T, publish: bool)
where T: MappableType,

Set a user-defined property to the specified value. The property is identified by a unique, case-sensitive string key. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.