Enable some key release event forwarding
[ardour.git] / gtk2_ardour / plugin_ui.cc
index d351e5efba147195ae2f73f6257e1c0661cf9ec6..b4a22c6f902f08c35c3615a78cb3601e80807cd6 100644 (file)
@@ -1,21 +1,27 @@
 /*
-    Copyright (C) 2000 Paul Davis
-
-    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., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
+ * Copyright (C) 2005-2006 Nick Mainsbridge <mainsbridge@gmail.com>
+ * Copyright (C) 2005-2017 Paul Davis <paul@linuxaudiosystems.com>
+ * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
+ * Copyright (C) 2006-2009 Sampo Savolainen <v2@iki.fi>
+ * Copyright (C) 2006-2015 David Robillard <d@drobilla.net>
+ * Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
+ * Copyright (C) 2012-2019 Robin Gareus <robin@gareus.org>
+ * Copyright (C) 2013-2018 John Emmas <john@creativepost.co.uk>
+ *
+ * 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.
+ */
 
 #ifdef WAF_BUILD
 #include "gtk2ardour-config.h"
 #include "pbd/xml++.h"
 #include "pbd/failed_constructor.h"
 
-#include <gtkmm/widget.h>
-#include <gtkmm/box.h>
-#include <gtkmm2ext/click_box.h>
-#include <gtkmm2ext/fastmeter.h>
-#include <gtkmm2ext/barcontroller.h>
-#include <gtkmm2ext/utils.h>
-#include <gtkmm2ext/doi.h>
-#include <gtkmm2ext/slider_controller.h>
-#include <gtkmm2ext/application.h>
+#include "gtkmm/widget.h"
+#include "gtkmm/box.h"
+
+#include "gtkmm2ext/utils.h"
+#include "gtkmm2ext/doi.h"
+#include "gtkmm2ext/application.h"
+
+#include "widgets/tooltips.h"
+#include "widgets/fastmeter.h"
 
 #include "ardour/session.h"
 #include "ardour/plugin.h"
 #include "ardour/lxvst_plugin.h"
 #include "lxvst_plugin_ui.h"
 #endif
+#ifdef MACVST_SUPPORT
+#include "ardour/mac_vst_plugin.h"
+#include "vst_plugin_ui.h"
+#endif
 #ifdef LV2_SUPPORT
 #include "ardour/lv2_plugin.h"
 #include "lv2_plugin_ui.h"
 
 #include "ardour_window.h"
 #include "ardour_ui.h"
-#include "prompter.h"
 #include "plugin_ui.h"
 #include "utils.h"
 #include "gui_thread.h"
 #include "public_editor.h"
+#include "processor_box.h"
 #include "keyboard.h"
 #include "latency_gui.h"
+#include "plugin_dspload_ui.h"
 #include "plugin_eq_gui.h"
+#include "plugin_presets_ui.h"
+#include "timers.h"
 #include "new_plugin_preset_dialog.h"
-#include "tooltips.h"
 
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 using namespace std;
 using namespace ARDOUR;
 using namespace ARDOUR_UI_UTILS;
+using namespace ArdourWidgets;
 using namespace PBD;
 using namespace Gtkmm2ext;
 using namespace Gtk;
 
