summaryrefslogtreecommitdiffstats
path: root/src/libs/gui
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-12-21 03:32:55 +0000
committerDavid Robillard <d@drobilla.net>2007-12-21 03:32:55 +0000
commit39dbfbaf661bfec067d02b26bbc04608d74413c6 (patch)
tree11b3d8948b881f3272b944a483466dd1b57fdbf9 /src/libs/gui
parent3efacf8a4ac1b0c90b544f41881596ff91f37efa (diff)
downloadingen-39dbfbaf661bfec067d02b26bbc04608d74413c6.tar.gz
ingen-39dbfbaf661bfec067d02b26bbc04608d74413c6.tar.bz2
ingen-39dbfbaf661bfec067d02b26bbc04608d74413c6.zip
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
Diffstat (limited to 'src/libs/gui')
-rw-r--r--src/libs/gui/NodeModule.cpp119
-rw-r--r--src/libs/gui/NodeModule.hpp8
2 files changed, 65 insertions, 62 deletions
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 <cassert>
#include <raul/Atom.hpp>
#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<PatchCanvas> canvas, SharedPtr<NodeModel> 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<PatchCanvas> canvas, SharedPtr<NodeModel> 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<const PluginModel*>(_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<const PluginModel*>(_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;
@@ -314,6 +305,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()
{
uint32_t index=0;
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<NodeModel> _node;
NodeMenu* _menu;
- SLV2UIInstance _slv2_ui;
- Gtk::Widget* _gui;
- Gnome::Canvas::Widget* _gui_item;
+ SharedPtr<PluginUI> _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;
};