pub struct Signal { /* private fields */ }
Implementations§
Source§impl Signal
impl Signal
Sourcepub fn get_status(&self) -> SignalStatus
pub fn get_status(&self) -> SignalStatus
Get the status of the signal instance.
Calling this function will reset the flags was_set_remote
and was_set_local
and return their pre-reset values.
§Examples
Use this function to check if you should push or read data from the signal:
use libmapper_rs::device::Device;
use libmapper_rs::signal::Signal;
use std::time::Duration;
fn main_loop(dev: &Device, sig: &mut Signal, value: &mut f64) {
loop {
dev.poll_and_block(Duration::from_millis(10));
if sig.get_status().was_set_remote() { // check if there's a new value waiting for us
let (new_value, _) = sig.get_value_single::<f64>().unwrap();
*value = new_value;
} else {
sig.set_value_single(value);
}
}
}
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}
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}
Sourcepub fn get_data_type(&self) -> mpr_type
pub fn get_data_type(&self) -> mpr_type
Get the type of data this signal is storing.
Sourcepub fn get_vector_length(&self) -> u32
pub fn get_vector_length(&self) -> u32
Get the length of the vector this signal is storing. This will be how long the slice returned from Signal::get_value is.
If this is 1, you should use Signal::get_value_single instead.
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}
Source§impl Signal
impl Signal
Sourcepub fn set_value_single<T: MappableType + Copy>(
&mut self,
value: &T,
) -> Result<(), SignalError>
pub fn set_value_single<T: MappableType + Copy>( &mut self, value: &T, ) -> Result<(), SignalError>
Set the value of the signal.
This function will return SignalError::WrongType
if the passed generic type doesn’t match the signal’s type.
If this signal is a vector, only the first element of the vector will be set.
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}
Sourcepub fn get_value_single<T: MappableType + Copy>(
&self,
) -> Result<(T, u64), SignalError>
pub fn get_value_single<T: MappableType + Copy>( &self, ) -> Result<(T, u64), SignalError>
Get the value of the signal.
This function will return SignalError::WrongType
if the passed generic type doesn’t match the signal’s type.
If this signal is a vector, only the first element of the vector will be returned.
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}
Sourcepub fn get_value<T: MappableType + Copy>(
&self,
) -> Result<(Vec<T>, u64), SignalError>
pub fn get_value<T: MappableType + Copy>( &self, ) -> Result<(Vec<T>, u64), SignalError>
Get the value of the signal.
This function will return SignalError::WrongType
if the passed generic type doesn’t match the signal’s type.
The length of the returned slice will be equal to the value returned by get_vector_length.
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 set_value<T: MappableType + Copy>(
&mut self,
values: &[T],
) -> Result<(), SignalError>
pub fn set_value<T: MappableType + Copy>( &mut self, values: &[T], ) -> Result<(), SignalError>
Set the value of the signal.
This function will return SignalError::WrongType
if the passed generic type doesn’t match the signal’s type.
The length of the slice must be equal to the value returned by get_vector_length.
If the lengths are not equal this function return an Err
of SignalError::WrongLengthArg
.
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_direction(&self) -> mpr_dir
pub fn get_direction(&self) -> mpr_dir
Get the direction of the signal. This value determines how signal data can flow to/from this signal.
For example, you cannot map to a signal with direction MPR_DIR_OUT
.