+
 PluginUIWindow::PluginUIWindow (
        boost::shared_ptr<PluginInsert> insert,
        bool                            scrollable,
@@ -87,8 +101,8 @@ PluginUIWindow::PluginUIWindow (
        , was_visible (false)
        , _keyboard_focused (false)
 #ifdef AUDIOUNIT_SUPPORT
-        , pre_deactivate_x (-1)
-        , pre_deactivate_y (-1)
+       , pre_deactivate_x (-1)
+       , pre_deactivate_y (-1)
 #endif
 
 {
@@ -106,6 +120,10 @@ PluginUIWindow::PluginUIWindow (
                        have_gui = create_lxvst_editor (insert);
                        break;
 
+               case ARDOUR::MacVST:
+                       have_gui = create_mac_vst_editor (insert);
+                       break;
+
                case ARDOUR::AudioUnit:
                        have_gui = create_audiounit_editor (insert);
                        break;
@@ -155,6 +173,7 @@ PluginUIWindow::PluginUIWindow (
                if (h > 600) h = 600;
        }
 
+       set_border_width (0);
        set_default_size (w, h);
        set_resizable (_pluginui->resizable());
 }
@@ -178,10 +197,10 @@ PluginUIWindow::on_show ()
        }
 
        if (_pluginui) {
-#if defined (HAVE_AUDIOUNITS) && defined(GTKOSX)
-                if (pre_deactivate_x >= 0) {
-                        move (pre_deactivate_x, pre_deactivate_y);
-                }
+#if defined (HAVE_AUDIOUNITS) && defined(__APPLE__)
+               if (pre_deactivate_x >= 0) {
+                       move (pre_deactivate_x, pre_deactivate_y);
+               }
 #endif
 
                if (_pluginui->on_window_show (_title)) {
@@ -193,8 +212,8 @@ PluginUIWindow::on_show ()
 void
 PluginUIWindow::on_hide ()
 {
-#if defined (HAVE_AUDIOUNITS) && defined(GTKOSX)
-        get_position (pre_deactivate_x, pre_deactivate_y);
+#if defined (HAVE_AUDIOUNITS) && defined(__APPLE__)
+       get_position (pre_deactivate_x, pre_deactivate_y);
 #endif
 
        Window::on_hide ();
@@ -271,6 +290,35 @@ PluginUIWindow::create_lxvst_editor(boost::shared_ptr<PluginInsert>)
 #endif
 }
 
+bool
+#ifdef MACVST_SUPPORT
+PluginUIWindow::create_mac_vst_editor (boost::shared_ptr<PluginInsert> insert)
+#else
+PluginUIWindow::create_mac_vst_editor (boost::shared_ptr<PluginInsert>)
+#endif
+{
+#ifndef MACVST_SUPPORT
+       return false;
+#else
+       boost::shared_ptr<MacVSTPlugin> mvst;
+       if ((mvst = boost::dynamic_pointer_cast<MacVSTPlugin> (insert->plugin())) == 0) {
+               error << string_compose (_("unknown type of editor-supplying plugin (note: no MacVST support in this version of %1)"), PROGRAM_NAME)
+                     << endmsg;
+               throw failed_constructor ();
+       }
+       VSTPluginUI* vpu = create_mac_vst_gui (insert);
+       _pluginui = vpu;
+       _pluginui->KeyboardFocused.connect (sigc::mem_fun (*this, &PluginUIWindow::keyboard_focused));
+       add (*vpu);
+       vpu->package (*this);
+
+       Application::instance()->ActivationChanged.connect (mem_fun (*this, &PluginUIWindow::app_activated));
+
+       return true;
+#endif
+}
+
+
 bool
 #ifdef AUDIOUNIT_SUPPORT
 PluginUIWindow::create_audiounit_editor (boost::shared_ptr<PluginInsert> insert)
@@ -293,7 +341,7 @@ PluginUIWindow::create_audiounit_editor (boost::shared_ptr<PluginInsert>)
 }
 
 void
-#ifdef GTKOSX
+#ifdef __APPLE__
 PluginUIWindow::app_activated (bool yn)
 #else
 PluginUIWindow::app_activated (bool)
@@ -304,15 +352,15 @@ PluginUIWindow::app_activated (bool)
                if (yn) {
                        if (was_visible) {
                                _pluginui->activate ();
-                                if (pre_deactivate_x >= 0) {
-                                        move (pre_deactivate_x, pre_deactivate_y);
-                                }
+                               if (pre_deactivate_x >= 0) {
+                                       move (pre_deactivate_x, pre_deactivate_y);
+                               }
                                present ();
                                was_visible = true;
                        }
                } else {
                        was_visible = is_visible();
-                        get_position (pre_deactivate_x, pre_deactivate_y);
+                       get_position (pre_deactivate_x, pre_deactivate_y);
                        hide ();
                        _pluginui->deactivate ();
                }
@@ -362,11 +410,11 @@ PluginUIWindow::on_key_press_event (GdkEventKey* event)
                        }
                }
                return true;
-       } 
+       }
        /* for us to be getting key press events, there really
           MUST be a _pluginui, but just to be safe, check ...
        */
