From cfdb181f3725c7606f61685604c940e5a497601b Mon Sep 17 00:00:00 2001 From: falkTX Date: Wed, 15 Jan 2020 20:51:23 +0000 Subject: [PATCH] Add safety checks around CV control ranges Signed-off-by: falkTX --- source/backend/plugin/CarlaPlugin.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/source/backend/plugin/CarlaPlugin.cpp b/source/backend/plugin/CarlaPlugin.cpp index 6bf7c4075..7ff436577 100644 --- a/source/backend/plugin/CarlaPlugin.cpp +++ b/source/backend/plugin/CarlaPlugin.cpp @@ -1736,11 +1736,10 @@ void CarlaPlugin::setParameterMappedControlIndex(const uint32_t parameterId, con if (paramData.mappedControlIndex == index) return; + const ParameterRanges& paramRanges(pData->param.ranges[parameterId]); + if ((paramData.hints & PARAMETER_MAPPED_RANGES_SET) == 0x0) - { - ParameterRanges& paramRanges(pData->param.ranges[parameterId]); setParameterMappedRange(parameterId, paramRanges.min, paramRanges.max, true, true); - } #ifndef BUILD_BRIDGE_ALTERNATIVE_ARCH char strBuf[STR_MAX+1]; @@ -1770,6 +1769,15 @@ void CarlaPlugin::setParameterMappedControlIndex(const uint32_t parameterId, con CARLA_SAFE_ASSERT(pData->client->removePort(kEnginePortTypeCV, strBuf, true)); CARLA_SAFE_ASSERT(pData->event.cvSourcePorts->removeCVSource(parameterId)); } + else if (paramData.mappedControlIndex == CONTROL_INDEX_NONE) + { + // when doing MIDI CC mapping, ensure ranges are within bounds + if (paramData.mappedMinimum < paramRanges.min || paramData.mappedMaximum > paramRanges.max) + setParameterMappedRange(parameterId, + std::max(paramData.mappedMinimum, paramRanges.min), + std::min(paramData.mappedMaximum, paramRanges.max), + true, true); + } #endif paramData.mappedControlIndex = index; @@ -1800,6 +1808,13 @@ void CarlaPlugin::setParameterMappedRange(const uint32_t parameterId, const floa (paramData.hints & PARAMETER_MAPPED_RANGES_SET) != 0x0) return; + if (paramData.mappedControlIndex != CONTROL_INDEX_NONE && paramData.mappedControlIndex != CONTROL_INDEX_CV) + { + const ParameterRanges& paramRanges(pData->param.ranges[parameterId]); + CARLA_SAFE_ASSERT_RETURN(minimum >= paramRanges.min,); + CARLA_SAFE_ASSERT_RETURN(maximum <= paramRanges.max,); + } + paramData.hints |= PARAMETER_MAPPED_RANGES_SET; paramData.mappedMinimum = minimum; paramData.mappedMaximum = maximum;