From 00f2ad0069fe4e51e40e6a3b3d41f125b67f89cf Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 7 Jun 2011 02:44:16 +0000 Subject: Remove use of smart pointers in FlowCanvas entirely. Since FlowCanvas's containers own their children, there is no real benefit to using smart pointers for objects, though there is overhead. There are no longer any add or remove methods for containers, simply create (new) and destroy (delete) objects and things should work as expected. git-svn-id: http://svn.drobilla.net/lad/trunk/patchage@3366 a436a847-0d15-0410-975c-d299462d15a1 --- src/AlsaDriver.cpp | 80 +++++++++++++++++++++++++----------------- src/AlsaDriver.hpp | 35 ++++++++++--------- src/Driver.hpp | 10 +++--- src/JackDbusDriver.cpp | 13 ++++--- src/JackDbusDriver.hpp | 12 +++---- src/JackDriver.cpp | 79 ++++++++++++++++++----------------------- src/JackDriver.hpp | 18 +++++----- src/Patchage.cpp | 10 +++--- src/PatchageCanvas.cpp | 95 +++++++++++++++++++++++++++++++++++--------------- src/PatchageCanvas.hpp | 30 ++++++++-------- src/PatchageEvent.cpp | 17 +++++---- src/PatchageModule.cpp | 4 +-- src/PatchageModule.hpp | 4 +-- src/PatchagePort.hpp | 10 +++--- 14 files changed, 228 insertions(+), 189 deletions(-) (limited to 'src') diff --git a/src/AlsaDriver.cpp b/src/AlsaDriver.cpp index abd6b82..a22ecc8 100644 --- a/src/AlsaDriver.cpp +++ b/src/AlsaDriver.cpp @@ -82,6 +82,20 @@ AlsaDriver::detach() } } +static bool +is_alsa_port(const PatchagePort* port) +{ + return port->type() == ALSA_MIDI; +} + +/** Destroy all JACK (canvas) ports. + */ +void +AlsaDriver::destroy_all() +{ + _app->canvas()->remove_ports(is_alsa_port); +} + /** Refresh all Alsa Midi ports and connections. */ void @@ -96,38 +110,38 @@ AlsaDriver::refresh() refresh_connections(); } -boost::shared_ptr +PatchagePort* AlsaDriver::create_port_view(Patchage* patchage, const PortID& id) { - boost::shared_ptr parent; - boost::shared_ptr port; + PatchageModule* parent; + PatchagePort* port; create_port_view_internal(patchage, id.id.alsa_addr, parent, port); return port; } -boost::shared_ptr +PatchageModule* AlsaDriver::find_or_create_module( Patchage* patchage, const std::string& client_name, ModuleType type) { - boost::shared_ptr m = _app->canvas()->find_module(client_name, type); + PatchageModule* m = _app->canvas()->find_module(client_name, type); if (!m) { - m = boost::shared_ptr(new PatchageModule(patchage, client_name, type)); + m = new PatchageModule(patchage, client_name, type); m->load_location(); _app->canvas()->add_module(client_name, m); - _app->enqueue_resize(m.get()); + _app->enqueue_resize(m); } return m; } void AlsaDriver::create_port_view_internal( - Patchage* patchage, - snd_seq_addr_t addr, - boost::shared_ptr& m, - boost::shared_ptr& port) + Patchage* patchage, + snd_seq_addr_t addr, + PatchageModule*& m, + PatchagePort*& port) { if (ignore(addr)) return; @@ -184,7 +198,7 @@ AlsaDriver::create_port_view_internal( if (!split) { m = find_or_create_module(_app, client_name, InputOutput); if (!m->get_port(port_name)) { - port = create_port(m, port_name, is_input, addr); + port = create_port(*m, port_name, is_input, addr); port->show(); m->add_port(port); } @@ -193,7 +207,7 @@ AlsaDriver::create_port_view_internal( ModuleType type = ((is_input) ? Input : Output); m = find_or_create_module(_app, client_name, type); if (!m->get_port(port_name)) { - port = create_port(m, port_name, is_input, addr); + port = create_port(*m, port_name, is_input, addr); port->show(); m->add_port(port); } @@ -202,7 +216,7 @@ AlsaDriver::create_port_view_internal( type = ((!is_input) ? Input : Output); m = find_or_create_module(_app, client_name, type); if (!m->get_port(port_name)) { - port = create_port(m, port_name, !is_input, addr); + port = create_port(*m, port_name, !is_input, addr); port->show(); m->add_port(port); } @@ -210,15 +224,15 @@ AlsaDriver::create_port_view_internal( } } -boost::shared_ptr -AlsaDriver::create_port(boost::shared_ptr parent, +PatchagePort* +AlsaDriver::create_port(PatchageModule& parent, const string& name, bool is_input, snd_seq_addr_t addr) { - boost::shared_ptr ret( - new PatchagePort(parent, ALSA_MIDI, name, is_input, - _app->state_manager()->get_port_color(ALSA_MIDI))); + PatchagePort* ret = new PatchagePort( + parent, ALSA_MIDI, name, is_input, + _app->state_manager()->get_port_color(ALSA_MIDI)); - dynamic_cast(parent->canvas())->index_port( + dynamic_cast(parent.canvas())->index_port( PortID(addr, is_input), ret); ret->alsa_addr(addr); @@ -281,10 +295,10 @@ AlsaDriver::refresh_ports() snd_seq_port_info_t* pinfo; snd_seq_port_info_alloca(&pinfo); - boost::shared_ptr parent; - boost::shared_ptr port; + PatchageModule* parent; + PatchagePort* port; - std::set< boost::shared_ptr > to_resize; + std::set to_resize; while (snd_seq_query_next_client (_seq, cinfo) >= 0) { snd_seq_port_info_set_client(pinfo, snd_seq_client_info_get_client(cinfo)); @@ -294,7 +308,7 @@ AlsaDriver::refresh_ports() if (!ignore(addr)) { create_port_view_internal(_app, addr, parent, port); if (parent) - _app->enqueue_resize(parent.get()); + _app->enqueue_resize(parent); } } } @@ -308,15 +322,15 @@ AlsaDriver::refresh_connections() assert(is_attached()); assert(_seq); - boost::shared_ptr m; - boost::shared_ptr p; + PatchageModule* m = NULL; + PatchagePort* p = NULL; for (FlowCanvas::Canvas::Items::iterator i = _app->canvas()->items().begin(); i != _app->canvas()->items().end(); ++i) { - m = boost::dynamic_pointer_cast(*i); + m = dynamic_cast(*i); if (m) { for (FlowCanvas::Module::Ports::const_iterator j = m->ports().begin(); j != m->ports().end(); ++j) { - p = boost::dynamic_pointer_cast(*j); + p = dynamic_cast(*j); if (p->type() == ALSA_MIDI) add_connections(p); } @@ -327,13 +341,13 @@ AlsaDriver::refresh_connections() /** Add all connections for the given port. */ void -AlsaDriver::add_connections(boost::shared_ptr port) +AlsaDriver::add_connections(PatchagePort* port) { assert(is_attached()); assert(_seq); const snd_seq_addr_t* addr = port->alsa_addr(); - boost::shared_ptr connected_port; + PatchagePort* connected_port; // Fix a problem with duplex->duplex connections (would show up twice) // No sense doing them all twice anyway.. @@ -366,7 +380,8 @@ AlsaDriver::add_connections(boost::shared_ptr port) * \return Whether connection succeeded. */ bool -AlsaDriver::connect(boost::shared_ptr src_port, boost::shared_ptr dst_port) +AlsaDriver::connect(PatchagePort* src_port, + PatchagePort* dst_port) { const snd_seq_addr_t* src = src_port->alsa_addr(); const snd_seq_addr_t* dst = dst_port->alsa_addr(); @@ -410,7 +425,8 @@ AlsaDriver::connect(boost::shared_ptr src_port, boost::shared_ptr< * \return Whether disconnection succeeded. */ bool -AlsaDriver::disconnect(boost::shared_ptr src_port, boost::shared_ptr dst_port) +AlsaDriver::disconnect(PatchagePort* src_port, + PatchagePort* dst_port) { const snd_seq_addr_t* src = src_port->alsa_addr(); const snd_seq_addr_t* dst = dst_port->alsa_addr(); diff --git a/src/AlsaDriver.hpp b/src/AlsaDriver.hpp index ab849b9..54c35b1 100644 --- a/src/AlsaDriver.hpp +++ b/src/AlsaDriver.hpp @@ -44,16 +44,17 @@ public: bool is_attached() const { return (_seq != NULL); } void refresh(); + void destroy_all(); - boost::shared_ptr create_port_view( + PatchagePort* create_port_view( Patchage* patchage, const PortID& id); - bool connect(boost::shared_ptr src_port, - boost::shared_ptr dst_port); + bool connect(PatchagePort* src_port, + PatchagePort* dst_port); - bool disconnect(boost::shared_ptr src_port, - boost::shared_ptr dst_port); + bool disconnect(PatchagePort* src_port, + PatchagePort* dst_port); void print_addr(snd_seq_addr_t addr); @@ -63,13 +64,13 @@ private: void refresh_ports(); void refresh_connections(); - void add_connections(boost::shared_ptr port); + void add_connections(PatchagePort* port); bool create_refresh_port(); static void* refresh_main(void* me); void _refresh_main(); - boost::shared_ptr + PatchageModule* find_or_create_module( Patchage* patchage, const std::string& client_name, @@ -77,16 +78,16 @@ private: void create_port_view_internal( - Patchage* patchage, - snd_seq_addr_t addr, - boost::shared_ptr& parent, - boost::shared_ptr& port); - - boost::shared_ptr create_port( - boost::shared_ptr parent, - const std::string& name, - bool is_input, - snd_seq_addr_t addr); + Patchage* patchage, + snd_seq_addr_t addr, + PatchageModule*& parent, + PatchagePort*& port); + + PatchagePort* create_port( + PatchageModule& parent, + const std::string& name, + bool is_input, + snd_seq_addr_t addr); Patchage* _app; snd_seq_t* _seq; diff --git a/src/Driver.hpp b/src/Driver.hpp index feae11b..05b9e0b 100644 --- a/src/Driver.hpp +++ b/src/Driver.hpp @@ -42,15 +42,15 @@ public: virtual void refresh() = 0; virtual void destroy_all() {} - virtual boost::shared_ptr create_port_view( + virtual PatchagePort* create_port_view( Patchage* patchage, const PortID& id) = 0; - virtual bool connect(boost::shared_ptr src_port, - boost::shared_ptr dst_port) = 0; + virtual bool connect(PatchagePort* src_port, + PatchagePort* dst_port) = 0; - virtual bool disconnect(boost::shared_ptr src_port, - boost::shared_ptr dst_port) = 0; + virtual bool disconnect(PatchagePort* src_port, + PatchagePort* dst_port) = 0; sigc::signal signal_attached; sigc::signal signal_detached; diff --git a/src/JackDbusDriver.cpp b/src/JackDbusDriver.cpp index 51f71c6..7b43e58 100644 --- a/src/JackDbusDriver.cpp +++ b/src/JackDbusDriver.cpp @@ -97,8 +97,7 @@ JackDriver::destroy_all() for (FlowCanvas::Module::Ports::iterator p = ports.begin(); p != ports.end(); ++p) { SharedPtr port = boost::dynamic_pointer_cast(*p); if (port && (port->type() == JACK_AUDIO || port->type() == JACK_MIDI)) { - module->remove_port(port); - port->hide(); + _app->canvas()->remove_port(port->id()); } } @@ -845,8 +844,8 @@ JackDriver::refresh() bool JackDriver::connect( - SharedPtr src, - SharedPtr dst) + PatchagePort* src, + PatchagePort* dst) { const char* client1_name; const char* port1_name; @@ -874,8 +873,8 @@ JackDriver::connect( bool JackDriver::disconnect( - SharedPtr src, - SharedPtr dst) + PatchagePort* src, + PatchagePort* dst) { const char* client1_name; const char* port1_name; @@ -1070,7 +1069,7 @@ JackDriver::reset_max_dsp_load() _max_dsp_load = 0.0; } -SharedPtr +PatchagePort* JackDriver::create_port_view( Patchage* patchage, const PortID& id) diff --git a/src/JackDbusDriver.hpp b/src/JackDbusDriver.hpp index 9e790ee..ca4fb91 100644 --- a/src/JackDbusDriver.hpp +++ b/src/JackDbusDriver.hpp @@ -48,13 +48,13 @@ public: void destroy_all(); bool connect( - boost::shared_ptr src, - boost::shared_ptr dst); + PatchagePort* src, + PatchagePort* dst); bool disconnect( - boost::shared_ptr src, - boost::shared_ptr dst); - + PatchagePort* src, + PatchagePort* dst); + size_t get_xruns(); void reset_xruns(); @@ -67,7 +67,7 @@ public: void process_events(Patchage* app) {} - boost::shared_ptr create_port_view( + PatchagePort* create_port_view( Patchage* patchage, const PortID& ref); diff --git a/src/JackDriver.cpp b/src/JackDriver.cpp index 773fba9..1973303 100644 --- a/src/JackDriver.cpp +++ b/src/JackDriver.cpp @@ -109,33 +109,21 @@ JackDriver::detach() _app->status_msg("[JACK] Detached"); } +static bool +is_jack_port(const PatchagePort* port) +{ + return port->type() == JACK_AUDIO || port->type() == JACK_MIDI; +} + /** Destroy all JACK (canvas) ports. */ void JackDriver::destroy_all() { - FlowCanvas::Canvas::Items modules = _app->canvas()->items(); // copy - for (FlowCanvas::Canvas::Items::iterator m = modules.begin(); m != modules.end(); ++m) { - SharedPtr module = PtrCast(*m); - if (!module) - continue; - FlowCanvas::Module::Ports ports = module->ports(); // copy - for (FlowCanvas::Module::Ports::iterator p = ports.begin(); p != ports.end(); ++p) { - boost::shared_ptr port = boost::dynamic_pointer_cast(*p); - if ((port && port->type() == JACK_AUDIO) || (port->type() == JACK_MIDI)) { - module->remove_port(port); - port->hide(); - } - } - - if (module->ports().empty()) - _app->canvas()->remove_item(module); - else - _app->enqueue_resize(module.get()); - } + _app->canvas()->remove_ports(is_jack_port); } -boost::shared_ptr +PatchagePort* JackDriver::create_port_view(Patchage* patchage, const PortID& id) { @@ -145,7 +133,7 @@ JackDriver::create_port_view(Patchage* patchage, jack_port = jack_port_by_id(_client, id.id.jack_id); if (jack_port == NULL) - return boost::shared_ptr(); + return NULL; const int jack_flags = jack_port_flags(jack_port); @@ -162,38 +150,35 @@ JackDriver::create_port_view(Patchage* patchage, } } - boost::shared_ptr parent - = _app->canvas()->find_module(module_name, type); + PatchageModule* parent = _app->canvas()->find_module(module_name, type); bool resize = false; if (!parent) { - parent = boost::shared_ptr( - new PatchageModule(patchage, module_name, type)); + parent = new PatchageModule(patchage, module_name, type); parent->load_location(); patchage->canvas()->add_module(module_name, parent); parent->show(); resize = true; } - boost::shared_ptr port - = boost::dynamic_pointer_cast(parent->get_port(port_name)); + PatchagePort* port = dynamic_cast(parent->get_port(port_name)); if (!port) { - port = create_port(parent, jack_port, id); + port = create_port(*parent, jack_port, id); port->show(); parent->add_port(port); resize = true; } if (resize) - _app->enqueue_resize(parent.get()); + _app->enqueue_resize(parent); return port; } -boost::shared_ptr -JackDriver::create_port(boost::shared_ptr parent, jack_port_t* port, PortID id) +PatchagePort* +JackDriver::create_port(PatchageModule& parent, jack_port_t* port, PortID id) { assert(port); const char* const type_str = jack_port_type(port); @@ -205,16 +190,16 @@ JackDriver::create_port(boost::shared_ptr parent, jack_port_t* p port_type = JACK_MIDI; } else { Raul::warn << jack_port_name(port) << " has unknown type \'" << type_str << "\'" << endl; - return boost::shared_ptr(); + return NULL; } - boost::shared_ptr ret( + PatchagePort* ret( new PatchagePort(parent, port_type, jack_port_short_name(port), (jack_port_flags(port) & JackPortIsInput), _app->state_manager()->get_port_color(port_type))); if (id.type != PortID::NULL_PORT_ID) { - dynamic_cast(parent->canvas())->index_port(id, ret); + dynamic_cast(parent.canvas())->index_port(id, ret); } return ret; @@ -274,10 +259,10 @@ JackDriver::refresh() } } - boost::shared_ptr m = _app->canvas()->find_module(client1_name, type); + PatchageModule* m = _app->canvas()->find_module(client1_name, type); if (!m) { - m = boost::shared_ptr(new PatchageModule(_app, client1_name, type)); + m = new PatchageModule(_app, client1_name, type); m->load_location(); _app->canvas()->add_module(client1_name, m); } @@ -296,9 +281,9 @@ JackDriver::refresh() } if (!m->get_port(jack_port_short_name(port))) - m->add_port(create_port(m, port, PortID())); + m->add_port(create_port(*m, port, PortID())); - _app->enqueue_resize(m.get()); + _app->enqueue_resize(m); } // Add all connections @@ -314,7 +299,7 @@ JackDriver::refresh() const ModuleType port1_type = (jack_port_flags(port) & JackPortIsInput) ? Input : Output; - boost::shared_ptr client1_module + PatchageModule* client1_module = _app->canvas()->find_module(client1_name, port1_type); if (connected_ports) { @@ -327,17 +312,17 @@ JackDriver::refresh() const ModuleType port2_type = (port1_type == Input) ? Output : Input; - boost::shared_ptr client2_module + PatchageModule* client2_module = _app->canvas()->find_module(client2_name, port2_type); - boost::shared_ptr port1 = client1_module->get_port(port1_name); - boost::shared_ptr port2 = client2_module->get_port(port2_name); + FlowCanvas::Port* port1 = client1_module->get_port(port1_name); + FlowCanvas::Port* port2 = client2_module->get_port(port2_name); if (!port1 || !port2) continue; - boost::shared_ptr src; - boost::shared_ptr dst; + FlowCanvas::Port* src = NULL; + FlowCanvas::Port* dst = NULL; if (port1->is_output() && port2->is_input()) { src = port1; @@ -387,7 +372,8 @@ JackDriver::port_names(const PortID& id, * \return Whether connection succeeded. */ bool -JackDriver::connect(boost::shared_ptr src_port, boost::shared_ptr dst_port) +JackDriver::connect(PatchagePort* src_port, + PatchagePort* dst_port) { if (_client == NULL) return false; @@ -409,7 +395,8 @@ JackDriver::connect(boost::shared_ptr src_port, boost::shared_ptr< * \return Whether disconnection succeeded. */ bool -JackDriver::disconnect(boost::shared_ptr const src_port, boost::shared_ptr const dst_port) +JackDriver::disconnect(PatchagePort* const src_port, + PatchagePort* const dst_port) { if (_client == NULL) return false; diff --git a/src/JackDriver.hpp b/src/JackDriver.hpp index 311b72a..f503bf9 100644 --- a/src/JackDriver.hpp +++ b/src/JackDriver.hpp @@ -55,15 +55,15 @@ public: std::string& module_name, std::string& port_name); - boost::shared_ptr create_port_view( + PatchagePort* create_port_view( Patchage* patchage, const PortID& id); - bool connect(boost::shared_ptr src, - boost::shared_ptr dst); + bool connect(PatchagePort* src, + PatchagePort* dst); - bool disconnect(boost::shared_ptr src, - boost::shared_ptr dst); + bool disconnect(PatchagePort* src, + PatchagePort* dst); uint32_t get_xruns() { return _xruns; } void reset_xruns(); @@ -80,10 +80,10 @@ public: void process_events(Patchage* app); private: - boost::shared_ptr create_port( - boost::shared_ptr parent, - jack_port_t* port, - PortID id); + PatchagePort* create_port( + PatchageModule& parent, + jack_port_t* port, + PortID id); static void error_cb(const char* msg); diff --git a/src/Patchage.cpp b/src/Patchage.cpp index bfb067c..9dbc3c5 100644 --- a/src/Patchage.cpp +++ b/src/Patchage.cpp @@ -512,7 +512,7 @@ Patchage::update_state() { for (FlowCanvas::Canvas::Items::iterator i = _canvas->items().begin(); i != _canvas->items().end(); ++i) { - SharedPtr module = PtrCast(*i); + FlowCanvas::Module* module = dynamic_cast(*i); if (module) module->load_location(); } @@ -628,12 +628,10 @@ Patchage::save_session(bool close) script << "sleep 3" << endl; script << endl; - for (FlowCanvas::ConnectionList::const_iterator c = _canvas->connections().begin(); + for (FlowCanvas::Canvas::Connections::const_iterator c = _canvas->connections().begin(); c != _canvas->connections().end(); ++c) { - boost::shared_ptr src - = boost::dynamic_pointer_cast((*c)->source().lock()); - boost::shared_ptr dst - = boost::dynamic_pointer_cast((*c)->dest().lock()); + PatchagePort* src = dynamic_cast((*c)->source()); + PatchagePort* dst = dynamic_cast((*c)->dest()); if (!src || !dst || src->type() == ALSA_MIDI || dst->type() == ALSA_MIDI) { continue; diff --git a/src/PatchageCanvas.cpp b/src/PatchageCanvas.cpp index a26e75d..279a852 100644 --- a/src/PatchageCanvas.cpp +++ b/src/PatchageCanvas.cpp @@ -42,14 +42,14 @@ PatchageCanvas::PatchageCanvas(Patchage* app, int width, int height) { } -boost::shared_ptr +PatchageModule* PatchageCanvas::find_module(const string& name, ModuleType type) { const ModuleIndex::const_iterator i = _module_index.find(name); if (i == _module_index.end()) - return boost::shared_ptr(); + return NULL; - boost::shared_ptr io_module; + PatchageModule* io_module = NULL; for (ModuleIndex::const_iterator j = i; j != _module_index.end() && j->first == name; ++j) { if (j->second->type() == type) { return j->second; @@ -62,10 +62,10 @@ PatchageCanvas::find_module(const string& name, ModuleType type) return io_module; } -boost::shared_ptr +PatchagePort* PatchageCanvas::find_port(const PortID& id) { - boost::shared_ptr pp; + PatchagePort* pp = NULL; PortIndex::iterator i = _port_index.find(id); if (i != _port_index.end()) { @@ -78,17 +78,17 @@ PatchageCanvas::find_port(const PortID& id) if (id.type == PortID::JACK_ID) { jack_port_t* jack_port = jack_port_by_id(_app->jack_driver()->client(), id.id.jack_id); if (!jack_port) - return boost::shared_ptr(); + return NULL; string module_name; string port_name; _app->jack_driver()->port_names(id, module_name, port_name); - SharedPtr module = find_module( + PatchageModule* module = find_module( module_name, (jack_port_flags(jack_port) & JackPortIsInput) ? Input : Output); if (module) - pp = PtrCast(module->get_port(port_name)); + pp = dynamic_cast(module->get_port(port_name)); if (pp) index_port(id, pp); @@ -98,10 +98,10 @@ PatchageCanvas::find_port(const PortID& id) return pp; } -boost::shared_ptr +PatchagePort* PatchageCanvas::remove_port(const PortID& id) { - boost::shared_ptr port = find_port(id); + PatchagePort* const port = find_port(id); if (!port) return port; @@ -116,29 +116,67 @@ PatchageCanvas::remove_port(const PortID& id) return port; } -boost::shared_ptr +void +PatchageCanvas::remove_ports(bool (*pred)(const PatchagePort*)) +{ + std::set empty; + for (Items::iterator i = items().begin(); i != items().end(); ++i) { + PatchageModule* module = dynamic_cast(*i); + if (!module) + continue; + + FlowCanvas::Module::Ports ports = module->ports(); // copy + for (FlowCanvas::Module::Ports::iterator p = ports.begin(); + p != ports.end(); ++p) { + if (pred(dynamic_cast(*p))) { + delete *p; + } + } + + if (module->num_ports() == 0) { + empty.insert(module); + } + } + + for (PortIndex::iterator i = _port_index.begin(); + i != _port_index.end();) { + PortIndex::iterator next = i; + ++next; + if (pred(i->second)) { + _port_index.erase(i); + } + i = next; + } + + for (std::set::iterator i = empty.begin(); + i != empty.end(); ++i) { + delete *i; + } +} + +PatchagePort* PatchageCanvas::find_port_by_name(const std::string& client_name, const std::string& port_name) { const ModuleIndex::const_iterator i = _module_index.find(client_name); if (i == _module_index.end()) - return boost::shared_ptr(); + return NULL; for (ModuleIndex::const_iterator j = i; j != _module_index.end() && j->first == client_name; ++j) { - SharedPtr port = PtrCast(j->second->get_port(port_name)); + PatchagePort* port = dynamic_cast(j->second->get_port(port_name)); if (port) return port; } - return boost::shared_ptr(); + return NULL; } void -PatchageCanvas::connect(boost::shared_ptr port1, - boost::shared_ptr port2) +PatchageCanvas::connect(FlowCanvas::Connectable* port1, + FlowCanvas::Connectable* port2) { - boost::shared_ptr p1 = boost::dynamic_pointer_cast(port1); - boost::shared_ptr p2 = boost::dynamic_pointer_cast(port2); + PatchagePort* p1 = dynamic_cast(port1); + PatchagePort* p2 = dynamic_cast(port2); if (!p1 || !p2) return; @@ -157,18 +195,17 @@ PatchageCanvas::connect(boost::shared_ptr port1, } void -PatchageCanvas::disconnect(boost::shared_ptr port1, - boost::shared_ptr port2) +PatchageCanvas::disconnect(FlowCanvas::Connectable* port1, + FlowCanvas::Connectable* port2) { - boost::shared_ptr input = boost::dynamic_pointer_cast(port1); - boost::shared_ptr output = boost::dynamic_pointer_cast(port2); - + PatchagePort* input = dynamic_cast(port1); + PatchagePort* output = dynamic_cast(port2); if (!input || !output) return; if (input->is_output() && output->is_input()) { // Damn, guessed wrong - boost::shared_ptr swap = input; + PatchagePort* swap = input; input = output; output = swap; } @@ -199,13 +236,13 @@ PatchageCanvas::status_message(const string& msg) } void -PatchageCanvas::add_module(const std::string& name, boost::shared_ptr module) +PatchageCanvas::add_module(const std::string& name, PatchageModule* module) { _module_index.insert(std::make_pair(name, module)); // Join partners, if applicable - boost::shared_ptr in_module; - boost::shared_ptr out_module; + PatchageModule* in_module = NULL; + PatchageModule* out_module = NULL; if (module->type() == Input) { in_module = module; out_module = find_module(name, Output); @@ -220,14 +257,14 @@ PatchageCanvas::add_module(const std::string& name, boost::shared_ptr i) +PatchageCanvas::remove_item(FlowCanvas::Item* i) { // Remove item from canvas const bool ret = FlowCanvas::Canvas::remove_item(i); if (!ret) return ret; - SharedPtr module = PtrCast(i); + PatchageModule* const module = dynamic_cast(i); if (!module) return ret; diff --git a/src/PatchageCanvas.hpp b/src/PatchageCanvas.hpp index b7ec3b2..e7e8214 100644 --- a/src/PatchageCanvas.hpp +++ b/src/PatchageCanvas.hpp @@ -42,38 +42,40 @@ class PatchageCanvas : public FlowCanvas::Canvas { public: PatchageCanvas(Patchage* _app, int width, int height); - boost::shared_ptr find_module(const std::string& name, ModuleType type); - boost::shared_ptr find_port(const PortID& id); + PatchageModule* find_module(const std::string& name, ModuleType type); + PatchagePort* find_port(const PortID& id); - boost::shared_ptr find_port_by_name(const std::string& client_name, - const std::string& port_name); + PatchagePort* find_port_by_name(const std::string& client_name, + const std::string& port_name); - void connect(boost::shared_ptr port1, - boost::shared_ptr port2); + void connect(FlowCanvas::Connectable* port1, + FlowCanvas::Connectable* port2); - void disconnect(boost::shared_ptr port1, - boost::shared_ptr port2); + void disconnect(FlowCanvas::Connectable* port1, + FlowCanvas::Connectable* port2); void status_message(const std::string& msg); - void index_port(const PortID& id, boost::shared_ptr port) { + void index_port(const PortID& id, PatchagePort* port) { _port_index.insert(std::make_pair(id, port)); } - void add_module(const std::string& name, boost::shared_ptr module); - bool remove_item(boost::shared_ptr i); + void remove_ports(bool (*pred)(const PatchagePort*)); - boost::shared_ptr remove_port(const PortID& id); + void add_module(const std::string& name, PatchageModule* module); + bool remove_item(FlowCanvas::Item* i); + + PatchagePort* remove_port(const PortID& id); void destroy(); private: Patchage* _app; - typedef std::map< const PortID, boost::shared_ptr > PortIndex; + typedef std::map PortIndex; PortIndex _port_index; - typedef std::multimap< const std::string, boost::shared_ptr > ModuleIndex; + typedef std::multimap ModuleIndex; ModuleIndex _module_index; }; diff --git a/src/PatchageEvent.cpp b/src/PatchageEvent.cpp index e77de3f..d1afb1a 100644 --- a/src/PatchageEvent.cpp +++ b/src/PatchageEvent.cpp @@ -47,12 +47,11 @@ PatchageEvent::execute(Patchage* patchage) _str = NULL; } else if (_type == CLIENT_DESTRUCTION) { - SharedPtr module = PtrCast( + PatchageModule* module = dynamic_cast( patchage->canvas()->find_module(_str, InputOutput)); if (module) { patchage->canvas()->remove_item(module); - module.reset(); } free(_str); @@ -72,7 +71,7 @@ PatchageEvent::execute(Patchage* patchage) } if (driver) { - SharedPtr port = driver->create_port_view(patchage, _port_1); + PatchagePort* port = driver->create_port_view(patchage, _port_1); if (port) patchage->enqueue_resize(port->module()); else @@ -83,17 +82,17 @@ PatchageEvent::execute(Patchage* patchage) } else if (_type == PORT_DESTRUCTION) { - SharedPtr port = patchage->canvas()->remove_port(_port_1); + PatchagePort* port = patchage->canvas()->remove_port(_port_1); if (port) { - port.reset(); + delete port; } else { Raul::error << "Unable to find port `" << _port_1 << "' to destroy" << endl; } } else if (_type == CONNECTION) { - SharedPtr port_1 = patchage->canvas()->find_port(_port_1); - SharedPtr port_2 = patchage->canvas()->find_port(_port_2); + PatchagePort* port_1 = patchage->canvas()->find_port(_port_1); + PatchagePort* port_2 = patchage->canvas()->find_port(_port_2); if (!port_1) Raul::error << "Unable to find port `" << _port_1 << "' to connect" << endl; @@ -104,8 +103,8 @@ PatchageEvent::execute(Patchage* patchage) } else if (_type == DISCONNECTION) { - SharedPtr port_1 = patchage->canvas()->find_port(_port_1); - SharedPtr port_2 = patchage->canvas()->find_port(_port_2); + PatchagePort* port_1 = patchage->canvas()->find_port(_port_1); + PatchagePort* port_2 = patchage->canvas()->find_port(_port_2); if (!port_1) Raul::error << "Unable to find port `" << _port_1 << "' to disconnect" << endl; diff --git a/src/PatchageModule.cpp b/src/PatchageModule.cpp index 9cdcb7a..e19418b 100644 --- a/src/PatchageModule.cpp +++ b/src/PatchageModule.cpp @@ -112,14 +112,14 @@ PatchageModule::join() } void -PatchageModule::add_port(boost::shared_ptr port) +PatchageModule::add_port(FlowCanvas::Port* port) { FlowCanvas::Module::add_port(port); update_menu(); } void -PatchageModule::remove_port(boost::shared_ptr port) +PatchageModule::remove_port(FlowCanvas::Port* port) { FlowCanvas::Module::remove_port(port); update_menu(); diff --git a/src/PatchageModule.hpp b/src/PatchageModule.hpp index ebccbb5..2a58182 100644 --- a/src/PatchageModule.hpp +++ b/src/PatchageModule.hpp @@ -32,8 +32,8 @@ public: PatchageModule(Patchage* app, const std::string& name, ModuleType type, double x=0, double y=0); ~PatchageModule(); - void add_port(boost::shared_ptr port); - void remove_port(boost::shared_ptr port); + void add_port(FlowCanvas::Port* port); + void remove_port(FlowCanvas::Port* port); void split(); void join(); diff --git a/src/PatchagePort.hpp b/src/PatchagePort.hpp index 8e4c188..47c1513 100644 --- a/src/PatchagePort.hpp +++ b/src/PatchagePort.hpp @@ -39,11 +39,11 @@ class PatchagePort : public FlowCanvas::Port { public: - PatchagePort(boost::shared_ptr module, - PortType type, - const std::string& name, - bool is_input, - uint32_t color) + PatchagePort(FlowCanvas::Module& module, + PortType type, + const std::string& name, + bool is_input, + uint32_t color) : Port(module, name, is_input, color) , _type(type) { -- cgit v1.2.1