-       
+
        if (_pluginui) {
                _pluginui->grab_focus();
                if (_pluginui->non_gtk_gui()) {
@@ -379,7 +427,7 @@ PluginUIWindow::on_key_press_event (GdkEventKey* event)
                } else {
                        return relay_key_press (event, this);
                }
-       } 
+       }
 
        return false;
 }
@@ -391,13 +439,13 @@ PluginUIWindow::on_key_release_event (GdkEventKey *event)
                if (_pluginui) {
                        if (_pluginui->non_gtk_gui()) {
                                _pluginui->forward_key_event (event);
+                               return true;
                        }
-                       return true;
                }
-               return false;
        } else {
-               return true;
+               gtk_window_propagate_key_event (GTK_WINDOW(gobj()), event);
        }
+       return relay_key_press (event, this);
 }
 
 void
@@ -418,13 +466,19 @@ PlugUIBase::PlugUIBase (boost::shared_ptr<PluginInsert> pi)
        , add_button (_("Add"))
        , save_button (_("Save"))
        , delete_button (_("Delete"))
+       , preset_browser_button (_("Preset Browser"))
        , reset_button (_("Reset"))
        , bypass_button (ArdourButton::led_default_elements)
+       , pin_management_button (_("Pinout"))
        , description_expander (_("Description"))
        , plugin_analysis_expander (_("Plugin analysis"))
+       , cpuload_expander (_("CPU Profile"))
        , latency_gui (0)
        , latency_dialog (0)
        , eqgui (0)
+       , stats_gui (0)
+       , preset_gui (0)
+       , preset_dialog (0)
 {
        _preset_modified.set_size_request (16, -1);
        _preset_combo.set_text("(default)");
@@ -432,31 +486,49 @@ PlugUIBase::PlugUIBase (boost::shared_ptr<PluginInsert> pi)
        set_tooltip (add_button, _("Save a new preset"));
        set_tooltip (save_button, _("Save the current preset"));
        set_tooltip (delete_button, _("Delete the current preset"));
+       set_tooltip (preset_browser_button, _("Show Preset Browser Dialog"));
        set_tooltip (reset_button, _("Reset parameters to default (if no parameters are in automation play mode)"));
+       set_tooltip (pin_management_button, _("Show Plugin Pin Management Dialog"));
        set_tooltip (bypass_button, _("Disable signal processing by the plugin"));
+       set_tooltip (latency_button, _("Edit Plugin Delay/Latency Compensation"));
        _no_load_preset = 0;
 
        update_preset_list ();
        update_preset ();
 
+       latency_button.set_icon (ArdourIcon::LatencyClock);
+       latency_button.add_elements (ArdourButton::Text);
+
        add_button.set_name ("generic button");
+       add_button.set_icon (ArdourIcon::PsetAdd);
        add_button.signal_clicked.connect (sigc::mem_fun (*this, &PlugUIBase::add_plugin_setting));
 
        save_button.set_name ("generic button");
+       save_button.set_icon (ArdourIcon::PsetSave);
        save_button.signal_clicked.connect(sigc::mem_fun(*this, &PlugUIBase::save_plugin_setting));
 
        delete_button.set_name ("generic button");
+       delete_button.set_icon (ArdourIcon::PsetDelete);
        delete_button.signal_clicked.connect (sigc::mem_fun (*this, &PlugUIBase::delete_plugin_setting));
 
+       preset_browser_button.set_name ("generic button");
+       preset_browser_button.set_icon (ArdourIcon::PsetBrowse);
+       preset_browser_button.signal_clicked.connect (sigc::mem_fun (*this, &PlugUIBase::browse_presets));
+
        reset_button.set_name ("generic button");
+       reset_button.set_icon (ArdourIcon::PluginReset);
        reset_button.signal_clicked.connect (sigc::mem_fun (*this, &PlugUIBase::reset_plugin_parameters));
 
+       pin_management_button.set_name ("generic button");
+       pin_management_button.set_icon (ArdourIcon::PluginPinout);
+       pin_management_button.signal_clicked.connect (sigc::mem_fun (*this, &PlugUIBase::manage_pins));
 
        insert->ActiveChanged.connect (active_connection, invalidator (*this), boost::bind (&PlugUIBase::processor_active_changed, this,  boost::weak_ptr<Processor>(insert)), gui_context());
 
        bypass_button.set_name ("plugin bypass button");
        bypass_button.set_text (_("Bypass"));
-       bypass_button.set_active (!pi->active());
+       bypass_button.set_icon (ArdourIcon::PluginBypass);
+       bypass_button.set_active (!pi->enabled ());
        bypass_button.signal_button_release_event().connect (sigc::mem_fun(*this, &PlugUIBase::bypass_button_release), false);
        focus_button.add_events (Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK);
 
@@ -479,6 +551,9 @@ PlugUIBase::PlugUIBase (boost::shared_ptr<PluginInsert> pi)
        plugin_analysis_expander.property_expanded().signal_changed().connect( sigc::mem_fun(*this, &PlugUIBase::toggle_plugin_analysis));
        plugin_analysis_expander.set_expanded(false);
 
+       cpuload_expander.property_expanded().signal_changed().connect( sigc::mem_fun(*this, &PlugUIBase::toggle_cpuload_display));
+       cpuload_expander.set_expanded(false);
+
        insert->DropReferences.connect (death_connection, invalidator (*this), boost::bind (&PlugUIBase::plugin_going_away, this), gui_context());
 
        plugin->PresetAdded.connect (*this, invalidator (*this), boost::bind (&PlugUIBase::preset_added_or_removed, this), gui_context ());
@@ -488,13 +563,19 @@ PlugUIBase::PlugUIBase (boost::shared_ptr<PluginInsert> pi)
 
        insert->AutomationStateChanged.connect (*this, invalidator (*this), boost::bind (&PlugUIBase::automation_state_changed, this), gui_context());
 
+       insert->LatencyChanged.connect (*this, invalidator (*this), boost::bind (&PlugUIBase::set_latency_label, this), gui_context());
+
        automation_state_changed();
 }
 
 PlugUIBase::~PlugUIBase()
 {
        delete eqgui;
+       delete stats_gui;
+       delete preset_gui;
        delete latency_gui;
+       delete latency_dialog;
+       delete preset_dialog;
 }
 
 void
