Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

off by one error in value conversion #301

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading