Struct libmapper_rs::signal::Signal
source · 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;
fn main_loop(dev: &Device, sig: &mut Signal, value: &mut f64) {
loop {
dev.poll_and_block(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?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn main() {
let dev = Device::create("rustmapper");
loop {
dev.poll_and_block(10);
if dev.is_ready() {
break;
}
}
println!("Device became ready!");
let mut sig = dev.create_vector_signal::<f64>("test_sin", mpr_dir::MPR_DIR_OUT, 2);
let debug_sig = dev.create_vector_signal::<f64>("debug_msg", mpr_dir::MPR_DIR_IN, 2);
loop {
dev.poll_and_block(100);
let time = (SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis() as u64) as f64
/ 1000f64;
let values = [time.sin(), time.cos()];
sig.set_value(&values).unwrap();
if debug_sig.get_status().was_set_remote() {
println!(
"Received debug message: {:?}",
debug_sig.get_value::<f64>().unwrap().0
);
}
}
}
More examples
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
fn main() {
let dev = Device::create("rustmapper");
loop {
dev.poll_and_block(10);
if dev.is_ready() {
break;
}
}
println!("Device became ready!");
let mut sig = dev.create_signal::<f64>("test_sin", mpr_dir::MPR_DIR_OUT);
sig.set_property(mpr_prop::MPR_PROP_MIN, -1.0);
sig.set_property(mpr_prop::MPR_PROP_MAX, 1.0);
let debug_sig = dev.create_signal::<f64>("debug_msg", mpr_dir::MPR_DIR_IN);
assert!(debug_sig.get_property::<f64>(mpr_prop::MPR_PROP_MIN).is_none());
loop {
dev.poll_and_block(100);
let time = ((SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis() as u64) as f64
/ 1000f64)
.sin();
sig.set_value_single(&time).unwrap();
if debug_sig.get_status().was_set_remote() {
println!(
"Received debug message: {:?}",
debug_sig.get_value_single::<f64>().unwrap()
);
}
}
}
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.
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?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
pub fn main() {
let dev = Device::create("rustmapper");
loop {
dev.poll_and_block(10);
if dev.is_ready() {
break;
}
}
println!("Device became ready!");
let mut sig_a =
dev.create_signal::<i32>("output", libmapper_rs::constants::mpr_dir::MPR_DIR_OUT);
let sig_b = dev.create_signal::<i32>("input", libmapper_rs::constants::mpr_dir::MPR_DIR_IN);
let map = Map::create(&sig_a, &sig_b);
map.push();
loop {
dev.poll_and_block(100);
if map.is_ready() {
break;
}
}
println!("Map created!");
for i in 0..100 {
sig_a.set_value_single(&i).unwrap();
dev.poll_and_block(10);
let val = sig_b
.get_value_single::<i32>()
.expect("Signal didn't send!");
println!("Sent: {}, Received: {}", i, val.0);
assert_eq!(i, val.0)
}
}
More examples
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
fn main() {
let dev = Device::create("rustmapper");
loop {
dev.poll_and_block(10);
if dev.is_ready() {
break;
}
}
println!("Device became ready!");
let mut sig = dev.create_signal::<f64>("test_sin", mpr_dir::MPR_DIR_OUT);
sig.set_property(mpr_prop::MPR_PROP_MIN, -1.0);
sig.set_property(mpr_prop::MPR_PROP_MAX, 1.0);
let debug_sig = dev.create_signal::<f64>("debug_msg", mpr_dir::MPR_DIR_IN);
assert!(debug_sig.get_property::<f64>(mpr_prop::MPR_PROP_MIN).is_none());
loop {
dev.poll_and_block(100);
let time = ((SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis() as u64) as f64
/ 1000f64)
.sin();
sig.set_value_single(&time).unwrap();
if debug_sig.get_status().was_set_remote() {
println!(
"Received debug message: {:?}",
debug_sig.get_value_single::<f64>().unwrap()
);
}
}
}
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?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
pub fn main() {
let dev = Device::create("rustmapper");
loop {
dev.poll_and_block(10);
if dev.is_ready() {
break;
}
}
println!("Device became ready!");
let mut sig_a =
dev.create_signal::<i32>("output", libmapper_rs::constants::mpr_dir::MPR_DIR_OUT);
let sig_b = dev.create_signal::<i32>("input", libmapper_rs::constants::mpr_dir::MPR_DIR_IN);
let map = Map::create(&sig_a, &sig_b);
map.push();
loop {
dev.poll_and_block(100);
if map.is_ready() {
break;
}
}
println!("Map created!");
for i in 0..100 {
sig_a.set_value_single(&i).unwrap();
dev.poll_and_block(10);
let val = sig_b
.get_value_single::<i32>()
.expect("Signal didn't send!");
println!("Sent: {}, Received: {}", i, val.0);
assert_eq!(i, val.0)
}
}
More examples
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
fn main() {
let dev = Device::create("rustmapper");
loop {
dev.poll_and_block(10);
if dev.is_ready() {
break;
}
}
println!("Device became ready!");
let mut sig = dev.create_signal::<f64>("test_sin", mpr_dir::MPR_DIR_OUT);
sig.set_property(mpr_prop::MPR_PROP_MIN, -1.0);
sig.set_property(mpr_prop::MPR_PROP_MAX, 1.0);
let debug_sig = dev.create_signal::<f64>("debug_msg", mpr_dir::MPR_DIR_IN);
assert!(debug_sig.get_property::<f64>(mpr_prop::MPR_PROP_MIN).is_none());
loop {
dev.poll_and_block(100);
let time = ((SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis() as u64) as f64
/ 1000f64)
.sin();
sig.set_value_single(&time).unwrap();
if debug_sig.get_status().was_set_remote() {
println!(
"Received debug message: {:?}",
debug_sig.get_value_single::<f64>().unwrap()
);
}
}
}
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?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn main() {
let dev = Device::create("rustmapper");
loop {
dev.poll_and_block(10);
if dev.is_ready() {
break;
}
}
println!("Device became ready!");
let mut sig = dev.create_vector_signal::<f64>("test_sin", mpr_dir::MPR_DIR_OUT, 2);
let debug_sig = dev.create_vector_signal::<f64>("debug_msg", mpr_dir::MPR_DIR_IN, 2);
loop {
dev.poll_and_block(100);
let time = (SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis() as u64) as f64
/ 1000f64;
let values = [time.sin(), time.cos()];
sig.set_value(&values).unwrap();
if debug_sig.get_status().was_set_remote() {
println!(
"Received debug message: {:?}",
debug_sig.get_value::<f64>().unwrap().0
);
}
}
}
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?
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn main() {
let dev = Device::create("rustmapper");
loop {
dev.poll_and_block(10);
if dev.is_ready() {
break;
}
}
println!("Device became ready!");
let mut sig = dev.create_vector_signal::<f64>("test_sin", mpr_dir::MPR_DIR_OUT, 2);
let debug_sig = dev.create_vector_signal::<f64>("debug_msg", mpr_dir::MPR_DIR_IN, 2);
loop {
dev.poll_and_block(100);
let time = (SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_millis() as u64) as f64
/ 1000f64;
let values = [time.sin(), time.cos()];
sig.set_value(&values).unwrap();
if debug_sig.get_status().was_set_remote() {
println!(
"Received debug message: {:?}",
debug_sig.get_value::<f64>().unwrap().0
);
}
}
}
Trait Implementations§
source§impl AsMprObject for Signal
impl AsMprObject for Signal
fn as_mpr_object(&self) -> *mut c_void
impl Send for Signal
impl Sync for Signal
Auto Trait Implementations§
impl Freeze for Signal
impl RefUnwindSafe for Signal
impl Unpin for Signal
impl UnwindSafe for Signal
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
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,
source§fn set_property_str(&self, property: mpr_prop, value: &str)
fn set_property_str(&self, property: mpr_prop, value: &str)
source§fn get_property<T>(&self, property: mpr_prop) -> Option<T>
fn get_property<T>(&self, property: mpr_prop) -> Option<T>
None
.