/* This file is part of Patchage. * Copyright (C) 2007 Dave Robillard * * Patchage 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. * * Patchage 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 "config.h" #include "common.hpp" #include "PatchageCanvas.hpp" #include "Patchage.hpp" #include "PatchageModule.hpp" #include "PatchagePort.hpp" PatchageCanvas::PatchageCanvas(Patchage* app, int width, int height) : FlowCanvas::Canvas(width, height) , _app(app) { } boost::shared_ptr PatchageCanvas::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 PatchageCanvas::find_module(const string& name, ModuleType type) { for (ItemList::iterator m = _items.begin(); m != _items.end(); ++m) { boost::shared_ptr pm = boost::dynamic_pointer_cast(*m); if (pm && pm->identify(name, type)) { return pm; } } return boost::shared_ptr(); } void PatchageCanvas::connect(boost::shared_ptr port1, boost::shared_ptr port2) { _app->connect(boost::dynamic_pointer_cast(port1), boost::dynamic_pointer_cast(port2)); } void PatchageCanvas::disconnect(boost::shared_ptr port1, boost::shared_ptr port2) { _app->disconnect(boost::dynamic_pointer_cast(port1), boost::dynamic_pointer_cast(port2)); } void PatchageCanvas::status_message(const string& msg) { _app->status_msg(string("[Canvas] ").append(msg)); } boost::shared_ptr PatchageCanvas::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 dynamic_pointer_cast(port); } return boost::shared_ptr(); } boost::shared_ptr PatchageCanvas::lookup_port_by_a2j_jack_port_name( const char * a2j_jack_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; PortVector ports = module->ports(); // copy for (PortVector::iterator p = ports.begin(); p != ports.end(); ++p) { boost::shared_ptr port = boost::dynamic_pointer_cast(*p); if (port->is_a2j_mapped && port->a2j_jack_port_name == a2j_jack_port_name) { return dynamic_pointer_cast(port); } } } return boost::shared_ptr(); }