I have a knob for controlling PWM of an LFO, which default to a range from 0.01 (1%) to 0.99 (99%). However I have a context-menu where different ranges can be selected. To facilitat this I’ve made a PwmRangeQuantity which allows different ranges to be set (bascially it just changes minValue and maxValue of the ParamQuantity
struct PwmRangeQuantity : ParamQuantity {
enum pwmRange { pwm_01_99, pwm_05_95, pwm_10_90, pwm_15_85, pwm_20_80, pwm_25_75 };
PwmRangeQuantity() {
minValue = 0.01f;
maxValue = 0.99f;
defaultValue = 0.5f;
}
void setRange(float minRange = 0.01f, float maxRange = 0.99f) {
float currValue = getValue();
// Set new range, and clamp value to range
this->minValue = minRange;
this->maxValue = maxRange;
setValue(currValue);
}
void setRange(pwmRange range) {
const float minPwmRange[]{ 0.01f, 0.05f, 0.10f, 0.15f, 0.20f, 0.25f };
const float maxPwmRange[]{ 0.99f, 0.95f, 0.90f, 0.85f, 0.80f, 0.75f };
setRange(minPwmRange[range], maxPwmRange[range]);
}
void reset() override {
setRange(0.01f, 0.99f);
setValue(defaultValue);
}
float getDisplayValue() override {
unit = " %";
displayMultiplier = 100.f;
return ParamQuantity::getDisplayValue();
}
};
If the knob (param) is dialed to 99% (with a range from 1% to 99%) and I select another range (calling the setRange method of my PwmRangeQuantity struct), the visual knob keeps its current position, but the value of the knob/param is changed to 75%, which is just perfect.
However if I change the range back to the range 1% to 99%, the visual knob is still turned fully clockwise, which with the new range should be 99%. The parameter is still correctly “read” as 75% when calling getValue of the param, however I had expected the knob (RoundSmallBlackKnob) to turn a bit couter-clockwise to the 75% position
float pwmValue = params[PWMKNOB_PARAM].getValue();
Perhaps I have addressed this wrongly? I have no problem with the actual min/max of the param to stay fixed at 0.01 to 0.99 (or -1 to +1 or whatever) as long as the tool-tip shows the “correct value” according to the selected range, and right-clicking the knob and enter a value, the knob should set the correct value, but I’m usure how/which methods to override to acomplish this?