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