Skip to content

Commit

Permalink
Trying to fix MetricParameter constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 committed Jan 9, 2025
1 parent 3802b9b commit ef2eff3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,42 @@

namespace chowdsp
{
MetricParameter::MetricParameter (const ParameterID& parameterID,
const juce::String& paramName,
const juce::NormalisableRange<float>& paramRange,
float defaultValue,
const juce::String& unitSuffix,
int numDecimalPlaces)
: MetricParameter (
parameterID,
paramName,
paramRange,
defaultValue,
[numDecimalPlaces, unitSuffix] (float v)
{ return toString (v, numDecimalPlaces) + unitSuffix; })
{
}

MetricParameter::MetricParameter (
const ParameterID& parameterID,
const juce::String& paramName,
const juce::NormalisableRange<float>& paramRange,
float defaultValue,
const std::function<juce::String (float)>& valueToTextFunction,
std::function<float (const juce::String&)>&& textToValueFunction)
: FloatParameter (
parameterID,
paramName,
paramRange,
defaultValue,
valueToTextFunction,
textToValueFunction != nullptr
? std::move (textToValueFunction)
: [] (const juce::String& str)
{ return fromString (str); })
{
}

juce::String MetricParameter::toString (float value, int numDecimalPlaces)
{
if (value < 1.0e-9f) // pico
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,15 @@ class MetricParameter : public FloatParameter
const juce::NormalisableRange<float>& paramRange,
float defaultValue,
const juce::String& unitSuffix = {},
int numDecimalPlaces = 2)
: MetricParameter (
parameterID,
paramName,
paramRange,
defaultValue,
[numDecimalPlaces, unitSuffix] (float v)
{ return toString (v, numDecimalPlaces) + unitSuffix; })
{
}
int numDecimalPlaces = 2);

MetricParameter (
const ParameterID& parameterID,
const juce::String& paramName,
const juce::NormalisableRange<float>& paramRange,
float defaultValue,
const std::function<juce::String (float)>& valueToTextFunction,
std::function<float (const juce::String&)>&& textToValueFunction = [] (const juce::String& str)
{ return fromString (str); })
: FloatParameter (
parameterID,
paramName,
paramRange,
defaultValue,
valueToTextFunction,
std::move (textToValueFunction))
{
}
std::function<float (const juce::String&)>&& textToValueFunction = nullptr);

static juce::String toString (float value, int numDecimalPlaces);
static float fromString (const juce::String& str);
Expand Down

0 comments on commit ef2eff3

Please sign in to comment.