Skip to main content

scanner/
scanner.rs

1//! # Example: Scan
2//! Will print a tree of all devices and signals found on the network.
3
4use std::time::Duration;
5
6use libmapper_rs::{constants::{mpr_prop, mpr_type}, graph::Graph, object::MapperObject};
7
8/// Prints out a list of all device names found on the network
9
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.poll_and_block(Duration::from_millis(100));
16  graph.subscribe(None, &[mpr_type::MPR_DEV, mpr_type::MPR_SIG]);
17  graph.poll_and_block(Duration::from_millis(100)); // poll before and after to ensure discovery
18
19  loop {
20
21    graph.poll_and_block(Duration::from_millis(100));
22    let list = graph.get_devices();
23
24    if list.len() != 0 {
25      for dev in list {
26        println!("Device: {}", dev.get_property_str(mpr_prop::MPR_PROP_NAME).unwrap());
27        let signals = dev.get_signals(libmapper_rs::constants::mpr_dir::MPR_DIR_ANY);
28        for sig in signals {
29          println!("\tSignal: {}", sig.get_property_str(mpr_prop::MPR_PROP_NAME).unwrap());
30          println!("\t\tType: {:?}", sig.get_property::<mpr_type>(mpr_prop::MPR_PROP_TYPE).unwrap());
31          println!("\t\tVector Length: {:?}", sig.get_vector_length());
32          println!("\t\tMin: {:?}", sig.get_property::<f32>(mpr_prop::MPR_PROP_MIN));
33          println!("\t\tMax: {:?}", sig.get_property::<f32>(mpr_prop::MPR_PROP_MAX));
34          println!("\t\tUnit: {:?}", sig.get_property_str(mpr_prop::MPR_PROP_UNIT));
35          println!("\t\tNum instances: {:?}", sig.get_property::<i32>(mpr_prop::MPR_PROP_NUM_INST).unwrap());
36          println!("");
37        }
38      }
39      break;
40    }
41    
42    println!("Loop {}", count);
43    count += 1;
44  }
45  
46}