summaryrefslogtreecommitdiffstats
path: root/src/libs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/client/Makefile.am2
-rw-r--r--src/libs/client/PluginModel.cpp65
-rw-r--r--src/libs/client/PluginModel.hpp4
-rw-r--r--src/libs/client/PluginUI.cpp115
-rw-r--r--src/libs/client/PluginUI.hpp65
-rw-r--r--src/libs/gui/NodeModule.cpp119
-rw-r--r--src/libs/gui/NodeModule.hpp8
7 files changed, 255 insertions, 123 deletions
diff --git a/src/libs/client/Makefile.am b/src/libs/client/Makefile.am
index e9314c55..60f5c509 100644
--- a/src/libs/client/Makefile.am
+++ b/src/libs/client/Makefile.am
@@ -50,6 +50,8 @@ libingen_client_la_SOURCES = \
PatchModel.hpp \
PluginModel.cpp \
PluginModel.hpp \
+ PluginUI.hpp \
+ PluginUI.cpp \
PortModel.cpp \
PortModel.hpp \
PresetModel.hpp \
diff --git a/src/libs/client/PluginModel.cpp b/src/libs/client/PluginModel.cpp
index 8c2ad71c..83762566 100644
--- a/src/libs/client/PluginModel.cpp
+++ b/src/libs/client/PluginModel.cpp
@@ -20,6 +20,7 @@
//#include "lv2_osc_print.h"
#include "PluginModel.hpp"
#include "PatchModel.hpp"
+#include "PluginUI.hpp"
using namespace std;
using Ingen::Shared::EngineInterface;
@@ -91,73 +92,17 @@ lv2_ui_write(LV2UI_Controller controller,
port->type().uri(), buffer_size, buffer);
}
-
-void
-lv2_ui_command(LV2UI_Controller controller,
- uint32_t argc,
- const char* const* argv)
-{
- cerr << "********* LV2 UI COMMAND" << endl;
-}
-
-
-void
-lv2_ui_program_change(LV2UI_Controller controller,
- unsigned char program)
-{
- cerr << "********* LV2 UI PROGRAM CHANGE" << endl;
-}
-
-
-void
-lv2_ui_program_save(LV2UI_Controller controller,
- unsigned char program,
- const char* name)
-{
- cerr << "********* LV2 UI PROGRAM SAVE" << endl;
-}
-
#ifdef HAVE_SLV2
-SLV2UIInstance
-PluginModel::ui(EngineInterface* engine, NodeModel* node) const
+SharedPtr<PluginUI>
+PluginModel::ui(SharedPtr<EngineInterface> engine, SharedPtr<NodeModel> node) const
{
if (_type != LV2)
- return NULL;
+ return SharedPtr<PluginUI>();
Glib::Mutex::Lock(_rdf_world->mutex());
- // FIXME: leak
- NodeController* controller = new NodeController();
- controller->engine = engine;
- controller->node = node;
-
- SLV2UIInstance ret = NULL;
-
- const char* gtk_gui_uri = "http://ll-plugins.nongnu.org/lv2/ext/gui#GtkGUI";
-
- SLV2UIs uis = slv2_plugin_get_uis(_slv2_plugin);
- SLV2UI ui = NULL;
-
- if (slv2_values_size(uis) > 0) {
- for (unsigned i=0; i < slv2_uis_size(uis); ++i) {
- ui = slv2_uis_get_at(uis, i);
-
- if (slv2_ui_is_type(ui, gtk_gui_uri)) {
- break;
- } else {
- ui = NULL;
- }
- }
- }
-
- if (ui) {
- cout << "Found GTK Plugin UI " << slv2_ui_get_uri(ui) << endl;
- ret = slv2_ui_instantiate(_slv2_plugin, ui, lv2_ui_write, controller, NULL);
- //slv2_ui_free(ui);
- }
-
- return ret;
+ return PluginUI::create(engine, node, _slv2_plugin);
}
diff --git a/src/libs/client/PluginModel.hpp b/src/libs/client/PluginModel.hpp
index 25dd2d9c..de90bba2 100644
--- a/src/libs/client/PluginModel.hpp
+++ b/src/libs/client/PluginModel.hpp
@@ -37,6 +37,7 @@ namespace Client {
class PatchModel;
class NodeModel;
+class PluginUI;
/** Model for a plugin available for loading.
@@ -89,7 +90,8 @@ public:
_slv2_plugins = slv2_world_get_all_plugins(_slv2_world);
}
- SLV2UIInstance ui(Ingen::Shared::EngineInterface* engine, NodeModel* node) const;
+ SharedPtr<PluginUI> ui(SharedPtr<Shared::EngineInterface> engine,
+ SharedPtr<NodeModel> node) const;
const string& icon_path() const;
static string get_lv2_icon_path(SLV2Plugin plugin);
diff --git a/src/libs/client/PluginUI.cpp b/src/libs/client/PluginUI.cpp
new file mode 100644
index 00000000..3c15b15e
--- /dev/null
+++ b/src/libs/client/PluginUI.cpp
@@ -0,0 +1,115 @@
+/* This file is part of Ingen.
+ * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
+ *
+ * Ingen is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <iostream>
+#include "PluginUI.hpp"
+#include "NodeModel.hpp"
+#include "PortModel.hpp"
+
+using namespace std;
+using Ingen::Shared::EngineInterface;
+
+namespace Ingen {
+namespace Client {
+
+static void
+lv2_ui_write(LV2UI_Controller controller,
+ uint32_t port_index,
+ uint32_t buffer_size,
+ const void* buffer)
+{
+ /*cerr << "********* LV2 UI WRITE:" << endl;
+ lv2_osc_message_print((const LV2Message*)buffer);
+
+ fprintf(stderr, "RAW:\n");
+ for (uint32_t i=0; i < buffer_size; ++i) {
+ unsigned char byte = ((unsigned char*)buffer)[i];
+ if (byte >= 32 && byte <= 126)
+ fprintf(stderr, "%c ", ((unsigned char*)buffer)[i]);
+ else
+ fprintf(stderr, "%2X ", ((unsigned char*)buffer)[i]);
+ }
+
+ fprintf(stderr, "\n");
+ */
+
+ PluginUI* ui = (PluginUI*)controller;
+
+ SharedPtr<PortModel> port = ui->node()->ports()[port_index];
+
+ ui->engine()->set_port_value_immediate(port->path(),
+ port->type().uri(), buffer_size, buffer);
+}
+
+
+PluginUI::PluginUI(SharedPtr<EngineInterface> engine,
+ SharedPtr<NodeModel> node)
+ : _engine(engine)
+ , _node(node)
+ , _instance(NULL)
+{
+}
+
+
+PluginUI::~PluginUI()
+{
+ slv2_ui_instance_free(_instance);
+}
+
+
+SharedPtr<PluginUI>
+PluginUI::create(SharedPtr<EngineInterface> engine,
+ SharedPtr<NodeModel> node,
+ SLV2Plugin plugin)
+{
+ SharedPtr<PluginUI> ret;
+
+ static const char* gtk_gui_uri = "http://ll-plugins.nongnu.org/lv2/ext/gui#GtkGUI";
+
+ SLV2UIs uis = slv2_plugin_get_uis(plugin);
+ SLV2UI ui = NULL;
+
+ if (slv2_values_size(uis) > 0) {
+ for (unsigned i=0; i < slv2_uis_size(uis); ++i) {
+ SLV2UI this_ui = slv2_uis_get_at(uis, i);
+ if (slv2_ui_is_type(this_ui, gtk_gui_uri)) {
+ ui = this_ui;
+ break;
+ }
+ }
+ }
+
+ if (ui) {
+ cout << "Found GTK Plugin UI: " << slv2_ui_get_uri(ui) << endl;
+ ret = SharedPtr<PluginUI>(new PluginUI(engine, node));
+ SLV2UIInstance inst = slv2_ui_instantiate(
+ plugin, ui, lv2_ui_write, ret.get(), NULL);
+
+ if (inst) {
+ ret->set_instance(inst);
+ } else {
+ cerr << "ERROR: Failed to instantiate Plugin UI" << endl;
+ ret = SharedPtr<PluginUI>();
+ }
+ }
+
+ return ret;
+}
+
+
+} // namespace Client
+} // namespace Ingen
diff --git a/src/libs/client/PluginUI.hpp b/src/libs/client/PluginUI.hpp
new file mode 100644
index 00000000..62bbf9af
--- /dev/null
+++ b/src/libs/client/PluginUI.hpp
@@ -0,0 +1,65 @@
+/* This file is part of Ingen.
+ * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
+ *
+ * Ingen is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * Ingen is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef PLUGINUI_H
+#define PLUGINUI_H
+
+#include <slv2/slv2.h>
+#include <raul/SharedPtr.hpp>
+
+namespace Ingen {
+namespace Shared { class EngineInterface; }
+namespace Client {
+
+class NodeModel;
+
+
+/** Model for a plugin available for loading.
+ *
+ * \ingroup IngenClient
+ */
+class PluginUI {
+public:
+ ~PluginUI();
+
+ static SharedPtr<PluginUI>
+ create(SharedPtr<Shared::EngineInterface> engine,
+ SharedPtr<NodeModel> node,
+ SLV2Plugin plugin);
+
+ SharedPtr<Shared::EngineInterface> engine() { return _engine; }
+ SharedPtr<NodeModel> node() { return _node; }
+ SLV2UIInstance instance() { return _instance; }
+
+private:
+ PluginUI(SharedPtr<Ingen::Shared::EngineInterface> engine,
+ SharedPtr<NodeModel> node);
+
+ void set_instance(SLV2UIInstance instance) { _instance = instance; }
+
+ SharedPtr<Shared::EngineInterface> _engine;
+ SharedPtr<NodeModel> _node;
+ SLV2UIInstance _instance;
+};
+
+
+} // namespace Client
+} // namespace Ingen
+
+#endif // PLUGINUI_H
+
+
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;
};