From 39dbfbaf661bfec067d02b26bbc04608d74413c6 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 21 Dec 2007 03:32:55 +0000 Subject: Fix SLV2 GUI sketchiness, repeated embedding/unembedding/pop-up/window destroy, etc. Break out LV2 GUI stuff to a separate class, SharedPtr it up, spiffify, etc. git-svn-id: http://svn.drobilla.net/lad/ingen@993 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/gui/NodeModule.cpp | 119 ++++++++++++++++++++++---------------------- src/libs/gui/NodeModule.hpp | 8 +-- 2 files changed, 65 insertions(+), 62 deletions(-) (limited to 'src/libs/gui') diff --git a/src/libs/gui/NodeModule.cpp b/src/libs/gui/NodeModule.cpp index f15a6f77..856c4486 100644 --- a/src/libs/gui/NodeModule.cpp +++ b/src/libs/gui/NodeModule.cpp @@ -18,18 +18,19 @@ #include #include #include "interface/EngineInterface.hpp" -#include "client/PatchModel.hpp" #include "client/NodeModel.hpp" +#include "client/PatchModel.hpp" +#include "client/PluginUI.hpp" #include "App.hpp" +#include "GladeFactory.hpp" +#include "NodeControlWindow.hpp" #include "NodeModule.hpp" #include "PatchCanvas.hpp" +#include "PatchWindow.hpp" #include "Port.hpp" -#include "GladeFactory.hpp" #include "RenameWindow.hpp" -#include "PatchWindow.hpp" -#include "WindowFactory.hpp" #include "SubpatchModule.hpp" -#include "NodeControlWindow.hpp" +#include "WindowFactory.hpp" namespace Ingen { namespace GUI { @@ -38,10 +39,10 @@ namespace GUI { NodeModule::NodeModule(boost::shared_ptr canvas, SharedPtr node) : FlowCanvas::Module(canvas, node->path().name()) , _node(node) - , _slv2_ui(NULL) - , _gui(NULL) - , _gui_item(NULL) + , _gui_widget(NULL) , _gui_container(NULL) + , _gui_item(NULL) + , _gui_window(NULL) , _last_gui_request_width(0) , _last_gui_request_height(0) { @@ -108,9 +109,10 @@ NodeModule::create(boost::shared_ptr canvas, SharedPtr n void NodeModule::control_change(uint32_t index, float control) { - if (_slv2_ui) { - const LV2UI_Descriptor* const ui_descriptor = slv2_ui_instance_get_descriptor(_slv2_ui); - LV2UI_Handle ui_handle = slv2_ui_instance_get_handle(_slv2_ui); + if (_plugin_ui) { + SLV2UIInstance inst = _plugin_ui->instance(); + const LV2UI_Descriptor* ui_descriptor = slv2_ui_instance_get_descriptor(inst); + LV2UI_Handle ui_handle = slv2_ui_instance_get_handle(inst); if (ui_descriptor->port_event) ui_descriptor->port_event(ui_handle, index, 4, &control); } @@ -121,42 +123,34 @@ void NodeModule::embed_gui(bool embed) { if (embed) { - - // FIXME: leaks? - + + if (_gui_window) { + cerr << "LV2 GUI already popped up, cannot embed" << endl; + return; + } + GtkWidget* c_widget = NULL; if (!_gui_item) { - cerr << "Embedding LV2 GUI" << endl; - + const PluginModel* const plugin = dynamic_cast(_node->plugin()); assert(plugin); - _slv2_ui = plugin->ui(App::instance().engine().get(), _node.get()); + _plugin_ui = plugin->ui(App::instance().engine(), _node); - if (_slv2_ui) { - cerr << "Found UI" << endl; - c_widget = (GtkWidget*)slv2_ui_instance_get_widget(_slv2_ui); - _gui = Glib::wrap(c_widget); - assert(_gui); + if (_plugin_ui) { + c_widget = (GtkWidget*)slv2_ui_instance_get_widget(_plugin_ui->instance()); + _gui_widget = Glib::wrap(c_widget); + assert(_gui_widget); if (_gui_container) delete _gui_container; - //container = new Gtk::Alignment(); // transparent bg but uber slow - _gui_container = new Gtk::EventBox(); + _gui_container = manage(new Gtk::EventBox()); _gui_container->set_name("ingen_embedded_node_gui_container"); _gui_container->set_border_width(2); - _gui_container->add(*_gui); + _gui_container->add(*_gui_widget); _gui_container->show_all(); - /*Gdk::Color color; - color.set_red((_color & 0xFF000000) >> 24); - color.set_green((_color & 0x00FF0000) >> 16); - color.set_blue((_color & 0xFF000000) >> 8); - container->modify_bg(Gtk::STATE_NORMAL, color); - container->modify_bg(Gtk::STATE_ACTIVE, color); - container->modify_bg(Gtk::STATE_PRELIGHT, color); - container->modify_bg(Gtk::STATE_SELECTED, color);*/ const double y = 4 + _canvas_title.property_text_height(); _gui_item = new Gnome::Canvas::Widget(*this, 2.0, y, *_gui_container); @@ -164,9 +158,9 @@ NodeModule::embed_gui(bool embed) } if (_gui_item) { - assert(_gui); - cerr << "Created canvas item" << endl; - _gui->show_all(); + + assert(_gui_widget); + _gui_widget->show_all(); _gui_item->show(); Gtk::Requisition r = _gui_container->size_request(); @@ -182,19 +176,17 @@ NodeModule::embed_gui(bool embed) App::instance().engine()->enable_port_broadcasting((*p)->path()); } else { - cerr << "*** Failed to create canvas item" << endl; + cerr << "ERROR: Failed to create canvas item for LV2 UI" << endl; } - } else { + } else { // un-embed + if (_gui_item) { delete _gui_item; _gui_item = NULL; - } - - if (_slv2_ui) { - slv2_ui_instance_free(_slv2_ui); - _slv2_ui = NULL; - _gui = NULL; + _gui_container = NULL; // managed + _gui_widget = NULL; // managed + _plugin_ui.reset(); } _ports_y_offset = 0; @@ -214,7 +206,7 @@ NodeModule::embed_gui(bool embed) resize(); } - + void NodeModule::gui_size_request(Gtk::Requisition* r, bool force) @@ -279,30 +271,29 @@ NodeModule::popup_gui() { #ifdef HAVE_SLV2 if (_node->plugin()->type() == PluginModel::LV2) { - if (_slv2_ui) { - cerr << "LV2 GUI already embedded" << endl; + if (_plugin_ui) { + cerr << "LV2 GUI already embedded, cannot pop up" << endl; return false; } const PluginModel* const plugin = dynamic_cast(_node->plugin()); assert(plugin); - _slv2_ui = plugin->ui(App::instance().engine().get(), _node.get()); + _plugin_ui = plugin->ui(App::instance().engine(), _node); - if (_slv2_ui) { - cerr << "Popping up LV2 GUI" << endl; - - // FIXME: leaks - - GtkWidget* c_widget = (GtkWidget*)slv2_ui_instance_get_widget(_slv2_ui); - _gui = Glib::wrap(c_widget); + if (_plugin_ui) { + GtkWidget* c_widget = (GtkWidget*)slv2_ui_instance_get_widget(_plugin_ui->instance()); + _gui_widget = Glib::wrap(c_widget); - Gtk::Window* win = new Gtk::Window(); - win->add(*_gui); - _gui->show_all(); + _gui_window = new Gtk::Window(); + _gui_window->add(*_gui_widget); + _gui_widget->show_all(); initialise_gui_values(); - win->present(); + _gui_window->signal_unmap().connect( + sigc::mem_fun(this, &NodeModule::on_gui_window_close)); + _gui_window->present(); + return true; } else { cerr << "No LV2 GUI" << endl; @@ -313,6 +304,16 @@ NodeModule::popup_gui() } +void +NodeModule::on_gui_window_close() +{ + delete _gui_window; + _gui_window = NULL; + _plugin_ui.reset(); + _gui_widget = NULL; +} + + void NodeModule::initialise_gui_values() { diff --git a/src/libs/gui/NodeModule.hpp b/src/libs/gui/NodeModule.hpp index dcfd97dd..d73b4529 100644 --- a/src/libs/gui/NodeModule.hpp +++ b/src/libs/gui/NodeModule.hpp @@ -69,6 +69,7 @@ protected: void show_control_window(); bool popup_gui(); + void on_gui_window_close(); void rename(); void set_variable(const std::string& key, const Atom& value); @@ -86,10 +87,11 @@ protected: SharedPtr _node; NodeMenu* _menu; - SLV2UIInstance _slv2_ui; - Gtk::Widget* _gui; - Gnome::Canvas::Widget* _gui_item; + SharedPtr _plugin_ui; + Gtk::Widget* _gui_widget; Gtk::Container* _gui_container; + Gnome::Canvas::Widget* _gui_item; ///< iff embedded + Gtk::Window* _gui_window; ///< iff popped up int _last_gui_request_width; int _last_gui_request_height; }; -- cgit v1.2.1