aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2015-12-31 14:10:55 -0500
committerDavid Robillard <d@drobilla.net>2015-12-31 14:10:55 -0500
commit0bb0b753c62c900027def66288489442cb69f336 (patch)
tree40f19d3d2f1748ca7130749b93c9ac4f697dfa55 /src
parent5a7c238a33400b5572a587f7290ca7027b207f70 (diff)
downloadjalv-0bb0b753c62c900027def66288489442cb69f336.tar.gz
jalv-0bb0b753c62c900027def66288489442cb69f336.tar.bz2
jalv-0bb0b753c62c900027def66288489442cb69f336.zip
Fix controls when range is given with integers
Diffstat (limited to 'src')
-rw-r--r--src/control.c7
-rw-r--r--src/jalv_gtk.c25
-rw-r--r--src/jalv_qt.cpp2
3 files changed, 22 insertions, 12 deletions
diff --git a/src/control.c b/src/control.c
index 1921785..97ba797 100644
--- a/src/control.c
+++ b/src/control.c
@@ -39,6 +39,9 @@ new_port_control(Jalv* jalv, uint32_t index)
id->jalv = jalv;
id->type = PORT;
id->index = index;
+ id->min = lilv_port_get(plug, lport, nodes->lv2_minimum);
+ id->max = lilv_port_get(plug, lport, nodes->lv2_maximum);
+ id->def = lilv_port_get(plug, lport, nodes->lv2_default);
id->is_toggle = lilv_port_has_property(plug, lport, nodes->lv2_toggled);
id->is_integer = lilv_port_has_property(plug, lport, nodes->lv2_integer);
id->is_enumeration = lilv_port_has_property(plug, lport, nodes->lv2_enumeration);
@@ -47,12 +50,12 @@ new_port_control(Jalv* jalv, uint32_t index)
lilv_port_get_range(plug, lport, &id->def, &id->min, &id->max);
if (lilv_port_has_property(plug, lport, jalv->nodes.lv2_sampleRate)) {
/* Adjust range for lv2:sampleRate controls */
- if (lilv_node_is_float(id->min)) {
+ if (lilv_node_is_float(id->min) || lilv_node_is_int(id->min)) {
const float min = lilv_node_as_float(id->min) * jalv->sample_rate;
lilv_node_free(id->min);
id->min = lilv_new_float(jalv->world, min);
}
- if (lilv_node_is_float(id->max)) {
+ if (lilv_node_is_float(id->max) || lilv_node_is_int(id->max)) {
const float max = lilv_node_as_float(id->max) * jalv->sample_rate;
lilv_node_free(id->max);
id->max = lilv_new_float(jalv->world, max);
diff --git a/src/jalv_gtk.c b/src/jalv_gtk.c
index a3f6320..104d7a2 100644
--- a/src/jalv_gtk.c
+++ b/src/jalv_gtk.c
@@ -30,6 +30,15 @@ typedef struct {
GtkSpinButton* spin;
GtkWidget* control;
} Controller;
+static float
+get_float(const LilvNode* node, float fallback)
+{
+ if (lilv_node_is_float(node) || lilv_node_is_int(node)) {
+ return lilv_node_as_float(node);
+ }
+
+ return fallback;
+}
static GtkWidget*
new_box(gboolean horizontal, gint spacing)
@@ -791,8 +800,8 @@ make_combo(ControlID* record, float value)
static Controller*
make_log_slider(ControlID* record, float value)
{
- const float min = lilv_node_is_float(record->min) ? lilv_node_as_float(record->min) : 0.0f;
- const float max = lilv_node_is_float(record->max) ? lilv_node_as_float(record->max) : 1.0f;
+ const float min = get_float(record->min, 0.0f);
+ const float max = get_float(record->max, 1.0f);
const float lmin = logf(min);
const float lmax = logf(max);
const float ldft = logf(value);
@@ -814,8 +823,8 @@ make_log_slider(ControlID* record, float value)
static Controller*
make_slider(ControlID* record, float value)
{
- const float min = lilv_node_is_float(record->min) ? lilv_node_as_float(record->min) : 0.0f;
- const float max = lilv_node_is_float(record->max) ? lilv_node_as_float(record->max) : 1.0f;
+ const float min = get_float(record->min, 0.0f);
+ const float max = get_float(record->max, 1.0f);
const double step = record->is_integer ? 1.0 : ((max - min) / 100.0);
GtkWidget* scale = new_hscale(min, max, step);
GtkWidget* spin = gtk_spin_button_new_with_range(min, max, step);
@@ -1009,7 +1018,8 @@ build_control_widget(Jalv* jalv, GtkWidget* window)
size_t np = 0;
LILV_FOREACH(scale_points, s, sp) {
const LilvScalePoint* p = lilv_scale_points_get(sp, s);
- if (lilv_node_is_float(lilv_scale_point_get_value(p))) {
+ if (lilv_node_is_float(lilv_scale_point_get_value(p)) ||
+ lilv_node_is_int(lilv_scale_point_get_value(p))) {
control_id->points[np].value = lilv_node_as_float(
lilv_scale_point_get_value(p));
control_id->points[np].label = g_strdup(
@@ -1068,10 +1078,7 @@ build_control_widget(Jalv* jalv, GtkWidget* window)
} else if (record->value_type == jalv->forge.Path) {
controller = make_file_chooser(record);
} else {
- controller = make_controller(record,
- (lilv_node_is_float(record->def)
- ? lilv_node_as_float(record->def)
- : 0.0f));
+ controller = make_controller(record, get_float(record->def, 0.0f));
}
record->widget = controller;
diff --git a/src/jalv_qt.cpp b/src/jalv_qt.cpp
index b531f75..114faf2 100644
--- a/src/jalv_qt.cpp
+++ b/src/jalv_qt.cpp
@@ -429,7 +429,7 @@ Control::Control(PortContainer portContainer, QWidget* parent)
LILV_FOREACH(scale_points, s, sp) {
const LilvScalePoint* p = lilv_scale_points_get(sp, s);
const LilvNode* val = lilv_scale_point_get_value(p);
- if (!lilv_node_is_float(val)) {
+ if (!lilv_node_is_float(val) && !lilv_node_is_int(val)) {
continue;
}