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.
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.
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.
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.
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);
}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.
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.