summaryrefslogtreecommitdiffstats
path: root/ingen/Node.hpp
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-08-19 02:57:26 +0000
committerDavid Robillard <d@drobilla.net>2012-08-19 02:57:26 +0000
commitba1f169967f64b9657074fba2de803b29829345c (patch)
treeb46baed3c4d96f2129cb58686b09b2b86d86d05e /ingen/Node.hpp
parent800c329a0b77f9044923885abe0728028eca8350 (diff)
downloadingen-ba1f169967f64b9657074fba2de803b29829345c.tar.gz
ingen-ba1f169967f64b9657074fba2de803b29829345c.tar.bz2
ingen-ba1f169967f64b9657074fba2de803b29829345c.zip
GraphObject => Node
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4722 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'ingen/Node.hpp')
-rw-r--r--ingen/Node.hpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/ingen/Node.hpp b/ingen/Node.hpp
new file mode 100644
index 00000000..9ec6abd1
--- /dev/null
+++ b/ingen/Node.hpp
@@ -0,0 +1,104 @@
+/*
+ This file is part of Ingen.
+ Copyright 2007-2012 David Robillard <http://drobilla.net/>
+
+ 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 <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef INGEN_NODE_HPP
+#define INGEN_NODE_HPP
+
+#include "raul/Path.hpp"
+#include "raul/SharedPtr.hpp"
+#include "ingen/Resource.hpp"
+
+namespace Raul {
+class Atom;
+class Path;
+class Symbol;
+}
+
+namespace Ingen {
+
+class Edge;
+class Plugin;
+class Store;
+
+/** An object on the audio graph.
+ *
+ * The key property of nodes is that all nodes have a path and a symbol, as
+ * well as a URI.
+ *
+ * To avoid ugly inheritance issues and the need for excessive use of
+ * dynamic_cast, this class contains some members which are only applicable to
+ * certain types of node. There is a type tag which can be used to determine
+ * the type of any Node.
+ *
+ * @ingroup Ingen
+ */
+class Node : public Resource
+{
+public:
+ enum GraphType {
+ GRAPH,
+ BLOCK,
+ PORT
+ };
+
+ typedef std::pair<const Node*, const Node*> EdgesKey;
+ typedef std::map< EdgesKey, SharedPtr<Edge> > Edges;
+
+ // Graphs only
+ Edges& edges() { return _edges; }
+ const Edges& edges() const { return _edges; }
+
+ // Blocks and graphs only
+ virtual uint32_t num_ports() const { return 0; }
+ virtual Node* port(uint32_t index) const { return NULL; }
+ virtual const Plugin* plugin() const { return NULL; }
+
+ // All objects
+ virtual GraphType graph_type() const = 0;
+ virtual const Raul::Path& path() const = 0;
+ virtual const Raul::Symbol& symbol() const = 0;
+ virtual Node* graph_parent() const = 0;
+
+ static Raul::URI root_uri() { return Raul::URI("ingen:root"); }
+
+ static bool uri_is_path(const Raul::URI& uri) {
+ return uri.substr(0, root_uri().length()) == root_uri();
+ }
+
+ static Raul::Path uri_to_path(const Raul::URI& uri) {
+ return (uri == root_uri())
+ ? Raul::Path("/")
+ : Raul::Path(uri.substr(root_uri().length()));
+ }
+
+ static Raul::URI path_to_uri(const Raul::Path& path) {
+ return Raul::URI(root_uri() + path.c_str());
+ }
+
+protected:
+ friend class Store;
+ virtual void set_path(const Raul::Path& p) = 0;
+
+ Node(URIs& uris, const Raul::Path& path)
+ : Resource(uris, path_to_uri(path))
+ {}
+
+ Edges _edges; ///< Graphs only
+};
+
+} // namespace Ingen
+
+#endif // INGEN_NODE_HPP