summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/PatchageCanvas.cpp26
-rw-r--r--src/PatchageCanvas.hpp2
-rw-r--r--src/PatchageEvent.cpp18
3 files changed, 25 insertions, 21 deletions
diff --git a/src/PatchageCanvas.cpp b/src/PatchageCanvas.cpp
index 552f583..48ce657 100644
--- a/src/PatchageCanvas.cpp
+++ b/src/PatchageCanvas.cpp
@@ -67,11 +67,13 @@ PatchageCanvas::find_module(const string& name, ModuleType type)
boost::shared_ptr<PatchagePort>
PatchageCanvas::find_port(const PortID& id)
{
+ boost::shared_ptr<PatchagePort> pp;
+
PortIndex::iterator i = _port_index.find(id);
- if (i != _port_index.end())
+ if (i != _port_index.end()) {
+ assert(i->second->module().lock());
return i->second;
-
- boost::shared_ptr<PatchagePort> pp;
+ }
#ifdef USE_LIBJACK
// Alsa ports are always indexed (or don't exist at all)
@@ -98,6 +100,23 @@ PatchageCanvas::find_port(const PortID& id)
return pp;
}
+boost::shared_ptr<PatchagePort>
+PatchageCanvas::remove_port(const PortID& id)
+{
+ boost::shared_ptr<PatchagePort> port = find_port(id);
+ if (!port)
+ return port;
+
+ _port_index.erase(id);
+
+ SharedPtr<PatchageModule> module = PtrCast<PatchageModule>(port->module().lock());
+ if (!module)
+ return port;
+
+ module->remove_port(port);
+ _app->enqueue_resize(module);
+ return port;
+}
boost::shared_ptr<PatchagePort>
PatchageCanvas::find_port_by_name(const std::string& client_name,
@@ -218,7 +237,6 @@ PatchageCanvas::remove_item(boost::shared_ptr<Item> i)
return ret;
// Remove module from cache
- boost::shared_ptr<PatchageModule> io_module;
for (ModuleIndex::iterator i = _module_index.find(module->name());
i != _module_index.end() && i->first == module->name(); ++i) {
if (i->second == module) {
diff --git a/src/PatchageCanvas.hpp b/src/PatchageCanvas.hpp
index c75af02..128f318 100644
--- a/src/PatchageCanvas.hpp
+++ b/src/PatchageCanvas.hpp
@@ -62,6 +62,8 @@ public:
void add_module(const std::string& name, boost::shared_ptr<PatchageModule> module);
bool remove_item(boost::shared_ptr<Item> i);
+ boost::shared_ptr<PatchagePort> remove_port(const PortID& id);
+
void destroy();
private:
diff --git a/src/PatchageEvent.cpp b/src/PatchageEvent.cpp
index 5b27726..dffbff3 100644
--- a/src/PatchageEvent.cpp
+++ b/src/PatchageEvent.cpp
@@ -53,8 +53,6 @@ PatchageEvent::execute(Patchage* patchage)
if (module) {
patchage->canvas()->remove_item(module);
module.reset();
- } else {
- Raul::error << "Unable to find client `" << _str << "' to remove" << endl;
}
free(_str);
@@ -85,23 +83,9 @@ PatchageEvent::execute(Patchage* patchage)
} else if (_type == PORT_DESTRUCTION) {
- SharedPtr<PatchagePort> port = patchage->canvas()->find_port(_port_1);
-
+ SharedPtr<PatchagePort> port = patchage->canvas()->remove_port(_port_1);
if (port) {
- SharedPtr<PatchageModule> module = PtrCast<PatchageModule>(port->module().lock());
- assert(module);
-
- module->remove_port(port);
port.reset();
-
- // No empty modules (for now)
- if (module->num_ports() == 0) {
- patchage->canvas()->remove_item(module);
- module.reset();
- } else {
- patchage->enqueue_resize(module);
- }
-
} else {
Raul::error << "Unable to find port `" << _port_1 << "' to destroy" << endl;
}