commit f2cb4e0f0c6fc901dcbff3fcbd02aec2aa0b9fb2
parent 3857d83acd411ffee53d31537bfad45eed652c72
Author: falkTX <falktx@falktx.com>
Date: Thu, 25 Aug 2022 08:40:01 +0100
Add KnobEventHandler::isInteger(), avoid out of bounds stepping
Diffstat:
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git 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
@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
- * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
+ * Copyright (C) 2012-2022 Filipe Coelho <falktx@falktx.com>
*
* 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;