From fded17eedbabf377ee9541287f9df2505cfd3d67 Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Wed, 10 Jan 2024 15:37:05 +0100 Subject: [PATCH] vst3 map --- templates/lv2/data/manifest.ttl | 8 ++------ templates/vst3/src/data.h | 10 ++++++---- templates/vst3/src/vst3.c | 33 +++++++++++++++++++-------------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/templates/lv2/data/manifest.ttl b/templates/lv2/data/manifest.ttl index b190557..a2abc88 100644 --- a/templates/lv2/data/manifest.ttl +++ b/templates/lv2/data/manifest.ttl @@ -61,14 +61,10 @@ lv2:shortName "{{=p.shortName.substring(0, 16)}}" ; {{?}} lv2:symbol "{{=p.symbol}}" ; -{{?"defaultValue" in p}} - lv2:default {{=p.defaultValue.toExponential()}} ; -{{?}} -{{?"minimum" in p}} +{{?p.type == "control"}} lv2:minimum {{=p.minimum.toExponential()}} ; -{{?}} -{{?"maximum" in p}} lv2:maximum {{=p.maximum.toExponential()}} ; + lv2:default {{=p.defaultValue.toExponential()}} ; {{?}} {{?p.sidechain}} lv2:portProperty lv2:isSideChain ; diff --git a/templates/vst3/src/data.h b/templates/vst3/src/data.h index f9634c1..6a161b5 100644 --- a/templates/vst3/src/data.h +++ b/templates/vst3/src/data.h @@ -112,8 +112,8 @@ static struct Steinberg_Vst_ParameterInfo parameterInfo[DATA_PRODUCT_PARAMETERS_ /* .title = */ { {{~Array.from(p.name) :c}}0x{{=c.charCodeAt(0).toString(16)}}, {{~}}0 }, /* .shortTitle = */ { {{~Array.from(p.shortName) :c}}0x{{=c.charCodeAt(0).toString(16)}}, {{~}}0 }, /* .units = */ { {{~Array.from(p.unit in it.tibia.vst3.units ? it.tibia.vst3.units[p.unit] : "") :c}}0x{{=c.charCodeAt(0).toString(16)}}, {{~}}0 }, - /* .stepCount = */ {{?p.toggled}}1{{??p.list && p.scalePoints.length > 1}}Number(1 / (p.scalePoints.length - 1)).toExponential(){{??p.integer && "maximum" in p && "minimum" in p}}Number(p.maximum - p.minimum).toExponential(){{??}}0{{?}}, - /* .defaultNormalizedValue = */ {{="defaultValue" in p && "maximum" in p && "minimum" in p ? Number((p.defaultValue - p.minimum) / (p.maximum - p.minimum)).toExponential() : 0.0}}, + /* .stepCount = */ {{?p.toggled}}1{{??p.list && p.scalePoints.length > 1}}Number(1 / (p.scalePoints.length - 1)).toExponential(){{??p.integer}}Number(p.maximum - p.minimum).toExponential(){{??}}0{{?}}, + /* .defaultNormalizedValue = */ {{=Number((p.defaultValue - p.minimum) / (p.maximum - p.minimum)).toExponential()}}, /* .unitId = */ 0, /* .flags = */ {{?p.direction == "input"}}Steinberg_Vst_ParameterInfo_ParameterFlags_kCanAutomate{{??}}Steinberg_Vst_ParameterInfo_ParameterFlags_kIsReadOnly{{?}} {{?}} @@ -129,14 +129,16 @@ static struct { size_t index; double min; double max; + double def; uint32_t flags; // scalePoints? } parameterData[DATA_PRODUCT_PARAMETERS_N] = { {{~it.product.parameters.filter(x => !x.isLatency) :p:i}} { /* .index = */ {{=p.paramIndex}}, - /* .min = */ {{="minimum" in p ? p.minimum.toExponential() : 0.0}}, - /* .max = */ {{="maximum" in p ? p.maximum.toExponential() : 0.0}}, + /* .min = */ {{=p.minimum.toExponential()}}, + /* .max = */ {{=p.maximum.toExponential()}}, + /* .def = */ {{=p.defaultValue.toExponential()}}, /* .flags = */ {{?p.isBypass}}DATA_PARAM_BYPASS{{??}}0{{?p.toggled}} | DATA_PARAM_TOGGLED{{?}}{{?p.integer}} | DATA_PARAM_INTEGER{{?}}{{?}} }, {{~}} diff --git a/templates/vst3/src/vst3.c b/templates/vst3/src/vst3.c index 1a6c23f..7e765fc 100644 --- a/templates/vst3/src/vst3.c +++ b/templates/vst3/src/vst3.c @@ -469,7 +469,7 @@ static Steinberg_tresult controllerInitialize(void* thisInterface, struct Steinb c->context = context; #if DATA_PRODUCT_PARAMETERS_N > 0 for (int i = 0; i < DATA_PRODUCT_PARAMETERS_N; i++) - c->parameters[i] = parameterInfo[i].defaultNormalizedValue; + c->parameters[i] = parameterData[i].def; #endif return Steinberg_kResultOk; } @@ -481,13 +481,12 @@ static Steinberg_tresult controllerTerminate(void* thisInterface) { return Steinberg_kResultOk; } -static Steinberg_tresult controllerSetParamNormalized(void* thisInterface, Steinberg_Vst_ParamID id, Steinberg_Vst_ParamValue value); - static Steinberg_tresult controllerSetComponentState(void* thisInterface, struct Steinberg_IBStream* state) { TRACE("controller set component state %p %p\n", thisInterface, (void *)state); if (state == NULL) return Steinberg_kResultFalse; #if DATA_PRODUCT_PARAMETERS_N > 0 + controller *c = (controller *)thisInterface; for (size_t i = 0; i < DATA_PRODUCT_PARAMETERS_N; i++) { if (parameterInfo[i].flags & Steinberg_Vst_ParameterInfo_ParameterFlags_kIsReadOnly) continue; @@ -498,7 +497,7 @@ static Steinberg_tresult controllerSetComponentState(void* thisInterface, struct return Steinberg_kResultFalse; if (IS_BIG_ENDIAN) v.u = SWAP_UINT32(v.u); - controllerSetParamNormalized(thisInterface, i, v.f); + c->parameters[i] = v.f; } #endif TRACE(" ok\n"); @@ -570,12 +569,19 @@ static void dToStr(double v, Steinberg_Vst_String128 s, int precision) { s[i] = '\0'; } +static double parameterMap(Steinberg_Vst_ParamID id, double v) { + return parameterData[id].min + (parameterData[id].max - parameterData[id].min) * v; +} + +static double parameterUnmap(Steinberg_Vst_ParamID id, double v) { + return (v - parameterData[id].min) / (parameterData[id].max - parameterData[id].min); +} + static Steinberg_tresult controllerGetParamStringByValue(void* thisInterface, Steinberg_Vst_ParamID id, Steinberg_Vst_ParamValue valueNormalized, Steinberg_Vst_String128 string) { TRACE("controller get param string by value\n"); if (id >= DATA_PRODUCT_PARAMETERS_N) return Steinberg_kResultFalse; - //mapping TBD - dToStr(valueNormalized, string, 2); + dToStr(parameterMap(id, valueNormalized), string, 2); return Steinberg_kResultTrue; } @@ -611,28 +617,27 @@ static Steinberg_tresult controllerGetParamValueByString(void* thisInterface, St TRACE("controller get param value by string\n"); if (id >= DATA_PRODUCT_PARAMETERS_N) return Steinberg_kResultFalse; - //mapping TBD - TCharToD(string, valueNormalized); + double v; + TCharToD(string, &v); + *valueNormalized = parameterUnmap(id, v); return Steinberg_kResultTrue; } static Steinberg_Vst_ParamValue controllerNormalizedParamToPlain(void* thisInterface, Steinberg_Vst_ParamID id, Steinberg_Vst_ParamValue valueNormalized) { TRACE("controller normalized param to plain\n"); - //mapping TBD - return valueNormalized; + return parameterMap(id, valueNormalized); } static Steinberg_Vst_ParamValue controllerPlainParamToNormalized(void* thisInterface, Steinberg_Vst_ParamID id, Steinberg_Vst_ParamValue plainValue) { TRACE("controller plain param to normalized\n"); - //mapping TBD - return plainValue; + return parameterUnmap(id, plainValue); } static Steinberg_Vst_ParamValue controllerGetParamNormalized(void* thisInterface, Steinberg_Vst_ParamID id) { TRACE("controller get param normalized\n"); #if DATA_PRODUCT_PARAMETERS_N > 0 controller *c = (controller *)thisInterface; - return c->parameters[id]; + return parameterMap(id, c->parameters[id]); #else return 0.0; #endif @@ -644,7 +649,7 @@ static Steinberg_tresult controllerSetParamNormalized(void* thisInterface, Stein if (id >= DATA_PRODUCT_PARAMETERS_N) return Steinberg_kResultFalse; controller *c = (controller *)thisInterface; - c->parameters[id] = value; + c->parameters[id] = parameterMap(id, value); return Steinberg_kResultTrue; #else return Steinberg_kResultFalse;