diff --git a/templates/api/src/plugin_api.h b/templates/api/src/plugin_api.h index 3e2e7c9..a193234 100644 --- a/templates/api/src/plugin_api.h +++ b/templates/api/src/plugin_api.h @@ -46,9 +46,9 @@ typedef struct { const char * (*get_bindir)(void *handle); const char * (*get_datadir)(void *handle); {{?it.product.parameters.find(x => x.direction == "input")}} - void (*set_parameter_begin)(void *handle, size_t index); + void (*set_parameter_begin)(void *handle, size_t index, float value); void (*set_parameter)(void *handle, size_t index, float value); - void (*set_parameter_end)(void *handle, size_t index); + void (*set_parameter_end)(void *handle, size_t index, float value); {{?}} } plugin_ui_callbacks; diff --git a/templates/lv2-next/src/lv2.c b/templates/lv2-next/src/lv2.c index 39fd934..4734804 100644 --- a/templates/lv2-next/src/lv2.c +++ b/templates/lv2-next/src/lv2.c @@ -348,11 +348,13 @@ 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) { +static void ui_set_parameter_begin_cb(void *handle, size_t index, float value) { ui_instance *instance = (ui_instance *)handle; if (instance->has_touch) { index = index_to_param[index]; instance->touch.touch(instance->touch.handle, index, true); + value = adjust_param(index - CONTROL_INPUT_INDEX_OFFSET, value); + instance->write(instance->controller, index, sizeof(float), 0, &value); } } @@ -363,10 +365,12 @@ static void ui_set_parameter_cb(void *handle, size_t index, float value) { instance->write(instance->controller, index, sizeof(float), 0, &value); } -static void ui_set_parameter_end_cb(void *handle, size_t index) { +static void ui_set_parameter_end_cb(void *handle, size_t index, float value) { ui_instance *instance = (ui_instance *)handle; if (instance->has_touch) { index = index_to_param[index]; + value = adjust_param(index - CONTROL_INPUT_INDEX_OFFSET, value); + instance->write(instance->controller, index, sizeof(float), 0, &value); instance->touch.touch(instance->touch.handle, index, false); } } diff --git a/templates/lv2/src/lv2.c b/templates/lv2/src/lv2.c index 4d53a6c..2d189f7 100644 --- a/templates/lv2/src/lv2.c +++ b/templates/lv2/src/lv2.c @@ -527,11 +527,13 @@ 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) { +static void ui_set_parameter_begin_cb(void *handle, size_t index, float value) { ui_instance *instance = (ui_instance *)handle; if (instance->has_touch) { index = index_to_param[index]; instance->touch.touch(instance->touch.handle, index, true); + value = adjust_param(index - CONTROL_INPUT_INDEX_OFFSET, value); + instance->write(instance->controller, index, sizeof(float), 0, &value); } } @@ -542,10 +544,12 @@ static void ui_set_parameter_cb(void *handle, size_t index, float value) { instance->write(instance->controller, index, sizeof(float), 0, &value); } -static void ui_set_parameter_end_cb(void *handle, size_t index) { +static void ui_set_parameter_end_cb(void *handle, size_t index, float value) { ui_instance *instance = (ui_instance *)handle; if (instance->has_touch) { index = index_to_param[index]; + value = adjust_param(index - CONTROL_INPUT_INDEX_OFFSET, value); + instance->write(instance->controller, index, sizeof(float), 0, &value); instance->touch.touch(instance->touch.handle, index, false); } } diff --git a/templates/vst3/src/vst3.c b/templates/vst3/src/vst3.c index 36a046a..8331734 100644 --- a/templates/vst3/src/vst3.c +++ b/templates/vst3/src/vst3.c @@ -1397,7 +1397,7 @@ static void plugViewUpdateAllParameters(plugView *view) { # endif } -static void plugViewSetParameterBeginCb(void *handle, size_t index) { +static void plugViewSetParameterBeginCb(void *handle, size_t index, float value) { TRACE("set parameter begin cb\n"); # ifdef DATA_PARAM_LATENCY_INDEX @@ -1406,7 +1406,12 @@ static void plugViewSetParameterBeginCb(void *handle, size_t index) { index = index >= DATA_PARAM_LATENCY_INDEX ? index - 1 : index; # endif plugView *v = (plugView *)handle; + ParameterData *p; + double *pv; + controllerGetParamDataValuePtrs(v->ctrl, index, &p, &pv); + *pv = parameterAdjust(p, 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(p, *pv)); } static void plugViewSetParameterCb(void *handle, size_t index, float value) { @@ -1426,7 +1431,7 @@ static void plugViewSetParameterCb(void *handle, size_t index, float value) { v->ctrl->componentHandler->lpVtbl->performEdit(v->ctrl->componentHandler, parameterInfo[index].id, parameterUnmap(p, *pv)); } -static void plugViewSetParameterEndCb(void *handle, size_t index) { +static void plugViewSetParameterEndCb(void *handle, size_t index, float value) { TRACE("set parameter end cb\n"); # ifdef DATA_PARAM_LATENCY_INDEX @@ -1435,6 +1440,11 @@ static void plugViewSetParameterEndCb(void *handle, size_t index) { index = index >= DATA_PARAM_LATENCY_INDEX ? index - 1 : index; # endif plugView *v = (plugView *)handle; + ParameterData *p; + double *pv; + controllerGetParamDataValuePtrs(v->ctrl, index, &p, &pv); + *pv = parameterAdjust(p, value); // let Reaper find the updated value + v->ctrl->componentHandler->lpVtbl->performEdit(v->ctrl->componentHandler, parameterInfo[index].id, parameterUnmap(p, *pv)); v->ctrl->componentHandler->lpVtbl->endEdit(v->ctrl->componentHandler, parameterInfo[index].id); } diff --git a/test/plugin_ui.h b/test/plugin_ui.h index c81ef5e..7d72612 100644 --- a/test/plugin_ui.h +++ b/test/plugin_ui.h @@ -159,22 +159,19 @@ static PuglStatus plugin_ui_on_event(PuglView *view, const PuglEvent *event) { && 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); + instance->cbs.set_parameter_begin(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); + instance->cbs.set_parameter_begin(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)); + instance->cbs.set_parameter_begin(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) { @@ -227,7 +224,24 @@ static PuglStatus plugin_ui_on_event(PuglView *view, const PuglEvent *event) { } if (instance->param_down != -1) { - instance->cbs.set_parameter_end(instance->cbs.handle, instance->param_down); + 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_end(instance->cbs.handle, 0, -60.f + 80.f * instance->gain); + puglPostRedisplay(instance->view); + break; + case 1: + instance->delay = v; + instance->cbs.set_parameter_end(instance->cbs.handle, 1, 1000.f * instance->delay); + puglPostRedisplay(instance->view); + break; + case 2: + instance->cutoff = v; + instance->cbs.set_parameter_end(instance->cbs.handle, 2, (632.4555320336746f * instance->cutoff + 20.653108640674372f) / (1.0326554320337158f - instance->cutoff)); + puglPostRedisplay(instance->view); + break; + } instance->param_down = -1; } }