From 93850c202de8b073a1ce1dd8bd246d407bce4e2f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 30 Sep 2008 16:50:21 +0000 Subject: Flatten ingen source directory heirarchy a bit. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@1551 a436a847-0d15-0410-975c-d299462d15a1 --- src/client/PatchModel.cpp | 190 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 src/client/PatchModel.cpp (limited to 'src/client/PatchModel.cpp') diff --git a/src/client/PatchModel.cpp b/src/client/PatchModel.cpp new file mode 100644 index 00000000..af20c9f8 --- /dev/null +++ b/src/client/PatchModel.cpp @@ -0,0 +1,190 @@ +/* This file is part of Ingen. + * Copyright (C) 2007 Dave Robillard + * + * Ingen 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. + * + * Ingen 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 "PatchModel.hpp" +#include "NodeModel.hpp" +#include "ConnectionModel.hpp" +#include "ClientStore.hpp" +#include +#include + +using std::cerr; using std::cout; using std::endl; + +namespace Ingen { +namespace Client { + + +void +PatchModel::add_child(SharedPtr c) +{ + assert(c->parent().get() == this); + + SharedPtr pm = PtrCast(c); + if (pm) { + add_port(pm); + return; + } + + SharedPtr nm = PtrCast(c); + if (nm) + signal_new_node.emit(nm); +} + + +bool +PatchModel::remove_child(SharedPtr o) +{ + assert(o->path().is_child_of(_path)); + assert(o->parent().get() == this); + + SharedPtr pm = PtrCast(o); + if (pm) + remove_port(pm); + + // Remove any connections which referred to this object, + // since they can't possibly exist anymore + for (Connections::iterator j = _connections->begin(); j != _connections->end() ; ) { + + Connections::iterator next = j; + ++next; + + SharedPtr cm = PtrCast(*j); + assert(cm); + + if (cm->src_port_path().parent() == o->path() + || cm->src_port_path() == o->path() + || cm->dst_port_path().parent() == o->path() + || cm->dst_port_path() == o->path()) { + signal_removed_connection.emit(cm); + _connections->erase(j); // cuts our reference + assert(!get_connection(cm->src_port_path(), cm->dst_port_path())); // no duplicates + } + j = next; + } + + SharedPtr nm = PtrCast(o); + if (nm) + signal_removed_node.emit(nm); + + return true; +} + + +void +PatchModel::clear() +{ + _connections->clear(); + + NodeModel::clear(); + + assert(_connections->empty()); + assert(_ports.empty()); +} + + +SharedPtr +PatchModel::get_connection(const string& src_port_path, const string& dst_port_path) const +{ + for (Connections::const_iterator i = _connections->begin(); i != _connections->end(); ++i) + if ((*i)->src_port_path() == src_port_path && (*i)->dst_port_path() == dst_port_path) + return PtrCast(*i); + + return SharedPtr(); +} + + +/** Add a connection to this patch. + * + * A reference to @a cm is taken, released on deletion or removal. + * If @a cm only contains paths (not pointers to the actual ports), the ports + * will be found and set. The ports referred to not existing as children of + * this patch is a fatal error. + */ +void +PatchModel::add_connection(SharedPtr cm) +{ + // Store should have 'resolved' the connection already + assert(cm); + assert(cm->src_port()); + assert(cm->dst_port()); + assert(cm->src_port()->parent()); + assert(cm->dst_port()->parent()); + assert(cm->src_port_path() != cm->dst_port_path()); + assert(cm->src_port()->parent().get() == this + || cm->src_port()->parent()->parent().get() == this); + assert(cm->dst_port()->parent().get() == this + || cm->dst_port()->parent()->parent().get() == this); + + SharedPtr existing = get_connection(cm->src_port_path(), cm->dst_port_path()); + + if (existing) { + assert(cm->src_port() == existing->src_port()); + assert(cm->dst_port() == existing->dst_port()); + } else { + _connections->push_back(new Connections::Node(cm)); + signal_new_connection.emit(cm); + } +} + + +void +PatchModel::remove_connection(const string& src_port_path, const string& dst_port_path) +{ + for (Connections::iterator i = _connections->begin(); i != _connections->end(); ++i) { + SharedPtr cm = PtrCast(*i); + assert(cm); + if (cm->src_port_path() == src_port_path && cm->dst_port_path() == dst_port_path) { + signal_removed_connection.emit(cm); + delete _connections->erase(i); // cuts our reference + assert(!get_connection(src_port_path, dst_port_path)); // no duplicates + return; + } + } + + cerr << "[PatchModel::remove_connection] WARNING: Failed to find connection " << + src_port_path << " -> " << dst_port_path << endl; +} + + +bool +PatchModel::enabled() const +{ + Properties::const_iterator i = _properties.find("ingen:enabled"); + return (i != _properties.end() && i->second.type() == Atom::BOOL && i->second.get_bool()); +} + + +void +PatchModel::set_property(const string& key, const Atom& value) +{ + ObjectModel::set_property(key, value); + if (key == "ingen:polyphony") + _poly = value.get_int32(); +} + + +bool +PatchModel::polyphonic() const +{ + return (_parent) + ? (_poly > 1) && _poly == PtrCast(_parent)->poly() && _poly > 1 + : (_poly > 1); +} + + +} // namespace Client +} // namespace Ingen -- cgit v1.2.1