Add operator<< for bundles.
[ardour.git] / gtk2_ardour / lv2_plugin_ui.cc
index d736ba723d026e9f438f06ac747f53509d4578bc..f8924e5bec048c005863b8ec56722fa1217854ea 100644 (file)
@@ -29,22 +29,6 @@ using namespace Gtk;
 using namespace ARDOUR;
 using namespace PBD;
 
-std::vector<struct lv2_external_ui*> g_external_uis;
-
-void close_external_ui_windows()
-{
-       struct lv2_external_ui* external_ui_ptr;
-
-       //cout << "close_external_ui_windows" << endl;
-
-       while (!g_external_uis.empty()) {
-               //cout << "pop" << endl;
-               external_ui_ptr = g_external_uis.back();
-               LV2_EXTERNAL_UI_HIDE(external_ui_ptr);
-               g_external_uis.pop_back();
-       }
-}
-
 void
 LV2PluginUI::lv2_ui_write(
                LV2UI_Controller controller,
@@ -63,26 +47,16 @@ LV2PluginUI::lv2_ui_write(
 
 void LV2PluginUI::on_external_ui_closed(LV2UI_Controller controller)
 {
-       //cout << "on_external_ui_closed" << endl;
-
        LV2PluginUI* me = (LV2PluginUI*)controller;
        me->_screen_update_connection.disconnect();
-       //me->insert->set_gui(0);
-
-       for (std::vector<struct lv2_external_ui*>::iterator it = g_external_uis.begin() ; it < g_external_uis.end(); it++) {
-               if (*it == me->_external_ui_ptr) {
-                       g_external_uis.erase(it);
-               }
-       }
-
-       //slv2_ui_instance_get_descriptor(me->_inst)->cleanup(me->_inst);
        me->_external_ui_ptr = NULL;
 }
 
 void
 LV2PluginUI::parameter_changed (uint32_t port_index, float val)
 {
-       //cout << "parameter_changed" << endl;
+       PlugUIBase::parameter_changed (port_index, val);
+       
        if (val != _values[port_index]) {
                parameter_update(port_index, val);
        }
@@ -155,7 +129,7 @@ LV2PluginUI::LV2PluginUI (boost::shared_ptr<PluginInsert> pi, boost::shared_ptr<
 }
 
 void
-LV2PluginUI::lv2ui_instantiate(const Glib::ustring& title)
+LV2PluginUI::lv2ui_instantiate(const std::string& title)
 {
        LV2_Feature** features;
        LV2_Feature** features_src;
@@ -212,7 +186,6 @@ LV2PluginUI::lv2ui_instantiate(const Glib::ustring& title)
                        pack_start(*_gui_widget, true, true);
                } else {
                        _external_ui_ptr = (struct lv2_external_ui *)slv2_ui_instance_get_widget(_inst);
-                       g_external_uis.push_back(_external_ui_ptr);
                }
        }
 
@@ -227,8 +200,6 @@ LV2PluginUI::lv2ui_instantiate(const Glib::ustring& title)
                        }
                }
        }
-
-       _lv2->ParameterChanged.connect (parameter_connection, ui_bind (&LV2PluginUI::parameter_changed, this, _1, _2), gui_context());
 }
 
 LV2PluginUI::~LV2PluginUI ()
@@ -239,6 +210,23 @@ LV2PluginUI::~LV2PluginUI ()
                delete[] _values;
        }
        // plugin destructor destroys the GTK GUI
+       
+        
+        const LV2UI_Descriptor* ui_desc = slv2_ui_instance_get_descriptor(_inst);
+        LV2UI_Handle ui_handle = slv2_ui_instance_get_handle(_inst);
+               
+        /*Call cleanup to tell the plugin to close its GUI and delete it*/
+               
+        if (ui_desc) {
+                ui_desc->cleanup(ui_handle);
+        }
+               
+        _screen_update_connection.disconnect();                
+
+        if (_lv2->is_external_ui()) {
+               /*external UI is no longer valid - on_window_hide() will not try to use it if is NULL*/
+               _external_ui_ptr = NULL;
+       }
 }
 
 int
@@ -285,7 +273,7 @@ LV2PluginUI::is_update_wanted(uint32_t /*index*/)
 }
 
 bool
-LV2PluginUI::on_window_show(const Glib::ustring& title)
+LV2PluginUI::on_window_show(const std::string& title)
 {
        //cout << "on_window_show - " << title << endl; flush(cout);