2 * Copyright (C) 2018 Robin Gareus <robin@gareus.org>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include "gtkmm2ext/utils.h"
21 #include "ardour/plugin.h"
22 #include "gui_thread.h"
24 #include "plugin_presets_ui.h"
28 using namespace ARDOUR;
30 PluginPresetsUI::PluginPresetsUI (boost::shared_ptr<PluginInsert> insert)
32 , _load_button (_("Load"))
34 _plugin_preset_model = Gtk::TreeStore::create (_plugin_preset_columns);
35 _plugin_preset_display.set_model (_plugin_preset_model);
36 _plugin_preset_display.set_headers_visible (true);
37 _plugin_preset_display.get_selection ()->set_mode (Gtk::SELECTION_SINGLE);
38 _plugin_preset_display.get_selection ()->signal_changed ().connect (sigc::mem_fun (*this, &PluginPresetsUI::preset_selected));
39 _plugin_preset_display.set_sensitive (true);
41 Gtk::CellRendererText* label_render = Gtk::manage (new Gtk::CellRendererText());
42 Gtk::TreeView::Column* label_col = Gtk::manage (new Gtk::TreeView::Column (_("Preset"), *label_render));
43 label_col->add_attribute (label_render->property_markup(), _plugin_preset_columns.name);
44 _plugin_preset_display.append_column (*label_col);
46 _preset_desc.set_editable (false);
47 _preset_desc.set_can_focus (false);
48 _preset_desc.set_wrap_mode (Gtk::WRAP_WORD);
49 _preset_desc.set_size_request (400,200);
50 _preset_desc.set_name (X_("TextOnBackground"));
51 _preset_desc.set_border_width (6);
53 _preset_scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
54 _preset_scroller.add (_plugin_preset_display);
56 _load_button.set_name ("generic button");
57 _load_button.signal_clicked.connect (sigc::mem_fun (*this, &PluginPresetsUI::load_preset));
58 _load_button.set_sensitive (false);
60 attach (_preset_scroller, 0, 1, 0, 2, Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 2, 0);
61 attach (_preset_desc, 1, 2, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::FILL, 2, 0);
62 attach (_load_button, 1, 2, 1, 2, Gtk::FILL, Gtk::SHRINK, 2, 0);
64 boost::shared_ptr<Plugin> plugin (_insert->plugin ());
66 plugin->PresetAdded.connect (_preset_connections, invalidator (*this), boost::bind (&PluginPresetsUI::update_preset_list, this), gui_context ());
67 plugin->PresetRemoved.connect (_preset_connections, invalidator (*this), boost::bind (&PluginPresetsUI::update_preset_list, this), gui_context ());
68 plugin->PresetLoaded.connect (_preset_connections, invalidator (*this), boost::bind (&PluginPresetsUI::update_preset_list, this), gui_context ());
70 update_preset_list ();
74 PluginPresetsUI::update_preset_list ()
76 boost::shared_ptr<Plugin> plugin (_insert->plugin ());
78 Plugin::PresetRecord const& p = plugin->last_preset ();
79 std::vector<Plugin::PresetRecord> presets = plugin->get_presets ();
82 std::string selected_uri;
83 if (_plugin_preset_display.get_selection ()->count_selected_rows () == 1) {
84 Gtk::TreeIter iter = _plugin_preset_display.get_selection ()->get_selected ();
85 ARDOUR::Plugin::PresetRecord const& ppr ((*iter)[_plugin_preset_columns.plugin_preset]);
86 selected_uri = ppr.uri;
89 _plugin_preset_model->clear ();
91 bool found_active = false;
93 for (std::vector<Plugin::PresetRecord>::const_iterator i = presets.begin (); i != presets.end (); ++i) {
94 Gtk::TreeModel::Row row = *(_plugin_preset_model->append ());
95 if (p.uri == i->uri) {
96 row[_plugin_preset_columns.name] = string_compose ("<span weight=\"bold\" background=\"green\">%1</span>", Gtkmm2ext::markup_escape_text (i->label));
99 row[_plugin_preset_columns.name] = Gtkmm2ext::markup_escape_text (i->label);
101 row[_plugin_preset_columns.description] = i->description;
102 row[_plugin_preset_columns.plugin_preset] = *i;
106 Gtk::TreeModel::Row row = *(_plugin_preset_model->prepend ());
108 row[_plugin_preset_columns.name] = _("(none)");
110 row[_plugin_preset_columns.name] = string_compose ("<span weight=\"bold\" background=\"green\">%1</span>", _("(none)"));
112 row[_plugin_preset_columns.description] = "";
113 row[_plugin_preset_columns.plugin_preset] = Plugin::PresetRecord ();
116 Gtk::TreeModel::Children rows = _plugin_preset_model->children ();
117 for (Gtk::TreeModel::Children::iterator i = rows.begin (); i != rows.end (); ++i) {
118 ARDOUR::Plugin::PresetRecord const& ppr ((*i)[_plugin_preset_columns.plugin_preset]);
119 if (ppr.uri == selected_uri) {
120 _plugin_preset_display.get_selection ()->select (*i);
128 PluginPresetsUI::preset_selected ()
130 if (_plugin_preset_display.get_selection ()->count_selected_rows () != 1) {
134 Gtk::TreeIter iter = _plugin_preset_display.get_selection ()->get_selected ();
136 ARDOUR::Plugin::PresetRecord const& ppr ((*iter)[_plugin_preset_columns.plugin_preset]);
141 } else if (ppr.user) {
142 d = _("(user preset)");
144 d = (*iter)[_plugin_preset_columns.description];
146 _preset_desc.get_buffer ()->set_text (d);
148 Plugin::PresetRecord const& p = _insert->plugin ()->last_preset ();
149 _load_button.set_sensitive (ppr.valid && !(p.valid && p.uri == ppr.uri));
153 PluginPresetsUI::load_preset ()
155 if (_plugin_preset_display.get_selection ()->count_selected_rows () != 1) {
159 Gtk::TreeIter iter = _plugin_preset_display.get_selection ()->get_selected ();
160 ARDOUR::Plugin::PresetRecord const& ppr ((*iter)[_plugin_preset_columns.plugin_preset]);
162 _insert->load_preset (ppr);