From 47372f00cc6fe39f65594aa6edf6544157e94ce7 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 12 Mar 2007 18:13:03 +0000 Subject: Removed name-based interface for FlowCanvas (using the view as a model = evil), related performance improvements (especially for Machina). Updates for FlowCanvas API changes. Machina SMF import performance improvements (temporarily disabled node labels). git-svn-id: http://svn.drobilla.net/lad/patchage@356 a436a847-0d15-0410-975c-d299462d15a1 --- src/AlsaDriver.cpp | 4 ++-- src/JackDriver.cpp | 8 ++++---- src/Patchage.cpp | 6 +++--- src/PatchageEvent.cpp | 2 +- src/PatchageFlowCanvas.cpp | 39 +++++++++++++++++++++++++++++++++++---- src/PatchageFlowCanvas.h | 4 ++++ 6 files changed, 49 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp index b9d6a48..5a11b67 100644 --- a/src/AlsaDriver.cpp +++ b/src/AlsaDriver.cpp @@ -274,9 +274,9 @@ AlsaDriver::refresh_connections() boost::shared_ptr m; boost::shared_ptr p; - for (ItemMap::iterator i = _app->canvas()->items().begin(); + for (ItemList::iterator i = _app->canvas()->items().begin(); i != _app->canvas()->items().end(); ++i) { - m = boost::dynamic_pointer_cast((*i).second); + m = boost::dynamic_pointer_cast(*i); if (m) { for (PortVector::const_iterator j = m->ports().begin(); j != m->ports().end(); ++j) { p = boost::dynamic_pointer_cast(*j); diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp index 3f2920c..02bd105 100644 --- a/src/JackDriver.cpp +++ b/src/JackDriver.cpp @@ -114,9 +114,9 @@ JackDriver::detach() void JackDriver::destroy_all_ports() { - ItemMap modules = _app->canvas()->items(); // copy - for (ItemMap::iterator m = modules.begin(); m != modules.end(); ++m) { - SharedPtr module = PtrCast(m->second); + ItemList modules = _app->canvas()->items(); // copy + for (ItemList::iterator m = modules.begin(); m != modules.end(); ++m) { + SharedPtr module = PtrCast(*m); if (!module) continue; PortVector ports = module->ports(); // copy @@ -128,7 +128,7 @@ JackDriver::destroy_all_ports() } if (module->ports().empty()) - _app->canvas()->remove_item(module->name()); + _app->canvas()->remove_item(module); } } diff --git a/src/Patchage.cpp b/src/Patchage.cpp index ce41c47..0e73a37 100644 --- a/src/Patchage.cpp +++ b/src/Patchage.cpp @@ -437,10 +437,10 @@ Patchage::zoom_changed() void Patchage::update_state() { - for (ItemMap::iterator i = _canvas->items().begin(); i != _canvas->items().end(); ++i) { - SharedPtr module = PtrCast((*i).second); + for (ItemList::iterator i = _canvas->items().begin(); i != _canvas->items().end(); ++i) { + SharedPtr module = PtrCast(*i); if (module) - module->load_location(); + module->load_location(); } //cerr << "[Patchage] Resizing window: (" << _state_manager->get_window_size().x diff --git a/src/PatchageEvent.cpp b/src/PatchageEvent.cpp index 09b28a1..0eed12e 100644 --- a/src/PatchageEvent.cpp +++ b/src/PatchageEvent.cpp @@ -75,7 +75,7 @@ PatchageEvent::execute() } if (module->num_ports() == 0) { - _patchage->canvas()->remove_item(module->name()); // FIXME: slow + _patchage->canvas()->remove_item(module); module->hide(); module.reset(); } diff --git a/src/PatchageFlowCanvas.cpp b/src/PatchageFlowCanvas.cpp index bdb5c0a..042d259 100644 --- a/src/PatchageFlowCanvas.cpp +++ b/src/PatchageFlowCanvas.cpp @@ -33,11 +33,24 @@ PatchageFlowCanvas::PatchageFlowCanvas(Patchage* app, int width, int height) } +boost::shared_ptr +PatchageFlowCanvas::get_item(const string& name) +{ + ItemList::iterator m = _items.begin(); + + for ( ; m != _items.end(); ++m) + if ((*m)->name() == name) + break; + + return (m == _items.end()) ? boost::shared_ptr() : *m; +} + + boost::shared_ptr PatchageFlowCanvas::find_module(const string& name, ModuleType type) { - for (ItemMap::iterator m = _items.begin(); m != _items.end(); ++m) { - boost::shared_ptr pm = boost::dynamic_pointer_cast((*m).second); + for (ItemList::iterator m = _items.begin(); m != _items.end(); ++m) { + boost::shared_ptr pm = boost::dynamic_pointer_cast(*m); if (pm && pm->name() == name && pm->type() == type) { return pm; } @@ -52,8 +65,8 @@ boost::shared_ptr PatchageFlowCanvas::find_port(const snd_seq_addr_t* alsa_addr) { boost::shared_ptr pp; - for (ItemMap::iterator m = _items.begin(); m != _items.end(); ++m) { - SharedPtr module = PtrCast(m->second); + for (ItemList::iterator m = _items.begin(); m != _items.end(); ++m) { + SharedPtr module = PtrCast(*m); if (!module) continue; for (PortVector::const_iterator p = module->ports().begin(); p != module->ports().end(); ++p) { @@ -130,3 +143,21 @@ PatchageFlowCanvas::status_message(const string& msg) _app->status_message(string("[Canvas] ").append(msg)); } + +boost::shared_ptr +PatchageFlowCanvas::get_port(const string& node_name, const string& port_name) +{ + for (ItemList::iterator i = _items.begin(); i != _items.end(); ++i) { + const boost::shared_ptr item = *i; + const boost::shared_ptr module + = boost::dynamic_pointer_cast(item); + if (!module) + continue; + const boost::shared_ptr port = module->get_port(port_name); + if (module->name() == node_name && port) + return port; + } + + return boost::shared_ptr(); +} + diff --git a/src/PatchageFlowCanvas.h b/src/PatchageFlowCanvas.h index 05b7bef..899c503 100644 --- a/src/PatchageFlowCanvas.h +++ b/src/PatchageFlowCanvas.h @@ -45,6 +45,10 @@ public: void disconnect(boost::shared_ptr port1, boost::shared_ptr port2); void status_message(const string& msg); + + boost::shared_ptr get_item(const string& name); + boost::shared_ptr get_port(const string& module_name, + const string& port_name); private: Patchage* _app; -- cgit v1.2.1