Skip to content

Commit

Permalink
off by one error in value conversion (#301)
Browse files Browse the repository at this point in the history
  • Loading branch information
defiantnerd authored Sep 5, 2024
1 parent e82e4d7 commit c4167b8
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/detail/vst3/parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <clap/ext/params.h>
#include <public.sdk/source/vst/vstparameters.h>
#include <functional>
#include <cmath>

class Vst3Parameter : public Steinberg::Vst::Parameter
{
Expand All @@ -50,11 +51,15 @@ class Vst3Parameter : public Steinberg::Vst::Parameter
bool fromString(const Steinberg::Vst::TChar* string, Steinberg::Vst::ParamValue& valueNormalized) const override;
#endif

// for asClapValue() and asVst3Value()
// regarding conversion and the meaning of stepCount take a look here:
// https://steinbergmedia.github.io/vst3_dev_portal/pages/Technical+Documentation/Parameters+Automation/Index.html#conversion-of-normalized-values

inline double asClapValue(double vst3value) const
{
if (info.stepCount > 0)
{
return (vst3value * info.stepCount + 1) + min_value;
return (vst3value * info.stepCount) + min_value;
}
return (vst3value * (max_value - min_value)) + min_value;
}
Expand All @@ -63,7 +68,7 @@ class Vst3Parameter : public Steinberg::Vst::Parameter
auto& info = this->getInfo();
if (info.stepCount > 0)
{
return (clapvalue - min_value) / float(info.stepCount + 1);
return floor(clapvalue - min_value) / float(info.stepCount);
}
return (clapvalue - min_value) / (max_value - min_value);
}
Expand Down

0 comments on commit c4167b8

Please sign in to comment.