add store preset window
This commit is contained in:
2
gdigi.c
2
gdigi.c
@@ -234,7 +234,7 @@ void set_preset_level(int level)
|
|||||||
set_option(PRESET_LEVEL, PRESET_POSITION, level);
|
set_option(PRESET_LEVEL, PRESET_POSITION, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
void store_preset_name(int x, gchar *name)
|
void store_preset_name(int x, const gchar *name)
|
||||||
{
|
{
|
||||||
static char set_name[] = {0xF0, 0x00, 0x00, 0x10, 0x00, 0x5e, 0x02, 0x39, 0x00, 0x04, 0x00, 0x01, 0x00 /* preset number */, 0x00 /* name starts here */, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
static char set_name[] = {0xF0, 0x00, 0x00, 0x10, 0x00, 0x5e, 0x02, 0x39, 0x00, 0x04, 0x00, 0x01, 0x00 /* preset number */, 0x00 /* name starts here */, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||||
|
|
||||||
|
|||||||
2
gdigi.h
2
gdigi.h
@@ -496,7 +496,7 @@ typedef enum {
|
|||||||
|
|
||||||
void set_option(guint id, guint position, guint value);
|
void set_option(guint id, guint position, guint value);
|
||||||
void switch_preset(guint bank, guint x);
|
void switch_preset(guint bank, guint x);
|
||||||
void store_preset_name(int x, gchar *name);
|
void store_preset_name(int x, const gchar *name);
|
||||||
void set_preset_level(int level);
|
void set_preset_level(int level);
|
||||||
GStrv query_preset_names(PresetBank bank);
|
GStrv query_preset_names(PresetBank bank);
|
||||||
|
|
||||||
|
|||||||
76
gui.c
76
gui.c
@@ -258,6 +258,59 @@ GtkWidget *create_preset_tree()
|
|||||||
return treeview;
|
return treeview;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void show_store_preset_window(GtkWidget *window, gchar *default_name)
|
||||||
|
{
|
||||||
|
GtkWidget *dialog, *cmbox, *entry, *table, *label;
|
||||||
|
GStrv names;
|
||||||
|
int x;
|
||||||
|
|
||||||
|
dialog = gtk_dialog_new_with_buttons("Store preset",
|
||||||
|
GTK_WINDOW(window),
|
||||||
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||||
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||||
|
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
table = gtk_table_new(2, 2, FALSE);
|
||||||
|
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), table);
|
||||||
|
|
||||||
|
cmbox = gtk_combo_box_new_text();
|
||||||
|
names = query_preset_names(PRESETS_USER);
|
||||||
|
for (x=0; x<g_strv_length(names); x++) {
|
||||||
|
gchar *title = g_strdup_printf("%d - %s", x+1, names[x]);
|
||||||
|
gtk_combo_box_append_text(GTK_COMBO_BOX(cmbox), title);
|
||||||
|
g_free(title);
|
||||||
|
}
|
||||||
|
g_strfreev(names);
|
||||||
|
gtk_table_attach_defaults(GTK_TABLE(table), cmbox, 1, 2, 0, 1);
|
||||||
|
|
||||||
|
entry = gtk_entry_new();
|
||||||
|
if (default_name != NULL)
|
||||||
|
gtk_entry_set_text(GTK_ENTRY(entry), default_name);
|
||||||
|
gtk_table_attach_defaults(GTK_TABLE(table), entry, 1, 2, 1, 2);
|
||||||
|
|
||||||
|
label = gtk_label_new("Preset slot:");
|
||||||
|
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
|
||||||
|
|
||||||
|
label = gtk_label_new("Preset name:");
|
||||||
|
gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
|
||||||
|
|
||||||
|
gtk_widget_show_all(GTK_DIALOG(dialog)->vbox);
|
||||||
|
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
|
||||||
|
gint number = gtk_combo_box_get_active(GTK_COMBO_BOX(cmbox));
|
||||||
|
if (number != -1) {
|
||||||
|
store_preset_name(number, gtk_entry_get_text(GTK_ENTRY(entry)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_widget_destroy(dialog);
|
||||||
|
}
|
||||||
|
static void action_store_cb(GtkAction *action)
|
||||||
|
{
|
||||||
|
GtkWidget *window = g_object_get_data(G_OBJECT(action), "window");
|
||||||
|
show_store_preset_window(window, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static void action_show_about_dialog_cb(GtkAction *action)
|
static void action_show_about_dialog_cb(GtkAction *action)
|
||||||
{
|
{
|
||||||
static const gchar * const authors[] = {
|
static const gchar * const authors[] = {
|
||||||
@@ -326,6 +379,21 @@ static void action_open_preset_cb(GtkAction *action)
|
|||||||
gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
||||||
Preset *preset = create_preset_from_xml_file(filename);
|
Preset *preset = create_preset_from_xml_file(filename);
|
||||||
if (preset != NULL) {
|
if (preset != NULL) {
|
||||||
|
gtk_widget_hide(dialog);
|
||||||
|
|
||||||
|
GList *iter = preset->params;
|
||||||
|
while (iter) {
|
||||||
|
SettingParam *param = iter->data;
|
||||||
|
iter = iter->next;
|
||||||
|
|
||||||
|
/* sending those is likely to freeze/reboot device */
|
||||||
|
if ((param->id == 8704) || (param->id == 8705))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
set_option(param->id, param->position, param->value);
|
||||||
|
};
|
||||||
|
show_store_preset_window(window, preset->name);
|
||||||
|
|
||||||
preset_free(preset);
|
preset_free(preset);
|
||||||
loaded = TRUE;
|
loaded = TRUE;
|
||||||
}
|
}
|
||||||
@@ -347,9 +415,11 @@ static void action_quit_cb(GtkAction *action)
|
|||||||
|
|
||||||
static GtkActionEntry entries[] = {
|
static GtkActionEntry entries[] = {
|
||||||
{"File", NULL, "_File"},
|
{"File", NULL, "_File"},
|
||||||
|
{"Preset", NULL, "_Preset"},
|
||||||
{"Help", NULL, "_Help"},
|
{"Help", NULL, "_Help"},
|
||||||
{"Open", GTK_STOCK_OPEN, "_Open", "<control>O", "Open preset file", G_CALLBACK(action_open_preset_cb)},
|
{"Open", GTK_STOCK_OPEN, "_Open", "<control>O", "Open preset file", G_CALLBACK(action_open_preset_cb)},
|
||||||
{"Quit", GTK_STOCK_QUIT, "_Quit", "<control>Q", "Quit", G_CALLBACK(action_quit_cb)},
|
{"Quit", GTK_STOCK_QUIT, "_Quit", "<control>Q", "Quit", G_CALLBACK(action_quit_cb)},
|
||||||
|
{"Store", NULL, "_Store", "<control>S", "Store", G_CALLBACK(action_store_cb)},
|
||||||
{"About", GTK_STOCK_ABOUT, "_About", "<control>A", "About", G_CALLBACK(action_show_about_dialog_cb)},
|
{"About", GTK_STOCK_ABOUT, "_About", "<control>A", "About", G_CALLBACK(action_show_about_dialog_cb)},
|
||||||
};
|
};
|
||||||
static guint n_entries = G_N_ELEMENTS(entries);
|
static guint n_entries = G_N_ELEMENTS(entries);
|
||||||
@@ -362,6 +432,9 @@ static const gchar *menu_info =
|
|||||||
" <separator/>"
|
" <separator/>"
|
||||||
" <menuitem action='Quit'/>"
|
" <menuitem action='Quit'/>"
|
||||||
" </menu>"
|
" </menu>"
|
||||||
|
" <menu action='Preset'>"
|
||||||
|
" <menuitem action='Store'/>"
|
||||||
|
" </menu>"
|
||||||
" <menu action='Help'>"
|
" <menu action='Help'>"
|
||||||
" <menuitem action='About'/>"
|
" <menuitem action='About'/>"
|
||||||
" </menu>"
|
" </menu>"
|
||||||
@@ -398,6 +471,9 @@ static void add_menubar(GtkWidget *window, GtkWidget *vbox)
|
|||||||
action = gtk_ui_manager_get_action(ui, "/MenuBar/File/Open");
|
action = gtk_ui_manager_get_action(ui, "/MenuBar/File/Open");
|
||||||
g_object_set_data(G_OBJECT(action), "window", window);
|
g_object_set_data(G_OBJECT(action), "window", window);
|
||||||
|
|
||||||
|
action = gtk_ui_manager_get_action(ui, "/MenuBar/Preset/Store");
|
||||||
|
g_object_set_data(G_OBJECT(action), "window", window);
|
||||||
|
|
||||||
action = gtk_ui_manager_get_action(ui, "/MenuBar/Help/About");
|
action = gtk_ui_manager_get_action(ui, "/MenuBar/Help/About");
|
||||||
g_object_set_data(G_OBJECT(action), "window", window);
|
g_object_set_data(G_OBJECT(action), "window", window);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user