+ GUI: remove unused (and misleading) fields - the widget pointer is always stored...
[calf.git] / src / preset_gui.cpp
blob44cf74075858ae30d7c69033c7e9d575dfd18655
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 <config.h>
21 #include <map>
22 #include <glade/glade.h>
23 #include <calf/giface.h>
24 #include <calf/gui.h>
25 #include <calf/preset.h>
26 #include <calf/preset_gui.h>
27 #include <calf/main_win.h>
29 using namespace calf_plugins;
30 using namespace std;
32 // this way of filling presets menu is not that great
34 GladeXML *store_preset_xml = NULL;
35 GtkWidget *store_preset_dlg = NULL;
37 void store_preset_dlg_destroy(GtkWindow *window, gpointer data)
39 store_preset_dlg = NULL;
42 void calf_plugins::store_preset(GtkWindow *toplevel, plugin_gui *gui)
44 if (store_preset_dlg)
46 gtk_window_present(GTK_WINDOW(store_preset_dlg));
47 return;
49 store_preset_xml = glade_xml_new(PKGLIBDIR "/calf.glade", NULL, NULL);
50 store_preset_dlg = glade_xml_get_widget(store_preset_xml, "store_preset");
51 gtk_signal_connect(GTK_OBJECT(store_preset_dlg), "destroy", G_CALLBACK(store_preset_dlg_destroy), NULL);
52 GtkWidget *preset_name_combo = glade_xml_get_widget(store_preset_xml, "preset_name");
53 GtkTreeModel *model = GTK_TREE_MODEL(gtk_list_store_new(1, G_TYPE_STRING));
54 gtk_combo_box_set_model(GTK_COMBO_BOX(preset_name_combo), model);
55 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(preset_name_combo), 0);
56 for(preset_vector::const_iterator i = get_user_presets().presets.begin(); i != get_user_presets().presets.end(); i++)
58 if (i->plugin != gui->effect_name)
59 continue;
60 gtk_combo_box_append_text(GTK_COMBO_BOX(preset_name_combo), i->name.c_str());
62 int response = gtk_dialog_run(GTK_DIALOG(store_preset_dlg));
64 plugin_preset sp;
65 sp.name = gtk_combo_box_get_active_text(GTK_COMBO_BOX(preset_name_combo));
66 sp.bank = 0;
67 sp.program = 0;
68 sp.plugin = gui->effect_name;
70 gtk_widget_destroy(store_preset_dlg);
71 if (response == GTK_RESPONSE_OK)
73 sp.get_from(gui->plugin);
74 preset_list tmp;
75 try {
76 tmp.load(tmp.get_preset_filename(false).c_str());
78 catch(...)
80 tmp = get_user_presets();
82 bool found = false;
83 for(preset_vector::const_iterator i = tmp.presets.begin(); i != tmp.presets.end(); i++)
85 if (i->plugin == gui->effect_name && i->name == sp.name)
87 found = true;
88 break;
91 if (found)
93 GtkWidget *dialog = gtk_message_dialog_new(gui->window->toplevel, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL,
94 "Preset '%s' already exists. Overwrite?", sp.name.c_str());
95 int response = gtk_dialog_run(GTK_DIALOG(dialog));
96 gtk_widget_destroy(dialog);
97 if (response != GTK_RESPONSE_OK)
98 return;
100 tmp.add(sp);
101 get_user_presets() = tmp;
102 get_user_presets().save(tmp.get_preset_filename(false).c_str());
103 gui->window->main->refresh_all_presets(false);
105 //gtk_window_set_transient_for(GTK_WINDOW(store_preset_dlg), toplevel);
108 void calf_plugins::activate_preset(GtkAction *action, activate_preset_params *params)
110 plugin_gui *gui = params->gui;
111 plugin_preset &p = (params->builtin ? get_builtin_presets() : get_user_presets()).presets[params->preset];
112 if (p.plugin != gui->effect_name)
113 return;
114 if (!gui->plugin->activate_preset(p.bank, p.program))
115 p.activate(gui->plugin);
116 gui->refresh();