From 211d86f5e9a1490f5fbbe280690fc05329961899 Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Sun, 12 Jan 2025 21:56:16 +0100 Subject: [PATCH] implemented vst3 controller get/set state --- templates/vst3/src/vst3.c | 47 ++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/templates/vst3/src/vst3.c b/templates/vst3/src/vst3.c index f695277..7c1f34f 100644 --- a/templates/vst3/src/vst3.c +++ b/templates/vst3/src/vst3.c @@ -1536,19 +1536,50 @@ static Steinberg_tresult controllerSetComponentState(void* thisInterface, struct } static Steinberg_tresult controllerSetState(void* thisInterface, struct Steinberg_IBStream* state) { - (void)thisInterface; - (void)state; - TRACE("controller set state\n"); - return Steinberg_kNotImplemented; + if (state == NULL) + return Steinberg_kResultFalse; +#if DATA_PRODUCT_PARAMETERS_N > 0 + controller *c = (controller *)((char *)thisInterface - offsetof(controller, vtblIEditController)); + for (size_t i = 0; i < DATA_PRODUCT_PARAMETERS_N; i++) { + if (parameterInfo[i].flags & Steinberg_Vst_ParameterInfo_ParameterFlags_kIsReadOnly) + continue; + union { float f; uint32_t u; } v; + Steinberg_int32 n; + state->lpVtbl->read(state, &v, 4, &n); + if (n != 4) + return Steinberg_kResultFalse; + if (IS_BIG_ENDIAN) + v.u = SWAP_UINT32(v.u); + c->parameters[i] = parameterAdjust(i, v.f); + if (c->views) + for (size_t j = 0; j < c->viewsCount; j++) + plugViewUpdateParameter(c->views[j], i); + } +#endif + return Steinberg_kResultOk; } static Steinberg_tresult controllerGetState(void* thisInterface, struct Steinberg_IBStream* state) { - (void)thisInterface; - (void)state; - TRACE("controller get state\n"); - return Steinberg_kNotImplemented; + if (state == NULL) + return Steinberg_kResultFalse; +#if DATA_PRODUCT_PARAMETERS_N > 0 + controller *c = (controller *)((char *)thisInterface - offsetof(controller, vtblIEditController)); + for (size_t i = 0; i < DATA_PRODUCT_PARAMETERS_N; i++) { + if (parameterInfo[i].flags & Steinberg_Vst_ParameterInfo_ParameterFlags_kIsReadOnly) + continue; + union { float f; uint32_t u; } v; + v.f = c->parameters[i]; + if (IS_BIG_ENDIAN) + v.u = SWAP_UINT32(v.u); + Steinberg_int32 n; + state->lpVtbl->write(state, &v, 4, &n); + if (n != 4) + return Steinberg_kResultFalse; + } +#endif + return Steinberg_kResultOk; } static Steinberg_int32 controllerGetParameterCount(void* thisInterface) {