@@ -508,25 +589,17 @@ PlugUIBase::plugin_going_away ()
 void
 PlugUIBase::set_latency_label ()
 {
-       framecnt_t const l = insert->effective_latency ();
-       framecnt_t const sr = insert->session().frame_rate ();
+       samplecnt_t const l = insert->effective_latency ();
+       float const sr = insert->session().sample_rate ();
 
-       string t;
-
-       if (l < sr / 1000) {
-               t = string_compose (P_("latency (%1 sample)", "latency (%1 samples)", l), l);
-       } else {
-               t = string_compose (_("latency (%1 ms)"), (float) l / ((float) sr / 1000.0f));
-       }
-
-       latency_button.set_text (t);
+       latency_button.set_text (samples_as_time_string (l, sr, true));
 }
 
 void
 PlugUIBase::latency_button_clicked ()
 {
        if (!latency_gui) {
-               latency_gui = new LatencyGUI (*(insert.get()), insert->session().frame_rate(), insert->session().get_block_size());
+               latency_gui = new LatencyGUI (*(insert.get()), insert->session().sample_rate(), insert->session().get_block_size());
                latency_dialog = new ArdourWindow (_("Edit Latency"));
                /* use both keep-above and transient for to try cover as many
                   different WM's as possible.
@@ -537,9 +610,9 @@ PlugUIBase::latency_button_clicked ()
                        latency_dialog->set_transient_for (*win);
                }
                latency_dialog->add (*latency_gui);
-               latency_dialog->signal_hide().connect (sigc::mem_fun (*this, &PlugUIBase::set_latency_label));
        }
 
+       latency_gui->refresh ();
        latency_dialog->show_all ();
 }
 
@@ -550,7 +623,7 @@ PlugUIBase::processor_active_changed (boost::weak_ptr<Processor> weak_p)
        boost::shared_ptr<Processor> p (weak_p.lock());
 
        if (p) {
-               bypass_button.set_active (!p->active());
+               bypass_button.set_active (!p->enabled ());
        }
 }
 
@@ -561,34 +634,16 @@ PlugUIBase::preset_selected (Plugin::PresetRecord preset)
                return;
        }
        if (!preset.label.empty()) {
-               plugin->load_preset (preset);
+               insert->load_preset (preset);
        } else {
                // blank selected = no preset
                plugin->clear_preset();
        }
 }
 
-#ifdef NO_PLUGIN_STATE
-static bool seen_saving_message = false;
-
-static void show_no_plugin_message()
-{
-       info << string_compose (_("Plugin presets are not supported in this build of %1. Consider paying for a full version"),
-                       PROGRAM_NAME)
-            << endmsg;
-       info << _("To get full access to updates without this limitation\n"
-                 "consider becoming a subscriber for a low cost every month.")
-            << endmsg;
-       info << X_("https://community.ardour.org/s/subscribe")
-            << endmsg;
-       ARDOUR_UI::instance()->popup_error(_("Plugin presets are not supported in this build, see the Log window for more information."));
-}
-#endif
-
 void
 PlugUIBase::add_plugin_setting ()
 {
-#ifndef NO_PLUGIN_STATE
        NewPluginPresetDialog d (plugin, _("New Preset"));
 
        switch (d.run ()) {
@@ -607,43 +662,23 @@ PlugUIBase::add_plugin_setting ()
                }
                break;
        }
-#else
-       if (!seen_saving_message) {
-               seen_saving_message = true;
-               show_no_plugin_message();
-       }
-#endif
 }
 
 void
 PlugUIBase::save_plugin_setting ()
 {
-#ifndef NO_PLUGIN_STATE
        string const name = _preset_combo.get_text ();
        plugin->remove_preset (name);
        Plugin::PresetRecord const r = plugin->save_preset (name);
        if (!r.uri.empty ()) {
                plugin->load_preset (r);
        }
-#else
-       if (!seen_saving_message) {
-               seen_saving_message = true;
-               show_no_plugin_message();
-       }
-#endif
 }
 
 void
 PlugUIBase::delete_plugin_setting ()
 {
-#ifndef NO_PLUGIN_STATE
        plugin->remove_preset (_preset_combo.get_text ());
-#else
-       if (!seen_saving_message) {
-               seen_saving_message = true;
-               show_no_plugin_message();
-       }
-#endif
 }
 
 void
@@ -658,17 +693,58 @@ PlugUIBase::reset_plugin_parameters ()
        insert->reset_parameters_to_default ();
 }
 
+bool
+PlugUIBase::has_descriptive_presets () const
+{
+       std::vector<Plugin::PresetRecord> presets = insert->plugin()->get_presets();
+       for (std::vector<Plugin::PresetRecord>::const_iterator i = presets.begin(); i != presets.end(); ++i) {
+               if (i->valid && !i->description.empty()) {
+                       return true;
+               }
+       }
+       return false;
+}
+
+void
+PlugUIBase::browse_presets ()
+{
+       if (!preset_dialog) {
+               if (preset_gui) {
+                       /* Do not allow custom window, if preset_gui is used.
+                        * e.g. generic-plugin UI.
+                        */
+                       return;
+               }
+               preset_dialog = new ArdourWindow (_("Select Preset"));
+               preset_dialog->set_keep_above (true);
+               Window* win = dynamic_cast<Window*> (preset_browser_button.get_toplevel ());
+               if (win) {
+                       preset_dialog->set_transient_for (*win);
+               }
+               preset_gui = new PluginPresetsUI (insert);
+               preset_dialog->add (*preset_gui);
+       }
+       preset_dialog->show_all ();
+}
+
+void
+PlugUIBase::manage_pins ()
+{
+       PluginPinWindowProxy* proxy = insert->pinmgr_proxy ();
+       if (proxy) {
+               proxy->get (true);
+               proxy->present ();
+               proxy->get ()->raise();
+       }
+}
+
 bool
 PlugUIBase::bypass_button_release (GdkEventButton*)
 {
        bool view_says_bypassed = (bypass_button.active_state() != 0);
 
-       if (view_says_bypassed != insert->active()) {
-               if (view_says_bypassed) {
-                       insert->activate ();
-               } else {
-                       insert->deactivate ();
-               }
+       if (view_says_bypassed != insert->enabled ()) {
+               insert->enable (view_says_bypassed);
        }
 
        return false;
@@ -714,11 +790,21 @@ PlugUIBase::toggle_description()
        }
 
        if (!description_expander.get_expanded()) {
+               const int child_height = description_expander.get_child ()->get_height ();
+
                description_expander.remove();
+
+               Gtk::Window *toplevel = (Gtk::Window*) description_expander.get_ancestor (GTK_TYPE_WINDOW);
+
+               if (toplevel) {
+                       Gtk::Requisition wr;
+                       toplevel->get_size (wr.width, wr.height);
+                       wr.height -= child_height;
+                       toplevel->resize (wr.width, wr.height);
+               }
        }
 }
 
