Struct libmapper_rs::graph::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)
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
pub fn main() {
    let dev = Device::create("rustmapper");
    loop {
        dev.poll_and_block(Duration::from_millis(10));
        if dev.is_ready() {
            break;
        }
    }

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

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

    println!("Device became ready!");
    let mut sig_a =
        dev.create_signal::<i32>("output", libmapper_rs::constants::mpr_dir::MPR_DIR_OUT);
    let sig_b = dev.create_signal::<i32>("input", libmapper_rs::constants::mpr_dir::MPR_DIR_IN);
    let map = Map::create(&sig_a, &sig_b);
    map.push();
    loop {
        dev.poll_and_block(Duration::from_millis(100));
        if map.is_ready() {
            break;
        }
    }
    println!("Map created!");
    for i in 0..100 {
        sig_a.set_value_single(&i).unwrap();
        dev.poll_and_block(Duration::from_millis(10));
        let val = sig_b
            .get_value_single::<i32>()
            .expect("Signal didn't send!");
        println!("Sent: {}, Received: {}", i, val.0);
        assert_eq!(i, val.0)
    }
}
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 + Default + 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§

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

§

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

§

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.