aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHanspeter Portner <dev@open-music-kontrollers.ch>2015-08-07 13:21:55 +0200
committerHanspeter Portner <dev@open-music-kontrollers.ch>2015-08-07 13:21:55 +0200
commit5e6a36cc4649d632d63030554a48702c2544d613 (patch)
tree42f247b24ecd5d6af132ede7eb5c30255ec25145
parent346681aaf806cf255e7c31de5e229a5c9a4f78ec (diff)
downloadsynthpod-5e6a36cc4649d632d63030554a48702c2544d613.tar.xz
optimize smart slider math.
-rw-r--r--lib/smart_slider.c14
-rw-r--r--lib/synthpod_app.c4
-rw-r--r--lib/synthpod_ui.c20
3 files changed, 23 insertions, 15 deletions
diff --git a/lib/smart_slider.c b/lib/smart_slider.c
index 289dc616..49167446 100644
--- a/lib/smart_slider.c
+++ b/lib/smart_slider.c
@@ -33,6 +33,8 @@ struct _smart_slider_t {
Evas_Object *theme;
float min;
float max;
+ float scale;
+ float diff;
float dflt;
float value;
@@ -66,6 +68,8 @@ _smart_slider_smart_init(Evas_Object *o)
priv->min = 0.f;
priv->max = 1.f;
+ priv->diff = priv->max - priv->min;
+ priv->scale = 1.f / priv->diff;
priv->dflt = 0.f;
priv->value = priv->dflt;
@@ -94,13 +98,13 @@ _smart_slider_value_flush(Evas_Object *o)
smart_slider_t *priv = evas_object_smart_data_get(o);
// calculate exact value
- float new_value = priv->min + (priv->drag * (priv->max - priv->min));
+ float new_value = priv->min + priv->drag * priv->diff;
double drag_x;
if(priv->integer)
{
new_value = floor(new_value);
- drag_x = (new_value - priv->min) / (priv->max - priv->min);
+ drag_x = (new_value - priv->min) * priv->scale;
}
else
drag_x = priv->drag;
@@ -206,7 +210,7 @@ _mouse_wheel(void *data, Evas *e, Evas_Object *obj, void *event_info)
float scale;
if(priv->integer)
{
- scale = 1.f / (priv->max - priv->min);
+ scale = priv->scale;
}
else
{
@@ -312,6 +316,8 @@ smart_slider_range_set(Evas_Object *o, float min, float max, float dflt)
priv->min = min;
priv->max = max;
priv->dflt = dflt;
+ priv->diff = priv->max - priv->min;
+ priv->scale = 1.f / priv->diff;
_smart_slider_value_flush(o);
}
@@ -345,7 +351,7 @@ smart_slider_value_set(Evas_Object *o, float value)
: value);
priv->value = INFINITY;
- priv->drag = (new_value - priv->min) / (priv->max - priv->min);
+ priv->drag = (new_value - priv->min) * priv->scale;
_smart_slider_value_flush(o);
}
diff --git a/lib/synthpod_app.c b/lib/synthpod_app.c
index c68d3515..c087bb16 100644
--- a/lib/synthpod_app.c
+++ b/lib/synthpod_app.c
@@ -1088,7 +1088,7 @@ sp_app_new(const LilvWorld *world, sp_app_driver_t *driver, void *data)
else
; //TODO report
- app->fps.bound = driver->sample_rate / 30; //TODO make this configurable
+ app->fps.bound = driver->sample_rate / 24; //TODO make this configurable
app->fps.counter = 0;
app->ramp_samples = driver->sample_rate / 10; // ramp over 0.1s
@@ -2255,7 +2255,7 @@ sp_app_run_post(sp_app_t *app, uint32_t nsamples)
if(app->fps.counter >= app->fps.bound) // check whether we reached boundary
{
send_port_updates = 1;
- app->fps.counter -= app->fps.bound; // reet sample counter
+ app->fps.counter -= app->fps.bound; // reset sample counter
}
// iterate over all modules
diff --git a/lib/synthpod_ui.c b/lib/synthpod_ui.c
index a2bab2cc..c45355e0 100644
--- a/lib/synthpod_ui.c
+++ b/lib/synthpod_ui.c
@@ -219,6 +219,8 @@ struct _port_t {
port_buffer_type_t buffer_type; // none, sequence
int patchable; // support patch:Message
+ bool integer;
+ bool toggled;
LilvScalePoints *points;
char *unit;
@@ -373,9 +375,9 @@ _std_port_event(LV2UI_Handle handle, uint32_t index, uint32_t size,
if(protocol == ui->regs.port.float_protocol.urid)
{
float val = *(float *)buf;
- int toggled = lilv_port_has_property(mod->plug, port->tar, ui->regs.port.toggled.node);
// we should not set a value lower/higher than min/max for widgets
+ //FIXME should be done by smart_*_value_set
if(val < port->min)
val = port->min;
if(val > port->max)
@@ -383,7 +385,7 @@ _std_port_event(LV2UI_Handle handle, uint32_t index, uint32_t size,
if(port->std.widget)
{
- if(toggled)
+ if(port->toggled)
smart_toggle_value_set(port->std.widget, floor(val));
else if(port->points)
smart_spinner_value_set(port->std.widget, val);
@@ -1585,6 +1587,8 @@ _sp_ui_mod_add(sp_ui_t *ui, const char *uri, u_id_t uid, LV2_Handle inst,
lilv_node_free(min_node);
lilv_node_free(max_node);
+ tar->integer = lilv_port_has_property(mod->plug, tar->tar, ui->regs.port.integer.node);
+ tar->toggled = lilv_port_has_property(mod->plug, tar->tar, ui->regs.port.toggled.node);
int enumeration = lilv_port_has_property(plug, port, ui->regs.port.enumeration.node);
tar->points = enumeration
? lilv_port_get_scale_points(plug, port)
@@ -3380,7 +3384,7 @@ _sldr_changed(void *data, Evas_Object *obj, void *event)
sp_ui_t *ui = mod->ui;
float val = smart_slider_value_get(obj);
- if(lilv_port_has_property(mod->plug, port->tar, ui->regs.port.integer.node)) //FIXME use integer flag
+ if(port->integer)
val = floor(val);
_std_ui_write_function(mod, port->index, sizeof(float),
@@ -3484,14 +3488,12 @@ _modlist_std_content_get(void *data, Evas_Object *obj, const char *part)
Evas_Object *child = NULL;
if(port->type == PORT_TYPE_CONTROL)
{
- int integer = lilv_port_has_property(mod->plug, port->tar, ui->regs.port.integer.node);
- int toggled = lilv_port_has_property(mod->plug, port->tar, ui->regs.port.toggled.node);
- float step_val = integer
+ float step_val = port->integer
? 1.f / (port->max - port->min)
: 0.001; // use 1000 steps for continuous values
float val = port->dflt;
- if(toggled)
+ if(port->toggled)
{
Evas_Object *check = smart_toggle_add(evas_object_evas_get(lay));
if(check)
@@ -3537,8 +3539,8 @@ _modlist_std_content_get(void *data, Evas_Object *obj, const char *part)
{
smart_slider_range_set(sldr, port->min, port->max, port->dflt);
smart_slider_color_set(sldr, mod->col);
- smart_slider_integer_set(sldr, integer);
- smart_slider_format_set(sldr, integer ? "%.0f %s" : "%.4f %s");
+ smart_slider_integer_set(sldr, port->integer);
+ smart_slider_format_set(sldr, port->integer ? "%.0f %s" : "%.4f %s");
if(port->unit)
smart_slider_unit_set(sldr, port->unit);
smart_slider_disabled_set(sldr, port->direction == PORT_DIRECTION_OUTPUT);