LineGraph: z axis for lo and hi pass handles
[calf.git] / src / preset_gui.cpp
blobb674aee4736e94ac406429b1067a1d9f58cf4111
1 /* Calf DSP Library
2 * GUI functions for preset management.
3 * Copyright (C) 2007 Krzysztof Foltman
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <calf/gui.h>
21 #include <calf/preset.h>
22 #include <calf/preset_gui.h>
24 using namespace calf_plugins;
25 using namespace std;
27 // this way of filling presets menu is not that great
29 struct activate_preset_params
31 plugin_gui *gui;
32 int preset;
33 bool builtin;
35 activate_preset_params(plugin_gui *_gui, int _preset, bool _builtin)
36 : gui(_gui), preset(_preset), builtin(_builtin)
41 gui_preset_access::gui_preset_access(plugin_gui *_gui)
43 gui = _gui;
44 store_preset_dlg = NULL;
47 void gui_preset_access::store_preset()
49 if (store_preset_dlg)
51 gtk_window_present(GTK_WINDOW(store_preset_dlg));
52 return;
54 GtkBuilder *store_preset_builder = gtk_builder_new();
55 const gchar *objects[] = { "store_preset", NULL };
56 GError *error = NULL;
57 if (!gtk_builder_add_objects_from_file(store_preset_builder, PKGLIBDIR "/calf-gui.xml", (gchar **)objects, &error))
59 g_warning("Cannot load preset GUI dialog: %s", error->message);
60 g_error_free(error);
61 g_object_unref(G_OBJECT(store_preset_builder));
62 return;
64 store_preset_dlg = GTK_WIDGET(gtk_builder_get_object(store_preset_builder, "store_preset"));
65 g_signal_connect(GTK_OBJECT(store_preset_dlg), "destroy", G_CALLBACK(on_dlg_destroy_window), (gui_preset_access *)this);
66 // gtk_widget_set_name(GTK_WIDGET(store_preset_dlg), "Calf-Preset");
67 GtkWidget *preset_name_combo = GTK_WIDGET(gtk_builder_get_object(store_preset_builder, "preset_name"));
68 GtkTreeModel *model = GTK_TREE_MODEL(gtk_list_store_new(1, G_TYPE_STRING));
69 gtk_combo_box_set_model(GTK_COMBO_BOX(preset_name_combo), model);
70 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(preset_name_combo), 0);
71 for(preset_vector::const_iterator i = get_user_presets().presets.begin(); i != get_user_presets().presets.end(); ++i)
73 if (i->plugin != gui->effect_name)
74 continue;
75 gtk_combo_box_append_text(GTK_COMBO_BOX(preset_name_combo), i->name.c_str());
77 int response = gtk_dialog_run(GTK_DIALOG(store_preset_dlg));
79 plugin_preset sp;
80 sp.name = gtk_combo_box_get_active_text(GTK_COMBO_BOX(preset_name_combo));
81 sp.bank = 0;
82 sp.program = 0;
83 sp.plugin = gui->effect_name;
85 gtk_widget_destroy(store_preset_dlg);
86 if (response == GTK_RESPONSE_OK)
88 sp.get_from(gui->plugin);
89 preset_list tmp;
90 try {
91 tmp.load(tmp.get_preset_filename(false).c_str(), false);
93 catch(...)
95 tmp = get_user_presets();
97 bool found = false;
98 for(preset_vector::const_iterator i = tmp.presets.begin(); i != tmp.presets.end(); ++i)
100 if (i->plugin == gui->effect_name && i->name == sp.name)
102 found = true;
103 break;
106 if (found)
108 GtkWidget *dialog = gtk_message_dialog_new(gui->window->toplevel, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL,
109 "Preset '%s' already exists. Overwrite?", sp.name.c_str());
110 int response = gtk_dialog_run(GTK_DIALOG(dialog));
111 gtk_widget_destroy(dialog);
112 if (response != GTK_RESPONSE_OK)
113 return;
115 tmp.add(sp);
116 get_user_presets() = tmp;
117 get_user_presets().save(tmp.get_preset_filename(false).c_str());
118 if (gui->window->main)
119 gui->window->main->refresh_all_presets(false);
121 g_object_unref(G_OBJECT(store_preset_builder));
124 void gui_preset_access::activate_preset(int preset, bool builtin)
126 plugin_preset &p = (builtin ? get_builtin_presets() : get_user_presets()).presets[preset];
127 if (p.plugin != gui->effect_name)
128 return;
129 if (!gui->plugin->activate_preset(p.bank, p.program))
130 p.activate(gui->plugin);
131 gui->refresh();
134 void gui_preset_access::on_dlg_destroy_window(GtkWindow *window, gpointer data)
136 ((gui_preset_access *)data)->store_preset_dlg = NULL;