From 12650980b0e02d0c1e9db64d7b7e9d94d08a2e07 Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Wed, 17 Jul 2024 10:40:55 +0200 Subject: [PATCH 1/2] split ui set parameter in begin/perform/end phases --- templates/lv2/src/lv2.c | 20 +++++++++++-- templates/vst3/src/vst3.c | 35 ++++++++++++++++++++-- test/plugin_ui.h | 63 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 110 insertions(+), 8 deletions(-) diff --git a/templates/lv2/src/lv2.c b/templates/lv2/src/lv2.c index 843bb69..82837c1 100644 --- a/templates/lv2/src/lv2.c +++ b/templates/lv2/src/lv2.c @@ -33,7 +33,9 @@ typedef struct { const char * format; const char * (*get_bindir)(void *handle); const char * (*get_datadir)(void *handle); + void (*set_parameter_begin)(void *handle, size_t index); void (*set_parameter)(void *handle, size_t index, float value); + void (*set_parameter_end)(void *handle, size_t index); } plugin_ui_callbacks; #include "data.h" @@ -360,12 +362,22 @@ static const char * ui_get_bundle_path_cb(void *handle) { } # if DATA_PRODUCT_CONTROL_INPUTS_N > 0 +static void ui_set_parameter_begin_cb(void *handle, size_t index) { + (void)handle; + (void)index; +} + static void ui_set_parameter_cb(void *handle, size_t index, float value) { ui_instance *instance = (ui_instance *)handle; index = index_to_param[index]; value = adjust_param(index - CONTROL_INPUT_INDEX_OFFSET, value); instance->write(instance->controller, index, sizeof(float), 0, &value); } + +static void ui_set_parameter_end_cb(void *handle, size_t index) { + (void)handle; + (void)index; +} # endif static LV2UI_Handle ui_instantiate(const LV2UI_Descriptor * descriptor, const char * plugin_uri, const char * bundle_path, LV2UI_Write_Function write_function, LV2UI_Controller controller, LV2UI_Widget * widget, const LV2_Feature * const * features) { @@ -395,9 +407,13 @@ static LV2UI_Handle ui_instantiate(const LV2UI_Descriptor * descriptor, const ch /* .get_bindir = */ ui_get_bundle_path_cb, /* .get_datadir = */ ui_get_bundle_path_cb, # if DATA_PRODUCT_CONTROL_INPUTS_N > 0 - /* .set_parameter = */ ui_set_parameter_cb + /* .set_parameter_begin = */ ui_set_parameter_begin_cb, + /* .set_parameter = */ ui_set_parameter_cb, + /* .set_parameter_end = */ ui_set_parameter_end_cb # else - /* .set_parameter = */ NULL + /* .set_parameter_begin = */ NULL, + /* .set_parameter = */ NULL, + /* .set_parameter_end = */ NULL # endif }; # if DATA_PRODUCT_CONTROL_INPUTS_N > 0 diff --git a/templates/vst3/src/vst3.c b/templates/vst3/src/vst3.c index 45296b2..ffe500c 100644 --- a/templates/vst3/src/vst3.c +++ b/templates/vst3/src/vst3.c @@ -33,7 +33,9 @@ typedef struct { const char * format; const char * (*get_bindir)(void *handle); const char * (*get_datadir)(void *handle); + void (*set_parameter_begin)(void *handle, size_t index); void (*set_parameter)(void *handle, size_t index, float value); + void (*set_parameter_end)(void *handle, size_t index); } plugin_ui_callbacks; #pragma GCC diagnostic push @@ -1095,6 +1097,18 @@ static void plugViewUpdateAllParameters(plugView *view) { plugin_ui_set_parameter(view->ui, parameterData[i].index, view->ctrl->parameters[i]); } +static void plugViewSetParameterBeginCb(void *handle, size_t index) { + TRACE("set parameter begin cb\n"); + +# ifdef DATA_PARAM_LATENCY_INDEX + if (index == DATA_PARAM_LATENCY_INDEX) + return; + index = index >= DATA_PARAM_LATENCY_INDEX ? index - 1 : index; +# endif + plugView *v = (plugView *)handle; + v->ctrl->componentHandler->lpVtbl->beginEdit(v->ctrl->componentHandler, parameterInfo[index].id); +} + static void plugViewSetParameterCb(void *handle, size_t index, float value) { TRACE("set parameter cb\n"); @@ -1105,10 +1119,21 @@ static void plugViewSetParameterCb(void *handle, size_t index, float value) { # endif plugView *v = (plugView *)handle; v->ctrl->parameters[index] = parameterAdjust(index, value); // let Reaper find the updated value - v->ctrl->componentHandler->lpVtbl->beginEdit(v->ctrl->componentHandler, parameterInfo[index].id); v->ctrl->componentHandler->lpVtbl->performEdit(v->ctrl->componentHandler, parameterInfo[index].id, parameterUnmap(index, v->ctrl->parameters[index])); +} + +static void plugViewSetParameterEndCb(void *handle, size_t index) { + TRACE("set parameter end cb\n"); + +# ifdef DATA_PARAM_LATENCY_INDEX + if (index == DATA_PARAM_LATENCY_INDEX) + return; + index = index >= DATA_PARAM_LATENCY_INDEX ? index - 1 : index; +# endif + plugView *v = (plugView *)handle; v->ctrl->componentHandler->lpVtbl->endEdit(v->ctrl->componentHandler, parameterInfo[index].id); } + # endif # ifdef __APPLE__ @@ -1144,9 +1169,13 @@ static Steinberg_tresult plugViewAttached(void* thisInterface, void* parent, Ste /* .get_bindir = */ get_bindir_cb, /* .get_datadir = */ get_datadir_cb, # if DATA_PRODUCT_PARAMETERS_N > 0 - /* .set_parameter = */ plugViewSetParameterCb + /* .set_parameter_begin = */ plugViewSetParameterBeginCb, + /* .set_parameter = */ plugViewSetParameterCb, + /* .set_parameter_end = */ plugViewSetParameterEndCb # else - /* .set_parameter = */ NULL + /* .set_parameter_begin = */ NULL, + /* .set_parameter = */ NULL, + /* .set_parameter_end = */ NULL # endif }; v->ui = plugin_ui_create(1, parent, &cbs); diff --git a/test/plugin_ui.h b/test/plugin_ui.h index 120e4cd..c81ef5e 100644 --- a/test/plugin_ui.h +++ b/test/plugin_ui.h @@ -40,6 +40,8 @@ typedef struct { char bypass; float y_z1; + int param_down; + plugin_ui_callbacks cbs; } plugin_ui; @@ -144,7 +146,7 @@ static PuglStatus plugin_ui_on_event(PuglView *view, const PuglEvent *event) { puglPostRedisplay(instance->view); } break; - case PUGL_BUTTON_RELEASE: + case PUGL_BUTTON_PRESS: { plugin_ui *instance = (plugin_ui *)puglGetHandle(view); const PuglButtonEvent *ev = (const PuglButtonEvent *)event; @@ -155,24 +157,78 @@ static PuglStatus plugin_ui_on_event(PuglView *view, const PuglEvent *event) { if (ev->x >= x + 0.1 * w && ev->x <= x + 0.9 * w && ev->y >= y + 0.15 * h && ev->y <= y + 0.25 * h) { + instance->param_down = 0; instance->gain = (float)((ev->x - (x + 0.1 * w)) / (0.8 * w)); + instance->cbs.set_parameter_begin(instance->cbs.handle, 0); instance->cbs.set_parameter(instance->cbs.handle, 0, -60.f + 80.f * instance->gain); puglPostRedisplay(instance->view); } else if (ev->x >= x + 0.1 * w && ev->x <= x + 0.9 * w && ev->y >= y + 0.3 * h && ev->y <= y + 0.4 * h) { + instance->param_down = 1; instance->delay = (float)((ev->x - (x + 0.1 * w)) / (0.8 * w)); + instance->cbs.set_parameter_begin(instance->cbs.handle, 1); instance->cbs.set_parameter(instance->cbs.handle, 1, 1000.f * instance->delay); puglPostRedisplay(instance->view); } else if (ev->x >= x + 0.1 * w && ev->x <= x + 0.9 * w && ev->y >= y + 0.45 * h && ev->y <= y + 0.55 * h) { + instance->param_down = 2; instance->cutoff = (float)((ev->x - (x + 0.1 * w)) / (0.8 * w)); + instance->cbs.set_parameter_begin(instance->cbs.handle, 2); instance->cbs.set_parameter(instance->cbs.handle, 2, (632.4555320336746f * instance->cutoff + 20.653108640674372f) / (1.0326554320337158f - instance->cutoff)); puglPostRedisplay(instance->view); } else if (ev->x >= x + 0.4 * w && ev->x <= x + 0.6 * w && ev->y >= y + 0.6 * h && ev->y <= y + 0.7 * h) { - instance->bypass = !instance->bypass; - instance->cbs.set_parameter(instance->cbs.handle, 3, instance->bypass ? 1.f : 0.f); + instance->param_down = 3; + } + } + break; + case PUGL_MOTION: + { + plugin_ui *instance = (plugin_ui *)puglGetHandle(view); + const PuglMotionEvent *ev = (const PuglMotionEvent *)event; + double x = instance->x; + double w = instance->w; + float v = ev->x < x + 0.1 * w ? 0.f : (ev->x > x + 0.9 * w ? 1.f : (float)((ev->x - (x + 0.1 * w)) / (0.8 * w))); + + switch (instance->param_down) { + case 0: + instance->gain = v; + instance->cbs.set_parameter(instance->cbs.handle, 0, -60.f + 80.f * instance->gain); puglPostRedisplay(instance->view); + break; + case 1: + instance->delay = v; + instance->cbs.set_parameter(instance->cbs.handle, 1, 1000.f * instance->delay); + puglPostRedisplay(instance->view); + break; + case 2: + instance->cutoff = v; + instance->cbs.set_parameter(instance->cbs.handle, 2, (632.4555320336746f * instance->cutoff + 20.653108640674372f) / (1.0326554320337158f - instance->cutoff)); + puglPostRedisplay(instance->view); + break; + } + } + break; + case PUGL_BUTTON_RELEASE: + { + plugin_ui *instance = (plugin_ui *)puglGetHandle(view); + const PuglButtonEvent *ev = (const PuglButtonEvent *)event; + double x = instance->x; + double y = instance->y; + double w = instance->w; + double h = instance->h; + + if (instance->param_down == 3) + if (ev->x >= x + 0.4 * w && ev->x <= x + 0.6 * w + && ev->y >= y + 0.6 * h && ev->y <= y + 0.7 * h) { + instance->bypass = !instance->bypass; + instance->cbs.set_parameter(instance->cbs.handle, 3, instance->bypass ? 1.f : 0.f); + puglPostRedisplay(instance->view); + } + + if (instance->param_down != -1) { + instance->cbs.set_parameter_end(instance->cbs.handle, instance->param_down); + instance->param_down = -1; } } break; @@ -193,6 +249,7 @@ static plugin_ui *plugin_ui_create(char has_parent, void *parent, plugin_ui_call plugin_ui *instance = malloc(sizeof(plugin_ui)); if (instance == NULL) return NULL; + instance->param_down = -1; instance->world = puglNewWorld(PUGL_MODULE, 0); instance->view = puglNewView(instance->world); puglSetSizeHint(instance->view, PUGL_DEFAULT_SIZE, WIDTH, HEIGHT); From 78bb6c54f736520380ec265f2fe1608446656e84 Mon Sep 17 00:00:00 2001 From: Stefano D'Angelo Date: Wed, 17 Jul 2024 11:17:21 +0200 Subject: [PATCH 2/2] implemented lv2 ui:touch --- templates/lv2/data/manifest.ttl.in | 4 --- templates/lv2/src/lv2.c | 39 ++++++++++++++++++++---------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/templates/lv2/data/manifest.ttl.in b/templates/lv2/data/manifest.ttl.in index c8531f4..131f00b 100644 --- a/templates/lv2/data/manifest.ttl.in +++ b/templates/lv2/data/manifest.ttl.in @@ -125,15 +125,11 @@ {{=it.tibia.lv2.ttlURI(it.lv2.ui.uri)}} a ui:@UI_TYPE@ ; ui:binary <{{=it.product.bundleName}}@DLL_SUFFIX@> ; - lv2:extensionData ui:resize ; {{?!it.product.ui.userResizable}} lv2:optionalFeature ui:noUserResize ; # doesn't work as lv2:requiredFeature, don't ask me why {{?!it.product.ui.selfResizable}} lv2:optionalFeature ui:fixedSize ; {{?}} -{{?}} -{{?it.product.ui.selfResizable}} - lv2:optionalFeature ui:resize ; {{?}} lv2:requiredFeature ui:idleInterface ; lv2:extensionData ui:idleInterface . diff --git a/templates/lv2/src/lv2.c b/templates/lv2/src/lv2.c index 82837c1..03d46d4 100644 --- a/templates/lv2/src/lv2.c +++ b/templates/lv2/src/lv2.c @@ -346,6 +346,8 @@ typedef struct { # if DATA_PRODUCT_CONTROL_INPUTS_N > 0 LV2UI_Write_Function write; LV2UI_Controller controller; + char has_touch; + LV2UI_Touch touch; # endif } ui_instance; @@ -363,8 +365,11 @@ static const char * ui_get_bundle_path_cb(void *handle) { # if DATA_PRODUCT_CONTROL_INPUTS_N > 0 static void ui_set_parameter_begin_cb(void *handle, size_t index) { - (void)handle; - (void)index; + ui_instance *instance = (ui_instance *)handle; + if (instance->has_touch) { + index = index_to_param[index]; + instance->touch.touch(instance->touch.handle, index, true); + } } static void ui_set_parameter_cb(void *handle, size_t index, float value) { @@ -375,23 +380,17 @@ static void ui_set_parameter_cb(void *handle, size_t index, float value) { } static void ui_set_parameter_end_cb(void *handle, size_t index) { - (void)handle; - (void)index; + ui_instance *instance = (ui_instance *)handle; + if (instance->has_touch) { + index = index_to_param[index]; + instance->touch.touch(instance->touch.handle, index, false); + } } # endif static LV2UI_Handle ui_instantiate(const LV2UI_Descriptor * descriptor, const char * plugin_uri, const char * bundle_path, LV2UI_Write_Function write_function, LV2UI_Controller controller, LV2UI_Widget * widget, const LV2_Feature * const * features) { (void)descriptor; (void)plugin_uri; - (void)bundle_path; - - char has_parent = 0; - void *parent = NULL; - for (size_t i = 0; features[i] != NULL; i++) - if (!strcmp(features[i]->URI, LV2_UI__parent)) { - has_parent = 1; - parent = features[i]->data; - } ui_instance *instance = malloc(sizeof(ui_instance)); if (instance == NULL) @@ -401,6 +400,20 @@ static LV2UI_Handle ui_instantiate(const LV2UI_Descriptor * descriptor, const ch if (instance->bundle_path == NULL) goto err_bundle_path; + char has_parent = 0; + void *parent = NULL; + instance->has_touch = 0; + for (size_t i = 0; features[i] != NULL; i++) { + if (!strcmp(features[i]->URI, LV2_UI__parent)) { + has_parent = 1; + parent = features[i]->data; + } + if (!strcmp(features[i]->URI, LV2_UI__touch)) { + instance->has_touch = 1; + instance->touch = *((LV2UI_Touch *)features[i]->data); + } + } + plugin_ui_callbacks cbs = { /* .handle = */ (void *)instance, /* .format = */ "lv2",