diff --git a/gdigi.c b/gdigi.c index 6a105cd..ad23797 100644 --- a/gdigi.c +++ b/gdigi.c @@ -218,21 +218,11 @@ void set_option(guint id, guint position, guint value) } /* x = 0 to 60 */ -void switch_user_preset(int x) +void switch_preset(guint bank, guint x) { - static char switch_preset[] = {0x00, 0xF0, 0x00, 0x00, 0x10, 0x00, 0x5E, 0x02, 0x39, 0x00, 0x01 /* bank = user */, 0x00 /* no */, 0x04, 0x00, 0x00, 0x01, 0x00 /* confirm */, 0xF7}; - - switch_preset[11] = x; - switch_preset[16] = calculate_checksum(switch_preset, sizeof(switch_preset), 16); - - send_data(switch_preset, sizeof(switch_preset)); -} - -/* x = 0 to 60 */ -void switch_system_preset(int x) -{ - static char switch_preset[] = {0x00, 0xF0, 0x00, 0x00, 0x10, 0x00, 0x5E, 0x02, 0x39, 0x00, 0x00 /* bank = system */, 0x00 /* no */, 0x04, 0x00, 0x00, 0x01, 0x00 /* confirm */, 0xF7}; + static char switch_preset[] = {0x00, 0xF0, 0x00, 0x00, 0x10, 0x00, 0x5E, 0x02, 0x39, 0x00, 0x00 /* bank */, 0x00 /* no */, 0x04, 0x00, 0x00, 0x01, 0x00 /* confirm */, 0xF7}; + switch_preset[10] = bank; switch_preset[11] = x; switch_preset[16] = calculate_checksum(switch_preset, sizeof(switch_preset), 16); @@ -280,7 +270,7 @@ void set_preset_name(int x, gchar *name) Returns GStrv which must be freed with g_strfreev Returns NULL on error */ -GStrv query_preset_names(PresetBank bank) +GStrv query_preset_names(guint bank) { GString *data = NULL; int x; /* used to iterate over whole reply */ diff --git a/gdigi.h b/gdigi.h index 34bf5d1..f8c3624 100644 --- a/gdigi.h +++ b/gdigi.h @@ -468,8 +468,7 @@ typedef enum { } PresetBank; void set_option(guint id, guint position, guint value); -void switch_user_preset(int x); -void switch_system_preset(int x); +void switch_preset(guint bank, guint x); void set_preset_level(int level); GStrv query_preset_names(PresetBank bank); diff --git a/gui.c b/gui.c index 7bd9496..5305946 100644 --- a/gui.c +++ b/gui.c @@ -182,18 +182,104 @@ GtkWidget *create_vbox(Effect *widgets, gint amt) return vbox; } +enum { + PRESET_NAME_COLUMN = 0, + PRESET_NUMBER_COLUMN, + PRESET_BANK_COLUMN, + NUM_COLUMNS +}; + +void row_activate_cb(GtkTreeView *treeview, GtkTreePath *path, GtkTreeViewColumn *column, GtkTreeModel *model) { + GtkTreeIter iter; + gint id; + gint bank; + + gtk_tree_model_get_iter(model, &iter, path); + gtk_tree_model_get(model, &iter, PRESET_NUMBER_COLUMN, &id, PRESET_BANK_COLUMN, &bank, -1); + + if ((bank != -1) && (id != -1)) + switch_preset(bank, id); +} + +static void fill_store_with_presets(GtkTreeStore *model, guint bank, gchar *name) +{ + GtkTreeIter iter; + GtkTreeIter child_iter; + int x; + + GStrv presets = query_preset_names(bank); + gtk_tree_store_append(model, &iter, NULL); + gtk_tree_store_set(model, &iter, + PRESET_NAME_COLUMN, name, + PRESET_NUMBER_COLUMN, -1, + PRESET_BANK_COLUMN, -1, + -1); + + for (x=0; x