split ui set parameter in begin/perform/end phases
This commit is contained in:
parent
3d1fdd05ee
commit
12650980b0
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user