summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/NodeModule.cpp27
-rw-r--r--src/gui/NodeModule.hpp10
-rw-r--r--src/gui/PatchCanvas.cpp12
-rw-r--r--src/gui/PatchPortModule.cpp22
-rw-r--r--src/gui/PatchPortModule.hpp3
-rw-r--r--src/gui/Port.cpp26
-rw-r--r--src/gui/Port.hpp7
7 files changed, 58 insertions, 49 deletions
diff --git a/src/gui/NodeModule.cpp b/src/gui/NodeModule.cpp
index 16e624e4..acb46834 100644
--- a/src/gui/NodeModule.cpp
+++ b/src/gui/NodeModule.cpp
@@ -49,7 +49,7 @@ NodeModule::NodeModule(boost::shared_ptr<PatchCanvas> canvas, SharedPtr<NodeMode
assert(_node);
node->signal_new_port.connect(sigc::bind(sigc::mem_fun(this, &NodeModule::add_port), true));
- node->signal_removed_port.connect(sigc::mem_fun(this, &NodeModule::remove_port));
+ node->signal_removed_port.connect(sigc::hide_return(sigc::mem_fun(this, &NodeModule::remove_port)));
node->signal_variable.connect(sigc::mem_fun(this, &NodeModule::set_variable));
node->signal_property.connect(sigc::mem_fun(this, &NodeModule::set_property));
node->signal_renamed.connect(sigc::mem_fun(this, &NodeModule::rename));
@@ -250,12 +250,31 @@ NodeModule::add_port(SharedPtr<PortModel> port, bool resize_to_fit)
resize();
}
+
+boost::shared_ptr<Port>
+NodeModule::port(boost::shared_ptr<PortModel> model)
+{
+ for (PortVector::const_iterator p = ports().begin(); p != ports().end(); ++p) {
+ SharedPtr<Port> port = PtrCast<Port>(*p);
+ if (port->model() == model) {
+ cout << "FOUND: " << model->path() << endl;
+ return port;
+ }
+ }
+ return boost::shared_ptr<Port>();
+}
+
void
-NodeModule::remove_port(SharedPtr<PortModel> port)
+NodeModule::remove_port(SharedPtr<PortModel> model)
{
- SharedPtr<FlowCanvas::Port> p = Module::remove_port(port->path().name());
- p.reset();
+ SharedPtr<Port> p = port(model);
+ if (p) {
+ Module::remove_port(p);
+ p.reset();
+ } else {
+ cerr << "WARNING: Failed to find port on module: " << model->path() << endl;
+ }
}
diff --git a/src/gui/NodeModule.hpp b/src/gui/NodeModule.hpp
index b9425a86..85ae8027 100644
--- a/src/gui/NodeModule.hpp
+++ b/src/gui/NodeModule.hpp
@@ -54,11 +54,10 @@ public:
bool human_names);
virtual ~NodeModule();
-
- boost::shared_ptr<Port> port(const std::string& port_name) {
- return boost::dynamic_pointer_cast<Ingen::GUI::Port>(
- Module::get_port(port_name));
- }
+
+ boost::shared_ptr<Port> port(boost::shared_ptr<PortModel> model);
+
+ void remove_port(SharedPtr<PortModel> port);
virtual void store_location();
void show_human_names(bool b);
@@ -81,7 +80,6 @@ protected:
void set_property(const std::string& predicate, const Raul::Atom& value);
void add_port(SharedPtr<PortModel> port, bool resize=true);
- void remove_port(SharedPtr<PortModel> port);
void value_changed(uint32_t index, const Atom& value);
void initialise_gui_values();
diff --git a/src/gui/PatchCanvas.cpp b/src/gui/PatchCanvas.cpp
index acbd8efe..0d444ad3 100644
--- a/src/gui/PatchCanvas.cpp
+++ b/src/gui/PatchCanvas.cpp
@@ -379,10 +379,20 @@ PatchCanvas::remove_port(SharedPtr<PortModel> pm)
{
Views::iterator i = _views.find(pm);
+ // Port on this patch
if (i != _views.end()) {
- remove_item(i->second);
_views.erase(i);
+ bool ret = remove_item(i->second);
+ if (!ret)
+ cerr << "WARNING: Failed to remove port item: " << pm->path() << endl;
+ i->second.reset();
+
+ } else {
+ SharedPtr<NodeModule> module = PtrCast<NodeModule>(_views[pm->parent()]);
+ module->remove_port(pm);
}
+
+ assert(_views.find(pm) == _views.end());
}
diff --git a/src/gui/PatchPortModule.cpp b/src/gui/PatchPortModule.cpp
index d8aaa91d..89e19fea 100644
--- a/src/gui/PatchPortModule.cpp
+++ b/src/gui/PatchPortModule.cpp
@@ -42,20 +42,6 @@ PatchPortModule::PatchPortModule(boost::shared_ptr<PatchCanvas> canvas, SharedPt
assert(PtrCast<PatchModel>(port->parent()));
- /*resize();
-
- const Atom& x_atom = port->get_variable("ingenuity:canvas-x");
- const Atom& y_atom = port->get_variable("ingenuity:canvas-y");
-
- if (x_atom && y_atom && x_atom.type() == Atom::FLOAT && y_atom.type() == Atom::FLOAT) {
- move_to(x_atom.get_float(), y_atom.get_float());
- } else {
- double default_x;
- double default_y;
- canvas->get_new_module_location(default_x, default_y);
- move_to(default_x, default_y);
- }*/
-
set_stacked_border(port->polyphonic());
port->signal_variable.connect(sigc::mem_fun(this, &PatchPortModule::set_variable));
@@ -70,11 +56,9 @@ PatchPortModule::create(boost::shared_ptr<PatchCanvas> canvas, SharedPtr<PortMod
new PatchPortModule(canvas, port));
assert(ret);
- ret->_patch_port = boost::shared_ptr<Port>(new Port(ret, port, port->symbol(), true));
-
- ret->add_port(ret->_patch_port);
-
- ret->set_menu(ret->_patch_port->menu());
+ boost::shared_ptr<Port> view(new Port(ret, port, port->symbol(), true));
+ ret->add_port(view);
+ ret->set_menu(view->menu());
for (GraphObject::Variables::const_iterator m = port->variables().begin(); m != port->variables().end(); ++m)
ret->set_variable(m->first, m->second);
diff --git a/src/gui/PatchPortModule.hpp b/src/gui/PatchPortModule.hpp
index eec1b2c4..5e655e3e 100644
--- a/src/gui/PatchPortModule.hpp
+++ b/src/gui/PatchPortModule.hpp
@@ -51,8 +51,6 @@ class PatchPortModule : public FlowCanvas::Module
public:
static boost::shared_ptr<PatchPortModule> create(boost::shared_ptr<PatchCanvas> canvas,
SharedPtr<PortModel> port);
-
- virtual ~PatchPortModule() {}
virtual void store_location();
@@ -69,7 +67,6 @@ protected:
SharedPtr<PortModel> _port;
PortMenu* _menu;
- SharedPtr<Port> _patch_port; ///< Port on this 'anonymous' module
};
diff --git a/src/gui/Port.cpp b/src/gui/Port.cpp
index efca1a54..c819a957 100644
--- a/src/gui/Port.cpp
+++ b/src/gui/Port.cpp
@@ -48,32 +48,32 @@ Port::Port(
, _flipped(flip)
{
assert(module);
- assert(_port_model);
+ assert(pm);
delete _menu;
_menu = NULL;
- _port_model->signal_renamed.connect(sigc::mem_fun(this, &Port::renamed));
+ pm->signal_renamed.connect(sigc::mem_fun(this, &Port::renamed));
if (pm->type().is_control()) {
set_toggled(pm->is_toggle());
show_control();
float min = 0.0f, max = 1.0f;
- boost::shared_ptr<NodeModel> parent = PtrCast<NodeModel>(_port_model->parent());
+ boost::shared_ptr<NodeModel> parent = PtrCast<NodeModel>(pm->parent());
if (parent)
- parent->port_value_range(_port_model, min, max);
+ parent->port_value_range(pm, min, max);
set_control_min(min);
set_control_max(max);
pm->signal_variable.connect(sigc::mem_fun(this, &Port::variable_changed));
- _port_model->signal_value_changed.connect(sigc::mem_fun(this, &Port::value_changed));
+ pm->signal_value_changed.connect(sigc::mem_fun(this, &Port::value_changed));
}
- _port_model->signal_activity.connect(sigc::mem_fun(this, &Port::activity));
+ pm->signal_activity.connect(sigc::mem_fun(this, &Port::activity));
- value_changed(_port_model->value());
+ value_changed(pm->value());
}
@@ -89,7 +89,7 @@ Port::create_menu()
PortMenu* menu = NULL;
Glib::RefPtr<Gnome::Glade::Xml> xml = GladeFactory::new_glade_reference();
xml->get_widget_derived("object_menu", menu);
- menu->init(_port_model, _flipped);
+ menu->init(model(), _flipped);
set_menu(menu);
}
@@ -97,7 +97,7 @@ Port::create_menu()
void
Port::renamed()
{
- set_name(_port_model->path().name());
+ set_name(model()->path().name());
module().lock()->resize();
}
@@ -123,10 +123,10 @@ void
Port::set_control(float value, bool signal)
{
if (signal) {
- if (_port_model->type() == DataType::CONTROL) {
- App::instance().engine()->set_port_value(_port_model->path(), Atom(value));
- } else if (_port_model->type() == DataType::EVENT) {
- App::instance().engine()->set_port_value(_port_model->path(),
+ if (model()->type() == DataType::CONTROL) {
+ App::instance().engine()->set_port_value(model()->path(), Atom(value));
+ } else if (model()->type() == DataType::EVENT) {
+ App::instance().engine()->set_port_value(model()->path(),
Atom("<http://example.org/ev#BangEvent>", 0, NULL));
}
}
diff --git a/src/gui/Port.hpp b/src/gui/Port.hpp
index ebf9a59e..e826c7dc 100644
--- a/src/gui/Port.hpp
+++ b/src/gui/Port.hpp
@@ -22,6 +22,7 @@
#include <string>
#include "flowcanvas/Port.hpp"
#include "raul/SharedPtr.hpp"
+#include "raul/WeakPtr.hpp"
#include "raul/Atom.hpp"
namespace Ingen { namespace Client { class PortModel; } }
@@ -45,7 +46,7 @@ public:
~Port();
- SharedPtr<PortModel> model() const { return _port_model; }
+ SharedPtr<PortModel> model() const { return _port_model.lock(); }
void create_menu();
@@ -59,8 +60,8 @@ private:
void renamed();
- SharedPtr<PortModel> _port_model;
- bool _flipped;
+ WeakPtr<PortModel> _port_model;
+ bool _flipped;
};