Entry/spinbutton fixed
[calf.git] / src / preset_gui.cpp
blob3ac8e48277bbcd534c185ba5a45abccdd9402d27
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 // gtk_widget_set_name(GTK_WIDGET(store_preset_dlg), "Calf-Preset");
53 GtkWidget *preset_name_combo = glade_xml_get_widget(store_preset_xml, "preset_name");
54 GtkTreeModel *model = GTK_TREE_MODEL(gtk_list_store_new(1, G_TYPE_STRING));
55 gtk_combo_box_set_model(GTK_COMBO_BOX(preset_name_combo), model);
56 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(preset_name_combo), 0);
57 for(preset_vector::const_iterator i = get_user_presets().presets.begin(); i != get_user_presets().presets.end(); i++)
59 if (i->plugin != gui->effect_name)
60 continue;
61 gtk_combo_box_append_text(GTK_COMBO_BOX(preset_name_combo), i->name.c_str());
63 int response = gtk_dialog_run(GTK_DIALOG(store_preset_dlg));
65 plugin_preset sp;
66 sp.name = gtk_combo_box_get_active_text(GTK_COMBO_BOX(preset_name_combo));
67 sp.bank = 0;
68 sp.program = 0;
69 sp.plugin = gui->effect_name;
71 gtk_widget_destroy(store_preset_dlg);
72 if (response == GTK_RESPONSE_OK)
74 sp.get_from(gui->plugin);
75 preset_list tmp;
76 try {
77 tmp.load(tmp.get_preset_filename(false).c_str());
79 catch(...)
81 tmp = get_user_presets();
83 bool found = false;
84 for(preset_vector::const_iterator i = tmp.presets.begin(); i != tmp.presets.end(); i++)
86 if (i->plugin == gui->effect_name && i->name == sp.name)
88 found = true;
89 break;
92 if (found)
94 GtkWidget *dialog = gtk_message_dialog_new(gui->window->toplevel, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL,
95 "Preset '%s' already exists. Overwrite?", sp.name.c_str());
96 int response = gtk_dialog_run(GTK_DIALOG(dialog));
97 gtk_widget_destroy(dialog);
98 if (response != GTK_RESPONSE_OK)
99 return;
101 tmp.add(sp);
102 get_user_presets() = tmp;
103 get_user_presets().save(tmp.get_preset_filename(false).c_str());
104 gui->window->main->refresh_all_presets(false);
106 //gtk_window_set_transient_for(GTK_WINDOW(store_preset_dlg), toplevel);
109 void calf_plugins::activate_preset(GtkAction *action, activate_preset_params *params)
111 plugin_gui *gui = params->gui;
112 plugin_preset &p = (params->builtin ? get_builtin_presets() : get_user_presets()).presets[params->preset];
113 if (p.plugin != gui->effect_name)
114 return;
115 if (!gui->plugin->activate_preset(p.bank, p.program))
116 p.activate(gui->plugin);
117 gui->refresh();