Hi there!
in the current version of iPlug2, when you use the IParam::InitFrequency
function, it always displays frequency in Hz. Just sharing the below which can implement changing to kHz on demand:
GetParam(kParamFreq)->InitDouble("Freq", 200., 10., 22000.0, 1., "", 0, "", IParam::ShapeExp(), IParam::kUnitCustom
, [](double val, WDL_String& str) {
const bool gte1k = val >= 1000.;
const char* units = gte1k? "kHz" : "Hz";
if (gte1k) val *= 0.001;
str.SetFormatted(MAX_PARAM_DISPLAY_LEN, "%.2f %s", val, units);
});
What do people think about this type of behavior becoming the default? Not necessarily with this implementation (which just works around the existing limitation) but something more core to the library?
Thanks.
1 Like
And customize number of decimals, depending on a value? 
You could do that yourself pretty easily. But of course, an official implementation should do that.
The great thing about iPlug2 is that you can fork it and do what you like to it.
Of course we like PRs and merge some of them, but as library maintainers we have responsibilities not to suddenly change behaviours that might influence a load of products out in the wild. We have to be mindful of changing any behaviours.
Saying that it’s probably not a bad suggestion to display hz/kHz for frequency parameters. I’d take a look at a PR.
1 Like
I’d be happy to have a go at making one. Thanks @olilarkin!
Implemented as a PR here: Add new InitFrequencyAutoRange initialization function by etheory · Pull Request #1203 · iPlug2/iPlug2 · GitHub for anyone interested (and @John this also takes care of the precision handling automatically).
1 Like