-
 void
 PlugUIBase::toggle_plugin_analysis()
 {
@@ -729,12 +815,6 @@ PlugUIBase::toggle_plugin_analysis()
                        eqgui = new PluginEqGui (insert);
                }
 
-               Gtk::Window *toplevel = (Gtk::Window*) plugin_analysis_expander.get_ancestor (GTK_TYPE_WINDOW);
-
-               if (toplevel) {
-                       toplevel->get_size (pre_eq_size.width, pre_eq_size.height);
-               }
-
                plugin_analysis_expander.add (*eqgui);
                plugin_analysis_expander.show_all ();
                eqgui->start_listening ();
@@ -742,6 +822,7 @@ PlugUIBase::toggle_plugin_analysis()
 
        if (!plugin_analysis_expander.get_expanded()) {
                // Hide & remove from expander
+               const int child_height = plugin_analysis_expander.get_child ()->get_height ();
 
                eqgui->hide ();
                eqgui->stop_listening ();
@@ -750,11 +831,45 @@ PlugUIBase::toggle_plugin_analysis()
                Gtk::Window *toplevel = (Gtk::Window*) plugin_analysis_expander.get_ancestor (GTK_TYPE_WINDOW);
 
                if (toplevel) {
-                       toplevel->resize (pre_eq_size.width, pre_eq_size.height);
+                       Gtk::Requisition wr;
+                       toplevel->get_size (wr.width, wr.height);
+                       wr.height -= child_height;
+                       toplevel->resize (wr.width, wr.height);
                }
        }
 }
 
