* fixed jitter problems for midi clock and removed superfluous UI elements
[ardour.git] / gtk2_ardour / plugin_ui.cc
index 7f2955dfda62434035c4124021aad36287c6efb7..06d2a04125f1794be2eb783df4e789a5575818f0 100644 (file)
@@ -27,6 +27,7 @@
 #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>
 #ifdef VST_SUPPORT
 #include <ardour/vst_plugin.h>
 #endif
+#ifdef HAVE_LV2
+#include <ardour/lv2_plugin.h>
+#include "lv2_plugin_ui.h"
+#endif
 
 #include <lrdf.h>
 
@@ -51,6 +56,7 @@
 #include "utils.h"
 #include "gui_thread.h"
 #include "public_editor.h"
+#include "keyboard.h"
 
 #include "i18n.h"
 
@@ -61,10 +67,12 @@ using namespace Gtkmm2ext;
 using namespace Gtk;
 using namespace sigc;
 
-PluginUIWindow::PluginUIWindow (boost::shared_ptr<PluginInsert> insert, nframes64_t sr, nframes64_t period, bool scrollable)
+PluginUIWindow::PluginUIWindow (Gtk::Window* win, boost::shared_ptr<PluginInsert> insert, bool scrollable)
+       : parent (win)
 {
        bool have_gui = false;
        non_gtk_gui = false;
+       was_visible = false;
 
        Label* label = manage (new Label());
        label->set_markup ("<b>THIS IS THE PLUGIN UI</b>");
@@ -83,6 +91,10 @@ PluginUIWindow::PluginUIWindow (boost::shared_ptr<PluginInsert> insert, nframes6
                        error << _("Eh? LADSPA plugins don't have editors!") << endmsg;
                        break;
 
+               case ARDOUR::LV2:
+                       have_gui = create_lv2_editor (insert);
+                       break;
+
                default:
 #ifndef VST_SUPPORT
                        error << _("unknown type of editor-supplying plugin (note: no VST support in this version of ardour)")
@@ -101,8 +113,17 @@ PluginUIWindow::PluginUIWindow (boost::shared_ptr<PluginInsert> insert, nframes6
                GenericPluginUI*  pu  = new GenericPluginUI (insert, scrollable);
                
                _pluginui = pu;
-               add (*pu);
+               add( *pu );
+
+               /*
+               Gtk::HBox *hbox = new Gtk::HBox();
+               hbox->pack_start( *pu);
+               // TODO: this should be nicer
+               hbox->pack_start( eqgui_bin );
                
+               add (*manage(hbox));
+               */
+
                set_wmclass (X_("ardour_plugin_editor"), "Ardour");
 
                signal_map_event().connect (mem_fun (*pu, &GenericPluginUI::start_updating));
@@ -135,18 +156,50 @@ PluginUIWindow::~PluginUIWindow ()
 {
 }
 
+void
+PluginUIWindow::set_parent (Gtk::Window* win)
+{
+       parent = win;
+}
+
+void
+PluginUIWindow::on_map ()
+{
+       Window::on_map ();
+       set_keep_above (true);
+}
+
+bool
+PluginUIWindow::on_enter_notify_event (GdkEventCrossing *ev)
+{
+       Keyboard::the_keyboard().enter_window (ev, this);
+       return false;
+}
+
+bool
+PluginUIWindow::on_leave_notify_event (GdkEventCrossing *ev)
+{
+       Keyboard::the_keyboard().leave_window (ev, this);
+       return false;
+}
+
 void
 PluginUIWindow::on_show ()
 {
-       cerr << "PluginWindow shown\n";
-               
+       if (_pluginui) {
+               _pluginui->update_presets ();
+       }
+
        Window::on_show ();
+
+       if (parent) {
+               // set_transient_for (*parent);
+       }
 }
 
 void
 PluginUIWindow::on_hide ()
 {
-       cerr << "PluginWindow hidden\n";
        Window::on_hide ();
 }
 
@@ -201,9 +254,13 @@ PluginUIWindow::app_activated (bool yn)
        cerr << "APP activated ? " << yn << endl;
        if (_pluginui) {
                if (yn) {
-                       _pluginui->activate ();
-                       present ();
+                       if (was_visible) {
+                               _pluginui->activate ();
+                               present ();
+                               was_visible = true;
+                       }
                } else {
+                       was_visible = is_visible();
                        hide ();
                        _pluginui->deactivate ();
                }
@@ -211,6 +268,30 @@ PluginUIWindow::app_activated (bool yn)
 #endif
 }
 
+bool
+PluginUIWindow::create_lv2_editor(boost::shared_ptr<PluginInsert> insert)
+{
+#ifndef HAVE_LV2
+       return false;
+#else
+
+       boost::shared_ptr<LV2Plugin> vp;
+       
+       if ((vp = boost::dynamic_pointer_cast<LV2Plugin> (insert->plugin())) == 0) {
+               error << _("create_lv2_editor called on non-LV2 plugin") << endmsg;
+               throw failed_constructor ();
+       } else {
+               LV2PluginUI* lpu = new LV2PluginUI (insert, vp);
+               _pluginui = lpu;
+               add (*lpu);
+               lpu->package (*this);
+       }
+
+       non_gtk_gui = false;
+       return true;
+#endif
+}
+
 bool
 PluginUIWindow::on_key_press_event (GdkEventKey* event)
 {
@@ -329,3 +410,9 @@ PlugUIBase::bypass_toggled ()
                }
        }
 }
+
+void
+PlugUIBase::update_presets ()
+{
+       set_popdown_strings (preset_combo, plugin->get_presets());
+}