Browse Source

Add KnobEventHandler::isInteger(), avoid out of bounds stepping

pull/321/merge
falkTX 2 years ago
parent
commit
f2cb4e0f0c
2 changed files with 14 additions and 1 deletions
  1. +3
    -0
      dgl/EventHandlers.hpp
  2. +11
    -1
      dgl/src/EventHandlers.cpp

+ 3
- 0
dgl/EventHandlers.hpp View File

@@ -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;



+ 11
- 1
dgl/src/EventHandlers.cpp View File

@@ -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;


Loading…
Cancel
Save