diff --git a/src/params.rs b/src/params.rs index 1b501223..0a978940 100644 --- a/src/params.rs +++ b/src/params.rs @@ -96,11 +96,19 @@ macro_rules! impl_plainparam { } /// Get the string representation for a normalized value. Used as part of the wrappers. - pub fn normalized_value_to_string(&self, normalized: f32) -> String { + /// Most plugin formats already have support for units, in which case it shouldn't be + /// part of this string or some DAWs may show duplicate units. + pub fn normalized_value_to_string( + &self, + normalized: f32, + include_unit: bool, + ) -> String { let value = self.range.unnormalize(normalized); - match &self.value_to_string { - Some(f) => format!("{}{}", f(value), self.unit), - None => format!("{}{}", value, self.unit), + match (&self.value_to_string, include_unit) { + (Some(f), true) => format!("{}{}", f(value), self.unit), + (Some(f), false) => format!("{}", f(value)), + (None, true) => format!("{}{}", value, self.unit), + (None, false) => format!("{}", value), } } @@ -292,16 +300,18 @@ impl ParamPtr { } } - /// Get the string representation for a normalized value. Used as part of the wrappers. + /// Get the string representation for a normalized value. Used as part of the wrappers. Most + /// plugin formats already have support for units, in which case it shouldn't be part of this + /// string or some DAWs may show duplicate units. /// /// # Safety /// /// Calling this function is only safe as long as the object this `ParamPtr` was created for is /// still alive. - pub unsafe fn normalized_value_to_string(&self, normalized: f32) -> String { + pub unsafe fn normalized_value_to_string(&self, normalized: f32, include_unit: bool) -> String { match &self { - ParamPtr::FloatParam(p) => (**p).normalized_value_to_string(normalized), - ParamPtr::IntParam(p) => (**p).normalized_value_to_string(normalized), + ParamPtr::FloatParam(p) => (**p).normalized_value_to_string(normalized, include_unit), + ParamPtr::IntParam(p) => (**p).normalized_value_to_string(normalized, include_unit), } } diff --git a/src/wrapper/vst3.rs b/src/wrapper/vst3.rs index 8c0606f5..1ba45fcb 100644 --- a/src/wrapper/vst3.rs +++ b/src/wrapper/vst3.rs @@ -356,7 +356,7 @@ impl IEditController for Wrapper

{ } else if let Some(param_ptr) = self.param_by_hash.get(&id) { u16strlcpy( dest, - ¶m_ptr.normalized_value_to_string(value_normalized as f32), + ¶m_ptr.normalized_value_to_string(value_normalized as f32, false), ); kResultOk