From b4eac526e2bf17909081e28e86d853c2b05eb172 Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 14 Jul 2020 02:36:32 +0100 Subject: [PATCH] Add unused PluginParameterData::getFinalValueWithMidiDelta() Signed-off-by: falkTX --- source/backend/plugin/CarlaPluginInternal.cpp | 65 +++++++++++++++++-- source/backend/plugin/CarlaPluginInternal.hpp | 3 +- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/source/backend/plugin/CarlaPluginInternal.cpp b/source/backend/plugin/CarlaPluginInternal.cpp index b530e3095..57760624f 100644 --- a/source/backend/plugin/CarlaPluginInternal.cpp +++ b/source/backend/plugin/CarlaPluginInternal.cpp @@ -1,6 +1,6 @@ /* * Carla Plugin - * Copyright (C) 2011-2019 Filipe Coelho + * Copyright (C) 2011-2020 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -20,6 +20,7 @@ #include "CarlaLibCounter.hpp" #include "CarlaMathUtils.hpp" +#include "CarlaMIDI.h" CARLA_BACKEND_START_NAMESPACE @@ -311,9 +312,10 @@ static float _getUnnormalizedLogValue(const float min, const float max, const fl return rmin * std::pow(max/rmin, value); } -float PluginParameterData::getFinalUnnormalizedValue(const uint32_t parameterId, float value) const noexcept +float PluginParameterData::getFinalUnnormalizedValue(const uint32_t parameterId, + const float normalizedValue) const noexcept { - float min, max; + float min, max, value; if (data[parameterId].mappedControlIndex != CONTROL_INDEX_CV && (data[parameterId].hints & PARAMETER_MAPPED_RANGES_SET) != 0x0) @@ -329,14 +331,14 @@ float PluginParameterData::getFinalUnnormalizedValue(const uint32_t parameterId, if (data[parameterId].hints & PARAMETER_IS_BOOLEAN) { - value = (value < 0.5f) ? min : max; + value = (normalizedValue < 0.5f) ? min : max; } else { if (data[parameterId].hints & PARAMETER_IS_LOGARITHMIC) - value = _getUnnormalizedLogValue(min, max, value); + value = _getUnnormalizedLogValue(min, max, normalizedValue); else - value = _getUnnormalizedValue(min, max, value); + value = _getUnnormalizedValue(min, max, normalizedValue); if (data[parameterId].hints & PARAMETER_IS_INTEGER) value = std::rint(value); @@ -345,6 +347,57 @@ float PluginParameterData::getFinalUnnormalizedValue(const uint32_t parameterId, return value; } +float PluginParameterData::getFinalValueWithMidiDelta(const uint32_t parameterId, + float value, int8_t delta) const noexcept +{ + if (delta < 0) + return value; + if (data[parameterId].mappedControlIndex <= 0 || data[parameterId].mappedControlIndex >= MAX_MIDI_CONTROL) + return value; + + float min, max; + + if ((data[parameterId].hints & PARAMETER_MAPPED_RANGES_SET) != 0x0) + { + min = data[parameterId].mappedMinimum; + max = data[parameterId].mappedMaximum; + } + else + { + min = ranges[parameterId].min; + max = ranges[parameterId].max; + } + + if (data[parameterId].hints & PARAMETER_IS_BOOLEAN) + { + value = delta > 63 ? min : max; + } + else + { + if (data[parameterId].hints & PARAMETER_IS_INTEGER) + { + if (delta > 63) + value += delta - 128.0f; + else + value += delta; + } + else + { + if (delta > 63) + delta = delta - 128; + + value += (max - min) * (static_cast(delta) / 127.0f); + } + + if (value < min) + value = min; + else if (value > max) + value = max; + } + + return value; +} + // ----------------------------------------------------------------------- // PluginProgramData diff --git a/source/backend/plugin/CarlaPluginInternal.hpp b/source/backend/plugin/CarlaPluginInternal.hpp index 4e93a2363..507033fd3 100644 --- a/source/backend/plugin/CarlaPluginInternal.hpp +++ b/source/backend/plugin/CarlaPluginInternal.hpp @@ -182,7 +182,8 @@ struct PluginParameterData { void createNew(uint32_t newCount, bool withSpecial); void clear() noexcept; float getFixedValue(uint32_t parameterId, float value) const noexcept; - float getFinalUnnormalizedValue(uint32_t parameterId, float value) const noexcept; + float getFinalUnnormalizedValue(uint32_t parameterId, float normalizedValue) const noexcept; + float getFinalValueWithMidiDelta(uint32_t parameterId, float value, int8_t delta) const noexcept; CARLA_DECLARE_NON_COPY_STRUCT(PluginParameterData) };