+void
+PlugUIBase::toggle_cpuload_display()
+{
+       if (cpuload_expander.get_expanded() && !cpuload_expander.get_child()) {
+               if (stats_gui == 0) {
+                       stats_gui = new PluginLoadStatsGui (insert);
+               }
+               cpuload_expander.add (*stats_gui);
+               cpuload_expander.show_all();
+               stats_gui->start_updating ();
+       }
+
+       if (!cpuload_expander.get_expanded()) {
+               const int child_height = cpuload_expander.get_child ()->get_height ();
+
+               stats_gui->hide ();
+               stats_gui->stop_updating ();
+               cpuload_expander.remove();
+
+               Gtk::Window *toplevel = (Gtk::Window*) cpuload_expander.get_ancestor (GTK_TYPE_WINDOW);
+
+               if (toplevel) {
+                       Gtk::Requisition wr;
+                       toplevel->get_size (wr.width, wr.height);
+                       wr.height -= child_height;
+                       toplevel->resize (wr.width, wr.height);
+               }
+       }
+
+}
+
 void
 PlugUIBase::update_preset_list ()
 {
@@ -792,17 +907,17 @@ PlugUIBase::update_preset ()
        }
        --_no_load_preset;
 
-       save_button.set_sensitive (!p.uri.empty() && p.user);
        delete_button.set_sensitive (!p.uri.empty() && p.user);
-
        update_preset_modified ();
 }
 
 void
 PlugUIBase::update_preset_modified ()
 {
+       Plugin::PresetRecord p = plugin->last_preset();
 
-       if (plugin->last_preset().uri.empty()) {
+       if (p.uri.empty()) {
+               save_button.set_sensitive (false);
                _preset_modified.set_text ("");
                return;
        }
@@ -811,6 +926,7 @@ PlugUIBase::update_preset_modified ()
        if (_preset_modified.get_text().empty() == c) {
                _preset_modified.set_text (c ? "*" : "");
        }
+       save_button.set_sensitive (c && p.user);
 }
 
 void