diff --git a/dgl/EventHandlers.hpp b/dgl/EventHandlers.hpp index 3545a2c5..4cf0545b 100644 --- a/dgl/EventHandlers.hpp +++ b/dgl/EventHandlers.hpp @@ -120,6 +120,9 @@ public: KnobEventHandler& operator=(const KnobEventHandler& other); virtual ~KnobEventHandler(); + // if setStep(1) has been called before, this returns true + bool isInteger() const noexcept; + // returns raw value, is assumed to be scaled if using log float getValue() const noexcept; diff --git a/dgl/src/EventHandlers.cpp b/dgl/src/EventHandlers.cpp index 35666e42..b87f05c6 100644 --- a/dgl/src/EventHandlers.cpp +++ b/dgl/src/EventHandlers.cpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2021 Filipe Coelho + * Copyright (C) 2012-2022 Filipe Coelho * * Permission to use, copy, modify, and/or distribute this software for any purpose with * or without fee is hereby granted, provided that the above copyright notice and this @@ -455,6 +455,11 @@ struct KnobEventHandler::PrivateData { { const float rest = std::fmod(value2, step); value2 -= rest + (rest > step/2.0f ? step : 0.0f); + + if (value2 < minimum) + valueTmp = value2 = minimum; + else if (value2 > maximum) + valueTmp = value2 = maximum; } } @@ -565,6 +570,11 @@ KnobEventHandler::~KnobEventHandler() delete pData; } +bool KnobEventHandler::isInteger() const noexcept +{ + return d_isEqual(pData->step, 1.f); +} + float KnobEventHandler::getValue() const noexcept { return pData->value;