fix embedded plugin UI keyboard handling
[ardour.git] / gtk2_ardour / plugin_ui.cc
index 943a7a8bce4b058a77588a1710cfb22def3a8892..b4e8e0001efdc62b4690e4afb4680bd519ceafc9 100644 (file)
@@ -40,8 +40,6 @@
 #include <gtkmm2ext/slider_controller.h>
 #include <gtkmm2ext/application.h>
 
-#include "midi++/manager.h"
-
 #include "ardour/session.h"
 #include "ardour/plugin.h"
 #include "ardour/plugin_insert.h"
@@ -59,8 +57,6 @@
 #include "lv2_plugin_ui.h"
 #endif
 
-#include <lrdf.h>
-
 #include "ardour_window.h"
 #include "ardour_ui.h"
 #include "prompter.h"
@@ -77,6 +73,7 @@
 
 using namespace std;
 using namespace ARDOUR;
+using namespace ARDOUR_UI_UTILS;
 using namespace PBD;
 using namespace Gtkmm2ext;
 using namespace Gtk;
@@ -148,7 +145,6 @@ PluginUIWindow::PluginUIWindow (
        set_name ("PluginEditor");
        add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK|Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
 
-       signal_delete_event().connect (sigc::bind (sigc::ptr_fun (just_hide_it), reinterpret_cast<Window*> (this)), false);
        insert->DropReferences.connect (death_connection, invalidator (*this), boost::bind (&PluginUIWindow::plugin_going_away, this), gui_context());
 
        gint h = _pluginui->get_preferred_height ();
@@ -164,6 +160,9 @@ PluginUIWindow::PluginUIWindow (
 
 PluginUIWindow::~PluginUIWindow ()
 {
+#ifndef NDEBUG
+       cerr << "PluginWindow deleted for " << this << endl;
+#endif
        delete _pluginui;
 }
 
@@ -229,7 +228,7 @@ PluginUIWindow::create_windows_vst_editor(boost::shared_ptr<PluginInsert>)
                      << endmsg;
                throw failed_constructor ();
        } else {
-               WindowsVSTPluginUI* vpu = new WindowsVSTPluginUI (insert, vp);
+               WindowsVSTPluginUI* vpu = new WindowsVSTPluginUI (insert, vp, GTK_WIDGET(this->gobj()));
 
                _pluginui = vpu;
                _pluginui->KeyboardFocused.connect (sigc::mem_fun (*this, &PluginUIWindow::keyboard_focused));
@@ -334,6 +333,7 @@ PluginUIWindow::create_lv2_editor(boost::shared_ptr<PluginInsert> insert)
                _pluginui = lpu;
                add (*lpu);
                lpu->package (*this);
+               _pluginui->KeyboardFocused.connect (sigc::mem_fun (*this, &PluginUIWindow::keyboard_focused));
        }
 
        return true;
@@ -353,6 +353,7 @@ PluginUIWindow::on_key_press_event (GdkEventKey* event)
 {
        if (_keyboard_focused) {
                if (_pluginui) {
+                       _pluginui->grab_focus();
                        if (_pluginui->non_gtk_gui()) {
                                _pluginui->forward_key_event (event);
                        } else {
@@ -366,6 +367,7 @@ PluginUIWindow::on_key_press_event (GdkEventKey* event)
                */
 
                if (_pluginui) {
+                       _pluginui->grab_focus();
                        if (_pluginui->non_gtk_gui()) {
                                /* pass editor window as the window for the event
                                   to be handled in, not this one, because there are
@@ -408,8 +410,6 @@ PluginUIWindow::plugin_going_away ()
        }
 
        death_connection.disconnect ();
-
-       delete_when_idle (this);
 }
 
 PlugUIBase::PlugUIBase (boost::shared_ptr<PluginInsert> pi)
@@ -451,7 +451,7 @@ PlugUIBase::PlugUIBase (boost::shared_ptr<PluginInsert> pi)
        bypass_button.set_name ("plugin bypass button");
        bypass_button.set_text (_("Bypass"));
        bypass_button.set_active (!pi->active());
-       bypass_button.signal_button_release_event().connect (sigc::mem_fun(*this, &PlugUIBase::bypass_button_release));
+       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);
 
        focus_button.signal_button_release_event().connect (sigc::mem_fun(*this, &PlugUIBase::focus_toggled));
@@ -565,9 +565,14 @@ PlugUIBase::preset_selected ()
        }
 }
 
+#ifdef NO_PLUGIN_STATE
+static bool seen_saving_message = false;
+#endif
+
 void
 PlugUIBase::add_plugin_setting ()
 {
+#ifndef NO_PLUGIN_STATE
        NewPluginPresetDialog d (plugin);
 
        switch (d.run ()) {
@@ -586,23 +591,49 @@ PlugUIBase::add_plugin_setting ()
                }
                break;
        }
+#else 
+       if (!seen_saving_message) {
+               info << string_compose (_("Plugin presets are not supported in this build of %1. Consider paying for a full version"),
+                                       PROGRAM_NAME)
+                    << endmsg;
+               seen_saving_message = true;
+       }
+#endif
 }
 
 void
 PlugUIBase::save_plugin_setting ()
 {
+#ifndef NO_PLUGIN_STATE
        string const name = _preset_combo.get_active_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) {
+               info << string_compose (_("Plugin presets are not supported in this build of %1. Consider paying for a newer version"),
+                                       PROGRAM_NAME)
+                    << endmsg;
+               seen_saving_message = true;
+       }
+#endif
 }
 
 void
 PlugUIBase::delete_plugin_setting ()
 {
+#ifndef NO_PLUGIN_STATE
        plugin->remove_preset (_preset_combo.get_active_text ());
+#else
+       if (!seen_saving_message) {
+               info << string_compose (_("Plugin presets are not supported in this build of %1. Consider paying for a newer version"),
+                                       PROGRAM_NAME)
+                    << endmsg;
+               seen_saving_message = true;
+       }
+#endif
 }
 
 bool