diff --git a/src/params.rs b/src/params.rs index 537f332d..b9ee9771 100644 --- a/src/params.rs +++ b/src/params.rs @@ -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; diff --git a/src/params/boolean.rs b/src/params/boolean.rs index b3b91b34..97f28570 100644 --- a/src/params/boolean.rs +++ b/src/params/boolean.rs @@ -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 {} diff --git a/src/params/enums.rs b/src/params/enums.rs index 817bdc3e..5fb5e0da 100644 --- a/src/params/enums.rs +++ b/src/params/enums.rs @@ -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 Display for EnumParam { 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 Debug for EnumParam { + 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 super::Sealed for EnumParam {} diff --git a/src/params/float.rs b/src/params/float.rs index 572de863..479361b4 100644 --- a/src/params/float.rs +++ b/src/params/float.rs @@ -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 {} diff --git a/src/params/integer.rs b/src/params/integer.rs index 5f0e3b9f..e8d3d39b 100644 --- a/src/params/integer.rs +++ b/src/params/integer.rs @@ -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 {}