Skip to content

Commit 0acf5f0

Browse files
committed
Fix FloatParameter min/max logic
1 parent a718899 commit 0acf5f0

2 files changed

Lines changed: 23 additions & 16 deletions

File tree

Source/Processors/Parameter/Parameter.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -620,20 +620,17 @@ FloatParameter::FloatParameter (ParameterOwner* owner,
620620

621621
void FloatParameter::setNextValue (var newValue_, bool undoable)
622622
{
623-
if (newValue_.isDouble())
624-
{
625-
float value = (float) newValue_;
623+
if (newValue_ == currentValue)
624+
return;
626625

627-
if (value < minValue)
628-
newValue = minValue;
629-
else if (value > maxValue)
630-
newValue = maxValue;
631-
else
632-
newValue = value;
633-
}
626+
float value = (float) newValue_;
634627

635-
if (currentValue == newValue)
636-
return;
628+
if (value < minValue)
629+
newValue = minValue;
630+
else if (value > maxValue)
631+
newValue = maxValue;
632+
else
633+
newValue = value;
637634

638635
if (undoable)
639636
{

Source/Processors/Parameter/ParameterEditor.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,20 @@ TextBoxParameterEditor::TextBoxParameterEditor (Parameter* param, int rowHeightP
127127
label->setFont (labelFont);
128128
addAndMakeVisible (label.get());
129129

130-
if (param->getType() == Parameter::FLOAT_PARAM)
131-
valueTextBox = std::make_unique<CustomTextBox> (param->getKey(), String (float (param->getValue())), "0123456789.", ((FloatParameter*) param)->getUnit());
132-
else if (param->getType() == Parameter::INT_PARAM)
133-
valueTextBox = std::make_unique<CustomTextBox> (param->getKey(), String (int (param->getValue())), "0123456789");
130+
if (param->getType() == Parameter::FLOAT_PARAM) {
131+
if (((FloatParameter*) param)->getMinValue() < 0) {
132+
valueTextBox = std::make_unique<CustomTextBox> (param->getKey(), String (float (param->getValue())), "-0123456789.");
133+
} else {
134+
valueTextBox = std::make_unique<CustomTextBox> (param->getKey(), String (float (param->getValue())), "0123456789.");
135+
}
136+
}
137+
else if (param->getType() == Parameter::INT_PARAM) {
138+
if (((IntParameter*) param)->getMinValue() < 0) {
139+
valueTextBox = std::make_unique<CustomTextBox> (param->getKey(), String (int (param->getValue())), "-0123456789");
140+
} else {
141+
valueTextBox = std::make_unique<CustomTextBox> (param->getKey(), String (int (param->getValue())), "0123456789");
142+
}
143+
}
134144
else
135145
valueTextBox = std::make_unique<CustomTextBox> (param->getKey(), param->getValue().toString(), "");
136146

0 commit comments

Comments
 (0)