From b4412624a9d3288562cac67e3110ee29326a1157 Mon Sep 17 00:00:00 2001 From: Geraint Date: Sun, 22 Jun 2025 13:53:27 +0100 Subject: [PATCH] Parameter changes and correct value displays --- stfx/clap/stfx-clap.h | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/stfx/clap/stfx-clap.h b/stfx/clap/stfx-clap.h index f859135..0777d9a 100644 --- a/stfx/clap/stfx-clap.h +++ b/stfx/clap/stfx-clap.h @@ -148,11 +148,34 @@ struct Plugin : public clap_plugin { std::vector outputBuffers; void processEvent(const clap_event_header *header) { - LOG_EXPR(header->size); - LOG_EXPR(header->time); - LOG_EXPR(header->space_id); - LOG_EXPR(header->type); - LOG_EXPR(header->flags); + if (header->space_id != CLAP_CORE_EVENT_SPACE_ID) return; // only core events supported atm + if (header->type == CLAP_EVENT_PARAM_VALUE) { + auto *event = (clap_event_param_value *)header; + auto *param = (Param *)event->cookie; + if (!param) { + auto paramId = event->param_id; + for (auto &p : params) { + if (p.id == paramId) { + param = &p; + break; + } + } + if (!param) return; // invalid parameter + } else if (param->id != event->param_id) { + return; // inconsistent ID / cookie + } + if (param->rangeParam) { + *param->rangeParam = param->rangeInfo->fromUnit(event->value); + } else { + *param->steppedParam = int(std::round(event->value)); + } + } else { + LOG_EXPR(header->size); + LOG_EXPR(header->time); + LOG_EXPR(header->space_id); + LOG_EXPR(header->type); + LOG_EXPR(header->flags); + } } // CLAP plugin methods @@ -253,7 +276,7 @@ struct Plugin : public clap_plugin { plugin.processEvent(event); ++nextEventIndex; } - } + } inputBuffers.resize(0); outputBuffers.resize(0); return CLAP_PROCESS_CONTINUE; @@ -361,7 +384,7 @@ struct Plugin : public clap_plugin { for (auto ¶m : plugin.params) { if (param.id == paramId) { if (param.rangeParam) { - auto str = param.rangeInfo->toString(value); + auto str = param.rangeInfo->toString(param.rangeInfo->fromUnit(value)); std::strncpy(text, str.c_str(), textCapacity); } else { auto str = param.steppedInfo->toString(int(std::round(value)));