Compare commits

...

3 Commits

Author SHA1 Message Date
8976c54698 merge from main 2024-07-23 16:25:15 +02:00
Stefano D'Angelo
78bb6c54f7 implemented lv2 ui:touch 2024-07-17 11:17:21 +02:00
Stefano D'Angelo
12650980b0 split ui set parameter in begin/perform/end phases 2024-07-17 10:40:55 +02:00
4 changed files with 140 additions and 28 deletions

View File

@ -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 .

View File

@ -31,9 +31,12 @@ typedef struct {
typedef struct {
void *handle;
const char *format;
const char *(*get_bindir)(void *handle);
const char *(*get_datadir)(void *handle);
void (*set_parameter)(void *handle, size_t index, float value);
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"
@ -375,6 +378,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;
@ -391,26 +396,33 @@ 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) {
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) {
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) {
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)
@ -420,15 +432,33 @@ 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",
/* .get_bindir = */ ui_get_bundle_path_cb,
/* .get_datadir = */ ui_get_bundle_path_cb,
/* .handle = */ (void *)instance,
/* .format = */ "lv2",
/* .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

View File

@ -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
@ -1122,6 +1124,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");
@ -1132,10 +1146,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__
@ -1171,9 +1196,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);

View File

@ -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);