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
impl Map
Sourcepub fn create(src: &Signal, dst: &Signal) -> Map
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}
Sourcepub fn push(&self)
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}
Sourcepub fn is_ready(&self) -> bool
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}
Sourcepub fn set_expr(&self, expression: &str)
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§
Source§impl AsMprObject for Map
impl AsMprObject for Map
fn as_mpr_object(&self) -> *mut c_void
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<A> MapperObject for Awhere
A: AsMprObject,
impl<A> MapperObject for Awhere
A: AsMprObject,
Source§fn set_property<T>(&self, property: mpr_prop, value: T)where
T: MappableType,
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)
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,
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>
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,
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