From 800c329a0b77f9044923885abe0728028eca8350 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 19 Aug 2012 02:24:38 +0000 Subject: Patch => Graph git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4721 a436a847-0d15-0410-975c-d299462d15a1 --- src/client/ClientStore.cpp | 66 ++++++++--------- src/client/GraphModel.cpp | 173 +++++++++++++++++++++++++++++++++++++++++++++ src/client/PatchModel.cpp | 173 --------------------------------------------- src/client/PluginModel.cpp | 2 +- src/client/wscript | 2 +- 5 files changed, 208 insertions(+), 208 deletions(-) create mode 100644 src/client/GraphModel.cpp delete mode 100644 src/client/PatchModel.cpp (limited to 'src/client') diff --git a/src/client/ClientStore.cpp b/src/client/ClientStore.cpp index 07b44b84..6d4cbfd4 100644 --- a/src/client/ClientStore.cpp +++ b/src/client/ClientStore.cpp @@ -19,7 +19,7 @@ #include "ingen/client/EdgeModel.hpp" #include "ingen/client/BlockModel.hpp" #include "ingen/client/ObjectModel.hpp" -#include "ingen/client/PatchModel.hpp" +#include "ingen/client/GraphModel.hpp" #include "ingen/client/PluginModel.hpp" #include "ingen/client/PortModel.hpp" #include "ingen/client/SigClientInterface.hpp" @@ -223,9 +223,9 @@ ClientStore::put(const Raul::URI& uri, std::cerr << "}" << endl; #endif - bool is_patch, is_block, is_port, is_output; + bool is_graph, is_block, is_port, is_output; Resource::type(uris(), properties, - is_patch, is_block, is_port, is_output); + is_graph, is_block, is_port, is_output); // Check if uri is a plugin Iterator t = properties.find(_uris.rdf_type); @@ -233,8 +233,8 @@ ClientStore::put(const Raul::URI& uri, const Raul::Atom& type(t->second); const Raul::URI type_uri(type.get_uri()); const Plugin::Type plugin_type(Plugin::type_from_uri(type_uri)); - if (plugin_type == Plugin::Patch) { - is_patch = true; + if (plugin_type == Plugin::Graph) { + is_graph = true; } else if (plugin_type != Plugin::NIL) { SharedPtr p( new PluginModel(uris(), uri, type_uri, properties)); @@ -258,11 +258,11 @@ ClientStore::put(const Raul::URI& uri, } if (path.is_root()) { - is_patch = true; + is_graph = true; } - if (is_patch) { - SharedPtr model(new PatchModel(uris(), path)); + if (is_graph) { + SharedPtr model(new GraphModel(uris(), path)); model->set_properties(properties); add_object(model); } else if (is_block) { @@ -373,29 +373,29 @@ ClientStore::set_property(const Raul::URI& subject_uri, } } -SharedPtr -ClientStore::connection_patch(const Raul::Path& tail_path, +SharedPtr +ClientStore::connection_graph(const Raul::Path& tail_path, const Raul::Path& head_path) { - SharedPtr patch; + SharedPtr graph; if (tail_path.parent() == head_path.parent()) - patch = PtrCast(_object(tail_path.parent())); + graph = PtrCast(_object(tail_path.parent())); - if (!patch && tail_path.parent() == head_path.parent().parent()) - patch = PtrCast(_object(tail_path.parent())); + if (!graph && tail_path.parent() == head_path.parent().parent()) + graph = PtrCast(_object(tail_path.parent())); - if (!patch && tail_path.parent().parent() == head_path.parent()) - patch = PtrCast(_object(head_path.parent())); + if (!graph && tail_path.parent().parent() == head_path.parent()) + graph = PtrCast(_object(head_path.parent())); - if (!patch) - patch = PtrCast(_object(tail_path.parent().parent())); + if (!graph) + graph = PtrCast(_object(tail_path.parent().parent())); - if (!patch) - _log.error(Raul::fmt("Unable to find path for edge %1% => %2%\n") + if (!graph) + _log.error(Raul::fmt("Unable to find graph for edge %1% => %2%\n") % tail_path % head_path); - return patch; + return graph; } bool @@ -406,13 +406,13 @@ ClientStore::attempt_connection(const Raul::Path& tail_path, SharedPtr head = PtrCast(_object(head_path)); if (tail && head) { - SharedPtr patch = connection_patch(tail_path, head_path); + SharedPtr graph = connection_graph(tail_path, head_path); SharedPtr cm(new EdgeModel(tail, head)); tail->connected_to(head); head->connected_to(tail); - patch->add_edge(cm); + graph->add_edge(cm); return true; } else { _log.warn(Raul::fmt("Failed to connect %1% => %2%\n") @@ -441,26 +441,26 @@ ClientStore::disconnect(const Raul::Path& src_path, if (head) head->disconnected_from(tail); - SharedPtr patch = connection_patch(src_path, dst_path); - if (patch) - patch->remove_edge(tail.get(), head.get()); + SharedPtr graph = connection_graph(src_path, dst_path); + if (graph) + graph->remove_edge(tail.get(), head.get()); } void -ClientStore::disconnect_all(const Raul::Path& parent_patch, +ClientStore::disconnect_all(const Raul::Path& parent_graph, const Raul::Path& path) { - SharedPtr patch = PtrCast(_object(parent_patch)); + SharedPtr graph = PtrCast(_object(parent_graph)); SharedPtr object = _object(path); - if (!patch || !object) { + if (!graph || !object) { _log.error(Raul::fmt("Bad disconnect all notification %1% in %2%\n") - % path % parent_patch); + % path % parent_graph); return; } - const PatchModel::Edges edges = patch->edges(); - for (PatchModel::Edges::const_iterator i = edges.begin(); + const GraphModel::Edges edges = graph->edges(); + for (GraphModel::Edges::const_iterator i = edges.begin(); i != edges.end(); ++i) { SharedPtr c = PtrCast(i->second); if (c->tail()->parent() == object @@ -469,7 +469,7 @@ ClientStore::disconnect_all(const Raul::Path& parent_patch, || c->head()->path() == path) { c->tail()->disconnected_from(c->head()); c->head()->disconnected_from(c->tail()); - patch->remove_edge(c->tail().get(), c->head().get()); + graph->remove_edge(c->tail().get(), c->head().get()); } } } diff --git a/src/client/GraphModel.cpp b/src/client/GraphModel.cpp new file mode 100644 index 00000000..88943978 --- /dev/null +++ b/src/client/GraphModel.cpp @@ -0,0 +1,173 @@ +/* + This file is part of Ingen. + Copyright 2007-2012 David Robillard + + Ingen is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or 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 Affero General Public License for details. + + You should have received a copy of the GNU Affero General Public License + along with Ingen. If not, see . +*/ + +#include + +#include "ingen/URIs.hpp" +#include "ingen/client/BlockModel.hpp" +#include "ingen/client/ClientStore.hpp" +#include "ingen/client/EdgeModel.hpp" +#include "ingen/client/GraphModel.hpp" + +using namespace std; + +namespace Ingen { +namespace Client { + +void +GraphModel::add_child(SharedPtr c) +{ + assert(c->parent().get() == this); + + SharedPtr pm = PtrCast(c); + if (pm) { + add_port(pm); + return; + } + + SharedPtr bm = PtrCast(c); + if (bm) { + _signal_new_block.emit(bm); + } +} + +bool +GraphModel::remove_child(SharedPtr o) +{ + assert(o->path().is_child_of(path())); + assert(o->parent().get() == this); + + // Remove any connections which referred to this object, + // since they can't possibly exist anymore + for (Edges::iterator j = _edges.begin(); j != _edges.end();) { + Edges::iterator next = j; + ++next; + + SharedPtr cm = PtrCast(j->second); + assert(cm); + + if (cm->tail_path().parent() == o->path() + || cm->tail_path() == o->path() + || cm->head_path().parent() == o->path() + || cm->head_path() == o->path()) { + _signal_removed_edge.emit(cm); + _edges.erase(j); // cuts our reference + } + j = next; + } + + SharedPtr pm = PtrCast(o); + if (pm) + remove_port(pm); + + SharedPtr bm = PtrCast(o); + if (bm) { + _signal_removed_block.emit(bm); + } + + return true; +} + +void +GraphModel::clear() +{ + _edges.clear(); + + BlockModel::clear(); + + assert(_edges.empty()); + assert(_ports.empty()); +} + +SharedPtr +GraphModel::get_edge(const GraphObject* tail, const GraphObject* head) +{ + Edges::iterator i = _edges.find(make_pair(tail, head)); + if (i != _edges.end()) + return PtrCast(i->second); + else + return SharedPtr(); +} + +/** Add a connection to this graph. + * + * 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 graph is a fatal error. + */ +void +GraphModel::add_edge(SharedPtr cm) +{ + // Store should have 'resolved' the connection already + assert(cm); + assert(cm->tail()); + assert(cm->head()); + assert(cm->tail()->parent()); + assert(cm->head()->parent()); + assert(cm->tail_path() != cm->head_path()); + assert(cm->tail()->parent().get() == this + || cm->tail()->parent()->parent().get() == this); + assert(cm->head()->parent().get() == this + || cm->head()->parent()->parent().get() == this); + + SharedPtr existing = get_edge( + cm->tail().get(), cm->head().get()); + + if (existing) { + assert(cm->tail() == existing->tail()); + assert(cm->head() == existing->head()); + } else { + _edges.insert(make_pair(make_pair(cm->tail().get(), + cm->head().get()), cm)); + _signal_new_edge.emit(cm); + } +} + +void +GraphModel::remove_edge(const GraphObject* tail, const GraphObject* head) +{ + Edges::iterator i = _edges.find(make_pair(tail, head)); + if (i != _edges.end()) { + SharedPtr c = PtrCast(i->second); + _signal_removed_edge.emit(c); + _edges.erase(i); + } +} + +bool +GraphModel::enabled() const +{ + const Raul::Atom& enabled = get_property(_uris.ingen_enabled); + return (enabled.is_valid() && enabled.get_bool()); +} + +uint32_t +GraphModel::internal_poly() const +{ + const Raul::Atom& poly = get_property(_uris.ingen_polyphony); + return poly.is_valid() ? poly.get_int32() : 1; +} + +bool +GraphModel::polyphonic() const +{ + const Raul::Atom& poly = get_property(_uris.ingen_polyphonic); + return poly.is_valid() && poly.get_bool(); +} + +} // namespace Client +} // namespace Ingen diff --git a/src/client/PatchModel.cpp b/src/client/PatchModel.cpp deleted file mode 100644 index 9b622cda..00000000 --- a/src/client/PatchModel.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/* - This file is part of Ingen. - Copyright 2007-2012 David Robillard - - Ingen is free software: you can redistribute it and/or modify it under the - terms of the GNU Affero General Public License as published by the Free - Software Foundation, either version 3 of the License, or 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 Affero General Public License for details. - - You should have received a copy of the GNU Affero General Public License - along with Ingen. If not, see . -*/ - -#include - -#include "ingen/client/ClientStore.hpp" -#include "ingen/client/EdgeModel.hpp" -#include "ingen/client/BlockModel.hpp" -#include "ingen/client/PatchModel.hpp" -#include "ingen/URIs.hpp" - -using namespace std; - -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 bm = PtrCast(c); - if (bm) { - _signal_new_block.emit(bm); - } -} - -bool -PatchModel::remove_child(SharedPtr o) -{ - assert(o->path().is_child_of(path())); - assert(o->parent().get() == this); - - // Remove any connections which referred to this object, - // since they can't possibly exist anymore - for (Edges::iterator j = _edges.begin(); j != _edges.end();) { - Edges::iterator next = j; - ++next; - - SharedPtr cm = PtrCast(j->second); - assert(cm); - - if (cm->tail_path().parent() == o->path() - || cm->tail_path() == o->path() - || cm->head_path().parent() == o->path() - || cm->head_path() == o->path()) { - _signal_removed_edge.emit(cm); - _edges.erase(j); // cuts our reference - } - j = next; - } - - SharedPtr pm = PtrCast(o); - if (pm) - remove_port(pm); - - SharedPtr bm = PtrCast(o); - if (bm) { - _signal_removed_block.emit(bm); - } - - return true; -} - -void -PatchModel::clear() -{ - _edges.clear(); - - BlockModel::clear(); - - assert(_edges.empty()); - assert(_ports.empty()); -} - -SharedPtr -PatchModel::get_edge(const GraphObject* tail, const GraphObject* head) -{ - Edges::iterator i = _edges.find(make_pair(tail, head)); - if (i != _edges.end()) - return PtrCast(i->second); - else - 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_edge(SharedPtr cm) -{ - // Store should have 'resolved' the connection already - assert(cm); - assert(cm->tail()); - assert(cm->head()); - assert(cm->tail()->parent()); - assert(cm->head()->parent()); - assert(cm->tail_path() != cm->head_path()); - assert(cm->tail()->parent().get() == this - || cm->tail()->parent()->parent().get() == this); - assert(cm->head()->parent().get() == this - || cm->head()->parent()->parent().get() == this); - - SharedPtr existing = get_edge( - cm->tail().get(), cm->head().get()); - - if (existing) { - assert(cm->tail() == existing->tail()); - assert(cm->head() == existing->head()); - } else { - _edges.insert(make_pair(make_pair(cm->tail().get(), - cm->head().get()), cm)); - _signal_new_edge.emit(cm); - } -} - -void -PatchModel::remove_edge(const GraphObject* tail, const GraphObject* head) -{ - Edges::iterator i = _edges.find(make_pair(tail, head)); - if (i != _edges.end()) { - SharedPtr c = PtrCast(i->second); - _signal_removed_edge.emit(c); - _edges.erase(i); - } -} - -bool -PatchModel::enabled() const -{ - const Raul::Atom& enabled = get_property(_uris.ingen_enabled); - return (enabled.is_valid() && enabled.get_bool()); -} - -uint32_t -PatchModel::internal_poly() const -{ - const Raul::Atom& poly = get_property(_uris.ingen_polyphony); - return poly.is_valid() ? poly.get_int32() : 1; -} - -bool -PatchModel::polyphonic() const -{ - const Raul::Atom& poly = get_property(_uris.ingen_polyphonic); - return poly.is_valid() && poly.get_bool(); -} - -} // namespace Client -} // namespace Ingen diff --git a/src/client/PluginModel.cpp b/src/client/PluginModel.cpp index 53736a3e..371e6b46 100644 --- a/src/client/PluginModel.cpp +++ b/src/client/PluginModel.cpp @@ -24,7 +24,7 @@ #include "raul/Atom.hpp" #include "raul/Path.hpp" -#include "ingen/client/PatchModel.hpp" +#include "ingen/client/GraphModel.hpp" #include "ingen/client/PluginModel.hpp" #include "ingen/client/PluginUI.hpp" diff --git a/src/client/wscript b/src/client/wscript index c85ee5ab..c2b12ef3 100644 --- a/src/client/wscript +++ b/src/client/wscript @@ -14,8 +14,8 @@ def build(bld): obj.source = ''' BlockModel.cpp ClientStore.cpp + GraphModel.cpp ObjectModel.cpp - PatchModel.cpp PluginModel.cpp PluginUI.cpp PortModel.cpp -- cgit v1.2.1