From b5193900b5b33e8fc9688359979b2414266c14cc Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 28 Nov 2020 01:25:25 +0000 Subject: [PATCH] Do not save/restore lv2 parameter-patch values, intercept restore --- source/backend/CarlaBackend.h | 6 ++ source/backend/plugin/CarlaPlugin.cpp | 5 ++ source/backend/plugin/CarlaPluginInternal.hpp | 6 +- source/backend/plugin/CarlaPluginLV2.cpp | 67 +++++++++++++++++++ source/frontend/carla_backend.py | 4 ++ 5 files changed, 85 insertions(+), 3 deletions(-) diff --git a/source/backend/CarlaBackend.h b/source/backend/CarlaBackend.h index 5035a93e6..fcc30144d 100644 --- a/source/backend/CarlaBackend.h +++ b/source/backend/CarlaBackend.h @@ -341,6 +341,12 @@ static const uint PARAMETER_USES_CUSTOM_TEXT = 0x400; */ static const uint PARAMETER_CAN_BE_CV_CONTROLLED = 0x800; +/*! + * Parameter should not be saved as part of the project/session. + * @note only valid for parameter inputs. + */ +static const uint PARAMETER_IS_NOT_SAVED = 0x1000; + /** @} */ /* ------------------------------------------------------------------------------------------------------------ diff --git a/source/backend/plugin/CarlaPlugin.cpp b/source/backend/plugin/CarlaPlugin.cpp index 2401d88fa..31cedfff3 100644 --- a/source/backend/plugin/CarlaPlugin.cpp +++ b/source/backend/plugin/CarlaPlugin.cpp @@ -604,6 +604,8 @@ const CarlaStateSave& CarlaPlugin::getStateSave(const bool callPrepareForSave) if ((paramData.hints & PARAMETER_IS_ENABLED) == 0) continue; + if (paramData.hints & PARAMETER_IS_NOT_SAVED) + continue; const bool dummy = paramData.type != PARAMETER_INPUT || usingChunk; @@ -750,6 +752,9 @@ void CarlaPlugin::loadStateSave(const CarlaStateSave& stateSave) { for (uint32_t i=0; i < pData->param.count; ++i) { + if (pData->param.data[i].hints & PARAMETER_IS_NOT_SAVED) + continue; + if (getParameterSymbol(i, strBuf)) { ParamSymbol* const paramSymbol(new ParamSymbol(i, strBuf)); diff --git a/source/backend/plugin/CarlaPluginInternal.hpp b/source/backend/plugin/CarlaPluginInternal.hpp index 507033fd3..1d49a3ca1 100644 --- a/source/backend/plugin/CarlaPluginInternal.hpp +++ b/source/backend/plugin/CarlaPluginInternal.hpp @@ -48,9 +48,9 @@ const ushort kPluginMaxMidiEvents = 512; // ----------------------------------------------------------------------- // Extra parameter hints, hidden from backend -const uint PARAMETER_MAPPED_RANGES_SET = 0x1000; -const uint PARAMETER_IS_STRICT_BOUNDS = 0x2000; -const uint PARAMETER_IS_TRIGGER = 0x4000; +const uint PARAMETER_MAPPED_RANGES_SET = 0x10000; +const uint PARAMETER_IS_STRICT_BOUNDS = 0x20000; +const uint PARAMETER_IS_TRIGGER = 0x40000; // ----------------------------------------------------------------------- // Extra plugin hints, hidden from backend diff --git a/source/backend/plugin/CarlaPluginLV2.cpp b/source/backend/plugin/CarlaPluginLV2.cpp index 02a44231b..8a0dee430 100644 --- a/source/backend/plugin/CarlaPluginLV2.cpp +++ b/source/backend/plugin/CarlaPluginLV2.cpp @@ -1512,6 +1512,72 @@ public: if (std::strcmp(type, CUSTOM_DATA_TYPE_PROPERTY) == 0) return CarlaPlugin::setCustomData(type, key, value, sendGui); + // See if this key is from a parameter exposed by carla, apply value if yes + for (uint32_t i=0; i < fRdfDescriptor->ParameterCount; ++i) + { + const LV2_RDF_Parameter& rdfParam(fRdfDescriptor->Parameters[i]); + + if (std::strcmp(rdfParam.URI, key) == 0) + { + uint32_t parameterId = UINT32_MAX; + const int32_t rindex = static_cast(fRdfDescriptor->PortCount + i); + + switch (rdfParam.Type) + { + case LV2_PARAMETER_BOOL: + case LV2_PARAMETER_INT: + // case LV2_PARAMETER_LONG: + case LV2_PARAMETER_FLOAT: + case LV2_PARAMETER_DOUBLE: + for (uint32_t j=0; j < pData->param.count; ++j) + { + if (pData->param.data[j].rindex == rindex) + { + parameterId = j; + break; + } + } + break; + } + + if (parameterId == UINT32_MAX) + break; + + std::vector chunk(carla_getChunkFromBase64String(value)); + CARLA_SAFE_ASSERT_RETURN(chunk.size() > 0,); + +#ifdef CARLA_PROPER_CPP11_SUPPORT + const uint8_t* const valueptr = chunk.data(); +#else + const uint8_t* const valueptr = &chunk.front(); +#endif + float rvalue; + + switch (rdfParam.Type) + { + case LV2_PARAMETER_BOOL: + rvalue = *(const int32_t*)valueptr != 0 ? 1.0f : 0.0f; + break; + case LV2_PARAMETER_INT: + rvalue = static_cast(*(const int32_t*)valueptr); + break; + case LV2_PARAMETER_FLOAT: + rvalue = *(const float*)valueptr; + break; + case LV2_PARAMETER_DOUBLE: + rvalue = static_cast(*(const double*)valueptr); + break; + default: + // making compilers happy + rvalue = pData->param.ranges[parameterId].def; + break; + } + + fParamBuffers[parameterId] = pData->param.getFixedValue(parameterId, rvalue); + break; + } + } + CarlaPlugin::setCustomData(type, key, value, sendGui); } @@ -2965,6 +3031,7 @@ public: pData->param.data[j].type = PARAMETER_INPUT; pData->param.data[j].hints |= PARAMETER_IS_ENABLED; pData->param.data[j].hints |= PARAMETER_IS_AUTOMABLE; + pData->param.data[j].hints |= PARAMETER_IS_NOT_SAVED; needsCtrlIn = true; } else diff --git a/source/frontend/carla_backend.py b/source/frontend/carla_backend.py index d99c45501..e0ec4b5b2 100644 --- a/source/frontend/carla_backend.py +++ b/source/frontend/carla_backend.py @@ -321,6 +321,10 @@ PARAMETER_USES_CUSTOM_TEXT = 0x400 # Parameter can be turned into a CV control. PARAMETER_CAN_BE_CV_CONTROLLED = 0x800 +# Parameter should not be saved as part of the project/session. +# @note only valid for parameter inputs. +PARAMETER_IS_NOT_SAVED = 0x1000 + # --------------------------------------------------------------------------------------------------------------------- # Mapped Parameter Flags # Various flags for parameter mappings.