Implement Debug for parameters
This commit is contained in:
parent
4eb7614ee7
commit
1d9e7e6256
|
@ -5,7 +5,7 @@
|
|||
//! information.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::fmt::Display;
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::sync::Arc;
|
||||
|
||||
use self::internals::ParamPtr;
|
||||
|
@ -73,7 +73,7 @@ pub(crate) use sealed::Sealed;
|
|||
/// abstractions around parameters, consider wrapping them in a struct instead. Then use the
|
||||
/// `#[nested(id_prefix = "foo")]` syntax from the [`Params`] trait to reuse that wrapper in
|
||||
/// multiple places.
|
||||
pub trait Param: Display + sealed::Sealed {
|
||||
pub trait Param: Display + Debug + sealed::Sealed {
|
||||
/// The plain parameter type.
|
||||
type Plain: PartialEq;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Simple boolean parameters.
|
||||
|
||||
use atomic_float::AtomicF32;
|
||||
use std::fmt::Display;
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -61,6 +61,17 @@ impl Display for BoolParam {
|
|||
}
|
||||
}
|
||||
|
||||
impl Debug for BoolParam {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
// This uses the above `Display` instance to show the value
|
||||
if self.value.load(Ordering::Relaxed) != self.unmodulated_value.load(Ordering::Relaxed) {
|
||||
write!(f, "{}: {} (modulated)", &self.name, &self)
|
||||
} else {
|
||||
write!(f, "{}: {}", &self.name, &self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// `Params` can not be implemented outside of NIH-plug itself because `ParamPtr` is also closed
|
||||
impl super::Sealed for BoolParam {}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! Enum parameters. `enum` is a keyword, so `enums` it is.
|
||||
|
||||
use std::fmt::Display;
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -96,7 +96,7 @@ pub struct EnumParamInner {
|
|||
|
||||
impl<T: Enum + PartialEq> Display for EnumParam<T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
self.inner.fmt(f)
|
||||
Display::fmt(&self.inner, f)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,6 +110,23 @@ impl Display for EnumParamInner {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Enum + PartialEq> Debug for EnumParam<T> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
Debug::fmt(&self.inner, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for EnumParamInner {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
// This uses the above `Display` instance to show the value
|
||||
if self.inner.modulated_plain_value() != self.inner.unmodulated_plain_value() {
|
||||
write!(f, "{}: {} (modulated)", &self.name(), &self)
|
||||
} else {
|
||||
write!(f, "{}: {}", &self.name(), &self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// `Params` can not be implemented outside of NIH-plug itself because `ParamPtr` is also closed
|
||||
impl<T: Enum + PartialEq> super::Sealed for EnumParam<T> {}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Continuous (or discrete, with a step size) floating point parameters.
|
||||
|
||||
use atomic_float::AtomicF32;
|
||||
use std::fmt::Display;
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -86,6 +86,17 @@ impl Display for FloatParam {
|
|||
}
|
||||
}
|
||||
|
||||
impl Debug for FloatParam {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
// This uses the above `Display` instance to show the value
|
||||
if self.modulated_plain_value() != self.unmodulated_plain_value() {
|
||||
write!(f, "{}: {} (modulated)", &self.name, &self)
|
||||
} else {
|
||||
write!(f, "{}: {}", &self.name, &self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// `Params` can not be implemented outside of NIH-plug itself because `ParamPtr` is also closed
|
||||
impl super::Sealed for FloatParam {}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! Stepped integer parameters.
|
||||
|
||||
use atomic_float::AtomicF32;
|
||||
use std::fmt::Display;
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::sync::atomic::{AtomicI32, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -78,6 +78,17 @@ impl Display for IntParam {
|
|||
}
|
||||
}
|
||||
|
||||
impl Debug for IntParam {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
// This uses the above `Display` instance to show the value
|
||||
if self.modulated_plain_value() != self.unmodulated_plain_value() {
|
||||
write!(f, "{}: {} (modulated)", &self.name, &self)
|
||||
} else {
|
||||
write!(f, "{}: {}", &self.name, &self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// `Params` can not be implemented outside of NIH-plug itself because `ParamPtr` is also closed
|
||||
impl super::Sealed for IntParam {}
|
||||
|
||||
|
|
Loading…
Reference in a new issue