pub struct Device<'a> { /* private fields */ }
Expand description
A device is libmapper’s connection to the distributed graph. Each device is a collection of signal instances and their metadata.
§Examples
use libmapper_rs::device::Device;
use std::time::Duration;
// you can create a device with Device::create
let dev = Device::create("rust");
// you have to poll a device occasionally to make things happen
loop {
dev.poll_and_block(Duration::from_millis(10)); // poll in 10ms intervals
if dev.is_ready() {
break;
}
}
// create signals, etc...
Implementations§
Source§impl Device<'_>
impl Device<'_>
Sourcepub fn create(name: &str) -> Device<'_>
pub fn create(name: &str) -> Device<'_>
Create a new device with the given name. The device will use it’s own connection to the graph.
Before calling any other methods on the device, you should poll it until it is ready.
§Notes
If you plan on creating multiple devices, consider using (Device::create_from_graph)Device::create_from_graph instead to pool resources.
Examples found in repository?
6fn main() {
7 let dev = Device::create("CoolDev");
8 loop {
9 dev.poll_and_block(Duration::from_millis(10));
10 if dev.is_ready() {
11 println!("Device is ready!");
12 break;
13 }
14 }
15 let p = dev.get_property::<i64>(mpr_prop::MPR_PROP_ID).unwrap();
16 println!("Device ID: {}", p);
17}
More examples
5fn main() {
6 println!("Using libmapper version {} ", libmapper_rs::get_mapper_version());
7 let dev = Device::create("rustmapper");
8 loop {
9 dev.poll_and_block(Duration::from_millis(10));
10 if dev.is_ready() {
11 break;
12 }
13 }
14
15 println!("Device became ready!");
16}
5fn 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 = dev.create_vector_signal::<f64>("test_sin", mpr_dir::MPR_DIR_OUT, 2);
16 let debug_sig = dev.create_vector_signal::<f64>("debug_msg", mpr_dir::MPR_DIR_IN, 2);
17 loop {
18 dev.poll_and_block(Duration::from_millis(100));
19 let time = (SystemTime::now()
20 .duration_since(UNIX_EPOCH)
21 .unwrap()
22 .as_millis() as u64) as f64
23 / 1000f64;
24
25 let values = [time.sin(), time.cos()];
26 sig.set_value(&values).unwrap();
27 if debug_sig.get_status().was_set_remote() {
28 println!(
29 "Received debug message: {:?}",
30 debug_sig.get_value::<f64>().unwrap().0
31 );
32 }
33 }
34}
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}
5fn 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 = dev.create_signal::<f64>("test_sin", mpr_dir::MPR_DIR_OUT);
16 sig.set_property(mpr_prop::MPR_PROP_MIN, -1.0);
17 sig.set_property(mpr_prop::MPR_PROP_MAX, 1.0);
18
19 let debug_sig = dev.create_signal::<f64>("debug_msg", mpr_dir::MPR_DIR_IN);
20
21 assert!(debug_sig.get_property::<f64>(mpr_prop::MPR_PROP_MIN).is_err());
22 loop {
23 dev.poll_and_block(Duration::from_millis(100));
24 let time = ((SystemTime::now()
25 .duration_since(UNIX_EPOCH)
26 .unwrap()
27 .as_millis() as u64) as f64
28 / 1000f64)
29 .sin();
30 sig.set_value_single(&time).unwrap();
31 if debug_sig.get_status().was_set_remote() {
32 println!(
33 "Received debug message: {:?}",
34 debug_sig.get_value_single::<f64>().unwrap()
35 );
36 }
37 }
38}
Sourcepub fn create_from_graph<'a>(name: &str, graph: &'a Graph) -> Device<'a>
pub fn create_from_graph<'a>(name: &str, graph: &'a Graph) -> Device<'a>
Create a new device with a shared graph. Sharing a graph between devices allows them to pool some resources and networking, potentially improving performance.
Examples found in repository?
6fn main() {
7 let graph = Arc::new(Graph::create());
8 let counter: Arc<AtomicU64> = Arc::new(AtomicU64::new(0));
9
10 let mut threads = Vec::<JoinHandle<()>>::new();
11
12 {
13 // spawn a thread to poll the graph
14 let graph = Arc::clone(&graph);
15 let thread = std::thread::spawn(move || {
16 loop {
17 graph.poll();
18 }
19 });
20 threads.push(thread);
21 }
22
23 let mut num_workers = 10;
24 let arg = env::args().skip(1).next();
25 if arg.is_some() {
26 num_workers = arg.unwrap().parse::<i32>().unwrap_or(10);
27 }
28
29 // spawn n threads creating then deleting devices at random
30 for _ in 0..num_workers {
31 let graph = graph.clone();
32 let id_counter = counter.clone();
33 let thread = std::thread::spawn(move || {
34 let name = format!("rust_{:?}", thread::current().id());
35 loop {
36 let _dev = libmapper_rs::device::Device::create_from_graph(&name, &graph);
37 loop {
38 _dev.poll();
39 if _dev.is_ready() {
40 break;
41 }
42 }
43 let signal = _dev.create_signal::<f32>("test_sig", libmapper_rs::constants::mpr_dir::MPR_DIR_OUT);
44 thread::sleep(std::time::Duration::from_millis(id_counter.fetch_add(1, Ordering::SeqCst) as u64));
45 drop(signal);
46 drop(_dev);
47 }
48 });
49 threads.push(thread);
50 }
51
52 for thread in threads {
53 thread.join().unwrap();
54 }
55}
Source§impl Device<'_>
impl Device<'_>
Sourcepub fn poll(&self)
pub fn poll(&self)
Poll the device without blocking
§Notes
You may want to use poll_all in a multithreaded enviroment, when using non-blocking polling libmapper will use a heuristic to determine how many messages to parse at once for performance. If you don’t care how long this function will take to run, call Device::poll_all.
Examples found in repository?
6fn main() {
7 let graph = Arc::new(Graph::create());
8 let counter: Arc<AtomicU64> = Arc::new(AtomicU64::new(0));
9
10 let mut threads = Vec::<JoinHandle<()>>::new();
11
12 {
13 // spawn a thread to poll the graph
14 let graph = Arc::clone(&graph);
15 let thread = std::thread::spawn(move || {
16 loop {
17 graph.poll();
18 }
19 });
20 threads.push(thread);
21 }
22
23 let mut num_workers = 10;
24 let arg = env::args().skip(1).next();
25 if arg.is_some() {
26 num_workers = arg.unwrap().parse::<i32>().unwrap_or(10);
27 }
28
29 // spawn n threads creating then deleting devices at random
30 for _ in 0..num_workers {
31 let graph = graph.clone();
32 let id_counter = counter.clone();
33 let thread = std::thread::spawn(move || {
34 let name = format!("rust_{:?}", thread::current().id());
35 loop {
36 let _dev = libmapper_rs::device::Device::create_from_graph(&name, &graph);
37 loop {
38 _dev.poll();
39 if _dev.is_ready() {
40 break;
41 }
42 }
43 let signal = _dev.create_signal::<f32>("test_sig", libmapper_rs::constants::mpr_dir::MPR_DIR_OUT);
44 thread::sleep(std::time::Duration::from_millis(id_counter.fetch_add(1, Ordering::SeqCst) as u64));
45 drop(signal);
46 drop(_dev);
47 }
48 });
49 threads.push(thread);
50 }
51
52 for thread in threads {
53 thread.join().unwrap();
54 }
55}
Sourcepub fn poll_all(&self)
pub fn poll_all(&self)
Processes all messages in the device’s queue, no matter how long it takes. If using dedicated threads to poll devices this is probably what you want to use instead of poll
Sourcepub fn poll_and_block(&self, time: Duration)
pub fn poll_and_block(&self, time: Duration)
Blocks the current thread for a specified amount of time. Use this function instead of sleeping in a loop.
Examples found in repository?
6fn main() {
7 let dev = Device::create("CoolDev");
8 loop {
9 dev.poll_and_block(Duration::from_millis(10));
10 if dev.is_ready() {
11 println!("Device is ready!");
12 break;
13 }
14 }
15 let p = dev.get_property::<i64>(mpr_prop::MPR_PROP_ID).unwrap();
16 println!("Device ID: {}", p);
17}
More examples
5fn main() {
6 println!("Using libmapper version {} ", libmapper_rs::get_mapper_version());
7 let dev = Device::create("rustmapper");
8 loop {
9 dev.poll_and_block(Duration::from_millis(10));
10 if dev.is_ready() {
11 break;
12 }
13 }
14
15 println!("Device became ready!");
16}
5fn 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 = dev.create_vector_signal::<f64>("test_sin", mpr_dir::MPR_DIR_OUT, 2);
16 let debug_sig = dev.create_vector_signal::<f64>("debug_msg", mpr_dir::MPR_DIR_IN, 2);
17 loop {
18 dev.poll_and_block(Duration::from_millis(100));
19 let time = (SystemTime::now()
20 .duration_since(UNIX_EPOCH)
21 .unwrap()
22 .as_millis() as u64) as f64
23 / 1000f64;
24
25 let values = [time.sin(), time.cos()];
26 sig.set_value(&values).unwrap();
27 if debug_sig.get_status().was_set_remote() {
28 println!(
29 "Received debug message: {:?}",
30 debug_sig.get_value::<f64>().unwrap().0
31 );
32 }
33 }
34}
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}
5fn 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 = dev.create_signal::<f64>("test_sin", mpr_dir::MPR_DIR_OUT);
16 sig.set_property(mpr_prop::MPR_PROP_MIN, -1.0);
17 sig.set_property(mpr_prop::MPR_PROP_MAX, 1.0);
18
19 let debug_sig = dev.create_signal::<f64>("debug_msg", mpr_dir::MPR_DIR_IN);
20
21 assert!(debug_sig.get_property::<f64>(mpr_prop::MPR_PROP_MIN).is_err());
22 loop {
23 dev.poll_and_block(Duration::from_millis(100));
24 let time = ((SystemTime::now()
25 .duration_since(UNIX_EPOCH)
26 .unwrap()
27 .as_millis() as u64) as f64
28 / 1000f64)
29 .sin();
30 sig.set_value_single(&time).unwrap();
31 if debug_sig.get_status().was_set_remote() {
32 println!(
33 "Received debug message: {:?}",
34 debug_sig.get_value_single::<f64>().unwrap()
35 );
36 }
37 }
38}
Source§impl Device<'_>
impl Device<'_>
Sourcepub fn is_ready(&self) -> bool
pub fn is_ready(&self) -> bool
Tests if the device is ready to use.
Do not try to call any other methods until this returns true
.
Examples found in repository?
6fn main() {
7 let dev = Device::create("CoolDev");
8 loop {
9 dev.poll_and_block(Duration::from_millis(10));
10 if dev.is_ready() {
11 println!("Device is ready!");
12 break;
13 }
14 }
15 let p = dev.get_property::<i64>(mpr_prop::MPR_PROP_ID).unwrap();
16 println!("Device ID: {}", p);
17}
More examples
5fn main() {
6 println!("Using libmapper version {} ", libmapper_rs::get_mapper_version());
7 let dev = Device::create("rustmapper");
8 loop {
9 dev.poll_and_block(Duration::from_millis(10));
10 if dev.is_ready() {
11 break;
12 }
13 }
14
15 println!("Device became ready!");
16}
5fn 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 = dev.create_vector_signal::<f64>("test_sin", mpr_dir::MPR_DIR_OUT, 2);
16 let debug_sig = dev.create_vector_signal::<f64>("debug_msg", mpr_dir::MPR_DIR_IN, 2);
17 loop {
18 dev.poll_and_block(Duration::from_millis(100));
19 let time = (SystemTime::now()
20 .duration_since(UNIX_EPOCH)
21 .unwrap()
22 .as_millis() as u64) as f64
23 / 1000f64;
24
25 let values = [time.sin(), time.cos()];
26 sig.set_value(&values).unwrap();
27 if debug_sig.get_status().was_set_remote() {
28 println!(
29 "Received debug message: {:?}",
30 debug_sig.get_value::<f64>().unwrap().0
31 );
32 }
33 }
34}
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}
5fn 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 = dev.create_signal::<f64>("test_sin", mpr_dir::MPR_DIR_OUT);
16 sig.set_property(mpr_prop::MPR_PROP_MIN, -1.0);
17 sig.set_property(mpr_prop::MPR_PROP_MAX, 1.0);
18
19 let debug_sig = dev.create_signal::<f64>("debug_msg", mpr_dir::MPR_DIR_IN);
20
21 assert!(debug_sig.get_property::<f64>(mpr_prop::MPR_PROP_MIN).is_err());
22 loop {
23 dev.poll_and_block(Duration::from_millis(100));
24 let time = ((SystemTime::now()
25 .duration_since(UNIX_EPOCH)
26 .unwrap()
27 .as_millis() as u64) as f64
28 / 1000f64)
29 .sin();
30 sig.set_value_single(&time).unwrap();
31 if debug_sig.get_status().was_set_remote() {
32 println!(
33 "Received debug message: {:?}",
34 debug_sig.get_value_single::<f64>().unwrap()
35 );
36 }
37 }
38}
6fn main() {
7 let graph = Arc::new(Graph::create());
8 let counter: Arc<AtomicU64> = Arc::new(AtomicU64::new(0));
9
10 let mut threads = Vec::<JoinHandle<()>>::new();
11
12 {
13 // spawn a thread to poll the graph
14 let graph = Arc::clone(&graph);
15 let thread = std::thread::spawn(move || {
16 loop {
17 graph.poll();
18 }
19 });
20 threads.push(thread);
21 }
22
23 let mut num_workers = 10;
24 let arg = env::args().skip(1).next();
25 if arg.is_some() {
26 num_workers = arg.unwrap().parse::<i32>().unwrap_or(10);
27 }
28
29 // spawn n threads creating then deleting devices at random
30 for _ in 0..num_workers {
31 let graph = graph.clone();
32 let id_counter = counter.clone();
33 let thread = std::thread::spawn(move || {
34 let name = format!("rust_{:?}", thread::current().id());
35 loop {
36 let _dev = libmapper_rs::device::Device::create_from_graph(&name, &graph);
37 loop {
38 _dev.poll();
39 if _dev.is_ready() {
40 break;
41 }
42 }
43 let signal = _dev.create_signal::<f32>("test_sig", libmapper_rs::constants::mpr_dir::MPR_DIR_OUT);
44 thread::sleep(std::time::Duration::from_millis(id_counter.fetch_add(1, Ordering::SeqCst) as u64));
45 drop(signal);
46 drop(_dev);
47 }
48 });
49 threads.push(thread);
50 }
51
52 for thread in threads {
53 thread.join().unwrap();
54 }
55}
Source§impl<'a> Device<'a>
impl<'a> Device<'a>
Sourcepub fn get_graph(&self) -> Option<&'a Graph>
pub fn get_graph(&self) -> Option<&'a Graph>
Get the shared graph used by this device. If the device was created with Device::create this will return None.
Source§impl Device<'_>
impl Device<'_>
Check if the device was created with a shared graph.
Sourcepub fn create_signal<T: MappableType + Copy>(
&self,
name: &str,
direction: mpr_dir,
) -> Signal
pub fn create_signal<T: MappableType + Copy>( &self, name: &str, direction: mpr_dir, ) -> Signal
Create a signal with the given name and direction.
§Notes
- The signal will have a vector length of 1 (i.e. single value).
- The passed generic parameter controls what type of data the signal will hold.
§Examples
use libmapper_rs::device::Device;
use libmapper_rs::constants::mpr_dir;
fn setup_signals(dev: &Device) {
// create an outgoing signal that outputs a single f64 value
let sig = dev.create_signal::<f64>("test_signal", mpr_dir::MPR_DIR_OUT);
}
Examples found in repository?
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}
More examples
5fn 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 = dev.create_signal::<f64>("test_sin", mpr_dir::MPR_DIR_OUT);
16 sig.set_property(mpr_prop::MPR_PROP_MIN, -1.0);
17 sig.set_property(mpr_prop::MPR_PROP_MAX, 1.0);
18
19 let debug_sig = dev.create_signal::<f64>("debug_msg", mpr_dir::MPR_DIR_IN);
20
21 assert!(debug_sig.get_property::<f64>(mpr_prop::MPR_PROP_MIN).is_err());
22 loop {
23 dev.poll_and_block(Duration::from_millis(100));
24 let time = ((SystemTime::now()
25 .duration_since(UNIX_EPOCH)
26 .unwrap()
27 .as_millis() as u64) as f64
28 / 1000f64)
29 .sin();
30 sig.set_value_single(&time).unwrap();
31 if debug_sig.get_status().was_set_remote() {
32 println!(
33 "Received debug message: {:?}",
34 debug_sig.get_value_single::<f64>().unwrap()
35 );
36 }
37 }
38}
6fn main() {
7 let graph = Arc::new(Graph::create());
8 let counter: Arc<AtomicU64> = Arc::new(AtomicU64::new(0));
9
10 let mut threads = Vec::<JoinHandle<()>>::new();
11
12 {
13 // spawn a thread to poll the graph
14 let graph = Arc::clone(&graph);
15 let thread = std::thread::spawn(move || {
16 loop {
17 graph.poll();
18 }
19 });
20 threads.push(thread);
21 }
22
23 let mut num_workers = 10;
24 let arg = env::args().skip(1).next();
25 if arg.is_some() {
26 num_workers = arg.unwrap().parse::<i32>().unwrap_or(10);
27 }
28
29 // spawn n threads creating then deleting devices at random
30 for _ in 0..num_workers {
31 let graph = graph.clone();
32 let id_counter = counter.clone();
33 let thread = std::thread::spawn(move || {
34 let name = format!("rust_{:?}", thread::current().id());
35 loop {
36 let _dev = libmapper_rs::device::Device::create_from_graph(&name, &graph);
37 loop {
38 _dev.poll();
39 if _dev.is_ready() {
40 break;
41 }
42 }
43 let signal = _dev.create_signal::<f32>("test_sig", libmapper_rs::constants::mpr_dir::MPR_DIR_OUT);
44 thread::sleep(std::time::Duration::from_millis(id_counter.fetch_add(1, Ordering::SeqCst) as u64));
45 drop(signal);
46 drop(_dev);
47 }
48 });
49 threads.push(thread);
50 }
51
52 for thread in threads {
53 thread.join().unwrap();
54 }
55}
Sourcepub fn create_vector_signal<T: MappableType + Copy>(
&self,
name: &str,
direction: mpr_dir,
vector_length: u32,
) -> Signal
pub fn create_vector_signal<T: MappableType + Copy>( &self, name: &str, direction: mpr_dir, vector_length: u32, ) -> Signal
Create a signal with the given name, direction, and vector length.
§Notes
- The passed generic parameter controls what type of data the signal will hold.
Examples found in repository?
5fn 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 = dev.create_vector_signal::<f64>("test_sin", mpr_dir::MPR_DIR_OUT, 2);
16 let debug_sig = dev.create_vector_signal::<f64>("debug_msg", mpr_dir::MPR_DIR_IN, 2);
17 loop {
18 dev.poll_and_block(Duration::from_millis(100));
19 let time = (SystemTime::now()
20 .duration_since(UNIX_EPOCH)
21 .unwrap()
22 .as_millis() as u64) as f64
23 / 1000f64;
24
25 let values = [time.sin(), time.cos()];
26 sig.set_value(&values).unwrap();
27 if debug_sig.get_status().was_set_remote() {
28 println!(
29 "Received debug message: {:?}",
30 debug_sig.get_value::<f64>().unwrap().0
31 );
32 }
33 }
34}
Sourcepub fn get_signals(&self, direction: mpr_dir) -> Vec<Signal>
pub fn get_signals(&self, direction: mpr_dir) -> Vec<Signal>
Get a list of all signals owned by this device.
Examples found in repository?
10fn main() {
11 let graph = Graph::create();
12 let mut count = 0;
13
14 // Have to subscribe to all devices first in order to discover devices we don't own!
15 graph.subscribe(None, &[mpr_type::MPR_DEV, mpr_type::MPR_SIG]);
16
17 loop {
18
19 graph.poll_and_block(Duration::from_millis(100));
20 let list = graph.get_devices();
21
22 if list.len() != 0 {
23 for dev in list {
24 println!("Device: {}", dev.get_property_str(mpr_prop::MPR_PROP_NAME).unwrap());
25 let signals = dev.get_signals(libmapper_rs::constants::mpr_dir::MPR_DIR_ANY);
26 for sig in signals {
27 println!("\tSignal: {}", sig.get_property_str(mpr_prop::MPR_PROP_NAME).unwrap());
28 println!("\t\tType: {:?}", sig.get_property::<mpr_type>(mpr_prop::MPR_PROP_TYPE).unwrap());
29 println!("\t\tVector Length: {:?}", sig.get_vector_length());
30 println!("\t\tMin: {:?}", sig.get_property::<f32>(mpr_prop::MPR_PROP_MIN));
31 println!("\t\tMax: {:?}", sig.get_property::<f32>(mpr_prop::MPR_PROP_MAX));
32 println!("\t\tUnit: {:?}", sig.get_property_str(mpr_prop::MPR_PROP_UNIT));
33 println!("\t\tNum instances: {:?}", sig.get_property::<i32>(mpr_prop::MPR_PROP_NUM_INST).unwrap());
34 println!("");
35 }
36 }
37 break;
38 }
39
40 println!("Loop {}", count);
41 count += 1;
42 }
43
44}