aboutsummaryrefslogtreecommitdiffstats
path: root/src/jalv_gtk2.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-04-11 17:59:42 +0000
committerDavid Robillard <d@drobilla.net>2012-04-11 17:59:42 +0000
commit081425005a2b61093b97eecb1d72cf58a5c17b7a (patch)
tree7c30b048ed201e0f8cee2218c59cb236ee216984 /src/jalv_gtk2.c
parent454f7c8b0ac63c1291fba5445d870773d0c980d3 (diff)
downloadjalv-081425005a2b61093b97eecb1d72cf58a5c17b7a.tar.gz
jalv-081425005a2b61093b97eecb1d72cf58a5c17b7a.tar.bz2
jalv-081425005a2b61093b97eecb1d72cf58a5c17b7a.zip
Use actual scale point values for combo boxes (don't assume scale point values match integer combo box indices).
git-svn-id: http://svn.drobilla.net/lad/trunk/jalv@4164 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/jalv_gtk2.c')
-rw-r--r--src/jalv_gtk2.c39
1 files changed, 33 insertions, 6 deletions
diff --git a/src/jalv_gtk2.c b/src/jalv_gtk2.c
index 7023c9f..d6829b5 100644
--- a/src/jalv_gtk2.c
+++ b/src/jalv_gtk2.c
@@ -14,6 +14,8 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <math.h>
+
#include <gtk/gtk.h>
#include "jalv_internal.h"
@@ -204,7 +206,20 @@ jalv_ui_port_event(Jalv* jalv,
}
if (GTK_IS_COMBO_BOX(widget)) {
- fprintf(stderr, "TODO: Combo box value change\n");
+ GtkTreeModel* model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
+ GValue value = G_VALUE_INIT;
+ GtkTreeIter i;
+ bool valid = gtk_tree_model_get_iter_first(model, &i);
+ while (valid) {
+ gtk_tree_model_get_value(model, &i, 0, &value);
+ const double v = g_value_get_double(&value);
+ g_value_unset(&value);
+ if (fabs(v - *(float*)buffer) < FLT_EPSILON) {
+ gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget), &i);
+ return;
+ }
+ valid = gtk_tree_model_iter_next(model, &i);
+ }
} else if (GTK_IS_TOGGLE_BUTTON(widget)) {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
*(float*)buffer > 0.0f);
@@ -225,8 +240,17 @@ slider_changed(GtkRange* range, gpointer data)
static void
combo_changed(GtkComboBox* box, gpointer data)
{
- float fval = (float)gtk_combo_box_get_active(GTK_COMBO_BOX(box));
- ((struct Port*)data)->control = fval;
+ GtkTreeIter iter;
+ if (gtk_combo_box_get_active_iter(box, &iter)) {
+ GtkTreeModel* model = gtk_combo_box_get_model(box);
+ GValue value = G_VALUE_INIT;
+
+ gtk_tree_model_get_value(model, &iter, 0, &value);
+ const double v = g_value_get_double(&value);
+ g_value_unset(&value);
+
+ ((struct Port*)data)->control = v;
+ }
}
static gboolean
@@ -257,12 +281,15 @@ static GtkWidget*
make_combo(struct Port* port, GHashTable* points, int deft)
{
GList* list = g_hash_table_get_keys(points);
- GtkListStore* list_store = gtk_list_store_new(1, G_TYPE_STRING);
+ GtkListStore* list_store = gtk_list_store_new(
+ 2, G_TYPE_DOUBLE, G_TYPE_STRING);
for (GList* cur = g_list_sort(list, dcmp); cur; cur = cur->next) {
GtkTreeIter iter;
gtk_list_store_append(list_store, &iter);
gtk_list_store_set(list_store, &iter,
- 0, g_hash_table_lookup(points, cur->data), -1);
+ 0, *(double*)cur->data,
+ 1, g_hash_table_lookup(points, cur->data),
+ -1);
}
g_list_free(list);
@@ -272,7 +299,7 @@ make_combo(struct Port* port, GHashTable* points, int deft)
GtkCellRenderer* cell = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), cell, TRUE);
- gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell, "text", 0, NULL);
+ gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), cell, "text", 1, NULL);
g_signal_connect(G_OBJECT(combo),
"changed", G_CALLBACK(combo_changed), port);